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