@rebasepro/server-postgresql 0.2.3 → 0.2.4

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 (50) hide show
  1. package/dist/common/src/collections/default-collections.d.ts +12 -0
  2. package/dist/common/src/collections/index.d.ts +1 -0
  3. package/dist/common/src/util/permissions.d.ts +1 -0
  4. package/dist/index.es.js +844 -160
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +842 -158
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +1 -1
  9. package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +1 -0
  10. package/dist/server-postgresql/src/auth/services.d.ts +43 -1
  11. package/dist/server-postgresql/src/connection.d.ts +25 -0
  12. package/dist/server-postgresql/src/schema/auth-schema.d.ts +2382 -35
  13. package/dist/server-postgresql/src/services/EntityFetchService.d.ts +4 -0
  14. package/dist/server-postgresql/src/services/entityService.d.ts +2 -0
  15. package/dist/server-postgresql/src/services/realtimeService.d.ts +20 -0
  16. package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +18 -0
  17. package/dist/types/src/controllers/auth.d.ts +2 -24
  18. package/dist/types/src/controllers/client.d.ts +0 -3
  19. package/dist/types/src/controllers/collection_registry.d.ts +1 -1
  20. package/dist/types/src/controllers/data_driver.d.ts +18 -0
  21. package/dist/types/src/controllers/registry.d.ts +5 -4
  22. package/dist/types/src/rebase_context.d.ts +1 -1
  23. package/dist/types/src/types/auth_adapter.d.ts +2 -4
  24. package/dist/types/src/types/collections.d.ts +0 -4
  25. package/dist/types/src/types/component_ref.d.ts +1 -1
  26. package/dist/types/src/types/cron.d.ts +1 -1
  27. package/dist/types/src/types/entity_views.d.ts +1 -0
  28. package/dist/types/src/types/export_import.d.ts +1 -1
  29. package/dist/types/src/types/formex.d.ts +2 -2
  30. package/dist/types/src/types/properties.d.ts +2 -2
  31. package/dist/types/src/types/translations.d.ts +28 -12
  32. package/dist/types/src/types/user_management_delegate.d.ts +6 -4
  33. package/dist/types/src/users/roles.d.ts +0 -8
  34. package/package.json +6 -6
  35. package/src/PostgresBackendDriver.ts +4 -2
  36. package/src/PostgresBootstrapper.ts +27 -8
  37. package/src/auth/ensure-tables.ts +79 -17
  38. package/src/auth/services.ts +292 -23
  39. package/src/connection.ts +77 -0
  40. package/src/data-transformer.ts +2 -2
  41. package/src/schema/auth-schema.ts +80 -14
  42. package/src/schema/generate-drizzle-schema.ts +6 -6
  43. package/src/services/EntityFetchService.ts +69 -10
  44. package/src/services/entityService.ts +2 -0
  45. package/src/services/realtimeService.ts +214 -2
  46. package/src/utils/drizzle-conditions.ts +74 -2
  47. package/src/websocket.ts +10 -2
  48. package/test/auth-services.test.ts +15 -28
  49. package/test/drizzle-conditions.test.ts +168 -0
  50. package/vite.config.ts +1 -1
@@ -1,6 +1,7 @@
1
1
  import { SQL } from "drizzle-orm";
2
2
  import { PgTable } from "drizzle-orm/pg-core";
3
3
  import { Entity, FilterValues } from "@rebasepro/types";
4
+ import type { VectorSearchParams } from "@rebasepro/types";
4
5
  import { RelationService } from "./RelationService";
5
6
  import { DrizzleClient } from "../interfaces";
6
7
  import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry";
@@ -102,6 +103,7 @@ export declare class EntityFetchService {
102
103
  startAfter?: Record<string, unknown>;
103
104
  searchString?: string;
104
105
  databaseId?: string;
106
+ vectorSearch?: VectorSearchParams;
105
107
  }): Promise<Entity<M>[]>;
106
108
  /**
107
109
  * Fallback path used when db.query is unavailable.
@@ -123,6 +125,7 @@ export declare class EntityFetchService {
123
125
  startAfter?: Record<string, unknown>;
124
126
  searchString?: string;
125
127
  databaseId?: string;
128
+ vectorSearch?: VectorSearchParams;
126
129
  }): Promise<Entity<M>[]>;
127
130
  /**
128
131
  * Search entities by text
@@ -175,6 +178,7 @@ export declare class EntityFetchService {
175
178
  startAfter?: Record<string, unknown>;
176
179
  searchString?: string;
177
180
  databaseId?: string;
181
+ vectorSearch?: VectorSearchParams;
178
182
  }, include?: string[]): Promise<Record<string, unknown>[]>;
179
183
  /**
180
184
  * Fetch a single entity with optional relation includes for REST API.
@@ -1,4 +1,5 @@
1
1
  import { Entity, FilterValues } from "@rebasepro/types";
2
+ import type { VectorSearchParams } from "@rebasepro/types";
2
3
  import { EntityFetchService } from "./EntityFetchService";
3
4
  import { EntityPersistService } from "./EntityPersistService";
4
5
  import { RelationService } from "./RelationService";
@@ -42,6 +43,7 @@ export declare class EntityService implements EntityRepository {
42
43
  startAfter?: Record<string, unknown>;
43
44
  searchString?: string;
44
45
  databaseId?: string;
46
+ vectorSearch?: VectorSearchParams;
45
47
  }): Promise<Entity<M>[]>;
46
48
  /**
47
49
  * Search entities by text
@@ -22,6 +22,10 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
22
22
  private db;
23
23
  private registry;
24
24
  private clients;
25
+ private channels;
26
+ private presence;
27
+ private presenceInterval?;
28
+ private static readonly PRESENCE_TIMEOUT_MS;
25
29
  private entityService;
26
30
  private _subscriptions;
27
31
  private subscriptionCallbacks;
@@ -152,6 +156,22 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
152
156
  * Returns ["posts", "posts/70"] for the example above
153
157
  */
154
158
  private getParentPaths;
159
+ /** Join a broadcast channel */
160
+ joinChannel(clientId: string, channel: string): void;
161
+ /** Leave a broadcast channel */
162
+ leaveChannel(clientId: string, channel: string): void;
163
+ /** Broadcast a message to all clients in a channel except sender */
164
+ broadcastToChannel(clientId: string, channel: string, event: string, payload: unknown): void;
165
+ /** Track presence in a channel */
166
+ trackPresence(clientId: string, channel: string, state: Record<string, unknown>): void;
167
+ /** Remove presence from a channel */
168
+ removePresence(clientId: string, channel: string): void;
169
+ /** Send full presence state to a specific client */
170
+ sendPresenceState(clientId: string, channel: string): void;
171
+ /** Broadcast presence diff (joins/leaves) to channel */
172
+ private broadcastPresenceDiff;
173
+ /** Periodic cleanup for stale presences */
174
+ private ensurePresenceCleanup;
155
175
  /**
156
176
  * Gracefully tear down all realtime resources.
157
177
  *
@@ -108,6 +108,24 @@ export declare class DrizzleConditionBuilder {
108
108
  * Find the corresponding junction table for an inverse many-to-many relation
109
109
  */
110
110
  private static findCorrespondingJunctionTable;
111
+ /**
112
+ * Build vector similarity search expressions for pgvector.
113
+ *
114
+ * Returns:
115
+ * - `orderBy`: SQL expression to ORDER BY distance (ascending = closest first)
116
+ * - `filter`: optional WHERE clause for distance threshold
117
+ * - `distanceSelect`: SQL expression for selecting the distance as `_distance`
118
+ */
119
+ static buildVectorSearchConditions(table: PgTable<any>, vectorSearch: {
120
+ property: string;
121
+ vector: number[];
122
+ distance?: "cosine" | "l2" | "inner_product";
123
+ threshold?: number;
124
+ }): {
125
+ orderBy: SQL;
126
+ filter?: SQL;
127
+ distanceSelect: SQL;
128
+ };
111
129
  }
112
130
  /**
113
131
  * Alias for DrizzleConditionBuilder for consistent naming with other database implementations.
@@ -1,6 +1,4 @@
1
- import { StorageSource } from "./storage";
2
1
  import { Role, User } from "../users";
3
- import { RebaseData } from "./data";
4
2
  /**
5
3
  * Capabilities advertised by an auth provider.
6
4
  * UI components use this to show/hide features dynamically
@@ -89,6 +87,8 @@ export interface AuthControllerExtended<USER extends User = User, ExtraData = un
89
87
  code: string;
90
88
  redirectUri: string;
91
89
  }) => Promise<void>;
90
+ /** Generic OAuth login — works with any provider. Posts payload to /auth/{providerId}. */
91
+ oauthLogin?: (providerId: string, payload: Record<string, unknown>) => Promise<void>;
92
92
  /** Register a new user */
93
93
  register?(email: string, password: string, displayName?: string): Promise<void>;
94
94
  /** Skip login (for anonymous access if enabled) */
@@ -102,25 +102,3 @@ export interface AuthControllerExtended<USER extends User = User, ExtraData = un
102
102
  /** Update user profile */
103
103
  updateProfile?(displayName?: string, photoURL?: string): Promise<USER>;
104
104
  }
105
- /**
106
- * Implement this function to allow access to specific users.
107
- * @group Hooks and utilities
108
- */
109
- export type Authenticator<USER extends User = User> = (props: {
110
- /**
111
- * Logged-in user or null
112
- */
113
- user: USER | null;
114
- /**
115
- * AuthController
116
- */
117
- authController: AuthController<USER>;
118
- /**
119
- * Unified data access API
120
- */
121
- data: RebaseData;
122
- /**
123
- * Used storage implementation
124
- */
125
- storageSource: StorageSource;
126
- }) => boolean | Promise<boolean>;
@@ -65,7 +65,6 @@ export interface AdminRole {
65
65
  name: string;
66
66
  isAdmin: boolean;
67
67
  defaultPermissions: Record<string, unknown> | null;
68
- config: Record<string, unknown> | null;
69
68
  }
70
69
  /**
71
70
  * Client-side Admin API interface.
@@ -123,7 +122,6 @@ export interface AdminAPI {
123
122
  name: string;
124
123
  isAdmin?: boolean;
125
124
  defaultPermissions?: Record<string, unknown>;
126
- config?: Record<string, unknown>;
127
125
  }): Promise<{
128
126
  role: AdminRole;
129
127
  }>;
@@ -131,7 +129,6 @@ export interface AdminAPI {
131
129
  name?: string;
132
130
  isAdmin?: boolean;
133
131
  defaultPermissions?: Record<string, unknown>;
134
- config?: Record<string, unknown>;
135
132
  }): Promise<{
136
133
  role: AdminRole;
137
134
  }>;
@@ -4,7 +4,7 @@ import type { EntityReference } from "../types/entities";
4
4
  * Controller that provides access to the registered entity collections.
5
5
  * @group Models
6
6
  */
7
- export type CollectionRegistryController<DB = Record<string, unknown>, EC extends EntityCollection = EntityCollection<any>> = {
7
+ export type CollectionRegistryController<DB = Record<string, unknown>, EC extends EntityCollection = EntityCollection> = {
8
8
  /**
9
9
  * List of the mapped collections in the CMS.
10
10
  * Each entry relates to a collection in the root database.
@@ -17,6 +17,21 @@ export type ListenEntityProps<M extends Record<string, unknown> = Record<string,
17
17
  onUpdate: (entity: Entity<M> | null) => void;
18
18
  onError?: (error: Error) => void;
19
19
  };
20
+ /**
21
+ * Configuration for vector similarity search queries.
22
+ * Vector search applies an ORDER BY distance expression and optionally
23
+ * filters results by a distance threshold.
24
+ */
25
+ export interface VectorSearchParams {
26
+ /** Property name containing the vector column */
27
+ property: string;
28
+ /** Query vector to compare against */
29
+ vector: number[];
30
+ /** Distance function (default: "cosine") */
31
+ distance?: "cosine" | "l2" | "inner_product";
32
+ /** Only return results within this distance threshold */
33
+ threshold?: number;
34
+ }
20
35
  /**
21
36
  * @internal
22
37
  */
@@ -30,6 +45,8 @@ export interface FetchCollectionProps<M extends Record<string, unknown> = Record
30
45
  orderBy?: string;
31
46
  searchString?: string;
32
47
  order?: "desc" | "asc";
48
+ /** Vector similarity search configuration */
49
+ vectorSearch?: VectorSearchParams;
33
50
  }
34
51
  /**
35
52
  * @internal
@@ -187,6 +204,7 @@ export interface RestFetchService {
187
204
  startAfter?: Record<string, unknown>;
188
205
  searchString?: string;
189
206
  databaseId?: string;
207
+ vectorSearch?: VectorSearchParams;
190
208
  }, include?: string[]): Promise<Record<string, unknown>[]>;
191
209
  /**
192
210
  * Fetch a single flattened entity with optional relation includes.
@@ -4,6 +4,7 @@ import type { EntityCollectionsBuilder } from "../types/builders";
4
4
  import type { EntityCustomView } from "../types/entity_views";
5
5
  import type { EntityAction } from "../types/entity_actions";
6
6
  import type { AppView, NavigationGroupMapping } from "./navigation";
7
+ import type { RebasePlugin } from "../types/plugins";
7
8
  /**
8
9
  * Options to enable the built-in collection editor.
9
10
  * When provided to `<RebaseCMS>`, the editor is auto-wired as a native feature.
@@ -19,12 +20,12 @@ export interface CollectionEditorOptions {
19
20
  /** Suggested base paths shown when creating new collections. */
20
21
  pathSuggestions?: string[];
21
22
  }
22
- export interface RebaseCMSConfig<EC extends EntityCollection = any> {
23
+ export interface RebaseCMSConfig<EC extends EntityCollection = EntityCollection> {
23
24
  collections?: EC[] | EntityCollectionsBuilder<EC>;
24
25
  homePage?: ReactNode;
25
- entityViews?: EntityCustomView<any>[];
26
+ entityViews?: EntityCustomView[];
26
27
  entityActions?: EntityAction[];
27
- plugins?: any[];
28
+ plugins?: RebasePlugin[];
28
29
  /**
29
30
  * Centralized configuration for how collections and views are grouped
30
31
  * in the navigation sidebar and home page.
@@ -42,7 +43,7 @@ export interface RebaseCMSConfig<EC extends EntityCollection = any> {
42
43
  collectionEditor?: boolean | CollectionEditorOptions;
43
44
  }
44
45
  export interface RebaseStudioConfig {
45
- tools?: ("sql" | "js" | "rls" | "schema" | "storage" | "cron" | "schema-visualizer" | "branches" | "api")[];
46
+ tools?: ("sql" | "js" | "rls" | "schema" | "storage" | "cron" | "schema-visualizer" | "branches" | "api" | "logs")[];
46
47
  homePage?: ReactNode;
47
48
  devViews?: AppView[];
48
49
  }
@@ -28,7 +28,7 @@ export type RebaseCallContext<USER extends User = User> = {
28
28
  * const { client } = props.context;
29
29
  * const result = await client.functions.invoke('extract-job', { url });
30
30
  */
31
- client: RebaseClient<any>;
31
+ client: RebaseClient;
32
32
  /**
33
33
  * Unified data access — `context.data.products.create(...)`.
34
34
  * Access any collection as a dynamic property.
@@ -133,7 +133,7 @@ export interface AuthUserData {
133
133
  displayName?: string | null;
134
134
  photoUrl?: string | null;
135
135
  emailVerified?: boolean;
136
- metadata?: Record<string, any>;
136
+ metadata?: Record<string, unknown>;
137
137
  createdAt?: Date;
138
138
  updatedAt?: Date;
139
139
  }
@@ -146,7 +146,7 @@ export interface AuthCreateUserData {
146
146
  password?: string;
147
147
  displayName?: string;
148
148
  photoUrl?: string;
149
- metadata?: Record<string, any>;
149
+ metadata?: Record<string, unknown>;
150
150
  }
151
151
  /**
152
152
  * Role data exposed by the auth adapter.
@@ -168,7 +168,6 @@ export interface AuthRoleData {
168
168
  edit?: boolean;
169
169
  delete?: boolean;
170
170
  }> | null;
171
- config?: Record<string, unknown> | null;
172
171
  }
173
172
  /**
174
173
  * Data for creating a role.
@@ -180,7 +179,6 @@ export interface AuthCreateRoleData {
180
179
  isAdmin?: boolean;
181
180
  defaultPermissions?: AuthRoleData["defaultPermissions"];
182
181
  collectionPermissions?: AuthRoleData["collectionPermissions"];
183
- config?: AuthRoleData["config"];
184
182
  }
185
183
  /**
186
184
  * User management operations for the admin panel.
@@ -589,10 +589,6 @@ export interface FilterPreset<Key extends string = string> {
589
589
  */
590
590
  sort?: [Key, "asc" | "desc"];
591
591
  }
592
- /**
593
- * @deprecated Use {@link FilterPreset} instead.
594
- */
595
- export type QuickFilter<Key extends string = string> = FilterPreset<Key>;
596
592
  /**
597
593
  * Used to indicate valid filter combinations (e.g. created in Firestore)
598
594
  * If the user selects a specific filter/sort combination, the CMS checks if it's
@@ -37,7 +37,7 @@ export interface LazyComponentRef<P = unknown> {
37
37
  *
38
38
  * @group Types
39
39
  */
40
- export type ComponentRef<P = unknown> = React.ComponentType<P> | LazyComponentRef<P> | (() => Promise<{
40
+ export type ComponentRef<P = any> = React.ComponentType<P> | LazyComponentRef<P> | (() => Promise<{
41
41
  default: React.ComponentType<P>;
42
42
  }>) | string;
43
43
  /**
@@ -44,7 +44,7 @@ export interface CronJobContext {
44
44
  /** A simple logger scoped to this job run. */
45
45
  log: (...args: unknown[]) => void;
46
46
  /** The RebaseClient instance to interact with the database. */
47
- client: RebaseClient<any>;
47
+ client: RebaseClient;
48
48
  }
49
49
  export type CronJobRunState = "idle" | "running" | "success" | "error" | "disabled";
50
50
  /**
@@ -50,6 +50,7 @@ export interface FormContext<M extends Record<string, unknown> = Record<string,
50
50
  export type EntityCustomView<M extends Record<string, unknown> = Record<string, unknown>> = {
51
51
  key: string;
52
52
  name: string;
53
+ icon?: string | React.ReactNode;
53
54
  tabComponent?: React.ReactNode;
54
55
  includeActions?: boolean | "bottom";
55
56
  Builder?: ComponentRef<EntityCustomViewParams<M>>;
@@ -15,7 +15,7 @@ export interface ExportConfig<USER extends User = User> {
15
15
  export interface ExportMappingFunction<USER extends User = User> {
16
16
  key: string;
17
17
  builder: ({ entity, context }: {
18
- entity: Entity<any>;
18
+ entity: Entity;
19
19
  context: RebaseContext<USER>;
20
20
  }) => Promise<string> | string;
21
21
  }
@@ -1,5 +1,5 @@
1
1
  import React, { FormEvent } from "react";
2
- export type FormexController<T = any> = {
2
+ export type FormexController<T = unknown> = {
3
3
  values: T;
4
4
  initialValues: T;
5
5
  setValues: (values: T) => void;
@@ -32,7 +32,7 @@ export type FormexController<T = any> = {
32
32
  canUndo: boolean;
33
33
  canRedo: boolean;
34
34
  };
35
- export type FormexResetProps<T = any> = {
35
+ export type FormexResetProps<T = unknown> = {
36
36
  values?: T;
37
37
  submitCount?: number;
38
38
  errors?: Record<string, string>;
@@ -104,8 +104,8 @@ export interface BaseUIConfig<CustomProps = unknown> {
104
104
  disabled?: boolean | PropertyDisabledConfig;
105
105
  widthPercentage?: number;
106
106
  customProps?: CustomProps;
107
- Field?: ComponentRef<any>;
108
- Preview?: ComponentRef<any>;
107
+ Field?: ComponentRef;
108
+ Preview?: ComponentRef;
109
109
  }
110
110
  export interface BaseProperty<CustomProps = unknown> {
111
111
  ui?: BaseUIConfig<CustomProps>;
@@ -105,6 +105,12 @@ export interface RebaseTranslations {
105
105
  navigation_drawer: string;
106
106
  collapse: string;
107
107
  expand: string;
108
+ /** Tooltip for the language switcher in the drawer footer */
109
+ change_language?: string;
110
+ /** Tooltip for the theme toggle in the drawer footer */
111
+ toggle_theme?: string;
112
+ /** Aria label for the user menu trigger in the drawer footer */
113
+ user_menu?: string;
108
114
  error: string;
109
115
  error_uploading_file: string;
110
116
  error_deleting: string;
@@ -426,18 +432,28 @@ export interface RebaseTranslations {
426
432
  deleted: string;
427
433
  select_reference: string;
428
434
  select_references: string;
429
- account_settings: string;
430
- profile: string;
431
- sessions: string;
432
- display_name: string;
433
- photo_url: string;
434
- save_profile: string;
435
- saving: string;
436
- no_active_sessions: string;
437
- revoking: string;
438
- revoke_all_sessions: string;
439
- unknown_device: string;
440
- current: string;
435
+ account_settings?: string;
436
+ profile?: string;
437
+ sessions?: string;
438
+ security?: string;
439
+ change_password?: string;
440
+ current_password?: string;
441
+ new_password?: string;
442
+ confirm_password?: string;
443
+ password_changed?: string;
444
+ passwords_dont_match?: string;
445
+ password_too_short?: string;
446
+ password_change_not_available?: string;
447
+ changing_password?: string;
448
+ display_name?: string;
449
+ photo_url?: string;
450
+ save_profile?: string;
451
+ saving?: string;
452
+ no_active_sessions?: string;
453
+ revoking?: string;
454
+ revoke_all_sessions?: string;
455
+ unknown_device?: string;
456
+ current?: string;
441
457
  role_id: string;
442
458
  role_name: string;
443
459
  add_reference: string;
@@ -104,15 +104,17 @@ export interface UserManagementDelegate<USER extends User = User> {
104
104
  * If true, the UI will allow the user to create the default roles (admin, editor, viewer).
105
105
  */
106
106
  allowDefaultRolesCreation?: boolean;
107
- /**
108
- * Should collection config permissions be included?
109
- */
110
- includeCollectionConfigPermissions?: boolean;
111
107
  /**
112
108
  * Optionally define roles for a given user. This is useful when the roles
113
109
  * are coming from a separate provider than the one issuing the tokens.
114
110
  */
115
111
  defineRolesFor?: (user: USER) => Promise<Role[] | undefined> | Role[] | undefined;
112
+ /**
113
+ * Whether any admin users exist. Used by the bootstrap banner to decide
114
+ * whether to prompt. Populated via a lightweight check (e.g. `limit=1`
115
+ * query) instead of loading all users.
116
+ */
117
+ hasAdminUsers?: boolean;
116
118
  /**
117
119
  * Optional function to bootstrap an admin user.
118
120
  * Often used when the database is empty.
@@ -11,12 +11,4 @@ export type Role = {
11
11
  * If this flag is true, the user can perform any action
12
12
  */
13
13
  isAdmin?: boolean;
14
- /**
15
- * Permissions related to editing the collections
16
- */
17
- config?: {
18
- createCollections?: boolean;
19
- editCollections?: boolean | "own";
20
- deleteCollections?: boolean | "own";
21
- };
22
14
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/server-postgresql",
3
3
  "type": "module",
4
- "version": "0.2.3",
4
+ "version": "0.2.4",
5
5
  "description": "PostgreSQL data source backend implementation for Rebase with Drizzle ORM",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -68,11 +68,11 @@
68
68
  "hono": "^4.12.21",
69
69
  "pg": "^8.21.0",
70
70
  "ws": "^8.20.1",
71
- "@rebasepro/common": "0.2.3",
72
- "@rebasepro/server-core": "0.2.3",
73
- "@rebasepro/types": "0.2.3",
74
- "@rebasepro/utils": "0.2.3",
75
- "@rebasepro/sdk-generator": "0.2.3"
71
+ "@rebasepro/common": "0.2.4",
72
+ "@rebasepro/sdk-generator": "0.2.4",
73
+ "@rebasepro/types": "0.2.4",
74
+ "@rebasepro/server-core": "0.2.4",
75
+ "@rebasepro/utils": "0.2.4"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/jest": "^29.5.14",
@@ -145,7 +145,8 @@ propertyCallbacks: undefined };
145
145
  startAfter,
146
146
  orderBy,
147
147
  searchString,
148
- order
148
+ order,
149
+ vectorSearch
149
150
  }: FetchCollectionProps<M>): Promise<Entity<M>[]> {
150
151
 
151
152
  const entities = await this.entityService.fetchCollection<M>(path, {
@@ -156,7 +157,8 @@ propertyCallbacks: undefined };
156
157
  offset,
157
158
  startAfter: startAfter as Record<string, unknown> | undefined,
158
159
  databaseId: collection?.databaseId,
159
- searchString
160
+ searchString,
161
+ vectorSearch
160
162
  });
161
163
 
162
164
  const { collection: resolvedCollection, callbacks, propertyCallbacks } = this.resolveCollectionCallbacks(collection, path);
@@ -25,7 +25,8 @@ import {
25
25
  createAuthRoutes,
26
26
  createAdminRoutes,
27
27
  requireAuth,
28
- requireAdmin
28
+ requireAdmin,
29
+ logger
29
30
  // @ts-ignore
30
31
  } from "@rebasepro/server-core";
31
32
  import { ensureAuthTablesExist } from "./auth/ensure-tables";
@@ -50,6 +51,7 @@ import type { HonoEnv } from "@rebasepro/server-core";
50
51
  */
51
52
  export interface PostgresDriverInternals {
52
53
  db: NodePgDatabase<any>;
54
+ readDb?: NodePgDatabase<any>;
53
55
  registry: PostgresCollectionRegistry;
54
56
  realtimeService: RealtimeService;
55
57
  driver: PostgresBackendDriver;
@@ -83,7 +85,7 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
83
85
  const registry = new PostgresCollectionRegistry();
84
86
  if (collections) {
85
87
  registry.registerMultiple(collections);
86
- console.log(`📋 [PostgresRegistry] Registered ${registry.getCollections().length} collections: [${registry.getCollections().map(c => c.slug).join(", ")}]`);
88
+ logger.info(`📋 [PostgresRegistry] Registered ${registry.getCollections().length} collections: [${registry.getCollections().map(c => c.slug).join(", ")}]`);
87
89
  }
88
90
 
89
91
  // Register tables
@@ -114,12 +116,26 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
114
116
  try {
115
117
  await schemaAwareDb.execute(sql`SELECT 1`);
116
118
  } catch (err) {
117
- console.error("❌ Failed to connect to PostgreSQL:", err);
118
- console.warn("⚠️ Continuing without initial database verification. Drizzle/PG will attempt to connect on subsequent queries.");
119
+ logger.error("❌ Failed to connect to PostgreSQL", { error: err });
120
+ logger.warn("⚠️ Continuing without initial database verification. Drizzle/PG will attempt to connect on subsequent queries.");
119
121
  }
120
122
 
121
123
  // Create services
122
124
  const realtimeService = new RealtimeService(schemaAwareDb, registry);
125
+
126
+ // Initialize read replica connection if configured
127
+ let readDb: import("drizzle-orm/node-postgres").NodePgDatabase<any> | undefined;
128
+ const readUrl = process.env.DATABASE_READ_URL;
129
+ if (readUrl && readUrl !== pgConfig.connectionString) {
130
+ try {
131
+ const { createReadReplicaConnection } = await import("./connection");
132
+ const readResources = createReadReplicaConnection(readUrl, mergedSchema);
133
+ readDb = readResources.db;
134
+ logger.info("📖 [PostgresBootstrapper] Read replica connection established");
135
+ } catch (err) {
136
+ logger.warn("⚠️ Could not connect to read replica, falling back to primary for all queries", { error: err });
137
+ }
138
+ }
123
139
  const poolManager = pgConfig.adminConnectionString
124
140
  ? new DatabasePoolManager(pgConfig.adminConnectionString)
125
141
  : undefined;
@@ -131,21 +147,24 @@ export function createPostgresBootstrapper(pgConfig: PostgresDriverConfig): Back
131
147
  try {
132
148
  await driver.branchService.ensureBranchMetadataTable();
133
149
  } catch (err) {
134
- console.warn("⚠️ Could not initialize branch metadata table:", err);
150
+ logger.warn("⚠️ Could not initialize branch metadata table", { error: err });
135
151
  }
136
152
  }
137
153
 
138
154
  // Enable cross-instance realtime (opt-in)
139
- if (pgConfig.connectionString) {
155
+ // Prefer DATABASE_DIRECT_URL to bypass PgBouncer for LISTEN/NOTIFY
156
+ const directUrl = process.env.DATABASE_DIRECT_URL || pgConfig.connectionString;
157
+ if (directUrl) {
140
158
  try {
141
- await realtimeService.startListening(pgConfig.connectionString);
159
+ await realtimeService.startListening(directUrl);
142
160
  } catch (err) {
143
- console.warn("⚠️ Cross-instance realtime could not be started:", err);
161
+ logger.warn("⚠️ Cross-instance realtime could not be started", { error: err });
144
162
  }
145
163
  }
146
164
 
147
165
  const internals: PostgresDriverInternals = {
148
166
  db: schemaAwareDb,
167
+ readDb,
149
168
  registry,
150
169
  realtimeService,
151
170
  driver,