@rebasepro/types 0.1.2 → 0.2.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.
- package/LICENSE +1 -1
- package/dist/controllers/auth.d.ts +9 -8
- package/dist/controllers/client.d.ts +3 -0
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/auth_adapter.d.ts +356 -0
- package/dist/types/collections.d.ts +67 -2
- package/dist/types/database_adapter.d.ts +94 -0
- package/dist/types/entity_actions.d.ts +7 -1
- package/dist/types/entity_callbacks.d.ts +1 -1
- package/dist/types/entity_views.d.ts +36 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/properties.d.ts +24 -5
- package/dist/types/property_config.d.ts +6 -2
- package/dist/types/relations.d.ts +1 -1
- package/dist/types/translations.d.ts +8 -0
- package/dist/users/user.d.ts +5 -0
- package/package.json +13 -10
- package/src/controllers/analytics_controller.d.ts +7 -0
- package/src/controllers/auth.d.ts +125 -0
- package/src/controllers/auth.tsx +2 -5
- package/src/controllers/client.d.ts +183 -0
- package/src/controllers/client.ts +3 -2
- package/src/controllers/collection_registry.d.ts +46 -0
- package/src/controllers/customization_controller.d.ts +60 -0
- package/src/controllers/data.d.ts +168 -0
- package/src/controllers/data_driver.d.ts +195 -0
- package/src/controllers/database_admin.d.ts +11 -0
- package/src/controllers/dialogs_controller.d.ts +36 -0
- package/src/controllers/effective_role.d.ts +4 -0
- package/src/controllers/email.d.ts +34 -0
- package/src/controllers/index.d.ts +18 -0
- package/src/controllers/local_config_persistence.d.ts +20 -0
- package/src/controllers/navigation.d.ts +225 -0
- package/src/controllers/registry.d.ts +62 -0
- package/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/src/controllers/side_entity_controller.d.ts +97 -0
- package/src/controllers/snackbar.d.ts +24 -0
- package/src/controllers/storage.d.ts +171 -0
- package/src/index.d.ts +4 -0
- package/src/rebase_context.d.ts +122 -0
- package/src/types/auth_adapter.d.ts +354 -0
- package/src/types/auth_adapter.ts +410 -0
- package/src/types/backend.d.ts +536 -0
- package/src/types/backend_hooks.d.ts +187 -0
- package/src/types/builders.d.ts +15 -0
- package/src/types/chips.d.ts +5 -0
- package/src/types/collections.d.ts +920 -0
- package/src/types/collections.ts +77 -2
- package/src/types/component_ref.d.ts +47 -0
- package/src/types/cron.d.ts +102 -0
- package/src/types/data_source.d.ts +64 -0
- package/src/types/database_adapter.d.ts +90 -0
- package/src/types/database_adapter.ts +120 -0
- package/src/types/entities.d.ts +145 -0
- package/src/types/entity_actions.d.ts +98 -0
- package/src/types/entity_actions.tsx +8 -1
- package/src/types/entity_callbacks.d.ts +173 -0
- package/src/types/entity_callbacks.ts +1 -1
- package/src/types/entity_link_builder.d.ts +7 -0
- package/src/types/entity_overrides.d.ts +10 -0
- package/src/types/entity_views.d.ts +60 -0
- package/src/types/entity_views.tsx +39 -1
- package/src/types/export_import.d.ts +21 -0
- package/src/types/formex.d.ts +40 -0
- package/src/types/index.d.ts +28 -0
- package/src/types/index.ts +2 -0
- package/src/types/locales.d.ts +4 -0
- package/src/types/modify_collections.d.ts +5 -0
- package/src/types/plugins.d.ts +282 -0
- package/src/types/plugins.tsx +1 -1
- package/src/types/properties.d.ts +1160 -0
- package/src/types/properties.ts +34 -4
- package/src/types/property_config.d.ts +70 -0
- package/src/types/property_config.tsx +6 -3
- package/src/types/relations.d.ts +336 -0
- package/src/types/relations.ts +1 -1
- package/src/types/slots.d.ts +262 -0
- package/src/types/translations.d.ts +882 -0
- package/src/types/translations.ts +11 -0
- package/src/types/user_management_delegate.d.ts +121 -0
- package/src/types/websockets.d.ts +78 -0
- package/src/users/index.d.ts +2 -0
- package/src/users/roles.d.ts +22 -0
- package/src/users/user.d.ts +46 -0
- package/src/users/user.ts +6 -0
package/src/types/collections.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { EntityOverrides } from "./entity_overrides";
|
|
|
8
8
|
import type { User } from "../users";
|
|
9
9
|
import type { RebaseContext } from "../rebase_context";
|
|
10
10
|
import type { Relation } from "./relations";
|
|
11
|
-
import type { EntityCustomView } from "./entity_views";
|
|
11
|
+
import type { EntityCustomView, EntityDetailViewConfig } from "./entity_views";
|
|
12
12
|
import type { EntityAction } from "./entity_actions";
|
|
13
13
|
import type { ComponentRef } from "./component_ref";
|
|
14
14
|
|
|
@@ -134,7 +134,26 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
|
|
|
134
134
|
* When editing an entity, you can choose to open the entity in a side dialog
|
|
135
135
|
* or in a full screen dialog. Defaults to `full_screen`.
|
|
136
136
|
*/
|
|
137
|
-
openEntityMode?: "side_panel" | "full_screen" | "split";
|
|
137
|
+
openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Controls what happens when a user clicks on an entity in the collection view.
|
|
141
|
+
* - `"edit"` (default): Opens the entity in the edit form.
|
|
142
|
+
* - `"view"`: Opens a read-only detail view with an "Edit" button.
|
|
143
|
+
*/
|
|
144
|
+
defaultEntityAction?: "view" | "edit";
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Customization options for the read-only detail view.
|
|
148
|
+
* Only used when `defaultEntityAction` is `"view"`.
|
|
149
|
+
*/
|
|
150
|
+
detailView?: EntityDetailViewConfig;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Prevent default actions from being displayed or executed on this collection.
|
|
154
|
+
*/
|
|
155
|
+
disableDefaultActions?: ("edit" | "copy" | "delete")[];
|
|
156
|
+
|
|
138
157
|
|
|
139
158
|
|
|
140
159
|
/**
|
|
@@ -200,6 +219,25 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
|
|
|
200
219
|
*/
|
|
201
220
|
readonly defaultFilter?: FilterValues<Extract<keyof M, string> | (string & {})>; // setting FilterValues<M> can break defining collections by code
|
|
202
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Pre-defined filter presets that appear as quick-access options in the
|
|
224
|
+
* collection toolbar. Each preset applies a set of filters (and
|
|
225
|
+
* optionally a sort order) with a single click.
|
|
226
|
+
*
|
|
227
|
+
* ```ts
|
|
228
|
+
* filterPresets: [
|
|
229
|
+
* {
|
|
230
|
+
* label: "Shipped this month",
|
|
231
|
+
* filterValues: {
|
|
232
|
+
* status: ["==", "shipped"],
|
|
233
|
+
* order_date: [">=", new Date(Date.now() - 30 * 86400000)]
|
|
234
|
+
* }
|
|
235
|
+
* }
|
|
236
|
+
* ]
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
readonly filterPresets?: FilterPreset<Extract<keyof M, string> | (string & {})>[];
|
|
240
|
+
|
|
203
241
|
/**
|
|
204
242
|
* Default sort applied to this collection.
|
|
205
243
|
* When setting this prop, entities will have a default order
|
|
@@ -386,6 +424,13 @@ export interface PostgresCollection<M extends Record<string, unknown> = Record<s
|
|
|
386
424
|
*/
|
|
387
425
|
table: string;
|
|
388
426
|
|
|
427
|
+
/**
|
|
428
|
+
* The PostgreSQL schema name for this table.
|
|
429
|
+
* E.g. "public", "rebase", "auth".
|
|
430
|
+
* If not specified, "public" is used (or the default search path).
|
|
431
|
+
*/
|
|
432
|
+
schema?: string;
|
|
433
|
+
|
|
389
434
|
/**
|
|
390
435
|
* For SQL databases, you can define the relations between collections here.
|
|
391
436
|
* Relations describe JOINs, foreign keys, and junction tables.
|
|
@@ -646,6 +691,36 @@ export type WhereFilterOp =
|
|
|
646
691
|
export type FilterValues<Key extends string> =
|
|
647
692
|
Partial<Record<Key, [WhereFilterOp, unknown]>>;
|
|
648
693
|
|
|
694
|
+
/**
|
|
695
|
+
* A pre-defined filter preset for quick access in the collection toolbar.
|
|
696
|
+
* Users can select a preset to instantly apply a set of filters and
|
|
697
|
+
* optionally a sort order.
|
|
698
|
+
*
|
|
699
|
+
* @group Models
|
|
700
|
+
*/
|
|
701
|
+
export interface FilterPreset<Key extends string = string> {
|
|
702
|
+
/**
|
|
703
|
+
* Display label shown in the preset menu.
|
|
704
|
+
* If omitted, a summary is auto-generated from the filter keys.
|
|
705
|
+
*/
|
|
706
|
+
label?: string;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* The filter values to apply when this preset is selected.
|
|
710
|
+
*/
|
|
711
|
+
filterValues: FilterValues<Key>;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Optional sort override to apply alongside the filter values.
|
|
715
|
+
*/
|
|
716
|
+
sort?: [Key, "asc" | "desc"];
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* @deprecated Use {@link FilterPreset} instead.
|
|
721
|
+
*/
|
|
722
|
+
export type QuickFilter<Key extends string = string> = FilterPreset<Key>;
|
|
723
|
+
|
|
649
724
|
/**
|
|
650
725
|
* Used to indicate valid filter combinations (e.g. created in Firestore)
|
|
651
726
|
* If the user selects a specific filter/sort combination, the CMS checks if it's
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Internal marker for a lazily-loaded component reference.
|
|
4
|
+
* Created by the Vite transform plugin when converting string paths
|
|
5
|
+
* to deferred `import()` calls. Users should NOT create these manually.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface LazyComponentRef<P = unknown> {
|
|
10
|
+
readonly __rebaseLazy: true;
|
|
11
|
+
readonly load: () => Promise<{
|
|
12
|
+
default: React.ComponentType<P>;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A reference to a React component that can be provided in three forms:
|
|
17
|
+
*
|
|
18
|
+
* 1. **String path** (recommended for collection configs):
|
|
19
|
+
* ```ts
|
|
20
|
+
* Field: "../../frontend/src/components/MyField"
|
|
21
|
+
* ```
|
|
22
|
+
* The Vite plugin transforms this into a `LazyComponentRef` at build time.
|
|
23
|
+
* On the backend, the string stays inert and is never evaluated.
|
|
24
|
+
*
|
|
25
|
+
* 2. **Lazy import function**:
|
|
26
|
+
* ```ts
|
|
27
|
+
* Field: () => import("../../frontend/src/components/MyField")
|
|
28
|
+
* ```
|
|
29
|
+
* Standard ES dynamic import. Backend never calls the function.
|
|
30
|
+
*
|
|
31
|
+
* 3. **Direct component reference** (use only in frontend-only code):
|
|
32
|
+
* ```ts
|
|
33
|
+
* Field: MyFieldComponent
|
|
34
|
+
* ```
|
|
35
|
+
* Importing a component at the top level will pull React into the
|
|
36
|
+
* backend runtime — only safe in code that the backend never imports.
|
|
37
|
+
*
|
|
38
|
+
* @group Types
|
|
39
|
+
*/
|
|
40
|
+
export type ComponentRef<P = unknown> = React.ComponentType<P> | LazyComponentRef<P> | (() => Promise<{
|
|
41
|
+
default: React.ComponentType<P>;
|
|
42
|
+
}>) | string;
|
|
43
|
+
/**
|
|
44
|
+
* Type guard: checks if a value is a `LazyComponentRef` produced by the
|
|
45
|
+
* Vite transform plugin.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isLazyComponentRef<P = unknown>(ref: unknown): ref is LazyComponentRef<P>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { RebaseClient } from "../controllers/client";
|
|
2
|
+
/**
|
|
3
|
+
* Cron Job type definitions for Rebase.
|
|
4
|
+
*
|
|
5
|
+
* These types define the shape of cron job definitions, their runtime
|
|
6
|
+
* status, and execution log entries — used across server-core, client,
|
|
7
|
+
* and studio packages.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A cron job definition file exports this shape as its default export.
|
|
11
|
+
* See the example cron files in `app/backend/crons/` for usage.
|
|
12
|
+
*/
|
|
13
|
+
export interface CronJobDefinition {
|
|
14
|
+
schedule: string;
|
|
15
|
+
/** Human-readable name shown in the Studio UI. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Optional description shown in the Studio UI. */
|
|
18
|
+
description?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the job is enabled at startup. Defaults to `true`.
|
|
21
|
+
* Can be toggled at runtime via the Admin API.
|
|
22
|
+
*/
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum number of seconds the handler may run before being
|
|
26
|
+
* considered timed-out. Default: 300 (5 min).
|
|
27
|
+
*/
|
|
28
|
+
timeoutSeconds?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The handler function executed on each tick.
|
|
31
|
+
* Receives a context object with the data driver and logger.
|
|
32
|
+
* May return arbitrary JSON-serialisable data stored in the log.
|
|
33
|
+
*/
|
|
34
|
+
handler: (ctx: CronJobContext) => Promise<unknown> | unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Context passed to each cron handler invocation.
|
|
38
|
+
*/
|
|
39
|
+
export interface CronJobContext {
|
|
40
|
+
/** The job's unique ID (derived from filename). */
|
|
41
|
+
jobId: string;
|
|
42
|
+
/** The current scheduled tick timestamp. */
|
|
43
|
+
scheduledAt: Date;
|
|
44
|
+
/** A simple logger scoped to this job run. */
|
|
45
|
+
log: (...args: unknown[]) => void;
|
|
46
|
+
/** The RebaseClient instance to interact with the database. */
|
|
47
|
+
client: RebaseClient<any>;
|
|
48
|
+
}
|
|
49
|
+
export type CronJobRunState = "idle" | "running" | "success" | "error" | "disabled";
|
|
50
|
+
/**
|
|
51
|
+
* Full runtime information about a registered cron job.
|
|
52
|
+
*/
|
|
53
|
+
export interface CronJobStatus {
|
|
54
|
+
/** Unique identifier (derived from filename, e.g. "cleanup-sessions"). */
|
|
55
|
+
id: string;
|
|
56
|
+
/** Human-readable name from the definition. */
|
|
57
|
+
name: string;
|
|
58
|
+
/** Description from the definition. */
|
|
59
|
+
description?: string;
|
|
60
|
+
/** The cron schedule expression. */
|
|
61
|
+
schedule: string;
|
|
62
|
+
/** Whether the job is currently enabled. */
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
/** Current run state. */
|
|
65
|
+
state: CronJobRunState;
|
|
66
|
+
/** ISO timestamp of the last execution start. */
|
|
67
|
+
lastRunAt?: string;
|
|
68
|
+
/** ISO timestamp of the next scheduled execution. */
|
|
69
|
+
nextRunAt?: string;
|
|
70
|
+
/** Duration of the last run in milliseconds. */
|
|
71
|
+
lastDurationMs?: number;
|
|
72
|
+
/** Error message from the last failed run. */
|
|
73
|
+
lastError?: string;
|
|
74
|
+
/** Total number of executions since server start. */
|
|
75
|
+
totalRuns: number;
|
|
76
|
+
/** Total number of failed executions since server start. */
|
|
77
|
+
totalFailures: number;
|
|
78
|
+
}
|
|
79
|
+
export type CronLogLevel = "info" | "error" | "warn";
|
|
80
|
+
/**
|
|
81
|
+
* A single execution log entry stored in the in-memory ring buffer.
|
|
82
|
+
*/
|
|
83
|
+
export interface CronJobLogEntry {
|
|
84
|
+
/** The job ID this log belongs to. */
|
|
85
|
+
jobId: string;
|
|
86
|
+
/** ISO timestamp when execution started. */
|
|
87
|
+
startedAt: string;
|
|
88
|
+
/** ISO timestamp when execution finished. */
|
|
89
|
+
finishedAt: string;
|
|
90
|
+
/** Duration in milliseconds. */
|
|
91
|
+
durationMs: number;
|
|
92
|
+
/** Whether this run succeeded. */
|
|
93
|
+
success: boolean;
|
|
94
|
+
/** Error message if the run failed. */
|
|
95
|
+
error?: string;
|
|
96
|
+
/** Arbitrary result data returned by the handler. */
|
|
97
|
+
result?: unknown;
|
|
98
|
+
/** Captured log lines. */
|
|
99
|
+
logs: string[];
|
|
100
|
+
/** Whether this was a manual trigger. */
|
|
101
|
+
manual?: boolean;
|
|
102
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes the capabilities and features supported by a data source (driver).
|
|
3
|
+
*
|
|
4
|
+
* Each driver (Postgres, Firebase, MongoDB, etc.) declares which features it
|
|
5
|
+
* supports. The CMS uses this descriptor to:
|
|
6
|
+
* - Show/hide editor tabs (e.g. Relations for SQL, Subcollections for Firebase)
|
|
7
|
+
* - Filter the property type picker (e.g. `relation` for SQL, `reference` for Firebase)
|
|
8
|
+
* - Toggle driver-specific form controls (e.g. `columnType` for SQL)
|
|
9
|
+
*
|
|
10
|
+
* @group Models
|
|
11
|
+
*/
|
|
12
|
+
export interface DataSourceCapabilities {
|
|
13
|
+
/** Unique driver key (e.g. "postgres", "firestore", "mongodb") */
|
|
14
|
+
key: string;
|
|
15
|
+
/** Human-readable label for the UI (e.g. "PostgreSQL", "Firebase / Firestore") */
|
|
16
|
+
label: string;
|
|
17
|
+
/** Does this source support SQL-style relations (JOINs)? */
|
|
18
|
+
supportsRelations: boolean;
|
|
19
|
+
/** Does this source support nested subcollections? */
|
|
20
|
+
supportsSubcollections: boolean;
|
|
21
|
+
/** Does this source support Row Level Security policies? */
|
|
22
|
+
supportsRLS: boolean;
|
|
23
|
+
/** Does this source support document references (Firebase-style)? */
|
|
24
|
+
supportsReferences: boolean;
|
|
25
|
+
/** Does this source support SQL column type annotations? */
|
|
26
|
+
supportsColumnTypes: boolean;
|
|
27
|
+
/** Does this source support real-time listeners? */
|
|
28
|
+
supportsRealtime: boolean;
|
|
29
|
+
/** Does this source support SQL admin operations (SQL editor, EXPLAIN, etc.)? */
|
|
30
|
+
supportsSQLAdmin: boolean;
|
|
31
|
+
/** Does this source support document admin operations (aggregation, stats)? */
|
|
32
|
+
supportsDocumentAdmin: boolean;
|
|
33
|
+
/** Does this source support schema admin (unmapped tables, table metadata)? */
|
|
34
|
+
supportsSchemaAdmin: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Subset of DataSourceCapabilities containing only feature flags.
|
|
38
|
+
* Useful when you only need to check capabilities without UI metadata.
|
|
39
|
+
* @group Models
|
|
40
|
+
*/
|
|
41
|
+
export type DataSourceFeatures = Omit<DataSourceCapabilities, "key" | "label">;
|
|
42
|
+
/** @group Models */
|
|
43
|
+
export declare const POSTGRES_CAPABILITIES: DataSourceCapabilities;
|
|
44
|
+
/** @group Models */
|
|
45
|
+
export declare const FIREBASE_CAPABILITIES: DataSourceCapabilities;
|
|
46
|
+
/** @group Models */
|
|
47
|
+
export declare const MONGODB_CAPABILITIES: DataSourceCapabilities;
|
|
48
|
+
/**
|
|
49
|
+
* Fallback capabilities when the driver is unknown.
|
|
50
|
+
* Enables everything so nothing is hidden unexpectedly.
|
|
51
|
+
* @group Models
|
|
52
|
+
*/
|
|
53
|
+
export declare const DEFAULT_CAPABILITIES: DataSourceCapabilities;
|
|
54
|
+
/**
|
|
55
|
+
* Look up capabilities for a given driver key.
|
|
56
|
+
* If `driver` is undefined or not found, returns `DEFAULT_CAPABILITIES`.
|
|
57
|
+
* @group Models
|
|
58
|
+
*/
|
|
59
|
+
export declare function getDataSourceCapabilities(driver?: string): DataSourceCapabilities;
|
|
60
|
+
/**
|
|
61
|
+
* Register custom capabilities for a third-party driver.
|
|
62
|
+
* @group Models
|
|
63
|
+
*/
|
|
64
|
+
export declare function registerDataSourceCapabilities(capabilities: DataSourceCapabilities): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
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-postgresql";
|
|
13
|
+
*
|
|
14
|
+
* initializeRebaseBackend({
|
|
15
|
+
* database: createPostgresAdapter({ connection: db, schema }),
|
|
16
|
+
* auth: { jwtSecret: "..." },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @group Backend
|
|
21
|
+
*/
|
|
22
|
+
import type { DataDriver } from "../controllers/data_driver";
|
|
23
|
+
import type { EntityCollection } from "./collections";
|
|
24
|
+
import type { CollectionRegistryInterface, DatabaseAdmin, InitializedDriver, RealtimeProvider } from "./backend";
|
|
25
|
+
/**
|
|
26
|
+
* A `DatabaseAdapter` provides data persistence for Rebase.
|
|
27
|
+
*
|
|
28
|
+
* @group Backend
|
|
29
|
+
*/
|
|
30
|
+
export interface DatabaseAdapter {
|
|
31
|
+
/**
|
|
32
|
+
* Which database engine this adapter handles.
|
|
33
|
+
*
|
|
34
|
+
* @example "postgres", "mysql", "mongodb", "sqlite"
|
|
35
|
+
*/
|
|
36
|
+
readonly type: string;
|
|
37
|
+
/**
|
|
38
|
+
* Create the DataDriver for CRUD operations.
|
|
39
|
+
*
|
|
40
|
+
* This is the only **required** method.
|
|
41
|
+
*
|
|
42
|
+
* @param config - Coordinator-provided config containing registered
|
|
43
|
+
* collections and the collection registry.
|
|
44
|
+
*/
|
|
45
|
+
initializeDriver(config: DatabaseAdapterInitConfig): Promise<InitializedDriver>;
|
|
46
|
+
/**
|
|
47
|
+
* Create a realtime provider for this database.
|
|
48
|
+
*
|
|
49
|
+
* Return `undefined` if the database does not support realtime
|
|
50
|
+
* change notifications.
|
|
51
|
+
*/
|
|
52
|
+
initializeRealtime?(driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Initialize entity history tracking.
|
|
55
|
+
*
|
|
56
|
+
* Return `undefined` if the database does not support history.
|
|
57
|
+
*/
|
|
58
|
+
initializeHistory?(config: unknown, driverResult: InitializedDriver): Promise<{
|
|
59
|
+
historyService: unknown;
|
|
60
|
+
} | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Initialize WebSocket server for realtime operations.
|
|
63
|
+
*/
|
|
64
|
+
initializeWebsockets?(server: unknown, realtimeService: RealtimeProvider, driver: DataDriver, config?: unknown): Promise<void> | void;
|
|
65
|
+
/**
|
|
66
|
+
* Return admin capabilities for this database (SQL editor, schema browser, branching).
|
|
67
|
+
*/
|
|
68
|
+
getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Mount any database-specific HTTP routes (e.g., custom admin endpoints).
|
|
71
|
+
*
|
|
72
|
+
* Called after all adapters are initialized.
|
|
73
|
+
*/
|
|
74
|
+
mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
|
|
75
|
+
/**
|
|
76
|
+
* Graceful shutdown: close connections, release resources.
|
|
77
|
+
*/
|
|
78
|
+
destroy?(): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Configuration passed by the coordinator to `DatabaseAdapter.initializeDriver()`.
|
|
82
|
+
*
|
|
83
|
+
* @group Backend
|
|
84
|
+
*/
|
|
85
|
+
export interface DatabaseAdapterInitConfig {
|
|
86
|
+
/** Registered collection definitions. */
|
|
87
|
+
collections: EntityCollection[];
|
|
88
|
+
/** The shared collection registry to register into. */
|
|
89
|
+
collectionRegistry: CollectionRegistryInterface;
|
|
90
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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-postgresql";
|
|
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 { EntityCollection } from "./collections";
|
|
25
|
+
import type {
|
|
26
|
+
CollectionRegistryInterface,
|
|
27
|
+
DatabaseAdmin,
|
|
28
|
+
InitializedDriver,
|
|
29
|
+
RealtimeProvider,
|
|
30
|
+
BootstrappedAuth,
|
|
31
|
+
} from "./backend";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A `DatabaseAdapter` provides data persistence for Rebase.
|
|
35
|
+
*
|
|
36
|
+
* @group Backend
|
|
37
|
+
*/
|
|
38
|
+
export interface DatabaseAdapter {
|
|
39
|
+
/**
|
|
40
|
+
* Which database engine this adapter handles.
|
|
41
|
+
*
|
|
42
|
+
* @example "postgres", "mysql", "mongodb", "sqlite"
|
|
43
|
+
*/
|
|
44
|
+
readonly type: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create the DataDriver for CRUD operations.
|
|
48
|
+
*
|
|
49
|
+
* This is the only **required** method.
|
|
50
|
+
*
|
|
51
|
+
* @param config - Coordinator-provided config containing registered
|
|
52
|
+
* collections and the collection registry.
|
|
53
|
+
*/
|
|
54
|
+
initializeDriver(config: DatabaseAdapterInitConfig): Promise<InitializedDriver>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a realtime provider for this database.
|
|
58
|
+
*
|
|
59
|
+
* Return `undefined` if the database does not support realtime
|
|
60
|
+
* change notifications.
|
|
61
|
+
*/
|
|
62
|
+
initializeRealtime?(driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Initialize auth tables / services if this driver supports them.
|
|
66
|
+
*/
|
|
67
|
+
initializeAuth?(
|
|
68
|
+
config: unknown,
|
|
69
|
+
driverResult: InitializedDriver,
|
|
70
|
+
): Promise<BootstrappedAuth | undefined>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Initialize entity history tracking.
|
|
74
|
+
*
|
|
75
|
+
* Return `undefined` if the database does not support history.
|
|
76
|
+
*/
|
|
77
|
+
initializeHistory?(
|
|
78
|
+
config: unknown,
|
|
79
|
+
driverResult: InitializedDriver,
|
|
80
|
+
): Promise<{ historyService: unknown } | undefined>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Initialize WebSocket server for realtime operations.
|
|
84
|
+
*/
|
|
85
|
+
initializeWebsockets?(
|
|
86
|
+
server: unknown,
|
|
87
|
+
realtimeService: RealtimeProvider,
|
|
88
|
+
driver: DataDriver,
|
|
89
|
+
config?: unknown,
|
|
90
|
+
): Promise<void> | void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Return admin capabilities for this database (SQL editor, schema browser, branching).
|
|
94
|
+
*/
|
|
95
|
+
getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Mount any database-specific HTTP routes (e.g., custom admin endpoints).
|
|
99
|
+
*
|
|
100
|
+
* Called after all adapters are initialized.
|
|
101
|
+
*/
|
|
102
|
+
mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Graceful shutdown: close connections, release resources.
|
|
106
|
+
*/
|
|
107
|
+
destroy?(): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Configuration passed by the coordinator to `DatabaseAdapter.initializeDriver()`.
|
|
112
|
+
*
|
|
113
|
+
* @group Backend
|
|
114
|
+
*/
|
|
115
|
+
export interface DatabaseAdapterInitConfig {
|
|
116
|
+
/** Registered collection definitions. */
|
|
117
|
+
collections: EntityCollection[];
|
|
118
|
+
/** The shared collection registry to register into. */
|
|
119
|
+
collectionRegistry: CollectionRegistryInterface;
|
|
120
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* New or existing status
|
|
3
|
+
* @group Models
|
|
4
|
+
*/
|
|
5
|
+
export type EntityStatus = "new" | "existing" | "copy";
|
|
6
|
+
/**
|
|
7
|
+
* Representation of an entity fetched from the driver
|
|
8
|
+
* @group Models
|
|
9
|
+
*/
|
|
10
|
+
export interface Entity<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
11
|
+
/**
|
|
12
|
+
* ID of the entity
|
|
13
|
+
*/
|
|
14
|
+
id: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* A string representing the path of the referenced document (relative
|
|
17
|
+
* to the root of the database).
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* Current values
|
|
22
|
+
*/
|
|
23
|
+
values: EntityValues<M>;
|
|
24
|
+
/**
|
|
25
|
+
* Which driver this entity belongs to (e.g., 'postgres', 'firestore').
|
|
26
|
+
* If not specified, the default driver is assumed.
|
|
27
|
+
*/
|
|
28
|
+
driver?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Which database within the driver (e.g., for Firestore multi-database).
|
|
31
|
+
* If not specified, the default database of the driver is used.
|
|
32
|
+
*/
|
|
33
|
+
databaseId?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This type represents a record of key value pairs as described in an
|
|
37
|
+
* entity collection.
|
|
38
|
+
* @group Models
|
|
39
|
+
*/
|
|
40
|
+
export type EntityValues<M extends Record<string, unknown>> = M;
|
|
41
|
+
/**
|
|
42
|
+
* Props for creating an EntityReference
|
|
43
|
+
*/
|
|
44
|
+
export interface EntityReferenceProps {
|
|
45
|
+
/** ID of the entity */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Path of the collection (relative to the root of the database) */
|
|
48
|
+
path: string;
|
|
49
|
+
/** Which driver (e.g., 'postgres', 'firestore'). Defaults to "(default)" */
|
|
50
|
+
driver?: string;
|
|
51
|
+
/** Which database within the driver. Defaults to "(default)" */
|
|
52
|
+
databaseId?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Class used to create a reference to an entity in a different path.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Simple reference (most common case - single driver, single db)
|
|
59
|
+
* new EntityReference({ id: "123", path: "users" })
|
|
60
|
+
*
|
|
61
|
+
* // Reference to a different driver (e.g., Firestore)
|
|
62
|
+
* new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
|
|
63
|
+
*
|
|
64
|
+
* // Reference to a specific database within a driver
|
|
65
|
+
* new EntityReference({ id: "123", path: "orders", driver: "postgres", databaseId: "orders_db" })
|
|
66
|
+
*/
|
|
67
|
+
export declare class EntityReference {
|
|
68
|
+
readonly __type = "reference";
|
|
69
|
+
/**
|
|
70
|
+
* ID of the entity
|
|
71
|
+
*/
|
|
72
|
+
readonly id: string;
|
|
73
|
+
/**
|
|
74
|
+
* A string representing the path of the referenced document (relative
|
|
75
|
+
* to the root of the database).
|
|
76
|
+
*/
|
|
77
|
+
readonly path: string;
|
|
78
|
+
/**
|
|
79
|
+
* Which driver (e.g., 'postgres', 'firestore').
|
|
80
|
+
* Defaults to "(default)" if not specified.
|
|
81
|
+
*/
|
|
82
|
+
readonly driver?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Which database within the driver.
|
|
85
|
+
* Defaults to "(default)" if not specified.
|
|
86
|
+
*/
|
|
87
|
+
readonly databaseId?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Create a reference to an entity.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Simple reference (most common case)
|
|
93
|
+
* new EntityReference({ id: "123", path: "users" })
|
|
94
|
+
*
|
|
95
|
+
* // With driver
|
|
96
|
+
* new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
|
|
97
|
+
*/
|
|
98
|
+
constructor(props: EntityReferenceProps);
|
|
99
|
+
get pathWithId(): string;
|
|
100
|
+
/**
|
|
101
|
+
* Get the full path including driver and database prefixes if specified.
|
|
102
|
+
* For the common case (single driver, single db), this just returns pathWithId.
|
|
103
|
+
*/
|
|
104
|
+
get fullPath(): string;
|
|
105
|
+
isEntityReference(): boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Class used to create a reference to an entity in a different path
|
|
109
|
+
*/
|
|
110
|
+
export declare class EntityRelation {
|
|
111
|
+
readonly __type = "relation";
|
|
112
|
+
/**
|
|
113
|
+
* ID of the entity
|
|
114
|
+
*/
|
|
115
|
+
readonly id: string | number;
|
|
116
|
+
/**
|
|
117
|
+
* A string representing the path of the referenced document (relative
|
|
118
|
+
* to the root of the database).
|
|
119
|
+
*/
|
|
120
|
+
readonly path: string;
|
|
121
|
+
/**
|
|
122
|
+
* Pre-fetched data payload to eliminate N+1 queries.
|
|
123
|
+
* When present, clients can use this directly instead of fetching.
|
|
124
|
+
*/
|
|
125
|
+
readonly data?: Entity;
|
|
126
|
+
constructor(id: string | number, path: string, data?: Entity);
|
|
127
|
+
get pathWithId(): string;
|
|
128
|
+
isEntityReference(): boolean;
|
|
129
|
+
isEntityRelation(): boolean;
|
|
130
|
+
}
|
|
131
|
+
export declare class GeoPoint {
|
|
132
|
+
/**
|
|
133
|
+
* The latitude of this GeoPoint instance.
|
|
134
|
+
*/
|
|
135
|
+
readonly latitude: number;
|
|
136
|
+
/**
|
|
137
|
+
* The longitude of this GeoPoint instance.
|
|
138
|
+
*/
|
|
139
|
+
readonly longitude: number;
|
|
140
|
+
constructor(latitude: number, longitude: number);
|
|
141
|
+
}
|
|
142
|
+
export declare class Vector {
|
|
143
|
+
readonly value: number[];
|
|
144
|
+
constructor(value: number[]);
|
|
145
|
+
}
|