@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/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) {
@@ -821,116 +821,6 @@
821
821
  toggleJob
822
822
  };
823
823
  }
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
824
  function parseWhereFilter(where) {
935
825
  if (!where) return void 0;
936
826
  const filters = {};
@@ -1083,22 +973,22 @@
1083
973
  },
1084
974
  // Fluent builder instantiation
1085
975
  where(column, operator, value) {
1086
- return new QueryBuilder(client).where(column, operator, value);
976
+ return new common.QueryBuilder(client).where(column, operator, value);
1087
977
  },
1088
978
  orderBy(column, ascending) {
1089
- return new QueryBuilder(client).orderBy(column, ascending);
979
+ return new common.QueryBuilder(client).orderBy(column, ascending);
1090
980
  },
1091
981
  limit(count) {
1092
- return new QueryBuilder(client).limit(count);
982
+ return new common.QueryBuilder(client).limit(count);
1093
983
  },
1094
984
  offset(count) {
1095
- return new QueryBuilder(client).offset(count);
985
+ return new common.QueryBuilder(client).offset(count);
1096
986
  },
1097
987
  search(searchString) {
1098
- return new QueryBuilder(client).search(searchString);
988
+ return new common.QueryBuilder(client).search(searchString);
1099
989
  },
1100
990
  include(...relations) {
1101
- return new QueryBuilder(client).include(...relations);
991
+ return new common.QueryBuilder(client).include(...relations);
1102
992
  }
1103
993
  };
1104
994
  if (ws) {
@@ -2282,6 +2172,10 @@
2282
2172
  };
2283
2173
  return target;
2284
2174
  }
2175
+ Object.defineProperty(exports2, "QueryBuilder", {
2176
+ enumerable: true,
2177
+ get: () => common.QueryBuilder
2178
+ });
2285
2179
  exports2.ApiError = ApiError;
2286
2180
  exports2.RebaseApiError = RebaseApiError;
2287
2181
  exports2.RebaseWebSocketClient = RebaseWebSocketClient;