@dashai/sdk 0.8.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 +146 -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 +146 -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-BLNQ1S1C.d.cts → types-BwlzFHbq.d.cts} +109 -1
- package/dist/{types-BLNQ1S1C.d.ts → types-BwlzFHbq.d.ts} +109 -1
- package/package.json +2 -3
package/dist/deps/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as Deps } from '../types-
|
|
2
|
-
export { R as ReadOnlyTableClient } from '../types-
|
|
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
|
/**
|
package/dist/deps/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as Deps } from '../types-
|
|
2
|
-
export { R as ReadOnlyTableClient } from '../types-
|
|
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
|
@@ -345,7 +345,7 @@ function createHttp(config) {
|
|
|
345
345
|
async function request(method, path, body) {
|
|
346
346
|
const normalizedPath = `/${path.replace(LEADING_SLASH, "")}`;
|
|
347
347
|
const url = normalizedPath.startsWith("/api/") ? `${config.baseUrl.replace(/\/+$/, "")}${normalizedPath}` : `${base}${normalizedPath}`;
|
|
348
|
-
const token = config.getToken ? await config.getToken() : null;
|
|
348
|
+
const token = (config.getToken ? await config.getToken() : null) ?? config.apiKey ?? null;
|
|
349
349
|
const headers = { ...staticHeaders };
|
|
350
350
|
if (body !== void 0) {
|
|
351
351
|
headers["Content-Type"] = "application/json";
|
|
@@ -529,6 +529,7 @@ function createClient(config) {
|
|
|
529
529
|
deps(providerSlug) {
|
|
530
530
|
return makeDeps(transport, providerSlug);
|
|
531
531
|
},
|
|
532
|
+
datahub: makeDatahubClient(transport),
|
|
532
533
|
request(method, path, body) {
|
|
533
534
|
return transport.request(method, path, body);
|
|
534
535
|
},
|
|
@@ -593,6 +594,148 @@ function assertValidTableSlug2(slug) {
|
|
|
593
594
|
);
|
|
594
595
|
}
|
|
595
596
|
}
|
|
597
|
+
function makeDatahubClient(transport) {
|
|
598
|
+
return {
|
|
599
|
+
table(tableId) {
|
|
600
|
+
assertValidTableId(tableId);
|
|
601
|
+
const root = `/datahub/tables/${tableId}/rows`;
|
|
602
|
+
return {
|
|
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() : "";
|
|
609
|
+
const path = qs ? `${root}?${qs}` : root;
|
|
610
|
+
return transport.request("GET", path);
|
|
611
|
+
},
|
|
612
|
+
async get(rowId) {
|
|
613
|
+
return transport.request(
|
|
614
|
+
"GET",
|
|
615
|
+
`${root}/${rowId}`
|
|
616
|
+
);
|
|
617
|
+
},
|
|
618
|
+
async create(body) {
|
|
619
|
+
return transport.request("POST", root, body);
|
|
620
|
+
},
|
|
621
|
+
async update(rowId, body) {
|
|
622
|
+
return transport.request(
|
|
623
|
+
"PATCH",
|
|
624
|
+
`${root}/${rowId}`,
|
|
625
|
+
body
|
|
626
|
+
);
|
|
627
|
+
},
|
|
628
|
+
async delete(rowId) {
|
|
629
|
+
return transport.request(
|
|
630
|
+
"DELETE",
|
|
631
|
+
`${root}/${rowId}`
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
function assertValidTableId(tableId) {
|
|
639
|
+
if (!Number.isInteger(tableId) || tableId <= 0) {
|
|
640
|
+
throw new Error(
|
|
641
|
+
`@dashai/sdk: invalid Data Hub table id "${tableId}". Must be a positive integer.`
|
|
642
|
+
);
|
|
643
|
+
}
|
|
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
|
+
}
|
|
596
739
|
function makeTableClient(transport, tableSlug) {
|
|
597
740
|
const root = `/db/${tableSlug}`;
|
|
598
741
|
return {
|
|
@@ -645,7 +788,7 @@ function createDevClient(overrides = {}) {
|
|
|
645
788
|
const moduleEntry = overrides.moduleSlug ? fileConfig?.modules?.[overrides.moduleSlug] : void 0;
|
|
646
789
|
const runtimeToken = readEnv("DASHWISE_RUNTIME_TOKEN") ?? moduleEntry?.runtimeToken ?? null;
|
|
647
790
|
const installationId = overrides.installationId ?? readEnv("DASHWISE_INSTALLATION_ID") ?? (runtimeToken !== null ? "sandbox" : "local");
|
|
648
|
-
const snapshotToken = runtimeToken ?? readEnv("DASHWISE_API_TOKEN") ?? fileConfig?.token ?? null;
|
|
791
|
+
const snapshotToken = runtimeToken ?? readEnv("DASHWISE_API_KEY") ?? readEnv("DASHWISE_API_TOKEN") ?? fileConfig?.token ?? null;
|
|
649
792
|
const resolvedGetToken = overrides.getToken ?? (() => snapshotToken);
|
|
650
793
|
return createClient({
|
|
651
794
|
...overrides,
|
|
@@ -703,7 +846,7 @@ function isPlausibleFileShape(v) {
|
|
|
703
846
|
}
|
|
704
847
|
|
|
705
848
|
// src/index.ts
|
|
706
|
-
var VERSION = "0.
|
|
849
|
+
var VERSION = "0.10.0" ;
|
|
707
850
|
|
|
708
851
|
exports.ContractViolationError = ContractViolationError;
|
|
709
852
|
exports.DashwiseError = DashwiseError;
|