@rebasepro/types 0.30.1 → 0.31.0-canary.g902a0ce

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
package/README.md CHANGED
@@ -14,29 +14,31 @@ of it resolves too: Node has supported `require(esm)` since 22.12.
14
14
 
15
15
  ## What This Package Does
16
16
 
17
- Provides the canonical type definitions used across all Rebase packages — both client-side and server-side. It has no runtime dependencies, but it is not types-only: it also exports the constants and small runtime helpers those packages share (`ADMIN_PROPERTY_KEYS`, `GeoPoint`, `declaredDataSources`, …). Every other `@rebasepro/*` package depends on it.
17
+ Provides the canonical type definitions used across all Rebase packages — both client-side and server-side. It has no runtime dependencies, but it is not types-only: it also exports the constants and small runtime helpers those packages share (`declaredDataSources`, `bucket`, …). Every other `@rebasepro/*` package depends on it.
18
18
 
19
19
  ## Key Exports
20
20
 
21
- ### Collection & Entity Types
21
+ ### Tables
22
22
 
23
23
  | Export | Description |
24
24
  |--------|-------------|
25
- | `CollectionConfig` | Full collection definition (name, slug, properties, callbacks, security rules, views) |
26
- | `Property` | Union type for all property configurations (text, number, date, reference, array, map, etc.) |
27
- | `Entity` | Generic entity record type |
28
- | `CollectionCallbacks` | Lifecycle hooks (`afterRead`, `beforeSave`, `afterSave`, `afterSaveError`, `beforeDelete`, `afterDelete`) |
29
- | `EntityValues` | Record of property values for an entity |
30
- | `SecurityRule` | RLS-style access control rule for a collection |
25
+ | `defineTable`, `defineAuthTable`, `defineView` | Declare a table, the users table, or a SQL view. `rls` is required on every table. Re-exported by `@rebasepro/server/schema`, the entry a `backend/schema` file imports. New in 0.31. |
26
+ | `col`, `rel`, `json`, `policy` | The column, relation, JSON-shape and policy-expression builders. New in 0.31. |
27
+ | `TableDescriptor`, `ColumnDescriptor`, `RelationDescriptor`, `RlsDescriptor` | The compiled form of a table: what the backend serves at `GET /api/schema/tables` and the SDK generator reads. New in 0.31. |
28
+ | `TableHooks` | A table's lifecycle hooks (`beforeQuery`, `afterRead`, `beforeSave`, `afterSave`, `afterSaveError`, `beforeDelete`, `afterDelete`). New in 0.31. |
29
+ | `InferRow`, `InferInsert`, `InferUpdate`, `DatabaseOf` | Row types inferred from a table, and a typed `Database` from a schema module. New in 0.31. |
30
+ | `TablePatch` | The schema editor's edits, as a typed list of operations. New in 0.31. |
31
+ | `SecurityRule` | One rule of a table's `rls` |
32
+ | `Register` | Augmented by a project to type server-side data: `database` (generated) or `tables` (the schema module) |
31
33
 
32
34
  ### Backend & Driver Interfaces
33
35
 
34
36
  | Export | Description |
35
37
  |--------|-------------|
36
- | `DataDriver` | Abstract interface for database drivers (`fetchCollection`, `fetchOne`, `save`, `delete`, etc.) |
38
+ | `DataDriver` | Abstract interface for database drivers (`fetchCollection`, `fetchOne`, `save`, `delete`, etc.). Reads return the row `GET /api/data/<table>` returns, with a relation only when `include` names it. |
37
39
  | `DatabaseAdapter` | Pluggable database adapter interface (used by `server`) |
38
40
  | `BackendBootstrapper` | Lifecycle interface for initializing database drivers, auth, history, and realtime |
39
- | `DatabaseAdmin` | Admin operations interface (SQL execution, collection stats, table metadata) |
41
+ | `DatabaseAdmin` | Admin operations interface (SQL execution, table stats, table metadata) |
40
42
  | `RealtimeProvider` | Interface for realtime subscription providers |
41
43
  | `BackendConfig` / `BackendInstance` | Abstract backend configuration and instance types |
42
44
  | `HealthCheckResult` | Return type for health check operations |
@@ -57,27 +59,24 @@ Provides the canonical type definitions used across all Rebase packages — both
57
59
  | `RebaseClient` | Top-level client interface (data, auth, storage, email) |
58
60
  | `RebaseServerClient` | The server-side `rebase` singleton: `RebaseClient` without `data`, plus `dataAsAdmin` |
59
61
  | `StorageSource` | File storage interface |
60
- | `CollectionRegistryInterface` | Collection lookup and registration |
61
62
 
62
63
  ### Other
63
64
 
64
65
  | Export | Description |
65
66
  |--------|-------------|
66
67
  | `CronJobDefinition` | Cron job configuration type |
67
- | `CollectionCallbacks` | Lifecycle callbacks for entity CRUD operations |
68
68
  | `WebSocketMessage` | WebSocket protocol message types |
69
69
 
70
- The admin panel's own types — `AuthController`, the plugin type `RebasePlugin`, `Locale` — live in `@rebasepro/cms-types`.
70
+ The admin panel's own types — `AuthController`, the plugin type `RebasePlugin`, `Locale`, and the collection and property view model it draws (`CollectionConfig`, `StringProperty` and every `…Property`, `CollectionCallbacks`) — live in `@rebasepro/cms-types`.
71
71
 
72
72
  ## Quick Start
73
73
 
74
74
  ```typescript
75
75
  import type {
76
- CollectionConfig,
76
+ TableDescriptor,
77
77
  DataDriver,
78
78
  DatabaseAdapter,
79
79
  User,
80
- Property,
81
80
  } from "@rebasepro/types";
82
81
  ```
83
82
 
@@ -87,8 +86,7 @@ Every `@rebasepro/*` package depends on this one. Key consumers:
87
86
 
88
87
  | Package | Uses |
89
88
  |---------|------|
90
- | `@rebasepro/server` | `DataDriver`, `DatabaseAdapter`, `BackendBootstrapper`, `AuthAdapter` |
89
+ | `@rebasepro/server` | the table builders, `DataDriver`, `DatabaseAdapter`, `BackendBootstrapper`, `AuthAdapter` |
91
90
  | `@rebasepro/server-postgres` | `BackendBootstrapper`, `InitializedDriver`, `RealtimeProvider` |
92
- | `@rebasepro/server-mongo` | `BackendBootstrapper`, `DataDriver`, `CollectionConfig` |
93
91
  | `@rebasepro/client` | `RebaseClient`, `StorageSource` |
94
- | `@rebasepro/cms` | `CollectionConfig`, `Property`, controller interfaces |
92
+ | `@rebasepro/cms` | `TableDescriptor`, controller interfaces |
@@ -16,7 +16,7 @@ import type { CallerCredential } from "./types/api_keys.js";
16
16
  * `data` is left off because server-side there is none. The object is the
17
17
  * `rebase` singleton, which omits `data` so that its admin-scoped plane has
18
18
  * exactly one name. This used to be declared as the full `RebaseClient`, so
19
- * `context.client.data.collection(…)` compiled and then threw "Cannot read
19
+ * `context.client.data.table(…)` compiled and then threw "Cannot read
20
20
  * properties of undefined" in production. In the browser the panel's client
21
21
  * does carry a `data`, but `context.data` is the accessor there too: one name
22
22
  * for a callback's queries on both sides of the wire.
@@ -86,7 +86,7 @@ export type RebaseCallContext<USER extends User = User, DB = RegisteredDatabase>
86
86
  client: RebaseCallbackClient<DB>;
87
87
  /**
88
88
  * Unified data access — `context.data.products.create(...)`.
89
- * Access any collection as a dynamic property.
89
+ * Access any table as a dynamic property.
90
90
  *
91
91
  * **Inherits the privilege of whatever triggered the callback.** This is not
92
92
  * a fixed trust level, and it is the one thing to know about this accessor:
@@ -108,7 +108,7 @@ export type RebaseCallContext<USER extends User = User, DB = RegisteredDatabase>
108
108
  * that, or reach for {@link client}`.dataAsAdmin` deliberately when the
109
109
  * callback genuinely has to see what an admin may see. Note what that does
110
110
  * *not* buy you: `policy.serverContext()` (`rebase.uid() IS NULL`) is false
111
- * for the service identity, so a collection whose only rule is
111
+ * for the service identity, so a table whose only rule is
112
112
  * `serverContext()` stays closed to it.
113
113
  *
114
114
  * Verified end-to-end against Postgres rather than asserted — see
@@ -11,6 +11,7 @@ import type { RoleSummary } from "../types/scopes.js";
11
11
  import type { StorageSourceDefinition } from "../types/storage_source.js";
12
12
  import type { RegisteredDatabase } from "../types/register.js";
13
13
  import type { AccessSimulation } from "../types/auth_adapter.js";
14
+ import type { TableDescriptor } from "../schema/descriptor.js";
14
15
  /**
15
16
  * Event type for authentication state changes
16
17
  */
@@ -319,6 +320,32 @@ export interface CronAPI {
319
320
  job: CronJobStatus;
320
321
  }>;
321
322
  }
323
+ /**
324
+ * Options of {@link SchemaAPI.tables}.
325
+ * @group Schema
326
+ */
327
+ export interface SchemaTablesOptions {
328
+ /** Abandons the request. */
329
+ signal?: AbortSignal;
330
+ }
331
+ /**
332
+ * The backend's tables, as `GET /api/schema/tables` serves them to the caller.
333
+ * @group Schema
334
+ */
335
+ export interface SchemaAPI {
336
+ /**
337
+ * Every table the signed-in caller may see, redacted for them: what the
338
+ * admin panel renders with no frontend configuration.
339
+ *
340
+ * Asked again, the request carries the `ETag` of the last answer in
341
+ * `If-None-Match`, and a `304` hands back the tables that answer held.
342
+ *
343
+ * Rejects with a `RebaseApiError`: status `401` when nobody is signed in;
344
+ * code `SCHEMA_UNAVAILABLE` (status `404`) when the backend serves no
345
+ * tables — auth is not configured there, or it predates the route.
346
+ */
347
+ tables(options?: SchemaTablesOptions): Promise<TableDescriptor[]>;
348
+ }
322
349
  /**
323
350
  * Client-side database-backup management interface.
324
351
  * @group Backups
@@ -525,6 +552,8 @@ export interface RebaseClient<DB = unknown> {
525
552
  cron?: CronAPI;
526
553
  /** Database backup management API */
527
554
  backups?: BackupsAPI;
555
+ /** The backend's tables, as served to the caller (`GET /api/schema/tables`). */
556
+ schema?: SchemaAPI;
528
557
  /** Custom backend functions API */
529
558
  functions?: FunctionsAPI;
530
559
  /** The project's service keys. Requires `keys:read` / `keys:write`. */