@dashai/sdk 0.9.0 → 0.10.0

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.
@@ -1,5 +1,5 @@
1
- import { D as Deps } from '../types-DXsbCVkb.cjs';
2
- export { R as ReadOnlyTableClient } from '../types-DXsbCVkb.cjs';
1
+ import { D as Deps } from '../types-BwlzFHbq.cjs';
2
+ export { R as ReadOnlyTableClient } from '../types-BwlzFHbq.cjs';
3
3
  export { D as DependencyContractError, O as OperationNotAllowedByProviderError, P as ProviderTableMissingError } from '../errors-BV75u7b9.cjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { D as Deps } from '../types-DXsbCVkb.js';
2
- export { R as ReadOnlyTableClient } from '../types-DXsbCVkb.js';
1
+ import { D as Deps } from '../types-BwlzFHbq.js';
2
+ export { R as ReadOnlyTableClient } from '../types-BwlzFHbq.js';
3
3
  export { D as DependencyContractError, O as OperationNotAllowedByProviderError, P as ProviderTableMissingError } from '../errors-BV75u7b9.js';
4
4
 
5
5
  /**
package/dist/index.cjs CHANGED
@@ -600,8 +600,12 @@ function makeDatahubClient(transport) {
600
600
  assertValidTableId(tableId);
601
601
  const root = `/datahub/tables/${tableId}/rows`;
602
602
  return {
603
- async list(query) {
604
- const qs = query ? new URLSearchParams(query).toString() : "";
603
+ async list(opts) {
604
+ const arg = opts;
605
+ const flat = isDatahubListOpts(
606
+ arg
607
+ ) ? compileDatahubListOpts(arg) : arg;
608
+ const qs = flat ? new URLSearchParams(flat).toString() : "";
605
609
  const path = qs ? `${root}?${qs}` : root;
606
610
  return transport.request("GET", path);
607
611
  },
@@ -638,6 +642,100 @@ function assertValidTableId(tableId) {
638
642
  );
639
643
  }
640
644
  }
645
+ var DATAHUB_LIST_OPT_KEYS = /* @__PURE__ */ new Set([
646
+ "filter",
647
+ "sort",
648
+ "search",
649
+ "limit",
650
+ "page"
651
+ ]);
652
+ var FILTER_GROUP_KEYS = /* @__PURE__ */ new Set(["AND", "OR"]);
653
+ function isDatahubListOpts(opts) {
654
+ if (opts === void 0 || opts === null || typeof opts !== "object") {
655
+ return false;
656
+ }
657
+ return Object.keys(opts).some((k) => DATAHUB_LIST_OPT_KEYS.has(k));
658
+ }
659
+ function compileDatahubListOpts(opts) {
660
+ const out = {};
661
+ if (opts.filter !== void 0) {
662
+ const where = opts.filter;
663
+ if (hasFilterGrouping(where)) {
664
+ out.filters = JSON.stringify(whereToBackendTree(where));
665
+ } else {
666
+ for (const [field, value] of Object.entries(where)) {
667
+ if (value === void 0) continue;
668
+ if (isFilterOpsObject(value)) {
669
+ for (const [op, opValue] of Object.entries(value)) {
670
+ if (opValue === void 0) continue;
671
+ out[`filter__${field}__${op}`] = stringifyFilterValue(opValue);
672
+ }
673
+ } else {
674
+ out[`filter__${field}__equal`] = stringifyFilterValue(value);
675
+ }
676
+ }
677
+ }
678
+ }
679
+ if (opts.sort !== void 0 && opts.sort.length > 0) {
680
+ out.order_by = opts.sort.map(
681
+ (s) => s.dir === "desc" ? `-${s.field}` : s.field
682
+ ).join(",");
683
+ }
684
+ if (opts.search !== void 0) out.search = opts.search;
685
+ if (typeof opts.limit === "number") out.size = String(opts.limit);
686
+ if (typeof opts.page === "number") out.page = String(opts.page);
687
+ if (opts.filter !== void 0 || opts.sort !== void 0 && opts.sort.length > 0) {
688
+ out.user_field_names = "true";
689
+ }
690
+ return out;
691
+ }
692
+ function hasFilterGrouping(where) {
693
+ return Object.keys(where).some((k) => FILTER_GROUP_KEYS.has(k));
694
+ }
695
+ function isFilterGroupNode(node) {
696
+ return Object.keys(node).some((k) => FILTER_GROUP_KEYS.has(k));
697
+ }
698
+ function fieldLeaves(node) {
699
+ const leaves = [];
700
+ for (const [field, value] of Object.entries(node)) {
701
+ if (FILTER_GROUP_KEYS.has(field) || value === void 0) continue;
702
+ if (isFilterOpsObject(value)) {
703
+ for (const [op, opValue] of Object.entries(value)) {
704
+ if (opValue === void 0) continue;
705
+ leaves.push({ field, type: op, value: stringifyFilterValue(opValue) });
706
+ }
707
+ } else {
708
+ leaves.push({ field, type: "equal", value: stringifyFilterValue(value) });
709
+ }
710
+ }
711
+ return leaves;
712
+ }
713
+ function whereToBackendTree(where, defaultType = "AND") {
714
+ const obj = where;
715
+ const groupKey = Object.keys(obj).find((k) => FILTER_GROUP_KEYS.has(k));
716
+ if (groupKey) {
717
+ const children = obj[groupKey] ?? [];
718
+ const filters = [];
719
+ const filter_groups = [];
720
+ for (const child of children) {
721
+ const childObj = child;
722
+ if (isFilterGroupNode(childObj)) {
723
+ filter_groups.push(whereToBackendTree(child));
724
+ } else {
725
+ filters.push(...fieldLeaves(childObj));
726
+ }
727
+ }
728
+ return { filter_type: groupKey, filters, filter_groups };
729
+ }
730
+ return { filter_type: defaultType, filters: fieldLeaves(obj), filter_groups: [] };
731
+ }
732
+ function isFilterOpsObject(value) {
733
+ return typeof value === "object" && value !== null && !Array.isArray(value);
734
+ }
735
+ function stringifyFilterValue(value) {
736
+ if (value === null) return "";
737
+ return String(value);
738
+ }
641
739
  function makeTableClient(transport, tableSlug) {
642
740
  const root = `/db/${tableSlug}`;
643
741
  return {
@@ -748,7 +846,7 @@ function isPlausibleFileShape(v) {
748
846
  }
749
847
 
750
848
  // src/index.ts
751
- var VERSION = "0.9.0" ;
849
+ var VERSION = "0.10.0" ;
752
850
 
753
851
  exports.ContractViolationError = ContractViolationError;
754
852
  exports.DashwiseError = DashwiseError;