@rebasepro/cms-types 0.17.0-canary.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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/dist/admin_collection.d.ts +650 -0
  3. package/dist/augment.d.ts +81 -0
  4. package/dist/collections.d.ts +282 -0
  5. package/dist/controllers/analytics_controller.d.ts +7 -0
  6. package/dist/controllers/auth.d.ts +111 -0
  7. package/dist/controllers/customization_controller.d.ts +69 -0
  8. package/dist/controllers/dialogs_controller.d.ts +36 -0
  9. package/dist/controllers/index.d.ts +10 -0
  10. package/dist/controllers/local_config_persistence.d.ts +20 -0
  11. package/dist/controllers/navigation.d.ts +248 -0
  12. package/dist/controllers/registry.d.ts +96 -0
  13. package/dist/controllers/side_dialogs_controller.d.ts +67 -0
  14. package/dist/controllers/side_panel_controller.d.ts +97 -0
  15. package/dist/controllers/snackbar.d.ts +45 -0
  16. package/dist/index.d.ts +18 -0
  17. package/dist/index.es.js +154 -0
  18. package/dist/index.es.js.map +1 -0
  19. package/dist/react_component_ref.d.ts +43 -0
  20. package/dist/rebase_context.d.ts +68 -0
  21. package/dist/types/breadcrumbs.d.ts +15 -0
  22. package/dist/types/builders.d.ts +15 -0
  23. package/dist/types/collection_views.d.ts +105 -0
  24. package/dist/types/component_overrides.d.ts +196 -0
  25. package/dist/types/entity_actions.d.ts +112 -0
  26. package/dist/types/entity_display.d.ts +148 -0
  27. package/dist/types/entity_link_builder.d.ts +7 -0
  28. package/dist/types/entity_views.d.ts +115 -0
  29. package/dist/types/export_import.d.ts +21 -0
  30. package/dist/types/form_layout.d.ts +126 -0
  31. package/dist/types/formex.d.ts +40 -0
  32. package/dist/types/index.d.ts +18 -0
  33. package/dist/types/locales.d.ts +4 -0
  34. package/dist/types/modify_collections.d.ts +5 -0
  35. package/dist/types/plugins.d.ts +277 -0
  36. package/dist/types/property_config.d.ts +74 -0
  37. package/dist/types/property_options.d.ts +255 -0
  38. package/dist/types/slots.d.ts +279 -0
  39. package/dist/types/translations.d.ts +989 -0
  40. package/dist/types/user_management_delegate.d.ts +22 -0
  41. package/package.json +103 -0
  42. package/src/admin_collection.ts +775 -0
  43. package/src/augment.ts +79 -0
  44. package/src/collections.ts +312 -0
  45. package/src/controllers/analytics_controller.tsx +57 -0
  46. package/src/controllers/auth.ts +122 -0
  47. package/src/controllers/customization_controller.tsx +81 -0
  48. package/src/controllers/dialogs_controller.tsx +37 -0
  49. package/src/controllers/index.ts +10 -0
  50. package/src/controllers/local_config_persistence.tsx +22 -0
  51. package/src/controllers/navigation.ts +288 -0
  52. package/src/controllers/registry.ts +114 -0
  53. package/src/controllers/side_dialogs_controller.tsx +82 -0
  54. package/src/controllers/side_panel_controller.tsx +112 -0
  55. package/src/controllers/snackbar.ts +51 -0
  56. package/src/index.ts +20 -0
  57. package/src/react_component_ref.ts +52 -0
  58. package/src/rebase_context.ts +81 -0
  59. package/src/types/breadcrumbs.ts +16 -0
  60. package/src/types/builders.ts +18 -0
  61. package/src/types/collection_views.tsx +125 -0
  62. package/src/types/component_overrides.ts +244 -0
  63. package/src/types/entity_actions.tsx +134 -0
  64. package/src/types/entity_display.ts +182 -0
  65. package/src/types/entity_link_builder.ts +8 -0
  66. package/src/types/entity_views.tsx +135 -0
  67. package/src/types/export_import.ts +26 -0
  68. package/src/types/form_layout.ts +137 -0
  69. package/src/types/formex.ts +45 -0
  70. package/src/types/index.ts +18 -0
  71. package/src/types/locales.ts +81 -0
  72. package/src/types/modify_collections.tsx +6 -0
  73. package/src/types/plugins.tsx +346 -0
  74. package/src/types/property_config.tsx +97 -0
  75. package/src/types/property_options.ts +300 -0
  76. package/src/types/slots.tsx +334 -0
  77. package/src/types/translations.ts +1104 -0
  78. package/src/types/user_management_delegate.ts +23 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rebase
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,650 @@
1
+ /**
2
+ * The typed admin block, and the type you author a collection against.
3
+ *
4
+ * A collection is one file. Schema, security rules and callbacks sit at the top
5
+ * level, where the backend reads them; everything the admin panel renders sits
6
+ * under `admin`. `@rebasepro/types` does not declare that field at all — naming a
7
+ * kanban column definition would drag `React.ReactNode` back into the BaaS
8
+ * contract, and a server has no use for one. `augment.ts` in this package declares
9
+ * it, by declaration merging, onto core's `CollectionConfig`. So this is the other
10
+ * side of that boundary: the 38 fields, fully typed, in the package where React
11
+ * exists, and reachable only by a program that has opted in.
12
+ *
13
+ * Each field is declared exactly once, here. Core does not carry a React-free
14
+ * skeleton of the same shape; two definitions that agree only by luck is the
15
+ * `WhereFilterOp` mistake, and this block is far bigger than one union.
16
+ */
17
+ import type React from "react";
18
+ import type { CollectionConfig, ComponentRef, FilterPreset, FilterValues, FirebaseCollectionConfig, FirebaseProperties, InferEntityType, MongoDBCollectionConfig, MongoProperties, OrderBySpec, PostgresCollectionConfig, PostgresProperties, User } from "@rebasepro/types";
19
+ import type { AdditionalFieldDelegate, CollectionActionsProps, CollectionSize, DefaultSelectedViewBuilder, KanbanConfig, SelectionController, ViewMode } from "./collections.js";
20
+ import type { EntityCustomView, FormViewConfig } from "./types/entity_views.js";
21
+ import type { CollectionCustomView } from "./types/collection_views.js";
22
+ import type { EntityDisplay } from "./types/entity_display.js";
23
+ import type { FormLayoutConfig } from "./types/form_layout.js";
24
+ import type { EntityAction } from "./types/entity_actions.js";
25
+ import type { ExportConfig } from "./types/export_import.js";
26
+ import type { CollectionComponentOverrideMap } from "./types/component_overrides.js";
27
+ /**
28
+ * A key naming one of `M`'s fields, or a dotted path into a `map` field.
29
+ *
30
+ * Both forms are resolved with `getValueInPath`, so `"profile.displayName"` is
31
+ * as valid as `"title"`. Only the *root* is checked — the path below it is a
32
+ * nested `Properties` object this type has no view of — which is enough to
33
+ * reject the mistake that actually happens: a misspelled or removed field.
34
+ *
35
+ * When `M` is the default `Record<string, unknown>` — the plain
36
+ * `const x: PostgresCollectionConfig = { … }` annotation, which infers nothing —
37
+ * `Extract<keyof M, string>` is `string` and this accepts anything, exactly as
38
+ * before. `defineCollection` is what supplies a real `M` and turns the check on.
39
+ */
40
+ export type PropertyPath<M> = Extract<keyof M, string> | `${Extract<keyof M, string>}.${string}`;
41
+ /**
42
+ * The `display` block for a collection, with its property paths checked
43
+ * against `M`.
44
+ *
45
+ * `EntityDisplay` is generic over the path type so that
46
+ * `@rebasepro/cms-types`' two halves do not import each other in a cycle;
47
+ * this alias is what an authoring site actually names.
48
+ */
49
+ export type CollectionDisplay<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = EntityDisplay<PropertyPath<M>, M, USER>;
50
+ /**
51
+ * A key naming a *column* in the list view: a property path, a child-collection
52
+ * column, or the `key` of one of this collection's `additionalFields`.
53
+ *
54
+ * `AdditionalFieldDelegate.key` is a plain `string`, and the block is not
55
+ * generic over its own `additionalFields`, so there is no type-level channel
56
+ * carrying those keys here. Accepting any string to cover them is what made this
57
+ * field unchecked in the first place; instead the two provable arms are closed
58
+ * and {@link AdditionalFieldKey} is the explicit, castable escape.
59
+ */
60
+ export type ColumnKey<M> = PropertyPath<M> | `subcollection:${string}` | AdditionalFieldKey;
61
+ /**
62
+ * Opt-out for a `propertiesOrder` / `listProperties` entry that names an
63
+ * `additionalFields` key rather than a property.
64
+ *
65
+ * The brand is **required**, which is the entire mechanism: a bare `"score"` is
66
+ * not assignable, so the entry has to be written `"score" as AdditionalFieldKey`
67
+ * — a visible admission that this key is not a property. An optional brand
68
+ * (`__additionalFieldKey?: never`) would be satisfied by every string and put us
69
+ * straight back to accepting typos.
70
+ *
71
+ * ```ts
72
+ * propertiesOrder: ["title", "score" as AdditionalFieldKey]
73
+ * ```
74
+ */
75
+ export type AdditionalFieldKey = string & {
76
+ readonly __additionalFieldKey: true;
77
+ };
78
+ /**
79
+ * Admin-panel presentation and behaviour for a collection.
80
+ *
81
+ * A `type` rather than an `interface`, and that is load-bearing: TypeScript gives
82
+ * an implicit index signature to an object *type alias* but not to an interface.
83
+ * `toAdminCollectionConfig` has to widen a collection carrying this block to
84
+ * `Record<string, unknown>` in order to move the flattened keys back under
85
+ * `admin`, and as an interface that conversion is an error (TS2352, "index
86
+ * signature for type 'string' is missing"). Flipping it and running
87
+ * `pnpm typecheck` reproduces that in one line.
88
+ *
89
+ * Declaration merging is not wanted here anyway; a plugin adding fields to the
90
+ * block would have nothing reading them.
91
+ *
92
+ * @group Models
93
+ */
94
+ export type AdminCollectionOptions<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
95
+ /**
96
+ * Icon for the navigation sidebar or cards.
97
+ *
98
+ * Either a Lucide icon name (`"FileText"`, `"ShoppingCart"`) or a rendered
99
+ * element. Prefer the name: it survives serialization, so the collection file
100
+ * stays loadable by the backend and by `rebase generate-sdk`, and it is what
101
+ * the schema editor writes back.
102
+ */
103
+ icon?: string | React.ReactNode;
104
+ /**
105
+ * Navigation group for this collection.
106
+ * Collections sharing the same group name will be visually grouped
107
+ * together in the drawer and home page. If not set, the collection
108
+ * falls into the default "Views" group.
109
+ */
110
+ group?: string;
111
+ /**
112
+ * Array of entity views that this collection has.
113
+ * Can be an array of `EntityCustomView` or a string representing the key of a global `EntityCustomView`.
114
+ */
115
+ entityViews?: (string | EntityCustomView<Record<string, unknown>>)[];
116
+ /**
117
+ * Default preview properties displayed when this collection is referenced to.
118
+ */
119
+ previewProperties?: Extract<keyof M, string>[];
120
+ /**
121
+ * Properties to display as columns in the list view.
122
+ * If not specified, the list view uses a smart default (Title, Status, Date).
123
+ */
124
+ listProperties?: ColumnKey<M>[];
125
+ /**
126
+ * How a record of this collection shows up — its title, subtitle, image,
127
+ * status, date and tags.
128
+ *
129
+ * Each role takes a property path or a resolver, and a resolver may be
130
+ * async:
131
+ *
132
+ * ```ts
133
+ * display: {
134
+ * title: "name",
135
+ * image: "cover.url",
136
+ * subtitle: ({ entity }) => `${entity.values.city}, ${entity.values.country}`,
137
+ * status: async ({ entity, context }) =>
138
+ * (await context.data.audits.get(`${entity.id}/latest`))?.state
139
+ * }
140
+ * ```
141
+ *
142
+ * Every role left out is derived from the property schema exactly as before,
143
+ * so a collection that says nothing renders as it always did. See
144
+ * {@link EntityDisplay} for what each role means and
145
+ * {@link EntityDisplayResolver} for what a resolver is handed.
146
+ */
147
+ readonly display?: EntityDisplay<PropertyPath<M>, M, USER>;
148
+ /**
149
+ * When editing a entity, you can choose to open the entity in a side dialog
150
+ * or in a full screen dialog. Defaults to `full_screen`.
151
+ */
152
+ openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
153
+ /**
154
+ * Controls what happens when a user clicks on a entity in the collection view.
155
+ * - `"edit"` (default): Opens the entity in the edit form.
156
+ * - `"view"`: Opens a read-only detail view with an "Edit" button.
157
+ */
158
+ defaultEntityAction?: "view" | "edit";
159
+ /**
160
+ * Replace the default entity form with a custom component.
161
+ * The Builder receives the same props as entity view tabs
162
+ * (entity, formContext, collection, etc.) and has full control over the UI.
163
+ *
164
+ * Works in both edit mode and read-only mode (when `defaultEntityAction`
165
+ * is `"view"`). In read-only mode, `formContext.readOnly` will be `true`.
166
+ */
167
+ formView?: FormViewConfig;
168
+ /**
169
+ * How the generated form is laid out: which properties are grouped into
170
+ * sections in the main column, and which are pulled out into the metadata
171
+ * rail beside it.
172
+ *
173
+ * Entirely optional. With no `form` block the layout is derived from the
174
+ * properties themselves — see {@link FormLayoutConfig} — which is what most
175
+ * collections should rely on. Reach for this when the derived grouping is
176
+ * wrong for your domain, not to restate it.
177
+ *
178
+ * Unlike {@link FormViewConfig}, this does not replace the generated form:
179
+ * every field keeps its validation, error focus, local-changes restore and
180
+ * autosave wiring.
181
+ */
182
+ form?: FormLayoutConfig<M>;
183
+ /**
184
+ * Prevent default actions from being displayed or executed on this collection.
185
+ */
186
+ disableDefaultActions?: ("edit" | "copy" | "delete")[];
187
+ /**
188
+ * Order in which the properties are displayed.
189
+ * If you are specifying your collection as code, the order is the same as the
190
+ * one you define in `properties`. Additional columns are added at the
191
+ * end of the list, if the order is not specified.
192
+ *
193
+ * You can use this prop to hide some properties from the table view.
194
+ * Note that if you set this prop, other ways to hide fields, like
195
+ * `hidden` in the property definition, will be ignored.
196
+ * `propertiesOrder` has precedence over `hidden`.
197
+ *
198
+ * Supported entry formats:
199
+ * - For properties, use the property key.
200
+ * - For additional fields, use the field key.
201
+ * - Child collections (Firestore subcollections, or Postgres relations
202
+ * with `many` cardinality) each get a column with id
203
+ * `subcollection:<slug>`, e.g. `subcollection:orders`.
204
+ */
205
+ propertiesOrder?: ColumnKey<M>[];
206
+ /**
207
+ * If enabled, content is loaded in batches. If `false` all entities in the
208
+ * collection are loaded. This means that when reaching the end of the
209
+ * collection, the admin will load more entities.
210
+ * You can specify a number to specify the pagination size (50 by default)
211
+ * Defaults to `true`
212
+ */
213
+ pagination?: boolean | number;
214
+ selectionEnabled?: boolean;
215
+ /**
216
+ * Pass your own selection controller if you want to control selected
217
+ * entities externally.
218
+ * @see useSelectionController
219
+ */
220
+ selectionController?: SelectionController<M>;
221
+ /**
222
+ * Force a filter in this view. If applied, the rest of the filters will
223
+ * be disabled. Filters applied with this prop cannot be changed.
224
+ * e.g. `fixedFilter: { age: [">", 18] }`
225
+ * e.g. `fixedFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
226
+ */
227
+ readonly fixedFilter?: FilterValues<PropertyPath<M>>;
228
+ /**
229
+ * Initial filters applied to the collection this collection is related to.
230
+ * Defaults to none. Filters applied with this prop can be changed.
231
+ * e.g. `defaultFilter: { age: [">", 18] }`
232
+ * e.g. `defaultFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
233
+ */
234
+ readonly defaultFilter?: FilterValues<PropertyPath<M>>;
235
+ /**
236
+ * Pre-defined filter presets that appear as quick-access options in the
237
+ * collection toolbar. Each preset applies a set of filters (and
238
+ * optionally a sort order) with a single click.
239
+ *
240
+ * ```ts
241
+ * filterPresets: [
242
+ * {
243
+ * label: "Shipped this month",
244
+ * filterValues: {
245
+ * status: ["==", "shipped"],
246
+ * order_date: [">=", new Date(Date.now() - 30 * 86400000)]
247
+ * }
248
+ * }
249
+ * ]
250
+ * ```
251
+ */
252
+ readonly filterPresets?: FilterPreset<PropertyPath<M>>[];
253
+ /**
254
+ * Default sort applied to this collection.
255
+ * When setting this prop, entities will have a default order
256
+ * applied in the collection.
257
+ *
258
+ * One key, or several applied in order of significance — the second breaks
259
+ * ties on the first, and so on. The row id breaks the last tie, so the
260
+ * order is total and paging over it neither repeats nor skips rows.
261
+ *
262
+ * @example sort: ["order", "asc"]
263
+ * @example sort: [["roles", "asc"], ["createdAt", "desc"]]
264
+ */
265
+ readonly sort?: OrderBySpec<PropertyPath<M>>;
266
+ /**
267
+ * You can add additional fields to the collection view by implementing
268
+ * an additional field delegate.
269
+ */
270
+ readonly additionalFields?: AdditionalFieldDelegate<M, USER>[];
271
+ /**
272
+ * Default size of the rendered collection
273
+ */
274
+ defaultSize?: CollectionSize;
275
+ /**
276
+ * Can the elements in this collection be edited inline in the collection
277
+ * view. Even when inline editing is disabled, entities can still be
278
+ * edited in the side panel (subject to `securityRules`).
279
+ */
280
+ inlineEditing?: boolean;
281
+ /**
282
+ * Should this collection be hidden from the main navigation panel, if
283
+ * it is at the root level, or in the entity side panel if it's a
284
+ * subcollection.
285
+ * It will still be accessible if you reach the specified path.
286
+ * You can also use this collection as a reference target.
287
+ *
288
+ * Note that this covers *both* roles at once. A collection that is a root
289
+ * collection **and** the target of a many-relation is hidden in both places,
290
+ * which is rarely what you want for a join or audit table: it should not be
291
+ * a destination in the drawer, but it is exactly what you want to see on its
292
+ * parent. Use {@link hideFromEntityViews} to separate the two.
293
+ */
294
+ hideFromNavigation?: boolean;
295
+ /**
296
+ * Should this collection be hidden from the tab strip of a parent entity,
297
+ * when it is reached as a child view (a Firestore subcollection, or the
298
+ * target of a `many`-cardinality relation).
299
+ *
300
+ * Independent of {@link hideFromNavigation}, which governs the drawer. The
301
+ * two exist separately because a collection commonly plays both roles and
302
+ * wants a different answer for each:
303
+ *
304
+ * - a join table (`company_members`) is not a destination but *is* a
305
+ * meaningful tab → `hideFromNavigation: true`, this left unset;
306
+ * - a table with a dedicated workspace (`scraped_jobs`) may want the
307
+ * opposite, so the workspace stays the only way in.
308
+ *
309
+ * Defaults to `false`. Setting {@link hideFromNavigation} does not imply it.
310
+ */
311
+ hideFromEntityViews?: boolean;
312
+ /**
313
+ * If you want to open custom views or subcollections by default when opening the edit
314
+ * view of a entity, you can specify the path to the view here.
315
+ * The path is relative to the current collection. For example if you have a collection
316
+ * that has a custom view as well as a subcollection that refers to another entity, you can
317
+ * either specify the path to the custom view or the path to the subcollection.
318
+ */
319
+ defaultSelectedView?: string | DefaultSelectedViewBuilder;
320
+ /**
321
+ * Should the ID of this collection be hidden from the form view.
322
+ */
323
+ hideIdFromForm?: boolean;
324
+ /**
325
+ * Should the ID of this collection be hidden from the grid view.
326
+ */
327
+ hideIdFromCollection?: boolean;
328
+ /**
329
+ * If set to true, the form will be auto-saved when the user changes
330
+ * the value of a field.
331
+ * Defaults to false.
332
+ * When a new entity is created, this property can be updated to generated a new ID
333
+ */
334
+ formAutoSave?: boolean;
335
+ /**
336
+ *
337
+ */
338
+ exportable?: boolean | ExportConfig<USER>;
339
+ /**
340
+ * Width of the side dialog (in pixels) when opening a entity in this collection.
341
+ */
342
+ sideDialogWidth?: number | string;
343
+ /**
344
+ * If set to true, the default values of the properties will be applied
345
+ * to the entity every time the entity is updated (not only when created).
346
+ * Defaults to false.
347
+ */
348
+ alwaysApplyDefaultValues?: boolean;
349
+ /**
350
+ * If set to true, a tab including the JSON representation of the entity will be included.
351
+ */
352
+ includeJsonView?: boolean;
353
+ /**
354
+ * Should local changes be backed up in local storage, to prevent data loss on
355
+ * accidental navigations.
356
+ * - `manual_apply`: When the user navigates back to a entity with local changes,
357
+ * they will be prompted to restore the changes.
358
+ * - `auto_apply`: When the user navigates back to a entity with local changes,
359
+ * the changes will be automatically applied.
360
+ * - `false`: Local changes will not be backed up.
361
+ * Defaults to `manual_apply`.
362
+ */
363
+ localChangesBackup?: "manual_apply" | "auto_apply" | false;
364
+ /**
365
+ * Default view mode for displaying this collection.
366
+ * - "list": Display entities as a list (default)
367
+ * - "table": Display entities in a table with inline editing
368
+ * - "cards": Display entities as a grid of cards with thumbnails
369
+ * - "kanban": Display entities in a Kanban board grouped by a property
370
+ * - any `key` from {@link customViews}
371
+ * Defaults to "list".
372
+ */
373
+ defaultViewMode?: ViewMode;
374
+ /**
375
+ * Which view modes are available for this collection.
376
+ * Possible values: "list", "table", "cards", "kanban", and any `key` from
377
+ * {@link customViews}.
378
+ * Defaults to all four built-ins plus every declared custom view.
379
+ * Note: "kanban" will only be available if the collection has at least
380
+ * one string property with `enum` defined, regardless of this setting.
381
+ * With a single entry the view switcher is hidden.
382
+ */
383
+ enabledViews?: ViewMode[];
384
+ /**
385
+ * Additional ways to render this collection's rows, offered in the view
386
+ * switcher beside list / table / cards / kanban.
387
+ *
388
+ * Can be an array of `CollectionCustomView` or a string naming the `key` of
389
+ * one registered globally on `<RebaseCMS collectionViews={…}>`. The
390
+ * string form is what lets a React-free config package reference React UI,
391
+ * and it is what the collection editor stores.
392
+ *
393
+ * A custom view is another rendering of the *same query* — it is handed the
394
+ * live table controller and inherits filters, search and the entity side
395
+ * panel. Use an `AppView` instead for a workflow spanning collections.
396
+ *
397
+ * @example
398
+ * ```ts
399
+ * admin: {
400
+ * customViews: [
401
+ * { key: "map", name: "Map", icon: "Map", Builder: MapView }
402
+ * ],
403
+ * enabledViews: ["table", "map"],
404
+ * defaultViewMode: "map"
405
+ * }
406
+ * ```
407
+ */
408
+ customViews?: (string | CollectionCustomView<Record<string, unknown>>)[];
409
+ /**
410
+ * Configuration for Kanban board view mode.
411
+ * When set, the Kanban view mode becomes available.
412
+ *
413
+ * A board is only half-configured without {@link orderProperty}. Cards
414
+ * still drag between columns — that writes `columnProperty` — but their
415
+ * order *within* a column has nowhere to be stored, so it resets on the
416
+ * next read and the board renders a warning bar saying so. Declare both,
417
+ * always.
418
+ */
419
+ kanban?: KanbanConfig<M>;
420
+ /**
421
+ * Property key to use for ordering items.
422
+ *
423
+ * Must reference a **string** property — a `number` can never hold one of
424
+ * these keys, so a numeric `sortOrder` leaves the board permanently asking
425
+ * to be initialised. The convention across the collections here is a
426
+ * hidden `__order: { type: "string", admin: { disabled: true,
427
+ * hideFromCollection: true } }`.
428
+ *
429
+ * Reordering writes a `fractional-indexing` key built from the base36,
430
+ * lower-case alphabet `0123456789abcdefghijklmnopqrstuvwxyz` — `"i0"`,
431
+ * `"i1"`, `"i0i"`. Single case because *Postgres* does the sorting and its
432
+ * default collation is not byte ordering; base36 rather than the library's
433
+ * default base62 for the same reason. Generating a key without passing
434
+ * that alphabet yields base62 keys (`"a0"`), which this board rejects.
435
+ *
436
+ * Nothing assigns a key on insert. A row created by a cron, a seed, a
437
+ * migration or the REST API lands with this property null, and the board
438
+ * shows an **Initialize** bar until someone clicks it. Backends that
439
+ * create rows for a board should append a key themselves — see the
440
+ * "Kanban boards" section of the `rebase-collections` skill.
441
+ *
442
+ * Used by Kanban view for ordering within columns and can be used for
443
+ * general ordering purposes.
444
+ */
445
+ readonly orderProperty?: Extract<keyof M, string>;
446
+ /**
447
+ * Actions that can be performed on the entities in this collection.
448
+ *
449
+ * An entry may be the action itself, or the `key` of one registered app-level
450
+ * on `<RebaseCMS entityActions={…}>` — `resolveEntityAction` looks a string
451
+ * up against that list.
452
+ *
453
+ * The key form is what lets a collection declared in a React-free config
454
+ * package use an action whose UI is React: an action carries an `onClick` and
455
+ * usually renders a dialog, so importing one into a collection file pulls the
456
+ * admin bundle into any backend that loads it for its schema. Naming it costs
457
+ * nothing there.
458
+ *
459
+ * `string` was accepted at runtime and by the collection editor — which stores
460
+ * exactly these keys — long before the type said so, which meant the documented
461
+ * approach needed a cast. Mirrors `entityViews`, typed this way already.
462
+ */
463
+ entityActions?: (string | EntityAction<M, USER>)[];
464
+ /**
465
+ * Builder for the collection actions rendered in the toolbar
466
+ */
467
+ Actions?: ComponentRef<CollectionActionsProps>[];
468
+ /**
469
+ * Collection-scoped component overrides. These take precedence over
470
+ * global overrides set on `<Rebase>`, but only within this collection's
471
+ * views (entity form, detail view, table, empty state, etc.).
472
+ *
473
+ * Only collection-scoped components (like `Entity.Form`, `Collection.EmptyState`,
474
+ * `Collection.Card`, etc.) can be overridden here. App-level components
475
+ * (like `Shell.AppBar`, `HomePage`) can only be overridden at the `<Rebase>` level.
476
+ *
477
+ * @example
478
+ * ```tsx
479
+ * const productsCollection: PostgresCollectionConfig = {
480
+ * name: "Products",
481
+ * slug: "products",
482
+ * table: "products",
483
+ * components: {
484
+ * "Entity.Form": { Component: ProductCustomForm },
485
+ * "Collection.Card": { Component: ProductCard },
486
+ * },
487
+ * properties: { ... }
488
+ * };
489
+ * ```
490
+ */
491
+ components?: CollectionComponentOverrideMap;
492
+ };
493
+ /**
494
+ * There is deliberately no `AdminCollectionConfig` here any more.
495
+ *
496
+ * It used to be `Omit<CollectionConfig, "admin"> & { admin?: AdminCollectionOptions }`,
497
+ * a wrapper that existed because core typed the block opaquely. Now that `augment.ts`
498
+ * declares `admin` directly on `BaseCollectionConfig`, `CollectionConfig` *is* the
499
+ * authoring type — the wrapper would be an alias of it, and a second name for one thing
500
+ * is what this whole refactor has been removing.
501
+ *
502
+ * A project opts its program in with one line, once:
503
+ *
504
+ * ```ts
505
+ * /// <reference types="@rebasepro/cms-types" />
506
+ * ```
507
+ *
508
+ * after which `admin` is typed on every collection and every property. Without it,
509
+ * writing one is an error — which is the guarantee a BaaS install depends on.
510
+ */
511
+ /**
512
+ * Define a collection with the admin block type-checked.
513
+ *
514
+ * The same identity function as `defineCollection` in `@rebasepro/common` — which
515
+ * is what a BaaS or headless project uses, and where `admin` does not exist at all
516
+ * — with one difference: importing this one brings the augmentation with it, so
517
+ * `admin: { icon, listProperties, kanban }` gets completion and a typo is an
518
+ * error. See {@link AdminCollectionOptions}.
519
+ *
520
+ * Import it from the layer you are in. A project with an admin panel wants this
521
+ * one; a project without one has no `admin` block to check.
522
+ *
523
+ * `const P` captures the literal property types, which is what gives
524
+ * `admin.display`, `admin.sort` and `admin.propertiesOrder` completion over
525
+ * the collection's own property keys rather than plain `string`.
526
+ *
527
+ * @example
528
+ * export default defineCollection({
529
+ * slug: "posts",
530
+ * table: "posts",
531
+ * properties: {
532
+ * title: { name: "Title", type: "string" },
533
+ * status: { name: "Status", type: "string" }
534
+ * },
535
+ * admin: {
536
+ * icon: "FileText",
537
+ * display: { title: "title" }, // completion: "title" | "status"
538
+ * listProperties: ["title", "status"]
539
+ * }
540
+ * });
541
+ *
542
+ * @group Builder
543
+ */
544
+ export declare function defineCollection<const P extends PostgresProperties, USER extends User = User>(collection: Omit<PostgresCollectionConfig<InferEntityType<P>, USER>, "properties"> & {
545
+ properties: P;
546
+ }): PostgresCollectionConfig<InferEntityType<P>, USER> & {
547
+ properties: P;
548
+ };
549
+ /** Define a Firestore-backed collection with the admin block checked. @group Builder */
550
+ export declare function defineCollection<const P extends FirebaseProperties, USER extends User = User>(collection: Omit<FirebaseCollectionConfig<InferEntityType<P>, USER>, "properties"> & {
551
+ properties: P;
552
+ }): FirebaseCollectionConfig<InferEntityType<P>, USER> & {
553
+ properties: P;
554
+ };
555
+ /** Define a MongoDB-backed collection with the admin block checked. @group Builder */
556
+ export declare function defineCollection<const P extends MongoProperties, USER extends User = User>(collection: Omit<MongoDBCollectionConfig<InferEntityType<P>, USER>, "properties"> & {
557
+ properties: P;
558
+ }): MongoDBCollectionConfig<InferEntityType<P>, USER> & {
559
+ properties: P;
560
+ };
561
+ /**
562
+ * Re-exported from `@rebasepro/types`, where the list has to live: the ts-morph
563
+ * schema editor in `@rebasepro/server` needs it to know which keys go inside the
564
+ * block when it rewrites a collection file, and a core package may not import
565
+ * this one. The list is plain data, so core is a fine home for it.
566
+ *
567
+ * What core *cannot* do is check the list against the type. That happens here.
568
+ *
569
+ * @group Models
570
+ */
571
+ export type { AdminCollectionKey } from "@rebasepro/types";
572
+ /**
573
+ * Core's list, re-exported through a `satisfies` clause that is the agreement
574
+ * check: a key core names that is not an option here fails to compile, and
575
+ * `satisfies` keeps the literal tuple type rather than widening it to `string[]`.
576
+ *
577
+ * The reverse direction — an option missing from core's list — has no type-level
578
+ * expression, since there is no exhaustiveness check over an optional-property
579
+ * keyof. `test/admin_collection.test.ts` counts them instead.
580
+ */
581
+ export declare const ADMIN_COLLECTION_KEYS: readonly ["Actions", "additionalFields", "alwaysApplyDefaultValues", "components", "customViews", "defaultEntityAction", "defaultFilter", "defaultSelectedView", "defaultSize", "defaultViewMode", "disableDefaultActions", "display", "enabledViews", "entityActions", "entityViews", "exportable", "filterPresets", "fixedFilter", "form", "formAutoSave", "formView", "group", "hideFromEntityViews", "hideFromNavigation", "hideIdFromCollection", "hideIdFromForm", "icon", "includeJsonView", "inlineEditing", "kanban", "listProperties", "localChangesBackup", "openEntityMode", "orderProperty", "pagination", "previewProperties", "propertiesOrder", "selectionController", "selectionEnabled", "sideDialogWidth", "sort"];
582
+ /**
583
+ * A collection as the admin panel works with it: the contract with the `admin`
584
+ * block flattened onto the top level.
585
+ *
586
+ * The panel reads presentation fields in a few hundred places, and threading
587
+ * `collection.admin?.propertiesOrder` through all of them would be noise that
588
+ * buys nothing — the panel has already resolved the collection by then, merging
589
+ * the declared config with the user's per-collection overrides from local
590
+ * storage. So the panel gets a flat *view model*, exactly as it already does for
591
+ * entities (`Entity` is an admin view model over flat rows, not a wire type).
592
+ *
593
+ * The distinction that matters is direction:
594
+ *
595
+ * - **Reading** a resolved collection → `AdminCollection` (flat, convenient).
596
+ * - **Authoring or persisting** one → core's `CollectionConfig`, with the `admin`
597
+ * block this package augments onto it (nested, which is what the file on disk
598
+ * and the wire both look like).
599
+ *
600
+ * `admin` is kept alongside the flattened fields so the collection editor can
601
+ * still see the block it has to write back.
602
+ *
603
+ * @group Models
604
+ */
605
+ export type AdminCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = WithFlatAdmin<CollectionConfig<M, USER>, M, USER>;
606
+ /**
607
+ * Flatten the admin block onto one member of the collection union at a time.
608
+ *
609
+ * `CollectionConfig` is a union discriminated on `engine`
610
+ * (Postgres | Firestore | MongoDB), and a bare `Omit<Union, "admin">` collapses it
611
+ * into a single object type with the discriminant widened. The result stops being
612
+ * assignable back to `CollectionConfig`, so every call that hands a resolved
613
+ * collection to a core function fails — which is exactly what happened. The
614
+ * `C extends unknown` clause makes the mapping distributive, so each member keeps
615
+ * its literal `engine` and stays assignable to its counterpart.
616
+ */
617
+ type WithFlatAdmin<C, M extends Record<string, unknown>, USER extends User> = C extends unknown ? Omit<C, "admin"> & AdminCollectionOptions<M, USER> & {
618
+ admin?: AdminCollectionOptions<M, USER>;
619
+ } : never;
620
+ /** {@link AdminCollection} for a Postgres collection. @group Models */
621
+ export type AdminPostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = Omit<PostgresCollectionConfig<M, USER>, "admin"> & AdminCollectionOptions<M, USER> & {
622
+ admin?: AdminCollectionOptions<M, USER>;
623
+ };
624
+ /**
625
+ * Flatten a collection's `admin` block onto it, producing the panel's view model.
626
+ *
627
+ * Shallow by design: the block's fields are independent, so a deep merge would
628
+ * only create opportunities for a nested object to be half from one source and
629
+ * half from the other. `admin` survives on the result.
630
+ *
631
+ * Idempotent — flattening an already-flat collection returns an equivalent one —
632
+ * because the panel resolves collections at more than one entry point (the
633
+ * registry, `<Rebase collections>`, a plugin's `modifyCollection`) and they must
634
+ * not fight over which has run.
635
+ */
636
+ export declare function resolveAdminCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: CollectionConfig<M, USER> | AdminCollection<M, USER>): AdminCollection<M, USER>;
637
+ /**
638
+ * The inverse: lift flattened admin fields back into the block.
639
+ *
640
+ * Used on the way out — persisting from the collection editor, or handing a
641
+ * collection to anything that expects the authoring shape. Any key in
642
+ * {@link ADMIN_COLLECTION_KEYS} found at the top level is moved down, so a
643
+ * round trip through the panel does not leave the file flat.
644
+ *
645
+ * The nesting itself lives in `@rebasepro/types` because the schema editor in
646
+ * `@rebasepro/server` — which cannot import this package — has to do exactly the
647
+ * same thing when it writes a collection file back to disk. Two copies of the
648
+ * rule disagreed on which side wins, and the disagreement was invisible.
649
+ */
650
+ export declare function toAdminCollectionConfig<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: AdminCollection<M, USER> | CollectionConfig<M, USER>): CollectionConfig<M, USER>;