@rebasepro/types 0.5.0 → 0.6.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.
@@ -1,6 +1,8 @@
1
1
  import type { User } from "../users";
2
2
  import type { RebaseData } from "./data";
3
3
  import type { EmailService } from "./email";
4
+ import type { StorageSource } from "./storage";
5
+ import type { CronJobStatus, CronJobLogEntry } from "../types/cron";
4
6
  /**
5
7
  * Event type for authentication state changes
6
8
  */
@@ -14,7 +16,6 @@ export interface RebaseSession {
14
16
  expiresAt: number;
15
17
  user: User;
16
18
  }
17
- import type { StorageSource } from "./storage";
18
19
  /**
19
20
  * Unified Authentication Client Interface
20
21
  * Pure functional SDK interface, decoupled from UI and React hooks
@@ -111,8 +112,65 @@ export interface AdminAPI {
111
112
  }>;
112
113
  }
113
114
  /**
114
- * Overarching abstraction that unites Data, Auth, Storage, and Email.
115
- * Adapters for Supabase or Firebase simply need to implement this interface.
115
+ * Client-side Cron job management interface.
116
+ * @group Cron
117
+ */
118
+ export interface CronAPI {
119
+ listJobs(): Promise<{
120
+ jobs: CronJobStatus[];
121
+ }>;
122
+ getJob(jobId: string): Promise<{
123
+ job: CronJobStatus;
124
+ }>;
125
+ triggerJob(jobId: string): Promise<{
126
+ log: CronJobLogEntry;
127
+ job: CronJobStatus;
128
+ }>;
129
+ getJobLogs(jobId: string, options?: {
130
+ limit?: number;
131
+ }): Promise<{
132
+ logs: CronJobLogEntry[];
133
+ }>;
134
+ toggleJob(jobId: string, enabled: boolean): Promise<{
135
+ job: CronJobStatus;
136
+ }>;
137
+ }
138
+ /**
139
+ * Options for invoking a custom backend function.
140
+ * @group Functions
141
+ */
142
+ export interface FunctionInvokeOptions {
143
+ /** HTTP method — defaults to `"POST"`. */
144
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
145
+ /** Sub-path appended after the function name. */
146
+ path?: string;
147
+ /** Extra headers merged into the request. */
148
+ headers?: Record<string, string>;
149
+ }
150
+ /**
151
+ * Client interface for invoking custom backend functions.
152
+ * @group Functions
153
+ */
154
+ export interface FunctionsAPI {
155
+ /**
156
+ * Invoke a custom backend function by name.
157
+ *
158
+ * @typeParam T - Expected shape of the response payload.
159
+ * @param name - Function name (filename without extension, e.g. `"extract-job"`).
160
+ * @param payload - Optional JSON-serialisable body sent as POST.
161
+ * @param options - Optional overrides (method, sub-path, headers).
162
+ */
163
+ invoke<T = unknown>(name: string, payload?: unknown, options?: FunctionInvokeOptions): Promise<T>;
164
+ }
165
+ /**
166
+ * The single, canonical Rebase client interface.
167
+ *
168
+ * Used everywhere: the server-side `rebase` singleton, the SDK's
169
+ * `createRebaseClient()`, React context, cron job context, etc.
170
+ *
171
+ * Core fields (`data`, `auth`) are always present. Everything else
172
+ * is optional — which capabilities are populated depends on the
173
+ * runtime environment and adapter.
116
174
  */
117
175
  export interface RebaseClient<DB = unknown> {
118
176
  /** Unified Data access layer */
@@ -123,43 +181,32 @@ export interface RebaseClient<DB = unknown> {
123
181
  storage?: StorageSource;
124
182
  /**
125
183
  * Server-side email service.
126
- *
127
- * Available when SMTP (or a custom `sendEmail` function) is configured
128
- * in the backend auth config. `undefined` when email is not configured.
129
- *
130
- * > **Note:** This is only available on the server-side `rebase` singleton.
131
- * > The client-side SDK does not include an email service.
184
+ * Available when SMTP or a custom `sendEmail` function is configured.
132
185
  */
133
186
  email?: EmailService;
134
187
  /** Admin API for user management */
135
188
  admin?: AdminAPI;
136
- /**
137
- * The base HTTP URL of the backend server.
138
- * Exposed by the SDK client (`@rebasepro/client`) and used to auto-derive
139
- * the `ApiConfigProvider` URL.
140
- */
189
+ /** Cron job management API */
190
+ cron?: CronAPI;
191
+ /** Custom backend functions API */
192
+ functions?: FunctionsAPI;
193
+ /** Base HTTP URL of the backend server */
141
194
  baseUrl?: string;
142
- /**
143
- * WebSocket client for realtime subscriptions and admin capabilities.
144
- * Exposed by the SDK client (`@rebasepro/client`). The shape is intentionally
145
- * left as `unknown` in the base interface — callers should narrow via feature
146
- * detection (e.g. `typeof ws.executeSql === "function"`).
147
- */
195
+ /** WebSocket client for realtime subscriptions */
148
196
  ws?: unknown;
197
+ /** Set the auth token for subsequent requests */
198
+ setToken?(token: string | null): void;
199
+ /** Set a function that lazily resolves the auth token */
200
+ setAuthTokenGetter?(getter: () => Promise<string | null>): void;
201
+ /** Set handler called when a request returns 401 */
202
+ setOnUnauthorized?(handler: () => Promise<boolean>): void;
203
+ /** Resolve the current auth token */
204
+ resolveToken?(): Promise<string | null>;
205
+ /** Make a raw HTTP call to the backend */
206
+ call?<T = unknown>(endpoint: string, payload?: unknown): Promise<T>;
149
207
  /**
150
208
  * Execute raw SQL against the database.
151
- *
152
- * Only available server-side when the backend uses a SQL database
153
- * (PostgreSQL, MySQL, etc.). `undefined` for document databases
154
- * (MongoDB, Firestore) and on the client-side SDK.
155
- *
156
- * @example
157
- * ```typescript
158
- * // In a cron job or custom function:
159
- * if (ctx.client.sql) {
160
- * const rows = await ctx.client.sql("SELECT count(*) FROM orders");
161
- * }
162
- * ```
209
+ * Only available server-side with a SQL database.
163
210
  */
164
211
  sql?(query: string, options?: {
165
212
  database?: string;
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import type { EntityLinkBuilder } from "../types/entity_link_builder";
3
2
  import type { Locale } from "../types/locales";
4
3
  import type { EntityAction } from "../types/entity_actions";
@@ -6,6 +5,7 @@ import type { EntityCustomView } from "../types/entity_views";
6
5
  import type { RebasePlugin } from "../types/plugins";
7
6
  import type { PropertyConfig } from "../types/property_config";
8
7
  import type { SlotContribution } from "../types/slots";
8
+ import type { ComponentOverrideMap } from "../types/component_overrides";
9
9
  export type CustomizationController = {
10
10
  /**
11
11
  * Builder for generating utility links for entities
@@ -49,12 +49,13 @@ export type CustomizationController = {
49
49
  * the `propertyConfig` prop of a property in a collection.
50
50
  */
51
51
  propertyConfigs: Record<string, PropertyConfig>;
52
- components?: {
53
- /**
54
- * Component to render when a reference is missing
55
- */
56
- missingReference?: React.ComponentType<{
57
- path: string;
58
- }>;
59
- };
52
+ /**
53
+ * Global component overrides. Keys are component names from
54
+ * {@link OverridableComponentName}. Values replace the default
55
+ * implementation everywhere in the app.
56
+ *
57
+ * Collection-scoped overrides (set on individual collections)
58
+ * take precedence over global overrides.
59
+ */
60
+ components?: ComponentOverrideMap;
60
61
  };
package/dist/index.es.js CHANGED
@@ -1,222 +1,274 @@
1
- class EntityReference {
2
- __type = "reference";
3
- /**
4
- * ID of the entity
5
- */
6
- id;
7
- /**
8
- * A string representing the path of the referenced document (relative
9
- * to the root of the database).
10
- */
11
- path;
12
- /**
13
- * Which driver (e.g., 'postgres', 'firestore').
14
- * Defaults to "(default)" if not specified.
15
- */
16
- driver;
17
- /**
18
- * Which database within the driver.
19
- * Defaults to "(default)" if not specified.
20
- */
21
- databaseId;
22
- /**
23
- * Create a reference to an entity.
24
- *
25
- * @example
26
- * // Simple reference (most common case)
27
- * new EntityReference({ id: "123", path: "users" })
28
- *
29
- * // With driver
30
- * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
31
- */
32
- constructor(props) {
33
- this.id = props.id;
34
- this.path = props.path;
35
- this.driver = props.driver;
36
- this.databaseId = props.databaseId;
37
- }
38
- get pathWithId() {
39
- return `${this.path}/${this.id}`;
40
- }
41
- /**
42
- * Get the full path including driver and database prefixes if specified.
43
- * For the common case (single driver, single db), this just returns pathWithId.
44
- */
45
- get fullPath() {
46
- const parts = [];
47
- if (this.driver && this.driver !== "(default)") {
48
- parts.push(this.driver);
49
- }
50
- if (this.databaseId && this.databaseId !== "(default)") {
51
- parts.push(this.databaseId);
52
- }
53
- if (parts.length > 0) {
54
- return `${parts.join(":")}:::${this.path}/${this.id}`;
55
- }
56
- return this.pathWithId;
57
- }
58
- isEntityReference() {
59
- return true;
60
- }
61
- }
62
- class EntityRelation {
63
- __type = "relation";
64
- /**
65
- * ID of the entity
66
- */
67
- id;
68
- /**
69
- * A string representing the path of the referenced document (relative
70
- * to the root of the database).
71
- */
72
- path;
73
- /**
74
- * Pre-fetched data payload to eliminate N+1 queries.
75
- * When present, clients can use this directly instead of fetching.
76
- */
77
- data;
78
- constructor(id, path, data) {
79
- this.id = id;
80
- this.path = path;
81
- this.data = data;
82
- }
83
- get pathWithId() {
84
- return `${this.path}/${this.id}`;
85
- }
86
- isEntityReference() {
87
- return false;
88
- }
89
- isEntityRelation() {
90
- return true;
91
- }
92
- }
93
- class GeoPoint {
94
- /**
95
- * The latitude of this GeoPoint instance.
96
- */
97
- latitude;
98
- /**
99
- * The longitude of this GeoPoint instance.
100
- */
101
- longitude;
102
- constructor(latitude, longitude) {
103
- this.latitude = latitude;
104
- this.longitude = longitude;
105
- }
106
- }
107
- class Vector {
108
- value;
109
- constructor(value) {
110
- this.value = value;
111
- }
112
- }
1
+ //#region src/types/entities.ts
2
+ /**
3
+ * Class used to create a reference to an entity in a different path.
4
+ *
5
+ * @example
6
+ * // Simple reference (most common case - single driver, single db)
7
+ * new EntityReference({ id: "123", path: "users" })
8
+ *
9
+ * // Reference to a different driver (e.g., Firestore)
10
+ * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
11
+ *
12
+ * // Reference to a specific database within a driver
13
+ * new EntityReference({ id: "123", path: "orders", driver: "postgres", databaseId: "orders_db" })
14
+ */
15
+ var EntityReference = class {
16
+ __type = "reference";
17
+ /**
18
+ * ID of the entity
19
+ */
20
+ id;
21
+ /**
22
+ * A string representing the path of the referenced document (relative
23
+ * to the root of the database).
24
+ */
25
+ path;
26
+ /**
27
+ * Which driver (e.g., 'postgres', 'firestore').
28
+ * Defaults to "(default)" if not specified.
29
+ */
30
+ driver;
31
+ /**
32
+ * Which database within the driver.
33
+ * Defaults to "(default)" if not specified.
34
+ */
35
+ databaseId;
36
+ /**
37
+ * Create a reference to an entity.
38
+ *
39
+ * @example
40
+ * // Simple reference (most common case)
41
+ * new EntityReference({ id: "123", path: "users" })
42
+ *
43
+ * // With driver
44
+ * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
45
+ */
46
+ constructor(props) {
47
+ this.id = props.id;
48
+ this.path = props.path;
49
+ this.driver = props.driver;
50
+ this.databaseId = props.databaseId;
51
+ }
52
+ get pathWithId() {
53
+ return `${this.path}/${this.id}`;
54
+ }
55
+ /**
56
+ * Get the full path including driver and database prefixes if specified.
57
+ * For the common case (single driver, single db), this just returns pathWithId.
58
+ */
59
+ get fullPath() {
60
+ const parts = [];
61
+ if (this.driver && this.driver !== "(default)") parts.push(this.driver);
62
+ if (this.databaseId && this.databaseId !== "(default)") parts.push(this.databaseId);
63
+ if (parts.length > 0) return `${parts.join(":")}:::${this.path}/${this.id}`;
64
+ return this.pathWithId;
65
+ }
66
+ isEntityReference() {
67
+ return true;
68
+ }
69
+ };
70
+ /**
71
+ * Class used to create a reference to an entity in a different path
72
+ */
73
+ var EntityRelation = class {
74
+ __type = "relation";
75
+ /**
76
+ * ID of the entity
77
+ */
78
+ id;
79
+ /**
80
+ * A string representing the path of the referenced document (relative
81
+ * to the root of the database).
82
+ */
83
+ path;
84
+ /**
85
+ * Pre-fetched data payload to eliminate N+1 queries.
86
+ * When present, clients can use this directly instead of fetching.
87
+ */
88
+ data;
89
+ constructor(id, path, data) {
90
+ this.id = id;
91
+ this.path = path;
92
+ this.data = data;
93
+ }
94
+ get pathWithId() {
95
+ return `${this.path}/${this.id}`;
96
+ }
97
+ isEntityReference() {
98
+ return false;
99
+ }
100
+ isEntityRelation() {
101
+ return true;
102
+ }
103
+ };
104
+ var GeoPoint = class {
105
+ /**
106
+ * The latitude of this GeoPoint instance.
107
+ */
108
+ latitude;
109
+ /**
110
+ * The longitude of this GeoPoint instance.
111
+ */
112
+ longitude;
113
+ constructor(latitude, longitude) {
114
+ this.latitude = latitude;
115
+ this.longitude = longitude;
116
+ }
117
+ };
118
+ var Vector = class {
119
+ value;
120
+ constructor(value) {
121
+ this.value = value;
122
+ }
123
+ };
124
+ //#endregion
125
+ //#region src/types/collections.ts
126
+ /**
127
+ * Type guard for PostgreSQL collections.
128
+ * Returns true if the collection uses the Postgres driver (or the default driver).
129
+ * @group Models
130
+ */
113
131
  function isPostgresCollection(collection) {
114
- return !collection.driver || collection.driver === "postgres";
132
+ return !collection.driver || collection.driver === "postgres";
115
133
  }
134
+ /**
135
+ * Type guard for Firebase / Firestore collections.
136
+ * @group Models
137
+ */
116
138
  function isFirebaseCollection(collection) {
117
- return collection.driver === "firestore";
139
+ return collection.driver === "firestore";
118
140
  }
141
+ /**
142
+ * Type guard for MongoDB collections.
143
+ * @group Models
144
+ */
119
145
  function isMongoDBCollection(collection) {
120
- return collection.driver === "mongodb";
146
+ return collection.driver === "mongodb";
121
147
  }
148
+ //#endregion
149
+ //#region src/types/backend.ts
150
+ /**
151
+ * Type guard: does this admin support SQL operations?
152
+ * @group Admin
153
+ */
122
154
  function isSQLAdmin(admin) {
123
- return !!admin && typeof admin.executeSql === "function";
155
+ return !!admin && typeof admin.executeSql === "function";
124
156
  }
157
+ /**
158
+ * Type guard: does this admin support document operations?
159
+ * @group Admin
160
+ */
125
161
  function isDocumentAdmin(admin) {
126
- return !!admin && (typeof admin.executeAggregate === "function" || typeof admin.fetchCollectionStats === "function");
162
+ return !!admin && (typeof admin.executeAggregate === "function" || typeof admin.fetchCollectionStats === "function");
127
163
  }
164
+ /**
165
+ * Type guard: does this admin support schema management?
166
+ * @group Admin
167
+ */
128
168
  function isSchemaAdmin(admin) {
129
- return !!admin && (typeof admin.fetchUnmappedTables === "function" || typeof admin.fetchTableMetadata === "function");
169
+ return !!admin && (typeof admin.fetchUnmappedTables === "function" || typeof admin.fetchTableMetadata === "function");
130
170
  }
171
+ /**
172
+ * Type guard: does this admin support database branching?
173
+ * @group Admin
174
+ */
131
175
  function isBranchAdmin(admin) {
132
- return !!admin && typeof admin.createBranch === "function";
176
+ return !!admin && typeof admin.createBranch === "function";
133
177
  }
134
- const POSTGRES_CAPABILITIES = {
135
- key: "postgres",
136
- label: "PostgreSQL",
137
- supportsRelations: true,
138
- supportsSubcollections: false,
139
- supportsRLS: true,
140
- supportsReferences: false,
141
- supportsColumnTypes: true,
142
- supportsRealtime: true,
143
- supportsSQLAdmin: true,
144
- supportsDocumentAdmin: false,
145
- supportsSchemaAdmin: true
178
+ //#endregion
179
+ //#region src/types/data_source.ts
180
+ /** @group Models */
181
+ var POSTGRES_CAPABILITIES = {
182
+ key: "postgres",
183
+ label: "PostgreSQL",
184
+ supportsRelations: true,
185
+ supportsSubcollections: false,
186
+ supportsRLS: true,
187
+ supportsReferences: false,
188
+ supportsColumnTypes: true,
189
+ supportsRealtime: true,
190
+ supportsSQLAdmin: true,
191
+ supportsDocumentAdmin: false,
192
+ supportsSchemaAdmin: true
146
193
  };
147
- const FIREBASE_CAPABILITIES = {
148
- key: "firestore",
149
- label: "Firebase / Firestore",
150
- supportsRelations: false,
151
- supportsSubcollections: true,
152
- supportsRLS: false,
153
- supportsReferences: true,
154
- supportsColumnTypes: false,
155
- supportsRealtime: true,
156
- supportsSQLAdmin: false,
157
- supportsDocumentAdmin: false,
158
- supportsSchemaAdmin: false
194
+ /** @group Models */
195
+ var FIREBASE_CAPABILITIES = {
196
+ key: "firestore",
197
+ label: "Firebase / Firestore",
198
+ supportsRelations: false,
199
+ supportsSubcollections: true,
200
+ supportsRLS: false,
201
+ supportsReferences: true,
202
+ supportsColumnTypes: false,
203
+ supportsRealtime: true,
204
+ supportsSQLAdmin: false,
205
+ supportsDocumentAdmin: false,
206
+ supportsSchemaAdmin: false
159
207
  };
160
- const MONGODB_CAPABILITIES = {
161
- key: "mongodb",
162
- label: "MongoDB",
163
- supportsRelations: false,
164
- supportsSubcollections: true,
165
- supportsRLS: false,
166
- supportsReferences: true,
167
- supportsColumnTypes: false,
168
- supportsRealtime: false,
169
- supportsSQLAdmin: false,
170
- supportsDocumentAdmin: true,
171
- supportsSchemaAdmin: true
208
+ /** @group Models */
209
+ var MONGODB_CAPABILITIES = {
210
+ key: "mongodb",
211
+ label: "MongoDB",
212
+ supportsRelations: false,
213
+ supportsSubcollections: true,
214
+ supportsRLS: false,
215
+ supportsReferences: true,
216
+ supportsColumnTypes: false,
217
+ supportsRealtime: false,
218
+ supportsSQLAdmin: false,
219
+ supportsDocumentAdmin: true,
220
+ supportsSchemaAdmin: true
172
221
  };
173
- const DEFAULT_CAPABILITIES = {
174
- key: "(default)",
175
- label: "Default",
176
- supportsRelations: true,
177
- supportsSubcollections: true,
178
- supportsRLS: true,
179
- supportsReferences: true,
180
- supportsColumnTypes: true,
181
- supportsRealtime: true,
182
- supportsSQLAdmin: true,
183
- supportsDocumentAdmin: true,
184
- supportsSchemaAdmin: true
222
+ /**
223
+ * Fallback capabilities when the driver is unknown.
224
+ * Enables everything so nothing is hidden unexpectedly.
225
+ * @group Models
226
+ */
227
+ var DEFAULT_CAPABILITIES = {
228
+ key: "(default)",
229
+ label: "Default",
230
+ supportsRelations: true,
231
+ supportsSubcollections: true,
232
+ supportsRLS: true,
233
+ supportsReferences: true,
234
+ supportsColumnTypes: true,
235
+ supportsRealtime: true,
236
+ supportsSQLAdmin: true,
237
+ supportsDocumentAdmin: true,
238
+ supportsSchemaAdmin: true
185
239
  };
186
- const CAPABILITIES_REGISTRY = {
187
- postgres: POSTGRES_CAPABILITIES,
188
- firestore: FIREBASE_CAPABILITIES,
189
- mongodb: MONGODB_CAPABILITIES,
190
- "(default)": DEFAULT_CAPABILITIES
240
+ var CAPABILITIES_REGISTRY = {
241
+ postgres: POSTGRES_CAPABILITIES,
242
+ firestore: FIREBASE_CAPABILITIES,
243
+ mongodb: MONGODB_CAPABILITIES,
244
+ "(default)": DEFAULT_CAPABILITIES
191
245
  };
246
+ /**
247
+ * Look up capabilities for a given driver key.
248
+ * If `driver` is undefined or not found, returns `DEFAULT_CAPABILITIES`.
249
+ * @group Models
250
+ */
192
251
  function getDataSourceCapabilities(driver) {
193
- if (!driver) return POSTGRES_CAPABILITIES;
194
- return CAPABILITIES_REGISTRY[driver] ?? DEFAULT_CAPABILITIES;
252
+ if (!driver) return POSTGRES_CAPABILITIES;
253
+ return CAPABILITIES_REGISTRY[driver] ?? DEFAULT_CAPABILITIES;
195
254
  }
255
+ /**
256
+ * Register custom capabilities for a third-party driver.
257
+ * @group Models
258
+ */
196
259
  function registerDataSourceCapabilities(capabilities) {
197
- CAPABILITIES_REGISTRY[capabilities.key] = capabilities;
260
+ CAPABILITIES_REGISTRY[capabilities.key] = capabilities;
198
261
  }
262
+ //#endregion
263
+ //#region src/types/component_ref.ts
264
+ /**
265
+ * Type guard: checks if a value is a `LazyComponentRef` produced by the
266
+ * Vite transform plugin.
267
+ */
199
268
  function isLazyComponentRef(ref) {
200
- return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
269
+ return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
201
270
  }
202
- export {
203
- DEFAULT_CAPABILITIES,
204
- EntityReference,
205
- EntityRelation,
206
- FIREBASE_CAPABILITIES,
207
- GeoPoint,
208
- MONGODB_CAPABILITIES,
209
- POSTGRES_CAPABILITIES,
210
- Vector,
211
- getDataSourceCapabilities,
212
- isBranchAdmin,
213
- isDocumentAdmin,
214
- isFirebaseCollection,
215
- isLazyComponentRef,
216
- isMongoDBCollection,
217
- isPostgresCollection,
218
- isSQLAdmin,
219
- isSchemaAdmin,
220
- registerDataSourceCapabilities
221
- };
222
- //# sourceMappingURL=index.es.js.map
271
+ //#endregion
272
+ export { DEFAULT_CAPABILITIES, EntityReference, EntityRelation, FIREBASE_CAPABILITIES, GeoPoint, MONGODB_CAPABILITIES, POSTGRES_CAPABILITIES, Vector, getDataSourceCapabilities, isBranchAdmin, isDocumentAdmin, isFirebaseCollection, isLazyComponentRef, isMongoDBCollection, isPostgresCollection, isSQLAdmin, isSchemaAdmin, registerDataSourceCapabilities };
273
+
274
+ //# sourceMappingURL=index.es.js.map