@rebasepro/client 0.2.1 → 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.
package/dist/admin.d.ts CHANGED
@@ -14,7 +14,6 @@ export interface RebaseRole {
14
14
  name: string;
15
15
  isAdmin: boolean;
16
16
  defaultPermissions: Record<string, unknown> | null;
17
- config: Record<string, unknown> | null;
18
17
  }
19
18
  export interface CreateAdminOptions {
20
19
  adminPath?: string;
@@ -68,7 +67,6 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
68
67
  name: string;
69
68
  isAdmin?: boolean;
70
69
  defaultPermissions?: Record<string, unknown>;
71
- config?: Record<string, unknown>;
72
70
  }) => Promise<{
73
71
  role: RebaseRole;
74
72
  }>;
@@ -76,7 +74,6 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
76
74
  name?: string;
77
75
  isAdmin?: boolean;
78
76
  defaultPermissions?: Record<string, unknown>;
79
- config?: Record<string, unknown>;
80
77
  }) => Promise<{
81
78
  role: RebaseRole;
82
79
  }>;
package/dist/auth.d.ts CHANGED
@@ -24,7 +24,9 @@ export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "
24
24
  export interface AuthConfig {
25
25
  needsSetup: boolean;
26
26
  registrationEnabled: boolean;
27
- emailServiceEnabled: boolean;
27
+ emailServiceEnabled?: boolean;
28
+ passwordReset?: boolean;
29
+ emailVerification?: boolean;
28
30
  enabledProviders: string[];
29
31
  }
30
32
  export interface AuthStorage {
@@ -1,7 +1,7 @@
1
1
  import { Transport, FindParams } from "./transport";
2
2
  import { RebaseWebSocketClient } from "./websocket";
3
- import { CollectionAccessor } from "@rebasepro/types";
4
- import { FilterOperator, QueryBuilder } from "./query_builder";
3
+ import { CollectionAccessor, FilterOperator } from "@rebasepro/types";
4
+ import { QueryBuilder } from "./query_builder";
5
5
  /**
6
6
  * CollectionClient extends `CollectionAccessor` from `@rebasepro/types` so that
7
7
  * `client.data` can be passed directly to the core Rebase component.
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export * from "./auth";
9
9
  export * from "./admin";
10
10
  export * from "./cron";
11
11
  export * from "./collection";
12
+ export * from "./query_builder";
12
13
  export * from "./websocket";
13
14
  export * from "./storage";
14
15
  export * from "./reviver";
@@ -20,7 +21,9 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
20
21
  }
21
22
  import { RebaseWebSocketClient } from "./websocket";
22
23
  import { RebaseClient as BaseRebaseClient, RebaseData, StorageSource } from "@rebasepro/types";
23
- export type RebaseClient<DB = Record<string, unknown>> = BaseRebaseClient<DB> & {
24
+ export type { Entity, FindResponse } from "@rebasepro/types";
25
+ type KebabToCamelCase<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamelCase<U>>}` : S;
26
+ export type RebaseClient<DB = Record<string, unknown>> = Omit<BaseRebaseClient<DB>, "data"> & {
24
27
  setToken: (token: string | null) => void;
25
28
  setAuthTokenGetter: (getter: () => Promise<string | null>) => void;
26
29
  setOnUnauthorized: (handler: () => Promise<boolean>) => void;
@@ -32,14 +35,14 @@ export type RebaseClient<DB = Record<string, unknown>> = BaseRebaseClient<DB> &
32
35
  ws?: RebaseWebSocketClient;
33
36
  storage?: StorageSource;
34
37
  call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
35
- data: RebaseData & {
36
- collection<K extends keyof DB>(slug: Extract<K, string>): CollectionClient<DB[K] extends {
38
+ data: {
39
+ collection<S extends string>(slug: S): CollectionClient<KebabToCamelCase<S> extends keyof DB ? (DB[KebabToCamelCase<S>] extends {
37
40
  Row: infer R extends Record<string, unknown>;
38
- } ? R : Record<string, unknown>>;
41
+ } ? R : Record<string, unknown>) : Record<string, unknown>>;
39
42
  } & {
40
43
  [K in keyof DB]: CollectionClient<DB[K] extends {
41
44
  Row: infer R extends Record<string, unknown>;
42
45
  } ? R : Record<string, unknown>>;
43
- };
46
+ } & RebaseData;
44
47
  };
45
48
  export declare function createRebaseClient<DB = Record<string, unknown>>(options: CreateRebaseClientOptions): RebaseClient<DB>;
package/dist/index.es.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Vector, GeoPoint, EntityRelation, EntityReference } from "@rebasepro/types";
2
+ import { QueryBuilder } from "@rebasepro/common";
3
+ import { QueryBuilder as QueryBuilder2 } from "@rebasepro/common";
2
4
  import { toSnakeCase } from "@rebasepro/utils";
3
5
  function rebaseReviver(_key, value) {
4
6
  if (value && typeof value === "object" && "__type" in value) {
@@ -139,6 +141,13 @@ function createTransport(config) {
139
141
  } catch (e) {
140
142
  }
141
143
  }
144
+ const getErrorField = (obj, field) => {
145
+ const err = obj?.error;
146
+ if (err && typeof err === "object" && err !== null && field in err) {
147
+ return err[field];
148
+ }
149
+ return obj?.[field];
150
+ };
142
151
  if (res.status === 401 && onUnauthorizedHandler) {
143
152
  const retried = await onUnauthorizedHandler();
144
153
  if (retried) {
@@ -174,9 +183,9 @@ function createTransport(config) {
174
183
  }
175
184
  throw new RebaseApiError(
176
185
  retryRes.status,
177
- retryBody?.error?.message || retryBody?.message || fallbackMessage || `Request failed with status ${retryRes.status}`,
178
- retryBody?.error?.code || retryBody?.code,
179
- retryBody?.error?.details || retryBody?.details
186
+ String(getErrorField(retryBody, "message") || fallbackMessage || `Request failed with status ${retryRes.status}`),
187
+ getErrorField(retryBody, "code"),
188
+ getErrorField(retryBody, "details")
180
189
  );
181
190
  }
182
191
  return retryBody;
@@ -190,9 +199,9 @@ function createTransport(config) {
190
199
  }
191
200
  throw new RebaseApiError(
192
201
  res.status,
193
- body?.error?.message || body?.message || fallbackMessage || `Request failed with status ${res.status}`,
194
- body?.error?.code || body?.code,
195
- body?.error?.details || body?.details
202
+ String(getErrorField(body, "message") || fallbackMessage || `Request failed with status ${res.status}`),
203
+ getErrorField(body, "code"),
204
+ getErrorField(body, "details")
196
205
  );
197
206
  }
198
207
  return body;
@@ -819,116 +828,6 @@ function createCron(transport, options) {
819
828
  toggleJob
820
829
  };
821
830
  }
822
- function mapOperator(op) {
823
- switch (op) {
824
- case "==":
825
- return "eq";
826
- case "!=":
827
- return "neq";
828
- case ">":
829
- return "gt";
830
- case ">=":
831
- return "gte";
832
- case "<":
833
- return "lt";
834
- case "<=":
835
- return "lte";
836
- case "array-contains":
837
- return "cs";
838
- case "array-contains-any":
839
- return "csa";
840
- case "not-in":
841
- return "nin";
842
- default:
843
- return op;
844
- }
845
- }
846
- class QueryBuilder {
847
- constructor(collection) {
848
- this.collection = collection;
849
- }
850
- params = { where: {} };
851
- /**
852
- * Add a filter condition to your query.
853
- * @example
854
- * client.collection('users').where('age', '>=', 18).find()
855
- */
856
- where(column, operator, value) {
857
- if (!this.params.where) {
858
- this.params.where = {};
859
- }
860
- const mappedOp = mapOperator(operator);
861
- let formattedValue = value;
862
- if (Array.isArray(value) && ["in", "nin", "cs", "csa"].includes(mappedOp)) {
863
- formattedValue = `(${value.join(",")})`;
864
- } else if (value === null) {
865
- formattedValue = "null";
866
- }
867
- this.params.where[column] = mappedOp === "eq" ? String(formattedValue) : `${mappedOp}.${formattedValue}`;
868
- return this;
869
- }
870
- /**
871
- * Order the results by a specific column.
872
- * @example
873
- * client.collection('users').orderBy('createdAt', 'desc').find()
874
- */
875
- orderBy(column, ascending = "asc") {
876
- this.params.orderBy = `${column}:${ascending}`;
877
- return this;
878
- }
879
- /**
880
- * Limit the number of results returned.
881
- */
882
- limit(count) {
883
- this.params.limit = count;
884
- return this;
885
- }
886
- /**
887
- * Skip the first N results.
888
- */
889
- offset(count) {
890
- this.params.offset = count;
891
- return this;
892
- }
893
- /**
894
- * Set a free-text search string if supported by the backend.
895
- */
896
- search(searchString) {
897
- this.params.searchString = searchString;
898
- return this;
899
- }
900
- /**
901
- * Include related entities in the response.
902
- * Relations will be populated with full entity data instead of just IDs.
903
- *
904
- * @param relations - Relation names to include, or "*" for all.
905
- * @example
906
- * // Include specific relations
907
- * client.data.posts.include("tags", "author").find()
908
- *
909
- * // Include all relations
910
- * client.data.posts.include("*").find()
911
- */
912
- include(...relations) {
913
- this.params.include = relations;
914
- return this;
915
- }
916
- /**
917
- * Execute the find query and return the results.
918
- */
919
- async find() {
920
- return this.collection.find(this.params);
921
- }
922
- /**
923
- * Listen to realtime updates matching this query.
924
- */
925
- listen(onUpdate, onError) {
926
- if (!this.collection.listen) {
927
- throw new Error("Listen is only available when RebaseClient is configured with a websocketUrl.");
928
- }
929
- return this.collection.listen(this.params, onUpdate, onError);
930
- }
931
- }
932
831
  function parseWhereFilter(where) {
933
832
  if (!where) return void 0;
934
833
  const filters = {};
@@ -2282,6 +2181,7 @@ function createRebaseClient(options) {
2282
2181
  }
2283
2182
  export {
2284
2183
  ApiError,
2184
+ QueryBuilder2 as QueryBuilder,
2285
2185
  RebaseApiError,
2286
2186
  RebaseWebSocketClient,
2287
2187
  buildQueryString,