@rebasepro/client 0.1.2 → 0.2.3
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/LICENSE +21 -6
- package/dist/auth.d.ts +8 -6
- package/dist/collection.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +5 -113
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +14 -121
- package/dist/index.umd.js.map +1 -1
- package/dist/query_builder.d.ts +1 -53
- package/package.json +9 -9
- package/src/auth.ts +4 -8
- package/src/collection.ts +2 -2
- package/src/index.ts +2 -1
- package/src/query_builder.ts +1 -125
- package/src/transport.ts +2 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rebase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/auth.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "
|
|
|
24
24
|
export interface AuthConfig {
|
|
25
25
|
needsSetup: boolean;
|
|
26
26
|
registrationEnabled: boolean;
|
|
27
|
-
googleEnabled: boolean;
|
|
28
27
|
emailServiceEnabled: boolean;
|
|
28
|
+
enabledProviders: string[];
|
|
29
29
|
}
|
|
30
30
|
export interface AuthStorage {
|
|
31
31
|
getItem: (key: string) => string | null;
|
|
@@ -50,11 +50,13 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
50
50
|
accessToken: string;
|
|
51
51
|
refreshToken: string;
|
|
52
52
|
}>;
|
|
53
|
-
signInWithGoogle: (
|
|
54
|
-
idToken
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
signInWithGoogle: (payload: {
|
|
54
|
+
idToken: string;
|
|
55
|
+
} | {
|
|
56
|
+
accessToken: string;
|
|
57
|
+
} | {
|
|
58
|
+
code: string;
|
|
59
|
+
redirectUri: string;
|
|
58
60
|
}) => Promise<{
|
|
59
61
|
user: RebaseUser;
|
|
60
62
|
accessToken: string;
|
package/dist/collection.d.ts
CHANGED
|
@@ -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 {
|
|
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
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) {
|
|
@@ -381,13 +383,12 @@ function createAuth(transport, options) {
|
|
|
381
383
|
refreshToken: session.refreshToken
|
|
382
384
|
};
|
|
383
385
|
}
|
|
384
|
-
async function signInWithGoogle(
|
|
386
|
+
async function signInWithGoogle(payload) {
|
|
385
387
|
const fetchFn = getFetch();
|
|
386
|
-
const body = typeof tokenOrPayload === "string" ? { idToken: tokenOrPayload } : tokenOrPayload;
|
|
387
388
|
const res = await fetchFn(authUrl("/google"), {
|
|
388
389
|
method: "POST",
|
|
389
390
|
headers: { "Content-Type": "application/json" },
|
|
390
|
-
body: JSON.stringify(
|
|
391
|
+
body: JSON.stringify(payload)
|
|
391
392
|
});
|
|
392
393
|
const responseBody = await res.json().catch(() => ({}));
|
|
393
394
|
if (!res.ok) throwApiError(res.status, responseBody, res.statusText);
|
|
@@ -820,116 +821,6 @@ function createCron(transport, options) {
|
|
|
820
821
|
toggleJob
|
|
821
822
|
};
|
|
822
823
|
}
|
|
823
|
-
function mapOperator(op) {
|
|
824
|
-
switch (op) {
|
|
825
|
-
case "==":
|
|
826
|
-
return "eq";
|
|
827
|
-
case "!=":
|
|
828
|
-
return "neq";
|
|
829
|
-
case ">":
|
|
830
|
-
return "gt";
|
|
831
|
-
case ">=":
|
|
832
|
-
return "gte";
|
|
833
|
-
case "<":
|
|
834
|
-
return "lt";
|
|
835
|
-
case "<=":
|
|
836
|
-
return "lte";
|
|
837
|
-
case "array-contains":
|
|
838
|
-
return "cs";
|
|
839
|
-
case "array-contains-any":
|
|
840
|
-
return "csa";
|
|
841
|
-
case "not-in":
|
|
842
|
-
return "nin";
|
|
843
|
-
default:
|
|
844
|
-
return op;
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
class QueryBuilder {
|
|
848
|
-
constructor(collection) {
|
|
849
|
-
this.collection = collection;
|
|
850
|
-
}
|
|
851
|
-
params = { where: {} };
|
|
852
|
-
/**
|
|
853
|
-
* Add a filter condition to your query.
|
|
854
|
-
* @example
|
|
855
|
-
* client.collection('users').where('age', '>=', 18).find()
|
|
856
|
-
*/
|
|
857
|
-
where(column, operator, value) {
|
|
858
|
-
if (!this.params.where) {
|
|
859
|
-
this.params.where = {};
|
|
860
|
-
}
|
|
861
|
-
const mappedOp = mapOperator(operator);
|
|
862
|
-
let formattedValue = value;
|
|
863
|
-
if (Array.isArray(value) && ["in", "nin", "cs", "csa"].includes(mappedOp)) {
|
|
864
|
-
formattedValue = `(${value.join(",")})`;
|
|
865
|
-
} else if (value === null) {
|
|
866
|
-
formattedValue = "null";
|
|
867
|
-
}
|
|
868
|
-
this.params.where[column] = mappedOp === "eq" ? String(formattedValue) : `${mappedOp}.${formattedValue}`;
|
|
869
|
-
return this;
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* Order the results by a specific column.
|
|
873
|
-
* @example
|
|
874
|
-
* client.collection('users').orderBy('createdAt', 'desc').find()
|
|
875
|
-
*/
|
|
876
|
-
orderBy(column, ascending = "asc") {
|
|
877
|
-
this.params.orderBy = `${column}:${ascending}`;
|
|
878
|
-
return this;
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* Limit the number of results returned.
|
|
882
|
-
*/
|
|
883
|
-
limit(count) {
|
|
884
|
-
this.params.limit = count;
|
|
885
|
-
return this;
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Skip the first N results.
|
|
889
|
-
*/
|
|
890
|
-
offset(count) {
|
|
891
|
-
this.params.offset = count;
|
|
892
|
-
return this;
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Set a free-text search string if supported by the backend.
|
|
896
|
-
*/
|
|
897
|
-
search(searchString) {
|
|
898
|
-
this.params.searchString = searchString;
|
|
899
|
-
return this;
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Include related entities in the response.
|
|
903
|
-
* Relations will be populated with full entity data instead of just IDs.
|
|
904
|
-
*
|
|
905
|
-
* @param relations - Relation names to include, or "*" for all.
|
|
906
|
-
* @example
|
|
907
|
-
* // Include specific relations
|
|
908
|
-
* client.data.posts.include("tags", "author").find()
|
|
909
|
-
*
|
|
910
|
-
* // Include all relations
|
|
911
|
-
* client.data.posts.include("*").find()
|
|
912
|
-
*/
|
|
913
|
-
include(...relations) {
|
|
914
|
-
this.params.include = relations;
|
|
915
|
-
return this;
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* Execute the find query and return the results.
|
|
919
|
-
*/
|
|
920
|
-
async find() {
|
|
921
|
-
return this.collection.find(this.params);
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
* Listen to realtime updates matching this query.
|
|
925
|
-
*/
|
|
926
|
-
listen(onUpdate, onError) {
|
|
927
|
-
if (!this.collection.listen) {
|
|
928
|
-
throw new Error("Listen is only available when RebaseClient is configured with a websocketUrl.");
|
|
929
|
-
}
|
|
930
|
-
return this.collection.listen(this.params, onUpdate, onError);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
824
|
function parseWhereFilter(where) {
|
|
934
825
|
if (!where) return void 0;
|
|
935
826
|
const filters = {};
|
|
@@ -2283,6 +2174,7 @@ function createRebaseClient(options) {
|
|
|
2283
2174
|
}
|
|
2284
2175
|
export {
|
|
2285
2176
|
ApiError,
|
|
2177
|
+
QueryBuilder2 as QueryBuilder,
|
|
2286
2178
|
RebaseApiError,
|
|
2287
2179
|
RebaseWebSocketClient,
|
|
2288
2180
|
buildQueryString,
|