@rebasepro/sdk-generator 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 (84) hide show
  1. package/LICENSE +6 -0
  2. package/dist/common/src/collections/CollectionRegistry.d.ts +48 -0
  3. package/dist/common/src/collections/index.d.ts +1 -0
  4. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  5. package/dist/common/src/index.d.ts +3 -0
  6. package/dist/common/src/util/builders.d.ts +57 -0
  7. package/dist/common/src/util/callbacks.d.ts +6 -0
  8. package/dist/common/src/util/collections.d.ts +11 -0
  9. package/dist/common/src/util/common.d.ts +2 -0
  10. package/dist/common/src/util/conditions.d.ts +26 -0
  11. package/dist/common/src/util/entities.d.ts +36 -0
  12. package/dist/common/src/util/enums.d.ts +3 -0
  13. package/dist/common/src/util/index.d.ts +16 -0
  14. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  15. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  16. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  17. package/dist/common/src/util/paths.d.ts +14 -0
  18. package/dist/common/src/util/permissions.d.ts +5 -0
  19. package/dist/common/src/util/references.d.ts +2 -0
  20. package/dist/common/src/util/relations.d.ts +12 -0
  21. package/dist/common/src/util/resolutions.d.ts +72 -0
  22. package/dist/common/src/util/storage.d.ts +24 -0
  23. package/dist/index.cjs +211 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.es.js +208 -0
  26. package/dist/index.es.js.map +1 -0
  27. package/dist/sdk-generator/src/generate-types.d.ts +2 -0
  28. package/dist/sdk-generator/src/index.d.ts +19 -0
  29. package/dist/sdk-generator/src/utils.d.ts +22 -0
  30. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  31. package/dist/types/src/controllers/auth.d.ts +117 -0
  32. package/dist/types/src/controllers/client.d.ts +58 -0
  33. package/dist/types/src/controllers/collection_registry.d.ts +44 -0
  34. package/dist/types/src/controllers/customization_controller.d.ts +54 -0
  35. package/dist/types/src/controllers/data.d.ts +141 -0
  36. package/dist/types/src/controllers/data_driver.d.ts +168 -0
  37. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  38. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  39. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  40. package/dist/types/src/controllers/index.d.ts +17 -0
  41. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  42. package/dist/types/src/controllers/navigation.d.ts +213 -0
  43. package/dist/types/src/controllers/registry.d.ts +51 -0
  44. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  45. package/dist/types/src/controllers/side_entity_controller.d.ts +89 -0
  46. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  47. package/dist/types/src/controllers/storage.d.ts +173 -0
  48. package/dist/types/src/index.d.ts +4 -0
  49. package/dist/types/src/rebase_context.d.ts +101 -0
  50. package/dist/types/src/types/backend.d.ts +533 -0
  51. package/dist/types/src/types/builders.d.ts +14 -0
  52. package/dist/types/src/types/chips.d.ts +5 -0
  53. package/dist/types/src/types/collections.d.ts +812 -0
  54. package/dist/types/src/types/data_source.d.ts +64 -0
  55. package/dist/types/src/types/entities.d.ts +145 -0
  56. package/dist/types/src/types/entity_actions.d.ts +98 -0
  57. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  58. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  59. package/dist/types/src/types/entity_overrides.d.ts +9 -0
  60. package/dist/types/src/types/entity_views.d.ts +61 -0
  61. package/dist/types/src/types/export_import.d.ts +21 -0
  62. package/dist/types/src/types/index.d.ts +22 -0
  63. package/dist/types/src/types/locales.d.ts +4 -0
  64. package/dist/types/src/types/modify_collections.d.ts +5 -0
  65. package/dist/types/src/types/plugins.d.ts +225 -0
  66. package/dist/types/src/types/properties.d.ts +1091 -0
  67. package/dist/types/src/types/property_config.d.ts +70 -0
  68. package/dist/types/src/types/relations.d.ts +336 -0
  69. package/dist/types/src/types/slots.d.ts +228 -0
  70. package/dist/types/src/types/translations.d.ts +826 -0
  71. package/dist/types/src/types/user_management_delegate.d.ts +120 -0
  72. package/dist/types/src/types/websockets.d.ts +78 -0
  73. package/dist/types/src/users/index.d.ts +2 -0
  74. package/dist/types/src/users/roles.d.ts +22 -0
  75. package/dist/types/src/users/user.d.ts +46 -0
  76. package/jest.config.cjs +13 -0
  77. package/package.json +51 -0
  78. package/src/generate-types.ts +176 -0
  79. package/src/index.ts +71 -0
  80. package/src/json-logic-js.d.ts +8 -0
  81. package/src/utils.ts +42 -0
  82. package/test/sdk-generator.test.ts +78 -0
  83. package/tsconfig.json +26 -0
  84. package/vite.config.ts +49 -0
@@ -0,0 +1,101 @@
1
+ import { AnalyticsController, AuthController, StorageSource, UserConfigurationPersistence, DatabaseAdmin } from "./controllers";
2
+ import { RebaseData } from "./controllers/data";
3
+ import { User } from "./users";
4
+ import { UserManagementDelegate } from "./types/user_management_delegate";
5
+ /**
6
+ * Context that is provided to entity callbacks (hooks).
7
+ * It contains only the dependencies that are available in both the frontend and the backend.
8
+ * @group Hooks and utilities
9
+ */
10
+ export type RebaseCallContext<USER extends User = User> = {
11
+ /**
12
+ * Unified data access — `context.data.products.create(...)`.
13
+ * Access any collection as a dynamic property.
14
+ */
15
+ data: RebaseData;
16
+ /**
17
+ * Used storage implementation
18
+ */
19
+ storageSource: StorageSource;
20
+ /**
21
+ * Set by the backend when callbacks are executed on the server.
22
+ */
23
+ user?: USER;
24
+ };
25
+ /**
26
+ * Context that includes the internal controllers and contexts used by the app.
27
+ * Some controllers and context included in this context can be accessed
28
+ * directly from their respective hooks.
29
+ * @group Hooks and utilities
30
+ * @see useRebaseContext
31
+ */
32
+ export type RebaseContext<USER extends User = User, AuthControllerType extends AuthController<USER> = AuthController<USER>> = RebaseCallContext<USER> & {
33
+ authController: AuthControllerType;
34
+ /**
35
+ * Controller mapping strings to collections
36
+ */
37
+ collectionRegistryController?: import("./controllers/collection_registry").CollectionRegistryController;
38
+ /**
39
+ * Controller for navigation state
40
+ */
41
+ navigationStateController?: import("./controllers/navigation").NavigationStateController;
42
+ /**
43
+ * Controller for side dialogs (side sheets)
44
+ */
45
+ sideDialogsController?: import("./controllers/side_dialogs_controller").SideDialogsController;
46
+ /**
47
+ * Controller to open the side dialog displaying entity forms
48
+ */
49
+ sideEntityController?: import("./controllers/side_entity_controller").SideEntityController;
50
+ /**
51
+ * Controller resolving URLs in the CMS
52
+ */
53
+ urlController?: import("./controllers/navigation").UrlController;
54
+ /**
55
+ * Controller to handle simple confirmation and alert dialogs
56
+ */
57
+ dialogsController?: import("./controllers/dialogs_controller").DialogsController;
58
+ /**
59
+ * Controller for CMS customization
60
+ */
61
+ customizationController?: import("./controllers/customization_controller").CustomizationController;
62
+ /**
63
+ * Controller for effective role
64
+ */
65
+ effectiveRoleController?: {
66
+ effectiveRole: string | null;
67
+ setEffectiveRole: (role: string | null) => void;
68
+ };
69
+ /**
70
+ * Use this controller to access data stored in the browser for the user
71
+ */
72
+ userConfigPersistence?: UserConfigurationPersistence;
73
+ /**
74
+ * Callback to send analytics events
75
+ */
76
+ analyticsController?: AnalyticsController;
77
+ /**
78
+ * This section is used to manage users in the CMS.
79
+ * It is used to show user information in various places of the CMS,
80
+ * for example, to show who created or modified an entity,
81
+ * or to assign ownership of an entity.
82
+ *
83
+ * In the base CMS, this information is not used for access control.
84
+ * You can pass your own implementation of this section, to populate
85
+ * the dropdown of users when assigning ownership of an entity,
86
+ * or to show more information about the user.
87
+ *
88
+ * If you are using the Rebase user management plugin, this
89
+ * section will be implemented automatically.
90
+ */
91
+ userManagement?: UserManagementDelegate<USER>;
92
+ /**
93
+ * Administrative database operations (SQL, schema discovery).
94
+ * Only available in developer/admin contexts.
95
+ */
96
+ databaseAdmin?: DatabaseAdmin;
97
+ /**
98
+ * Controller for snackbars
99
+ */
100
+ snackbarController?: import("./controllers/snackbar").SnackbarController;
101
+ };
@@ -0,0 +1,533 @@
1
+ import { Entity, EntityCollection, FilterValues, WhereFilterOp } from "./index";
2
+ /**
3
+ * Abstract database connection interface.
4
+ * Represents a connection to any database system.
5
+ */
6
+ export interface DatabaseConnection {
7
+ /**
8
+ * Type identifier for this database (e.g., 'postgres', 'mongodb', 'mysql')
9
+ */
10
+ readonly type: string;
11
+ /**
12
+ * Whether the connection is currently active
13
+ */
14
+ readonly isConnected?: boolean;
15
+ /**
16
+ * Close the database connection and release resources.
17
+ */
18
+ close?(): Promise<void>;
19
+ }
20
+ /**
21
+ * A single filter condition for database queries
22
+ */
23
+ export interface QueryFilter {
24
+ field: string;
25
+ operator: WhereFilterOp;
26
+ value: unknown;
27
+ }
28
+ /**
29
+ * Options for fetching a collection of entities
30
+ */
31
+ export interface FetchCollectionOptions<M extends Record<string, unknown> = Record<string, unknown>> {
32
+ filter?: FilterValues<Extract<keyof M, string>>;
33
+ orderBy?: string;
34
+ order?: "desc" | "asc";
35
+ limit?: number;
36
+ startAfter?: unknown;
37
+ searchString?: string;
38
+ databaseId?: string;
39
+ collection?: EntityCollection;
40
+ }
41
+ /**
42
+ * Options for searching entities
43
+ */
44
+ export interface SearchOptions<M extends Record<string, unknown> = Record<string, unknown>> {
45
+ filter?: FilterValues<Extract<keyof M, string>>;
46
+ orderBy?: string;
47
+ order?: "desc" | "asc";
48
+ limit?: number;
49
+ databaseId?: string;
50
+ collection?: EntityCollection;
51
+ }
52
+ /**
53
+ * Options for counting entities
54
+ */
55
+ export interface CountOptions<M extends Record<string, unknown> = Record<string, unknown>> {
56
+ filter?: FilterValues<Extract<keyof M, string>>;
57
+ databaseId?: string;
58
+ }
59
+ /**
60
+ * Abstract condition builder interface.
61
+ * Implementations translate Rebase filter conditions to database-specific queries.
62
+ *
63
+ * Note: This interface can be implemented as instance methods or as a class with static methods.
64
+ * For static implementations (like DrizzleConditionBuilder), use the ConditionBuilderStatic type.
65
+ *
66
+ * @template T The type of condition returned by the builder (e.g., SQL for PostgreSQL, Filter<Document> for MongoDB)
67
+ */
68
+ export interface ConditionBuilder<T = unknown> {
69
+ /**
70
+ * Build filter conditions from Rebase FilterValues
71
+ */
72
+ buildFilterConditions<M extends Record<string, unknown>>(filter: FilterValues<Extract<keyof M, string>>, collectionPath: string, ...args: unknown[]): T[];
73
+ /**
74
+ * Build search conditions for text search
75
+ */
76
+ buildSearchConditions(searchString: string, properties: Record<string, unknown>, ...args: unknown[]): T[];
77
+ /**
78
+ * Combine multiple conditions with AND operator
79
+ */
80
+ combineConditionsWithAnd(conditions: T[]): T | undefined;
81
+ /**
82
+ * Combine multiple conditions with OR operator
83
+ */
84
+ combineConditionsWithOr(conditions: T[]): T | undefined;
85
+ }
86
+ /**
87
+ * Static condition builder type for implementations using static methods.
88
+ * Use this type when the class provides static methods rather than instance methods.
89
+ *
90
+ * @example
91
+ * // DrizzleConditionBuilder satisfies this type
92
+ * const builder: ConditionBuilderStatic<SQL> = DrizzleConditionBuilder;
93
+ */
94
+ export type ConditionBuilderStatic<T = unknown> = {
95
+ buildFilterConditions<M extends Record<string, unknown>>(filter: FilterValues<Extract<keyof M, string>>, ...args: unknown[]): T[];
96
+ buildSearchConditions(searchString: string, properties: Record<string, unknown>, ...args: unknown[]): T[];
97
+ combineConditionsWithAnd(conditions: T[]): T | undefined;
98
+ combineConditionsWithOr(conditions: T[]): T | undefined;
99
+ };
100
+ /**
101
+ * Abstract entity repository interface.
102
+ * Handles all CRUD operations for entities in the database.
103
+ *
104
+ * Implementations should handle:
105
+ * - Entity serialization/deserialization
106
+ * - Relation resolution
107
+ * - ID generation and conversion
108
+ */
109
+ export interface EntityRepository {
110
+ /**
111
+ * Fetch a single entity by ID
112
+ */
113
+ fetchEntity<M extends Record<string, unknown>>(collectionPath: string, entityId: string | number, databaseId?: string): Promise<Entity<M> | undefined>;
114
+ /**
115
+ * Fetch a collection of entities with optional filtering, ordering, and pagination
116
+ */
117
+ fetchCollection<M extends Record<string, unknown>>(collectionPath: string, options?: FetchCollectionOptions<M>): Promise<Entity<M>[]>;
118
+ /**
119
+ * Search entities by text
120
+ */
121
+ searchEntities<M extends Record<string, unknown>>(collectionPath: string, searchString: string, options?: SearchOptions<M>): Promise<Entity<M>[]>;
122
+ /**
123
+ * Count entities in a collection
124
+ */
125
+ countEntities<M extends Record<string, unknown>>(collectionPath: string, options?: CountOptions<M>): Promise<number>;
126
+ /**
127
+ * Save an entity (create or update)
128
+ */
129
+ saveEntity<M extends Record<string, unknown>>(collectionPath: string, values: Partial<M>, entityId?: string | number, databaseId?: string): Promise<Entity<M>>;
130
+ /**
131
+ * Delete an entity by ID
132
+ */
133
+ deleteEntity(collectionPath: string, entityId: string | number, databaseId?: string): Promise<void>;
134
+ /**
135
+ * Check if a field value is unique in a collection
136
+ */
137
+ checkUniqueField(collectionPath: string, fieldName: string, value: unknown, excludeEntityId?: string, databaseId?: string): Promise<boolean>;
138
+ }
139
+ /**
140
+ * Configuration for subscribing to a collection
141
+ */
142
+ export interface CollectionSubscriptionConfig {
143
+ clientId: string;
144
+ path: string;
145
+ filter?: unknown;
146
+ orderBy?: string;
147
+ order?: "desc" | "asc";
148
+ limit?: number;
149
+ startAfter?: unknown;
150
+ databaseId?: string;
151
+ searchString?: string;
152
+ }
153
+ /**
154
+ * Configuration for subscribing to a single entity
155
+ */
156
+ export interface EntitySubscriptionConfig {
157
+ clientId: string;
158
+ path: string;
159
+ entityId: string | number;
160
+ }
161
+ /**
162
+ * Abstract realtime provider interface.
163
+ * Handles real-time subscriptions and notifications for entity changes.
164
+ */
165
+ export interface RealtimeProvider {
166
+ /**
167
+ * Subscribe to collection changes
168
+ */
169
+ subscribeToCollection(subscriptionId: string, config: CollectionSubscriptionConfig, callback?: (entities: Entity[]) => void): void;
170
+ /**
171
+ * Subscribe to single entity changes
172
+ */
173
+ subscribeToEntity(subscriptionId: string, config: EntitySubscriptionConfig, callback?: (entity: Entity | null) => void): void;
174
+ /**
175
+ * Unsubscribe from a subscription
176
+ */
177
+ unsubscribe(subscriptionId: string): void;
178
+ /**
179
+ * Notify all relevant subscribers of an entity update
180
+ */
181
+ notifyEntityUpdate(path: string, entityId: string, entity: Entity | null, databaseId?: string): Promise<void>;
182
+ }
183
+ /**
184
+ * Abstract collection registry interface.
185
+ * Manages registration and lookup of entity collections.
186
+ */
187
+ export interface CollectionRegistryInterface {
188
+ /**
189
+ * Register a collection
190
+ */
191
+ register(collection: EntityCollection): void;
192
+ /**
193
+ * Get a collection by its path
194
+ */
195
+ getCollectionByPath(path: string): EntityCollection | undefined;
196
+ /**
197
+ * Get all registered collections
198
+ */
199
+ getCollections(): EntityCollection[];
200
+ }
201
+ /**
202
+ * Abstract data transformer interface.
203
+ * Handles serialization/deserialization between frontend and database formats.
204
+ */
205
+ export interface DataTransformer {
206
+ /**
207
+ * Transform entity data for storage in the database
208
+ */
209
+ serializeToDatabase<M extends Record<string, unknown>>(entity: M, collection: EntityCollection): Record<string, unknown>;
210
+ /**
211
+ * Transform database data back to entity format
212
+ */
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>;
376
+ }
377
+ /**
378
+ * Configuration for creating a database backend
379
+ */
380
+ export interface BackendConfig {
381
+ /**
382
+ * Type of database backend
383
+ */
384
+ type: string;
385
+ /**
386
+ * Database connection (implementation-specific)
387
+ */
388
+ connection: unknown;
389
+ /**
390
+ * Schema definition (implementation-specific, e.g., Drizzle schema for PostgreSQL)
391
+ */
392
+ schema?: unknown;
393
+ }
394
+ /**
395
+ * A complete backend instance with all required services.
396
+ *
397
+ * Now includes optional lifecycle management and admin capabilities.
398
+ */
399
+ export interface BackendInstance extends BackendLifecycle {
400
+ /**
401
+ * Entity repository for CRUD operations
402
+ */
403
+ entityRepository: EntityRepository;
404
+ /**
405
+ * Realtime provider for subscriptions
406
+ */
407
+ realtimeProvider: RealtimeProvider;
408
+ /**
409
+ * Collection registry
410
+ */
411
+ collectionRegistry: CollectionRegistryInterface;
412
+ /**
413
+ * The underlying database connection
414
+ */
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;
422
+ }
423
+ /**
424
+ * Factory function type for creating backend instances
425
+ */
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[]>;
@@ -0,0 +1,5 @@
1
+ export type ColorScheme = {
2
+ color: string;
3
+ text: string;
4
+ };
5
+ export type ColorKey = "blueLighter" | "cyanLighter" | "tealLighter" | "greenLighter" | "yellowLighter" | "orangeLighter" | "redLighter" | "pinkLighter" | "purpleLighter" | "grayLighter" | "blueLight" | "cyanLight" | "tealLight" | "greenLight" | "yellowLight" | "orangeLight" | "redLight" | "pinkLight" | "purpleLight" | "grayLight" | "blueDark" | "cyanDark" | "tealDark" | "greenDark" | "yellowDark" | "orangeDark" | "redDark" | "pinkDark" | "purpleDark" | "grayDark" | "blueDarker" | "cyanDarker" | "tealDarker" | "greenDarker" | "yellowDarker" | "orangeDarker" | "redDarker" | "pinkDarker" | "purpleDarker" | "grayDarker";