@rebasepro/types 0.17.3 → 0.18.1

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 (71) hide show
  1. package/README.md +4 -0
  2. package/dist/call_context.d.ts +20 -0
  3. package/dist/controllers/client.d.ts +36 -4
  4. package/dist/controllers/data.d.ts +120 -10
  5. package/dist/errors.d.ts +83 -4
  6. package/dist/index.es.js +522 -160
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/types/admin_block.d.ts +2 -2
  9. package/dist/types/auth_adapter.d.ts +41 -6
  10. package/dist/types/backend.d.ts +48 -0
  11. package/dist/types/collections.d.ts +25 -1
  12. package/dist/types/cron.d.ts +34 -0
  13. package/dist/types/database_adapter.d.ts +39 -0
  14. package/dist/types/entity_callbacks.d.ts +14 -1
  15. package/dist/types/filter-operators.d.ts +24 -1
  16. package/dist/types/policy.d.ts +29 -1
  17. package/dist/types/properties.d.ts +216 -3
  18. package/dist/types/relations.d.ts +65 -7
  19. package/dist/types/resource_kinds.d.ts +173 -17
  20. package/dist/types/resources.d.ts +108 -7
  21. package/dist/types/rls-functions.d.ts +11 -0
  22. package/dist/types/storage_source.d.ts +12 -23
  23. package/package.json +24 -23
  24. package/src/call_context.ts +0 -120
  25. package/src/controllers/auth_state.ts +0 -24
  26. package/src/controllers/client.ts +0 -494
  27. package/src/controllers/collection_registry.ts +0 -62
  28. package/src/controllers/data.ts +0 -1012
  29. package/src/controllers/data_driver.ts +0 -576
  30. package/src/controllers/effective_role.ts +0 -4
  31. package/src/controllers/email.ts +0 -91
  32. package/src/controllers/index.ts +0 -11
  33. package/src/controllers/storage.ts +0 -252
  34. package/src/errors.ts +0 -119
  35. package/src/index.ts +0 -5
  36. package/src/types/admin_block.ts +0 -209
  37. package/src/types/api_keys.ts +0 -108
  38. package/src/types/auth_adapter.ts +0 -580
  39. package/src/types/backend.ts +0 -987
  40. package/src/types/backup.ts +0 -26
  41. package/src/types/channel_bus.ts +0 -202
  42. package/src/types/chips.ts +0 -34
  43. package/src/types/collection_contract.ts +0 -278
  44. package/src/types/collections.ts +0 -763
  45. package/src/types/component_ref.ts +0 -92
  46. package/src/types/cron.ts +0 -213
  47. package/src/types/data_source.ts +0 -357
  48. package/src/types/database_adapter.ts +0 -267
  49. package/src/types/entities.ts +0 -226
  50. package/src/types/entity_callbacks.ts +0 -229
  51. package/src/types/filter-operators.ts +0 -444
  52. package/src/types/history.ts +0 -66
  53. package/src/types/index.ts +0 -36
  54. package/src/types/indexes.ts +0 -180
  55. package/src/types/policy.ts +0 -328
  56. package/src/types/postgres_introspection.ts +0 -101
  57. package/src/types/project_manifest.ts +0 -598
  58. package/src/types/properties.ts +0 -1368
  59. package/src/types/relations.ts +0 -417
  60. package/src/types/resource_kinds.ts +0 -390
  61. package/src/types/resources.ts +0 -368
  62. package/src/types/rls-functions.ts +0 -98
  63. package/src/types/schema_editing.ts +0 -157
  64. package/src/types/schema_version.ts +0 -112
  65. package/src/types/search.ts +0 -247
  66. package/src/types/security_rules.ts +0 -344
  67. package/src/types/storage_authorize.ts +0 -77
  68. package/src/types/storage_source.ts +0 -248
  69. package/src/types/websockets.ts +0 -117
  70. package/src/users/index.ts +0 -2
  71. package/src/users/user.ts +0 -69
@@ -1,267 +0,0 @@
1
- /**
2
- * @module DatabaseAdapter
3
- *
4
- * Pluggable database abstraction for Rebase.
5
- *
6
- *
7
- * A `DatabaseAdapter` focuses purely on data persistence and related concerns (realtime, history).
8
- * It does NOT handle authentication — auth is managed separately by an `AuthAdapter`.
9
- *
10
- * @example
11
- * ```ts
12
- * import { createPostgresAdapter } from "@rebasepro/server-postgres";
13
- *
14
- * initializeRebaseBackend({
15
- * database: createPostgresAdapter({ connection: db, schema }),
16
- * auth: { jwtSecret: "..." },
17
- * });
18
- * ```
19
- *
20
- * @group Backend
21
- */
22
-
23
- import type { DataDriver } from "../controllers/data_driver";
24
- import type { CollectionConfig } from "./collections";
25
- import type {
26
- CollectionRegistryInterface,
27
- DatabaseAdmin,
28
- InitializedDriver,
29
- RealtimeProvider,
30
- BootstrappedAuth
31
- } from "./backend";
32
- import type { HistoryConfig } from "../controllers/client";
33
-
34
- /**
35
- * A `DatabaseAdapter` provides data persistence for Rebase.
36
- *
37
- * @group Backend
38
- */
39
- export interface DatabaseAdapter {
40
- /**
41
- * Which database engine this adapter handles.
42
- *
43
- * @example "postgres", "mysql", "mongodb", "sqlite"
44
- */
45
- readonly type: string;
46
-
47
- /**
48
- * Create the DataDriver for CRUD operations.
49
- *
50
- * This is the only **required** method.
51
- *
52
- * @param config - Coordinator-provided config containing registered
53
- * collections and the collection registry.
54
- */
55
- initializeDriver(config: DatabaseAdapterInitConfig): Promise<InitializedDriver>;
56
-
57
- /**
58
- * Create a realtime provider for this database.
59
- *
60
- * Return `undefined` if the database does not support realtime
61
- * change notifications.
62
- */
63
- initializeRealtime?(driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
64
-
65
- /**
66
- * Initialize auth tables / services if this driver supports them.
67
- */
68
- initializeAuth?(
69
- config: unknown,
70
- driverResult: InitializedDriver,
71
- ): Promise<BootstrappedAuth | undefined>;
72
-
73
- /**
74
- * Initialize entity history tracking.
75
- *
76
- * Return `undefined` if the database does not support history.
77
- */
78
- initializeHistory?(
79
- config: HistoryConfig,
80
- driverResult: InitializedDriver,
81
- ): Promise<{ historyService: unknown } | undefined>;
82
-
83
- /**
84
- * Initialize WebSocket server for realtime operations.
85
- *
86
- * `adapter` is the configured AuthAdapter, if any. It is what makes the
87
- * socket secure by default: an implementation that receives one requires
88
- * authentication regardless of whether a local `jwtSecret` exists. The
89
- * parameter was missing from this signature while the caller in `init.ts`
90
- * already passed it, so it was dropped at every adapter that routed through
91
- * here — turning an adapter-authenticated server's socket into one that
92
- * accepted every client as already authenticated.
93
- */
94
- initializeWebsockets?(
95
- server: unknown,
96
- realtimeService: RealtimeProvider,
97
- driver: DataDriver,
98
- config?: unknown,
99
- adapter?: import("./auth_adapter").AuthAdapter,
100
- ): Promise<void> | void;
101
-
102
- /**
103
- * Bring the database's collection tables up to date, additively — the boot
104
- * companion to `db push`. See `BackendBootstrapper.ensureCollectionSchema`
105
- * for the contract (create-only; never drop, narrow, or rewrite).
106
- *
107
- * Optional, and MUST be forwarded by any wrapper that turns this adapter
108
- * into a `BackendBootstrapper`: the runtime calls it through the bootstrapper
109
- * at boot, and a wrapper that silently omits it leaves a managed tenant
110
- * 500ing every data route with no create step ever having run.
111
- *
112
- * `driverResult` is optional because this runs BEFORE `initializeDriver`, so
113
- * there may be no result to pass. The bundle path can supply a pre-init
114
- * stand-in because the coordinator opened the connection itself; an app that
115
- * constructed this adapter never handed the framework a connection handle,
116
- * so it passes `undefined` and the adapter MUST fall back to the connection
117
- * it was constructed with. An adapter that dereferences `driverResult`
118
- * unconditionally works for managed tenants and breaks every self-built one.
119
- */
120
- ensureCollectionSchema?(
121
- collections: unknown[],
122
- driverResult?: InitializedDriver,
123
- log?: (message: string) => void,
124
- ): Promise<{ applied: number }>;
125
-
126
- /**
127
- * Apply the collections' RLS policies (ENABLE ROW LEVEL SECURITY + the
128
- * `securityRules` compiled to `CREATE POLICY`) — the boot companion to the
129
- * policy half of `db push`. Idempotent; see
130
- * `BackendBootstrapper.ensureCollectionPolicies`.
131
- *
132
- * Same forwarding requirement as `ensureCollectionSchema`: without the
133
- * policies, tables exist but every user-context read is denied (a public
134
- * collection answers 401).
135
- */
136
- ensureCollectionPolicies?(
137
- collections: unknown[],
138
- driverResult?: InitializedDriver,
139
- log?: (message: string) => void,
140
- ): Promise<{ applied: number }>;
141
-
142
- /**
143
- * Read the collections schema version this database was last provisioned
144
- * from, or `null` when nothing has ever stamped it.
145
- *
146
- * `null` is not an error and MUST NOT be treated as one — every database
147
- * provisioned before the stamp existed reads this way, and so does every
148
- * fresh one until its first provisioning boot finishes.
149
- *
150
- * Same forwarding requirement as the two hooks above: a wrapper that omits
151
- * it turns the check off, and a check that is off looks exactly like a check
152
- * that passed.
153
- */
154
- readCollectionsSchemaVersion?(
155
- driverResult?: InitializedDriver,
156
- ): Promise<string | null>;
157
-
158
- /**
159
- * Record the collections schema version this process just applied.
160
- *
161
- * Called only by the process that provisions, and only after the tables AND
162
- * the policies are in place — a stamp written earlier would claim a schema
163
- * that a half-finished boot never finished creating.
164
- */
165
- stampCollectionsSchemaVersion?(
166
- version: string,
167
- driverResult?: InitializedDriver,
168
- ): Promise<void>;
169
-
170
- /**
171
- * Return admin capabilities for this database (SQL editor, schema browser, branching).
172
- */
173
- getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
174
-
175
- /**
176
- * Mount any database-specific HTTP routes (e.g., custom admin endpoints).
177
- *
178
- * Called after all adapters are initialized.
179
- */
180
- mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
181
-
182
- /**
183
- * Graceful shutdown: close connections, release resources.
184
- */
185
- destroy?(): Promise<void>;
186
- }
187
-
188
- /**
189
- * Configuration passed by the coordinator to `DatabaseAdapter.initializeDriver()`.
190
- *
191
- * @group Backend
192
- */
193
- export interface DatabaseAdapterInitConfig {
194
- /** Registered collection definitions. */
195
- collections: CollectionConfig[];
196
- /** The shared collection registry to register into. */
197
- collectionRegistry: CollectionRegistryInterface;
198
- /**
199
- * Whether this driver should describe its own schema.
200
- *
201
- * True when the project declared no collections, so there is nothing to
202
- * serve unless the driver reads the live database and reports what it found
203
- * on `InitializedDriver.collections`. Drivers that cannot introspect may
204
- * ignore it — `initializeRebaseBackend` fails the boot with their name
205
- * rather than serving nothing.
206
- *
207
- * This was a `mode: "cms" | "baas"` flag, which was never independent of
208
- * `collections`: every consumer already required the list to be empty
209
- * before acting on it, so the flag could only ever agree or contradict.
210
- */
211
- introspectCollections?: boolean;
212
- /**
213
- * Options for an introspecting driver — see `RebaseBackendConfig.baas`.
214
- * Drivers that introspect should honour `unprotectedTables`.
215
- */
216
- baas?: { unprotectedTables?: "exclude" | "serve" };
217
- /**
218
- * What the runtime's boot-time table provisioning did, in this process,
219
- * before this driver was initialized.
220
- *
221
- * A driver that checks for missing tables cannot otherwise tell "the create
222
- * step ran and this table still is not here" from "no create step ran at
223
- * all" — and those need opposite advice. The Postgres driver's drift warning
224
- * assumed the first, told operators to redeploy with REBASE_MIGRATE_ON_BOOT
225
- * unset, and pointed at driver version skew; for an app whose boot path had
226
- * no provisioning step, all of that was unactionable and one investigation
227
- * chased a driver that was perfectly current.
228
- *
229
- * Absent when the caller predates this field: treat that as "unknown" and
230
- * fall back to generic guidance rather than asserting either case.
231
- */
232
- schemaProvisioning?: {
233
- /** Whether the table-creation hook actually ran this boot. */
234
- attempted: boolean;
235
- /** Why it did not, when it did not — safe to print verbatim. */
236
- reason?: string;
237
- };
238
- /**
239
- * What this process wants from the realtime subsystem.
240
- *
241
- * Both halves used to be assumed true, and both were wrong for a split
242
- * deployment. A `functions` or `worker` process has no websocket clients, so
243
- * consuming change events buys it a dedicated `LISTEN` connection to deliver
244
- * to nobody; and it is explicitly not the process that owns schema DDL, so
245
- * installing capture triggers from it contradicts the one-owner rule the
246
- * runtime otherwise refuses to boot without.
247
- *
248
- * Absent means both — every caller that predates this field is a
249
- * single-process deployment, where both are true.
250
- */
251
- realtime?: {
252
- /**
253
- * Consume change events: open the `LISTEN` connection, start CDC or the
254
- * app-level fallback. False for a process that serves no websockets.
255
- *
256
- * Writes made by a non-consuming process are still published: capture is
257
- * database triggers, so the publisher is the database.
258
- */
259
- subscribe: boolean;
260
- /**
261
- * Install what capture needs — the trigger function, the per-table
262
- * triggers, any channel-history tables. This is DDL, and it follows the
263
- * same single-owner rule as every other boot-time schema change.
264
- */
265
- provision: boolean;
266
- };
267
- }
@@ -1,226 +0,0 @@
1
- import type { SearchMatch } from "./search";
2
- /**
3
- * New or existing status
4
- * @group Models
5
- */
6
- export type EntityStatus = "new" | "existing" | "copy";
7
-
8
- /**
9
- * Representation of a entity fetched from the driver
10
- * @group Models
11
- */
12
- export interface Entity<M extends Record<string, unknown> = Record<string, unknown>> {
13
-
14
- /**
15
- * ID of the entity
16
- */
17
- id: string | number;
18
-
19
- /**
20
- * A string representing the path of the referenced document (relative
21
- * to the root of the database).
22
- */
23
- path: string;
24
-
25
- /**
26
- * Current values
27
- */
28
- values: EntityValues<M>;
29
-
30
- /**
31
- * Why this entity is in a search result: which declared fields matched, and
32
- * the text around each hit.
33
- *
34
- * Present only on rows returned by a search that asked for it. A sibling of
35
- * `values` rather than a key inside it, because it describes the *query*,
36
- * not the record — nothing in the collection declares it, no form edits it,
37
- * and a record fetched by id never has one.
38
- */
39
- searchMatches?: SearchMatch[];
40
-
41
- /**
42
- * Which driver this entity belongs to (e.g., 'postgres', 'firestore').
43
- * If not specified, the default driver is assumed.
44
- */
45
- driver?: string;
46
-
47
- /**
48
- * Which database within the driver (e.g., for Firestore multi-database).
49
- * If not specified, the default database of the driver is used.
50
- */
51
- databaseId?: string;
52
- }
53
-
54
- /**
55
- * This type represents a record of key value pairs as described in an
56
- * entity collection.
57
- * @group Models
58
- */
59
- export type EntityValues<M extends Record<string, unknown>> = M;
60
-
61
- /**
62
- * Props for creating a EntityReference
63
- */
64
- export interface EntityReferenceProps {
65
- /** ID of the entity */
66
- id: string;
67
- /** Path of the collection (relative to the root of the database) */
68
- path: string;
69
- /** Which driver (e.g., 'postgres', 'firestore'). Defaults to "(default)" */
70
- driver?: string;
71
- /** Which database within the driver. Defaults to "(default)" */
72
- databaseId?: string;
73
- }
74
-
75
- /**
76
- * Class used to create a reference to a entity in a different path.
77
- *
78
- * @example
79
- * // Simple reference (most common case - single driver, single db)
80
- * new EntityReference({ id: "123", path: "users" })
81
- *
82
- * // Reference to a different driver (e.g., Firestore)
83
- * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
84
- *
85
- * // Reference to a specific database within a driver
86
- * new EntityReference({ id: "123", path: "orders", driver: "postgres", databaseId: "orders_db" })
87
- */
88
- export class EntityReference {
89
-
90
- readonly __type = "reference";
91
- /**
92
- * ID of the entity
93
- */
94
- readonly id: string;
95
- /**
96
- * A string representing the path of the referenced document (relative
97
- * to the root of the database).
98
- */
99
- readonly path: string;
100
-
101
- /**
102
- * Which driver (e.g., 'postgres', 'firestore').
103
- * Defaults to "(default)" if not specified.
104
- */
105
- readonly driver?: string;
106
-
107
- /**
108
- * Which database within the driver.
109
- * Defaults to "(default)" if not specified.
110
- */
111
- readonly databaseId?: string;
112
-
113
- /**
114
- * Create a reference to a entity.
115
- *
116
- * @example
117
- * // Simple reference (most common case)
118
- * new EntityReference({ id: "123", path: "users" })
119
- *
120
- * // With driver
121
- * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
122
- */
123
- constructor(props: EntityReferenceProps) {
124
- this.id = props.id;
125
- this.path = props.path;
126
- this.driver = props.driver;
127
- this.databaseId = props.databaseId;
128
- }
129
-
130
- get pathWithId() {
131
- return `${this.path}/${this.id}`;
132
- }
133
-
134
- /**
135
- * Get the full path including driver and database prefixes if specified.
136
- * For the common case (single driver, single db), this just returns pathWithId.
137
- */
138
- get fullPath() {
139
- const parts: string[] = [];
140
-
141
- // Add driver prefix if not default
142
- if (this.driver && this.driver !== "(default)") {
143
- parts.push(this.driver);
144
- }
145
-
146
- // Add database prefix if specified
147
- if (this.databaseId && this.databaseId !== "(default)") {
148
- parts.push(this.databaseId);
149
- }
150
-
151
- if (parts.length > 0) {
152
- return `${parts.join(":")}:::${this.path}/${this.id}`;
153
- }
154
- return this.pathWithId;
155
- }
156
-
157
- isEntityReference() {
158
- return true;
159
- }
160
- }
161
-
162
- /**
163
- * Class used to create a reference to a entity in a different path
164
- */
165
- export class EntityRelation {
166
-
167
- readonly __type = "relation";
168
- /**
169
- * ID of the entity
170
- */
171
- readonly id: string | number;
172
- /**
173
- * A string representing the path of the referenced document (relative
174
- * to the root of the database).
175
- */
176
- readonly path: string;
177
-
178
- /**
179
- * Pre-fetched data payload to eliminate N+1 queries.
180
- * When present, clients can use this directly instead of fetching.
181
- */
182
- readonly data?: Record<string, unknown>;
183
-
184
- constructor(id: string | number, path: string, data?: Record<string, unknown>) {
185
- this.id = id;
186
- this.path = path;
187
- this.data = data;
188
- }
189
-
190
- get pathWithId() {
191
- return `${this.path}/${this.id}`;
192
- }
193
-
194
- isEntityReference() {
195
- return false;
196
- }
197
-
198
- isEntityRelation() {
199
- return true;
200
- }
201
- }
202
-
203
- export class GeoPoint {
204
-
205
- /**
206
- * The latitude of this GeoPoint instance.
207
- */
208
- readonly latitude: number;
209
- /**
210
- * The longitude of this GeoPoint instance.
211
- */
212
- readonly longitude: number;
213
-
214
- constructor(latitude: number, longitude: number) {
215
- this.latitude = latitude;
216
- this.longitude = longitude;
217
- }
218
- }
219
-
220
- export class Vector {
221
- readonly value: number[];
222
-
223
- constructor(value: number[]) {
224
- this.value = value;
225
- }
226
- }