viewkitjs 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/MIGRATION.md +40 -6
  3. package/README.md +1 -1
  4. package/fields/dist/query/index.d.ts +2 -0
  5. package/fields/dist/query/index.js +2 -0
  6. package/fields/dist/query/list-request.d.ts +148 -0
  7. package/fields/dist/query/list-request.js +125 -0
  8. package/fields/dist/query/saved-view.d.ts +15 -0
  9. package/fields/dist/query/saved-view.js +11 -0
  10. package/fields/dist/query/settings.d.ts +9 -0
  11. package/fields/dist/query/settings.js +9 -0
  12. package/fields/docs/reference/query.md +66 -0
  13. package/package.json +5 -1
  14. package/postgres/README.md +1 -0
  15. package/postgres/dist/handler.d.ts +53 -0
  16. package/postgres/dist/handler.js +211 -0
  17. package/postgres/dist/ids.d.ts +1 -1
  18. package/postgres/dist/ids.js +19 -1
  19. package/postgres/dist/index.d.ts +1 -0
  20. package/postgres/dist/index.js +1 -0
  21. package/postgres/dist/limits.d.ts +3 -1
  22. package/postgres/dist/limits.js +1 -1
  23. package/postgres/dist/list-fields.d.ts +10 -0
  24. package/postgres/dist/list-fields.js +36 -0
  25. package/postgres/dist/readable.d.ts +4 -0
  26. package/postgres/dist/readable.js +4 -0
  27. package/postgres/dist/refusals.d.ts +9 -2
  28. package/postgres/dist/refusals.js +6 -0
  29. package/postgres/docs/guides/field-map.md +2 -2
  30. package/postgres/docs/guides/list-handler.md +99 -0
  31. package/postgres/docs/index.md +1 -0
  32. package/postgres/docs/reference/postgres.md +11 -3
  33. package/views/README.md +2 -2
  34. package/views/dist/atoms/RowMenu.d.ts +7 -0
  35. package/views/dist/atoms/RowMenu.js +18 -16
  36. package/views/dist/atoms/carried.d.ts +5 -0
  37. package/views/dist/atoms/carried.js +7 -0
  38. package/views/dist/atoms/types.d.ts +3 -0
  39. package/views/dist/contract.d.ts +26 -6
  40. package/views/dist/contract.js +25 -0
  41. package/views/dist/controls/alert-dialog/alert-dialog.js +2 -1
  42. package/views/dist/controls/atoms.d.ts +2 -0
  43. package/views/dist/controls/atoms.js +2 -0
  44. package/views/dist/controls/avatar/avatar.d.ts +3 -3
  45. package/views/dist/controls/avatar/avatar.js +1 -1
  46. package/views/dist/controls/avatar/tokens.d.ts +44 -0
  47. package/views/dist/controls/avatar/tokens.js +11 -0
  48. package/views/dist/controls/avatar.css +22 -5
  49. package/views/dist/controls/choice/tokens.d.ts +0 -4
  50. package/views/dist/controls/choice/tokens.js +0 -1
  51. package/views/dist/controls/choice.css +3 -3
  52. package/views/dist/controls/controls.d.ts +6 -0
  53. package/views/dist/controls/controls.js +10 -2
  54. package/views/dist/controls/customize/map-customize-body.js +1 -1
  55. package/views/dist/controls/field/field.d.ts +19 -4
  56. package/views/dist/controls/field/field.js +63 -5
  57. package/views/dist/controls/field/tokens.d.ts +4 -0
  58. package/views/dist/controls/field/tokens.js +1 -0
  59. package/views/dist/controls/field.css +41 -16
  60. package/views/dist/controls/glyphs/glyphs.d.ts +10 -0
  61. package/views/dist/controls/glyphs/glyphs.js +173 -0
  62. package/views/dist/controls/index.d.ts +2 -1
  63. package/views/dist/controls/index.js +2 -1
  64. package/views/dist/controls/input/input.js +5 -2
  65. package/views/dist/controls/input/tokens.d.ts +4 -0
  66. package/views/dist/controls/input/tokens.js +1 -0
  67. package/views/dist/controls/input.css +31 -3
  68. package/views/dist/controls/internal/icons.js +10 -0
  69. package/views/dist/controls/internal/keep-focus.d.ts +2 -0
  70. package/views/dist/controls/internal/keep-focus.js +17 -0
  71. package/views/dist/controls/internal/watch-frame.d.ts +2 -0
  72. package/views/dist/controls/internal/watch-frame.js +33 -0
  73. package/views/dist/controls/markdown/map-markdown.d.ts +4 -0
  74. package/views/dist/controls/markdown/map-markdown.js +5 -0
  75. package/views/dist/controls/menu/map-menu.js +2 -2
  76. package/views/dist/controls/menu-list/menu-list.d.ts +3 -0
  77. package/views/dist/controls/menu-list/menu-list.js +5 -4
  78. package/views/dist/controls/modal/modal.js +5 -1
  79. package/views/dist/controls/pane/pane.js +2 -1
  80. package/views/dist/controls/phone-header/header-bar.d.ts +5 -1
  81. package/views/dist/controls/phone-header/header-bar.js +2 -2
  82. package/views/dist/controls/phone-header.css +11 -1
  83. package/views/dist/controls/picker/map-picker.js +3 -0
  84. package/views/dist/controls/picker/picker.d.ts +14 -0
  85. package/views/dist/controls/picker/picker.js +30 -10
  86. package/views/dist/controls/picker.css +2 -0
  87. package/views/dist/controls/popover/popover.js +2 -1
  88. package/views/dist/controls/radio/radio.d.ts +5 -3
  89. package/views/dist/controls/radio/radio.js +18 -2
  90. package/views/dist/controls/radio/tokens.d.ts +44 -0
  91. package/views/dist/controls/radio/tokens.js +11 -0
  92. package/views/dist/controls/radio.css +79 -1
  93. package/views/dist/controls/select/select.d.ts +4 -0
  94. package/views/dist/controls/select/select.js +11 -5
  95. package/views/dist/controls/select/tokens.d.ts +8 -0
  96. package/views/dist/controls/select/tokens.js +2 -0
  97. package/views/dist/controls/select.css +17 -0
  98. package/views/dist/controls/setting-row/looks.d.ts +1 -1
  99. package/views/dist/controls/setting-row/looks.js +9 -4
  100. package/views/dist/controls/setting-row/setting-row.d.ts +45 -10
  101. package/views/dist/controls/setting-row/setting-row.js +82 -15
  102. package/views/dist/controls/setting-row/tokens.d.ts +74 -2
  103. package/views/dist/controls/setting-row/tokens.js +19 -1
  104. package/views/dist/controls/setting-row.css +135 -14
  105. package/views/dist/controls/sheet/bottom-sheet.d.ts +10 -2
  106. package/views/dist/controls/sheet/bottom-sheet.js +6 -3
  107. package/views/dist/controls/sheet.css +4 -1
  108. package/views/dist/controls/sort-editor/sort-editor.js +3 -2
  109. package/views/dist/controls/sort-editor.css +8 -2
  110. package/views/dist/controls/switch-row/tokens.d.ts +0 -12
  111. package/views/dist/controls/switch-row/tokens.js +0 -3
  112. package/views/dist/controls/switch-row.css +3 -7
  113. package/views/dist/controls/switch.css +17 -7
  114. package/views/dist/controls/tag/tag.d.ts +3 -1
  115. package/views/dist/controls/tag/tag.js +2 -2
  116. package/views/dist/controls/tag/tokens.d.ts +4 -0
  117. package/views/dist/controls/tag/tokens.js +1 -0
  118. package/views/dist/controls/tag-field/tag-field.d.ts +5 -1
  119. package/views/dist/controls/tag-field/tag-field.js +11 -5
  120. package/views/dist/controls/tag-field/tokens.d.ts +16 -0
  121. package/views/dist/controls/tag-field/tokens.js +4 -0
  122. package/views/dist/controls/tag-field.css +19 -0
  123. package/views/dist/controls/tag.css +2 -0
  124. package/views/dist/controls/toolbar/toolbar.d.ts +15 -3
  125. package/views/dist/controls/toolbar/toolbar.js +22 -15
  126. package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +14 -0
  127. package/views/dist/controls/toolbar-button/atom-toolbar-button.js +51 -0
  128. package/views/dist/controls/toolbar-button/toolbar-button.d.ts +1 -1
  129. package/views/dist/controls/toolbar-button/toolbar-button.js +2 -3
  130. package/views/dist/controls/toolbar-button.css +4 -0
  131. package/views/dist/controls/toolbar.css +5 -0
  132. package/views/dist/controls/views-list/map-view-menu.d.ts +3 -0
  133. package/views/dist/controls/views-list/map-view-menu.js +25 -0
  134. package/views/dist/controls/views-list/map-views-list-body.d.ts +28 -1
  135. package/views/dist/controls/views-list/map-views-list-body.js +39 -21
  136. package/views/dist/controls/views-list/rules.d.ts +2 -0
  137. package/views/dist/controls/views-list/view-menu.d.ts +7 -0
  138. package/views/dist/controls/views-list/view-menu.js +28 -24
  139. package/views/dist/controls/views-list/words.d.ts +2 -0
  140. package/views/dist/controls/views-list/words.js +1 -1
  141. package/views/dist/editors/EditorPanel.js +2 -1
  142. package/views/dist/editors/edit-session.js +2 -5
  143. package/views/dist/field-row/FieldRow.d.ts +4 -2
  144. package/views/dist/field-row/FieldRow.js +67 -20
  145. package/views/dist/field-row/FieldRowLane.d.ts +7 -2
  146. package/views/dist/field-row/FieldRowLane.js +4 -3
  147. package/views/dist/field-row/editors/RowEditor.d.ts +12 -0
  148. package/views/dist/field-row/editors/RowEditor.js +31 -1
  149. package/views/dist/field-row/editors/RowValueListEditor.d.ts +5 -1
  150. package/views/dist/field-row/editors/RowValueListEditor.js +4 -1
  151. package/views/dist/field-row/field-row-button.d.ts +5 -0
  152. package/views/dist/field-row/field-row-button.js +2 -0
  153. package/views/dist/fields/binding.d.ts +3 -2
  154. package/views/dist/fields/binding.js +38 -5
  155. package/views/dist/grid/chrome/GridColumnMenu.d.ts +4 -2
  156. package/views/dist/grid/chrome/GridColumnMenu.js +3 -2
  157. package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -1
  158. package/views/dist/grid/chrome/GridGroupMenu.js +4 -3
  159. package/views/dist/grid/chrome/GridHeader.d.ts +4 -1
  160. package/views/dist/grid/chrome/GridHeader.js +2 -2
  161. package/views/dist/grid/chrome/GridRow.js +6 -5
  162. package/views/dist/grid/chrome/GridRowCells.js +6 -9
  163. package/views/dist/grid/chrome/GridStructure.d.ts +4 -1
  164. package/views/dist/grid/chrome/GridStructure.js +4 -4
  165. package/views/dist/grid/chrome/GridTable.js +5 -2
  166. package/views/dist/grid/chrome/grid-column-menu-items.js +1 -1
  167. package/views/dist/grid/chrome/grid-row-menu-items.d.ts +27 -3
  168. package/views/dist/grid/chrome/grid-row-menu-items.js +92 -6
  169. package/views/dist/grid/chrome/grid-row-props.d.ts +7 -2
  170. package/views/dist/grid/chrome/grid-rows-menu.js +34 -6
  171. package/views/dist/grid/chrome/grid-table-props.d.ts +38 -7
  172. package/views/dist/grid/chrome/useGridBatchApi.d.ts +3 -1
  173. package/views/dist/grid/chrome/useGridBatchApi.js +4 -2
  174. package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -2
  175. package/views/dist/grid/chrome/useGridKeyboard.js +15 -9
  176. package/views/dist/grid/chrome/useGridPendingReconciliation.js +1 -2
  177. package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
  178. package/views/dist/grid/chrome/useGridTableInteractionModel.js +11 -5
  179. package/views/dist/grid/core/commit-model.d.ts +20 -2
  180. package/views/dist/grid/core/editing-controller.d.ts +18 -0
  181. package/views/dist/grid/core/editing-controller.js +188 -42
  182. package/views/dist/grid/core/editing-model.d.ts +3 -0
  183. package/views/dist/grid/core/editing-model.js +3 -0
  184. package/views/dist/grid/core/save-path.d.ts +24 -0
  185. package/views/dist/grid/core/save-path.js +122 -0
  186. package/views/dist/grid/core/spreadsheet-operations.d.ts +3 -0
  187. package/views/dist/grid/core/spreadsheet-operations.js +23 -0
  188. package/views/dist/grid/index.d.ts +3 -2
  189. package/views/dist/grid/index.js +1 -0
  190. package/views/dist/internal/field-rows.d.ts +26 -0
  191. package/views/dist/internal/field-rows.js +8 -0
  192. package/views/dist/internal/page-close.d.ts +7 -0
  193. package/views/dist/internal/page-close.js +43 -0
  194. package/views/dist/list/browser-views-store.d.ts +10 -0
  195. package/views/dist/list/browser-views-store.js +182 -0
  196. package/views/dist/list/index.d.ts +23 -0
  197. package/views/dist/list/index.js +8 -0
  198. package/views/dist/list/menu.d.ts +31 -0
  199. package/views/dist/list/menu.js +76 -0
  200. package/views/dist/list/parts.d.ts +6 -0
  201. package/views/dist/list/parts.js +59 -0
  202. package/views/dist/list/registry.d.ts +11 -0
  203. package/views/dist/list/registry.js +31 -0
  204. package/views/dist/list/root.d.ts +40 -0
  205. package/views/dist/list/root.js +128 -0
  206. package/views/dist/list/slot.d.ts +14 -0
  207. package/views/dist/list/slot.js +22 -0
  208. package/views/dist/list/source.d.ts +11 -0
  209. package/views/dist/list/source.js +31 -0
  210. package/views/dist/list/store.d.ts +87 -0
  211. package/views/dist/list/store.js +115 -0
  212. package/views/dist/list/toolbar.d.ts +6 -0
  213. package/views/dist/list/toolbar.js +359 -0
  214. package/views/dist/list/views-axis.d.ts +5 -0
  215. package/views/dist/list/views-axis.js +96 -0
  216. package/views/dist/list/views-store.d.ts +41 -0
  217. package/views/dist/list/views-store.js +1 -0
  218. package/views/dist/list/views.d.ts +67 -0
  219. package/views/dist/list/views.js +400 -0
  220. package/views/dist/model/preferences.js +1 -1
  221. package/views/dist/model/prefs-buckets.js +1 -1
  222. package/views/dist/panels/index.d.ts +3 -1
  223. package/views/dist/panels/index.js +1 -0
  224. package/views/dist/panels/react/customize-body.js +1 -0
  225. package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +41 -4
  226. package/views/dist/panels/react/toolbar/ReadyToolbar.js +6 -326
  227. package/views/dist/panels/react/toolbar/Toolbar.d.ts +9 -1
  228. package/views/dist/panels/react/toolbar/Toolbar.js +34 -23
  229. package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
  230. package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
  231. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +2 -2
  232. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +3 -1
  233. package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
  234. package/views/dist/panels/react/toolbar/context.d.ts +10 -2
  235. package/views/dist/panels/react/toolbar/context.js +3 -1
  236. package/views/dist/panels/react/views-row/FoldingViewRow.d.ts +1 -1
  237. package/views/dist/panels/react/views-row/FoldingViewRow.js +15 -4
  238. package/views/dist/panels/react/views-row/PillGroup.d.ts +5 -2
  239. package/views/dist/panels/react/views-row/PillGroup.js +16 -7
  240. package/views/dist/panels/react/views-row/ViewPicker.js +2 -12
  241. package/views/dist/panels/react/views-row/ViewPickerRow.d.ts +4 -2
  242. package/views/dist/panels/react/views-row/ViewPickerRow.js +9 -5
  243. package/views/dist/panels/react.d.ts +2 -2
  244. package/views/dist/panels/toolbar/edit-view.d.ts +7 -1
  245. package/views/dist/panels/toolbar/edit-view.js +14 -0
  246. package/views/dist/panels/toolbar/model.d.ts +5 -0
  247. package/views/dist/panels/toolbar/model.js +7 -3
  248. package/views/dist/panels/view-state.d.ts +5 -3
  249. package/views/dist/panels/views-row/model.d.ts +19 -2
  250. package/views/dist/panels/views-row/model.js +14 -0
  251. package/views/dist/provider/ViewsProvider.d.ts +16 -7
  252. package/views/dist/provider/ViewsProvider.js +23 -5
  253. package/views/dist/provider/components.d.ts +43 -2
  254. package/views/dist/provider/context.d.ts +2 -1
  255. package/views/dist/provider/context.js +1 -1
  256. package/views/dist/provider/ports.d.ts +19 -12
  257. package/views/dist/provider/ports.js +69 -1
  258. package/views/dist/react.d.ts +1 -1
  259. package/views/dist/styles.css +418 -59
  260. package/views/dist/styles.unlayered.css +418 -59
  261. package/views/docs/contract.md +42 -31
  262. package/views/docs/controls/avatar.md +11 -0
  263. package/views/docs/controls/choice.md +0 -1
  264. package/views/docs/controls/field.md +3 -0
  265. package/views/docs/controls/input.md +1 -0
  266. package/views/docs/controls/radio.md +16 -1
  267. package/views/docs/controls/select.md +2 -0
  268. package/views/docs/controls/setting-row.md +18 -0
  269. package/views/docs/controls/switch-row.md +0 -3
  270. package/views/docs/controls/tag-field.md +4 -0
  271. package/views/docs/controls/tag.md +1 -0
  272. package/views/docs/getting-started.md +2 -2
  273. package/views/docs/guides/atoms.md +2 -2
  274. package/views/docs/guides/columns.md +1 -1
  275. package/views/docs/guides/ports.md +1 -1
  276. package/views/docs/guides/the-grid.md +34 -7
  277. package/views/docs/guides/the-provider.md +4 -2
  278. package/views/docs/index.md +1 -0
  279. package/views/docs/reference/controls.md +35 -25
  280. package/views/docs/reference/editors-session.md +1 -1
  281. package/views/docs/reference/field-row.md +9 -1
  282. package/views/docs/reference/grid.md +14 -8
  283. package/views/docs/reference/list.md +227 -0
  284. package/views/docs/reference/looks.md +1 -1
  285. package/views/docs/reference/panels-react.md +17 -12
  286. package/views/docs/reference/panels.md +8 -5
  287. package/views/docs/reference/react.md +11 -9
  288. package/views/docs/reference/views.md +2 -2
  289. package/views/skills/views/SKILL.md +9 -6
@@ -103,6 +103,15 @@ export const listSettingsChangeSchema = z.strictObject(Object.fromEntries(Object
103
103
  part,
104
104
  schema.isOptional() ? schema.nullable() : schema.optional(),
105
105
  ])));
106
+ export const listRequestSettingsSchema = settingsObject.pick({
107
+ search: true,
108
+ filter: true,
109
+ sorts: true,
110
+ group: true,
111
+ rowOrderMode: true,
112
+ itemPositions: true,
113
+ });
114
+ export const savedSettingsSchema = settingsObject.omit({ search: true });
106
115
  export const LIST_SETTINGS_DEFAULTS = {
107
116
  layout: "table",
108
117
  filter: emptyTree(),
@@ -174,6 +174,72 @@ A link's platform is read through `matchesRule` with the part `platform`, from t
174
174
  - `LIST_SETTINGS_DEFAULTS` — a list with nothing set: a table, unfiltered, unsorted, ungrouped, its columns and look the app's own.
175
175
  - `settingsForSaving` — the settings a saved view keeps: all of them but the search. The value handed in is left as it is.
176
176
  - `listLookSchema` — the look's schema, shared by the settings and a person's own layer.
177
+ - `ListRequestSettings` — the settings' parts a list request carries: the search, the filter, the sorts, the group, the row order's mode and its hand-placed records.
178
+ - `listRequestSettingsSchema` — their schema, the settings' own parts picked, so each is checked as the settings check it. It refuses any other part (the layout, the columns, the board).
179
+ - `SavedListSettings` — the settings a saved view keeps: every part but the search.
180
+ - `savedSettingsSchema` — their schema, the settings' own, refusing a search.
181
+
182
+ ## A list request and its answer
183
+
184
+ What a list asks its server for, and what comes back, checked the same way in the browser and on a server. The views side sends it through a source (`viewkitjs/views/list`), and the server answers it.
185
+
186
+ - `ListRequest` — one list request, by its `part`. Every part carries:
187
+ - `version: 1`;
188
+ - its `settings` (`ListRequestSettings`);
189
+ - an optional `hold` (`ListHold`);
190
+ - an optional `context` (`ListContext`).
191
+
192
+ Each part also carries only its own keys:
193
+ - `rows`: a `page`, and optionally the `fields` each row carries (absent: every field the reader may read);
194
+ - `group`: one group's next page, as `group: { key }` (`""` for the rows with no value), a `page` and optional `fields`;
195
+ - `ids`: nothing more, for every matching row's id;
196
+ - `counts`: `{ of, fields }`, the options of up to 50 fields counted. `of: "filter"` leaves each field's own rules out, as a filter's picker counts; `of: "hold"` applies the hold's other fields, as a quick filter counts;
197
+ - `values`: one open field's values, by `field`;
198
+ - `view-counts`: each view's count, by `views`, at most 100 of `{ id, filter }`.
199
+ - `ListRequestOf` — the request of one part.
200
+ - `ListPart` — one part a request names.
201
+ - `LIST_PARTS` — the parts: `rows`, `group`, `ids`, `counts`, `values` and `view-counts`.
202
+ - `LIST_REQUEST_VERSION` — the version a request carries, 1. A later part joins without changing it: no request that holds today changes its meaning.
203
+ - `LIST_REQUEST_LIMITS` — the bounds beside the settings' own:
204
+ - a page of 1 to 1,000 rows;
205
+ - a cursor of 16,384 characters and a group key of 512;
206
+ - 200 fields asked, 50 fields counted and 100 views counted.
207
+ - `ListContext` — the reader's context: `now` (an ISO instant with its offset), `timeZone`, `locale` and `language`. Each one left out is the server's own.
208
+ - `ListPageAsk` — a page asked for: its `size`, and the `after` cursor the page before handed back (absent or `null`: the first).
209
+ - `listRequestSchema` — the one Zod schema of a request. Each part is strict. It refuses, each with its reason:
210
+ - another version: "a list request is version 1";
211
+ - a part it has no word for: "a list request's part is one of rows, group, ids, counts, values, view-counts";
212
+ - another part's key, and a settings part a request doesn't carry;
213
+ - what the settings' own rules refuse;
214
+ - a page past 1,000 rows;
215
+ - `"id"` as a field's key: `"id" is the record's id, never a field's key`;
216
+ - a field asked twice, and a view counted twice.
217
+ - `ListRow` — one row of an answer: your own flat row, `{ id, ...values }`, its record's key as text under `id`.
218
+ - `ListTotal` — how many rows match: `{ count, exact }`, `exact` false where the server stopped counting.
219
+ - `ListAnswerGroup` — one group of a grouped answer: `key`, `label` (the name the server read, or `null`), `count` and `hidden`. With `rows` it is loaded, and `next` is its next page's cursor; without them, a `group` request loads it.
220
+ - `ListRefused` — a refused request: `{ refused: { code, message } }`. It is a value, never a throw.
221
+ - `ListAnswer` — an answer, by its `part`, or a `ListRefused`:
222
+ - `rows`: `rows`, `next`, `total` (counted on a first page, `null` after) and `groups` (`null` when the list isn't grouped). A grouped answer holds its rows in its groups: its own `rows` is `[]`, its `next` is `null` and its `total` is the whole list's;
223
+ - `group`: `key`, `rows` and `next`;
224
+ - `ids`: `ids`;
225
+ - `counts`: each field's `{ counts, labels }`;
226
+ - `values`: `field`, `values` and `labels`;
227
+ - `view-counts`: each view's count by its id.
228
+ - `ListAnswerOf` — the answer of one part.
229
+ - `listAnswerSchema` — the one Zod schema of an answer. It reads loosely, dropping a key it doesn't know, so an answer may carry more later. It refuses a row without a text `id`, and a grouped answer with rows of its own.
230
+ - `isRefused` — whether an answer is a refusal.
231
+ - `answerFor` — `answerFor(request, answer)`: the answer, typed as the request's part's, or the refusal. It throws "answered part … to a … request" on an answer to another part.
232
+
233
+ ## A saved view
234
+
235
+ - `SavedView` — one saved view:
236
+ - `id` and `name`;
237
+ - `scope`: `"shared"` with everyone, or a person's own `"personal"`;
238
+ - its `settings`, without the search;
239
+ - its `position` in its scope's row;
240
+ - `updatedAt`, an ISO instant;
241
+ - `readOnly`, for a view your app declares in its code.
242
+ - `savedViewSchema` — the one Zod schema of a saved view, what a views store keeps and your route checks. Strict: it refuses an unknown key, a search in its settings, a scope it has no word for and an `updatedAt` that isn't an instant.
177
243
 
178
244
  ## A quick-filter hold
179
245
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viewkitjs",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "ViewKit — typed fields, the grid and its editors, and a list's SQL for record lists, in one package: viewkitjs/fields, viewkitjs/views and viewkitjs/postgres. By Sheaf.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -184,6 +184,10 @@
184
184
  "types": "./views/dist/panels/react.d.ts",
185
185
  "default": "./views/dist/panels/react.js"
186
186
  },
187
+ "./views/list": {
188
+ "types": "./views/dist/list/index.d.ts",
189
+ "default": "./views/dist/list/index.js"
190
+ },
187
191
  "./views/styles.css": "./views/dist/styles.css",
188
192
  "./views/styles.unlayered.css": "./views/dist/styles.unlayered.css",
189
193
  "./views/controls/*.css": "./views/dist/controls/*.css",
@@ -31,5 +31,6 @@ assert.deepEqual(query.values, [workspaceId]);
31
31
 
32
32
  - [The field map and the permission condition](docs/guides/field-map.md)
33
33
  - [A field map from your definitions](docs/guides/definitions.md)
34
+ - [Answering a list's requests](docs/guides/list-handler.md)
34
35
  - [Proving your answers with the test kit](docs/guides/test-kit.md)
35
36
  - [Every export](docs/reference/postgres.md)
@@ -0,0 +1,53 @@
1
+ import { type ListAnswer } from "viewkitjs/fields/query";
2
+ import type { Access } from "./access.js";
3
+ import { type FieldMap } from "./map.js";
4
+ import type { Readable } from "./readable.js";
5
+ import { type Run } from "./steps.js";
6
+ /** What `answerList` answers with: the app's map, how it runs a statement, and the reader's rows and fields, all the
7
+ * server's, never the request's. */
8
+ export type AnswerListOptions = {
9
+ readonly map: FieldMap;
10
+ readonly run: Run;
11
+ readonly access: Access;
12
+ readonly readable: Readable;
13
+ /** The fields of the list's own table a search reads; absent, every field the reader may read that a search answers. */
14
+ readonly search?: readonly string[];
15
+ };
16
+ /** The answer to a list request (`listRequestSchema`, viewkitjs/fields/query), read under the server's map, access and
17
+ * readable fields: one part's answer, or `{ refused: { code, message } }`, never a thrown refusal. */
18
+ export declare function answerList(request: unknown, options: AnswerListOptions): Promise<ListAnswer>;
19
+ /** The Fetch API's Request as the app's own types declare it (the DOM's, Node's, a Worker's); where none is declared,
20
+ * the one method the handler reads. */
21
+ type FetchRequest = typeof globalThis extends {
22
+ Request: {
23
+ prototype: infer R;
24
+ };
25
+ } ? R : {
26
+ text(): Promise<string>;
27
+ };
28
+ /** The Fetch API's Response as the app's own types declare it; where none is declared, what the handler sets. */
29
+ type FetchResponse = typeof globalThis extends {
30
+ Response: {
31
+ prototype: infer R;
32
+ };
33
+ } ? R : {
34
+ readonly status: number;
35
+ text(): Promise<string>;
36
+ };
37
+ /** The reader of one request: which rows of each table, and which fields, they may read. */
38
+ export type ListReader = {
39
+ readonly access: Access;
40
+ readonly readable: Readable;
41
+ };
42
+ /** What `listHandler` answers with: the app's map, how it runs a statement, and who asks, read per request from the
43
+ * app's own session (null: no reader, answered 401). */
44
+ export type ListHandlerOptions = {
45
+ readonly map: FieldMap;
46
+ readonly run: Run;
47
+ readonly access: (request: FetchRequest) => ListReader | null | Promise<ListReader | null>;
48
+ /** The fields of the list's own table a search reads; absent, every field the reader may read that a search answers. */
49
+ readonly search?: readonly string[];
50
+ };
51
+ /** A route for every list request a page makes: a Fetch Request in, a Response out (Next, Hono, a Worker). */
52
+ export declare function listHandler(options: ListHandlerOptions): (request: FetchRequest) => Promise<FetchResponse>;
53
+ export {};
@@ -0,0 +1,211 @@
1
+ import { hasSearch, isRefused, LIST_REQUEST_LIMITS, listRequestSchema, } from "viewkitjs/fields/query";
2
+ import { holdCountsQuery, optionCountsQuery, totalQuery } from "./counts.js";
3
+ import { fieldValuesQuery } from "./field-values.js";
4
+ import { groupsQuery } from "./groups.js";
5
+ import { idsQuery } from "./ids.js";
6
+ import { namedSearchKeys, readFieldKeys, searchFieldKeys } from "./list-fields.js";
7
+ import { isFieldMap } from "./map.js";
8
+ import { groupPageQuery, pageQuery } from "./page.js";
9
+ import { valuesQuery } from "./records.js";
10
+ import { REFUSALS, RefusedRequest } from "./refusals.js";
11
+ import { answer } from "./steps.js";
12
+ import { viewCountsQuery } from "./view-counts.js";
13
+ const GROUP_ROWS = 25;
14
+ const GROUPS_FILLED = 10;
15
+ export async function answerList(request, options) {
16
+ try {
17
+ return await answered(request, options);
18
+ }
19
+ catch (error) {
20
+ if (error instanceof RefusedRequest)
21
+ return { refused: { code: error.code, message: error.message } };
22
+ throw error;
23
+ }
24
+ }
25
+ async function answered(request, options) {
26
+ const { map, access, readable, run } = options;
27
+ if (!isFieldMap(map))
28
+ throw REFUSALS.notAMap();
29
+ if (Object.hasOwn(map.fields, "id"))
30
+ throw REFUSALS.reservedId();
31
+ const parsed = listRequestSchema.safeParse(request);
32
+ if (!parsed.success) {
33
+ const issue = parsed.error.issues[0];
34
+ throw REFUSALS.badRequest(issue.path.map(String).join("."), issue.message);
35
+ }
36
+ const asked = parsed.data;
37
+ for (const key of ["locale", "language"]) {
38
+ const tag = asked.context?.[key];
39
+ if (tag !== undefined && !knownLocale(tag))
40
+ throw REFUSALS.badRequest(`context.${key}`, `"${tag}" is not a locale Intl knows`);
41
+ }
42
+ const { settings, hold } = asked;
43
+ const context = {
44
+ timeZone: asked.context?.timeZone ?? "UTC",
45
+ now: asked.context?.now === undefined ? new Date() : new Date(asked.context.now),
46
+ };
47
+ const byKey = { map, access, readable, context };
48
+ const bare = { ...byKey, filter: settings.filter, ...(hold === undefined ? {} : { hold }) };
49
+ const text = settings.search;
50
+ const base = text !== undefined && hasSearch({ text, fields: [] })
51
+ ? {
52
+ ...bare,
53
+ search: {
54
+ text,
55
+ fields: options.search === undefined ? searchFieldKeys(bare) : namedSearchKeys(bare, options.search),
56
+ },
57
+ }
58
+ : bare;
59
+ const order = {
60
+ sorts: settings.sorts,
61
+ rowOrderMode: settings.rowOrderMode,
62
+ itemPositions: settings.itemPositions,
63
+ locale: asked.context?.locale,
64
+ language: asked.context?.language,
65
+ };
66
+ const reading = { base, order, byKey, run };
67
+ switch (asked.part) {
68
+ case "rows": {
69
+ const fields = rowFields(reading, asked);
70
+ const group = groupOf(settings.group);
71
+ if (group === null)
72
+ return flatRows(reading, fields, asked.page.size, asked.page.after ?? null);
73
+ if (asked.page.after != null)
74
+ throw REFUSALS.groupedAfter();
75
+ return groupedRows(reading, fields, group);
76
+ }
77
+ case "group": {
78
+ const group = groupOf(settings.group);
79
+ if (group === null)
80
+ throw REFUSALS.noGroup();
81
+ const fields = rowFields(reading, asked);
82
+ const page = groupPageQuery({
83
+ ...base,
84
+ ...order,
85
+ group,
86
+ key: asked.group.key,
87
+ size: asked.page.size,
88
+ after: asked.page.after ?? null,
89
+ });
90
+ const read = page.readPage(await run(page));
91
+ return { part: "group", key: asked.group.key, rows: await rowsOf(reading, fields, read.keys), next: read.next };
92
+ }
93
+ case "ids": {
94
+ const keys = await answer(idsQuery({ ...base, ...order }), run);
95
+ return { part: "ids", ids: keys.map(String) };
96
+ }
97
+ case "counts": {
98
+ const { of, fields: counted } = asked.counts;
99
+ const steps = counted.map((key) => [key, of === "filter" ? optionCountsQuery(base, key) : holdCountsQuery(base, key)]);
100
+ const counts = [];
101
+ for (const [key, step] of steps) {
102
+ const read = await answer(step, run);
103
+ counts.push([key, { counts: read.counts, labels: read.labels }]);
104
+ }
105
+ return { part: "counts", counts: Object.fromEntries(counts) };
106
+ }
107
+ case "values": {
108
+ const read = await answer(fieldValuesQuery(base, asked.field), run);
109
+ return { part: "values", field: asked.field, values: [...read.values], labels: read.labels };
110
+ }
111
+ case "view-counts":
112
+ return { part: "view-counts", counts: await answer(viewCountsQuery({ ...base, views: asked.views }), run) };
113
+ }
114
+ }
115
+ function rowFields(reading, asked) {
116
+ const named = asked.fields;
117
+ if (named === undefined)
118
+ return readFieldKeys(reading.byKey);
119
+ valuesQuery({ ...reading.byKey, ids: [], fields: named });
120
+ return named;
121
+ }
122
+ function knownLocale(tag) {
123
+ try {
124
+ Intl.getCanonicalLocales(tag);
125
+ return true;
126
+ }
127
+ catch {
128
+ return false;
129
+ }
130
+ }
131
+ function groupOf(group) {
132
+ return group === null || group.setAside ? null : group;
133
+ }
134
+ async function rowsOf(reading, fields, keys) {
135
+ const read = await valuesOf(reading, fields, keys);
136
+ return keys.flatMap((key) => {
137
+ const row = read.get(String(key));
138
+ return row === undefined ? [] : [row];
139
+ });
140
+ }
141
+ async function valuesOf(reading, fields, keys) {
142
+ const ids = [...new Set(keys.map(String))];
143
+ if (ids.length === 0)
144
+ return new Map();
145
+ const records = await answer(valuesQuery({ ...reading.byKey, ids, fields }), reading.run);
146
+ return new Map(records.map((record) => [String(record.key), { id: String(record.key), ...record.values }]));
147
+ }
148
+ async function flatRows(reading, fields, size, after) {
149
+ const { base, order, run } = reading;
150
+ const page = pageQuery({ ...base, ...order, size, after });
151
+ const total = after === null ? totalQuery(base) : null;
152
+ const read = page.readPage(await run(page));
153
+ const counted = total === null ? null : await answer(total, run);
154
+ return { part: "rows", rows: await rowsOf(reading, fields, read.keys), next: read.next, total: counted, groups: null };
155
+ }
156
+ async function groupedRows(reading, fields, group) {
157
+ const { base, order, run } = reading;
158
+ const groupsStep = groupsQuery({ ...base, group, locale: order.locale, language: order.language });
159
+ const total = totalQuery(base);
160
+ pageQuery({ ...base, ...order, size: GROUP_ROWS });
161
+ const groups = await answer(groupsStep, run);
162
+ if (groups.some((one) => one.key.length > LIST_REQUEST_LIMITS.groupKey))
163
+ throw REFUSALS.groupKeyTooLong(group.fieldKey, LIST_REQUEST_LIMITS.groupKey);
164
+ const counted = await answer(total, run);
165
+ const pages = new Map();
166
+ for (const one of groups.filter((g) => !g.hidden).slice(0, GROUPS_FILLED)) {
167
+ if (one.count === 0) {
168
+ pages.set(one.key, { keys: [], next: null });
169
+ continue;
170
+ }
171
+ const page = groupPageQuery({ ...base, ...order, group, key: one.key, size: GROUP_ROWS, after: null });
172
+ pages.set(one.key, page.readPage(await run(page)));
173
+ }
174
+ const read = await valuesOf(reading, fields, [...pages.values()].flatMap((page) => page.keys));
175
+ const answered = groups.map((one) => {
176
+ const head = { key: one.key, label: one.label, count: one.count, hidden: one.hidden };
177
+ const page = pages.get(one.key);
178
+ if (page === undefined)
179
+ return head;
180
+ const rows = page.keys.flatMap((key) => {
181
+ const row = read.get(String(key));
182
+ return row === undefined ? [] : [row];
183
+ });
184
+ return { ...head, rows, next: page.next };
185
+ });
186
+ return { part: "rows", rows: [], next: null, total: counted, groups: answered };
187
+ }
188
+ function respond(status, body) {
189
+ const Made = globalThis.Response;
190
+ const headers = body === null ? { "cache-control": "no-store" } : { "content-type": "application/json", "cache-control": "no-store" };
191
+ return new Made(body, { status, headers });
192
+ }
193
+ export function listHandler(options) {
194
+ const { map, run, search } = options;
195
+ return async (request) => {
196
+ const reader = await options.access(request);
197
+ if (reader == null)
198
+ return respond(401, null);
199
+ const text = await request.text();
200
+ let body;
201
+ try {
202
+ body = JSON.parse(text);
203
+ }
204
+ catch {
205
+ const refusal = REFUSALS.badRequest("", "the body is no JSON");
206
+ return respond(400, JSON.stringify({ refused: { code: refusal.code, message: refusal.message } }));
207
+ }
208
+ const answer = await answerList(body, { map, run, access: reader.access, readable: reader.readable, search });
209
+ return respond(isRefused(answer) ? 400 : 200, JSON.stringify(answer));
210
+ };
211
+ }
@@ -4,5 +4,5 @@ import { type PageRequest } from "./page.js";
4
4
  export declare const IDS_PAGE = 1000;
5
5
  /** A request for every id: a page's request, without its size, its cursor or its number. */
6
6
  export type IdsRequest = Omit<PageRequest, "size" | "after" | "page">;
7
- /** Every key the list keeps, in its order, one page of IDS_PAGE a step. */
7
+ /** Every key the list keeps, in its order, one page of IDS_PAGE a step, after a count capped at the map's `ids`. */
8
8
  export declare function idsQuery(request: IdsRequest): Step<readonly unknown[]>;
@@ -1,6 +1,10 @@
1
+ import { totalQuery } from "./counts.js";
2
+ import { REFUSALS } from "./refusals.js";
1
3
  import { pageQuery } from "./page.js";
2
4
  export const IDS_PAGE = 1000;
3
5
  export function idsQuery(request) {
6
+ const most = request.map.limits.ids;
7
+ const tooBig = () => REFUSALS.tooBig("ids", "ids", most);
4
8
  const stepFrom = (after, gathered) => {
5
9
  const query = pageQuery({ ...request, page: undefined, size: IDS_PAGE, after });
6
10
  return {
@@ -8,9 +12,23 @@ export function idsQuery(request) {
8
12
  read(rows) {
9
13
  const page = query.readPage(rows);
10
14
  const keys = [...gathered, ...page.keys];
15
+ if (keys.length > most)
16
+ throw tooBig();
11
17
  return page.next === null ? { answer: keys } : { next: stepFrom(page.next, keys) };
12
18
  },
13
19
  };
14
20
  };
15
- return stepFrom(null, []);
21
+ const first = stepFrom(null, []);
22
+ const counted = totalQuery({ ...request, cap: most });
23
+ return {
24
+ query: counted.query,
25
+ read(rows) {
26
+ const read = counted.read(rows);
27
+ if (!("answer" in read))
28
+ throw new TypeError("idsQuery: a total is one step");
29
+ if (!read.answer.exact)
30
+ throw tooBig();
31
+ return read.answer.count === 0 ? { answer: [] } : { next: first };
32
+ },
33
+ };
16
34
  }
@@ -11,6 +11,7 @@ export { groupPageQuery, pageQuery, type GroupPageRequest, type Page, type PageQ
11
11
  export { IDS_PAGE, idsQuery, type IdsRequest } from "./ids.js";
12
12
  export { VALUES_PAGE, valuesQuery, type RecordValues, type ValuesRequest } from "./records.js";
13
13
  export { answer, type ResultRow, type Run, type Step } from "./steps.js";
14
+ export { answerList, listHandler, type AnswerListOptions, type ListHandlerOptions, type ListReader } from "./handler.js";
14
15
  export { DISTINCT_LIMIT, holdCountsQuery, optionCountsQuery, totalQuery, type OptionCounts, type Total, type TotalRequest, } from "./counts.js";
15
16
  export { groupKeysQuery, groupsQuery, type Group, type GroupsRequest } from "./groups.js";
16
17
  export { figuresQuery, type FiguresRequest } from "./figures.js";
@@ -11,6 +11,7 @@ export { groupPageQuery, pageQuery, } from "./page.js";
11
11
  export { IDS_PAGE, idsQuery } from "./ids.js";
12
12
  export { VALUES_PAGE, valuesQuery } from "./records.js";
13
13
  export { answer } from "./steps.js";
14
+ export { answerList, listHandler } from "./handler.js";
14
15
  export { DISTINCT_LIMIT, holdCountsQuery, optionCountsQuery, totalQuery, } from "./counts.js";
15
16
  export { groupKeysQuery, groupsQuery } from "./groups.js";
16
17
  export { figuresQuery } from "./figures.js";
@@ -1,10 +1,12 @@
1
1
  /** A list request's caps: its filter's rules and groups (the root among them) and its depth (the root 1, each group and
2
- * each relation rule's `where` one deeper than the group holding it), its search's words, and a statement's values. */
2
+ * each relation rule's `where` one deeper than the group holding it), its search's words, a statement's values, and
3
+ * the ids an `ids` request answers. */
3
4
  export declare const REQUEST_LIMITS: {
4
5
  readonly rules: 500;
5
6
  readonly depth: 32;
6
7
  readonly searchWords: 50;
7
8
  readonly parameters: 30000;
9
+ readonly ids: 100000;
8
10
  };
9
11
  /** The caps a map holds: ViewKit's, or lower where the app lowered them. */
10
12
  export type RequestLimits = {
@@ -1 +1 @@
1
- export const REQUEST_LIMITS = { rules: 500, depth: 32, searchWords: 50, parameters: 30_000 };
1
+ export const REQUEST_LIMITS = { rules: 500, depth: 32, searchWords: 50, parameters: 30_000, ids: 100_000 };
@@ -0,0 +1,10 @@
1
+ import type { KeysRequest } from "./access.js";
2
+ /** The fields a row carries when the request names none: every field of the list's table the reader may read whose
3
+ * value they may read. */
4
+ export declare function readFieldKeys(request: KeysRequest): string[];
5
+ /** The fields a search reads when the app names none: every field of the list's table the reader may read that a
6
+ * search answers. A field no search answers yet (`not-yet`, `no-label`) is left out too. */
7
+ export declare function searchFieldKeys(request: KeysRequest): string[];
8
+ /** The app's named search fields for this reader: a field they may not read, or whose search reads one, left out; an
9
+ * unknown key, or a field no search answers yet, refused, as the app's own mistake. */
10
+ export declare function namedSearchKeys(request: KeysRequest, keys: readonly string[]): string[];
@@ -0,0 +1,36 @@
1
+ import { kept } from "./kept.js";
2
+ import { readableKeys } from "./readable.js";
3
+ import { valuesQuery } from "./records.js";
4
+ import { RefusedRequest } from "./refusals.js";
5
+ import { searchedReadOf } from "./search.js";
6
+ function keysAnswered(keys, build, codes) {
7
+ return keys.filter((key) => {
8
+ try {
9
+ return build(key);
10
+ }
11
+ catch (error) {
12
+ if (error instanceof RefusedRequest && codes.includes(error.code))
13
+ return false;
14
+ throw error;
15
+ }
16
+ });
17
+ }
18
+ const bare = (request) => ({
19
+ map: request.map,
20
+ access: request.access,
21
+ readable: request.readable,
22
+ context: request.context,
23
+ });
24
+ export function readFieldKeys(request) {
25
+ const base = bare(request);
26
+ const { scope } = kept(base);
27
+ return keysAnswered(readableKeys(scope, scope.map.table), (key) => (valuesQuery({ ...base, ids: [], fields: [key] }), true), ["hidden-field"]);
28
+ }
29
+ export function searchFieldKeys(request) {
30
+ const { scope, main } = kept(bare(request));
31
+ return keysAnswered(readableKeys(scope, scope.map.table), (key) => searchedReadOf(scope, main, key) !== null, ["not-yet", "no-label", "hidden-field"]);
32
+ }
33
+ export function namedSearchKeys(request, keys) {
34
+ const { scope, main } = kept(bare(request));
35
+ return keysAnswered(keys, (key) => (searchedReadOf(scope, main, key), true), ["hidden-field"]);
36
+ }
@@ -37,4 +37,8 @@ export declare function readingWorkedOut<T>(reader: Reader, read: () => T): T;
37
37
  * every field a statement reads passes.
38
38
  */
39
39
  export declare function readableField(reader: Reader, table: string, key: string): MappedField | undefined;
40
+ /** The keys of `table`'s fields the reader may read, in the map's order: each one `readableField` hands back without
41
+ * refusing (the reader's list holds it, and every field it reads, for a built map's worked-out fields). Refused when
42
+ * the request hands no list for `table`. Internal: a list's default fields start here. */
43
+ export declare function readableKeys(reader: Reader, table: string): string[];
40
44
  export {};
@@ -82,3 +82,7 @@ export function readableField(reader, table, key) {
82
82
  throw REFUSALS.hiddenField(at, key, placeOf(reader.map, hidden.table, hidden.key));
83
83
  return own.fields[key];
84
84
  }
85
+ export function readableKeys(reader, table) {
86
+ const keys = Object.keys(fieldsOf(reader.map, table)?.fields ?? {});
87
+ return keys.filter((key) => mayRead(reader, table, key) && hiddenRead(reader, table, key, new Set([`${table}\u0000${key}`])) === null);
88
+ }
@@ -1,6 +1,6 @@
1
1
  import type { RequestLimits } from "./limits.js";
2
2
  /** What a refused request names. */
3
- export type RefusalCode = "not-a-map" | "unknown-table" | "not-a-condition" | "no-condition" | "no-sql" | "unknown-field" | "unsafe-mapping" | "bad-rule" | "bad-hold" | "bad-sort" | "bad-cursor" | "no-label" | "no-fields" | "no-options" | "too-many" | "too-big" | "no-layout" | "not-yet" | "no-field-list" | "not-a-field-list" | "hidden-field";
3
+ export type RefusalCode = "not-a-map" | "unknown-table" | "not-a-condition" | "no-condition" | "no-sql" | "unknown-field" | "unsafe-mapping" | "bad-rule" | "bad-hold" | "bad-sort" | "bad-cursor" | "no-label" | "no-fields" | "no-options" | "too-many" | "too-big" | "no-layout" | "not-yet" | "no-field-list" | "not-a-field-list" | "hidden-field" | "bad-request" | "reserved-id";
4
4
  /** A request the translator writes no SQL for: `code` says why. */
5
5
  export declare class RefusedRequest extends Error {
6
6
  readonly code: RefusalCode;
@@ -31,10 +31,17 @@ export declare const REFUSALS: {
31
31
  readonly badHold: (path: string, words: string) => RefusedRequest;
32
32
  readonly badSort: (path: string, words: string) => RefusedRequest;
33
33
  readonly badCursor: (words: string) => RefusedRequest;
34
+ /** A body that is no list request (\`listRequestSchema\`): its first issue, at its place. */
35
+ readonly badRequest: (path: string, words: string) => RefusedRequest;
36
+ readonly reservedId: () => RefusedRequest;
37
+ readonly noGroup: () => RefusedRequest;
38
+ readonly groupedAfter: () => RefusedRequest;
39
+ /** A group whose key is longer than a list's answer holds: the field, never the value. */
40
+ readonly groupKeyTooLong: (key: string, most: number) => RefusedRequest;
34
41
  readonly noKeyType: (table: string, what?: "a page" | "a read by id") => RefusedRequest;
35
42
  readonly noOptions: (key: string, type: string) => RefusedRequest;
36
43
  readonly noLayout: (key: string, what: "board" | "calendar") => RefusedRequest;
37
- /** A filter, a search or a statement past one of the request's caps, at `path`. */
44
+ /** A filter, a search, a statement or a list's ids past one of the request's caps, at `path`. */
38
45
  readonly tooBig: (path: string, cap: keyof RequestLimits, most: number) => RefusedRequest;
39
46
  readonly tooManyViews: (limit: number) => RefusedRequest;
40
47
  readonly noValues: (key: string) => RefusedRequest;
@@ -3,6 +3,7 @@ const TOO_BIG = {
3
3
  depth: (most) => `a filter nests at most ${most} levels deep`,
4
4
  searchWords: (most) => `a search reads at most ${most} words`,
5
5
  parameters: (most) => `a statement binds at most ${most} values`,
6
+ ids: (most) => `a list answers at most ${most} ids; narrow the list first`,
6
7
  };
7
8
  export class RefusedRequest extends Error {
8
9
  code;
@@ -36,6 +37,11 @@ export const REFUSALS = {
36
37
  badHold: (path, words) => new RefusedRequest("bad-hold", `${path}: ${words}`),
37
38
  badSort: (path, words) => new RefusedRequest("bad-sort", `${path}: ${words}`),
38
39
  badCursor: (words) => new RefusedRequest("bad-cursor", `after: ${words}`),
40
+ badRequest: (path, words) => new RefusedRequest("bad-request", path === "" ? words : `${path}: ${words}`),
41
+ reservedId: () => new RefusedRequest("reserved-id", 'fields.id: "id" is the record\'s id in a list\'s answer, never a field\'s key; give the field another key'),
42
+ noGroup: () => new RefusedRequest("bad-request", "group: a group's page is asked under the list's group, and the settings hold none"),
43
+ groupedAfter: () => REFUSALS.badCursor("a grouped list pages each group by a group request"),
44
+ groupKeyTooLong: (key, most) => new RefusedRequest("too-big", `group: a group's key holds at most ${most} characters, and ${key} holds a longer value`),
39
45
  noKeyType: (table, what = "a page") => new RefusedRequest("unsafe-mapping", what === "a page"
40
46
  ? `tables.${table}.keyStored: a page binds its cursor's key; say how the key is kept`
41
47
  : `tables.${table}.keyStored: a read by id binds its keys; say how the key is kept`),
@@ -365,7 +365,7 @@ Inside a relation rule, a rule on a field the related table doesn't define has n
365
365
 
366
366
  A rule ViewKit wouldn't accept (an operator its field doesn't offer, a value of the wrong shape, a part its type doesn't have, a day that doesn't exist) is refused as `bad-rule`, at its place in the tree, and so is a date rule sent with no `context`, or a `context` whose time zone, region or moment can't be read. A rule naming a field your map doesn't hold is refused as `unknown-field`, where ViewKit in memory would have no opinion: a list's settings set such a rule aside before it reaches you.
367
367
 
368
- A request is held to caps before anything reads its tree (`REQUEST_LIMITS`): 500 rules and groups in the filter it compiles, the quick-filter hold on top and the root among them; 32 levels deep, the root 1 and each group and each relation rule's `where` one deeper than the group holding it; 50 search words; and 30,000 values in any one statement, under Postgres's own 65,535. Past one, it is refused as `too-big`, its message naming the cap and the place (`filter: a filter holds at most 500 rules and groups`), never answered with a statement your database refuses or a stack that overflows. The busiest saved views we have seen hold a handful of rules three levels deep, so the caps are far above any real list. Lower any of them for a map with `limits` (`defineFieldMap({ …, limits: { depth: 3 } })` holds a request to the depth a list's settings allow); a cap above ViewKit's is refused as a `FieldMapError`.
368
+ A request is held to caps before anything reads its tree (`REQUEST_LIMITS`): 500 rules and groups in the filter it compiles, the quick-filter hold on top and the root among them; 32 levels deep, the root 1 and each group and each relation rule's `where` one deeper than the group holding it; 50 search words; 30,000 values in any one statement, under Postgres's own 65,535; and 100,000 ids an `ids` request answers. Past one, it is refused as `too-big`, its message naming the cap and the place (`filter: a filter holds at most 500 rules and groups`), never answered with a statement your database refuses or a stack that overflows. The busiest saved views we have seen hold a handful of rules three levels deep, so the caps are far above any real list. The ids' cap is twice the most ids a real select-all or bulk action takes (50,000): an `ids` request reads a count capped there first, so a list past it is refused (`ids: a list answers at most 100,000 ids; narrow the list first`) after one statement, before any id is read. A drag in a list in manual order reads the same ids, so it is refused too in a list that keeps more. Lower any of them for a map with `limits` (`defineFieldMap({ …, limits: { depth: 3 } })` holds a request to the depth a list's settings allow); a cap above ViewKit's is refused as a `FieldMapError`.
369
369
 
370
370
  ### A quick-filter hold
371
371
 
@@ -682,7 +682,7 @@ Each of these counts or pages the rows `keysQuery` keeps, under the same permiss
682
682
 
683
683
  - **`fieldValuesQuery(request, fieldKey)`** is an open field's values, for a filter's options when the field has no fixed list: an open select's or tag list's values, a relation's, a user's or an actor's records, each named in `labels`, the most held first, then by value in the database's order, cut at 1,000 (`FIELD_VALUES_LIMIT`). It reads the request's whole filter and search: hand in the rows you mean (a record tab's pin, say, and no view filter, so picking a value never makes the others vanish). Any other field is refused as `no-options`. A record its own table's condition hides is never offered. It also answers a far field's values, for a Where row inside a relation rule, through a path of one or two relations: `<relation>.<far field>` or `<relation>.<relation>.<far field>`, each relation a field of the table the one before reaches. They are the distinct values of the far records the kept rows reach, each relation's own `where` applied (never its `within`), named as the list's own are, every table read under its own condition, and counted by the rows that reach them. A key your map holds as written is its own field. A path it can't follow is refused as `unknown-field`, one reaching a table whose fields your map doesn't describe as `no-fields`.
684
684
  - **`viewCountsQuery`** counts each view in one statement, each view's `filter` beside the request's own filter and search (a quick filter, a pin), at most 100 views (`VIEW_COUNTS_LIMIT`).
685
- - **`idsQuery`** is every key the list keeps, in the order its pages hold them, read a page of 1,000 a step with no cap: the ids behind "select all matching", and with manual order and no filter, the order a drag splices into.
685
+ - **`idsQuery`** is every key the list keeps, in the order its pages hold them, read a page of 1,000 a step, at most the map's `limits.ids` (100,000 unless lowered; past it, refused `too-big` after one capped count): the ids behind "select all matching", and with manual order and no filter, the order a drag splices into.
686
686
  - **`groupPageQuery`** pages one group's rows, by keyset, under the list's sorts or its manual order: exactly the rows the group counts. Its cursor is bound to the group and its key, so a cursor of one group is refused for another.
687
687
  - **`lanesQuery`** is a board's lanes: every lane's count, then one statement holding the first `size` cards (25, `LANE_ROWS`) of the first `fill` lanes shown (10, `LANES_FILLED`). Hand the board's field as a group (fields' `boardAxis`): a status, a select, a yes-or-no, a relation of one record or a user; a board by a relation that names `sortBy` opens a lane for each far record the reader may see, an empty one answered filled, with no cards; any other is refused as `no-layout`. A set-aside board field is no board field: replace it with `boardAxis(defaultBoardField(…), lanes)` before you ask; a `board` that still carries the mark gets one `"_all"` lane of every row, its field checked only for whether the reader may read it. Each lane's `next` is read by `groupPageQuery` for that lane.
688
688
  - **`calendarQuery`** is a calendar's month in the request's zone, in one statement: each day's count, the first 500 rows in date order (`CALENDAR_ROWS_LIMIT`), and every day those didn't reach topped up with its first 2 (`CALENDAR_DAY_ROWS`), so each cell draws what it holds and its "+N" is the day's real count. At most 42 days (`CALENDAR_DAYS_LIMIT`); a date or a date and time only, else `no-layout`. The zone is read only in each day's first instant, worked out in JavaScript.