@rebasepro/client 0.2.1 → 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/dist/collection.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +3 -110
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +12 -118
- package/dist/index.umd.js.map +1 -1
- package/dist/query_builder.d.ts +1 -53
- package/package.json +4 -3
- package/src/collection.ts +2 -2
- package/src/index.ts +1 -0
- package/src/query_builder.ts +1 -125
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) {
|
|
@@ -819,116 +821,6 @@ function createCron(transport, options) {
|
|
|
819
821
|
toggleJob
|
|
820
822
|
};
|
|
821
823
|
}
|
|
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
824
|
function parseWhereFilter(where) {
|
|
933
825
|
if (!where) return void 0;
|
|
934
826
|
const filters = {};
|
|
@@ -2282,6 +2174,7 @@ function createRebaseClient(options) {
|
|
|
2282
2174
|
}
|
|
2283
2175
|
export {
|
|
2284
2176
|
ApiError,
|
|
2177
|
+
QueryBuilder2 as QueryBuilder,
|
|
2285
2178
|
RebaseApiError,
|
|
2286
2179
|
RebaseWebSocketClient,
|
|
2287
2180
|
buildQueryString,
|