@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/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@rebasepro/types"), require("@rebasepro/utils")) : typeof define === "function" && define.amd ? define(["exports", "@rebasepro/types", "@rebasepro/utils"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase Client"] = {}, global.types, global.utils));
|
|
3
|
-
})(this, function(exports2, types, utils) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@rebasepro/types"), require("@rebasepro/common"), require("@rebasepro/utils")) : typeof define === "function" && define.amd ? define(["exports", "@rebasepro/types", "@rebasepro/common", "@rebasepro/utils"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase Client"] = {}, global.types, global.common, global.utils));
|
|
3
|
+
})(this, function(exports2, types, common, utils) {
|
|
4
4
|
"use strict";
|
|
5
5
|
function rebaseReviver(_key, value) {
|
|
6
6
|
if (value && typeof value === "object" && "__type" in value) {
|
|
@@ -383,13 +383,12 @@
|
|
|
383
383
|
refreshToken: session.refreshToken
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
|
-
async function signInWithGoogle(
|
|
386
|
+
async function signInWithGoogle(payload) {
|
|
387
387
|
const fetchFn = getFetch();
|
|
388
|
-
const body = typeof tokenOrPayload === "string" ? { idToken: tokenOrPayload } : tokenOrPayload;
|
|
389
388
|
const res = await fetchFn(authUrl("/google"), {
|
|
390
389
|
method: "POST",
|
|
391
390
|
headers: { "Content-Type": "application/json" },
|
|
392
|
-
body: JSON.stringify(
|
|
391
|
+
body: JSON.stringify(payload)
|
|
393
392
|
});
|
|
394
393
|
const responseBody = await res.json().catch(() => ({}));
|
|
395
394
|
if (!res.ok) throwApiError(res.status, responseBody, res.statusText);
|
|
@@ -822,116 +821,6 @@
|
|
|
822
821
|
toggleJob
|
|
823
822
|
};
|
|
824
823
|
}
|
|
825
|
-
function mapOperator(op) {
|
|
826
|
-
switch (op) {
|
|
827
|
-
case "==":
|
|
828
|
-
return "eq";
|
|
829
|
-
case "!=":
|
|
830
|
-
return "neq";
|
|
831
|
-
case ">":
|
|
832
|
-
return "gt";
|
|
833
|
-
case ">=":
|
|
834
|
-
return "gte";
|
|
835
|
-
case "<":
|
|
836
|
-
return "lt";
|
|
837
|
-
case "<=":
|
|
838
|
-
return "lte";
|
|
839
|
-
case "array-contains":
|
|
840
|
-
return "cs";
|
|
841
|
-
case "array-contains-any":
|
|
842
|
-
return "csa";
|
|
843
|
-
case "not-in":
|
|
844
|
-
return "nin";
|
|
845
|
-
default:
|
|
846
|
-
return op;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
class QueryBuilder {
|
|
850
|
-
constructor(collection) {
|
|
851
|
-
this.collection = collection;
|
|
852
|
-
}
|
|
853
|
-
params = { where: {} };
|
|
854
|
-
/**
|
|
855
|
-
* Add a filter condition to your query.
|
|
856
|
-
* @example
|
|
857
|
-
* client.collection('users').where('age', '>=', 18).find()
|
|
858
|
-
*/
|
|
859
|
-
where(column, operator, value) {
|
|
860
|
-
if (!this.params.where) {
|
|
861
|
-
this.params.where = {};
|
|
862
|
-
}
|
|
863
|
-
const mappedOp = mapOperator(operator);
|
|
864
|
-
let formattedValue = value;
|
|
865
|
-
if (Array.isArray(value) && ["in", "nin", "cs", "csa"].includes(mappedOp)) {
|
|
866
|
-
formattedValue = `(${value.join(",")})`;
|
|
867
|
-
} else if (value === null) {
|
|
868
|
-
formattedValue = "null";
|
|
869
|
-
}
|
|
870
|
-
this.params.where[column] = mappedOp === "eq" ? String(formattedValue) : `${mappedOp}.${formattedValue}`;
|
|
871
|
-
return this;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Order the results by a specific column.
|
|
875
|
-
* @example
|
|
876
|
-
* client.collection('users').orderBy('createdAt', 'desc').find()
|
|
877
|
-
*/
|
|
878
|
-
orderBy(column, ascending = "asc") {
|
|
879
|
-
this.params.orderBy = `${column}:${ascending}`;
|
|
880
|
-
return this;
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Limit the number of results returned.
|
|
884
|
-
*/
|
|
885
|
-
limit(count) {
|
|
886
|
-
this.params.limit = count;
|
|
887
|
-
return this;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Skip the first N results.
|
|
891
|
-
*/
|
|
892
|
-
offset(count) {
|
|
893
|
-
this.params.offset = count;
|
|
894
|
-
return this;
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* Set a free-text search string if supported by the backend.
|
|
898
|
-
*/
|
|
899
|
-
search(searchString) {
|
|
900
|
-
this.params.searchString = searchString;
|
|
901
|
-
return this;
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Include related entities in the response.
|
|
905
|
-
* Relations will be populated with full entity data instead of just IDs.
|
|
906
|
-
*
|
|
907
|
-
* @param relations - Relation names to include, or "*" for all.
|
|
908
|
-
* @example
|
|
909
|
-
* // Include specific relations
|
|
910
|
-
* client.data.posts.include("tags", "author").find()
|
|
911
|
-
*
|
|
912
|
-
* // Include all relations
|
|
913
|
-
* client.data.posts.include("*").find()
|
|
914
|
-
*/
|
|
915
|
-
include(...relations) {
|
|
916
|
-
this.params.include = relations;
|
|
917
|
-
return this;
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Execute the find query and return the results.
|
|
921
|
-
*/
|
|
922
|
-
async find() {
|
|
923
|
-
return this.collection.find(this.params);
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Listen to realtime updates matching this query.
|
|
927
|
-
*/
|
|
928
|
-
listen(onUpdate, onError) {
|
|
929
|
-
if (!this.collection.listen) {
|
|
930
|
-
throw new Error("Listen is only available when RebaseClient is configured with a websocketUrl.");
|
|
931
|
-
}
|
|
932
|
-
return this.collection.listen(this.params, onUpdate, onError);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
824
|
function parseWhereFilter(where) {
|
|
936
825
|
if (!where) return void 0;
|
|
937
826
|
const filters = {};
|
|
@@ -1084,22 +973,22 @@
|
|
|
1084
973
|
},
|
|
1085
974
|
// Fluent builder instantiation
|
|
1086
975
|
where(column, operator, value) {
|
|
1087
|
-
return new QueryBuilder(client).where(column, operator, value);
|
|
976
|
+
return new common.QueryBuilder(client).where(column, operator, value);
|
|
1088
977
|
},
|
|
1089
978
|
orderBy(column, ascending) {
|
|
1090
|
-
return new QueryBuilder(client).orderBy(column, ascending);
|
|
979
|
+
return new common.QueryBuilder(client).orderBy(column, ascending);
|
|
1091
980
|
},
|
|
1092
981
|
limit(count) {
|
|
1093
|
-
return new QueryBuilder(client).limit(count);
|
|
982
|
+
return new common.QueryBuilder(client).limit(count);
|
|
1094
983
|
},
|
|
1095
984
|
offset(count) {
|
|
1096
|
-
return new QueryBuilder(client).offset(count);
|
|
985
|
+
return new common.QueryBuilder(client).offset(count);
|
|
1097
986
|
},
|
|
1098
987
|
search(searchString) {
|
|
1099
|
-
return new QueryBuilder(client).search(searchString);
|
|
988
|
+
return new common.QueryBuilder(client).search(searchString);
|
|
1100
989
|
},
|
|
1101
990
|
include(...relations) {
|
|
1102
|
-
return new QueryBuilder(client).include(...relations);
|
|
991
|
+
return new common.QueryBuilder(client).include(...relations);
|
|
1103
992
|
}
|
|
1104
993
|
};
|
|
1105
994
|
if (ws) {
|
|
@@ -2283,6 +2172,10 @@
|
|
|
2283
2172
|
};
|
|
2284
2173
|
return target;
|
|
2285
2174
|
}
|
|
2175
|
+
Object.defineProperty(exports2, "QueryBuilder", {
|
|
2176
|
+
enumerable: true,
|
|
2177
|
+
get: () => common.QueryBuilder
|
|
2178
|
+
});
|
|
2286
2179
|
exports2.ApiError = ApiError;
|
|
2287
2180
|
exports2.RebaseApiError = RebaseApiError;
|
|
2288
2181
|
exports2.RebaseWebSocketClient = RebaseWebSocketClient;
|