@burdenoff/microfe-bigconsole 2026.1118.5 → 2026.1118.6

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.
@@ -0,0 +1,283 @@
1
+ import { AGGREGATES as e, COMPARISONS as t, aggregateAllowed as n, availableFields as r, emptyVisual as i, outputNames as a } from "./visualSql.js";
2
+ import { cloneElement as o, useId as s } from "react";
3
+ import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
4
+ // src/bigconsole/components/explore/VisualBuilder.tsx
5
+ var d = "rounded border border-border-default bg-bg-surface px-2 py-1 text-sm text-text-primary", f = d + " disabled:opacity-50";
6
+ function p({ label: e, children: t }) {
7
+ let n = s();
8
+ return /* @__PURE__ */ u("div", {
9
+ className: "flex flex-col gap-1 text-sm text-text-secondary",
10
+ children: [/* @__PURE__ */ l("label", {
11
+ htmlFor: n,
12
+ children: e
13
+ }), o(t, { id: n })]
14
+ });
15
+ }
16
+ function m({ label: e, value: t, options: n, first: r, onChange: i }) {
17
+ return /* @__PURE__ */ l(p, {
18
+ label: e,
19
+ children: /* @__PURE__ */ u("select", {
20
+ className: d,
21
+ value: t,
22
+ onChange: (e) => i(e.target.value),
23
+ children: [r !== void 0 && /* @__PURE__ */ l("option", {
24
+ value: "",
25
+ children: r
26
+ }), n.map((e) => /* @__PURE__ */ l("option", { children: e }, e))]
27
+ })
28
+ });
29
+ }
30
+ function h({ sources: o, value: s, onChange: h }) {
31
+ let g = (e) => h({
32
+ ...s,
33
+ ...e
34
+ }), _ = r(s, o), v = _.filter((e) => !e.masked), y = v.filter((e) => e.source === s.source), b = y.find((e) => e.ref === s.leftKey)?.type, x = v.filter((e) => e.source === s.join && e.type === b), S = (e, t) => g({ groups: t ? [...s.groups, e] : s.groups.filter((t) => t !== e) });
35
+ return /* @__PURE__ */ u("div", {
36
+ className: "space-y-4",
37
+ children: [
38
+ /* @__PURE__ */ u("div", {
39
+ className: "grid gap-3 sm:grid-cols-2",
40
+ children: [/* @__PURE__ */ l(p, {
41
+ label: "Source",
42
+ children: /* @__PURE__ */ u("select", {
43
+ className: d,
44
+ value: s.source,
45
+ onChange: (e) => h(i(e.target.value)),
46
+ children: [/* @__PURE__ */ l("option", {
47
+ value: "",
48
+ children: "Select a source"
49
+ }), o.map((e) => /* @__PURE__ */ l("option", {
50
+ value: e.id,
51
+ children: e.name
52
+ }, e.id))]
53
+ })
54
+ }), s.source && /* @__PURE__ */ l(p, {
55
+ label: "Join source",
56
+ children: /* @__PURE__ */ u("select", {
57
+ className: "rounded border border-border-default bg-bg-surface px-2 py-1 text-sm text-text-primary",
58
+ value: s.join,
59
+ onChange: (e) => h({
60
+ ...i(s.source),
61
+ join: e.target.value,
62
+ fields: s.fields.filter((e) => y.some((t) => t.ref === e))
63
+ }),
64
+ children: [/* @__PURE__ */ l("option", {
65
+ value: "",
66
+ children: "None"
67
+ }), o.filter((e) => e.id !== s.source).map((e) => /* @__PURE__ */ l("option", {
68
+ value: e.id,
69
+ children: e.name
70
+ }, e.id))]
71
+ })
72
+ })]
73
+ }),
74
+ s.join && /* @__PURE__ */ u("div", {
75
+ className: "flex flex-wrap gap-3",
76
+ children: [
77
+ /* @__PURE__ */ l(m, {
78
+ label: "Join type",
79
+ value: s.joinType,
80
+ options: ["INNER", "LEFT"],
81
+ onChange: (e) => g({ joinType: e })
82
+ }),
83
+ /* @__PURE__ */ l(m, {
84
+ label: "Left key",
85
+ value: s.leftKey,
86
+ options: y.map((e) => e.ref),
87
+ first: "Select field",
88
+ onChange: (e) => g({
89
+ leftKey: e,
90
+ rightKey: ""
91
+ })
92
+ }),
93
+ /* @__PURE__ */ l(m, {
94
+ label: "Right key",
95
+ value: s.rightKey,
96
+ options: x.map((e) => e.ref),
97
+ first: "Select matching type",
98
+ onChange: (e) => g({ rightKey: e })
99
+ })
100
+ ]
101
+ }),
102
+ s.source && /* @__PURE__ */ u(c, { children: [
103
+ /* @__PURE__ */ u("fieldset", { children: [/* @__PURE__ */ l("legend", {
104
+ className: "font-medium",
105
+ children: "Fields"
106
+ }), /* @__PURE__ */ l("div", {
107
+ className: "mt-1 flex flex-wrap gap-3",
108
+ children: _.map((e) => /* @__PURE__ */ u("label", {
109
+ className: "text-sm",
110
+ children: [
111
+ /* @__PURE__ */ l("input", {
112
+ type: "checkbox",
113
+ checked: s.fields.includes(e.ref),
114
+ onChange: (t) => g({
115
+ fields: t.target.checked ? [...s.fields, e.ref] : s.fields.filter((t) => t !== e.ref),
116
+ sort: ""
117
+ })
118
+ }),
119
+ " ",
120
+ e.ref,
121
+ e.masked ? " (masked)" : ""
122
+ ]
123
+ }, e.ref))
124
+ })] }),
125
+ /* @__PURE__ */ u("fieldset", {
126
+ className: "space-y-2",
127
+ children: [
128
+ /* @__PURE__ */ l("legend", {
129
+ className: "font-medium",
130
+ children: "Filters"
131
+ }),
132
+ s.filters.map((e, n) => {
133
+ let r = (e) => g({ filters: s.filters.map((t, r) => r === n ? {
134
+ ...t,
135
+ ...e
136
+ } : t) });
137
+ return /* @__PURE__ */ u("div", {
138
+ className: "flex flex-wrap items-end gap-2",
139
+ children: [
140
+ /* @__PURE__ */ l(m, {
141
+ label: "Filter field " + (n + 1),
142
+ value: e.field,
143
+ options: v.map((e) => e.ref),
144
+ first: "Select field",
145
+ onChange: (e) => r({
146
+ field: e,
147
+ value: ""
148
+ })
149
+ }),
150
+ /* @__PURE__ */ l(m, {
151
+ label: "Operator " + (n + 1),
152
+ value: e.op,
153
+ options: t,
154
+ onChange: (e) => r({ op: e })
155
+ }),
156
+ !e.op.startsWith("IS ") && /* @__PURE__ */ l(p, {
157
+ label: "Filter value " + (n + 1),
158
+ children: /* @__PURE__ */ l("input", {
159
+ className: "rounded border border-border-default bg-bg-surface px-2 py-1 text-sm text-text-primary",
160
+ value: e.value,
161
+ onChange: (e) => r({ value: e.target.value })
162
+ })
163
+ }),
164
+ /* @__PURE__ */ l("button", {
165
+ type: "button",
166
+ className: f,
167
+ "aria-label": "Remove filter " + (n + 1),
168
+ onClick: () => g({ filters: s.filters.filter((e, t) => t !== n) }),
169
+ children: "Remove"
170
+ })
171
+ ]
172
+ }, n);
173
+ }),
174
+ /* @__PURE__ */ l("button", {
175
+ type: "button",
176
+ className: f,
177
+ disabled: !v.length,
178
+ onClick: () => g({ filters: [...s.filters, {
179
+ field: "",
180
+ op: "=",
181
+ value: ""
182
+ }] }),
183
+ children: "Add filter"
184
+ })
185
+ ]
186
+ }),
187
+ /* @__PURE__ */ u("fieldset", {
188
+ className: "space-y-2",
189
+ children: [
190
+ /* @__PURE__ */ l("legend", {
191
+ className: "font-medium",
192
+ children: "Aggregates"
193
+ }),
194
+ s.aggregates.map((t, r) => {
195
+ let i = (e) => g({
196
+ aggregates: s.aggregates.map((t, n) => n === r ? {
197
+ ...t,
198
+ ...e
199
+ } : t),
200
+ sort: ""
201
+ });
202
+ return /* @__PURE__ */ u("div", {
203
+ className: "flex flex-wrap items-end gap-2",
204
+ children: [
205
+ /* @__PURE__ */ l(m, {
206
+ label: "Function " + (r + 1),
207
+ value: t.fn,
208
+ options: e,
209
+ onChange: (e) => i({
210
+ fn: e,
211
+ field: e === "COUNT" ? "*" : ""
212
+ })
213
+ }),
214
+ /* @__PURE__ */ l(m, {
215
+ label: "Aggregate field " + (r + 1),
216
+ value: t.field,
217
+ first: "Select field",
218
+ options: [...t.fn === "COUNT" ? ["*"] : [], ...v.filter((e) => n(t.fn, e.type)).map((e) => e.ref)],
219
+ onChange: (e) => i({ field: e })
220
+ }),
221
+ /* @__PURE__ */ l("button", {
222
+ type: "button",
223
+ className: f,
224
+ "aria-label": "Remove aggregate " + (r + 1),
225
+ onClick: () => g({
226
+ aggregates: s.aggregates.filter((e, t) => t !== r),
227
+ sort: ""
228
+ }),
229
+ children: "Remove"
230
+ })
231
+ ]
232
+ }, r);
233
+ }),
234
+ /* @__PURE__ */ l("button", {
235
+ type: "button",
236
+ className: f,
237
+ onClick: () => g({ aggregates: [...s.aggregates, {
238
+ fn: "COUNT",
239
+ field: "*"
240
+ }] }),
241
+ children: "Add aggregate"
242
+ })
243
+ ]
244
+ }),
245
+ /* @__PURE__ */ u("fieldset", { children: [/* @__PURE__ */ l("legend", {
246
+ className: "font-medium",
247
+ children: "Group by"
248
+ }), /* @__PURE__ */ l("div", {
249
+ className: "mt-1 flex flex-wrap gap-3",
250
+ children: v.map((e) => /* @__PURE__ */ u("label", {
251
+ className: "text-sm",
252
+ children: [
253
+ /* @__PURE__ */ l("input", {
254
+ type: "checkbox",
255
+ checked: s.groups.includes(e.ref),
256
+ "aria-label": "Group by " + e.ref,
257
+ onChange: (t) => S(e.ref, t.target.checked)
258
+ }),
259
+ " ",
260
+ e.ref
261
+ ]
262
+ }, e.ref))
263
+ })] }),
264
+ /* @__PURE__ */ u("div", {
265
+ className: "flex flex-wrap gap-3",
266
+ children: [/* @__PURE__ */ l(m, {
267
+ label: "Sort by",
268
+ value: s.sort,
269
+ first: "None",
270
+ options: a(s).filter((e, t) => t >= s.fields.length || v.some((e) => e.ref === s.fields[t])),
271
+ onChange: (e) => g({ sort: e })
272
+ }), s.sort && /* @__PURE__ */ l(m, {
273
+ label: "Direction",
274
+ value: s.direction,
275
+ options: ["ASC", "DESC"],
276
+ onChange: (e) => g({ direction: e })
277
+ })]
278
+ })
279
+ ] })
280
+ ]
281
+ });
282
+ }
283
+ export { p as Control, h as VisualBuilder, d as controlClass };
@@ -0,0 +1,32 @@
1
+ export declare function workspaceRequest(workspaceId: string, signal?: AbortSignal): {
2
+ requiredWorkspaceAuth: boolean;
3
+ requiredWorkspaceId: string;
4
+ queryDeduplication: boolean;
5
+ fetchOptions: {
6
+ signal: AbortSignal | undefined;
7
+ };
8
+ };
9
+ export declare function exploreError(error: unknown): string;
10
+ type Cell = string | boolean | number | null;
11
+ export interface QueryResult {
12
+ columns: string[];
13
+ rows: Cell[][];
14
+ truncated: boolean;
15
+ }
16
+ export declare function tabularResult(columns: string[], rows: unknown, truncated: boolean): QueryResult;
17
+ export declare function useExploreRun(workspaceId: string): {
18
+ run: (input: {
19
+ sql: string;
20
+ } | {
21
+ savedQueryId: string;
22
+ } | {
23
+ widgetId: string;
24
+ }) => Promise<void>;
25
+ cancel: () => Promise<void>;
26
+ running: boolean;
27
+ cancelling: boolean;
28
+ result: QueryResult | null;
29
+ error: string;
30
+ clearResult: () => void;
31
+ };
32
+ export {};
@@ -0,0 +1,104 @@
1
+ import { CancelExploreDocument as e, RunExploreDocument as t } from "../../../generated/wspace-operations.js";
2
+ import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
3
+ import { useApolloClient as o } from "@apollo/client/react";
4
+ import { CombinedGraphQLErrors as s } from "@apollo/client";
5
+ // src/bigconsole/components/explore/useExploreRun.ts
6
+ function c(e, t) {
7
+ return {
8
+ requiredWorkspaceAuth: !0,
9
+ requiredWorkspaceId: e,
10
+ queryDeduplication: !1,
11
+ fetchOptions: { signal: t }
12
+ };
13
+ }
14
+ var l = {
15
+ PERMISSION_DENIED: "You do not have permission to use this query or its sources.",
16
+ FORBIDDEN: "You do not have permission to use this query or its sources.",
17
+ INVALID_QUERY: "This SQL is invalid or uses an unsupported field or operation.",
18
+ SCHEMA_CHANGED: "A source schema changed. Review the query against the current schema and save a new definition.",
19
+ SOURCE_UNAVAILABLE: "A required source version is unavailable. Try again after ingestion completes.",
20
+ INVALID_DATA: "A source contains data that does not fit its declared schema.",
21
+ INPUT_LIMIT: "The query exceeds the input budget. Choose a smaller source.",
22
+ BUSY: "The query concurrency limit was reached. Try again shortly.",
23
+ CANCELLED: "Query cancelled.",
24
+ TIMEOUT: "The query timed out.",
25
+ ENGINE_UNAVAILABLE: "The query engine is unavailable. Try again shortly."
26
+ };
27
+ function u(e) {
28
+ if (s.is(e)) for (let t of e.errors) {
29
+ let e = t.extensions?.code;
30
+ if (typeof e == "string" && l[e]) return l[e];
31
+ }
32
+ return "The request could not be completed. Check your connection and try again.";
33
+ }
34
+ function d(e, t, n) {
35
+ if (!Array.isArray(t) || !t.every((t) => Array.isArray(t) && t.length === e.length && t.every((e) => e === null || [
36
+ "boolean",
37
+ "number",
38
+ "string"
39
+ ].includes(typeof e)))) throw Error("Invalid table response");
40
+ return {
41
+ columns: e,
42
+ rows: t,
43
+ truncated: n
44
+ };
45
+ }
46
+ function f(s) {
47
+ let l = o(), f = i(null), [p, m] = a(null), [h, g] = a(""), [_, v] = a(!1), [y, b] = a(!1), x = n((t) => l.mutate({
48
+ mutation: e,
49
+ variables: { requestId: t },
50
+ fetchPolicy: "no-cache",
51
+ context: c(s)
52
+ }), [l, s]);
53
+ return r(() => () => {
54
+ let e = f.current;
55
+ f.current = null, e && (e.controller.abort(), x(e.id).catch(() => {}));
56
+ }, [x]), {
57
+ run: n(async (e) => {
58
+ if (f.current) return;
59
+ let n = {
60
+ id: crypto.randomUUID(),
61
+ controller: new AbortController()
62
+ };
63
+ f.current = n, m(null), g(""), v(!0), b(!1);
64
+ try {
65
+ let r = await l.mutate({
66
+ mutation: t,
67
+ variables: {
68
+ requestId: n.id,
69
+ ...e
70
+ },
71
+ fetchPolicy: "no-cache",
72
+ context: c(s, n.controller.signal)
73
+ });
74
+ if (f.current !== n) return;
75
+ let i = r.data?.bigconsoleRunExplore;
76
+ if (!i) throw Error("Missing result");
77
+ m(d(i.columns, i.rows, i.truncated));
78
+ } catch (e) {
79
+ f.current === n && g(u(e));
80
+ } finally {
81
+ f.current === n && (f.current = null, v(!1), b(!1));
82
+ }
83
+ }, [l, s]),
84
+ cancel: async () => {
85
+ let e = f.current;
86
+ if (e) {
87
+ b(!0);
88
+ try {
89
+ await x(e.id);
90
+ } catch (t) {
91
+ f.current === e && (g(u(t)), b(!1));
92
+ }
93
+ }
94
+ },
95
+ running: _,
96
+ cancelling: y,
97
+ result: p,
98
+ error: h,
99
+ clearResult: () => {
100
+ m(null), g("");
101
+ }
102
+ };
103
+ }
104
+ export { u as exploreError, d as tabularResult, f as useExploreRun, c as workspaceRequest };
@@ -0,0 +1,49 @@
1
+ export interface ExploreField {
2
+ id: string;
3
+ name: string;
4
+ type: string;
5
+ masked: boolean;
6
+ nullable: boolean;
7
+ }
8
+ export interface ExploreSource {
9
+ id: string;
10
+ name: string;
11
+ fields: readonly ExploreField[];
12
+ }
13
+ export declare const AGGREGATES: readonly ["COUNT", "SUM", "AVG", "MIN", "MAX"];
14
+ export declare const COMPARISONS: readonly ["=", "<>", "<", "<=", ">", ">=", "IS NULL", "IS NOT NULL"];
15
+ export type Aggregate = (typeof AGGREGATES)[number];
16
+ export type Comparison = (typeof COMPARISONS)[number];
17
+ export interface VisualQuery {
18
+ source: string;
19
+ join: string;
20
+ joinType: 'INNER' | 'LEFT';
21
+ leftKey: string;
22
+ rightKey: string;
23
+ fields: string[];
24
+ aggregates: {
25
+ fn: Aggregate;
26
+ field: string;
27
+ }[];
28
+ groups: string[];
29
+ filters: {
30
+ field: string;
31
+ op: Comparison;
32
+ value: string;
33
+ }[];
34
+ sort: string;
35
+ direction: 'ASC' | 'DESC';
36
+ }
37
+ export declare function emptyVisual(source?: string): VisualQuery;
38
+ export declare function availableFields(query: VisualQuery, sources: readonly ExploreSource[]): {
39
+ ref: string;
40
+ source: string;
41
+ id: string;
42
+ name: string;
43
+ type: string;
44
+ masked: boolean;
45
+ nullable: boolean;
46
+ }[];
47
+ export declare function aggregateAllowed(fn: Aggregate, type: string): boolean;
48
+ export declare function outputNames(query: VisualQuery): string[];
49
+ export declare function visualSql(query: VisualQuery, sources: readonly ExploreSource[]): string;
@@ -0,0 +1,95 @@
1
+ // src/bigconsole/components/explore/visualSql.ts
2
+ var e = [
3
+ "COUNT",
4
+ "SUM",
5
+ "AVG",
6
+ "MIN",
7
+ "MAX"
8
+ ], t = [
9
+ "=",
10
+ "<>",
11
+ "<",
12
+ "<=",
13
+ ">",
14
+ ">=",
15
+ "IS NULL",
16
+ "IS NOT NULL"
17
+ ];
18
+ function n(e = "") {
19
+ return {
20
+ source: e,
21
+ join: "",
22
+ joinType: "INNER",
23
+ leftKey: "",
24
+ rightKey: "",
25
+ fields: [],
26
+ aggregates: [],
27
+ groups: [],
28
+ filters: [],
29
+ sort: "",
30
+ direction: "ASC"
31
+ };
32
+ }
33
+ function r(e, t) {
34
+ return t.filter((t) => t.id === e.source || t.id === e.join).flatMap((e) => e.fields.map((t) => ({
35
+ ...t,
36
+ ref: e.name + "." + t.name,
37
+ source: e.id
38
+ })));
39
+ }
40
+ var i = (e) => "\"" + e.replaceAll("\"", "\"\"") + "\"", a = (e) => e.split(".").map(i).join("."), o = (e) => /^(?:DECIMAL(?:\(\d+,\s*\d+\))?|BIGINT|INTEGER|INT64)$/i.test(e);
41
+ function s(e, t) {
42
+ return e === "COUNT" || e !== "SUM" && e !== "AVG" || o(t);
43
+ }
44
+ function c(e) {
45
+ let t = e.fields.map((e) => e.split(".").pop()), n = /* @__PURE__ */ new Set();
46
+ return [...t, ...e.aggregates.map((e) => (e.fn.toLowerCase() + "_" + (e.field.split(".").pop() || "rows")).replace("*", "rows"))].map((e) => {
47
+ let t = e.slice(0, 55), r = t;
48
+ for (let e = 2; n.has(r); e++) r = t + "_" + e;
49
+ return n.add(r), r;
50
+ });
51
+ }
52
+ function l(e, t) {
53
+ let n = t.find((t) => t.id === e.source);
54
+ if (!n) return "";
55
+ let l = r(e, t), u = (e) => l.find((t) => t.ref === e), d = (e) => !!u(e) && !u(e)?.masked, f = c(e);
56
+ if (!f.length || e.fields.some((e) => !u(e)) || (e.aggregates.length || e.groups.length) && (e.fields.some((t) => !e.groups.includes(t) || !d(t)) || e.groups.some((e) => !d(e)))) return "";
57
+ let p = e.fields.map((e, t) => a(e) + " AS " + i(f[t]));
58
+ for (let [t, n] of e.aggregates.entries()) {
59
+ let r = u(n.field);
60
+ if (n.field === "*" ? n.fn !== "COUNT" : !r || r.masked || !s(n.fn, r.type)) return "";
61
+ p.push(n.fn + "(" + (n.field === "*" ? "*" : a(n.field)) + ") AS " + i(f[e.fields.length + t]));
62
+ }
63
+ let m = ["SELECT " + p.join(", "), "FROM " + i(n.name)];
64
+ if (e.join) {
65
+ let r = t.find((t) => t.id === e.join), o = u(e.leftKey), s = u(e.rightKey);
66
+ if (!r || r.id === n.id || !o || !s || o.source !== n.id || s.source !== r.id || o.type !== s.type || o.masked || s.masked) return "";
67
+ m.push(e.joinType + " JOIN " + i(r.name) + " ON " + a(o.ref) + " = " + a(s.ref));
68
+ }
69
+ let h = [];
70
+ for (let t of e.filters) {
71
+ let e = u(t.field);
72
+ if (!e || e.masked) return "";
73
+ let n = a(e.ref) + " " + t.op;
74
+ if (t.op === "IS NULL" || t.op === "IS NOT NULL") {
75
+ h.push(n);
76
+ continue;
77
+ }
78
+ let r;
79
+ if (o(e.type)) {
80
+ if (!/^-?\d+(?:\.\d+)?$/.test(t.value)) return "";
81
+ r = t.value;
82
+ } else if (e.type.toUpperCase() === "BOOLEAN") {
83
+ if (!/^(true|false)$/i.test(t.value)) return "";
84
+ r = t.value.toUpperCase();
85
+ } else r = "'" + t.value.replaceAll("'", "''") + "'";
86
+ h.push(n + " " + r);
87
+ }
88
+ if (h.length && m.push("WHERE " + h.join(" AND ")), e.groups.length && m.push("GROUP BY " + e.groups.map(a).join(", ")), e.sort) {
89
+ let t = f.indexOf(e.sort);
90
+ if (t < 0 || t < e.fields.length && !d(e.fields[t])) return "";
91
+ m.push("ORDER BY " + i(e.sort) + " " + e.direction);
92
+ }
93
+ return m.join("\n");
94
+ }
95
+ export { e as AGGREGATES, t as COMPARISONS, s as aggregateAllowed, r as availableFields, n as emptyVisual, c as outputNames, l as visualSql };