@rebasepro/sdk-generator 0.2.4 → 0.2.5

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,12 +1,9 @@
1
- import { PostgresCollection } from "@rebasepro/types";
1
+ import type { PostgresCollection } from "@rebasepro/types";
2
2
  /**
3
- * Default users collection definition.
3
+ * Default users collection.
4
4
  *
5
- * Shared between the admin UI (for navigation/display) and the backend
6
- * (for schema generation). Both consumers prepend this to the developer's
7
- * collections array and rely on generic slug-based deduplication
8
- * (Map keyed by slug, last-write-wins) so that developer-defined
9
- * collections with the same slug override this default — no hardcoded
10
- * string checks required.
5
+ * Prepended to the developer's collections array by the admin and server.
6
+ * Slug-based dedup (Map keyed by slug, last-write-wins) lets developers
7
+ * override by defining their own collection with `slug: "users"`.
11
8
  */
12
9
  export declare const defaultUsersCollection: PostgresCollection;
@@ -1,4 +1,4 @@
1
- import { Role, User } from "../users";
1
+ import type { User } from "../users";
2
2
  /**
3
3
  * Capabilities advertised by an auth provider.
4
4
  * UI components use this to show/hide features dynamically
@@ -62,7 +62,7 @@ export type AuthController<USER extends User = User, ExtraData = unknown> = {
62
62
  extra: ExtraData;
63
63
  setExtra: (extra: ExtraData) => void;
64
64
  setUser?(user: USER | null): void;
65
- setUserRoles?(roles: Role[]): void;
65
+ setUserRoles?(roles: string[]): void;
66
66
  /**
67
67
  * Capabilities advertised by the auth provider.
68
68
  * UI components use this to feature-detect what the backend supports.
@@ -1,6 +1,6 @@
1
- import { User } from "../users";
2
- import { RebaseData } from "./data";
3
- import { EmailService } from "./email";
1
+ import type { User } from "../users";
2
+ import type { RebaseData } from "./data";
3
+ import type { EmailService } from "./email";
4
4
  /**
5
5
  * Event type for authentication state changes
6
6
  */
@@ -14,7 +14,7 @@ export interface RebaseSession {
14
14
  expiresAt: number;
15
15
  user: User;
16
16
  }
17
- import { StorageSource } from "./storage";
17
+ import type { StorageSource } from "./storage";
18
18
  /**
19
19
  * Unified Authentication Client Interface
20
20
  * Pure functional SDK interface, decoupled from UI and React hooks
@@ -56,19 +56,9 @@ export interface AdminUser {
56
56
  createdAt: string;
57
57
  updatedAt: string;
58
58
  }
59
- /**
60
- * Role record as returned by the Admin API.
61
- * @group Admin
62
- */
63
- export interface AdminRole {
64
- id: string;
65
- name: string;
66
- isAdmin: boolean;
67
- defaultPermissions: Record<string, unknown> | null;
68
- }
69
59
  /**
70
60
  * Client-side Admin API interface.
71
- * Provides user and role management operations.
61
+ * Provides user management operations.
72
62
  * @group Admin
73
63
  */
74
64
  export interface AdminAPI {
@@ -111,30 +101,6 @@ export interface AdminAPI {
111
101
  deleteUser(userId: string): Promise<{
112
102
  success: boolean;
113
103
  }>;
114
- listRoles(): Promise<{
115
- roles: AdminRole[];
116
- }>;
117
- getRole(roleId: string): Promise<{
118
- role: AdminRole;
119
- }>;
120
- createRole(data: {
121
- id: string;
122
- name: string;
123
- isAdmin?: boolean;
124
- defaultPermissions?: Record<string, unknown>;
125
- }): Promise<{
126
- role: AdminRole;
127
- }>;
128
- updateRole(roleId: string, data: {
129
- name?: string;
130
- isAdmin?: boolean;
131
- defaultPermissions?: Record<string, unknown>;
132
- }): Promise<{
133
- role: AdminRole;
134
- }>;
135
- deleteRole(roleId: string): Promise<{
136
- success: boolean;
137
- }>;
138
104
  bootstrap(): Promise<{
139
105
  success: boolean;
140
106
  message: string;
@@ -165,7 +131,7 @@ export interface RebaseClient<DB = unknown> {
165
131
  * > The client-side SDK does not include an email service.
166
132
  */
167
133
  email?: EmailService;
168
- /** Admin API for user and role management */
134
+ /** Admin API for user management */
169
135
  admin?: AdminAPI;
170
136
  /**
171
137
  * The base HTTP URL of the backend server.
@@ -180,4 +146,23 @@ export interface RebaseClient<DB = unknown> {
180
146
  * detection (e.g. `typeof ws.executeSql === "function"`).
181
147
  */
182
148
  ws?: unknown;
149
+ /**
150
+ * 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
+ * ```
163
+ */
164
+ sql?(query: string, options?: {
165
+ database?: string;
166
+ role?: string;
167
+ }): Promise<Record<string, unknown>[]>;
183
168
  }
@@ -125,6 +125,10 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
125
125
  * Delete a record by ID.
126
126
  */
127
127
  delete(id: string | number): Promise<void>;
128
+ /**
129
+ * Delete all records in this collection.
130
+ */
131
+ deleteAll?(): Promise<void>;
128
132
  /**
129
133
  * Subscribe to a collection for real-time updates.
130
134
  * Optional method, may not be supported by all implementations (like stateless HTTP clients).
@@ -129,6 +129,11 @@ export interface DataDriver {
129
129
  * @return was the whole deletion flow successful
130
130
  */
131
131
  deleteEntity<M extends Record<string, unknown> = Record<string, unknown>>(props: DeleteEntityProps<M>): Promise<void>;
132
+ /**
133
+ * Delete all entities from a collection.
134
+ * @param path Collection path
135
+ */
136
+ deleteAll?(path: string): Promise<void>;
132
137
  /**
133
138
  * Check if the given property is unique in the given collection
134
139
  * @param path Collection path
@@ -148,38 +148,6 @@ export interface AuthCreateUserData {
148
148
  photoUrl?: string;
149
149
  metadata?: Record<string, unknown>;
150
150
  }
151
- /**
152
- * Role data exposed by the auth adapter.
153
- * @group Auth
154
- */
155
- export interface AuthRoleData {
156
- id: string;
157
- name: string;
158
- isAdmin: boolean;
159
- defaultPermissions?: {
160
- read?: boolean;
161
- create?: boolean;
162
- edit?: boolean;
163
- delete?: boolean;
164
- } | null;
165
- collectionPermissions?: Record<string, {
166
- read?: boolean;
167
- create?: boolean;
168
- edit?: boolean;
169
- delete?: boolean;
170
- }> | null;
171
- }
172
- /**
173
- * Data for creating a role.
174
- * @group Auth
175
- */
176
- export interface AuthCreateRoleData {
177
- id: string;
178
- name: string;
179
- isAdmin?: boolean;
180
- defaultPermissions?: AuthRoleData["defaultPermissions"];
181
- collectionPermissions?: AuthRoleData["collectionPermissions"];
182
- }
183
151
  /**
184
152
  * User management operations for the admin panel.
185
153
  *
@@ -193,23 +161,9 @@ export interface UserManagementAdapter {
193
161
  createUser(data: AuthCreateUserData): Promise<AuthUserData>;
194
162
  updateUser(id: string, data: Partial<AuthCreateUserData>): Promise<AuthUserData | null>;
195
163
  deleteUser(id: string): Promise<void>;
196
- getUserRoles(userId: string): Promise<AuthRoleData[]>;
164
+ getUserRoles(userId: string): Promise<string[]>;
197
165
  setUserRoles(userId: string, roleIds: string[]): Promise<void>;
198
166
  }
199
- /**
200
- * Role management operations for the admin panel.
201
- *
202
- * Optional — if not provided by the adapter, role management is disabled.
203
- *
204
- * @group Auth
205
- */
206
- export interface RoleManagementAdapter {
207
- listRoles(): Promise<AuthRoleData[]>;
208
- getRoleById(id: string): Promise<AuthRoleData | null>;
209
- createRole(data: AuthCreateRoleData): Promise<AuthRoleData>;
210
- updateRole(id: string, data: Partial<AuthRoleData>): Promise<AuthRoleData | null>;
211
- deleteRole(id: string): Promise<void>;
212
- }
213
167
  /**
214
168
  * Pluggable authentication adapter for Rebase.
215
169
  *
@@ -217,7 +171,7 @@ export interface RoleManagementAdapter {
217
171
  * database layer. Each auth adapter knows how to:
218
172
  *
219
173
  * 1. Verify incoming HTTP requests (`verifyRequest`)
220
- * 2. Optionally manage users and roles (for the admin panel)
174
+ * 2. Optionally manage users (for the admin panel)
221
175
  * 3. Optionally mount auth-specific routes (login, register, etc.)
222
176
  * 4. Advertise its capabilities so the frontend can adapt
223
177
  *
@@ -269,11 +223,6 @@ export interface AuthAdapter {
269
223
  * Optional — if not provided, user management UI is hidden.
270
224
  */
271
225
  userManagement?: UserManagementAdapter;
272
- /**
273
- * Role CRUD for the admin panel.
274
- * Optional — if not provided, role management is disabled.
275
- */
276
- roleManagement?: RoleManagementAdapter;
277
226
  /**
278
227
  * Mount adapter-specific auth routes (login, register, refresh, etc.).
279
228
  *
@@ -289,7 +238,7 @@ export interface AuthAdapter {
289
238
  */
290
239
  createAuthRoutes?(): Hono<any, any, any> | undefined;
291
240
  /**
292
- * Mount admin routes for user/role management.
241
+ * Mount admin routes for user management.
293
242
  *
294
243
  * Same typing rationale as `createAuthRoutes` — the sub-app env is
295
244
  * unconstrained to support arbitrary adapter implementations.
@@ -345,8 +294,6 @@ export interface CustomAuthAdapterOptions {
345
294
  verifyToken?: (token: string) => Promise<AuthenticatedUser | null>;
346
295
  /** Optional user management for the admin panel. */
347
296
  userManagement?: UserManagementAdapter;
348
- /** Optional role management for the admin panel. */
349
- roleManagement?: RoleManagementAdapter;
350
297
  /** Static service key for server-to-server auth. */
351
298
  serviceKey?: string;
352
299
  /** Override default capabilities. */
@@ -527,8 +527,8 @@ export interface InitializedDriver {
527
527
  export interface BootstrappedAuth {
528
528
  /** User management service. */
529
529
  userService: unknown;
530
- /** Role management service. */
531
- roleService: unknown;
530
+ /** Role management service (optional, roles are now simple strings). */
531
+ roleService?: unknown;
532
532
  /** Email service (optional). */
533
533
  emailService?: unknown;
534
534
  /** Combined Auth Repository for unified token and user management. */
@@ -1,4 +1,4 @@
1
- import type { AdminUser, AdminRole } from "../controllers/client";
1
+ import type { AdminUser } from "../controllers/client";
2
2
  /**
3
3
  * Context passed to every backend hook.
4
4
  * Provides information about the request that triggered the hook.
@@ -64,19 +64,6 @@ export interface UserHooks {
64
64
  */
65
65
  afterDelete?(userId: string, context: BackendHookContext): void | Promise<void>;
66
66
  }
67
- /**
68
- * Hooks for intercepting Admin Role data at the API boundary.
69
- * @group Backend Hooks
70
- */
71
- export interface RoleHooks {
72
- /**
73
- * Transform a role record after it's read from the database,
74
- * before it's returned to the client.
75
- *
76
- * Return the modified role, or `null` to filter it out entirely.
77
- */
78
- afterRead?(role: AdminRole, context: BackendHookContext): AdminRole | null | Promise<AdminRole | null>;
79
- }
80
67
  /**
81
68
  * Hooks for intercepting collection entity data at the REST API boundary.
82
69
  *
@@ -146,7 +133,7 @@ export interface DataHooks {
146
133
  * These hooks run server-side after database operations complete and before
147
134
  * API responses are sent.
148
135
  *
149
- * - `users` / `roles` — intercept admin user and role management endpoints
136
+ * - `users` — intercept admin user management endpoints
150
137
  * - `data` — intercept ALL collection entity data flowing through the REST API
151
138
  *
152
139
  * `data` hooks complement per-collection `EntityCallbacks`. Entity callbacks
@@ -180,8 +167,6 @@ export interface DataHooks {
180
167
  export interface BackendHooks {
181
168
  /** Hooks for intercepting user management data */
182
169
  users?: UserHooks;
183
- /** Hooks for intercepting role management data */
184
- roles?: RoleHooks;
185
170
  /** Hooks for intercepting ALL collection entity data via the REST API */
186
171
  data?: DataHooks;
187
172
  }
@@ -1,6 +1,6 @@
1
1
  import type { ComponentRef } from "./component_ref";
2
- import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity, Vector } from "./entities";
3
- import type { Relation, JoinStep, OnAction } from "./relations";
2
+ import type { Entity, EntityReference, EntityRelation, EntityValues, GeoPoint, Vector } from "./entities";
3
+ import type { JoinStep, OnAction, Relation } from "./relations";
4
4
  import type { EntityCollection, FilterValues } from "./collections";
5
5
  import type { ColorKey, ColorScheme } from "./chips";
6
6
  import type { AuthController } from "../controllers/auth";
@@ -185,7 +185,7 @@ export interface StringProperty extends BaseProperty {
185
185
  * Optional database column type. If not set, it defaults to `varchar` or `uuid` depending on `isId` configuration.
186
186
  * Use `text` for strings with unbound length, `char` for fixed-length strings, or `varchar` for variable-length strings with a limit.
187
187
  */
188
- columnType?: "varchar" | "text" | "char";
188
+ columnType?: "varchar" | "text" | "char" | "uuid";
189
189
  /**
190
190
  * Rules for validating this property
191
191
  */
@@ -541,9 +541,11 @@ export interface ArrayProperty extends BaseProperty {
541
541
  ui?: ArrayUIConfig;
542
542
  type: "array";
543
543
  /**
544
- * Optional database column type. Defaults to `jsonb`.
544
+ * Optional database column type. By default, maps to a native Postgres array
545
+ * (e.g. `text[]`, `integer[]`/`numeric[]`, `boolean[]`) if the element type
546
+ * is a primitive, otherwise defaults to `jsonb`.
545
547
  */
546
- columnType?: "json" | "jsonb";
548
+ columnType?: "json" | "jsonb" | "text[]" | "integer[]" | "boolean[]" | "numeric[]";
547
549
  /**
548
550
  * The property of this array.
549
551
  * You can specify any property (except another Array property)
@@ -1,4 +1,4 @@
1
- import { Role, User } from "../users";
1
+ import type { User } from "../users";
2
2
  /**
3
3
  * Result of creating a new user via admin flow.
4
4
  * Contains the created user plus information about how credentials were delivered.
@@ -15,56 +15,46 @@ export interface UserCreationResult<USER extends User = User> {
15
15
  temporaryPassword?: string;
16
16
  }
17
17
  /**
18
- * Delegate to manage users, roles, and their permissions.
19
- * This interface allows the CMS to be completely agnostic of the underlying
20
- * authentication provider or backend.
18
+ * Delegate to manage auth-specific user operations.
19
+ *
20
+ * This interface allows the CMS to be agnostic of the underlying
21
+ * authentication provider or backend. User/role CRUD is now handled
22
+ * by the collection system; this delegate only exposes auth-specific
23
+ * operations (password hashing, invitations, bootstrap).
21
24
  *
22
25
  * @group Models
23
26
  */
24
27
  export interface UserManagementDelegate<USER extends User = User> {
25
28
  /**
26
- * Are the users and roles currently being fetched?
29
+ * Are auth-related operations currently loading?
27
30
  */
28
31
  loading: boolean;
29
32
  /**
30
- * List of users managed by the CMS.
33
+ * In-memory list of users (used for client-side filtering fallback).
31
34
  */
32
- users: USER[];
35
+ users?: USER[];
33
36
  /**
34
- * Optional error if users failed to load.
37
+ * Error from fetching the users list, if any.
35
38
  */
36
39
  usersError?: Error;
37
40
  /**
38
- * Function to get a user by its uid. This is used to show
39
- * user information when assigning ownership of an entity.
40
- * @param uid
41
+ * Look up a single user by UID from the in-memory cache.
41
42
  */
42
- getUser: (uid: string) => USER | null;
43
+ getUser?: (uid: string) => USER | null;
43
44
  /**
44
- * Search users with server-side pagination.
45
- * When provided, the CMS will use this for the users table
46
- * instead of loading all users into memory.
45
+ * Server-side user search with pagination.
47
46
  */
48
- searchUsers?: (options: {
47
+ searchUsers?: (params: {
49
48
  search?: string;
50
49
  limit?: number;
51
50
  offset?: number;
52
- orderBy?: string;
53
- orderDir?: "asc" | "desc";
54
- roleId?: string;
55
51
  }) => Promise<{
56
52
  users: USER[];
57
53
  total: number;
58
54
  }>;
59
- /**
60
- * Save a user (create or update)
61
- * @param user
62
- */
63
- saveUser?: (user: USER) => Promise<USER>;
64
55
  /**
65
56
  * Create a new user with invitation/password generation support.
66
57
  * Returns additional info about how the credentials were delivered.
67
- * Falls back to saveUser if not provided.
68
58
  */
69
59
  createUser?: (user: USER) => Promise<UserCreationResult<USER>>;
70
60
  /**
@@ -73,42 +63,15 @@ export interface UserManagementDelegate<USER extends User = User> {
73
63
  * or a flag indicating an email invitation was sent.
74
64
  */
75
65
  resetPassword?: (user: USER) => Promise<UserCreationResult<USER>>;
76
- /**
77
- * Delete a user
78
- * @param user
79
- */
80
- deleteUser?: (user: USER) => Promise<void>;
81
- /**
82
- * List of roles defined in the CMS.
83
- */
84
- roles?: Role[];
85
- /**
86
- * Optional error if roles failed to load.
87
- */
88
- rolesError?: Error;
89
- /**
90
- * Save a role (create or update)
91
- * @param role
92
- */
93
- saveRole?: (role: Role) => Promise<void>;
94
- /**
95
- * Delete a role
96
- * @param role
97
- */
98
- deleteRole?: (role: Role) => Promise<void>;
99
66
  /**
100
67
  * Is the currently logged in user an admin?
101
68
  */
102
69
  isAdmin?: boolean;
103
- /**
104
- * If true, the UI will allow the user to create the default roles (admin, editor, viewer).
105
- */
106
- allowDefaultRolesCreation?: boolean;
107
70
  /**
108
71
  * Optionally define roles for a given user. This is useful when the roles
109
72
  * are coming from a separate provider than the one issuing the tokens.
110
73
  */
111
- defineRolesFor?: (user: USER) => Promise<Role[] | undefined> | Role[] | undefined;
74
+ defineRolesFor?: (user: USER) => Promise<string[] | undefined> | string[] | undefined;
112
75
  /**
113
76
  * Whether any admin users exist. Used by the bootstrap banner to decide
114
77
  * whether to prompt. Populated via a lightweight check (e.g. `limit=1`
@@ -1,2 +1 @@
1
1
  export * from "./user";
2
- export * from "./roles";
@@ -35,7 +35,6 @@ export type User = {
35
35
  readonly isAnonymous: boolean;
36
36
  /**
37
37
  * Role IDs assigned to this user (e.g. ["admin", "editor"]).
38
- * These are plain string IDs — use the UserManagementDelegate to look up full Role objects.
39
38
  */
40
39
  roles?: string[];
41
40
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/sdk-generator",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Generate a typed JS SDK from Rebase collection definitions",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.es.js",
@@ -19,8 +19,8 @@
19
19
  "author": "rebase.pro",
20
20
  "license": "MIT",
21
21
  "peerDependencies": {
22
- "@rebasepro/common": "0.2.4",
23
- "@rebasepro/types": "0.2.4"
22
+ "@rebasepro/common": "0.2.5",
23
+ "@rebasepro/types": "0.2.5"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@jest/globals": "^29.7.0",
@@ -30,8 +30,8 @@
30
30
  "ts-jest": "^29.4.10",
31
31
  "typescript": "^5.9.3",
32
32
  "vite": "^7.3.3",
33
- "@rebasepro/common": "0.2.4",
34
- "@rebasepro/types": "0.2.4"
33
+ "@rebasepro/common": "0.2.5",
34
+ "@rebasepro/types": "0.2.5"
35
35
  },
36
36
  "exports": {
37
37
  ".": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
44
44
  "dependencies": {
45
- "@rebasepro/client": "0.2.4"
45
+ "@rebasepro/client": "0.2.5"
46
46
  },
47
47
  "repository": {
48
48
  "type": "git",
@@ -1,14 +0,0 @@
1
- export type Role = {
2
- /**
3
- * ID of the role
4
- */
5
- id: string;
6
- /**
7
- * Name of the role
8
- */
9
- name: string;
10
- /**
11
- * If this flag is true, the user can perform any action
12
- */
13
- isAdmin?: boolean;
14
- };