@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.
- package/README.md +1 -1
- package/dist/controllers/analytics_controller.d.ts +2 -2
- package/dist/controllers/auth.d.ts +50 -6
- package/dist/controllers/client.d.ts +58 -0
- package/dist/controllers/collection_registry.d.ts +44 -0
- package/dist/controllers/customization_controller.d.ts +5 -1
- package/dist/controllers/data.d.ts +141 -0
- package/dist/controllers/{datasource.d.ts → data_driver.d.ts} +25 -36
- package/dist/controllers/database_admin.d.ts +11 -0
- package/dist/controllers/effective_role.d.ts +4 -0
- package/dist/controllers/index.d.ts +11 -5
- package/dist/controllers/navigation.d.ts +9 -58
- package/dist/controllers/registry.d.ts +51 -0
- package/dist/controllers/side_entity_controller.d.ts +1 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +113 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +112 -11
- package/dist/index.umd.js.map +1 -1
- package/dist/rebase_context.d.ts +35 -25
- package/dist/types/backend.d.ts +296 -17
- package/dist/types/builders.d.ts +14 -0
- package/dist/types/collections.d.ts +166 -241
- package/dist/types/data_source.d.ts +64 -0
- package/dist/types/entities.d.ts +29 -24
- package/dist/types/entity_actions.d.ts +7 -7
- package/dist/types/entity_callbacks.d.ts +4 -4
- package/dist/types/entity_overrides.d.ts +6 -2
- package/dist/types/entity_views.d.ts +61 -0
- package/dist/types/index.d.ts +8 -5
- package/dist/types/plugins.d.ts +170 -221
- package/dist/types/properties.d.ts +17 -29
- package/dist/types/property_config.d.ts +13 -11
- package/dist/types/slots.d.ts +228 -0
- package/dist/types/translations.d.ts +826 -0
- package/dist/types/user_management_delegate.d.ts +42 -0
- package/dist/types/websockets.d.ts +45 -0
- package/dist/users/user.d.ts +4 -0
- package/package.json +7 -39
- package/src/controllers/analytics_controller.tsx +2 -2
- package/src/controllers/auth.tsx +53 -6
- package/src/controllers/client.ts +74 -0
- package/src/controllers/collection_registry.ts +53 -0
- package/src/controllers/customization_controller.tsx +6 -1
- package/src/controllers/data.ts +153 -0
- package/src/controllers/{datasource.ts → data_driver.ts} +41 -37
- package/src/controllers/database_admin.ts +22 -0
- package/src/controllers/effective_role.ts +4 -0
- package/src/controllers/index.ts +14 -5
- package/src/controllers/navigation.ts +9 -73
- package/src/controllers/registry.ts +62 -0
- package/src/controllers/side_entity_controller.tsx +1 -2
- package/src/index.ts +0 -1
- package/src/rebase_context.tsx +37 -33
- package/src/types/backend.ts +351 -19
- package/src/types/builders.ts +16 -0
- package/src/types/collections.ts +196 -259
- package/src/types/data_source.ts +156 -0
- package/src/types/entities.ts +35 -28
- package/src/types/entity_actions.tsx +6 -6
- package/src/types/entity_callbacks.ts +4 -4
- package/src/types/entity_overrides.tsx +6 -2
- package/src/types/entity_views.tsx +77 -0
- package/src/types/index.ts +9 -5
- package/src/types/plugins.tsx +198 -256
- package/src/types/properties.ts +22 -31
- package/src/types/property_config.tsx +11 -11
- package/src/types/slots.tsx +271 -0
- package/src/types/translations.ts +923 -0
- package/src/types/user_management_delegate.ts +43 -0
- package/src/types/websockets.ts +48 -0
- package/src/users/user.ts +5 -0
- package/dist/components/EntityFormActionsProps.d.ts +0 -17
- package/dist/components/EntityFormProps.d.ts +0 -46
- package/dist/components/PropertyPreviewProps.d.ts +0 -50
- package/dist/components/formex.d.ts +0 -40
- package/dist/components/index.d.ts +0 -3
- package/dist/types/fields.d.ts +0 -221
- package/dist/types/rebase.d.ts +0 -180
- package/src/components/EntityFormActionsProps.tsx +0 -18
- package/src/components/EntityFormProps.tsx +0 -52
- package/src/components/PropertyPreviewProps.tsx +0 -61
- package/src/components/formex.tsx +0 -46
- package/src/components/index.ts +0 -3
- package/src/types/fields.tsx +0 -298
- package/src/types/rebase.tsx +0 -211
package/src/types/backend.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface DatabaseConnection {
|
|
|
20
20
|
readonly isConnected?: boolean;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Close the database connection
|
|
23
|
+
* Close the database connection and release resources.
|
|
24
24
|
*/
|
|
25
25
|
close?(): Promise<void>;
|
|
26
26
|
}
|
|
@@ -41,7 +41,7 @@ export interface QueryFilter {
|
|
|
41
41
|
/**
|
|
42
42
|
* Options for fetching a collection of entities
|
|
43
43
|
*/
|
|
44
|
-
export interface FetchCollectionOptions<M extends Record<string,
|
|
44
|
+
export interface FetchCollectionOptions<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
45
45
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
46
46
|
orderBy?: string;
|
|
47
47
|
order?: "desc" | "asc";
|
|
@@ -49,23 +49,25 @@ export interface FetchCollectionOptions<M extends Record<string, any> = any> {
|
|
|
49
49
|
startAfter?: unknown;
|
|
50
50
|
searchString?: string;
|
|
51
51
|
databaseId?: string;
|
|
52
|
+
collection?: EntityCollection;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Options for searching entities
|
|
56
57
|
*/
|
|
57
|
-
export interface SearchOptions<M extends Record<string,
|
|
58
|
+
export interface SearchOptions<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
58
59
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
59
60
|
orderBy?: string;
|
|
60
61
|
order?: "desc" | "asc";
|
|
61
62
|
limit?: number;
|
|
62
63
|
databaseId?: string;
|
|
64
|
+
collection?: EntityCollection;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
/**
|
|
66
68
|
* Options for counting entities
|
|
67
69
|
*/
|
|
68
|
-
export interface CountOptions<M extends Record<string,
|
|
70
|
+
export interface CountOptions<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
69
71
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
70
72
|
databaseId?: string;
|
|
71
73
|
}
|
|
@@ -79,11 +81,11 @@ export interface CountOptions<M extends Record<string, any> = any> {
|
|
|
79
81
|
*
|
|
80
82
|
* @template T The type of condition returned by the builder (e.g., SQL for PostgreSQL, Filter<Document> for MongoDB)
|
|
81
83
|
*/
|
|
82
|
-
export interface ConditionBuilder<T =
|
|
84
|
+
export interface ConditionBuilder<T = unknown> {
|
|
83
85
|
/**
|
|
84
86
|
* Build filter conditions from Rebase FilterValues
|
|
85
87
|
*/
|
|
86
|
-
buildFilterConditions<M extends Record<string,
|
|
88
|
+
buildFilterConditions<M extends Record<string, unknown>>(
|
|
87
89
|
filter: FilterValues<Extract<keyof M, string>>,
|
|
88
90
|
collectionPath: string,
|
|
89
91
|
...args: unknown[]
|
|
@@ -117,8 +119,8 @@ export interface ConditionBuilder<T = any> {
|
|
|
117
119
|
* // DrizzleConditionBuilder satisfies this type
|
|
118
120
|
* const builder: ConditionBuilderStatic<SQL> = DrizzleConditionBuilder;
|
|
119
121
|
*/
|
|
120
|
-
export type ConditionBuilderStatic<T =
|
|
121
|
-
buildFilterConditions<M extends Record<string,
|
|
122
|
+
export type ConditionBuilderStatic<T = unknown> = {
|
|
123
|
+
buildFilterConditions<M extends Record<string, unknown>>(
|
|
122
124
|
filter: FilterValues<Extract<keyof M, string>>,
|
|
123
125
|
...args: unknown[]
|
|
124
126
|
): T[];
|
|
@@ -148,7 +150,7 @@ export interface EntityRepository {
|
|
|
148
150
|
/**
|
|
149
151
|
* Fetch a single entity by ID
|
|
150
152
|
*/
|
|
151
|
-
fetchEntity<M extends Record<string,
|
|
153
|
+
fetchEntity<M extends Record<string, unknown>>(
|
|
152
154
|
collectionPath: string,
|
|
153
155
|
entityId: string | number,
|
|
154
156
|
databaseId?: string
|
|
@@ -157,7 +159,7 @@ export interface EntityRepository {
|
|
|
157
159
|
/**
|
|
158
160
|
* Fetch a collection of entities with optional filtering, ordering, and pagination
|
|
159
161
|
*/
|
|
160
|
-
fetchCollection<M extends Record<string,
|
|
162
|
+
fetchCollection<M extends Record<string, unknown>>(
|
|
161
163
|
collectionPath: string,
|
|
162
164
|
options?: FetchCollectionOptions<M>
|
|
163
165
|
): Promise<Entity<M>[]>;
|
|
@@ -165,7 +167,7 @@ export interface EntityRepository {
|
|
|
165
167
|
/**
|
|
166
168
|
* Search entities by text
|
|
167
169
|
*/
|
|
168
|
-
searchEntities<M extends Record<string,
|
|
170
|
+
searchEntities<M extends Record<string, unknown>>(
|
|
169
171
|
collectionPath: string,
|
|
170
172
|
searchString: string,
|
|
171
173
|
options?: SearchOptions<M>
|
|
@@ -174,7 +176,7 @@ export interface EntityRepository {
|
|
|
174
176
|
/**
|
|
175
177
|
* Count entities in a collection
|
|
176
178
|
*/
|
|
177
|
-
countEntities<M extends Record<string,
|
|
179
|
+
countEntities<M extends Record<string, unknown>>(
|
|
178
180
|
collectionPath: string,
|
|
179
181
|
options?: CountOptions<M>
|
|
180
182
|
): Promise<number>;
|
|
@@ -182,7 +184,7 @@ export interface EntityRepository {
|
|
|
182
184
|
/**
|
|
183
185
|
* Save an entity (create or update)
|
|
184
186
|
*/
|
|
185
|
-
saveEntity<M extends Record<string,
|
|
187
|
+
saveEntity<M extends Record<string, unknown>>(
|
|
186
188
|
collectionPath: string,
|
|
187
189
|
values: Partial<M>,
|
|
188
190
|
entityId?: string | number,
|
|
@@ -315,20 +317,218 @@ export interface DataTransformer {
|
|
|
315
317
|
/**
|
|
316
318
|
* Transform entity data for storage in the database
|
|
317
319
|
*/
|
|
318
|
-
serializeToDatabase<M extends Record<string,
|
|
320
|
+
serializeToDatabase<M extends Record<string, unknown>>(
|
|
319
321
|
entity: M,
|
|
320
322
|
collection: EntityCollection
|
|
321
|
-
): Record<string,
|
|
323
|
+
): Record<string, unknown>;
|
|
322
324
|
|
|
323
325
|
/**
|
|
324
326
|
* Transform database data back to entity format
|
|
325
327
|
*/
|
|
326
|
-
deserializeFromDatabase<M extends Record<string,
|
|
327
|
-
data: Record<string,
|
|
328
|
+
deserializeFromDatabase<M extends Record<string, unknown>>(
|
|
329
|
+
data: Record<string, unknown>,
|
|
328
330
|
collection: EntityCollection
|
|
329
331
|
): Promise<M>;
|
|
330
332
|
}
|
|
331
333
|
|
|
334
|
+
// =============================================================================
|
|
335
|
+
// DATABASE ADMIN — CAPABILITY-SPECIFIC INTERFACES (1.3)
|
|
336
|
+
// =============================================================================
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Administrative operations for SQL-based databases (PostgreSQL, MySQL, etc.).
|
|
340
|
+
* Used by the SQL Editor, RLS Editor, and schema browser.
|
|
341
|
+
*
|
|
342
|
+
* @group Admin
|
|
343
|
+
*/
|
|
344
|
+
export interface SQLAdmin {
|
|
345
|
+
/**
|
|
346
|
+
* Execute raw SQL against the database.
|
|
347
|
+
*/
|
|
348
|
+
executeSql(sql: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]>;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Fetch the available databases on the server.
|
|
352
|
+
*/
|
|
353
|
+
fetchAvailableDatabases?(): Promise<string[]>;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Fetch the available database roles.
|
|
357
|
+
*/
|
|
358
|
+
fetchAvailableRoles?(): Promise<string[]>;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Fetch the current database name.
|
|
362
|
+
*/
|
|
363
|
+
fetchCurrentDatabase?(): Promise<string | undefined>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Administrative operations for document-based databases (MongoDB, Firestore, etc.).
|
|
368
|
+
* Used by future document administration tools.
|
|
369
|
+
*
|
|
370
|
+
* @group Admin
|
|
371
|
+
*/
|
|
372
|
+
export interface DocumentAdmin {
|
|
373
|
+
/**
|
|
374
|
+
* Execute an aggregation pipeline or equivalent query.
|
|
375
|
+
*/
|
|
376
|
+
executeAggregate?(pipeline: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Fetch statistics for a collection (document count, size, etc.).
|
|
380
|
+
*/
|
|
381
|
+
fetchCollectionStats?(collectionName: string): Promise<{ count: number; sizeBytes?: number }>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Administrative operations for schema management.
|
|
386
|
+
* Shared across SQL and document databases.
|
|
387
|
+
*
|
|
388
|
+
* @group Admin
|
|
389
|
+
*/
|
|
390
|
+
export interface SchemaAdmin {
|
|
391
|
+
/**
|
|
392
|
+
* Fetch database tables/collections not yet mapped to a Rebase collection.
|
|
393
|
+
*/
|
|
394
|
+
fetchUnmappedTables?(mappedPaths?: string[]): Promise<string[]>;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Fetch column/field metadata for a single table/collection.
|
|
398
|
+
* The return type is generic — SQL backends return TableMetadata,
|
|
399
|
+
* document backends may return a different shape.
|
|
400
|
+
*/
|
|
401
|
+
fetchTableMetadata?(tableName: string): Promise<unknown>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Metadata for a database branch.
|
|
406
|
+
* @group Admin
|
|
407
|
+
*/
|
|
408
|
+
export interface BranchInfo {
|
|
409
|
+
/** Branch name (without prefix). */
|
|
410
|
+
name: string;
|
|
411
|
+
/** The database this branch was created from. */
|
|
412
|
+
parentDatabase: string;
|
|
413
|
+
/** When the branch was created. */
|
|
414
|
+
createdAt: Date;
|
|
415
|
+
/** Size in bytes, if available from the server. */
|
|
416
|
+
sizeBytes?: number;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Administrative operations for database branching.
|
|
421
|
+
* Allows creating isolated database copies for development/preview workflows.
|
|
422
|
+
*
|
|
423
|
+
* @group Admin
|
|
424
|
+
*/
|
|
425
|
+
export interface BranchAdmin {
|
|
426
|
+
/** Create a new branch (database copy) from the current or specified source database. */
|
|
427
|
+
createBranch(name: string, options?: { source?: string }): Promise<BranchInfo>;
|
|
428
|
+
|
|
429
|
+
/** Delete a branch database. Cannot delete the main/default database. */
|
|
430
|
+
deleteBranch(name: string): Promise<void>;
|
|
431
|
+
|
|
432
|
+
/** List all branches (databases that were created via branching). */
|
|
433
|
+
listBranches(): Promise<BranchInfo[]>;
|
|
434
|
+
|
|
435
|
+
/** Get info about a specific branch. */
|
|
436
|
+
getBranchInfo(name: string): Promise<BranchInfo | undefined>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Union type for all admin capabilities.
|
|
441
|
+
* A backend may implement any combination of these interfaces.
|
|
442
|
+
*
|
|
443
|
+
* Use type guards (`isSQLAdmin`, `isDocumentAdmin`, `isSchemaAdmin`, `isBranchAdmin`)
|
|
444
|
+
* to safely narrow the type before calling methods.
|
|
445
|
+
*
|
|
446
|
+
* @group Admin
|
|
447
|
+
*/
|
|
448
|
+
export type DatabaseAdmin = Partial<SQLAdmin> & Partial<DocumentAdmin> & Partial<SchemaAdmin> & Partial<BranchAdmin>;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Type guard: does this admin support SQL operations?
|
|
452
|
+
* @group Admin
|
|
453
|
+
*/
|
|
454
|
+
export function isSQLAdmin(admin: DatabaseAdmin | undefined): admin is SQLAdmin {
|
|
455
|
+
return !!admin && typeof (admin as SQLAdmin).executeSql === "function";
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Type guard: does this admin support document operations?
|
|
460
|
+
* @group Admin
|
|
461
|
+
*/
|
|
462
|
+
export function isDocumentAdmin(admin: DatabaseAdmin | undefined): admin is DocumentAdmin {
|
|
463
|
+
return !!admin && (
|
|
464
|
+
typeof (admin as DocumentAdmin).executeAggregate === "function" ||
|
|
465
|
+
typeof (admin as DocumentAdmin).fetchCollectionStats === "function"
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Type guard: does this admin support schema management?
|
|
471
|
+
* @group Admin
|
|
472
|
+
*/
|
|
473
|
+
export function isSchemaAdmin(admin: DatabaseAdmin | undefined): admin is SchemaAdmin {
|
|
474
|
+
return !!admin && (
|
|
475
|
+
typeof (admin as SchemaAdmin).fetchUnmappedTables === "function" ||
|
|
476
|
+
typeof (admin as SchemaAdmin).fetchTableMetadata === "function"
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Type guard: does this admin support database branching?
|
|
482
|
+
* @group Admin
|
|
483
|
+
*/
|
|
484
|
+
export function isBranchAdmin(admin: DatabaseAdmin | undefined): admin is BranchAdmin {
|
|
485
|
+
return !!admin && typeof (admin as BranchAdmin).createBranch === "function";
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// =============================================================================
|
|
489
|
+
// LIFECYCLE INTERFACES (1.4)
|
|
490
|
+
// =============================================================================
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Health check result returned by `healthCheck()`.
|
|
494
|
+
* @group Lifecycle
|
|
495
|
+
*/
|
|
496
|
+
export interface HealthCheckResult {
|
|
497
|
+
/** Whether the backend is healthy and able to serve requests. */
|
|
498
|
+
healthy: boolean;
|
|
499
|
+
/** Round-trip latency to the database in milliseconds. */
|
|
500
|
+
latencyMs: number;
|
|
501
|
+
/** Optional details (e.g., pool stats, replication lag). */
|
|
502
|
+
details?: Record<string, unknown>;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Lifecycle contract for backend components that hold resources
|
|
507
|
+
* (database connections, WebSocket pools, timers, etc.).
|
|
508
|
+
*
|
|
509
|
+
* All methods are optional — simple backends (e.g., in-memory) can skip them.
|
|
510
|
+
* @group Lifecycle
|
|
511
|
+
*/
|
|
512
|
+
export interface BackendLifecycle {
|
|
513
|
+
/**
|
|
514
|
+
* Initialize the backend: open connections, run migrations, seed data.
|
|
515
|
+
* Called once during startup. Idempotent.
|
|
516
|
+
*/
|
|
517
|
+
initialize?(): Promise<void>;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Check whether the backend is healthy and reachable.
|
|
521
|
+
* Should be fast (< 1 s) and safe to call frequently.
|
|
522
|
+
*/
|
|
523
|
+
healthCheck?(): Promise<HealthCheckResult>;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Gracefully shut down: close connections, flush buffers, cancel timers.
|
|
527
|
+
* After calling `destroy()`, no other methods should be called.
|
|
528
|
+
*/
|
|
529
|
+
destroy?(): Promise<void>;
|
|
530
|
+
}
|
|
531
|
+
|
|
332
532
|
// =============================================================================
|
|
333
533
|
// BACKEND FACTORY INTERFACES
|
|
334
534
|
// =============================================================================
|
|
@@ -354,9 +554,11 @@ export interface BackendConfig {
|
|
|
354
554
|
}
|
|
355
555
|
|
|
356
556
|
/**
|
|
357
|
-
* A complete backend instance with all required services
|
|
557
|
+
* A complete backend instance with all required services.
|
|
558
|
+
*
|
|
559
|
+
* Now includes optional lifecycle management and admin capabilities.
|
|
358
560
|
*/
|
|
359
|
-
export interface BackendInstance {
|
|
561
|
+
export interface BackendInstance extends BackendLifecycle {
|
|
360
562
|
/**
|
|
361
563
|
* Entity repository for CRUD operations
|
|
362
564
|
*/
|
|
@@ -376,6 +578,13 @@ export interface BackendInstance {
|
|
|
376
578
|
* The underlying database connection
|
|
377
579
|
*/
|
|
378
580
|
connection: DatabaseConnection;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Administrative operations (SQL, schema, documents).
|
|
584
|
+
* What's available depends on the backend type — use type guards
|
|
585
|
+
* (`isSQLAdmin`, `isSchemaAdmin`, etc.) to narrow.
|
|
586
|
+
*/
|
|
587
|
+
admin?: DatabaseAdmin;
|
|
379
588
|
}
|
|
380
589
|
|
|
381
590
|
/**
|
|
@@ -383,3 +592,126 @@ export interface BackendInstance {
|
|
|
383
592
|
*/
|
|
384
593
|
export type BackendFactory<TConfig extends BackendConfig = BackendConfig> =
|
|
385
594
|
(config: TConfig) => BackendInstance;
|
|
595
|
+
|
|
596
|
+
// =============================================================================
|
|
597
|
+
// BACKEND BOOTSTRAPPER (1.2)
|
|
598
|
+
// =============================================================================
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* A `BackendBootstrapper` encapsulates all driver-specific initialization logic.
|
|
602
|
+
*
|
|
603
|
+
* Instead of hard-coding Postgres setup into `initializeRebaseBackend()`,
|
|
604
|
+
* each database backend provides its own bootstrapper that knows how to:
|
|
605
|
+
* - Create the DataDriver from a config object
|
|
606
|
+
* - Optionally initialize auth tables
|
|
607
|
+
* - Optionally create a realtime service
|
|
608
|
+
* - Mount driver-specific API routes
|
|
609
|
+
*
|
|
610
|
+
* The main `initializeRebaseBackend()` becomes a **coordinator** that iterates
|
|
611
|
+
* registered bootstrappers, calls their hooks, and wires the results together.
|
|
612
|
+
*
|
|
613
|
+
* @group Backend
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* // Third-party MySQL bootstrapper
|
|
618
|
+
* const mysqlBootstrapper: BackendBootstrapper = {
|
|
619
|
+
* type: "mysql",
|
|
620
|
+
* initializeDriver: async (config) => new MySQLDataDriver(config.connection),
|
|
621
|
+
* initializeRealtime: async (config) => new MySQLChangeStreamRealtime(config.connection),
|
|
622
|
+
* };
|
|
623
|
+
*
|
|
624
|
+
* initializeRebaseBackend({
|
|
625
|
+
* ...config,
|
|
626
|
+
* bootstrappers: [postgresBootstrapper, mysqlBootstrapper]
|
|
627
|
+
* });
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
export interface BackendBootstrapper {
|
|
631
|
+
/**
|
|
632
|
+
* Which driver type this bootstrapper handles.
|
|
633
|
+
* Must match the `type` field on the driver config object
|
|
634
|
+
* (e.g., `"postgres"`, `"mongodb"`, `"mysql"`).
|
|
635
|
+
*/
|
|
636
|
+
type: string;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Create a DataDriver from the given config.
|
|
640
|
+
* This is the only **required** method.
|
|
641
|
+
*/
|
|
642
|
+
initializeDriver(config: unknown): Promise<InitializedDriver>;
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Initialize auth tables / services if this driver supports them.
|
|
646
|
+
* Return undefined if auth is not supported by this backend.
|
|
647
|
+
*/
|
|
648
|
+
initializeAuth?(config: unknown, driverResult: InitializedDriver): Promise<BootstrappedAuth | undefined>;
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Initialize history tables / services if this driver supports them.
|
|
652
|
+
* Return undefined if history is not supported by this backend.
|
|
653
|
+
*/
|
|
654
|
+
initializeHistory?(config: unknown, driverResult: InitializedDriver): Promise<{ historyService: unknown } | undefined>;
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Create a realtime provider for this driver.
|
|
658
|
+
* Return undefined if the driver does not support realtime.
|
|
659
|
+
*/
|
|
660
|
+
initializeRealtime?(config: unknown, driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Mount any driver-specific HTTP routes (e.g., custom admin endpoints).
|
|
664
|
+
* Called after all drivers are initialized.
|
|
665
|
+
*/
|
|
666
|
+
mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Return admin capabilities for this driver.
|
|
670
|
+
*/
|
|
671
|
+
getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Initialize WebSocket server for realtime operations.
|
|
675
|
+
*/
|
|
676
|
+
initializeWebsockets?(server: unknown, realtimeService: RealtimeProvider, driver: import("../controllers/data_driver").DataDriver, config?: unknown): Promise<void> | void;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Result of `BackendBootstrapper.initializeDriver()`.
|
|
681
|
+
* @group Backend
|
|
682
|
+
*/
|
|
683
|
+
export interface InitializedDriver {
|
|
684
|
+
/** The DataDriver instance, ready for use. */
|
|
685
|
+
driver: import("../controllers/data_driver").DataDriver;
|
|
686
|
+
|
|
687
|
+
/** The realtime service, if the driver created one during init. */
|
|
688
|
+
realtimeProvider?: RealtimeProvider;
|
|
689
|
+
|
|
690
|
+
/** A collection registry to register schema / tables into. */
|
|
691
|
+
collectionRegistry?: CollectionRegistryInterface;
|
|
692
|
+
|
|
693
|
+
/** The underlying database connection (for lifecycle management). */
|
|
694
|
+
connection?: DatabaseConnection;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Opaque handle that the bootstrapper can use in subsequent hooks
|
|
698
|
+
* (e.g., `initializeAuth`, `mountRoutes`) to access driver internals.
|
|
699
|
+
* Not used by the coordinator.
|
|
700
|
+
*/
|
|
701
|
+
internals?: unknown;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Result of `BackendBootstrapper.initializeAuth()`.
|
|
706
|
+
* @group Backend
|
|
707
|
+
*/
|
|
708
|
+
export interface BootstrappedAuth {
|
|
709
|
+
/** User management service. */
|
|
710
|
+
userService: unknown;
|
|
711
|
+
/** Role management service. */
|
|
712
|
+
roleService: unknown;
|
|
713
|
+
/** Email service (optional). */
|
|
714
|
+
emailService?: unknown;
|
|
715
|
+
/** Combined Auth Repository for unified token and user management. */
|
|
716
|
+
authRepository?: unknown;
|
|
717
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthController, RebaseData } from "../controllers";
|
|
2
|
+
import { User } from "../users";
|
|
3
|
+
import { EntityCollection } from "./collections";
|
|
4
|
+
import { AppView } from "../controllers/navigation";
|
|
5
|
+
|
|
6
|
+
export type EntityCollectionsBuilder<EC extends EntityCollection = EntityCollection> = (params: {
|
|
7
|
+
user: User | null,
|
|
8
|
+
authController: AuthController,
|
|
9
|
+
data: RebaseData
|
|
10
|
+
}) => EC[] | Promise<EC[]>;
|
|
11
|
+
|
|
12
|
+
export type AppViewsBuilder = (params: {
|
|
13
|
+
user: User | null,
|
|
14
|
+
authController: AuthController,
|
|
15
|
+
data: RebaseData
|
|
16
|
+
}) => AppView[] | Promise<AppView[]>;
|