@rebasepro/client-postgresql 0.0.1-canary.f81da60 → 0.1.0

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.
@@ -50,7 +50,12 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
50
50
  accessToken: string;
51
51
  refreshToken: string;
52
52
  }>;
53
- signInWithGoogle: (idToken: string) => Promise<{
53
+ signInWithGoogle: (tokenOrPayload: string | {
54
+ idToken?: string;
55
+ accessToken?: string;
56
+ code?: string;
57
+ redirectUri?: string;
58
+ }) => Promise<{
54
59
  user: RebaseUser;
55
60
  accessToken: string;
56
61
  refreshToken: string;
@@ -0,0 +1,49 @@
1
+ import type { Transport } from "./transport";
2
+ /**
3
+ * Client interface for invoking custom backend functions.
4
+ *
5
+ * Custom functions are Hono route files auto-mounted by the Rebase backend
6
+ * at `/api/functions/{name}`. The `FunctionsClient` wraps the shared
7
+ * transport so callers never need to manually construct URLs or inject
8
+ * auth tokens.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const result = await client.functions.invoke<{ job: Job }>('extract-job', {
13
+ * url: 'https://example.com/posting',
14
+ * html: htmlContent,
15
+ * });
16
+ * ```
17
+ */
18
+ export interface FunctionsClient {
19
+ /**
20
+ * Invoke a custom backend function by name.
21
+ *
22
+ * @typeParam T - Expected shape of the response payload.
23
+ * @param name - Function name (the filename without extension, e.g. `"extract-job"`).
24
+ * @param payload - Optional JSON-serialisable body sent as `POST`.
25
+ * @param options - Optional overrides (HTTP method, sub-path, extra headers).
26
+ * @returns The parsed JSON response from the function.
27
+ */
28
+ invoke<T = unknown>(name: string, payload?: unknown, options?: FunctionInvokeOptions): Promise<T>;
29
+ }
30
+ export interface FunctionInvokeOptions {
31
+ /** HTTP method — defaults to `"POST"`. */
32
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
33
+ /** Sub-path appended after the function name, e.g. `"status/123"`. */
34
+ path?: string;
35
+ /** Extra headers merged into the request (auth is still injected automatically). */
36
+ headers?: Record<string, string>;
37
+ }
38
+ /**
39
+ * Create a `FunctionsClient` backed by the given transport.
40
+ *
41
+ * The transport already handles:
42
+ * - Base URL resolution
43
+ * - JWT injection via `Authorization: Bearer`
44
+ * - 401 retry / `onUnauthorized` flow
45
+ * - Consistent error throwing via `RebaseApiError`
46
+ *
47
+ * @internal
48
+ */
49
+ export declare function createFunctionsClient(transport: Transport): FunctionsClient;
@@ -3,6 +3,7 @@ import { createAuth, CreateAuthOptions } from "./auth";
3
3
  import { createAdmin, CreateAdminOptions } from "./admin";
4
4
  import { createCron, CreateCronOptions } from "./cron";
5
5
  import { CollectionClient } from "./collection";
6
+ import type { FunctionsClient } from "./functions";
6
7
  export * from "./transport";
7
8
  export * from "./auth";
8
9
  export * from "./admin";
@@ -11,6 +12,7 @@ export * from "./collection";
11
12
  export * from "./websocket";
12
13
  export * from "./storage";
13
14
  export * from "./reviver";
15
+ export * from "./functions";
14
16
  export interface CreateRebaseClientOptions extends RebaseClientConfig {
15
17
  auth?: CreateAuthOptions;
16
18
  admin?: CreateAdminOptions;
@@ -26,6 +28,7 @@ export type RebaseClient<DB = Record<string, unknown>> = BaseRebaseClient<DB> &
26
28
  auth: ReturnType<typeof createAuth>;
27
29
  admin: ReturnType<typeof createAdmin>;
28
30
  cron: ReturnType<typeof createCron>;
31
+ functions: FunctionsClient;
29
32
  ws?: RebaseWebSocketClient;
30
33
  storage?: StorageSource;
31
34
  call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
@@ -80,8 +80,14 @@ export type AuthController<USER extends User = User, ExtraData = unknown> = {
80
80
  export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
81
81
  /** Login with email and password */
82
82
  emailPasswordLogin?(email: string, password: string): Promise<void>;
83
- /** Login with a Google token (ID token or access token from popup) */
84
- googleLogin?(token: string, tokenType?: "idToken" | "accessToken"): Promise<void>;
83
+ /** Login with a Google token or authorization code */
84
+ googleLogin?: {
85
+ (token: string, tokenType?: "idToken" | "accessToken"): Promise<void>;
86
+ (payload: {
87
+ code: string;
88
+ redirectUri: string;
89
+ }): Promise<void>;
90
+ };
85
91
  /** Register a new user */
86
92
  register?(email: string, password: string, displayName?: string): Promise<void>;
87
93
  /** Skip login (for anonymous access if enabled) */
@@ -167,4 +167,17 @@ export interface RebaseClient<DB = unknown> {
167
167
  email?: EmailService;
168
168
  /** Admin API for user and role management */
169
169
  admin?: AdminAPI;
170
+ /**
171
+ * The base HTTP URL of the backend server.
172
+ * Exposed by the SDK client (`@rebasepro/client`) and used to auto-derive
173
+ * the `ApiConfigProvider` URL.
174
+ */
175
+ baseUrl?: string;
176
+ /**
177
+ * WebSocket client for realtime subscriptions and admin capabilities.
178
+ * Exposed by the SDK client (`@rebasepro/client`). The shape is intentionally
179
+ * left as `unknown` in the base interface — callers should narrow via feature
180
+ * detection (e.g. `typeof ws.executeSql === "function"`).
181
+ */
182
+ ws?: unknown;
170
183
  }
@@ -144,17 +144,18 @@ export interface AppView {
144
144
  * It will still be accessible if you reach the specified path
145
145
  */
146
146
  hideFromNavigation?: boolean;
147
+ /**
148
+ * Navigation group for this view.
149
+ * Views sharing the same group name will be visually grouped
150
+ * together in the drawer and home page. If not set, the view
151
+ * falls into the default "Views" group.
152
+ */
153
+ group?: string;
147
154
  /**
148
155
  * Component to be rendered. This can be any React component, and can use
149
156
  * any of the provided hooks
150
157
  */
151
158
  view: React.ReactNode;
152
- /**
153
- * Optional field used to group top level navigation entries under a
154
- * navigation view.
155
- * This prop is ignored for admin views.
156
- */
157
- group?: string;
158
159
  /**
159
160
  * If true, a wildcard route (slug/*) is automatically registered
160
161
  * alongside the base route, enabling nested navigation within this view.
@@ -193,6 +194,17 @@ export interface NavigationGroupMapping {
193
194
  * List of collection ids or view paths that belong to this group.
194
195
  */
195
196
  entries: string[];
197
+ /**
198
+ * Configure which groups start collapsed.
199
+ * Set to `true` to collapse in both drawer and home page,
200
+ * or use an object to control each independently.
201
+ *
202
+ * @defaultValue false (expanded)
203
+ */
204
+ collapsedByDefault?: boolean | {
205
+ drawer?: boolean;
206
+ home?: boolean;
207
+ };
196
208
  }
197
209
  export interface NavigationEntry {
198
210
  id: string;
@@ -3,7 +3,7 @@ import type { EntityCollection } from "../types/collections";
3
3
  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
- import type { AppView } from "./navigation";
6
+ import type { AppView, NavigationGroupMapping } from "./navigation";
7
7
  /**
8
8
  * Options to enable the built-in collection editor.
9
9
  * When provided to `<RebaseCMS>`, the editor is auto-wired as a native feature.
@@ -25,6 +25,14 @@ export interface RebaseCMSConfig<EC extends EntityCollection = any> {
25
25
  entityViews?: EntityCustomView<any>[];
26
26
  entityActions?: EntityAction[];
27
27
  plugins?: any[];
28
+ /**
29
+ * Centralized configuration for how collections and views are grouped
30
+ * in the navigation sidebar and home page.
31
+ * Each mapping defines a named group and the collection/view slugs
32
+ * that belong to it. The array order determines group display order.
33
+ * Entry order within each group determines card order.
34
+ */
35
+ navigationGroupMappings?: NavigationGroupMapping[];
28
36
  /**
29
37
  * Enable the built-in visual collection/schema editor.
30
38
  * Pass `true` for zero-config, or an options object for fine-grained control.
@@ -62,6 +62,13 @@ export interface EntitySidePanelProps<M extends Record<string, unknown> = Record
62
62
  * Allow the user to open the entity fullscreen
63
63
  */
64
64
  allowFullScreen?: boolean;
65
+ /**
66
+ * Pre-populate the form with these values when creating a new entity.
67
+ * Only applied when `entityId` is not set (i.e. the form is in "new" mode).
68
+ * Useful for actions that fetch data from an external source (e.g. a URL)
69
+ * and want to pre-fill the document before the user saves.
70
+ */
71
+ defaultValues?: Partial<M>;
65
72
  }
66
73
  /**
67
74
  * Controller to open the side dialog displaying entity forms
@@ -3,6 +3,7 @@ import type { AuthController } from "./controllers/auth";
3
3
  import type { StorageSource } from "./controllers/storage";
4
4
  import type { UserConfigurationPersistence } from "./controllers/local_config_persistence";
5
5
  import type { DatabaseAdmin } from "./types/backend";
6
+ import type { RebaseClient } from "./controllers/client";
6
7
  import type { RebaseData } from "./controllers/data";
7
8
  import type { User } from "./users";
8
9
  import type { UserManagementDelegate } from "./types/user_management_delegate";
@@ -12,6 +13,22 @@ import type { UserManagementDelegate } from "./types/user_management_delegate";
12
13
  * @group Hooks and utilities
13
14
  */
14
15
  export type RebaseCallContext<USER extends User = User> = {
16
+ /**
17
+ * The Rebase client instance.
18
+ * Available in all entity callbacks (beforeSave, afterSave, afterRead,
19
+ * beforeDelete, afterDelete) and in CollectionActionsProps via context.
20
+ * Use it to call backend functions, access data, storage, etc.
21
+ *
22
+ * @example
23
+ * // In a beforeSave callback:
24
+ * const result = await context.client.functions.invoke('my-function', { ... });
25
+ *
26
+ * @example
27
+ * // In a CollectionAction component:
28
+ * const { client } = props.context;
29
+ * const result = await client.functions.invoke('extract-job', { url });
30
+ */
31
+ client: RebaseClient<any>;
15
32
  /**
16
33
  * Unified data access — `context.data.products.create(...)`.
17
34
  * Access any collection as a dynamic property.
@@ -9,6 +9,7 @@ import type { RebaseContext } from "../rebase_context";
9
9
  import type { Relation } from "./relations";
10
10
  import type { EntityCustomView } from "./entity_views";
11
11
  import type { EntityAction } from "./entity_actions";
12
+ import type { ComponentRef } from "./component_ref";
12
13
  /**
13
14
  * Base interface containing all driver-agnostic collection properties.
14
15
  * Use {@link PostgresCollection} or {@link FirebaseCollection} for
@@ -86,6 +87,9 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
86
87
  icon?: string | React.ReactNode;
87
88
  /**
88
89
  * Navigation group for this collection.
90
+ * Collections sharing the same group name will be visually grouped
91
+ * together in the drawer and home page. If not set, the collection
92
+ * falls into the default "Views" group.
89
93
  */
90
94
  group?: string;
91
95
  /**
@@ -301,7 +305,7 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
301
305
  /**
302
306
  * Builder for the collection actions rendered in the toolbar
303
307
  */
304
- Actions?: React.ComponentType<any>[];
308
+ Actions?: ComponentRef<CollectionActionsProps>[];
305
309
  }
306
310
  /**
307
311
  * A collection backed by PostgreSQL (or any SQL database).
@@ -482,6 +486,21 @@ export interface CollectionActionsProps<M extends Record<string, unknown> = Reco
482
486
  * undefined means the count is still loading.
483
487
  */
484
488
  collectionEntitiesCount?: number;
489
+ /**
490
+ * Programmatically open the new-document form for this collection,
491
+ * optionally pre-populating it with initial field values.
492
+ * The form opens in the same mode configured for the collection
493
+ * (side panel, full screen, or split).
494
+ *
495
+ * This is the primary hook for workflows that need to create a document
496
+ * from external data — e.g. fetching content from a URL, importing from
497
+ * a third-party API, or duplicating from another system.
498
+ *
499
+ * @example
500
+ * // Inside a custom CollectionAction component:
501
+ * openNewDocument({ title: "Fetched title", body: "..." });
502
+ */
503
+ openNewDocument: (defaultValues?: Record<string, unknown>) => void;
485
504
  }
486
505
  /**
487
506
  * Use this controller to retrieve the selected entities or modify them in
@@ -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>;
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import type { Entity, EntityValues } from "./entities";
3
3
  import type { EntityCollection } from "./collections";
4
4
  import type { FormexController } from "./formex";
5
+ import type { ComponentRef } from "./component_ref";
5
6
  /**
6
7
  * Context passed to custom fields and entity views.
7
8
  * @group Form custom fields
@@ -46,7 +47,7 @@ export type EntityCustomView<M extends Record<string, unknown> = Record<string,
46
47
  name: string;
47
48
  tabComponent?: React.ReactNode;
48
49
  includeActions?: boolean | "bottom";
49
- Builder?: React.ComponentType<EntityCustomViewParams<M>>;
50
+ Builder?: ComponentRef<EntityCustomViewParams<M>>;
50
51
  position?: "start" | "end";
51
52
  };
52
53
  export interface EntityCustomViewParams<M extends Record<string, unknown> = Record<string, unknown>> {
@@ -23,3 +23,4 @@ export * from "./entity_views";
23
23
  export * from "./data_source";
24
24
  export * from "./cron";
25
25
  export * from "./backend_hooks";
26
+ export * from "./component_ref";
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import type { ComponentRef } from "./component_ref";
2
2
  import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity } from "./entities";
3
3
  import type { Relation, JoinStep, OnAction } from "./relations";
4
4
  import type { EntityCollection, FilterValues } from "./collections";
@@ -104,8 +104,8 @@ export interface BaseUIConfig<CustomProps = unknown> {
104
104
  disabled?: boolean | PropertyDisabledConfig;
105
105
  widthPercentage?: number;
106
106
  customProps?: CustomProps;
107
- Field?: React.ComponentType<any>;
108
- Preview?: React.ComponentType<any>;
107
+ Field?: ComponentRef<any>;
108
+ Preview?: ComponentRef<any>;
109
109
  }
110
110
  export interface BaseProperty<CustomProps = unknown> {
111
111
  ui?: BaseUIConfig<CustomProps>;
@@ -124,6 +124,18 @@ export interface BaseProperty<CustomProps = unknown> {
124
124
  * overwritten by the current property config.
125
125
  */
126
126
  propertyConfig?: string;
127
+ /**
128
+ * Explicit database column name. When set, this value is used as-is
129
+ * for the SQL column name, bypassing any snake_case conversion of
130
+ * the property key.
131
+ *
132
+ * This is automatically populated by `rebase schema introspect`
133
+ * to guarantee an exact match with the live database schema.
134
+ *
135
+ * For manually-authored collections you can omit this — the framework
136
+ * will derive the column name from the property key via `toSnakeCase()`.
137
+ */
138
+ columnName?: string;
127
139
  /**
128
140
  * Rules for validating this property
129
141
  */
@@ -51,6 +51,8 @@ export interface RebaseTranslations {
51
51
  all_entries_loaded: string;
52
52
  create_your_first_entry: string;
53
53
  no_results_filter_sort: string;
54
+ /** Shown when a text search yields no results. Supports `{{search}}` interpolation. */
55
+ no_results_search?: string;
54
56
  add: string;
55
57
  remove: string;
56
58
  copy_id: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/client-postgresql",
3
3
  "type": "module",
4
- "version": "0.0.1-canary.f81da60",
4
+ "version": "0.1.0",
5
5
  "description": "PostgreSQL data source client for Rebase",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -57,8 +57,8 @@
57
57
  "./package.json": "./package.json"
58
58
  },
59
59
  "dependencies": {
60
- "@rebasepro/client": "0.0.1-canary.f81da60",
61
- "@rebasepro/types": "0.0.1-canary.f81da60"
60
+ "@rebasepro/types": "0.1.0",
61
+ "@rebasepro/client": "0.1.0"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "react": ">=19.0.0",