@rebasepro/server-postgresql 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/LICENSE +6 -0
- package/README.md +106 -0
- package/build-errors.txt +37 -0
- package/dist/common/src/collections/CollectionRegistry.d.ts +48 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/buildRebaseData.d.ts +14 -0
- package/dist/common/src/index.d.ts +3 -0
- package/dist/common/src/util/builders.d.ts +57 -0
- package/dist/common/src/util/callbacks.d.ts +6 -0
- package/dist/common/src/util/collections.d.ts +11 -0
- package/dist/common/src/util/common.d.ts +2 -0
- package/dist/common/src/util/conditions.d.ts +26 -0
- package/dist/common/src/util/entities.d.ts +36 -0
- package/dist/common/src/util/enums.d.ts +3 -0
- package/dist/common/src/util/index.d.ts +16 -0
- package/dist/common/src/util/navigation_from_path.d.ts +34 -0
- package/dist/common/src/util/navigation_utils.d.ts +20 -0
- package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
- package/dist/common/src/util/paths.d.ts +14 -0
- package/dist/common/src/util/permissions.d.ts +5 -0
- package/dist/common/src/util/references.d.ts +2 -0
- package/dist/common/src/util/relations.d.ts +12 -0
- package/dist/common/src/util/resolutions.d.ts +72 -0
- package/dist/common/src/util/storage.d.ts +24 -0
- package/dist/index.es.js +10635 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +10643 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +112 -0
- package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +40 -0
- package/dist/server-postgresql/src/auth/ensure-tables.d.ts +6 -0
- package/dist/server-postgresql/src/auth/services.d.ts +188 -0
- package/dist/server-postgresql/src/cli.d.ts +1 -0
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +43 -0
- package/dist/server-postgresql/src/connection.d.ts +7 -0
- package/dist/server-postgresql/src/data-transformer.d.ts +36 -0
- package/dist/server-postgresql/src/databasePoolManager.d.ts +20 -0
- package/dist/server-postgresql/src/history/HistoryService.d.ts +71 -0
- package/dist/server-postgresql/src/history/ensure-history-table.d.ts +7 -0
- package/dist/server-postgresql/src/index.d.ts +13 -0
- package/dist/server-postgresql/src/interfaces.d.ts +18 -0
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +767 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +2 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema.d.ts +1 -0
- package/dist/server-postgresql/src/services/BranchService.d.ts +47 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +195 -0
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +41 -0
- package/dist/server-postgresql/src/services/RelationService.d.ts +92 -0
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +24 -0
- package/dist/server-postgresql/src/services/entityService.d.ts +102 -0
- package/dist/server-postgresql/src/services/index.d.ts +4 -0
- package/dist/server-postgresql/src/services/realtimeService.d.ts +186 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +116 -0
- package/dist/server-postgresql/src/websocket.d.ts +5 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +117 -0
- package/dist/types/src/controllers/client.d.ts +58 -0
- package/dist/types/src/controllers/collection_registry.d.ts +44 -0
- package/dist/types/src/controllers/customization_controller.d.ts +54 -0
- package/dist/types/src/controllers/data.d.ts +141 -0
- package/dist/types/src/controllers/data_driver.d.ts +168 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/index.d.ts +17 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +51 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +89 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +173 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +101 -0
- package/dist/types/src/types/backend.d.ts +533 -0
- package/dist/types/src/types/builders.d.ts +14 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +812 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +9 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +22 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +225 -0
- package/dist/types/src/types/properties.d.ts +1091 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +228 -0
- package/dist/types/src/types/translations.d.ts +826 -0
- package/dist/types/src/types/user_management_delegate.d.ts +120 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/jest-all.log +3128 -0
- package/jest.log +49 -0
- package/package.json +93 -0
- package/src/PostgresBackendDriver.ts +1024 -0
- package/src/PostgresBootstrapper.ts +232 -0
- package/src/auth/ensure-tables.ts +309 -0
- package/src/auth/services.ts +740 -0
- package/src/cli.ts +347 -0
- package/src/collections/PostgresCollectionRegistry.ts +96 -0
- package/src/connection.ts +62 -0
- package/src/data-transformer.ts +569 -0
- package/src/databasePoolManager.ts +84 -0
- package/src/history/HistoryService.ts +257 -0
- package/src/history/ensure-history-table.ts +45 -0
- package/src/index.ts +13 -0
- package/src/interfaces.ts +60 -0
- package/src/schema/auth-schema.ts +146 -0
- package/src/schema/generate-drizzle-schema-logic.ts +618 -0
- package/src/schema/generate-drizzle-schema.ts +151 -0
- package/src/services/BranchService.ts +237 -0
- package/src/services/EntityFetchService.ts +1447 -0
- package/src/services/EntityPersistService.ts +351 -0
- package/src/services/RelationService.ts +1012 -0
- package/src/services/entity-helpers.ts +121 -0
- package/src/services/entityService.ts +209 -0
- package/src/services/index.ts +13 -0
- package/src/services/realtimeService.ts +1005 -0
- package/src/utils/drizzle-conditions.ts +999 -0
- package/src/websocket.ts +487 -0
- package/test/auth-services.test.ts +569 -0
- package/test/branchService.test.ts +357 -0
- package/test/drizzle-conditions.test.ts +895 -0
- package/test/entityService.errors.test.ts +352 -0
- package/test/entityService.relations.test.ts +912 -0
- package/test/entityService.subcollection-search.test.ts +516 -0
- package/test/entityService.test.ts +977 -0
- package/test/generate-drizzle-schema.test.ts +795 -0
- package/test/historyService.test.ts +126 -0
- package/test/postgresDataDriver.test.ts +556 -0
- package/test/realtimeService.test.ts +276 -0
- package/test/relations.test.ts +662 -0
- package/test_drizzle_mock.js +3 -0
- package/test_find_changed.mjs +30 -0
- package/test_output.txt +3145 -0
- package/tsconfig.json +49 -0
- package/tsconfig.prod.json +20 -0
- package/vite.config.ts +82 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { WebSocket } from "ws";
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { Entity, DataDriver, WebSocketMessage } from "@rebasepro/types";
|
|
4
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
|
+
import { RealtimeProvider, CollectionSubscriptionConfig, EntitySubscriptionConfig } from "../interfaces";
|
|
6
|
+
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
|
|
7
|
+
/**
|
|
8
|
+
* Auth context stored per-subscription so real-time refetches respect RLS.
|
|
9
|
+
* Mirrors the session variables set by PostgresBackendDriver.withAuth().
|
|
10
|
+
*/
|
|
11
|
+
export interface SubscriptionAuthContext {
|
|
12
|
+
userId: string;
|
|
13
|
+
roles: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* PostgreSQL-specific realtime service.
|
|
17
|
+
* Handles WebSocket connections and subscriptions for real-time entity updates.
|
|
18
|
+
*
|
|
19
|
+
* Implements the RealtimeProvider interface for database abstraction.
|
|
20
|
+
*/
|
|
21
|
+
export declare class RealtimeService extends EventEmitter implements RealtimeProvider {
|
|
22
|
+
private db;
|
|
23
|
+
private registry;
|
|
24
|
+
private clients;
|
|
25
|
+
private entityService;
|
|
26
|
+
private _subscriptions;
|
|
27
|
+
private subscriptionCallbacks;
|
|
28
|
+
private driver?;
|
|
29
|
+
/** Unique identifier for this process instance, used to skip own notifications. */
|
|
30
|
+
private readonly instanceId;
|
|
31
|
+
/** Dedicated pg.Client for LISTEN (outside the Drizzle pool). */
|
|
32
|
+
private listenClient?;
|
|
33
|
+
/** Connection string used for reconnecting the LISTEN client. */
|
|
34
|
+
private listenConnectionString?;
|
|
35
|
+
/** Whether cross-instance broadcasting is active. */
|
|
36
|
+
private broadcasting;
|
|
37
|
+
/** Reconnection timer handle. */
|
|
38
|
+
private reconnectTimer?;
|
|
39
|
+
/** Debounce timers for collection refetches to prevent refetch storms. */
|
|
40
|
+
private refetchTimers;
|
|
41
|
+
/** Debounce window (ms) for coalescing rapid entity updates into a single correctness refetch. */
|
|
42
|
+
private static readonly REFETCH_DEBOUNCE_MS;
|
|
43
|
+
constructor(db: NodePgDatabase<any>, registry: PostgresCollectionRegistry);
|
|
44
|
+
/** Whether to emit verbose debug logs (disabled in production). */
|
|
45
|
+
private static readonly DEBUG;
|
|
46
|
+
private debugLog;
|
|
47
|
+
setDataDriver(driver: DataDriver): void;
|
|
48
|
+
get subscriptions(): Map<string, {
|
|
49
|
+
clientId: string;
|
|
50
|
+
type: "collection" | "entity";
|
|
51
|
+
path: string;
|
|
52
|
+
entityId?: string | number;
|
|
53
|
+
collectionRequest?: {
|
|
54
|
+
filter?: Record<string, unknown>;
|
|
55
|
+
orderBy?: string;
|
|
56
|
+
order?: "desc" | "asc";
|
|
57
|
+
limit?: number;
|
|
58
|
+
startAfter?: Record<string, unknown>;
|
|
59
|
+
databaseId?: string;
|
|
60
|
+
searchString?: string;
|
|
61
|
+
};
|
|
62
|
+
authContext?: SubscriptionAuthContext;
|
|
63
|
+
}>;
|
|
64
|
+
registerDataDriverSubscription(subscriptionId: string, subscription: {
|
|
65
|
+
clientId: string;
|
|
66
|
+
type: "collection" | "entity";
|
|
67
|
+
path: string;
|
|
68
|
+
entityId?: string | number;
|
|
69
|
+
collectionRequest?: {
|
|
70
|
+
filter?: Record<string, unknown>;
|
|
71
|
+
orderBy?: string;
|
|
72
|
+
order?: "desc" | "asc";
|
|
73
|
+
limit?: number;
|
|
74
|
+
startAfter?: Record<string, unknown>;
|
|
75
|
+
databaseId?: string;
|
|
76
|
+
searchString?: string;
|
|
77
|
+
};
|
|
78
|
+
authContext?: SubscriptionAuthContext;
|
|
79
|
+
}): void;
|
|
80
|
+
addSubscriptionCallback(subscriptionId: string, callback: (data: Entity[] | Entity | null) => void): void;
|
|
81
|
+
removeSubscriptionCallback(subscriptionId: string): void;
|
|
82
|
+
/**
|
|
83
|
+
* Subscribe to collection changes (RealtimeProvider interface)
|
|
84
|
+
*/
|
|
85
|
+
subscribeToCollection(subscriptionId: string, config: CollectionSubscriptionConfig, callback?: (entities: Entity[]) => void): void;
|
|
86
|
+
/**
|
|
87
|
+
* Subscribe to single entity changes (RealtimeProvider interface)
|
|
88
|
+
*/
|
|
89
|
+
subscribeToEntity(subscriptionId: string, config: EntitySubscriptionConfig, callback?: (entity: Entity | null) => void): void;
|
|
90
|
+
/**
|
|
91
|
+
* Unsubscribe from a subscription (RealtimeProvider interface)
|
|
92
|
+
*/
|
|
93
|
+
unsubscribe(subscriptionId: string): void;
|
|
94
|
+
addClient(clientId: string, ws: WebSocket): void;
|
|
95
|
+
handleClientMessage(clientId: string, message: WebSocketMessage, authContext?: SubscriptionAuthContext): Promise<void>;
|
|
96
|
+
removeClient(clientId: string): Promise<void>;
|
|
97
|
+
private handleMessage;
|
|
98
|
+
private handleCollectionSubscription;
|
|
99
|
+
private handleEntitySubscription;
|
|
100
|
+
private handleUnsubscribe;
|
|
101
|
+
/**
|
|
102
|
+
* Enhanced notification method that handles nested relation updates.
|
|
103
|
+
* @param broadcast When true (default), also sends a pg_notify so other instances
|
|
104
|
+
* pick up the change. Set to false when handling an incoming
|
|
105
|
+
* cross-instance notification to avoid infinite loops.
|
|
106
|
+
*/
|
|
107
|
+
notifyEntityUpdate(path: string, entityId: string, entity: Entity | null, databaseId?: string, broadcast?: boolean): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Notify subscriptions for a specific path
|
|
110
|
+
*/
|
|
111
|
+
private notifyPathUpdate;
|
|
112
|
+
/**
|
|
113
|
+
* Debounce a collection refetch for a WebSocket subscription.
|
|
114
|
+
* Coalesces rapid entity mutations into a single database query.
|
|
115
|
+
*/
|
|
116
|
+
private debouncedCollectionRefetch;
|
|
117
|
+
/**
|
|
118
|
+
* Debounce a collection refetch for a DataDriver callback subscription.
|
|
119
|
+
*/
|
|
120
|
+
private debouncedDriverRefetch;
|
|
121
|
+
/**
|
|
122
|
+
* Fetch a collection with optional RLS auth context.
|
|
123
|
+
* When authContext is provided, the fetch runs inside a transaction
|
|
124
|
+
* with set_config calls so PostgreSQL RLS policies are enforced.
|
|
125
|
+
*/
|
|
126
|
+
private fetchCollectionWithAuth;
|
|
127
|
+
/**
|
|
128
|
+
* Debounce an entity refetch for a WebSocket subscription.
|
|
129
|
+
*/
|
|
130
|
+
private debouncedEntityRefetch;
|
|
131
|
+
/**
|
|
132
|
+
* Debounce an entity refetch for a Driver callback subscription.
|
|
133
|
+
*/
|
|
134
|
+
private debouncedEntityDriverRefetch;
|
|
135
|
+
/**
|
|
136
|
+
* Fetch a single entity with optional RLS auth context.
|
|
137
|
+
*/
|
|
138
|
+
private fetchEntityWithAuth;
|
|
139
|
+
private sendCollectionUpdate;
|
|
140
|
+
private sendEntityUpdate;
|
|
141
|
+
/**
|
|
142
|
+
* Send a lightweight entity-level patch to a collection subscriber.
|
|
143
|
+
* The client can merge this into its cached data for instant feedback.
|
|
144
|
+
*/
|
|
145
|
+
private sendCollectionEntityPatch;
|
|
146
|
+
private sendError;
|
|
147
|
+
private sendMessage;
|
|
148
|
+
/**
|
|
149
|
+
* Extract parent paths from a nested path like "posts/70/tags"
|
|
150
|
+
* Returns ["posts", "posts/70"] for the example above
|
|
151
|
+
*/
|
|
152
|
+
private getParentPaths;
|
|
153
|
+
/**
|
|
154
|
+
* Enable cross-instance realtime broadcasting via Postgres LISTEN/NOTIFY.
|
|
155
|
+
* Creates a dedicated pg.Client (outside the Drizzle pool) that stays
|
|
156
|
+
* connected and listens for change notifications from other instances.
|
|
157
|
+
*
|
|
158
|
+
* This is an **optional** feature — if never called, the backend operates
|
|
159
|
+
* in single-instance mode (the default, perfectly fine for most setups).
|
|
160
|
+
*
|
|
161
|
+
* @param connectionString Raw Postgres connection string for the LISTEN client.
|
|
162
|
+
*/
|
|
163
|
+
startListening(connectionString: string): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Stop listening and clean up the dedicated LISTEN connection.
|
|
166
|
+
*/
|
|
167
|
+
stopListening(): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Broadcast a change notification to other instances via pg_notify.
|
|
170
|
+
* Uses the main Drizzle connection (pooled) — NOT the LISTEN client.
|
|
171
|
+
*/
|
|
172
|
+
private broadcastChange;
|
|
173
|
+
/**
|
|
174
|
+
* Create and connect the dedicated LISTEN client with auto-reconnect.
|
|
175
|
+
*/
|
|
176
|
+
private connectListenClient;
|
|
177
|
+
/**
|
|
178
|
+
* Schedule a reconnection attempt with a fixed 3s delay.
|
|
179
|
+
*/
|
|
180
|
+
private scheduleReconnect;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Alias for RealtimeService for consistent naming with other database implementations.
|
|
184
|
+
* This allows code to use PostgresRealtimeProvider alongside future MongoRealtimeProvider, etc.
|
|
185
|
+
*/
|
|
186
|
+
export declare const PostgresRealtimeProvider: typeof RealtimeService;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { SQL } from "drizzle-orm";
|
|
2
|
+
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
import { FilterValues, WhereFilterOp, Relation } from "@rebasepro/types";
|
|
4
|
+
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
|
|
5
|
+
/** Drizzle dynamic query builder — accepts innerJoin + where chaining */
|
|
6
|
+
export interface DrizzleDynamicQuery {
|
|
7
|
+
innerJoin(table: PgTable<any>, condition: SQL): this;
|
|
8
|
+
where(condition: SQL | undefined): this;
|
|
9
|
+
limit(limit: number): this;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Unified condition builder for Drizzle/PostgreSQL queries.
|
|
13
|
+
*
|
|
14
|
+
* This class uses static methods and satisfies the ConditionBuilderStatic<SQL> type.
|
|
15
|
+
* It translates Rebase filter conditions to Drizzle SQL conditions.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const builder: ConditionBuilderStatic<SQL> = DrizzleConditionBuilder;
|
|
19
|
+
*/
|
|
20
|
+
export declare class DrizzleConditionBuilder {
|
|
21
|
+
/**
|
|
22
|
+
* Build filter conditions from FilterValues
|
|
23
|
+
*/
|
|
24
|
+
static buildFilterConditions<M extends Record<string, any>>(filter: FilterValues<Extract<keyof M, string>>, table: PgTable<any>, collectionPath: string): SQL[];
|
|
25
|
+
/**
|
|
26
|
+
* Build a single filter condition for a specific operator and value
|
|
27
|
+
*/
|
|
28
|
+
static buildSingleFilterCondition(column: AnyPgColumn, op: WhereFilterOp, value: unknown): SQL | null;
|
|
29
|
+
/**
|
|
30
|
+
* Build relation-based conditions for different relation types
|
|
31
|
+
*/
|
|
32
|
+
static buildRelationConditions(relation: Relation, parentEntityId: string | number | (string | number)[], targetTable: PgTable<any>, parentTable: PgTable<any>, parentIdColumn: AnyPgColumn, targetIdColumn: AnyPgColumn, registry: PostgresCollectionRegistry): {
|
|
33
|
+
joinConditions: {
|
|
34
|
+
table: PgTable<any>;
|
|
35
|
+
condition: SQL;
|
|
36
|
+
}[];
|
|
37
|
+
whereConditions: SQL[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Build conditions for join path relations
|
|
41
|
+
*/
|
|
42
|
+
private static buildJoinPathConditions;
|
|
43
|
+
/**
|
|
44
|
+
* Build a single join condition between tables
|
|
45
|
+
*/
|
|
46
|
+
private static buildSingleJoinCondition;
|
|
47
|
+
/**
|
|
48
|
+
* Try to build a junction table join when direct foreign key relationship is not found
|
|
49
|
+
*/
|
|
50
|
+
private static tryBuildJunctionJoin;
|
|
51
|
+
/**
|
|
52
|
+
* Build conditions for junction table (many-to-many) relations
|
|
53
|
+
*/
|
|
54
|
+
private static buildJunctionTableConditions;
|
|
55
|
+
/**
|
|
56
|
+
* Build conditions for inverse junction table (many-to-many) relations
|
|
57
|
+
*/
|
|
58
|
+
private static buildInverseJunctionTableConditions;
|
|
59
|
+
/**
|
|
60
|
+
* Build conditions for simple relations (owning/inverse without join paths)
|
|
61
|
+
*/
|
|
62
|
+
private static buildSimpleRelationCondition;
|
|
63
|
+
/**
|
|
64
|
+
* Combine multiple conditions with AND operator
|
|
65
|
+
*/
|
|
66
|
+
static combineConditionsWithAnd(conditions: SQL[]): SQL | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Combine multiple conditions with OR operator
|
|
69
|
+
*/
|
|
70
|
+
static combineConditionsWithOr(conditions: SQL[]): SQL | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Build search conditions for text fields
|
|
73
|
+
*/
|
|
74
|
+
static buildSearchConditions(searchString: string, properties: Record<string, any>, table: PgTable<any>): SQL[];
|
|
75
|
+
/**
|
|
76
|
+
* Build a unique field check condition
|
|
77
|
+
*/
|
|
78
|
+
static buildUniqueFieldCondition(fieldColumn: AnyPgColumn, value: unknown, idColumn?: AnyPgColumn, excludeId?: string | number): SQL[];
|
|
79
|
+
/**
|
|
80
|
+
* Build relation-based query with joins and conditions
|
|
81
|
+
*/
|
|
82
|
+
static buildRelationQuery<T extends DrizzleDynamicQuery>(baseQuery: T, relation: Relation, parentEntityId: string | number | (string | number)[], targetTable: PgTable<any>, parentTable: PgTable<any>, parentIdColumn: AnyPgColumn, targetIdColumn: AnyPgColumn, registry: PostgresCollectionRegistry, additionalFilters?: SQL[]): T;
|
|
83
|
+
/**
|
|
84
|
+
* Build count query for relations with proper joins and conditions
|
|
85
|
+
*/
|
|
86
|
+
static buildRelationCountQuery<T extends DrizzleDynamicQuery>(baseCountQuery: T, relation: Relation, parentEntityId: string | number, targetTable: PgTable<any>, parentTable: PgTable<any>, parentIdColumn: AnyPgColumn, targetIdColumn: AnyPgColumn, registry: PostgresCollectionRegistry, additionalFilters?: SQL[]): T;
|
|
87
|
+
/**
|
|
88
|
+
* Build join path conditions for count queries
|
|
89
|
+
*/
|
|
90
|
+
private static buildJoinPathCountQuery;
|
|
91
|
+
/**
|
|
92
|
+
* Build junction table conditions for count queries
|
|
93
|
+
*/
|
|
94
|
+
private static buildJunctionCountQuery;
|
|
95
|
+
/**
|
|
96
|
+
* Build inverse junction table conditions for count queries
|
|
97
|
+
*/
|
|
98
|
+
private static buildInverseJunctionCountQuery;
|
|
99
|
+
/**
|
|
100
|
+
* Helper method to extract table names from columns
|
|
101
|
+
*/
|
|
102
|
+
static getTableNamesFromColumns(columns: string | string[]): string[];
|
|
103
|
+
/**
|
|
104
|
+
* Helper method to extract column names from columns
|
|
105
|
+
*/
|
|
106
|
+
static getColumnNamesFromColumns(columns: string | string[]): string[];
|
|
107
|
+
/**
|
|
108
|
+
* Find the corresponding junction table for an inverse many-to-many relation
|
|
109
|
+
*/
|
|
110
|
+
private static findCorrespondingJunctionTable;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Alias for DrizzleConditionBuilder for consistent naming with other database implementations.
|
|
114
|
+
* This allows code to use PostgresConditionBuilder alongside future MongoConditionBuilder, etc.
|
|
115
|
+
*/
|
|
116
|
+
export declare const PostgresConditionBuilder: typeof DrizzleConditionBuilder;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RealtimeService } from "./services/realtimeService";
|
|
2
|
+
import { PostgresBackendDriver } from "./PostgresBackendDriver";
|
|
3
|
+
import { Server } from "http";
|
|
4
|
+
import { AuthConfig } from "@rebasepro/server-core";
|
|
5
|
+
export declare function createPostgresWebSocket(server: Server, realtimeService: RealtimeService, driver: PostgresBackendDriver, authConfig?: AuthConfig): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type AnalyticsController = {
|
|
2
|
+
/**
|
|
3
|
+
* Callback used to get analytics events from the CMS
|
|
4
|
+
*/
|
|
5
|
+
onAnalyticsEvent?: (event: AnalyticsEvent, data?: object) => void;
|
|
6
|
+
};
|
|
7
|
+
export type AnalyticsEvent = "entity_click" | "entity_click_from_reference" | "reference_selection_clear" | "reference_selection_toggle" | "reference_selected_single" | "reference_selection_new_entity" | "edit_entity_clicked" | "entity_edited" | "new_entity_click" | "new_entity_saved" | "copy_entity_click" | "entity_copied" | "single_delete_dialog_open" | "multiple_delete_dialog_open" | "single_entity_deleted" | "multiple_entities_deleted" | "drawer_navigate_to_home" | "drawer_navigate_to_collection" | "drawer_navigate_to_view" | "home_navigate_to_collection" | "home_favorite_navigate_to_collection" | "home_navigate_to_view" | "home_navigate_to_admin_view" | "home_favorite_navigate_to_view" | "home_move_card" | "home_move_group" | "home_drop_new_group" | "collection_inline_editing" | "view_mode_changed" | "kanban_card_moved" | "kanban_column_reorder" | "kanban_property_changed" | "kanban_new_entity_in_column" | "kanban_backfill_order" | "card_view_entity_click" | "unmapped_event";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { StorageSource } from "./storage";
|
|
2
|
+
import { Role, User } from "../users";
|
|
3
|
+
import { RebaseData } from "./data";
|
|
4
|
+
/**
|
|
5
|
+
* Capabilities advertised by an auth provider.
|
|
6
|
+
* UI components use this to show/hide features dynamically
|
|
7
|
+
* (e.g. password reset, registration, session management).
|
|
8
|
+
* @group Hooks and utilities
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthCapabilities {
|
|
11
|
+
emailPasswordLogin?: boolean;
|
|
12
|
+
googleLogin?: boolean;
|
|
13
|
+
registration?: boolean;
|
|
14
|
+
passwordReset?: boolean;
|
|
15
|
+
sessionManagement?: boolean;
|
|
16
|
+
profileUpdate?: boolean;
|
|
17
|
+
emailVerification?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Controller for retrieving the logged user or performing auth related operations.
|
|
21
|
+
* Note that if you are implementing your AuthController, you probably will want
|
|
22
|
+
* to do it as the result of a hook.
|
|
23
|
+
* @group Hooks and utilities
|
|
24
|
+
*/
|
|
25
|
+
export type AuthController<USER extends User = User, ExtraData = unknown> = {
|
|
26
|
+
/**
|
|
27
|
+
* The user currently logged in
|
|
28
|
+
* The values can be: the user object, null if they skipped login
|
|
29
|
+
*/
|
|
30
|
+
user: USER | null;
|
|
31
|
+
/**
|
|
32
|
+
* Initial loading flag. It is used not to display the login screen
|
|
33
|
+
* when the app first loads, and it has not been checked whether the user
|
|
34
|
+
* is logged in or not.
|
|
35
|
+
*/
|
|
36
|
+
initialLoading?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Loading flag. It is used to display a loading screen when the user is
|
|
39
|
+
* logging in or out.
|
|
40
|
+
*/
|
|
41
|
+
authLoading: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Sign out
|
|
44
|
+
*/
|
|
45
|
+
signOut: () => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Error initializing the authentication
|
|
48
|
+
*/
|
|
49
|
+
authError?: unknown;
|
|
50
|
+
/**
|
|
51
|
+
* Error dispatched by the auth provider
|
|
52
|
+
*/
|
|
53
|
+
authProviderError?: unknown;
|
|
54
|
+
/**
|
|
55
|
+
* You can use this method to retrieve the auth token for the current user.
|
|
56
|
+
*/
|
|
57
|
+
getAuthToken: () => Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Has the user skipped the login process
|
|
60
|
+
*/
|
|
61
|
+
loginSkipped: boolean;
|
|
62
|
+
extra: ExtraData;
|
|
63
|
+
setExtra: (extra: ExtraData) => void;
|
|
64
|
+
setUser?(user: USER | null): void;
|
|
65
|
+
setUserRoles?(roles: Role[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Capabilities advertised by the auth provider.
|
|
68
|
+
* UI components use this to feature-detect what the backend supports.
|
|
69
|
+
*/
|
|
70
|
+
capabilities?: AuthCapabilities;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Extended auth controller with common optional auth methods.
|
|
74
|
+
* Backend implementations (Rebase backend, Firebase, Supabase, etc.)
|
|
75
|
+
* extend this with their own backend-specific extras.
|
|
76
|
+
* @group Hooks and utilities
|
|
77
|
+
*/
|
|
78
|
+
export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
|
|
79
|
+
/** Login with email and password */
|
|
80
|
+
emailPasswordLogin?(email: string, password: string): Promise<void>;
|
|
81
|
+
/** Login with a Google ID token or trigger Google popup */
|
|
82
|
+
googleLogin?(idToken: string): Promise<void>;
|
|
83
|
+
/** Register a new user */
|
|
84
|
+
register?(email: string, password: string, displayName?: string): Promise<void>;
|
|
85
|
+
/** Skip login (for anonymous access if enabled) */
|
|
86
|
+
skipLogin?(): void;
|
|
87
|
+
/** Request password reset email */
|
|
88
|
+
forgotPassword?(email: string): Promise<void>;
|
|
89
|
+
/** Reset password using a token */
|
|
90
|
+
resetPassword?(token: string, password: string): Promise<void>;
|
|
91
|
+
/** Change password for the authenticated user */
|
|
92
|
+
changePassword?(oldPassword: string, newPassword: string): Promise<void>;
|
|
93
|
+
/** Update user profile */
|
|
94
|
+
updateProfile?(displayName?: string, photoURL?: string): Promise<USER>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Implement this function to allow access to specific users.
|
|
98
|
+
* @group Hooks and utilities
|
|
99
|
+
*/
|
|
100
|
+
export type Authenticator<USER extends User = User> = (props: {
|
|
101
|
+
/**
|
|
102
|
+
* Logged-in user or null
|
|
103
|
+
*/
|
|
104
|
+
user: USER | null;
|
|
105
|
+
/**
|
|
106
|
+
* AuthController
|
|
107
|
+
*/
|
|
108
|
+
authController: AuthController<USER>;
|
|
109
|
+
/**
|
|
110
|
+
* Unified data access API
|
|
111
|
+
*/
|
|
112
|
+
data: RebaseData;
|
|
113
|
+
/**
|
|
114
|
+
* Used storage implementation
|
|
115
|
+
*/
|
|
116
|
+
storageSource: StorageSource;
|
|
117
|
+
}) => boolean | Promise<boolean>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { User } from "../users";
|
|
2
|
+
import { RebaseData } from "./data";
|
|
3
|
+
/**
|
|
4
|
+
* Event type for authentication state changes
|
|
5
|
+
*/
|
|
6
|
+
export type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED';
|
|
7
|
+
/**
|
|
8
|
+
* Standard session interface representing an authenticated state
|
|
9
|
+
*/
|
|
10
|
+
export interface RebaseSession {
|
|
11
|
+
accessToken: string;
|
|
12
|
+
refreshToken: string;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
user: User;
|
|
15
|
+
}
|
|
16
|
+
import { StorageSource } from "./storage";
|
|
17
|
+
/**
|
|
18
|
+
* Unified Authentication Client Interface
|
|
19
|
+
* Pure functional SDK interface, decoupled from UI and React hooks
|
|
20
|
+
*/
|
|
21
|
+
export interface AuthClient {
|
|
22
|
+
/**
|
|
23
|
+
* Get the current user from the server or cache
|
|
24
|
+
*/
|
|
25
|
+
getUser(): Promise<User | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the currently active session
|
|
28
|
+
*/
|
|
29
|
+
getSession(): RebaseSession | null;
|
|
30
|
+
/**
|
|
31
|
+
* Sign out the current user and clear local session
|
|
32
|
+
*/
|
|
33
|
+
signOut(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to authentication state changes
|
|
36
|
+
*/
|
|
37
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: RebaseSession | null) => void): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Manually refresh the session token
|
|
40
|
+
*/
|
|
41
|
+
refreshSession(): Promise<RebaseSession>;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Overarching abstraction that unites Data, Auth, and Storage.
|
|
46
|
+
* Adapters for Supabase or Firebase simply need to implement this interface.
|
|
47
|
+
*/
|
|
48
|
+
export interface RebaseClient<DB = any> {
|
|
49
|
+
/** Unified Data access layer */
|
|
50
|
+
data: RebaseData;
|
|
51
|
+
/** Unified Authentication layer */
|
|
52
|
+
auth: AuthClient;
|
|
53
|
+
/** Unified Storage layer */
|
|
54
|
+
storage?: StorageSource;
|
|
55
|
+
/** Optional admin panel specific tasks */
|
|
56
|
+
admin?: any;
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EntityCollection, EntityReference } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Controller that provides access to the registered entity collections.
|
|
4
|
+
* @group Models
|
|
5
|
+
*/
|
|
6
|
+
export type CollectionRegistryController<EC extends EntityCollection = EntityCollection<any>> = {
|
|
7
|
+
/**
|
|
8
|
+
* List of the mapped collections in the CMS.
|
|
9
|
+
* Each entry relates to a collection in the root database.
|
|
10
|
+
* Each of the navigation entries in this field
|
|
11
|
+
* generates an entry in the main menu.
|
|
12
|
+
*/
|
|
13
|
+
collections?: EntityCollection[];
|
|
14
|
+
/**
|
|
15
|
+
* Is the registry ready to be used
|
|
16
|
+
*/
|
|
17
|
+
initialised: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get the collection configuration for a given path.
|
|
20
|
+
* The collection is resolved from the given path or alias.
|
|
21
|
+
*/
|
|
22
|
+
getCollection: (slugOrPath: string, includeUserOverride?: boolean) => EC | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get the raw, un-normalized collection configuration.
|
|
25
|
+
* This bypasses the `CollectionRegistry` normalization (such as injecting `relation` instances).
|
|
26
|
+
* This is strictly for the Visual Editor to manipulate AST code without persisting runtime state.
|
|
27
|
+
*/
|
|
28
|
+
getRawCollection: (slugOrPath: string) => EC | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve all the related parent references for a given path
|
|
31
|
+
* @param path
|
|
32
|
+
*/
|
|
33
|
+
getParentReferencesFromPath: (path: string) => EntityReference[];
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve all the related parent collection ids for a given path
|
|
36
|
+
* @param path
|
|
37
|
+
*/
|
|
38
|
+
getParentCollectionIds: (path: string) => string[];
|
|
39
|
+
/**
|
|
40
|
+
* Resolve paths from a list of ids
|
|
41
|
+
* @param ids
|
|
42
|
+
*/
|
|
43
|
+
convertIdsToPaths: (ids: string[]) => string[];
|
|
44
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { EntityLinkBuilder, Locale, EntityAction, EntityCustomView, RebasePlugin, PropertyConfig, SlotContribution } from "../types";
|
|
3
|
+
export type CustomizationController = {
|
|
4
|
+
/**
|
|
5
|
+
* Builder for generating utility links for entities
|
|
6
|
+
*/
|
|
7
|
+
entityLinkBuilder?: EntityLinkBuilder;
|
|
8
|
+
/**
|
|
9
|
+
* Use plugins to modify the behaviour of the CMS.
|
|
10
|
+
*/
|
|
11
|
+
plugins?: RebasePlugin[];
|
|
12
|
+
/**
|
|
13
|
+
* Pre-merged slots from plugins + direct slot contributions.
|
|
14
|
+
*/
|
|
15
|
+
resolvedSlots: SlotContribution[];
|
|
16
|
+
/**
|
|
17
|
+
* List of additional custom views for entities.
|
|
18
|
+
* You can use the key to reference the custom view in
|
|
19
|
+
* the `entityViews` prop of a collection.
|
|
20
|
+
*
|
|
21
|
+
* You can also define an entity view from the UI.
|
|
22
|
+
*/
|
|
23
|
+
entityViews?: EntityCustomView[];
|
|
24
|
+
/**
|
|
25
|
+
* List of actions that can be performed on entities.
|
|
26
|
+
* These actions are displayed in the entity view and in the collection view.
|
|
27
|
+
* You can later reuse these actions in the `entityActions` prop of a collection,
|
|
28
|
+
* by specifying the `key` of the action.
|
|
29
|
+
*/
|
|
30
|
+
entityActions?: EntityAction[];
|
|
31
|
+
/**
|
|
32
|
+
* Format of the dates in the CMS.
|
|
33
|
+
* Defaults to 'MMMM dd, yyyy, HH:mm:ss'
|
|
34
|
+
*/
|
|
35
|
+
dateTimeFormat?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Locale of the CMS, currently only affecting dates
|
|
38
|
+
*/
|
|
39
|
+
locale?: Locale;
|
|
40
|
+
/**
|
|
41
|
+
* Record of custom form fields to be used in the CMS.
|
|
42
|
+
* You can use the key to reference the custom field in
|
|
43
|
+
* the `propertyConfig` prop of a property in a collection.
|
|
44
|
+
*/
|
|
45
|
+
propertyConfigs: Record<string, PropertyConfig>;
|
|
46
|
+
components?: {
|
|
47
|
+
/**
|
|
48
|
+
* Component to render when a reference is missing
|
|
49
|
+
*/
|
|
50
|
+
missingReference?: React.ComponentType<{
|
|
51
|
+
path: string;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
};
|