@rebasepro/types 0.0.1-canary.2 → 0.0.1-canary.4d4fb3e

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 (86) hide show
  1. package/README.md +1 -1
  2. package/dist/controllers/analytics_controller.d.ts +2 -2
  3. package/dist/controllers/auth.d.ts +50 -6
  4. package/dist/controllers/client.d.ts +58 -0
  5. package/dist/controllers/collection_registry.d.ts +44 -0
  6. package/dist/controllers/customization_controller.d.ts +5 -1
  7. package/dist/controllers/data.d.ts +141 -0
  8. package/dist/controllers/{datasource.d.ts → data_driver.d.ts} +25 -36
  9. package/dist/controllers/database_admin.d.ts +11 -0
  10. package/dist/controllers/effective_role.d.ts +4 -0
  11. package/dist/controllers/index.d.ts +11 -5
  12. package/dist/controllers/navigation.d.ts +9 -58
  13. package/dist/controllers/registry.d.ts +51 -0
  14. package/dist/controllers/side_entity_controller.d.ts +1 -2
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.es.js +113 -12
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +112 -11
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/rebase_context.d.ts +35 -25
  21. package/dist/types/backend.d.ts +296 -17
  22. package/dist/types/builders.d.ts +14 -0
  23. package/dist/types/collections.d.ts +166 -241
  24. package/dist/types/data_source.d.ts +64 -0
  25. package/dist/types/entities.d.ts +29 -24
  26. package/dist/types/entity_actions.d.ts +7 -7
  27. package/dist/types/entity_callbacks.d.ts +4 -4
  28. package/dist/types/entity_overrides.d.ts +6 -2
  29. package/dist/types/entity_views.d.ts +61 -0
  30. package/dist/types/index.d.ts +8 -5
  31. package/dist/types/plugins.d.ts +170 -221
  32. package/dist/types/properties.d.ts +17 -29
  33. package/dist/types/property_config.d.ts +13 -11
  34. package/dist/types/slots.d.ts +228 -0
  35. package/dist/types/translations.d.ts +826 -0
  36. package/dist/types/user_management_delegate.d.ts +42 -0
  37. package/dist/types/websockets.d.ts +45 -0
  38. package/dist/users/user.d.ts +4 -0
  39. package/package.json +7 -39
  40. package/src/controllers/analytics_controller.tsx +2 -2
  41. package/src/controllers/auth.tsx +53 -6
  42. package/src/controllers/client.ts +74 -0
  43. package/src/controllers/collection_registry.ts +53 -0
  44. package/src/controllers/customization_controller.tsx +6 -1
  45. package/src/controllers/data.ts +153 -0
  46. package/src/controllers/{datasource.ts → data_driver.ts} +41 -37
  47. package/src/controllers/database_admin.ts +22 -0
  48. package/src/controllers/effective_role.ts +4 -0
  49. package/src/controllers/index.ts +14 -5
  50. package/src/controllers/navigation.ts +9 -73
  51. package/src/controllers/registry.ts +62 -0
  52. package/src/controllers/side_entity_controller.tsx +1 -2
  53. package/src/index.ts +0 -1
  54. package/src/rebase_context.tsx +37 -33
  55. package/src/types/backend.ts +351 -19
  56. package/src/types/builders.ts +16 -0
  57. package/src/types/collections.ts +196 -259
  58. package/src/types/data_source.ts +156 -0
  59. package/src/types/entities.ts +35 -28
  60. package/src/types/entity_actions.tsx +6 -6
  61. package/src/types/entity_callbacks.ts +4 -4
  62. package/src/types/entity_overrides.tsx +6 -2
  63. package/src/types/entity_views.tsx +77 -0
  64. package/src/types/index.ts +9 -5
  65. package/src/types/plugins.tsx +198 -256
  66. package/src/types/properties.ts +22 -31
  67. package/src/types/property_config.tsx +11 -11
  68. package/src/types/slots.tsx +271 -0
  69. package/src/types/translations.ts +923 -0
  70. package/src/types/user_management_delegate.ts +43 -0
  71. package/src/types/websockets.ts +48 -0
  72. package/src/users/user.ts +5 -0
  73. package/dist/components/EntityFormActionsProps.d.ts +0 -17
  74. package/dist/components/EntityFormProps.d.ts +0 -46
  75. package/dist/components/PropertyPreviewProps.d.ts +0 -50
  76. package/dist/components/formex.d.ts +0 -40
  77. package/dist/components/index.d.ts +0 -3
  78. package/dist/types/fields.d.ts +0 -221
  79. package/dist/types/rebase.d.ts +0 -180
  80. package/src/components/EntityFormActionsProps.tsx +0 -18
  81. package/src/components/EntityFormProps.tsx +0 -52
  82. package/src/components/PropertyPreviewProps.tsx +0 -61
  83. package/src/components/formex.tsx +0 -46
  84. package/src/components/index.ts +0 -3
  85. package/src/types/fields.tsx +0 -298
  86. package/src/types/rebase.tsx +0 -211
@@ -13,7 +13,7 @@ export interface DatabaseConnection {
13
13
  */
14
14
  readonly isConnected?: boolean;
15
15
  /**
16
- * Close the database connection
16
+ * Close the database connection and release resources.
17
17
  */
18
18
  close?(): Promise<void>;
19
19
  }
@@ -28,7 +28,7 @@ export interface QueryFilter {
28
28
  /**
29
29
  * Options for fetching a collection of entities
30
30
  */
31
- export interface FetchCollectionOptions<M extends Record<string, any> = any> {
31
+ export interface FetchCollectionOptions<M extends Record<string, unknown> = Record<string, unknown>> {
32
32
  filter?: FilterValues<Extract<keyof M, string>>;
33
33
  orderBy?: string;
34
34
  order?: "desc" | "asc";
@@ -36,21 +36,23 @@ export interface FetchCollectionOptions<M extends Record<string, any> = any> {
36
36
  startAfter?: unknown;
37
37
  searchString?: string;
38
38
  databaseId?: string;
39
+ collection?: EntityCollection;
39
40
  }
40
41
  /**
41
42
  * Options for searching entities
42
43
  */
43
- export interface SearchOptions<M extends Record<string, any> = any> {
44
+ export interface SearchOptions<M extends Record<string, unknown> = Record<string, unknown>> {
44
45
  filter?: FilterValues<Extract<keyof M, string>>;
45
46
  orderBy?: string;
46
47
  order?: "desc" | "asc";
47
48
  limit?: number;
48
49
  databaseId?: string;
50
+ collection?: EntityCollection;
49
51
  }
50
52
  /**
51
53
  * Options for counting entities
52
54
  */
53
- export interface CountOptions<M extends Record<string, any> = any> {
55
+ export interface CountOptions<M extends Record<string, unknown> = Record<string, unknown>> {
54
56
  filter?: FilterValues<Extract<keyof M, string>>;
55
57
  databaseId?: string;
56
58
  }
@@ -63,11 +65,11 @@ export interface CountOptions<M extends Record<string, any> = any> {
63
65
  *
64
66
  * @template T The type of condition returned by the builder (e.g., SQL for PostgreSQL, Filter<Document> for MongoDB)
65
67
  */
66
- export interface ConditionBuilder<T = any> {
68
+ export interface ConditionBuilder<T = unknown> {
67
69
  /**
68
70
  * Build filter conditions from Rebase FilterValues
69
71
  */
70
- buildFilterConditions<M extends Record<string, any>>(filter: FilterValues<Extract<keyof M, string>>, collectionPath: string, ...args: unknown[]): T[];
72
+ buildFilterConditions<M extends Record<string, unknown>>(filter: FilterValues<Extract<keyof M, string>>, collectionPath: string, ...args: unknown[]): T[];
71
73
  /**
72
74
  * Build search conditions for text search
73
75
  */
@@ -89,8 +91,8 @@ export interface ConditionBuilder<T = any> {
89
91
  * // DrizzleConditionBuilder satisfies this type
90
92
  * const builder: ConditionBuilderStatic<SQL> = DrizzleConditionBuilder;
91
93
  */
92
- export type ConditionBuilderStatic<T = any> = {
93
- buildFilterConditions<M extends Record<string, any>>(filter: FilterValues<Extract<keyof M, string>>, ...args: unknown[]): T[];
94
+ export type ConditionBuilderStatic<T = unknown> = {
95
+ buildFilterConditions<M extends Record<string, unknown>>(filter: FilterValues<Extract<keyof M, string>>, ...args: unknown[]): T[];
94
96
  buildSearchConditions(searchString: string, properties: Record<string, unknown>, ...args: unknown[]): T[];
95
97
  combineConditionsWithAnd(conditions: T[]): T | undefined;
96
98
  combineConditionsWithOr(conditions: T[]): T | undefined;
@@ -108,23 +110,23 @@ export interface EntityRepository {
108
110
  /**
109
111
  * Fetch a single entity by ID
110
112
  */
111
- fetchEntity<M extends Record<string, any>>(collectionPath: string, entityId: string | number, databaseId?: string): Promise<Entity<M> | undefined>;
113
+ fetchEntity<M extends Record<string, unknown>>(collectionPath: string, entityId: string | number, databaseId?: string): Promise<Entity<M> | undefined>;
112
114
  /**
113
115
  * Fetch a collection of entities with optional filtering, ordering, and pagination
114
116
  */
115
- fetchCollection<M extends Record<string, any>>(collectionPath: string, options?: FetchCollectionOptions<M>): Promise<Entity<M>[]>;
117
+ fetchCollection<M extends Record<string, unknown>>(collectionPath: string, options?: FetchCollectionOptions<M>): Promise<Entity<M>[]>;
116
118
  /**
117
119
  * Search entities by text
118
120
  */
119
- searchEntities<M extends Record<string, any>>(collectionPath: string, searchString: string, options?: SearchOptions<M>): Promise<Entity<M>[]>;
121
+ searchEntities<M extends Record<string, unknown>>(collectionPath: string, searchString: string, options?: SearchOptions<M>): Promise<Entity<M>[]>;
120
122
  /**
121
123
  * Count entities in a collection
122
124
  */
123
- countEntities<M extends Record<string, any>>(collectionPath: string, options?: CountOptions<M>): Promise<number>;
125
+ countEntities<M extends Record<string, unknown>>(collectionPath: string, options?: CountOptions<M>): Promise<number>;
124
126
  /**
125
127
  * Save an entity (create or update)
126
128
  */
127
- saveEntity<M extends Record<string, any>>(collectionPath: string, values: Partial<M>, entityId?: string | number, databaseId?: string): Promise<Entity<M>>;
129
+ saveEntity<M extends Record<string, unknown>>(collectionPath: string, values: Partial<M>, entityId?: string | number, databaseId?: string): Promise<Entity<M>>;
128
130
  /**
129
131
  * Delete an entity by ID
130
132
  */
@@ -204,11 +206,173 @@ export interface DataTransformer {
204
206
  /**
205
207
  * Transform entity data for storage in the database
206
208
  */
207
- serializeToDatabase<M extends Record<string, any>>(entity: M, collection: EntityCollection): Record<string, any>;
209
+ serializeToDatabase<M extends Record<string, unknown>>(entity: M, collection: EntityCollection): Record<string, unknown>;
208
210
  /**
209
211
  * Transform database data back to entity format
210
212
  */
211
- deserializeFromDatabase<M extends Record<string, any>>(data: Record<string, any>, collection: EntityCollection): Promise<M>;
213
+ deserializeFromDatabase<M extends Record<string, unknown>>(data: Record<string, unknown>, collection: EntityCollection): Promise<M>;
214
+ }
215
+ /**
216
+ * Administrative operations for SQL-based databases (PostgreSQL, MySQL, etc.).
217
+ * Used by the SQL Editor, RLS Editor, and schema browser.
218
+ *
219
+ * @group Admin
220
+ */
221
+ export interface SQLAdmin {
222
+ /**
223
+ * Execute raw SQL against the database.
224
+ */
225
+ executeSql(sql: string, options?: {
226
+ database?: string;
227
+ role?: string;
228
+ }): Promise<Record<string, unknown>[]>;
229
+ /**
230
+ * Fetch the available databases on the server.
231
+ */
232
+ fetchAvailableDatabases?(): Promise<string[]>;
233
+ /**
234
+ * Fetch the available database roles.
235
+ */
236
+ fetchAvailableRoles?(): Promise<string[]>;
237
+ /**
238
+ * Fetch the current database name.
239
+ */
240
+ fetchCurrentDatabase?(): Promise<string | undefined>;
241
+ }
242
+ /**
243
+ * Administrative operations for document-based databases (MongoDB, Firestore, etc.).
244
+ * Used by future document administration tools.
245
+ *
246
+ * @group Admin
247
+ */
248
+ export interface DocumentAdmin {
249
+ /**
250
+ * Execute an aggregation pipeline or equivalent query.
251
+ */
252
+ executeAggregate?(pipeline: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
253
+ /**
254
+ * Fetch statistics for a collection (document count, size, etc.).
255
+ */
256
+ fetchCollectionStats?(collectionName: string): Promise<{
257
+ count: number;
258
+ sizeBytes?: number;
259
+ }>;
260
+ }
261
+ /**
262
+ * Administrative operations for schema management.
263
+ * Shared across SQL and document databases.
264
+ *
265
+ * @group Admin
266
+ */
267
+ export interface SchemaAdmin {
268
+ /**
269
+ * Fetch database tables/collections not yet mapped to a Rebase collection.
270
+ */
271
+ fetchUnmappedTables?(mappedPaths?: string[]): Promise<string[]>;
272
+ /**
273
+ * Fetch column/field metadata for a single table/collection.
274
+ * The return type is generic — SQL backends return TableMetadata,
275
+ * document backends may return a different shape.
276
+ */
277
+ fetchTableMetadata?(tableName: string): Promise<unknown>;
278
+ }
279
+ /**
280
+ * Metadata for a database branch.
281
+ * @group Admin
282
+ */
283
+ export interface BranchInfo {
284
+ /** Branch name (without prefix). */
285
+ name: string;
286
+ /** The database this branch was created from. */
287
+ parentDatabase: string;
288
+ /** When the branch was created. */
289
+ createdAt: Date;
290
+ /** Size in bytes, if available from the server. */
291
+ sizeBytes?: number;
292
+ }
293
+ /**
294
+ * Administrative operations for database branching.
295
+ * Allows creating isolated database copies for development/preview workflows.
296
+ *
297
+ * @group Admin
298
+ */
299
+ export interface BranchAdmin {
300
+ /** Create a new branch (database copy) from the current or specified source database. */
301
+ createBranch(name: string, options?: {
302
+ source?: string;
303
+ }): Promise<BranchInfo>;
304
+ /** Delete a branch database. Cannot delete the main/default database. */
305
+ deleteBranch(name: string): Promise<void>;
306
+ /** List all branches (databases that were created via branching). */
307
+ listBranches(): Promise<BranchInfo[]>;
308
+ /** Get info about a specific branch. */
309
+ getBranchInfo(name: string): Promise<BranchInfo | undefined>;
310
+ }
311
+ /**
312
+ * Union type for all admin capabilities.
313
+ * A backend may implement any combination of these interfaces.
314
+ *
315
+ * Use type guards (`isSQLAdmin`, `isDocumentAdmin`, `isSchemaAdmin`, `isBranchAdmin`)
316
+ * to safely narrow the type before calling methods.
317
+ *
318
+ * @group Admin
319
+ */
320
+ export type DatabaseAdmin = Partial<SQLAdmin> & Partial<DocumentAdmin> & Partial<SchemaAdmin> & Partial<BranchAdmin>;
321
+ /**
322
+ * Type guard: does this admin support SQL operations?
323
+ * @group Admin
324
+ */
325
+ export declare function isSQLAdmin(admin: DatabaseAdmin | undefined): admin is SQLAdmin;
326
+ /**
327
+ * Type guard: does this admin support document operations?
328
+ * @group Admin
329
+ */
330
+ export declare function isDocumentAdmin(admin: DatabaseAdmin | undefined): admin is DocumentAdmin;
331
+ /**
332
+ * Type guard: does this admin support schema management?
333
+ * @group Admin
334
+ */
335
+ export declare function isSchemaAdmin(admin: DatabaseAdmin | undefined): admin is SchemaAdmin;
336
+ /**
337
+ * Type guard: does this admin support database branching?
338
+ * @group Admin
339
+ */
340
+ export declare function isBranchAdmin(admin: DatabaseAdmin | undefined): admin is BranchAdmin;
341
+ /**
342
+ * Health check result returned by `healthCheck()`.
343
+ * @group Lifecycle
344
+ */
345
+ export interface HealthCheckResult {
346
+ /** Whether the backend is healthy and able to serve requests. */
347
+ healthy: boolean;
348
+ /** Round-trip latency to the database in milliseconds. */
349
+ latencyMs: number;
350
+ /** Optional details (e.g., pool stats, replication lag). */
351
+ details?: Record<string, unknown>;
352
+ }
353
+ /**
354
+ * Lifecycle contract for backend components that hold resources
355
+ * (database connections, WebSocket pools, timers, etc.).
356
+ *
357
+ * All methods are optional — simple backends (e.g., in-memory) can skip them.
358
+ * @group Lifecycle
359
+ */
360
+ export interface BackendLifecycle {
361
+ /**
362
+ * Initialize the backend: open connections, run migrations, seed data.
363
+ * Called once during startup. Idempotent.
364
+ */
365
+ initialize?(): Promise<void>;
366
+ /**
367
+ * Check whether the backend is healthy and reachable.
368
+ * Should be fast (< 1 s) and safe to call frequently.
369
+ */
370
+ healthCheck?(): Promise<HealthCheckResult>;
371
+ /**
372
+ * Gracefully shut down: close connections, flush buffers, cancel timers.
373
+ * After calling `destroy()`, no other methods should be called.
374
+ */
375
+ destroy?(): Promise<void>;
212
376
  }
213
377
  /**
214
378
  * Configuration for creating a database backend
@@ -228,9 +392,11 @@ export interface BackendConfig {
228
392
  schema?: unknown;
229
393
  }
230
394
  /**
231
- * A complete backend instance with all required services
395
+ * A complete backend instance with all required services.
396
+ *
397
+ * Now includes optional lifecycle management and admin capabilities.
232
398
  */
233
- export interface BackendInstance {
399
+ export interface BackendInstance extends BackendLifecycle {
234
400
  /**
235
401
  * Entity repository for CRUD operations
236
402
  */
@@ -247,8 +413,121 @@ export interface BackendInstance {
247
413
  * The underlying database connection
248
414
  */
249
415
  connection: DatabaseConnection;
416
+ /**
417
+ * Administrative operations (SQL, schema, documents).
418
+ * What's available depends on the backend type — use type guards
419
+ * (`isSQLAdmin`, `isSchemaAdmin`, etc.) to narrow.
420
+ */
421
+ admin?: DatabaseAdmin;
250
422
  }
251
423
  /**
252
424
  * Factory function type for creating backend instances
253
425
  */
254
426
  export type BackendFactory<TConfig extends BackendConfig = BackendConfig> = (config: TConfig) => BackendInstance;
427
+ /**
428
+ * A `BackendBootstrapper` encapsulates all driver-specific initialization logic.
429
+ *
430
+ * Instead of hard-coding Postgres setup into `initializeRebaseBackend()`,
431
+ * each database backend provides its own bootstrapper that knows how to:
432
+ * - Create the DataDriver from a config object
433
+ * - Optionally initialize auth tables
434
+ * - Optionally create a realtime service
435
+ * - Mount driver-specific API routes
436
+ *
437
+ * The main `initializeRebaseBackend()` becomes a **coordinator** that iterates
438
+ * registered bootstrappers, calls their hooks, and wires the results together.
439
+ *
440
+ * @group Backend
441
+ *
442
+ * @example
443
+ * ```typescript
444
+ * // Third-party MySQL bootstrapper
445
+ * const mysqlBootstrapper: BackendBootstrapper = {
446
+ * type: "mysql",
447
+ * initializeDriver: async (config) => new MySQLDataDriver(config.connection),
448
+ * initializeRealtime: async (config) => new MySQLChangeStreamRealtime(config.connection),
449
+ * };
450
+ *
451
+ * initializeRebaseBackend({
452
+ * ...config,
453
+ * bootstrappers: [postgresBootstrapper, mysqlBootstrapper]
454
+ * });
455
+ * ```
456
+ */
457
+ export interface BackendBootstrapper {
458
+ /**
459
+ * Which driver type this bootstrapper handles.
460
+ * Must match the `type` field on the driver config object
461
+ * (e.g., `"postgres"`, `"mongodb"`, `"mysql"`).
462
+ */
463
+ type: string;
464
+ /**
465
+ * Create a DataDriver from the given config.
466
+ * This is the only **required** method.
467
+ */
468
+ initializeDriver(config: unknown): Promise<InitializedDriver>;
469
+ /**
470
+ * Initialize auth tables / services if this driver supports them.
471
+ * Return undefined if auth is not supported by this backend.
472
+ */
473
+ initializeAuth?(config: unknown, driverResult: InitializedDriver): Promise<BootstrappedAuth | undefined>;
474
+ /**
475
+ * Initialize history tables / services if this driver supports them.
476
+ * Return undefined if history is not supported by this backend.
477
+ */
478
+ initializeHistory?(config: unknown, driverResult: InitializedDriver): Promise<{
479
+ historyService: unknown;
480
+ } | undefined>;
481
+ /**
482
+ * Create a realtime provider for this driver.
483
+ * Return undefined if the driver does not support realtime.
484
+ */
485
+ initializeRealtime?(config: unknown, driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
486
+ /**
487
+ * Mount any driver-specific HTTP routes (e.g., custom admin endpoints).
488
+ * Called after all drivers are initialized.
489
+ */
490
+ mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
491
+ /**
492
+ * Return admin capabilities for this driver.
493
+ */
494
+ getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
495
+ /**
496
+ * Initialize WebSocket server for realtime operations.
497
+ */
498
+ initializeWebsockets?(server: unknown, realtimeService: RealtimeProvider, driver: import("../controllers/data_driver").DataDriver, config?: unknown): Promise<void> | void;
499
+ }
500
+ /**
501
+ * Result of `BackendBootstrapper.initializeDriver()`.
502
+ * @group Backend
503
+ */
504
+ export interface InitializedDriver {
505
+ /** The DataDriver instance, ready for use. */
506
+ driver: import("../controllers/data_driver").DataDriver;
507
+ /** The realtime service, if the driver created one during init. */
508
+ realtimeProvider?: RealtimeProvider;
509
+ /** A collection registry to register schema / tables into. */
510
+ collectionRegistry?: CollectionRegistryInterface;
511
+ /** The underlying database connection (for lifecycle management). */
512
+ connection?: DatabaseConnection;
513
+ /**
514
+ * Opaque handle that the bootstrapper can use in subsequent hooks
515
+ * (e.g., `initializeAuth`, `mountRoutes`) to access driver internals.
516
+ * Not used by the coordinator.
517
+ */
518
+ internals?: unknown;
519
+ }
520
+ /**
521
+ * Result of `BackendBootstrapper.initializeAuth()`.
522
+ * @group Backend
523
+ */
524
+ export interface BootstrappedAuth {
525
+ /** User management service. */
526
+ userService: unknown;
527
+ /** Role management service. */
528
+ roleService: unknown;
529
+ /** Email service (optional). */
530
+ emailService?: unknown;
531
+ /** Combined Auth Repository for unified token and user management. */
532
+ authRepository?: unknown;
533
+ }
@@ -0,0 +1,14 @@
1
+ import { AuthController, RebaseData } from "../controllers";
2
+ import { User } from "../users";
3
+ import { EntityCollection } from "./collections";
4
+ import { AppView } from "../controllers/navigation";
5
+ export type EntityCollectionsBuilder<EC extends EntityCollection = EntityCollection> = (params: {
6
+ user: User | null;
7
+ authController: AuthController;
8
+ data: RebaseData;
9
+ }) => EC[] | Promise<EC[]>;
10
+ export type AppViewsBuilder = (params: {
11
+ user: User | null;
12
+ authController: AuthController;
13
+ data: RebaseData;
14
+ }) => AppView[] | Promise<AppView[]>;