@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 +0 -3
- package/dist/auth.d.ts +3 -1
- package/dist/collection.d.ts +2 -2
- package/dist/index.d.ts +8 -5
- package/dist/index.es.js +16 -116
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +25 -124
- package/dist/index.umd.js.map +1 -1
- package/dist/query_builder.d.ts +1 -53
- package/package.json +4 -3
- package/src/admin.ts +2 -3
- package/src/auth.ts +3 -1
- package/src/collection.ts +2 -2
- package/src/index.ts +14 -5
- package/src/query_builder.ts +1 -125
- package/src/transport.ts +17 -9
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) {
|
|
@@ -141,6 +141,13 @@
|
|
|
141
141
|
} catch (e) {
|
|
142
142
|
}
|
|
143
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
|
+
};
|
|
144
151
|
if (res.status === 401 && onUnauthorizedHandler) {
|
|
145
152
|
const retried = await onUnauthorizedHandler();
|
|
146
153
|
if (retried) {
|
|
@@ -176,9 +183,9 @@
|
|
|
176
183
|
}
|
|
177
184
|
throw new RebaseApiError(
|
|
178
185
|
retryRes.status,
|
|
179
|
-
retryBody
|
|
180
|
-
retryBody
|
|
181
|
-
retryBody
|
|
186
|
+
String(getErrorField(retryBody, "message") || fallbackMessage || `Request failed with status ${retryRes.status}`),
|
|
187
|
+
getErrorField(retryBody, "code"),
|
|
188
|
+
getErrorField(retryBody, "details")
|
|
182
189
|
);
|
|
183
190
|
}
|
|
184
191
|
return retryBody;
|
|
@@ -192,9 +199,9 @@
|
|
|
192
199
|
}
|
|
193
200
|
throw new RebaseApiError(
|
|
194
201
|
res.status,
|
|
195
|
-
body
|
|
196
|
-
body
|
|
197
|
-
body
|
|
202
|
+
String(getErrorField(body, "message") || fallbackMessage || `Request failed with status ${res.status}`),
|
|
203
|
+
getErrorField(body, "code"),
|
|
204
|
+
getErrorField(body, "details")
|
|
198
205
|
);
|
|
199
206
|
}
|
|
200
207
|
return body;
|
|
@@ -821,116 +828,6 @@
|
|
|
821
828
|
toggleJob
|
|
822
829
|
};
|
|
823
830
|
}
|
|
824
|
-
function mapOperator(op) {
|
|
825
|
-
switch (op) {
|
|
826
|
-
case "==":
|
|
827
|
-
return "eq";
|
|
828
|
-
case "!=":
|
|
829
|
-
return "neq";
|
|
830
|
-
case ">":
|
|
831
|
-
return "gt";
|
|
832
|
-
case ">=":
|
|
833
|
-
return "gte";
|
|
834
|
-
case "<":
|
|
835
|
-
return "lt";
|
|
836
|
-
case "<=":
|
|
837
|
-
return "lte";
|
|
838
|
-
case "array-contains":
|
|
839
|
-
return "cs";
|
|
840
|
-
case "array-contains-any":
|
|
841
|
-
return "csa";
|
|
842
|
-
case "not-in":
|
|
843
|
-
return "nin";
|
|
844
|
-
default:
|
|
845
|
-
return op;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
class QueryBuilder {
|
|
849
|
-
constructor(collection) {
|
|
850
|
-
this.collection = collection;
|
|
851
|
-
}
|
|
852
|
-
params = { where: {} };
|
|
853
|
-
/**
|
|
854
|
-
* Add a filter condition to your query.
|
|
855
|
-
* @example
|
|
856
|
-
* client.collection('users').where('age', '>=', 18).find()
|
|
857
|
-
*/
|
|
858
|
-
where(column, operator, value) {
|
|
859
|
-
if (!this.params.where) {
|
|
860
|
-
this.params.where = {};
|
|
861
|
-
}
|
|
862
|
-
const mappedOp = mapOperator(operator);
|
|
863
|
-
let formattedValue = value;
|
|
864
|
-
if (Array.isArray(value) && ["in", "nin", "cs", "csa"].includes(mappedOp)) {
|
|
865
|
-
formattedValue = `(${value.join(",")})`;
|
|
866
|
-
} else if (value === null) {
|
|
867
|
-
formattedValue = "null";
|
|
868
|
-
}
|
|
869
|
-
this.params.where[column] = mappedOp === "eq" ? String(formattedValue) : `${mappedOp}.${formattedValue}`;
|
|
870
|
-
return this;
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
* Order the results by a specific column.
|
|
874
|
-
* @example
|
|
875
|
-
* client.collection('users').orderBy('createdAt', 'desc').find()
|
|
876
|
-
*/
|
|
877
|
-
orderBy(column, ascending = "asc") {
|
|
878
|
-
this.params.orderBy = `${column}:${ascending}`;
|
|
879
|
-
return this;
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Limit the number of results returned.
|
|
883
|
-
*/
|
|
884
|
-
limit(count) {
|
|
885
|
-
this.params.limit = count;
|
|
886
|
-
return this;
|
|
887
|
-
}
|
|
888
|
-
/**
|
|
889
|
-
* Skip the first N results.
|
|
890
|
-
*/
|
|
891
|
-
offset(count) {
|
|
892
|
-
this.params.offset = count;
|
|
893
|
-
return this;
|
|
894
|
-
}
|
|
895
|
-
/**
|
|
896
|
-
* Set a free-text search string if supported by the backend.
|
|
897
|
-
*/
|
|
898
|
-
search(searchString) {
|
|
899
|
-
this.params.searchString = searchString;
|
|
900
|
-
return this;
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Include related entities in the response.
|
|
904
|
-
* Relations will be populated with full entity data instead of just IDs.
|
|
905
|
-
*
|
|
906
|
-
* @param relations - Relation names to include, or "*" for all.
|
|
907
|
-
* @example
|
|
908
|
-
* // Include specific relations
|
|
909
|
-
* client.data.posts.include("tags", "author").find()
|
|
910
|
-
*
|
|
911
|
-
* // Include all relations
|
|
912
|
-
* client.data.posts.include("*").find()
|
|
913
|
-
*/
|
|
914
|
-
include(...relations) {
|
|
915
|
-
this.params.include = relations;
|
|
916
|
-
return this;
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Execute the find query and return the results.
|
|
920
|
-
*/
|
|
921
|
-
async find() {
|
|
922
|
-
return this.collection.find(this.params);
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Listen to realtime updates matching this query.
|
|
926
|
-
*/
|
|
927
|
-
listen(onUpdate, onError) {
|
|
928
|
-
if (!this.collection.listen) {
|
|
929
|
-
throw new Error("Listen is only available when RebaseClient is configured with a websocketUrl.");
|
|
930
|
-
}
|
|
931
|
-
return this.collection.listen(this.params, onUpdate, onError);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
831
|
function parseWhereFilter(where) {
|
|
935
832
|
if (!where) return void 0;
|
|
936
833
|
const filters = {};
|
|
@@ -1083,22 +980,22 @@
|
|
|
1083
980
|
},
|
|
1084
981
|
// Fluent builder instantiation
|
|
1085
982
|
where(column, operator, value) {
|
|
1086
|
-
return new QueryBuilder(client).where(column, operator, value);
|
|
983
|
+
return new common.QueryBuilder(client).where(column, operator, value);
|
|
1087
984
|
},
|
|
1088
985
|
orderBy(column, ascending) {
|
|
1089
|
-
return new QueryBuilder(client).orderBy(column, ascending);
|
|
986
|
+
return new common.QueryBuilder(client).orderBy(column, ascending);
|
|
1090
987
|
},
|
|
1091
988
|
limit(count) {
|
|
1092
|
-
return new QueryBuilder(client).limit(count);
|
|
989
|
+
return new common.QueryBuilder(client).limit(count);
|
|
1093
990
|
},
|
|
1094
991
|
offset(count) {
|
|
1095
|
-
return new QueryBuilder(client).offset(count);
|
|
992
|
+
return new common.QueryBuilder(client).offset(count);
|
|
1096
993
|
},
|
|
1097
994
|
search(searchString) {
|
|
1098
|
-
return new QueryBuilder(client).search(searchString);
|
|
995
|
+
return new common.QueryBuilder(client).search(searchString);
|
|
1099
996
|
},
|
|
1100
997
|
include(...relations) {
|
|
1101
|
-
return new QueryBuilder(client).include(...relations);
|
|
998
|
+
return new common.QueryBuilder(client).include(...relations);
|
|
1102
999
|
}
|
|
1103
1000
|
};
|
|
1104
1001
|
if (ws) {
|
|
@@ -2282,6 +2179,10 @@
|
|
|
2282
2179
|
};
|
|
2283
2180
|
return target;
|
|
2284
2181
|
}
|
|
2182
|
+
Object.defineProperty(exports2, "QueryBuilder", {
|
|
2183
|
+
enumerable: true,
|
|
2184
|
+
get: () => common.QueryBuilder
|
|
2185
|
+
});
|
|
2285
2186
|
exports2.ApiError = ApiError;
|
|
2286
2187
|
exports2.RebaseApiError = RebaseApiError;
|
|
2287
2188
|
exports2.RebaseWebSocketClient = RebaseWebSocketClient;
|