@motifx-community/ui 0.1.0-beta.14 → 0.1.0-beta.16

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 (330) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +2 -2
  3. package/dist/components/diagram/Diagram.d.ts +607 -0
  4. package/dist/components/diagram/DiagramAutoPan.d.ts +17 -0
  5. package/dist/components/diagram/DiagramBends.d.ts +70 -0
  6. package/dist/components/diagram/DiagramDragging.d.ts +66 -0
  7. package/dist/components/diagram/DiagramEdgeView.d.ts +78 -0
  8. package/dist/components/diagram/DiagramGrid.d.ts +13 -0
  9. package/dist/components/diagram/DiagramHistory.d.ts +16 -0
  10. package/dist/components/diagram/DiagramLinks.d.ts +177 -0
  11. package/dist/components/diagram/DiagramMap.d.ts +62 -0
  12. package/dist/components/diagram/DiagramNodeView.d.ts +143 -0
  13. package/dist/components/diagram/DiagramOverview.d.ts +20 -0
  14. package/dist/components/diagram/DiagramPanning.d.ts +34 -0
  15. package/dist/components/diagram/diagram-alignment.d.ts +2 -0
  16. package/dist/components/diagram/diagram-auto-pan-host.d.ts +8 -0
  17. package/dist/components/diagram/diagram-background.d.ts +2 -0
  18. package/dist/components/diagram/diagram-bends-host.d.ts +17 -0
  19. package/dist/components/diagram/diagram-card-kind.d.ts +42 -0
  20. package/dist/components/diagram/diagram-card-node.d.ts +11 -0
  21. package/dist/components/diagram/diagram-center-options.d.ts +6 -0
  22. package/dist/components/diagram/diagram-change.d.ts +11 -0
  23. package/dist/components/diagram/diagram-class-member.d.ts +13 -0
  24. package/dist/components/diagram/diagram-class-node.d.ts +12 -0
  25. package/dist/components/diagram/diagram-column-checked-event-args.d.ts +9 -0
  26. package/dist/components/diagram/diagram-connected-event-args.d.ts +6 -0
  27. package/dist/components/diagram/diagram-connecting-event-args.d.ts +9 -0
  28. package/dist/components/diagram/diagram-connection.d.ts +7 -0
  29. package/dist/components/diagram/diagram-data.d.ts +12 -0
  30. package/dist/components/diagram/diagram-deleted-event-args.d.ts +8 -0
  31. package/dist/components/diagram/diagram-deleting-event-args.d.ts +9 -0
  32. package/dist/components/diagram/diagram-dragging-host.d.ts +47 -0
  33. package/dist/components/diagram/diagram-drawn-node.d.ts +10 -0
  34. package/dist/components/diagram/diagram-edge-end.d.ts +2 -0
  35. package/dist/components/diagram/diagram-edge-path.d.ts +5 -0
  36. package/dist/components/diagram/diagram-edge-reshaped-event-args.d.ts +8 -0
  37. package/dist/components/diagram/diagram-edge-reshaping-event-args.d.ts +6 -0
  38. package/dist/components/diagram/diagram-edge.d.ts +49 -0
  39. package/dist/components/diagram/diagram-edit.d.ts +10 -0
  40. package/dist/components/diagram/diagram-export-options.d.ts +14 -0
  41. package/dist/components/diagram/diagram-export.d.ts +28 -0
  42. package/dist/components/diagram/diagram-fit-options.d.ts +12 -0
  43. package/dist/components/diagram/diagram-history-changed-event-args.d.ts +14 -0
  44. package/dist/components/diagram/diagram-history-step.d.ts +9 -0
  45. package/dist/components/diagram/diagram-kinds.d.ts +9 -0
  46. package/dist/components/diagram/diagram-layered.d.ts +39 -0
  47. package/dist/components/diagram/diagram-layout-direction.d.ts +2 -0
  48. package/dist/components/diagram/diagram-layout-options.d.ts +24 -0
  49. package/dist/components/diagram/diagram-layout-type.d.ts +5 -0
  50. package/dist/components/diagram/diagram-layout.d.ts +33 -0
  51. package/dist/components/diagram/diagram-line-look.d.ts +6 -0
  52. package/dist/components/diagram/diagram-line.d.ts +11 -0
  53. package/dist/components/diagram/diagram-links-host.d.ts +45 -0
  54. package/dist/components/diagram/diagram-links-options.d.ts +7 -0
  55. package/dist/components/diagram/diagram-map-props.d.ts +10 -0
  56. package/dist/components/diagram/diagram-map-target.d.ts +27 -0
  57. package/dist/components/diagram/diagram-marker.d.ts +6 -0
  58. package/dist/components/diagram/diagram-mini-map-options.d.ts +13 -0
  59. package/dist/components/diagram/diagram-mini-map-position.d.ts +2 -0
  60. package/dist/components/diagram/diagram-node-context.d.ts +26 -0
  61. package/dist/components/diagram/diagram-node-host.d.ts +23 -0
  62. package/dist/components/diagram/diagram-node-kind.d.ts +43 -0
  63. package/dist/components/diagram/diagram-node-move.d.ts +11 -0
  64. package/dist/components/diagram/diagram-node-resized-event-args.d.ts +8 -0
  65. package/dist/components/diagram/diagram-node-resizing-event-args.d.ts +6 -0
  66. package/dist/components/diagram/diagram-node-size.d.ts +8 -0
  67. package/dist/components/diagram/diagram-node-status.d.ts +2 -0
  68. package/dist/components/diagram/diagram-node-toggled-event-args.d.ts +7 -0
  69. package/dist/components/diagram/diagram-node.d.ts +56 -0
  70. package/dist/components/diagram/diagram-nodes-moved-event-args.d.ts +6 -0
  71. package/dist/components/diagram/diagram-nodes-moving-event-args.d.ts +6 -0
  72. package/dist/components/diagram/diagram-panning-host.d.ts +19 -0
  73. package/dist/components/diagram/diagram-pasted-event-args.d.ts +7 -0
  74. package/dist/components/diagram/diagram-pasting-event-args.d.ts +11 -0
  75. package/dist/components/diagram/diagram-path-ends.d.ts +11 -0
  76. package/dist/components/diagram/diagram-path-result.d.ts +6 -0
  77. package/dist/components/diagram/diagram-paths.d.ts +35 -0
  78. package/dist/components/diagram/diagram-point.d.ts +5 -0
  79. package/dist/components/diagram/diagram-port-place.d.ts +9 -0
  80. package/dist/components/diagram/diagram-port.d.ts +27 -0
  81. package/dist/components/diagram/diagram-props.d.ts +159 -0
  82. package/dist/components/diagram/diagram-reconnected-event-args.d.ts +10 -0
  83. package/dist/components/diagram/diagram-reconnecting-event-args.d.ts +11 -0
  84. package/dist/components/diagram/diagram-rect.d.ts +7 -0
  85. package/dist/components/diagram/diagram-resize-side.d.ts +2 -0
  86. package/dist/components/diagram/diagram-route.d.ts +10 -0
  87. package/dist/components/diagram/diagram-selection-changed-event-args.d.ts +9 -0
  88. package/dist/components/diagram/diagram-selection.d.ts +5 -0
  89. package/dist/components/diagram/diagram-side.d.ts +2 -0
  90. package/dist/components/diagram/diagram-table-column.d.ts +13 -0
  91. package/dist/components/diagram/diagram-table-node.d.ts +12 -0
  92. package/dist/components/diagram/diagram-tree.d.ts +14 -0
  93. package/dist/components/diagram/diagram-viewport-changed-event-args.d.ts +8 -0
  94. package/dist/components/diagram/diagram-viewport-options.d.ts +5 -0
  95. package/dist/components/diagram/diagram-viewport.d.ts +6 -0
  96. package/dist/components/diagram/index.d.ts +65 -0
  97. package/dist/components/diagram/swallow-next-click.d.ts +5 -0
  98. package/dist/components/expressioneditor/ExpressionEditor.d.ts +111 -0
  99. package/dist/components/expressioneditor/expression-editor-props.d.ts +24 -0
  100. package/dist/components/expressioneditor/index.d.ts +2 -0
  101. package/dist/components/formlayout/FormLayout.d.ts +10 -3
  102. package/dist/components/formlayout/form-editor-type.d.ts +1 -1
  103. package/dist/components/formlayout/form-item.d.ts +4 -1
  104. package/dist/components/formlayout/form-layout-props.d.ts +1 -1
  105. package/dist/components/formlayout/index.d.ts +1 -0
  106. package/dist/components/formlayout/schema-items.d.ts +26 -0
  107. package/dist/components/pivotgrid/model/PivotAxisWindow.d.ts +53 -1
  108. package/dist/components/pivotgrid/model/PivotCellWindow.d.ts +2 -0
  109. package/dist/components/pivotgrid/model/PivotWindows.d.ts +3 -6
  110. package/dist/components/toolbar/Toolbar.d.ts +5 -3
  111. package/dist/core/control.d.ts +2 -0
  112. package/dist/core/keyboard.d.ts +5 -0
  113. package/dist/core/measure/index.d.ts +2 -0
  114. package/dist/core/measure/picture.d.ts +27 -0
  115. package/dist/core/shortcut-options.d.ts +5 -2
  116. package/dist/core/ui-strings.d.ts +191 -0
  117. package/dist/generated/tokens.d.ts +1615 -0
  118. package/dist/index.d.ts +2 -0
  119. package/dist/index.js +11501 -705
  120. package/dist/index.js.map +1 -1
  121. package/dist/locales/en.json +180 -1
  122. package/dist/locales/tr.json +180 -1
  123. package/dist/styles.css +2262 -3
  124. package/dist/tokens/index.d.ts +1615 -0
  125. package/dist/tokens/index.js +1615 -0
  126. package/dist/tokens/index.js.map +1 -1
  127. package/dist/{tr-BGbF9uCs.js → tr-4GNbFdQh.js} +361 -3
  128. package/dist/{tr-BGbF9uCs.js.map → tr-4GNbFdQh.js.map} +1 -1
  129. package/docs/accordion.md +1 -1
  130. package/docs/actionsheet.md +1 -1
  131. package/docs/appbar.md +1 -1
  132. package/docs/appmenu-api.md +1 -1
  133. package/docs/appmenu-programmatic.md +1 -1
  134. package/docs/appmenu-search.md +1 -1
  135. package/docs/appmenu.md +1 -1
  136. package/docs/avatar.md +1 -1
  137. package/docs/badge.md +1 -1
  138. package/docs/bar-gauge-angles.md +1 -1
  139. package/docs/bar-gauge-data.md +1 -1
  140. package/docs/bar-gauge-labels.md +1 -1
  141. package/docs/bar-gauge.md +1 -1
  142. package/docs/barcode.md +1 -1
  143. package/docs/bottomnavigation.md +1 -1
  144. package/docs/bottomsheet.md +1 -1
  145. package/docs/breadcrumb.md +1 -1
  146. package/docs/button.md +1 -1
  147. package/docs/buttongroup.md +1 -1
  148. package/docs/buttons.md +1 -1
  149. package/docs/calendar.md +1 -1
  150. package/docs/card.md +1 -1
  151. package/docs/chart-bars.md +1 -1
  152. package/docs/chart-candles.md +1 -1
  153. package/docs/chart-funnel.md +1 -1
  154. package/docs/chart-heatmap.md +1 -1
  155. package/docs/chart-lines.md +1 -1
  156. package/docs/chart-live.md +1 -1
  157. package/docs/chart-pie.md +1 -1
  158. package/docs/chart-radar.md +1 -1
  159. package/docs/chart-ranges.md +1 -1
  160. package/docs/chart-references.md +1 -1
  161. package/docs/chart-scatter.md +1 -1
  162. package/docs/chart-waterfall.md +1 -1
  163. package/docs/chart-zoom.md +1 -1
  164. package/docs/chart.md +1 -1
  165. package/docs/chat.md +1 -1
  166. package/docs/checkbox.md +1 -1
  167. package/docs/chip.md +1 -1
  168. package/docs/choice.md +1 -1
  169. package/docs/colorbox.md +1 -1
  170. package/docs/combobox.md +1 -1
  171. package/docs/commands.md +1 -1
  172. package/docs/control.md +1 -1
  173. package/docs/data.md +2 -2
  174. package/docs/datagrid-api.md +1 -1
  175. package/docs/datagrid-bands.md +1 -1
  176. package/docs/datagrid-drag-select.md +1 -1
  177. package/docs/datagrid-drag.md +1 -1
  178. package/docs/datagrid-editing.md +1 -1
  179. package/docs/datagrid-filtering.md +1 -1
  180. package/docs/datagrid-forms.md +1 -1
  181. package/docs/datagrid-grouping.md +1 -1
  182. package/docs/datagrid-layout.md +1 -1
  183. package/docs/datagrid-lookups.md +1 -1
  184. package/docs/datagrid-master-detail.md +1 -1
  185. package/docs/datagrid-scrolling.md +1 -1
  186. package/docs/datagrid-selection.md +1 -1
  187. package/docs/datagrid.md +1 -1
  188. package/docs/datalayer-api.md +491 -0
  189. package/docs/datalayer-changes.md +501 -0
  190. package/docs/datalayer-odata.md +998 -0
  191. package/docs/datalayer-pivot.md +850 -0
  192. package/docs/datalayer-queries.md +516 -0
  193. package/docs/datalayer-rest.md +529 -0
  194. package/docs/datalayer-soap.md +576 -0
  195. package/docs/datalayer-source.md +464 -0
  196. package/docs/datalayer.md +264 -0
  197. package/docs/datebox.md +1 -1
  198. package/docs/daterangebox.md +1 -1
  199. package/docs/diagram-api.md +200 -0
  200. package/docs/diagram-commands.md +79 -0
  201. package/docs/diagram-connections.md +157 -0
  202. package/docs/diagram-custom-nodes.md +325 -0
  203. package/docs/diagram-designer.md +816 -0
  204. package/docs/diagram-editing.md +62 -0
  205. package/docs/diagram-flow.md +157 -0
  206. package/docs/diagram-keyboard.md +58 -0
  207. package/docs/diagram-layout.md +354 -0
  208. package/docs/diagram-nodes.md +206 -0
  209. package/docs/diagram-tables.md +212 -0
  210. package/docs/diagram.md +217 -0
  211. package/docs/display.md +1 -1
  212. package/docs/draggable.md +1 -1
  213. package/docs/drawer.md +1 -1
  214. package/docs/dropdown.md +1 -1
  215. package/docs/editors.md +1 -1
  216. package/docs/expressioneditor.md +469 -0
  217. package/docs/expressions.md +431 -0
  218. package/docs/feedback.md +1 -1
  219. package/docs/fileuploader.md +1 -1
  220. package/docs/filterbuilder.md +1 -1
  221. package/docs/formlayout-schema.md +143 -0
  222. package/docs/formlayout.md +16 -4
  223. package/docs/foundations.md +1 -1
  224. package/docs/gallery.md +1 -1
  225. package/docs/gauge-base.md +1 -1
  226. package/docs/gauge-circular.md +1 -1
  227. package/docs/gauge-dashboards.md +1 -1
  228. package/docs/gauge-linear.md +1 -1
  229. package/docs/gauge-markers.md +1 -1
  230. package/docs/gauge-marks.md +1 -1
  231. package/docs/gauge-ranges.md +1 -1
  232. package/docs/gauge-scales.md +1 -1
  233. package/docs/gauge.md +1 -1
  234. package/docs/home.md +1 -1
  235. package/docs/keyboard.md +2 -2
  236. package/docs/language.md +1 -1
  237. package/docs/layout.md +1 -1
  238. package/docs/listbox.md +1 -1
  239. package/docs/loadpanel.md +1 -1
  240. package/docs/lookup.md +1 -1
  241. package/docs/markdown.md +1 -1
  242. package/docs/menus-api.md +1 -1
  243. package/docs/menus-context.md +1 -1
  244. package/docs/menus-customization.md +1 -1
  245. package/docs/menus-merging.md +1 -1
  246. package/docs/menus-programmatic.md +1 -1
  247. package/docs/menus.md +1 -1
  248. package/docs/multiview.md +1 -1
  249. package/docs/navigation.md +1 -1
  250. package/docs/numberbox.md +1 -1
  251. package/docs/otpinput.md +1 -1
  252. package/docs/pagination.md +1 -1
  253. package/docs/pivotgrid-api.md +1 -1
  254. package/docs/pivotgrid-chart.md +1 -1
  255. package/docs/pivotgrid-drilldown.md +1 -1
  256. package/docs/pivotgrid-export.md +1 -1
  257. package/docs/pivotgrid-fields.md +1 -1
  258. package/docs/pivotgrid-keyboard.md +1 -1
  259. package/docs/pivotgrid-layout.md +1 -1
  260. package/docs/pivotgrid-panel.md +1 -1
  261. package/docs/pivotgrid-remote.md +122 -44
  262. package/docs/pivotgrid-sorting.md +3 -3
  263. package/docs/pivotgrid-state.md +1 -1
  264. package/docs/pivotgrid-summaries.md +1 -1
  265. package/docs/pivotgrid.md +1 -1
  266. package/docs/popover.md +1 -1
  267. package/docs/progress.md +1 -1
  268. package/docs/qrcode.md +1 -1
  269. package/docs/radiogroup.md +1 -1
  270. package/docs/rating.md +1 -1
  271. package/docs/resizable.md +1 -1
  272. package/docs/ribbonmenu-api.md +1 -1
  273. package/docs/ribbonmenu-commands.md +1 -1
  274. package/docs/ribbonmenu-customization.md +1 -1
  275. package/docs/ribbonmenu-display.md +1 -1
  276. package/docs/ribbonmenu-layouts.md +1 -1
  277. package/docs/ribbonmenu-programmatic.md +1 -1
  278. package/docs/ribbonmenu.md +1 -1
  279. package/docs/scheduler-agenda.md +1 -1
  280. package/docs/scheduler-big-data.md +1 -1
  281. package/docs/scheduler-editing.md +1 -1
  282. package/docs/scheduler-form.md +1 -1
  283. package/docs/scheduler-icalendar.md +1 -1
  284. package/docs/scheduler-mobile.md +1 -1
  285. package/docs/scheduler-recurrence.md +1 -1
  286. package/docs/scheduler-resources.md +1 -1
  287. package/docs/scheduler-timeline.md +1 -1
  288. package/docs/scheduler.md +1 -1
  289. package/docs/scrollview.md +1 -1
  290. package/docs/shortcuteditor.md +1 -1
  291. package/docs/showcase-flowstudio.md +61 -0
  292. package/docs/showcase-home.md +1 -1
  293. package/docs/showcase-mail.md +1 -1
  294. package/docs/showcase.md +1 -1
  295. package/docs/signature.md +1 -1
  296. package/docs/skeleton.md +1 -1
  297. package/docs/slider.md +1 -1
  298. package/docs/sortable.md +1 -1
  299. package/docs/sparkline.md +1 -1
  300. package/docs/speeddial.md +1 -1
  301. package/docs/splitter.md +1 -1
  302. package/docs/stepper.md +1 -1
  303. package/docs/switch.md +1 -1
  304. package/docs/tabdocs-dock.md +1 -1
  305. package/docs/tabdocs-drag.md +1 -1
  306. package/docs/tabdocs-menus.md +1 -1
  307. package/docs/tabdocs-mobile.md +1 -1
  308. package/docs/tabdocs-tabs.md +1 -1
  309. package/docs/tabdocs-windows.md +1 -1
  310. package/docs/tabdocs-workspace.md +1 -1
  311. package/docs/tabdocs.md +1 -1
  312. package/docs/tabs.md +1 -1
  313. package/docs/tagbox.md +1 -1
  314. package/docs/textarea.md +1 -1
  315. package/docs/textbox.md +1 -1
  316. package/docs/tileview.md +1 -1
  317. package/docs/timeline.md +1 -1
  318. package/docs/toast.md +1 -1
  319. package/docs/tokens.md +324 -1
  320. package/docs/toolbar-api.md +1 -1
  321. package/docs/toolbar-customization.md +1 -1
  322. package/docs/toolbar.md +1 -1
  323. package/docs/tooltip.md +1 -1
  324. package/docs/treeview.md +1 -1
  325. package/docs/validationsummary.md +1 -1
  326. package/docs/window.md +1 -1
  327. package/docs/wizard.md +1 -1
  328. package/llms-full.txt +10142 -462
  329. package/llms.txt +32 -1
  330. package/package.json +2 -2
@@ -0,0 +1,491 @@
1
+ # Data layer: Custom adapters and API reference
2
+
3
+ > Data layer · @motifx-community/data 0.1.0-beta.3
4
+
5
+ Every adapter of the data layer extends `DataAdapter<T, K>` and serves one contract: the same loads, writes, events and errors over any backend. This page shows how to write an adapter of your own and lists the reference of the shared contract: the members of `DataAdapter`, its options, its capabilities, its events, its error codes and the memory helpers behind them. The [`DataSource`](datalayer-source.md#api) and [`ChangeTracker`](datalayer-changes.md#api) references are on their own pages.
6
+
7
+ ## Writing an adapter
8
+
9
+ An adapter of your own extends `DataAdapter<T, K>` and implements three things: `backendCapabilities`, which declares what the backend does itself; `loadRows`, which asks the backend for rows; and the writes the backend supports: `insertRow`, `updateRow`, `removeRow` and, where one request carries several changes, `saveBatch`. The base class does the rest. It checks the options and rejects invalid ones with `MJD302`, splits every load into the part the backend runs and the part that runs in memory, fires the [events](#events) around every operation, reads and compares keys as the `key` option declares them, turns every failure into a [`DataError`](#errors), and provides [`push`](#push) and [`save`](#save) to every subclass.
10
+
11
+ `loadRows` receives only what the declared capabilities let the backend apply; the base class runs the remaining options in memory on the rows it returns, with the adapter's `locale`, its declared `fields` and the per-field rules of the [options](#options). Filtering, sorting, grouping or summarizing in memory needs every matching row, so paging and counting move to memory along with it; [Capabilities](#capabilities) lists the rules.
12
+
13
+ The writes share one contract. `insertRow` receives the object given to `insert` itself: send it, and store it as it is when the backend keeps objects. Each write resolves to the backend's answer, or to nothing: an answer that holds every sent field counts as the saved row, and a smaller one, such as a new key or a version, is written onto what was sent. A write whose capability is off is rejected with `MJD301` before the method is called, so an adapter implements only what its backend supports.
14
+
15
+ | Member | Description |
16
+ | --- | --- |
17
+ | `backendCapabilities(): Capabilities` | Abstract. What the backend does itself; the `capabilities` option can only turn parts of it off. See [Capabilities](#capabilities). |
18
+ | `loadRows(options: LoadOptions): Promise<LoadResult<T>>` | Abstract. Asks the backend for rows. It receives only the options the capabilities cover; the base class applies the rest in memory to the rows it returns. With `count` among them, the result must carry `total`; an answer without a `rows` array rejects with `MJD104`. |
19
+ | `countRows(options: LoadOptions): Promise<number>` | The number of matching rows, for `count`. The default loads with `take: 0` and `count: true` and reads the result's `total`; override it where the backend counts more cheaply. |
20
+ | `findRow(key: K, options: ByKeyOptions): Promise<T \| undefined>` | The row of a key, for `byKey`. The default writes the key as a filter and loads one row; a function key loads the rows and scans them. Override it where the backend reads by key directly. |
21
+ | `insertRow(values: Partial<T>, options: OperationOptions): Promise<Partial<T> \| void>` | Saves a new row. `values` is the object given to `insert` itself: send it, and store it as it is when the backend keeps objects. Resolve to the backend's answer or to nothing. The default rejects with `MJD301`. |
22
+ | `updateRow(key: K, changes: Partial<T>, options: WriteOptions<T>): Promise<Partial<T> \| void>` | Saves changed fields. Resolve to the backend's answer or to nothing; `options.original` is the row as it was read, where the caller gave it. The default rejects with `MJD301`. |
23
+ | `removeRow(key: K, options: WriteOptions<T>): Promise<void>` | Deletes the row of a key. The default rejects with `MJD301`. |
24
+ | `saveBatch?(changes: readonly Change<T, K>[], options: OperationOptions): Promise<BatchResult<T>[]>` | Optional, for a backend that takes several changes in one request (OData `$batch`, one SOAP call). When it is declared, [`save`](#save) sends two or more changes through it. Resolve to one `BatchResult<T>` per change, in order: `{ ok: true, row? }` as the single writes resolve, or `{ ok: false, error }`; a missing result counts as a failure. |
25
+ | `rowsReplaced(): void` | Call it when the backend replaced the rows as a whole: `onChanged` fires with `source: 'replace'` and empty `changes`, and every data source over the adapter loads its rows again. |
26
+ | `applyPushedChanges(changes: readonly PushedChange<T, K>[]): void` | Called by [`push`](#push) before `onChanged` fires. An adapter that holds rows of its own applies the pushed changes to them here; the default does nothing. |
27
+ | `pivotRemotely(options: PivotLoadOptions<T>): boolean` | Whether the backend can compute this pivot: `false` when a level, a `keep` entry or a measure reads a value of its own, or a measure is `custom`; those need the rows in memory. Override it where the backend has further limits. |
28
+ | `loadPivotGroups(options: PivotLoadOptions<T>): Promise<unknown>` | For `capabilities.pivot`: the groups of the options, as the backend sends them (`PivotGroup`). The default rejects with `MJD301`. |
29
+ | `loadPivotMemberSlices(options: PivotMembersOptions<T>): Promise<unknown>` | For `capabilities.pivotWindow`: the members of the options, as `{ slices: [{ total, members }] }`. |
30
+ | `loadPivotChildCounts(options: PivotCountsOptions<T>): Promise<unknown>` | For `capabilities.pivotWindow`: the counts of the options, as `{ counts: [{ path, count }] }`. |
31
+ | `loadPivotBlockCounts(options: PivotBlocksOptions<T>): Promise<unknown>` | For `capabilities.pivotWindow` with `pivotBlocks`: the blocks of the options, as `{ blocks: [{ total, counts }] }`. |
32
+ | `loadPivotCellGroups(options: PivotCellsOptions<T>): Promise<unknown>` | For `capabilities.pivotWindow`: the groups of the crossings asked for (`PivotGroup`). |
33
+
34
+ A backend that computes pivots declares `capabilities.pivot` and overrides `loadPivotGroups`; one that also computes the parts a view loads as it scrolls declares `pivotWindow` and overrides the other pivot hooks. [Pivots and loading in parts](datalayer-pivot.md) explains the options and what a server answers.
35
+
36
+ ### Over HTTP
37
+
38
+ For an HTTP backend, extend `HttpAdapter` instead: it adds the shared [HTTP options](datalayer-rest.md#requests) and the `onRequesting` and `onResponded` events, and every request goes through its protected `send`. The REST, OData and SOAP adapters are written on top of it.
39
+
40
+ | Member | Description |
41
+ | --- | --- |
42
+ | `http: Readonly<HttpAdapterOptions<T>>` | The options as given. The shared options (`fetch`, `headers`, `beforeSend`, `afterReceive`, `timeoutMs`, `retry`, `resilience`, `readError`, `errorTextLength`, `credentials`) are listed on the [REST page](datalayer-rest.md#requests). |
43
+ | `send(init: HttpRequestInit): Promise<HttpResponse>` | Sends one request. `init` names the `operation`, `method`, `url`, `query`, `headers`, `data` (sent as JSON unless `body` is set) and `signal`. The request passes through `onRequesting` and `beforeSend`, which may change or cancel it, and through the retry or resilience policy. The answer resolves with its body read; an error status rejects with the `DataError` of `readError`, a timeout with `MJD102`. |
44
+ | `readError(response: HttpResponse): DataError` | The error of an answer whose status is outside 200 to 299. The default reads the body with `readErrorBody` and maps the status with `errorForStatus` (see [Errors](#errors)); the `readError` option, where it returns an error, takes precedence. Override it for a backend with an error format of its own. |
45
+ | `readBody(raw: Response, request: HttpRequest): Promise<unknown>` | Reads an answer's body: `null` for status 204 or 205 and for an empty body, parsed JSON for a JSON content type (`MJD104` when it does not parse), the text for everything else. |
46
+
47
+ The example below stores rows of tasks in the browser's `localStorage`, as JSON under one key. The store neither filters nor sorts, so `backendCapabilities` declares everything but the writes off, and `loadRows` returns every row: the search of the list is a filter the base class runs in memory. The writes read the stored array, change it and write it back; `insertRow` assigns the next key, and a key that is not stored rejects with `MJD204`. The store lives in this page, and the rows survive a reload of it.
48
+
49
+ ```tsx
50
+ import { data } from '@motifx-community/data';
51
+
52
+ export interface Task {
53
+ id: number;
54
+ title: string;
55
+ done: boolean;
56
+ }
57
+
58
+ const KEY = 'docs-datalayer-tasks';
59
+
60
+ const SEED: Task[] = [
61
+ { id: 1, title: 'Confirm the venue', done: true },
62
+ { id: 2, title: 'Print the badges', done: false },
63
+ { id: 3, title: 'Order lunch for the workshop', done: false },
64
+ { id: 4, title: 'Send the invitations', done: true },
65
+ { id: 5, title: 'Review the schedule', done: false },
66
+ ];
67
+
68
+ /**
69
+ * Tasks in the browser's localStorage, kept as JSON under one key. The store itself neither filters
70
+ * nor sorts: the capabilities declare only the writes, and the base class runs every query in memory.
71
+ */
72
+ export class TaskStore extends data.DataAdapter<Task, number> {
73
+ constructor() {
74
+ super({ key: 'id', fields: { title: 'string', done: 'boolean' } });
75
+ if (!localStorage.getItem(KEY)) this.write(SEED);
76
+ }
77
+
78
+ protected backendCapabilities(): data.Capabilities {
79
+ return { filter: false, sort: false, paging: false, count: false, select: false, group: false, summary: false, insert: true, update: true, remove: true };
80
+ }
81
+
82
+ protected loadRows(): Promise<data.LoadResult<Task>> {
83
+ return Promise.resolve({ rows: this.read() });
84
+ }
85
+
86
+ // `values` is the caller's object; the stored row carries the next free key.
87
+ protected override insertRow(values: Partial<Task>): Promise<Partial<Task>> {
88
+ const rows = this.read();
89
+ const row: Task = { title: '', done: false, ...values, id: rows.reduce((top, r) => Math.max(top, r.id), 0) + 1 };
90
+ this.write([...rows, row]);
91
+ return Promise.resolve(row);
92
+ }
93
+
94
+ protected override updateRow(key: number, changes: Partial<Task>): Promise<Partial<Task>> {
95
+ const rows = this.read();
96
+ const at = rows.findIndex((r) => r.id === key);
97
+ if (at < 0) return Promise.reject(data.DataError.create('MJD204', { operation: 'update' }));
98
+ rows[at] = { ...rows[at], ...changes, id: key };
99
+ this.write(rows);
100
+ return Promise.resolve(rows[at]);
101
+ }
102
+
103
+ protected override removeRow(key: number): Promise<void> {
104
+ const rows = this.read();
105
+ const at = rows.findIndex((r) => r.id === key);
106
+ if (at < 0) return Promise.reject(data.DataError.create('MJD204', { operation: 'remove' }));
107
+ rows.splice(at, 1);
108
+ this.write(rows);
109
+ return Promise.resolve();
110
+ }
111
+
112
+ private read(): Task[] {
113
+ try {
114
+ return JSON.parse(localStorage.getItem(KEY) ?? '[]') as Task[];
115
+ } catch {
116
+ return [];
117
+ }
118
+ }
119
+
120
+ private write(rows: Task[]) {
121
+ localStorage.setItem(KEY, JSON.stringify(rows));
122
+ }
123
+ }
124
+ ```
125
+
126
+ ## The shared contract
127
+
128
+ `DataAdapter<T, K>` types the row as `T` and the key as `K`. A failed operation rejects with a [`DataError`](#errors) and reports it through `onError`; `save` resolves instead and carries each failure in its outcome. A cancellation, through a `signal` or an event listener's `cancel`, rejects with an error of kind `'abort'` and is not reported.
129
+
130
+ | Member | Returns | Description |
131
+ | --- | --- | --- |
132
+ | `load(options?)` | `Promise<LoadResult<T>>` | Loads rows with `LoadOptions`: `filter`, `sort`, `skip`, `take`, `count`, `select`, `expand`, `group`, `groupSummary`, `groupsOnly`, `summary`, `params` and `signal`; [Filtering, sorting and grouping](datalayer-queries.md) explains them. The result holds `rows` and, as asked, `total`, `groups`, `groupCount` and `summary`. |
133
+ | `count(options?)` | `Promise<number>` | The number of rows the filter passes. The options take `filter`, `params` and `signal` only. |
134
+ | `byKey(key, options?)` | `Promise<T \| undefined>` | The row of a key, or `undefined` when there is none. The options add `select` and `expand` to `params` and `signal`. Needs the `key` option. |
135
+ | `insert(values, options?)` | `Promise<T>` | Saves a new row. Resolves to the saved row: the backend's own object when its answer holds every sent field, or the given object itself with the backend's fields, such as a new key, written onto it. |
136
+ | `update(key, changes, options?)` | `Promise<Partial<T>>` | Saves changed fields. Resolves to them as they were saved, with what the backend returned merged in. The options may carry `original`, the row as it was read, for a backend that detects changes made elsewhere. |
137
+ | `remove(key, options?)` | `Promise<void>` | Deletes the row of a key. |
138
+ | `save(changes, options?)` | `Promise<SaveOutcome<T, K>[]>` | Saves several changes, with one outcome per change; see [Saving many changes](#save). |
139
+ | `push(changes)` | `void` | Announces changes made elsewhere; see [Changes from elsewhere](#push). |
140
+ | `canFilter(filter)` | `boolean` | Whether the backend applies this filter. For one it cannot write, the caller loads the rows without it and filters them in memory; the OData adapter, for example, answers `false` for a condition its protocol cannot express. |
141
+ | `loadPivot(options?)` | `Promise<PivotLoadResult>` | The members and measures of a pivot, totals included; see [Pivots and loading in parts](datalayer-pivot.md). |
142
+ | `loadPivotMembers(options)` | `Promise<PivotMembersResult>` | Members of one level of a pivot axis, a part of each parent's children at a time, for a view that loads as it scrolls. |
143
+ | `loadPivotCounts(options)` | `Promise<PivotCountsResult>` | The number of children of members of a pivot axis. |
144
+ | `loadPivotBlocks(options)` | `Promise<PivotBlocksResult>` | How many members stand below the children of members, a block of children at a time. |
145
+ | `loadPivotCells(options)` | `Promise<PivotCellsResult>` | The measures where row members and column members cross; running totals a backend does not give are added up by the adapter. |
146
+ | `computesPivot(options)` | `boolean` | Whether the backend computes this pivot itself: `capabilities.pivot`, and nothing in the options that needs memory. |
147
+ | `capabilities` | `Capabilities` | What the backend does itself, minus what the `capabilities` option turned off; see [Capabilities](#capabilities). |
148
+ | `keys` | `RowKeys<T>` | Reads and compares row keys as the `key` option declares them; see [Row keys](#options). |
149
+ | `keyOf(row)` | `K` | The key of a row. Needs the `key` option. |
150
+ | `sameKey(a, b)` | `boolean` | Whether two keys name the same row; dates count by their moment, composite keys field by field. |
151
+ | `keyString(key)` | `string` | Equal strings for equal keys, for maps and sets. |
152
+ | `fields` | `Readonly<Record<string, FieldType>>` | The declared field types, as the options gave them. |
153
+ | `locale` | `string \| undefined` | The locale text comparisons in memory use. |
154
+ | `evaluateContext` | `EvaluateContext` | How memory reads, compares and sorts this adapter's rows: the fields, the locale and the per-field rules, ready for the [helpers](#helpers). |
155
+ | `onLoading … onError` | events | The ten events of the adapter; see [Events](#events). |
156
+ | `dispose()` | `void` | Releases the adapter's event emitters. |
157
+
158
+ ## Options
159
+
160
+ `DataAdapterOptions<T>` is the base of every adapter's options; each adapter adds the options of its backend on top ([REST](datalayer-rest.md#requests), [OData](datalayer-odata.md), [SOAP](datalayer-soap.md)).
161
+
162
+ | Option | Default | Description |
163
+ | --- | --- | --- |
164
+ | `key` | None | The row key (`KeyExpr<T>`): a field (`'id'`), several fields (the key is then an object of them, `{ orderId: 7, line: 2 }`), or a function of the row. Without it, `byKey`, `update`, `remove` and `keyOf` reject with `MJD303`; `insert` works, and the key of its outcome stays `undefined`. |
165
+ | `fields` | `{}` | The type of each field (`FieldType`: `'string'`, `'number'`, `'boolean'`, `'date'`, `'datetime'` or `'guid'`), where comparisons need one; a field without a declared type takes the type of the value it meets. `'date'` compares by calendar day, `'guid'` without case. |
166
+ | `locale` | The runtime's locale | The locale memory compares text in, without case; with `'tr'`, the dotted and the dotless i are told apart. |
167
+ | `capabilities` | `{}` | Turns off what an endpoint cannot do (`{ filter: false }`); that part then runs in memory. It only turns off: a capability the backend does not declare cannot be turned on. See [Capabilities](#capabilities). |
168
+ | `sortValue` | None | Sorting in memory reads the field with the returned function instead (a computed value); return `undefined` for the field's own value. |
169
+ | `filterValue` | None | Filtering in memory reads the field with the returned function instead (a computed value); return `undefined` for the field's own value. |
170
+ | `compare` | None | Sorting in memory compares the field's values with the returned function instead of the type rules; empty values still go last. |
171
+
172
+ ### Row keys
173
+
174
+ The adapter's `keys`, a `RowKeys<T>`, reads and compares keys as the `key` option declares them; code that handles keys of any shape, such as a cache over an adapter, uses it instead of reading fields itself. A composite key is an object of its fields. A function key has no fields, so it cannot be written as a filter; `byKey` then loads the rows and scans them.
175
+
176
+ | Member | Returns | Description |
177
+ | --- | --- | --- |
178
+ | `expr` | `KeyExpr<T> \| undefined` | The key as given: a field, several fields, or a function of the row. |
179
+ | `fields` | `readonly string[] \| null` | The key fields; `null` for a function key. |
180
+ | `isSet` | `boolean` | Whether a key is declared. |
181
+ | `isComposite` | `boolean` | Whether the key has more than one field. |
182
+ | `keyOf(row)` | `unknown` | The key of a row; a composite key is an object of its fields. |
183
+ | `hasKey(row)` | `boolean` | Whether the row has a complete key: no field of it `null`, `undefined` or empty text. For a function key, whether it gives a value. |
184
+ | `sameKey(a, b)` | `boolean` | Whether two keys are equal: dates by their moment, composite keys field by field, everything else by value. |
185
+ | `keyString(key)` | `string` | Equal strings for equal keys, for use in maps and sets. |
186
+ | `keyFilter(key)` | `FilterExpression \| null` | The key written as a filter; `null` for a function key, which has no field to filter on. |
187
+
188
+ ## Capabilities
189
+
190
+ `Capabilities` names what a backend does itself. The adapter's `capabilities` property is what `backendCapabilities()` declares, minus what the `capabilities` option turned off; whatever is off runs in memory on the rows `loadRows` returns. Only the writes have no memory side: a write whose capability is off rejects with `MJD301`.
191
+
192
+ Work that runs in memory moves together. Filtering, sorting, grouping or summarizing in memory needs every matching row, so paging and counting move to memory with them; a filter that runs in memory takes grouping and summaries along, since they would otherwise count rows the filter drops; and a field selection runs in memory whenever the memory work needs fields it would drop.
193
+
194
+ | Capability | Description |
195
+ | --- | --- |
196
+ | `filter` | The backend applies `filter`. Off, the rows are loaded without it and every matching row is filtered in memory; grouping, summaries, paging and counting move to memory with it. |
197
+ | `sort` | The backend applies `sort`. Off, the rows are sorted in memory, which needs every matching row. |
198
+ | `paging` | The backend applies `skip` and `take`. Off, the page is cut in memory from all the rows. |
199
+ | `count` | The backend returns `total` when `count` is set. Off, the matching rows are counted in memory. |
200
+ | `select` | The backend returns only the `select` fields. Off, the fields are picked in memory; memory work that needs other fields also moves the selection there. |
201
+ | `group` | The backend groups (`group`, `groupSummary`, `groupsOnly`). Off, the rows are grouped in memory; groups and summaries go together: when one runs in memory, both do. |
202
+ | `summary` | The backend computes `summary`. Off, the summaries are computed in memory over every matching row. |
203
+ | `pivot` | The backend computes pivots: `loadPivot` asks it through `loadPivotGroups`. Off or missing, the matching rows are loaded and grouped in memory. A pivot that needs memory anyway, such as one with a computed value or a custom measure, is grouped in memory either way. |
204
+ | `pivotWindow` | The backend computes the parts of a pivot (`loadPivotMembers`, `loadPivotCounts`, `loadPivotCells`). Off or missing, the rows are loaded and the parts are computed in memory. |
205
+ | `pivotBlocks` | With `pivotWindow`: the backend counts what stands below members (`loadPivotBlocks`, and `descendants` of `loadPivotMembers`) without reading every one. Off or missing, the counts are computed in memory. |
206
+ | `insert` | The backend inserts rows. Off, `insert` and an insert inside `save` reject with `MJD301`. |
207
+ | `update` | The backend updates rows. Off, `update` and an update inside `save` reject with `MJD301`. |
208
+ | `remove` | The backend deletes rows. Off, `remove` and a remove inside `save` reject with `MJD301`. |
209
+
210
+ ## Events
211
+
212
+ The events are `@motifx/core` events: subscribing returns an `IDisposable`, which a component registers with `this.motif.register` so that the subscription ends with the component. The `…ing` events occur before the backend is called; a listener may change what is sent, or set `cancel` to `true`, which rejects the operation with `MJD106`. The `…ed` events occur after the backend answered.
213
+
214
+ ```tsx
215
+ const stop = orders.onUpdating((e) => {
216
+ if ((e.changes.amount ?? 0) < 0) e.cancel = true; // the update rejects with MJD106
217
+ });
218
+ // later:
219
+ stop.dispose();
220
+ ```
221
+
222
+ | Event | Argument | Description |
223
+ | --- | --- | --- |
224
+ | `onLoading` | `{ cancel, options }` | Occurs when `load` begins, before the backend is asked. Listeners may change `options` or set `cancel`. |
225
+ | `onLoaded` | `{ options, result }` | Occurs when `load` resolves, with the checked options and the result. |
226
+ | `onInserting` | `{ cancel, values }` | Occurs before an insert is sent, from `insert` and from `save`. `values` is the object given to `insert` itself; listeners may change it or set `cancel`. |
227
+ | `onInserted` | `{ values, key, row }` | Occurs when an insert was saved: the sent values, the new key and the saved row. |
228
+ | `onUpdating` | `{ cancel, key, changes }` | Occurs before an update is sent, from `update` and from `save`. Listeners may change `changes` or set `cancel`. |
229
+ | `onUpdated` | `{ key, changes, row }` | Occurs when an update was saved; `row` is what `update` resolves to. |
230
+ | `onRemoving` | `{ cancel, key }` | Occurs before a remove is sent, from `remove` and from `save`. |
231
+ | `onRemoved` | `{ key }` | Occurs when a remove was saved. |
232
+ | `onChanged` | `{ changes, source }` | Occurs when rows changed: saved through the adapter (`source: 'write'`; `save` fires it once with every saved change), pushed from elsewhere (`'push'`), or replaced as a whole (`'replace'`, with empty `changes`). `changes` is a list of `PushedChange`. Every data source over the adapter follows this event. |
233
+ | `onError` | `{ error }` | Occurs when an operation fails, with its `DataError`. Cancellations (kind `'abort'`) are not reported. |
234
+
235
+ ## Errors
236
+
237
+ Every operation fails with a `DataError`, a core `MotifError` whose message carries a prefix, as in `[motifjs-data] MJD103: The backend answered 500.`. The `code` is stable; `kind` is the category a handler reacts to.
238
+
239
+ | Member | Type | Description |
240
+ | --- | --- | --- |
241
+ | `code` | `DataErrorCode` | The stable code, `MJD101` to `MJD305`. |
242
+ | `kind` | `DataErrorKind` | The category a handler reacts to: `'network'`, `'timeout'`, `'held'`, `'http'`, `'parse'`, `'abort'`, `'server'`, `'validation'`, `'conflict'`, `'not-found'`, `'unsupported'`, `'invalid'` or `'key'`. |
243
+ | `operation` | `DataOperation` | What failed: `'load'`, `'count'`, `'byKey'`, `'insert'`, `'update'`, `'remove'` or `'save'`. |
244
+ | `plainMessage` | `string` | The message without the `[motifjs-data] MJD…:` prefix, ready to show to a user. |
245
+ | `status` | `number \| undefined` | The HTTP status, where there is one. |
246
+ | `fields` | `Readonly<Record<string, string>> \| undefined` | The backend's messages by field, as `readErrorBody` found them. |
247
+ | `details` | `unknown` | The backend's answer body, or whatever else the failure carries. |
248
+ | `cause` | `unknown` | The original error, where one was wrapped. |
249
+
250
+ | Function | Description |
251
+ | --- | --- |
252
+ | `DataError.create(code, options, ...args)` | A new error of a code. `options` carries `operation` and, as needed, `message` (the backend's own message, used instead of the code's text), `status`, `fields`, `details` and `cause`; `args` fill the code's text. |
253
+ | `DataError.from(error, operation)` | Wraps anything thrown into a `DataError`: a `DataError` stays itself, a cancellation becomes `MJD105`, a failure of a core resilience policy `MJD102` or `MJD107` to `MJD109`, a network failure of `fetch` `MJD101`, and anything else `MJD201` with its message. |
254
+ | `isAbortError(error)` | Whether a failure is a cancellation: a `DataError` of kind `'abort'`, or any error named `AbortError`. |
255
+
256
+ The exported `DATA_ERRORS` constant maps every code to its kind and its English text, so an application can provide texts of its own by code. The codes:
257
+
258
+ | Code | Kind | Meaning |
259
+ | --- | --- | --- |
260
+ | `MJD101` | `network` | The backend could not be reached. |
261
+ | `MJD102` | `timeout` | No answer within the time limit (`timeoutMs`, or a timeout policy of the core). |
262
+ | `MJD103` | `http` | The backend answered an error status no more specific code covers; `status` holds it. |
263
+ | `MJD104` | `parse` | The answer could not be read: no `rows` array, a missing total, a body that is not valid JSON, a pivot answer of the wrong shape, or a batch answer without a result for a change. |
264
+ | `MJD105` | `abort` | The request was cancelled through its `signal`. |
265
+ | `MJD106` | `abort` | Cancelled by a listener of an `…ing` event, or by `beforeSend`. |
266
+ | `MJD107` | `held` | Not sent: the backend failed repeatedly, and a circuit-breaker policy pauses requests for a while. |
267
+ | `MJD108` | `held` | Not sent: too many requests are waiting (a bulkhead policy). |
268
+ | `MJD109` | `held` | Not sent: the request rate limit is reached. |
269
+ | `MJD201` | `server` | The backend reported an error; the message is the backend's where it sent one. |
270
+ | `MJD202` | `validation` | The backend rejected the values: HTTP status 400 or 422 with a message; `fields` holds the messages by field. |
271
+ | `MJD203` | `conflict` | A row with this key exists; HTTP status 409. |
272
+ | `MJD204` | `not-found` | No row with this key; HTTP status 404 on `byKey`, `update` or `remove`. |
273
+ | `MJD205` | `conflict` | The row was changed elsewhere since it was read; HTTP status 412. |
274
+ | `MJD301` | `unsupported` | This adapter cannot do this: a write whose capability is off, or a pivot hook the backend does not have. |
275
+ | `MJD302` | `invalid` | Invalid options: a negative `skip` or `take`, a filter that does not validate, or a malformed sort, group, summary or pivot item. |
276
+ | `MJD303` | `key` | The operation needs the `key` option. |
277
+ | `MJD304` | `key` | The new row has no key, and the adapter cannot assign one (the `ArrayAdapter` without `createKey`). |
278
+ | `MJD305` | `invalid` | The backend needs the row as it was read (`original` of `WriteOptions`) to save this change; HTTP status 428. |
279
+
280
+ ### Reading HTTP answers
281
+
282
+ Three exported functions turn HTTP answers into these errors; the HTTP adapters use them, and a custom `readError` can too.
283
+
284
+ | Function | Description |
285
+ | --- | --- |
286
+ | `errorForStatus(response, message, fields?)` | The `DataError` of an HTTP error answer: status 400 and 422 with a message or field messages become `MJD202`, 404 on `byKey`, `update` or `remove` `MJD204`, 409 `MJD203`, 412 `MJD205`, 428 `MJD305`, and everything else `MJD103` with the status. |
287
+ | `isTransientError(error)` | Whether a failure is worth retrying: no answer, a timeout, or status 408, 429 or 5xx. The default `retry` of the HTTP adapters retries only these. |
288
+ | `readErrorBody(body, textLength?)` | The message and the field messages of an error body: it reads `message`, `error`, `error.message` or `title`, and messages by field from `errors` as an object or from `error.details` as `[{ target, message }]`. A plain-text body becomes the message, cut after `textLength` characters (300 by default). |
289
+
290
+ ## Changes from elsewhere
291
+
292
+ `push(changes)` announces changes the adapter did not make: another user's save arriving over a live connection, a server event. The adapter applies them to rows it holds itself, where it holds any (`applyPushedChanges`), and fires `onChanged` with `source: 'push'`; every data source over the adapter applies them to its loaded rows. A `PushedChange` names one change:
293
+
294
+ | Member | Description |
295
+ | --- | --- |
296
+ | `type` | `'insert'`, `'update'` or `'remove'`. |
297
+ | `key` | The key of the changed row. |
298
+ | `data` | The row for an insert, the changed fields for an update; a remove carries none. |
299
+
300
+ ```tsx
301
+ // A live connection reports another user's save:
302
+ orders.push([
303
+ { type: 'update', key: 12, data: { status: 'shipped' } },
304
+ { type: 'remove', key: 31 },
305
+ ]);
306
+ ```
307
+
308
+ ## Saving many changes
309
+
310
+ `save(changes)` sends several changes and resolves to one `SaveOutcome` per change, in the order given; a failed change does not stop the others, and nothing is rolled back. The `…ing` event of each change fires first, and a cancelled or unsupported change becomes a failed outcome without being sent. Two or more remaining changes go through `saveBatch` where the adapter declares one; otherwise, and for a single change, they are sent one by one. After the answers, the `…ed` events fire per saved change, and `onChanged` fires once with all of them. [`ChangeTracker`](datalayer-changes.md) collects edits over a data source and saves them this way.
311
+
312
+ ```tsx
313
+ const outcomes = await orders.save([
314
+ { type: 'insert', data: { customer: 'Elif Demir', amount: 3 } },
315
+ { type: 'update', key: 12, data: { amount: 5 } },
316
+ { type: 'remove', key: 31 },
317
+ ]);
318
+ const failed = outcomes.filter((o) => !o.ok);
319
+ ```
320
+
321
+ | Change | Description |
322
+ | --- | --- |
323
+ | `{ type: 'insert', data }` | A new row; `data` is handed to the backend as `insert` hands it. |
324
+ | `{ type: 'update', key, data, original? }` | Changed fields of a row; `original` is the row as it was read (see `WriteOptions`). |
325
+ | `{ type: 'remove', key, original? }` | A row to delete. |
326
+
327
+ | Outcome | Description |
328
+ | --- | --- |
329
+ | `{ change, ok: true, key, row? }` | The change was saved: `key` is the new key of an insert, or the key of the update or remove, and `row` is what `insert` or `update` resolves to. A remove has no `row`. |
330
+ | `{ change, ok: false, error }` | The change failed, with its `DataError`. The other changes are still sent. |
331
+
332
+ ## Helpers for code of your own
333
+
334
+ The memory engine behind the fallback is exported, so code of your own, such as an in-page service of these docs or a test double, computes the same answers the adapters do. Every function takes an `EvaluateContext`, the adapter's `evaluateContext` or one you build, for field types, the locale and computed values. The pivot engine's own functions, `queryPivot`, `pivotGroups`, `pivotMembers` and the rest, are on [the pivot page](datalayer-pivot.md).
335
+
336
+ | Function | Description |
337
+ | --- | --- |
338
+ | `queryArray(rows, options?, ctx?)` | Runs `LoadOptions` on rows in memory: filter, sort, group, count, page, select and summaries, exactly as the fallback runs them. Without `select`, the result's rows are the given objects. |
339
+ | `pickFields(row, fields)` | A new row holding only the named fields. |
340
+ | `createRowFilter(filter, ctx?)` | A function that tests a row against a filter expression; a field without a declared type takes the type of the value. |
341
+ | `validateFilter(filter)` | Throws a `TypeError` where the value is not a valid filter expression; afterwards the type is narrowed to `FilterExpression`. |
342
+ | `fieldsInFilter(filter)` | The set of field names a filter expression reads. |
343
+ | `groupOrder(group, sort)` | The sort order grouping needs: the group fields first, then `sort`. |
344
+ | `groupContext(group, ctx)` | The context rows are put in group order with; it honors the `groupValue` and `groupCompare` rules of the context. |
345
+ | `groupRows(rows, group, summary, ctx?, withItems?)` | Groups rows that are already in group order into `RowGroup` levels; values group the way filters compare them, and empty values form one group with the key `null`. With `withItems: false`, the groups hold only their counts. |
346
+ | `rowsOfGroups(groups)` | The rows of the deepest level, in group order. |
347
+ | `summarize(rows, items, ctx?)` | The summary values of rows, in the order of the items. An empty set gives `0` for `count`, `countDistinct` and `sum`, and `null` for the others. |
348
+ | `SummaryRule` | How one summary item is computed: `value(row)` reads the value, and `start()` gives an accumulator (`add`, `result`) for one set of rows, for computing group summaries incrementally. |
349
+
350
+ ## Feedback
351
+
352
+ Loading issues…
353
+
354
+ ## Example files
355
+
356
+ `Tasks.tsx`
357
+
358
+ ```tsx
359
+ import { reactive } from '@motifx/core';
360
+ import { data } from '@motifx-community/data';
361
+ import { Button, ListBox, Stack, TextBox } from '@motifx-community/ui';
362
+ import { TaskStore, type Task } from './task-store';
363
+
364
+ /** A list over the custom adapter: writes go to the browser's storage, the search runs in memory. */
365
+ export default function Tasks() {
366
+ const form = reactive({ title: '', selected: null as number | null, open: 0 });
367
+ const store = new TaskStore();
368
+ const tasks = new data.DataSource<Task, number>({
369
+ adapter: store,
370
+ loadMode: 'all',
371
+ sort: [{ field: 'title', dir: 'asc' }],
372
+ searchFields: ['title'],
373
+ });
374
+ tasks.onChanged(() => (form.open = tasks.rows.filter((t) => !t.done).length));
375
+
376
+ const add = () => {
377
+ const title = form.title.trim();
378
+ if (title) store.insert({ title, done: false }).then(() => (form.title = ''));
379
+ };
380
+ const toggle = () => {
381
+ const row = tasks.rows.find((t) => t.id === form.selected);
382
+ if (row) store.update(row.id, { done: !row.done });
383
+ };
384
+ const removeSelected = () => {
385
+ if (form.selected === null) return;
386
+ store.remove(form.selected).then(() => (form.selected = null));
387
+ };
388
+
389
+ return (
390
+ <>
391
+ <Stack orientation="horizontal" wrap align="end">
392
+ <TextBox label="New task" x-model={() => form.title} />
393
+ <Button text="Add" variant="outline" onclick={add} />
394
+ </Stack>
395
+ <ListBox
396
+ label="Tasks"
397
+ dataSource={tasks}
398
+ textField={(t: Task) => (t.done ? `✓ ${t.title}` : t.title)}
399
+ valueField="id"
400
+ searchEnabled
401
+ height={8}
402
+ x-model={() => form.selected}
403
+ />
404
+ <Stack orientation="horizontal" wrap align="center">
405
+ <Button text="Done / not done" variant="outline" enabled={() => form.selected !== null} onclick={toggle} />
406
+ <Button text="Delete" variant="outline" enabled={() => form.selected !== null} onclick={removeSelected} />
407
+ <output class="api-tasks-open">{() => `${form.open} open in the list`}</output>
408
+ </Stack>
409
+ </>
410
+ );
411
+ }
412
+ ```
413
+
414
+ `task-store.ts`
415
+
416
+ ```tsx
417
+ import { data } from '@motifx-community/data';
418
+
419
+ export interface Task {
420
+ id: number;
421
+ title: string;
422
+ done: boolean;
423
+ }
424
+
425
+ const KEY = 'docs-datalayer-tasks';
426
+
427
+ const SEED: Task[] = [
428
+ { id: 1, title: 'Confirm the venue', done: true },
429
+ { id: 2, title: 'Print the badges', done: false },
430
+ { id: 3, title: 'Order lunch for the workshop', done: false },
431
+ { id: 4, title: 'Send the invitations', done: true },
432
+ { id: 5, title: 'Review the schedule', done: false },
433
+ ];
434
+
435
+ /**
436
+ * Tasks in the browser's localStorage, kept as JSON under one key. The store itself neither filters
437
+ * nor sorts: the capabilities declare only the writes, and the base class runs every query in memory.
438
+ */
439
+ export class TaskStore extends data.DataAdapter<Task, number> {
440
+ constructor() {
441
+ super({ key: 'id', fields: { title: 'string', done: 'boolean' } });
442
+ if (!localStorage.getItem(KEY)) this.write(SEED);
443
+ }
444
+
445
+ protected backendCapabilities(): data.Capabilities {
446
+ return { filter: false, sort: false, paging: false, count: false, select: false, group: false, summary: false, insert: true, update: true, remove: true };
447
+ }
448
+
449
+ protected loadRows(): Promise<data.LoadResult<Task>> {
450
+ return Promise.resolve({ rows: this.read() });
451
+ }
452
+
453
+ // `values` is the caller's object; the stored row carries the next free key.
454
+ protected override insertRow(values: Partial<Task>): Promise<Partial<Task>> {
455
+ const rows = this.read();
456
+ const row: Task = { title: '', done: false, ...values, id: rows.reduce((top, r) => Math.max(top, r.id), 0) + 1 };
457
+ this.write([...rows, row]);
458
+ return Promise.resolve(row);
459
+ }
460
+
461
+ protected override updateRow(key: number, changes: Partial<Task>): Promise<Partial<Task>> {
462
+ const rows = this.read();
463
+ const at = rows.findIndex((r) => r.id === key);
464
+ if (at < 0) return Promise.reject(data.DataError.create('MJD204', { operation: 'update' }));
465
+ rows[at] = { ...rows[at], ...changes, id: key };
466
+ this.write(rows);
467
+ return Promise.resolve(rows[at]);
468
+ }
469
+
470
+ protected override removeRow(key: number): Promise<void> {
471
+ const rows = this.read();
472
+ const at = rows.findIndex((r) => r.id === key);
473
+ if (at < 0) return Promise.reject(data.DataError.create('MJD204', { operation: 'remove' }));
474
+ rows.splice(at, 1);
475
+ this.write(rows);
476
+ return Promise.resolve();
477
+ }
478
+
479
+ private read(): Task[] {
480
+ try {
481
+ return JSON.parse(localStorage.getItem(KEY) ?? '[]') as Task[];
482
+ } catch {
483
+ return [];
484
+ }
485
+ }
486
+
487
+ private write(rows: Task[]) {
488
+ localStorage.setItem(KEY, JSON.stringify(rows));
489
+ }
490
+ }
491
+ ```