@rebasepro/types 0.30.1 → 0.31.0-canary.g59cd6fd

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 (57) hide show
  1. package/README.md +16 -18
  2. package/dist/call_context.d.ts +3 -3
  3. package/dist/controllers/client.d.ts +29 -0
  4. package/dist/controllers/data.d.ts +85 -332
  5. package/dist/controllers/data_driver.d.ts +47 -57
  6. package/dist/controllers/index.d.ts +0 -3
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.es.js +2567 -1151
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/schema/column_options.d.ts +336 -0
  11. package/dist/schema/column_type.d.ts +116 -0
  12. package/dist/schema/columns.d.ts +646 -0
  13. package/dist/schema/compiled.d.ts +114 -0
  14. package/dist/schema/descriptor.d.ts +349 -0
  15. package/dist/schema/hooks.d.ts +164 -0
  16. package/dist/schema/index.d.ts +13 -0
  17. package/dist/schema/infer.d.ts +340 -0
  18. package/dist/schema/json.d.ts +237 -0
  19. package/dist/schema/relations.d.ts +205 -0
  20. package/dist/schema/table.d.ts +304 -0
  21. package/dist/schema/table_options.d.ts +103 -0
  22. package/dist/schema/table_patch.d.ts +338 -0
  23. package/dist/types/auth_adapter.d.ts +5 -5
  24. package/dist/types/auth_hooks.d.ts +65 -0
  25. package/dist/types/backend.d.ts +85 -96
  26. package/dist/types/data_source.d.ts +4 -9
  27. package/dist/types/database_adapter.d.ts +30 -31
  28. package/dist/types/entities.d.ts +0 -162
  29. package/dist/types/filter-operators.d.ts +2 -26
  30. package/dist/types/history.d.ts +6 -9
  31. package/dist/types/index.d.ts +3 -9
  32. package/dist/types/mcp_app_modules.d.ts +0 -2
  33. package/dist/types/policy.d.ts +85 -10
  34. package/dist/types/project_manifest.d.ts +113 -46
  35. package/dist/types/read_query.d.ts +98 -0
  36. package/dist/types/register.d.ts +35 -5
  37. package/dist/types/relations.d.ts +0 -430
  38. package/dist/types/schema_editing.d.ts +54 -2
  39. package/dist/types/schema_version.d.ts +24 -4
  40. package/dist/types/security_rules.d.ts +225 -15
  41. package/dist/types/storage_authorize.d.ts +2 -2
  42. package/dist/types/tenancy.d.ts +3 -3
  43. package/dist/types/ui_preferences.d.ts +228 -0
  44. package/package.json +3 -2
  45. package/dist/controllers/auth_state.d.ts +0 -23
  46. package/dist/controllers/collection_registry.d.ts +0 -67
  47. package/dist/controllers/effective_role.d.ts +0 -4
  48. package/dist/types/admin_block.d.ts +0 -96
  49. package/dist/types/chips.d.ts +0 -16
  50. package/dist/types/collection_contract.d.ts +0 -43
  51. package/dist/types/collection_patch.d.ts +0 -74
  52. package/dist/types/collections.d.ts +0 -783
  53. package/dist/types/component_ref.d.ts +0 -81
  54. package/dist/types/conditions-contract.types.d.ts +0 -14
  55. package/dist/types/entity_callbacks.d.ts +0 -393
  56. package/dist/types/indexes.d.ts +0 -179
  57. package/dist/types/properties.d.ts +0 -1640
@@ -15,12 +15,27 @@
15
15
  * them with `getPolicyNamesForRule`/`getEffectiveSecurityRules` rather than
16
16
  * matching on `rule.name`.
17
17
  */
18
- import type { PolicyExpression } from "./policy.js";
18
+ import type { PolicyCondition } from "./policy.js";
19
19
  /**
20
20
  * SQL operation that a policy applies to.
21
21
  * @group Models
22
22
  */
23
23
  export type SecurityOperation = "select" | "insert" | "update" | "delete" | "all";
24
+ /**
25
+ * Who a rule's `access` shortcut admits.
26
+ *
27
+ * - `"public"` — every caller who reaches the database, signed in or not.
28
+ * - `"authenticated"` — a signed-in caller: the `rebase.uid()` is neither the
29
+ * server context's `NULL` nor an anonymous visitor's sentinel (see
30
+ * `policy.authenticated()`). On a project with anonymous sign-in this
31
+ * includes guests: a guest session has a real uid.
32
+ * - `"registered"` — a signed-in caller who has an account: `"authenticated"`
33
+ * minus guest sessions (see `policy.registered()`). What most rules meaning
34
+ * "a signed-in person" want on a project with anonymous sign-in enabled.
35
+ *
36
+ * @group Models
37
+ */
38
+ export type SecurityRuleAccess = "public" | "authenticated" | "registered";
24
39
  /**
25
40
  * Flexible Row Level Security rule for a collection.
26
41
  *
@@ -39,10 +54,11 @@ export type SecurityOperation = "select" | "insert" | "update" | "delete" | "all
39
54
  * operation. Permissive rules are OR'd together (any one passing is enough).
40
55
  * Restrictive rules are AND'd (all must pass). This is standard PostgreSQL RLS behavior.
41
56
  *
42
- * **Mutual exclusivity:** `ownerField`, `access`, structured `condition`, and
43
- * raw SQL (`using`/`withCheck`) cannot be combined. The type system enforces
44
- * this — attempting to set conflicting fields will produce a compile-time
45
- * error.
57
+ * **Mutual exclusivity:** `ownerField`, `access` and raw SQL
58
+ * (`using`/`withCheck`) cannot be combined with each other, and a structured
59
+ * `condition`/`check` combines only with `access`
60
+ * ({@link ConditionalAccessSecurityRule}). The type system enforces this —
61
+ * attempting to set conflicting fields will produce a compile-time error.
46
62
  *
47
63
  * **Which form to reach for:** prefer the structured {@link StructuredSecurityRule}
48
64
  * (`condition`/`check`) or the shortcuts (`ownerField`, `access`, `roles`). These
@@ -53,7 +69,7 @@ export type SecurityOperation = "select" | "insert" | "update" | "delete" | "all
53
69
  *
54
70
  * @group Models
55
71
  */
56
- export type SecurityRule = OwnerSecurityRule | PublicSecurityRule | StructuredSecurityRule | RawSQLSecurityRule | RawSQLCheckOnlySecurityRule | RolesOnlySecurityRule;
72
+ export type SecurityRule = OwnerSecurityRule | PublicSecurityRule | AuthenticatedSecurityRule | RegisteredSecurityRule | ConditionalAccessSecurityRule | CheckedAccessSecurityRule | StructuredSecurityRule | RawSQLSecurityRule | RawSQLCheckOnlySecurityRule | RolesOnlySecurityRule | RedactedSecurityRule;
57
73
  /**
58
74
  * Shared fields for all SecurityRule variants.
59
75
  * @group Models
@@ -190,14 +206,18 @@ export interface OwnerSecurityRule extends SecurityRuleBase {
190
206
  * Security rule that grants unrestricted row access (no row filtering).
191
207
  * Generates `USING (true)`.
192
208
  *
193
- * This means "no row-level filter", NOT "anonymous/unauthenticated access".
194
- * Authentication is still enforced at the API layer — this only controls which
195
- * *rows* authenticated users can see.
209
+ * This means "no row-level filter", NOT "anonymous/unauthenticated access" on
210
+ * its own: when the API requires a token (`AUTH_REQUIRE`, the default) a
211
+ * caller without one is refused before RLS is consulted. This only controls
212
+ * which *rows* a caller who reached the database sees.
213
+ *
214
+ * Cannot be combined with `using`, `withCheck`, or `ownerField`. To narrow the
215
+ * rows, add a `condition` — that is a {@link ConditionalAccessSecurityRule}.
196
216
  *
197
- * Cannot be combined with `using`, `withCheck`, or `ownerField`.
217
+ * For "any signed-in caller", see {@link AuthenticatedSecurityRule}.
198
218
  *
199
219
  * @example
200
- * // Public read (any authenticated user sees all rows)
220
+ * // Public read (every caller sees all rows)
201
221
  * { operation: "select", access: "public" }
202
222
  *
203
223
  * @group Models
@@ -211,6 +231,142 @@ export interface PublicSecurityRule extends SecurityRuleBase {
211
231
  condition?: never;
212
232
  check?: never;
213
233
  }
234
+ /**
235
+ * Security rule that grants any signed-in caller row access, with no row
236
+ * filter. Generates the signed-in test `policy.authenticated()` compiles to:
237
+ * `rebase.uid()` is neither the server context's `NULL` nor an anonymous
238
+ * visitor's sentinel.
239
+ *
240
+ * Older releases did not type this shape and compiled it to a policy that
241
+ * denies every row; it is a new shape with its own policy name (see
242
+ * `getPolicyNameHash`).
243
+ *
244
+ * Cannot be combined with `using`, `withCheck`, or `ownerField`. To narrow the
245
+ * rows, add a `condition` — that is a {@link ConditionalAccessSecurityRule}.
246
+ *
247
+ * @example
248
+ * // Any signed-in caller reads every row
249
+ * { operation: "select", access: "authenticated" }
250
+ *
251
+ * @group Models
252
+ */
253
+ export interface AuthenticatedSecurityRule extends SecurityRuleBase {
254
+ /** Grant row access, with no row filter, to any signed-in caller. */
255
+ access: "authenticated";
256
+ ownerField?: never;
257
+ using?: never;
258
+ withCheck?: never;
259
+ condition?: never;
260
+ check?: never;
261
+ }
262
+ /**
263
+ * Security rule that grants any signed-in caller who has an account row
264
+ * access, with no row filter: {@link AuthenticatedSecurityRule} minus guest
265
+ * sessions. Generates the test `policy.registered()` compiles to — signed in,
266
+ * and `rebase.is_anonymous()` is false.
267
+ *
268
+ * On a project with anonymous sign-in, a guest (`POST /auth/anonymous`) has a
269
+ * real uid and a real session, so `access: "authenticated"` admits anyone who
270
+ * presses "Continue as guest". Reach for `"registered"` when the rule is about
271
+ * a person who could be held responsible: writing a review, joining an
272
+ * organization, spending money.
273
+ *
274
+ * A new shape with its own policy name (see `getPolicyNameHash`).
275
+ *
276
+ * Cannot be combined with `using`, `withCheck`, or `ownerField`. To narrow the
277
+ * rows, add a `condition` — that is a {@link ConditionalAccessSecurityRule}.
278
+ *
279
+ * @example
280
+ * // Only callers with an account may post a review
281
+ * { operation: "insert", access: "registered" }
282
+ *
283
+ * @group Models
284
+ */
285
+ export interface RegisteredSecurityRule extends SecurityRuleBase {
286
+ /** Grant row access, with no row filter, to any signed-in caller who is not a guest. */
287
+ access: "registered";
288
+ ownerField?: never;
289
+ using?: never;
290
+ withCheck?: never;
291
+ condition?: never;
292
+ check?: never;
293
+ }
294
+ /**
295
+ * Security rule that grants `access` on the rows matching a condition:
296
+ * "anyone (or any signed-in caller) may do this, on rows where …".
297
+ *
298
+ * - `access: "public"` compiles to `USING (<condition>)` — no caller test.
299
+ * - `access: "authenticated"` compiles to
300
+ * `USING (<signed in> AND <condition>)`.
301
+ * - `access: "registered"` compiles to
302
+ * `USING (<signed in, not a guest> AND <condition>)`.
303
+ *
304
+ * The write clause is derived as a structured rule derives it: `WITH CHECK`
305
+ * from `check`, falling back to `condition`, gated by `access` the same way.
306
+ * With only `check` ({@link CheckedAccessSecurityRule}), the `USING` clause is
307
+ * the `access` test alone.
308
+ *
309
+ * `condition` / `check` take a {@link PolicyExpression} or the
310
+ * {@link PolicyShorthand} object form. `roles` ANDs an application-role test
311
+ * on, as on every rule.
312
+ *
313
+ * A new shape: its policy names are hashed from their own input (see
314
+ * `getPolicyNameHash`), so they never coincide with a name an older rule
315
+ * shape compiles to.
316
+ *
317
+ * Cannot be combined with `ownerField` or raw `using`/`withCheck`.
318
+ *
319
+ * @example
320
+ * // Anyone reads the published posts
321
+ * { operation: "select", access: "public", condition: { status: "published" } }
322
+ *
323
+ * @example
324
+ * // Signed-in callers may file a report, but only as an open one
325
+ * { operation: "insert", access: "authenticated", check: { state: "open" } }
326
+ *
327
+ * @group Models
328
+ */
329
+ export interface ConditionalAccessSecurityRule extends SecurityRuleBase {
330
+ /** The callers the rule admits — see {@link SecurityRuleAccess}. */
331
+ access: SecurityRuleAccess;
332
+ /**
333
+ * Which *existing* rows the callers may see / modify / delete (the `USING`
334
+ * clause, ANDed with the `access` test).
335
+ */
336
+ condition: PolicyCondition;
337
+ /**
338
+ * Which *new/updated* row values the callers may write (the `WITH CHECK`
339
+ * clause, ANDed with the `access` test). Defaults to `condition`.
340
+ */
341
+ check?: PolicyCondition;
342
+ ownerField?: never;
343
+ using?: never;
344
+ withCheck?: never;
345
+ }
346
+ /**
347
+ * {@link ConditionalAccessSecurityRule} with only a `check`: the callers named
348
+ * by `access` may write rows matching `check`; the `USING` clause (for
349
+ * `select` / `update` / `delete`) is the `access` test alone.
350
+ *
351
+ * @example
352
+ * // Signed-in callers may insert reports, only as open ones
353
+ * { operation: "insert", access: "authenticated", check: { state: "open" } }
354
+ *
355
+ * @group Models
356
+ */
357
+ export interface CheckedAccessSecurityRule extends SecurityRuleBase {
358
+ /** The callers the rule admits — see {@link SecurityRuleAccess}. */
359
+ access: SecurityRuleAccess;
360
+ /**
361
+ * Which *new/updated* row values the callers may write (the `WITH CHECK`
362
+ * clause, ANDed with the `access` test).
363
+ */
364
+ check: PolicyCondition;
365
+ condition?: never;
366
+ ownerField?: never;
367
+ using?: never;
368
+ withCheck?: never;
369
+ }
214
370
  /**
215
371
  * Security rule expressed as a structured, engine-agnostic
216
372
  * {@link PolicyExpression}. This is the **recommended** way to write a
@@ -218,7 +374,12 @@ export interface PublicSecurityRule extends SecurityRuleBase {
218
374
  * *and* is evaluated identically by the admin UI, so the UI can never show an
219
375
  * action the database will reject.
220
376
  *
221
- * Cannot be combined with `ownerField`, `access`, or raw `using`/`withCheck`.
377
+ * Cannot be combined with `ownerField` or raw `using`/`withCheck`; combined
378
+ * with `access` it is a {@link ConditionalAccessSecurityRule}.
379
+ *
380
+ * @example
381
+ * // Rows of one organisation that are not deleted (shorthand form)
382
+ * { operation: "select", condition: { orgId: "acme", deletedAt: null } }
222
383
  *
223
384
  * @example
224
385
  * // Owner, or any user holding the `moderator` role
@@ -236,14 +397,18 @@ export interface StructuredSecurityRule extends SecurityRuleBase {
236
397
  /**
237
398
  * Structured condition for the `USING` clause — which *existing* rows are
238
399
  * visible / can be modified / deleted (SELECT, UPDATE, DELETE).
400
+ *
401
+ * A {@link PolicyExpression}, or the {@link PolicyShorthand} object form
402
+ * (`{ status: "published" }` — each column equals its value).
239
403
  */
240
- condition: PolicyExpression;
404
+ condition: PolicyCondition;
241
405
  /**
242
406
  * Structured condition for the `WITH CHECK` clause — which *new/updated*
243
407
  * row values are allowed (INSERT, UPDATE). Defaults to `condition` when
244
- * omitted, mirroring PostgreSQL's own behavior.
408
+ * omitted, mirroring PostgreSQL's own behavior. Takes the same two forms
409
+ * as `condition`.
245
410
  */
246
- check?: PolicyExpression;
411
+ check?: PolicyCondition;
247
412
  ownerField?: never;
248
413
  access?: never;
249
414
  using?: never;
@@ -345,3 +510,48 @@ export interface RolesOnlySecurityRule extends SecurityRuleBase {
345
510
  condition?: never;
346
511
  check?: never;
347
512
  }
513
+ /**
514
+ * A rule whose SQL the server did not show this caller.
515
+ *
516
+ * `GET /api/schema/tables` serves a table's `rls.rules` to every caller who may
517
+ * read the table's description, because the panel decides which controls to
518
+ * offer from them. Raw SQL — a `using` / `withCheck` string, or a
519
+ * `policy.raw(…)` node anywhere inside a `condition` / `check` — is served
520
+ * only to administrators and `schema:read` holders: it is a description of
521
+ * the authorization model, not of the data. Everyone else receives this
522
+ * marker in the rule's place. It keeps what decides whom the rule concerns
523
+ * (`operation` / `operations`, `mode`, `roles`, `access`) and says nothing
524
+ * about which rows.
525
+ *
526
+ * Read-only: it is never authored. A table whose `rls` carries one is refused
527
+ * when it is compiled, and no policy is ever generated from one.
528
+ *
529
+ * The client-side evaluator treats it exactly as it treats a raw rule it
530
+ * cannot evaluate: *unknown*, never *allowed*. Panel gating (which resolves
531
+ * unknown optimistically) offers the action and lets Postgres decide;
532
+ * enforcement callers (which resolve unknown as deny) refuse.
533
+ *
534
+ * @example
535
+ * // What a non-admin is served for `{ operation: "update", roles: ["editor"], using: "owner_id = rebase.uid()" }`
536
+ * { operation: "update", roles: ["editor"], redacted: true }
537
+ *
538
+ * @group Models
539
+ */
540
+ export interface RedactedSecurityRule extends SecurityRuleBase {
541
+ /** The rule's clauses were withheld from this caller. */
542
+ redacted: true;
543
+ /** Who the rule admits, when the rule said so — see {@link SecurityRuleAccess}. */
544
+ access?: SecurityRuleAccess;
545
+ ownerField?: never;
546
+ using?: never;
547
+ withCheck?: never;
548
+ condition?: never;
549
+ check?: never;
550
+ }
551
+ /**
552
+ * Whether a rule is the {@link RedactedSecurityRule} marker the server sends
553
+ * in place of a rule whose SQL it withheld.
554
+ *
555
+ * @group Models
556
+ */
557
+ export declare function isRedactedSecurityRule(rule: SecurityRule): rule is RedactedSecurityRule;
@@ -51,7 +51,7 @@ export interface StorageAuthorizeContext {
51
51
  data?: StorageAuthorizeData;
52
52
  }
53
53
  /**
54
- * The slice of the data API a storage hook needs: read a collection, in the
54
+ * The slice of the data API a storage hook needs: read a table, in the
55
55
  * trusted server context.
56
56
  *
57
57
  * Deliberately read-only and deliberately tiny. A hook that can write is a hook
@@ -59,7 +59,7 @@ export interface StorageAuthorizeContext {
59
59
  * mutating anything.
60
60
  */
61
61
  export interface StorageAuthorizeData {
62
- collection(slug: string): {
62
+ table(slug: string): {
63
63
  find(query?: Record<string, unknown>): Promise<{
64
64
  data: Record<string, unknown>[];
65
65
  }>;
@@ -47,7 +47,7 @@ export interface TenantClaimSource {
47
47
  claim: string;
48
48
  }
49
49
  /**
50
- * The caller's tenants come from rows of a membership collection.
50
+ * The caller's tenants come from rows of a membership table.
51
51
  *
52
52
  * The many-tenants-per-user shape — a `memberships` table with a user column
53
53
  * and a tenant column, which is how a person belongs to three organizations at
@@ -62,8 +62,8 @@ export interface TenantClaimSource {
62
62
  */
63
63
  export interface TenantMembershipSource {
64
64
  membership: {
65
- /** Slug of the collection holding the memberships. */
66
- collection: string;
65
+ /** Slug of the table holding the memberships. */
66
+ table: string;
67
67
  /** The property on it that holds the user id (compared to `rebase.uid()`). */
68
68
  userField: string;
69
69
  /** The property on it that holds the tenant id. */
@@ -0,0 +1,228 @@
1
+ /**
2
+ * UI preferences: how a table is presented in the panel, stored as data.
3
+ *
4
+ * A table's schema lives in `backend/schema/*.ts`; how the panel presents it
5
+ * (labels, icon, column order and widths, hidden columns, the default view
6
+ * mode, enum labels and colours …) is a customization. Code customizations are
7
+ * written with `customizeTable` in the frontend. What the collection editor and
8
+ * the views change at runtime is stored as a {@link UiTablePreferences} delta —
9
+ * for the whole workspace, or for one user — and folded in after the code
10
+ * customizations, in this order:
11
+ *
12
+ * projected table → `tableCustomizations` (code) → workspace preferences → user preferences
13
+ *
14
+ * Every key here is one `customizeTable` accepts, with a JSON value only: no
15
+ * function, component or resolver can arrive this way. Schema facts (column
16
+ * types, validation, enum values, rules, `description`) are never stored here;
17
+ * they are schema edits (`TablePatch`).
18
+ *
19
+ * @module
20
+ */
21
+ import type { WhereFilterOp } from "./filter-operators.js";
22
+ /**
23
+ * Where a preference applies: to everybody in the workspace, or to one user.
24
+ *
25
+ * @group UI preferences
26
+ */
27
+ export type UiPreferenceScope = "workspace" | "user";
28
+ /**
29
+ * The label (and colour) of one enum value. A colour is a chip colour key
30
+ * (`"green"`, `"orangeDark"`).
31
+ *
32
+ * @group UI preferences
33
+ */
34
+ export interface UiEnumLabel {
35
+ label: string;
36
+ color?: string;
37
+ disabled?: boolean;
38
+ }
39
+ /**
40
+ * How one field is presented: the data-only subset of a field customization.
41
+ *
42
+ * @group UI preferences
43
+ */
44
+ export interface UiFieldPreferences {
45
+ name?: string;
46
+ hidden?: boolean;
47
+ hiddenInForm?: boolean;
48
+ disabled?: boolean;
49
+ readOnly?: boolean;
50
+ columnWidth?: number;
51
+ span?: 1 | 2 | 3 | 4;
52
+ multiline?: boolean;
53
+ markdown?: boolean;
54
+ previewAsTag?: boolean;
55
+ clearable?: boolean;
56
+ urlPreview?: boolean | "image" | "video" | "audio" | "file";
57
+ mode?: "date" | "date_time";
58
+ timezone?: string;
59
+ enumLabels?: {
60
+ [value: string]: string | UiEnumLabel;
61
+ };
62
+ enumOrder?: (string | number)[];
63
+ expanded?: boolean;
64
+ minimalistView?: boolean;
65
+ sortable?: boolean;
66
+ canAddElements?: boolean;
67
+ spreadChildren?: boolean;
68
+ keyValue?: boolean;
69
+ previewFields?: string[];
70
+ fieldOrder?: string[];
71
+ widget?: "select" | "dialog";
72
+ includeId?: boolean;
73
+ includeEntityLink?: boolean;
74
+ referenceTo?: string;
75
+ /** JSON-logic conditions (`{ disabled, hidden, readOnly, required … }`). */
76
+ conditions?: {
77
+ [key: string]: UiJsonValue;
78
+ };
79
+ /** A JSON document's keys. */
80
+ fields?: {
81
+ [key: string]: UiFieldPreferences;
82
+ };
83
+ /** An array's items. */
84
+ of?: UiFieldPreferences;
85
+ }
86
+ /**
87
+ * A JSON value, as conditions carry them.
88
+ *
89
+ * @group UI preferences
90
+ */
91
+ export type UiJsonValue = string | number | boolean | null | UiJsonValue[] | {
92
+ [key: string]: UiJsonValue;
93
+ };
94
+ /**
95
+ * The record slots of a table, each naming a field.
96
+ *
97
+ * @group UI preferences
98
+ */
99
+ export interface UiDisplayPreferences {
100
+ title?: string;
101
+ subtitle?: string;
102
+ image?: string;
103
+ status?: string;
104
+ date?: string;
105
+ tags?: string;
106
+ }
107
+ /**
108
+ * One sort: the field, the direction, and where nulls go.
109
+ *
110
+ * @group UI preferences
111
+ */
112
+ export type UiSortTuple = [string, "asc" | "desc"] | [string, "asc" | "desc", "first" | "last"];
113
+ /**
114
+ * A filter on one field: an operator and its value, or several.
115
+ *
116
+ * @group UI preferences
117
+ */
118
+ export type UiFilterCondition = [WhereFilterOp, UiJsonValue];
119
+ /**
120
+ * How one table is presented: the data-only subset of `customizeTable`'s
121
+ * options. A stored preference is a delta: what it names replaces what the
122
+ * code customization says, key by key (`fields` field by field).
123
+ *
124
+ * @group UI preferences
125
+ */
126
+ export interface UiTablePreferences {
127
+ name?: string;
128
+ singularName?: string;
129
+ icon?: string;
130
+ group?: string;
131
+ hideFromNavigation?: boolean;
132
+ hideFromEntityViews?: boolean;
133
+ defaultViewMode?: string;
134
+ enabledViews?: string[];
135
+ defaultSize?: "xs" | "s" | "m" | "l" | "xl";
136
+ kanban?: {
137
+ columnField: string;
138
+ orderField?: string;
139
+ };
140
+ fieldOrder?: string[];
141
+ listFields?: string[];
142
+ previewFields?: string[];
143
+ display?: UiDisplayPreferences;
144
+ hideIdFromCollection?: boolean;
145
+ /** The default sort. */
146
+ sort?: UiSortTuple | UiSortTuple[];
147
+ /** The filter a visitor starts from. */
148
+ defaultFilter?: {
149
+ [field: string]: UiFilterCondition | UiFilterCondition[];
150
+ };
151
+ pagination?: boolean | number;
152
+ inlineEditing?: boolean;
153
+ selectionEnabled?: boolean;
154
+ exportable?: boolean;
155
+ openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
156
+ defaultEntityAction?: "view" | "edit";
157
+ sideDialogWidth?: number | string;
158
+ defaultSelectedView?: string;
159
+ formAutoSave?: boolean;
160
+ alwaysApplyDefaultValues?: boolean;
161
+ includeJsonView?: boolean;
162
+ localChangesBackup?: "manual_apply" | "auto_apply" | false;
163
+ hideIdFromForm?: boolean;
164
+ /** Registered entity actions, by key. */
165
+ entityActions?: string[];
166
+ disableDefaultActions?: ("edit" | "copy" | "delete")[];
167
+ /** Registered entity views, by key. */
168
+ entityViews?: string[];
169
+ /** Registered collection views, by key. */
170
+ customViews?: string[];
171
+ fields?: {
172
+ [key: string]: UiFieldPreferences;
173
+ };
174
+ }
175
+ /**
176
+ * Every key a {@link UiTablePreferences} may hold, as data: what the server
177
+ * validates a stored preference by.
178
+ *
179
+ * @group UI preferences
180
+ */
181
+ export declare const UI_PREFERENCE_TABLE_KEYS: readonly ["alwaysApplyDefaultValues", "customViews", "defaultEntityAction", "defaultFilter", "defaultSelectedView", "defaultSize", "defaultViewMode", "disableDefaultActions", "display", "enabledViews", "entityActions", "entityViews", "exportable", "fieldOrder", "fields", "formAutoSave", "group", "hideFromEntityViews", "hideFromNavigation", "hideIdFromCollection", "hideIdFromForm", "icon", "includeJsonView", "inlineEditing", "kanban", "listFields", "localChangesBackup", "name", "openEntityMode", "pagination", "previewFields", "selectionEnabled", "sideDialogWidth", "singularName", "sort"];
182
+ /**
183
+ * Every key a {@link UiFieldPreferences} may hold, as data.
184
+ *
185
+ * @group UI preferences
186
+ */
187
+ export declare const UI_PREFERENCE_FIELD_KEYS: readonly ["canAddElements", "clearable", "columnWidth", "conditions", "disabled", "enumLabels", "enumOrder", "expanded", "fieldOrder", "fields", "hidden", "hiddenInForm", "includeEntityLink", "includeId", "keyValue", "markdown", "minimalistView", "mode", "multiline", "name", "of", "previewAsTag", "previewFields", "readOnly", "referenceTo", "sortable", "span", "spreadChildren", "timezone", "urlPreview", "widget"];
188
+ /**
189
+ * One problem with a preference delta: the path to the value, and what is
190
+ * wrong with it.
191
+ *
192
+ * @group UI preferences
193
+ */
194
+ export interface UiPreferenceProblem {
195
+ path: string;
196
+ message: string;
197
+ }
198
+ /**
199
+ * Every problem with a table's preference delta as it arrived: a key that is
200
+ * not a preference (a schema fact, a component, a misspelling) or a value of
201
+ * the wrong shape. Empty when it may be stored.
202
+ *
203
+ * @group UI preferences
204
+ */
205
+ export declare function uiTablePreferencesProblems(value: unknown): UiPreferenceProblem[];
206
+ /**
207
+ * Whether a value is a well-formed {@link UiTablePreferences} delta.
208
+ *
209
+ * @group UI preferences
210
+ */
211
+ export declare function isUiTablePreferences(value: unknown): value is UiTablePreferences;
212
+ /**
213
+ * One delta over another: what `over` names replaces what `base` says, key by
214
+ * key, and `fields` (and a field's nested `fields` / `of`) field by field.
215
+ *
216
+ * @group UI preferences
217
+ */
218
+ export declare function mergeUiTablePreferences(base: UiTablePreferences, over: UiTablePreferences): UiTablePreferences;
219
+ /**
220
+ * The preferences of a workspace or a user, by table slug.
221
+ *
222
+ * @group UI preferences
223
+ */
224
+ export interface UiPreferences {
225
+ tables: {
226
+ [slug: string]: UiTablePreferences;
227
+ };
228
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/types",
3
- "version": "0.30.1",
3
+ "version": "0.31.0-canary.g59cd6fd",
4
4
  "description": "Rebase type definitions — shared interfaces and controller types",
5
5
  "keywords": [
6
6
  "rebase",
@@ -81,7 +81,8 @@
81
81
  "testEnvironment": "node",
82
82
  "moduleNameMapper": {
83
83
  "\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js"
84
- }
84
+ },
85
+ "maxWorkers": 4
85
86
  },
86
87
  "scripts": {
87
88
  "watch": "vite build --watch",
@@ -1,23 +0,0 @@
1
- import type { User } from "../users/index.js";
2
- /**
3
- * The read-only slice of authentication state that property resolution needs.
4
- *
5
- * `dynamicProps`, `conditions` and the JSON-Logic condition context all want the
6
- * same one thing: who is asking. They used to be handed the entire
7
- * {@link AuthController} — `signOut`, `googleLogin`, `authLoading`, thirty-odd
8
- * members of frontend machinery — which meant `properties.ts` named a frontend
9
- * controller, and so did `resolveProperty` in `@rebasepro/common`, which the
10
- * Postgres schema generator calls at build time. A backend generating DDL had to
11
- * satisfy a type with a login method in it.
12
- *
13
- * `User` already carries `roles` and `metadata`, so this is not a reduction in
14
- * what a dynamic property can decide on — only in what it has to be given.
15
- * An `AuthController` satisfies this structurally, so the frontend passes the
16
- * controller it already has.
17
- *
18
- * @group Hooks and utilities
19
- */
20
- export interface AuthState<USER extends User = User> {
21
- /** The signed-in user, or `null` when nobody is. */
22
- user: USER | null;
23
- }
@@ -1,67 +0,0 @@
1
- import type { CollectionConfig } from "../types/collections.js";
2
- import type { EntityReference } from "../types/entities.js";
3
- /**
4
- * Controller that provides access to the registered entity collections.
5
- * @group Models
6
- */
7
- export type CollectionRegistryController<DB = Record<string, unknown>, EC extends CollectionConfig = CollectionConfig> = {
8
- /**
9
- * List of the mapped collections in the admin.
10
- * Each entry relates to a collection in the root database.
11
- * Each of the navigation entries in this field
12
- * generates an entry in the main menu.
13
- *
14
- * `EC`, like {@link getCollection} — this was hardcoded to `CollectionConfig`
15
- * while `getCollection` honoured the parameter, so the admin panel got its
16
- * view model from one and the raw contract from the other.
17
- */
18
- collections?: EC[];
19
- /**
20
- * Is the registry ready to be used
21
- */
22
- initialised: boolean;
23
- /**
24
- * Get the collection configuration for a given path.
25
- * The collection is resolved from the given path or alias.
26
- */
27
- getCollection: <K extends keyof DB>(slugOrPath: Extract<K, string>, includeUserOverride?: boolean) => EC | undefined;
28
- /**
29
- * Get the raw, un-normalized collection configuration.
30
- * This bypasses the `CollectionRegistry` normalization (such as injecting `relation` instances).
31
- * This is strictly for the Visual Editor to manipulate AST code without persisting runtime state.
32
- */
33
- getRawCollection: (slugOrPath: string) => EC | undefined;
34
- /**
35
- * The path a collection's rows are stored under, for the path the admin
36
- * addresses it by. A Firestore or MongoDB collection may declare a `path`
37
- * other than its slug — `slug: "fs_diagnosis", path: "diagnosis"` — and
38
- * `fs_diagnosis/abc/locales` is then stored at `diagnosis/abc/locales`.
39
- * This is what a reference to one of its records stores. Unchanged for a
40
- * collection stored under its slug.
41
- */
42
- resolveDataPath: (path: string) => string;
43
- /**
44
- * The path the admin addresses a collection by, for a path its rows are
45
- * stored under: the inverse of {@link resolveDataPath}, for a reference
46
- * read back. `diagnosis` may be both where a Firestore collection is stored
47
- * and the slug of a Postgres one; `preferredDriver` — the reference's
48
- * `driver`, or the data source of the record it was read from — decides.
49
- */
50
- resolveCollectionPath: (path: string, preferredDriver?: string) => string;
51
- /**
52
- * Retrieve all the related parent references for a given path
53
- * @param path
54
- */
55
- getParentReferencesFromPath: (path: string) => EntityReference[];
56
- /**
57
- * Retrieve all the related parent collection ids for a given path
58
- * @param path
59
- */
60
- getParentCollectionSlugs: (path: string) => string[];
61
- getParentEntityIds: (path: string) => string[];
62
- /**
63
- * Resolve paths from a list of ids
64
- * @param ids
65
- */
66
- convertIdsToPaths: (ids: string[]) => string[];
67
- };