@burdenoff/microfe-semanticfed 2026.1031.2 → 2026.1031.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/semanticfed/api/quotaRefusal.js +2 -1
- package/dist/semanticfed/api/quotaRefusal.js.map +1 -1
- package/dist/semanticfed/api/semanticfedGraphql.js +20 -11
- package/dist/semanticfed/api/semanticfedGraphql.js.map +1 -1
- package/dist/semanticfed/hooks/useSqlConsole.js +23 -20
- package/dist/semanticfed/hooks/useSqlConsole.js.map +1 -1
- package/dist/semanticfed/pages/QueryConsolePage.js +148 -148
- package/dist/semanticfed/pages/QueryConsolePage.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,8 @@ var e = "burdenoff:upgrade-prompt", t = ["QUOTA_EXHAUSTED", "QUOTA_NOT_PROVISION
|
|
|
4
4
|
semCreateDataSource: "semanticfed.sources.count",
|
|
5
5
|
semCreateModel: "semanticfed.models.count",
|
|
6
6
|
semPublishQuery: "semanticfed.queries.published",
|
|
7
|
-
semRunQuery: "semanticfed.query_runs.monthly"
|
|
7
|
+
semRunQuery: "semanticfed.query_runs.monthly",
|
|
8
|
+
semExecuteSql: "semanticfed.query_runs.monthly"
|
|
8
9
|
};
|
|
9
10
|
function r(e) {
|
|
10
11
|
return typeof e == "string" && t.includes(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotaRefusal.js","names":[],"sources":["../../../src/semanticfed/api/quotaRefusal.ts"],"sourcesContent":["/**\n * Plan-limit refusals from the workspace gateway (BOFF-3172).\n *\n * SemanticFed's billable mutations carry `@usage(checkQuota: true)`. When a\n * workspace has used up its plan's allowance the gateway refuses the call\n * before the resolver runs, with HTTP 429 and a GraphQL error whose\n * `extensions.code` is `QUOTA_EXHAUSTED` (or `QUOTA_NOT_PROVISIONED` when the\n * workspace holds no SemanticFed plan rows at all). The refusal names the\n * mutation in `extensions.field`, not the quota, so this module maps the field\n * back to its quota name.\n *\n * The refusal is announced on the shell's `burdenoff:upgrade-prompt` window\n * event, which the host shell answers with the shared `UpgradePromptModal`\n * (its CTA leads to the plan picker). The event is a plain DOM contract, so the\n * microfrontend does not import the modal or depend on the host's fe-libs\n * version.\n */\n\n/** Window event the host shell's `UpgradePromptModal` listens for. */\nconst UPGRADE_PROMPT_EVENT = 'burdenoff:upgrade-prompt';\n\nconst QUOTA_REFUSAL_CODES = ['QUOTA_EXHAUSTED', 'QUOTA_NOT_PROVISIONED'] as const;\n\ntype QuotaRefusalCode = (typeof QUOTA_REFUSAL_CODES)[number];\n\n/**\n * Billable SemanticFed mutation -> the quota its `@usage` directive charges.\n * Must match `wspace-semanticfed-svc` (src/utils/usage-billing.ts).\n */\nconst SEMANTICFED_QUOTA_BY_FIELD: Readonly<Record<string, string>> = {\n semCreateConnector: 'semanticfed.connectors.count',\n semCreateDataSource: 'semanticfed.sources.count',\n semCreateModel: 'semanticfed.models.count',\n semPublishQuery: 'semanticfed.queries.published',\n semRunQuery: 'semanticfed.query_runs.monthly',\n};\n\nexport interface QuotaRefusal {\n code: QuotaRefusalCode;\n /** Mutation the gateway refused, when it said. */\n field?: string;\n /** Quota the refused mutation charges, when the field is a known one. */\n quotaName?: string;\n /** Units left on the quota (absent when the quota was never provisioned). */\n limitLeft?: number;\n}\n\ninterface GraphQLErrorLike {\n message?: string;\n extensions?: Record<string, unknown> | null;\n}\n\nfunction isQuotaRefusalCode(value: unknown): value is QuotaRefusalCode {\n return typeof value === 'string' && (QUOTA_REFUSAL_CODES as readonly string[]).includes(value);\n}\n\n/** The first plan-limit refusal among GraphQL errors, or null. */\nexport function findQuotaRefusal(\n errors: readonly GraphQLErrorLike[] | undefined\n): QuotaRefusal | null {\n for (const error of errors ?? []) {\n const ext = error.extensions;\n if (!ext || !isQuotaRefusalCode(ext.code)) continue;\n const field = typeof ext.field === 'string' ? ext.field : undefined;\n const quotaName =\n typeof ext.quotaName === 'string'\n ? ext.quotaName\n : field !== undefined\n ? SEMANTICFED_QUOTA_BY_FIELD[field]\n : undefined;\n return {\n code: ext.code,\n field,\n quotaName,\n limitLeft: typeof ext.limitLeft === 'number' ? ext.limitLeft : undefined,\n };\n }\n return null;\n}\n\n/**\n * Ask the host shell to show its upgrade prompt for a refusal. The quota name\n * is passed as the `resource`, which the shell translates into the limited\n * resource's name. Safe no-op outside a browser.\n */\nexport function announceQuotaRefusal(refusal: QuotaRefusal): void {\n if (typeof window === 'undefined') return;\n window.dispatchEvent(\n new CustomEvent(UPGRADE_PROMPT_EVENT, {\n detail: {\n extensions: {\n code: refusal.code,\n field: refusal.field,\n quotaName: refusal.quotaName,\n resource: refusal.quotaName ?? refusal.field,\n limitLeft: refusal.limitLeft,\n },\n },\n })\n );\n}\n\n/** Error thrown by `semRequest` for a plan-limit refusal. */\nexport class SemQuotaError extends Error {\n readonly refusal: QuotaRefusal;\n\n constructor(message: string, refusal: QuotaRefusal) {\n super(message);\n this.name = 'SemQuotaError';\n this.refusal = refusal;\n }\n}\n"],"mappings":";AAmBA,IAAM,IAAuB,4BAEvB,IAAsB,CAAC,mBAAmB,wBAAwB,EAQlE,IAA+D;CACnE,oBAAoB;CACpB,qBAAqB;CACrB,gBAAgB;CAChB,iBAAiB;CACjB,aAAa;
|
|
1
|
+
{"version":3,"file":"quotaRefusal.js","names":[],"sources":["../../../src/semanticfed/api/quotaRefusal.ts"],"sourcesContent":["/**\n * Plan-limit refusals from the workspace gateway (BOFF-3172).\n *\n * SemanticFed's billable mutations carry `@usage(checkQuota: true)`. When a\n * workspace has used up its plan's allowance the gateway refuses the call\n * before the resolver runs, with HTTP 429 and a GraphQL error whose\n * `extensions.code` is `QUOTA_EXHAUSTED` (or `QUOTA_NOT_PROVISIONED` when the\n * workspace holds no SemanticFed plan rows at all). The refusal names the\n * mutation in `extensions.field`, not the quota, so this module maps the field\n * back to its quota name.\n *\n * The refusal is announced on the shell's `burdenoff:upgrade-prompt` window\n * event, which the host shell answers with the shared `UpgradePromptModal`\n * (its CTA leads to the plan picker). The event is a plain DOM contract, so the\n * microfrontend does not import the modal or depend on the host's fe-libs\n * version.\n */\n\n/** Window event the host shell's `UpgradePromptModal` listens for. */\nconst UPGRADE_PROMPT_EVENT = 'burdenoff:upgrade-prompt';\n\nconst QUOTA_REFUSAL_CODES = ['QUOTA_EXHAUSTED', 'QUOTA_NOT_PROVISIONED'] as const;\n\ntype QuotaRefusalCode = (typeof QUOTA_REFUSAL_CODES)[number];\n\n/**\n * Billable SemanticFed mutation -> the quota its `@usage` directive charges.\n * Must match `wspace-semanticfed-svc` (src/utils/usage-billing.ts).\n */\nconst SEMANTICFED_QUOTA_BY_FIELD: Readonly<Record<string, string>> = {\n semCreateConnector: 'semanticfed.connectors.count',\n semCreateDataSource: 'semanticfed.sources.count',\n semCreateModel: 'semanticfed.models.count',\n semPublishQuery: 'semanticfed.queries.published',\n semRunQuery: 'semanticfed.query_runs.monthly',\n // An ad-hoc SQL statement is metered as a query run (BOFF-4271).\n semExecuteSql: 'semanticfed.query_runs.monthly',\n};\n\nexport interface QuotaRefusal {\n code: QuotaRefusalCode;\n /** Mutation the gateway refused, when it said. */\n field?: string;\n /** Quota the refused mutation charges, when the field is a known one. */\n quotaName?: string;\n /** Units left on the quota (absent when the quota was never provisioned). */\n limitLeft?: number;\n}\n\ninterface GraphQLErrorLike {\n message?: string;\n extensions?: Record<string, unknown> | null;\n}\n\nfunction isQuotaRefusalCode(value: unknown): value is QuotaRefusalCode {\n return typeof value === 'string' && (QUOTA_REFUSAL_CODES as readonly string[]).includes(value);\n}\n\n/** The first plan-limit refusal among GraphQL errors, or null. */\nexport function findQuotaRefusal(\n errors: readonly GraphQLErrorLike[] | undefined\n): QuotaRefusal | null {\n for (const error of errors ?? []) {\n const ext = error.extensions;\n if (!ext || !isQuotaRefusalCode(ext.code)) continue;\n const field = typeof ext.field === 'string' ? ext.field : undefined;\n const quotaName =\n typeof ext.quotaName === 'string'\n ? ext.quotaName\n : field !== undefined\n ? SEMANTICFED_QUOTA_BY_FIELD[field]\n : undefined;\n return {\n code: ext.code,\n field,\n quotaName,\n limitLeft: typeof ext.limitLeft === 'number' ? ext.limitLeft : undefined,\n };\n }\n return null;\n}\n\n/**\n * Ask the host shell to show its upgrade prompt for a refusal. The quota name\n * is passed as the `resource`, which the shell translates into the limited\n * resource's name. Safe no-op outside a browser.\n */\nexport function announceQuotaRefusal(refusal: QuotaRefusal): void {\n if (typeof window === 'undefined') return;\n window.dispatchEvent(\n new CustomEvent(UPGRADE_PROMPT_EVENT, {\n detail: {\n extensions: {\n code: refusal.code,\n field: refusal.field,\n quotaName: refusal.quotaName,\n resource: refusal.quotaName ?? refusal.field,\n limitLeft: refusal.limitLeft,\n },\n },\n })\n );\n}\n\n/** Error thrown by `semRequest` for a plan-limit refusal. */\nexport class SemQuotaError extends Error {\n readonly refusal: QuotaRefusal;\n\n constructor(message: string, refusal: QuotaRefusal) {\n super(message);\n this.name = 'SemQuotaError';\n this.refusal = refusal;\n }\n}\n"],"mappings":";AAmBA,IAAM,IAAuB,4BAEvB,IAAsB,CAAC,mBAAmB,wBAAwB,EAQlE,IAA+D;CACnE,oBAAoB;CACpB,qBAAqB;CACrB,gBAAgB;CAChB,iBAAiB;CACjB,aAAa;CAEb,eAAe;CAChB;AAiBD,SAAS,EAAmB,GAA2C;AACrE,QAAO,OAAO,KAAU,YAAa,EAA0C,SAAS,EAAM;;AAIhG,SAAgB,EACd,GACqB;AACrB,MAAK,IAAM,KAAS,KAAU,EAAE,EAAE;EAChC,IAAM,IAAM,EAAM;AAClB,MAAI,CAAC,KAAO,CAAC,EAAmB,EAAI,KAAK,CAAE;EAC3C,IAAM,IAAQ,OAAO,EAAI,SAAU,WAAW,EAAI,QAAQ,KAAA,GACpD,IACJ,OAAO,EAAI,aAAc,WACrB,EAAI,YACJ,MAAU,KAAA,IAER,KAAA,IADA,EAA2B;AAEnC,SAAO;GACL,MAAM,EAAI;GACV;GACA;GACA,WAAW,OAAO,EAAI,aAAc,WAAW,EAAI,YAAY,KAAA;GAChE;;AAEH,QAAO;;AAQT,SAAgB,EAAqB,GAA6B;AAC5D,QAAO,SAAW,OACtB,OAAO,cACL,IAAI,YAAY,GAAsB,EACpC,QAAQ,EACN,YAAY;EACV,MAAM,EAAQ;EACd,OAAO,EAAQ;EACf,WAAW,EAAQ;EACnB,UAAU,EAAQ,aAAa,EAAQ;EACvC,WAAW,EAAQ;EACpB,EACF,EACF,CAAC,CACH;;AAIH,IAAa,IAAb,cAAmC,MAAM;CACvC;CAEA,YAAY,GAAiB,GAAuB;AAGlD,EAFA,MAAM,EAAQ,EACd,KAAK,OAAO,iBACZ,KAAK,UAAU"}
|
|
@@ -5,22 +5,31 @@ function i() {
|
|
|
5
5
|
let e = globalThis;
|
|
6
6
|
e.__graphqlFetchResponseCache?.clear(), e.__graphqlFetchPendingResponses?.clear(), e.__boffGraphQLResponseCache?.clear();
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var a = class extends Error {
|
|
9
|
+
code;
|
|
10
|
+
detail;
|
|
11
|
+
constructor(e, t, n) {
|
|
12
|
+
super(e), this.name = "SemRequestError", this.code = t, this.detail = n;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
async function o(o, s = {}, c) {
|
|
16
|
+
let l = await r({
|
|
10
17
|
gateway: "workspace",
|
|
11
|
-
baseUrl:
|
|
12
|
-
query:
|
|
13
|
-
variables:
|
|
18
|
+
baseUrl: c,
|
|
19
|
+
query: o,
|
|
20
|
+
variables: s,
|
|
14
21
|
workspaceToken: !0
|
|
15
22
|
});
|
|
16
|
-
if (
|
|
17
|
-
let r = n(
|
|
18
|
-
|
|
23
|
+
if (l.errors?.length) {
|
|
24
|
+
let r = n(l.errors);
|
|
25
|
+
if (r) throw t(r), new e(l.errors[0]?.message ?? "Plan limit reached", r);
|
|
26
|
+
let i = l.errors[0], o = i && typeof i == "object" && "extensions" in i && i.extensions ? i.extensions : {};
|
|
27
|
+
throw new a(i?.message ?? "GraphQL request failed", typeof o.code == "string" ? o.code : void 0, typeof o.technicalMessage == "string" ? o.technicalMessage : void 0);
|
|
19
28
|
}
|
|
20
|
-
if (!
|
|
21
|
-
return /^\s*mutation\b/.test(
|
|
29
|
+
if (!l.data) throw Error("GraphQL response did not include data");
|
|
30
|
+
return /^\s*mutation\b/.test(o) && i(), l.data;
|
|
22
31
|
}
|
|
23
32
|
//#endregion
|
|
24
|
-
export { a as semRequest };
|
|
33
|
+
export { a as SemRequestError, o as semRequest };
|
|
25
34
|
|
|
26
35
|
//# sourceMappingURL=semanticfedGraphql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semanticfedGraphql.js","names":[],"sources":["../../../src/semanticfed/api/semanticfedGraphql.ts"],"sourcesContent":["/**\n * SemanticFed GraphQL transport.\n *\n * Every call goes to the workspace gateway with a workspace-scoped token,\n * both supplied by the host shell (`graphqlFetch({ gateway: 'workspace',\n * workspaceToken: true })`). Operations are inline documents whose fields\n * match the `wspace-semanticfed-svc` subgraph schema exactly.\n */\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { announceQuotaRefusal, findQuotaRefusal, SemQuotaError } from './quotaRefusal';\n\n/**\n * fe-libs `graphqlFetch` coalesces query responses in short-lived in-memory\n * caches. A read issued right after a write would otherwise return the\n * pre-mutation response, so every mutation clears those caches.\n */\ntype GraphqlReadCacheGlobals = {\n __graphqlFetchResponseCache?: { clear: () => void };\n __graphqlFetchPendingResponses?: { clear: () => void };\n __boffGraphQLResponseCache?: { clear: () => void };\n};\n\nexport function clearGraphqlReadCaches(): void {\n const g = globalThis as GraphqlReadCacheGlobals;\n g.__graphqlFetchResponseCache?.clear();\n g.__graphqlFetchPendingResponses?.clear();\n g.__boffGraphQLResponseCache?.clear();\n}\n\nexport async function semRequest<TData>(\n query: string,\n variables: Record<string, unknown> = {},\n baseUrl?: string\n): Promise<TData> {\n const response = await graphqlFetch<TData>({\n gateway: 'workspace',\n baseUrl,\n query,\n variables,\n workspaceToken: true,\n });\n\n if (response.errors?.length) {\n // A plan-limit refusal (BOFF-3172) opens the shell's upgrade prompt and\n // throws a typed error, so callers can tell it apart from a failure.\n const refusal = findQuotaRefusal(response.errors);\n if (refusal) {\n announceQuotaRefusal(refusal);\n throw new SemQuotaError(response.errors[0]?.message ?? 'Plan limit reached', refusal);\n }\n
|
|
1
|
+
{"version":3,"file":"semanticfedGraphql.js","names":[],"sources":["../../../src/semanticfed/api/semanticfedGraphql.ts"],"sourcesContent":["/**\n * SemanticFed GraphQL transport.\n *\n * Every call goes to the workspace gateway with a workspace-scoped token,\n * both supplied by the host shell (`graphqlFetch({ gateway: 'workspace',\n * workspaceToken: true })`). Operations are inline documents whose fields\n * match the `wspace-semanticfed-svc` subgraph schema exactly.\n */\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { announceQuotaRefusal, findQuotaRefusal, SemQuotaError } from './quotaRefusal';\n\n/**\n * fe-libs `graphqlFetch` coalesces query responses in short-lived in-memory\n * caches. A read issued right after a write would otherwise return the\n * pre-mutation response, so every mutation clears those caches.\n */\ntype GraphqlReadCacheGlobals = {\n __graphqlFetchResponseCache?: { clear: () => void };\n __graphqlFetchPendingResponses?: { clear: () => void };\n __boffGraphQLResponseCache?: { clear: () => void };\n};\n\nexport function clearGraphqlReadCaches(): void {\n const g = globalThis as GraphqlReadCacheGlobals;\n g.__graphqlFetchResponseCache?.clear();\n g.__graphqlFetchPendingResponses?.clear();\n g.__boffGraphQLResponseCache?.clear();\n}\n\n/**\n * A GraphQL error returned by the gateway. `message` is the gateway's\n * user-facing text, which it generalises for client errors (\"Please check the\n * information and try again.\"); `detail` carries the service's own\n * explanation (`extensions.technicalMessage`), which surfaces such as the SQL\n * console show because it names the exact problem (BOFF-4271).\n */\nexport class SemRequestError extends Error {\n readonly code: string | undefined;\n readonly detail: string | undefined;\n\n constructor(message: string, code: string | undefined, detail: string | undefined) {\n super(message);\n this.name = 'SemRequestError';\n this.code = code;\n this.detail = detail;\n }\n}\n\nexport async function semRequest<TData>(\n query: string,\n variables: Record<string, unknown> = {},\n baseUrl?: string\n): Promise<TData> {\n const response = await graphqlFetch<TData>({\n gateway: 'workspace',\n baseUrl,\n query,\n variables,\n workspaceToken: true,\n });\n\n if (response.errors?.length) {\n // A plan-limit refusal (BOFF-3172) opens the shell's upgrade prompt and\n // throws a typed error, so callers can tell it apart from a failure.\n const refusal = findQuotaRefusal(response.errors);\n if (refusal) {\n announceQuotaRefusal(refusal);\n throw new SemQuotaError(response.errors[0]?.message ?? 'Plan limit reached', refusal);\n }\n const first = response.errors[0];\n const extensions: Record<string, unknown> =\n first && typeof first === 'object' && 'extensions' in first && first.extensions\n ? (first.extensions as Record<string, unknown>)\n : {};\n throw new SemRequestError(\n first?.message ?? 'GraphQL request failed',\n typeof extensions.code === 'string' ? extensions.code : undefined,\n typeof extensions.technicalMessage === 'string' ? extensions.technicalMessage : undefined\n );\n }\n if (!response.data) {\n throw new Error('GraphQL response did not include data');\n }\n if (/^\\s*mutation\\b/.test(query)) {\n clearGraphqlReadCaches();\n }\n return response.data;\n}\n"],"mappings":";;;AAuBA,SAAgB,IAA+B;CAC7C,IAAM,IAAI;AAGV,CAFA,EAAE,6BAA6B,OAAO,EACtC,EAAE,gCAAgC,OAAO,EACzC,EAAE,4BAA4B,OAAO;;AAUvC,IAAa,IAAb,cAAqC,MAAM;CACzC;CACA;CAEA,YAAY,GAAiB,GAA0B,GAA4B;AAIjF,EAHA,MAAM,EAAQ,EACd,KAAK,OAAO,mBACZ,KAAK,OAAO,GACZ,KAAK,SAAS;;;AAIlB,eAAsB,EACpB,GACA,IAAqC,EAAE,EACvC,GACgB;CAChB,IAAM,IAAW,MAAM,EAAoB;EACzC,SAAS;EACT;EACA;EACA;EACA,gBAAgB;EACjB,CAAC;AAEF,KAAI,EAAS,QAAQ,QAAQ;EAG3B,IAAM,IAAU,EAAiB,EAAS,OAAO;AACjD,MAAI,EAEF,OADA,EAAqB,EAAQ,EACvB,IAAI,EAAc,EAAS,OAAO,IAAI,WAAW,sBAAsB,EAAQ;EAEvF,IAAM,IAAQ,EAAS,OAAO,IACxB,IACJ,KAAS,OAAO,KAAU,YAAY,gBAAgB,KAAS,EAAM,aAChE,EAAM,aACP,EAAE;AACR,QAAM,IAAI,EACR,GAAO,WAAW,0BAClB,OAAO,EAAW,QAAS,WAAW,EAAW,OAAO,KAAA,GACxD,OAAO,EAAW,oBAAqB,WAAW,EAAW,mBAAmB,KAAA,EACjF;;AAEH,KAAI,CAAC,EAAS,KACZ,OAAU,MAAM,wCAAwC;AAK1D,QAHI,iBAAiB,KAAK,EAAM,IAC9B,GAAwB,EAEnB,EAAS"}
|
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
import { useSemanticFed as e } from "../providers/SemanticFedProvider.js";
|
|
2
|
-
import {
|
|
3
|
-
import { useMutation as
|
|
2
|
+
import { SemRequestError as t, semRequest as n } from "../api/semanticfedGraphql.js";
|
|
3
|
+
import { useMutation as r, useQuery as i } from "@tanstack/react-query";
|
|
4
4
|
//#region src/semanticfed/hooks/useSqlConsole.ts
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
let { apiGatewayUrl:
|
|
8
|
-
return
|
|
5
|
+
var a = "query SemSqlConsoleModels($pagination: PaginationInput) {\n semListModels(pagination: $pagination) {\n items {\n id\n name\n status\n }\n }\n}", o = "query SemSqlCatalog($modelId: ID) {\n semSqlCatalog(modelId: $modelId) {\n modelId\n modelName\n tables {\n name\n kind\n description\n primaryKey\n columns {\n name\n kind\n dataType\n aggregation\n description\n isPrimary\n }\n }\n }\n}", s = "mutation SemExecuteSql($input: SemExecuteSqlInput!) {\n semExecuteSql(input: $input) {\n modelId\n columns {\n name\n entity\n field\n aggregation\n dataType\n masked\n mask\n }\n rows\n rowCount\n truncated\n durationMs\n sourcesTouched\n }\n}", c = 100;
|
|
6
|
+
function l() {
|
|
7
|
+
let { apiGatewayUrl: t, workspaceId: r } = e();
|
|
8
|
+
return i({
|
|
9
9
|
queryKey: [
|
|
10
10
|
"semanticfed",
|
|
11
11
|
"sql",
|
|
12
12
|
"models",
|
|
13
|
-
|
|
13
|
+
r ?? "no-workspace"
|
|
14
14
|
],
|
|
15
|
-
enabled: !!
|
|
16
|
-
queryFn: async () => (await
|
|
15
|
+
enabled: !!r,
|
|
16
|
+
queryFn: async () => (await n(a, { pagination: { limit: c } }, t)).semListModels.items
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
let { apiGatewayUrl:
|
|
21
|
-
return
|
|
19
|
+
function u(t) {
|
|
20
|
+
let { apiGatewayUrl: r, workspaceId: a } = e();
|
|
21
|
+
return i({
|
|
22
22
|
queryKey: [
|
|
23
23
|
"semanticfed",
|
|
24
24
|
"sql",
|
|
25
25
|
"catalog",
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
a ?? "no-workspace",
|
|
27
|
+
t
|
|
28
28
|
],
|
|
29
|
-
enabled: !!(
|
|
30
|
-
queryFn: async () => (await
|
|
29
|
+
enabled: !!(a && t),
|
|
30
|
+
queryFn: async () => (await n(o, { modelId: t }, r)).semSqlCatalog
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
let { apiGatewayUrl:
|
|
35
|
-
return
|
|
33
|
+
function d() {
|
|
34
|
+
let { apiGatewayUrl: t } = e();
|
|
35
|
+
return r({ mutationFn: async (e) => (await n(s, { input: e }, t)).semExecuteSql });
|
|
36
|
+
}
|
|
37
|
+
function f(e) {
|
|
38
|
+
return e instanceof t && e.detail && e.code !== "INTERNAL_SERVER_ERROR" ? e.detail : e instanceof Error ? e.message : String(e);
|
|
36
39
|
}
|
|
37
40
|
//#endregion
|
|
38
|
-
export {
|
|
41
|
+
export { f as sqlErrorMessage, d as useSemExecuteSql, u as useSemSqlCatalog, l as useSemSqlModels };
|
|
39
42
|
|
|
40
43
|
//# sourceMappingURL=useSqlConsole.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSqlConsole.js","names":[],"sources":["../../../src/semanticfed/hooks/useSqlConsole.ts"],"sourcesContent":["/**\n * SQL console hooks, wired to the real `wspace-semanticfed-svc` SQL endpoint\n * (BOFF-4271): `semListModels` to pick a semantic model, `semSqlCatalog` for\n * the table/column browser and `semExecuteSql` to run a read-only SELECT\n * through the federated query engine with the caller's access policies.\n */\nimport { useMutation, useQuery } from '@tanstack/react-query';\n\nimport { semRequest } from '../api/semanticfedGraphql';\nimport { useSemanticFed } from '../providers/SemanticFedProvider';\n\nexport type SemSqlDataType =\n | 'STRING'\n | 'INTEGER'\n | 'DECIMAL'\n | 'BOOLEAN'\n | 'DATE'\n | 'TIMESTAMP'\n | 'JSON'\n | 'GEO'\n | 'UNKNOWN';\n\nexport interface SemModelSummary {\n id: string;\n name: string;\n status: string;\n}\n\nexport interface SemSqlCatalogColumn {\n name: string;\n kind: 'DIMENSION' | 'METRIC';\n dataType: SemSqlDataType;\n aggregation: string | null;\n description: string | null;\n isPrimary: boolean;\n}\n\nexport interface SemSqlCatalogTable {\n name: string;\n kind: string;\n description: string | null;\n primaryKey: string | null;\n columns: SemSqlCatalogColumn[];\n}\n\nexport interface SemSqlCatalog {\n modelId: string;\n modelName: string;\n tables: SemSqlCatalogTable[];\n}\n\nexport interface SemSqlResultColumn {\n name: string;\n entity: string;\n field: string;\n aggregation: string | null;\n dataType: SemSqlDataType;\n masked: boolean;\n mask: string | null;\n}\n\nexport interface SemSqlResult {\n modelId: string;\n columns: SemSqlResultColumn[];\n rows: Array<Record<string, unknown>>;\n rowCount: number;\n truncated: boolean;\n durationMs: number;\n sourcesTouched: number;\n}\n\nexport interface SemExecuteSqlInput {\n sql: string;\n modelId: string;\n maxRows?: number;\n}\n\nconst LIST_MODELS_QUERY = `query SemSqlConsoleModels($pagination: PaginationInput) {\n semListModels(pagination: $pagination) {\n items {\n id\n name\n status\n }\n }\n}`;\n\nconst SQL_CATALOG_QUERY = `query SemSqlCatalog($modelId: ID) {\n semSqlCatalog(modelId: $modelId) {\n modelId\n modelName\n tables {\n name\n kind\n description\n primaryKey\n columns {\n name\n kind\n dataType\n aggregation\n description\n isPrimary\n }\n }\n }\n}`;\n\nconst EXECUTE_SQL_MUTATION = `mutation SemExecuteSql($input: SemExecuteSqlInput!) {\n semExecuteSql(input: $input) {\n modelId\n columns {\n name\n entity\n field\n aggregation\n dataType\n masked\n mask\n }\n rows\n rowCount\n truncated\n durationMs\n sourcesTouched\n }\n}`;\n\n/** Largest model list the console offers (the picker is not paginated). */\nconst MODEL_PICKER_LIMIT = 100;\n\nexport function useSemSqlModels() {\n const { apiGatewayUrl, workspaceId } = useSemanticFed();\n return useQuery({\n queryKey: ['semanticfed', 'sql', 'models', workspaceId ?? 'no-workspace'] as const,\n enabled: Boolean(workspaceId),\n queryFn: async () => {\n const data = await semRequest<{ semListModels: { items: SemModelSummary[] } }>(\n LIST_MODELS_QUERY,\n { pagination: { limit: MODEL_PICKER_LIMIT } },\n apiGatewayUrl\n );\n return data.semListModels.items;\n },\n });\n}\n\nexport function useSemSqlCatalog(modelId: string | null) {\n const { apiGatewayUrl, workspaceId } = useSemanticFed();\n return useQuery({\n queryKey: ['semanticfed', 'sql', 'catalog', workspaceId ?? 'no-workspace', modelId] as const,\n enabled: Boolean(workspaceId && modelId),\n queryFn: async () => {\n const data = await semRequest<{ semSqlCatalog: SemSqlCatalog }>(\n SQL_CATALOG_QUERY,\n { modelId },\n apiGatewayUrl\n );\n return data.semSqlCatalog;\n },\n });\n}\n\nexport function useSemExecuteSql() {\n const { apiGatewayUrl } = useSemanticFed();\n return useMutation({\n mutationFn: async (input: SemExecuteSqlInput) => {\n const data = await semRequest<{ semExecuteSql: SemSqlResult }>(\n EXECUTE_SQL_MUTATION,\n { input },\n apiGatewayUrl\n );\n return data.semExecuteSql;\n },\n });\n}\n"],"mappings":";;;;AA6EA,IAAM,IAAoB,yKAUpB,IAAoB,wUAqBpB,IAAuB,qTAqBvB,IAAqB;AAE3B,SAAgB,IAAkB;CAChC,IAAM,EAAE,kBAAe,mBAAgB,GAAgB;AACvD,QAAO,EAAS;EACd,UAAU;GAAC;GAAe;GAAO;GAAU,KAAe;GAAe;EACzE,SAAS,EAAQ;EACjB,SAAS,aACM,MAAM,EACjB,GACA,EAAE,YAAY,EAAE,OAAO,GAAoB,EAAE,EAC7C,EACD,EACW,cAAc;EAE7B,CAAC;;AAGJ,SAAgB,EAAiB,GAAwB;CACvD,IAAM,EAAE,kBAAe,mBAAgB,GAAgB;AACvD,QAAO,EAAS;EACd,UAAU;GAAC;GAAe;GAAO;GAAW,KAAe;GAAgB;GAAQ;EACnF,SAAS,GAAQ,KAAe;EAChC,SAAS,aACM,MAAM,EACjB,GACA,EAAE,YAAS,EACX,EACD,EACW;EAEf,CAAC;;AAGJ,SAAgB,IAAmB;CACjC,IAAM,EAAE,qBAAkB,GAAgB;AAC1C,QAAO,EAAY,EACjB,YAAY,OAAO,OACJ,MAAM,EACjB,GACA,EAAE,UAAO,EACT,EACD,EACW,eAEf,CAAC"}
|
|
1
|
+
{"version":3,"file":"useSqlConsole.js","names":[],"sources":["../../../src/semanticfed/hooks/useSqlConsole.ts"],"sourcesContent":["/**\n * SQL console hooks, wired to the real `wspace-semanticfed-svc` SQL endpoint\n * (BOFF-4271): `semListModels` to pick a semantic model, `semSqlCatalog` for\n * the table/column browser and `semExecuteSql` to run a read-only SELECT\n * through the federated query engine with the caller's access policies.\n */\nimport { useMutation, useQuery } from '@tanstack/react-query';\n\nimport { SemRequestError, semRequest } from '../api/semanticfedGraphql';\nimport { useSemanticFed } from '../providers/SemanticFedProvider';\n\nexport type SemSqlDataType =\n | 'STRING'\n | 'INTEGER'\n | 'DECIMAL'\n | 'BOOLEAN'\n | 'DATE'\n | 'TIMESTAMP'\n | 'JSON'\n | 'GEO'\n | 'UNKNOWN';\n\nexport interface SemModelSummary {\n id: string;\n name: string;\n status: string;\n}\n\nexport interface SemSqlCatalogColumn {\n name: string;\n kind: 'DIMENSION' | 'METRIC';\n dataType: SemSqlDataType;\n aggregation: string | null;\n description: string | null;\n isPrimary: boolean;\n}\n\nexport interface SemSqlCatalogTable {\n name: string;\n kind: string;\n description: string | null;\n primaryKey: string | null;\n columns: SemSqlCatalogColumn[];\n}\n\nexport interface SemSqlCatalog {\n modelId: string;\n modelName: string;\n tables: SemSqlCatalogTable[];\n}\n\nexport interface SemSqlResultColumn {\n name: string;\n entity: string;\n field: string;\n aggregation: string | null;\n dataType: SemSqlDataType;\n masked: boolean;\n mask: string | null;\n}\n\nexport interface SemSqlResult {\n modelId: string;\n columns: SemSqlResultColumn[];\n rows: Array<Record<string, unknown>>;\n rowCount: number;\n truncated: boolean;\n durationMs: number;\n sourcesTouched: number;\n}\n\nexport interface SemExecuteSqlInput {\n sql: string;\n modelId: string;\n maxRows?: number;\n}\n\nconst LIST_MODELS_QUERY = `query SemSqlConsoleModels($pagination: PaginationInput) {\n semListModels(pagination: $pagination) {\n items {\n id\n name\n status\n }\n }\n}`;\n\nconst SQL_CATALOG_QUERY = `query SemSqlCatalog($modelId: ID) {\n semSqlCatalog(modelId: $modelId) {\n modelId\n modelName\n tables {\n name\n kind\n description\n primaryKey\n columns {\n name\n kind\n dataType\n aggregation\n description\n isPrimary\n }\n }\n }\n}`;\n\nconst EXECUTE_SQL_MUTATION = `mutation SemExecuteSql($input: SemExecuteSqlInput!) {\n semExecuteSql(input: $input) {\n modelId\n columns {\n name\n entity\n field\n aggregation\n dataType\n masked\n mask\n }\n rows\n rowCount\n truncated\n durationMs\n sourcesTouched\n }\n}`;\n\n/** Largest model list the console offers (the picker is not paginated). */\nconst MODEL_PICKER_LIMIT = 100;\n\nexport function useSemSqlModels() {\n const { apiGatewayUrl, workspaceId } = useSemanticFed();\n return useQuery({\n queryKey: ['semanticfed', 'sql', 'models', workspaceId ?? 'no-workspace'] as const,\n enabled: Boolean(workspaceId),\n queryFn: async () => {\n const data = await semRequest<{ semListModels: { items: SemModelSummary[] } }>(\n LIST_MODELS_QUERY,\n { pagination: { limit: MODEL_PICKER_LIMIT } },\n apiGatewayUrl\n );\n return data.semListModels.items;\n },\n });\n}\n\nexport function useSemSqlCatalog(modelId: string | null) {\n const { apiGatewayUrl, workspaceId } = useSemanticFed();\n return useQuery({\n queryKey: ['semanticfed', 'sql', 'catalog', workspaceId ?? 'no-workspace', modelId] as const,\n enabled: Boolean(workspaceId && modelId),\n queryFn: async () => {\n const data = await semRequest<{ semSqlCatalog: SemSqlCatalog }>(\n SQL_CATALOG_QUERY,\n { modelId },\n apiGatewayUrl\n );\n return data.semSqlCatalog;\n },\n });\n}\n\nexport function useSemExecuteSql() {\n const { apiGatewayUrl } = useSemanticFed();\n return useMutation({\n mutationFn: async (input: SemExecuteSqlInput) => {\n const data = await semRequest<{ semExecuteSql: SemSqlResult }>(\n EXECUTE_SQL_MUTATION,\n { input },\n apiGatewayUrl\n );\n return data.semExecuteSql;\n },\n });\n}\n\n/**\n * The text to show for a failed SQL statement. The gateway generalises client\n * errors, so the service's own explanation (syntax position, unknown column,\n * policy denial) is preferred whenever the service sent one.\n */\nexport function sqlErrorMessage(error: unknown): string {\n if (error instanceof SemRequestError && error.detail && error.code !== 'INTERNAL_SERVER_ERROR') {\n return error.detail;\n }\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;;AA6EA,IAAM,IAAoB,yKAUpB,IAAoB,wUAqBpB,IAAuB,qTAqBvB,IAAqB;AAE3B,SAAgB,IAAkB;CAChC,IAAM,EAAE,kBAAe,mBAAgB,GAAgB;AACvD,QAAO,EAAS;EACd,UAAU;GAAC;GAAe;GAAO;GAAU,KAAe;GAAe;EACzE,SAAS,EAAQ;EACjB,SAAS,aACM,MAAM,EACjB,GACA,EAAE,YAAY,EAAE,OAAO,GAAoB,EAAE,EAC7C,EACD,EACW,cAAc;EAE7B,CAAC;;AAGJ,SAAgB,EAAiB,GAAwB;CACvD,IAAM,EAAE,kBAAe,mBAAgB,GAAgB;AACvD,QAAO,EAAS;EACd,UAAU;GAAC;GAAe;GAAO;GAAW,KAAe;GAAgB;GAAQ;EACnF,SAAS,GAAQ,KAAe;EAChC,SAAS,aACM,MAAM,EACjB,GACA,EAAE,YAAS,EACX,EACD,EACW;EAEf,CAAC;;AAGJ,SAAgB,IAAmB;CACjC,IAAM,EAAE,qBAAkB,GAAgB;AAC1C,QAAO,EAAY,EACjB,YAAY,OAAO,OACJ,MAAM,EACjB,GACA,EAAE,UAAO,EACT,EACD,EACW,eAEf,CAAC;;AAQJ,SAAgB,EAAgB,GAAwB;AAItD,QAHI,aAAiB,KAAmB,EAAM,UAAU,EAAM,SAAS,0BAC9D,EAAM,SAER,aAAiB,QAAQ,EAAM,UAAU,OAAO,EAAM"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { translateWithFallback as e } from "../utils/i18n.js";
|
|
2
|
-
import {
|
|
3
|
-
import { useMemo as
|
|
4
|
-
import { AlertTriangle as
|
|
5
|
-
import { Fragment as
|
|
6
|
-
import { useI18n as
|
|
7
|
-
import { Badge as
|
|
2
|
+
import { sqlErrorMessage as t, useSemExecuteSql as n, useSemSqlCatalog as r, useSemSqlModels as i } from "../hooks/useSqlConsole.js";
|
|
3
|
+
import { useMemo as a, useState as o } from "react";
|
|
4
|
+
import { AlertTriangle as s, CheckCircle2 as c, Clock as l, Database as u, EyeOff as d, Loader2 as f, Play as p, Plug as m, Table2 as h, Terminal as g, XCircle as _ } from "lucide-react";
|
|
5
|
+
import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
6
|
+
import { useI18n as x } from "@burdenoff/fe-libs/shared/providers/shell";
|
|
7
|
+
import { Badge as S, Button as C, Card as w, CardContent as T, CardHeader as E, CardTitle as D } from "@burdenoff/fe-libs/ui";
|
|
8
8
|
//#region src/semanticfed/pages/QueryConsolePage.tsx
|
|
9
|
-
var
|
|
9
|
+
var O = [
|
|
10
10
|
100,
|
|
11
11
|
1e3,
|
|
12
12
|
1e4
|
|
13
|
-
],
|
|
14
|
-
function
|
|
13
|
+
], k = 10;
|
|
14
|
+
function A(e) {
|
|
15
15
|
if (!e) return "";
|
|
16
16
|
let t = e.columns.find((e) => e.kind === "DIMENSION"), n = e.columns.find((e) => e.kind === "METRIC"), r = (e) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(e) ? e : `"${e.replace(/"/g, "\"\"")}"`, i = r(e.name);
|
|
17
17
|
if (t && n) {
|
|
@@ -26,316 +26,316 @@ function k(e) {
|
|
|
26
26
|
}
|
|
27
27
|
return `SELECT *\nFROM ${i}\nLIMIT 100;`;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function j(e) {
|
|
30
30
|
return e == null ? "NULL" : typeof e == "object" ? JSON.stringify(e) : String(e);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
let { t:
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
-
let e =
|
|
32
|
+
function M() {
|
|
33
|
+
let { t: M } = x(), N = (t, n, r) => e(M, t, n, r), P = i(), [F, I] = o(null), L = F ?? P.data?.[0]?.id ?? null, R = r(L), z = n(), [B, V] = o(null), H = B ?? A(R.data?.tables[0]), U = (e) => V(e), [W, G] = o(1e3), [K, q] = o(null), [J, Y] = o(null), [X, Z] = o([]), Q = a(() => P.data?.find((e) => e.id === L)?.name ?? "", [P.data, L]), $ = async () => {
|
|
34
|
+
if (!L || H.trim() === "" || z.isPending) return;
|
|
35
|
+
Y(null);
|
|
36
|
+
let e = H, n = {
|
|
37
37
|
id: Date.now(),
|
|
38
38
|
sql: e,
|
|
39
|
-
modelName:
|
|
39
|
+
modelName: Q,
|
|
40
40
|
executedAt: (/* @__PURE__ */ new Date()).toLocaleTimeString()
|
|
41
41
|
};
|
|
42
42
|
try {
|
|
43
|
-
let
|
|
43
|
+
let t = await z.mutateAsync({
|
|
44
44
|
sql: e,
|
|
45
|
-
modelId:
|
|
46
|
-
maxRows:
|
|
45
|
+
modelId: L,
|
|
46
|
+
maxRows: W
|
|
47
47
|
});
|
|
48
|
-
|
|
49
|
-
...
|
|
48
|
+
q(t), Z((e) => [{
|
|
49
|
+
...n,
|
|
50
50
|
ok: !0,
|
|
51
|
-
rowCount:
|
|
52
|
-
durationMs: Math.round(
|
|
51
|
+
rowCount: t.rowCount,
|
|
52
|
+
durationMs: Math.round(t.durationMs),
|
|
53
53
|
message: null
|
|
54
|
-
}, ...e].slice(0,
|
|
54
|
+
}, ...e].slice(0, k));
|
|
55
55
|
} catch (e) {
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
...
|
|
56
|
+
let r = t(e);
|
|
57
|
+
q(null), Y(r), Z((e) => [{
|
|
58
|
+
...n,
|
|
59
59
|
ok: !1,
|
|
60
60
|
rowCount: 0,
|
|
61
61
|
durationMs: 0,
|
|
62
|
-
message:
|
|
63
|
-
}, ...e].slice(0,
|
|
62
|
+
message: r
|
|
63
|
+
}, ...e].slice(0, k));
|
|
64
64
|
}
|
|
65
|
-
},
|
|
66
|
-
return /* @__PURE__ */
|
|
65
|
+
}, ee = (e) => U(H.trim() === "" ? e : `${H}${e}`), te = P.isSuccess && P.data.length === 0;
|
|
66
|
+
return /* @__PURE__ */ b("div", {
|
|
67
67
|
className: "space-y-6 p-6",
|
|
68
68
|
children: [
|
|
69
|
-
/* @__PURE__ */
|
|
69
|
+
/* @__PURE__ */ b("div", {
|
|
70
70
|
className: "flex flex-wrap items-center justify-between gap-3",
|
|
71
71
|
"data-tour": "semanticfed-query-console-header",
|
|
72
|
-
children: [/* @__PURE__ */
|
|
72
|
+
children: [/* @__PURE__ */ b("div", { children: [/* @__PURE__ */ y("h1", {
|
|
73
73
|
className: "text-2xl font-semibold",
|
|
74
|
-
children:
|
|
75
|
-
}), /* @__PURE__ */
|
|
74
|
+
children: N("semanticfed.queryConsole.title", "Query Console")
|
|
75
|
+
}), /* @__PURE__ */ y("p", {
|
|
76
76
|
className: "text-sm text-muted-foreground",
|
|
77
|
-
children:
|
|
78
|
-
})] }), /* @__PURE__ */
|
|
77
|
+
children: N("semanticfed.queryConsole.sqlDescription", "Run read-only SQL against a semantic model. Every statement is federated across its data sources with your access policies applied.")
|
|
78
|
+
})] }), /* @__PURE__ */ b("div", {
|
|
79
79
|
className: "flex gap-2",
|
|
80
|
-
children: [/* @__PURE__ */
|
|
80
|
+
children: [/* @__PURE__ */ b(S, {
|
|
81
81
|
variant: "outline",
|
|
82
82
|
className: "gap-1",
|
|
83
|
-
children: [/* @__PURE__ */
|
|
84
|
-
}), /* @__PURE__ */
|
|
83
|
+
children: [/* @__PURE__ */ y(g, { className: "h-3 w-3" }), " SQL SELECT"]
|
|
84
|
+
}), /* @__PURE__ */ b(S, {
|
|
85
85
|
variant: "outline",
|
|
86
86
|
className: "gap-1",
|
|
87
|
-
children: [/* @__PURE__ */
|
|
87
|
+
children: [/* @__PURE__ */ y(m, { className: "h-3 w-3" }), N("semanticfed.queryConsole.badges.httpApi", "HTTP SQL API")]
|
|
88
88
|
})]
|
|
89
89
|
})]
|
|
90
90
|
}),
|
|
91
|
-
|
|
91
|
+
te && /* @__PURE__ */ y(w, { children: /* @__PURE__ */ b(T, {
|
|
92
92
|
className: "flex items-center gap-3 p-6 text-sm text-muted-foreground",
|
|
93
|
-
children: [/* @__PURE__ */
|
|
93
|
+
children: [/* @__PURE__ */ y(u, { className: "h-5 w-5" }), N("semanticfed.queryConsole.noModels", "No semantic model yet. Create a model with entities, dimensions and metrics, then query it here with SQL.")]
|
|
94
94
|
}) }),
|
|
95
|
-
/* @__PURE__ */
|
|
95
|
+
/* @__PURE__ */ b("div", {
|
|
96
96
|
className: "grid gap-4 lg:grid-cols-[18rem_minmax(0,1fr)]",
|
|
97
|
-
children: [/* @__PURE__ */
|
|
97
|
+
children: [/* @__PURE__ */ b(w, {
|
|
98
98
|
className: "min-w-0",
|
|
99
|
-
children: [/* @__PURE__ */
|
|
99
|
+
children: [/* @__PURE__ */ y(E, {
|
|
100
100
|
className: "pb-3",
|
|
101
|
-
children: /* @__PURE__ */
|
|
101
|
+
children: /* @__PURE__ */ b(D, {
|
|
102
102
|
className: "flex items-center gap-2 text-base",
|
|
103
|
-
children: [/* @__PURE__ */
|
|
103
|
+
children: [/* @__PURE__ */ y(h, { className: "h-4 w-4" }), N("semanticfed.queryConsole.schema.title", "Tables")]
|
|
104
104
|
})
|
|
105
|
-
}), /* @__PURE__ */
|
|
105
|
+
}), /* @__PURE__ */ b(T, {
|
|
106
106
|
className: "space-y-3",
|
|
107
107
|
children: [
|
|
108
|
-
/* @__PURE__ */
|
|
108
|
+
/* @__PURE__ */ y("label", {
|
|
109
109
|
className: "block text-xs font-medium text-muted-foreground",
|
|
110
110
|
htmlFor: "sql-console-model",
|
|
111
|
-
children:
|
|
111
|
+
children: N("semanticfed.queryConsole.schema.model", "Semantic model")
|
|
112
112
|
}),
|
|
113
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ y("select", {
|
|
114
114
|
id: "sql-console-model",
|
|
115
115
|
"data-testid": "sql-console-model",
|
|
116
116
|
className: "w-full rounded border bg-background p-2 text-sm",
|
|
117
|
-
value:
|
|
117
|
+
value: L ?? "",
|
|
118
118
|
onChange: (e) => {
|
|
119
|
-
|
|
119
|
+
I(e.target.value || null), V(null), q(null), Y(null);
|
|
120
120
|
},
|
|
121
|
-
disabled: !
|
|
122
|
-
children: (
|
|
121
|
+
disabled: !P.data || P.data.length === 0,
|
|
122
|
+
children: (P.data ?? []).map((e) => /* @__PURE__ */ y("option", {
|
|
123
123
|
value: e.id,
|
|
124
124
|
children: e.name
|
|
125
125
|
}, e.id))
|
|
126
126
|
}),
|
|
127
|
-
|
|
127
|
+
P.isError && /* @__PURE__ */ y("p", {
|
|
128
128
|
className: "text-xs text-destructive",
|
|
129
|
-
children:
|
|
129
|
+
children: t(P.error)
|
|
130
130
|
}),
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
R.isLoading && /* @__PURE__ */ y(f, { className: "h-4 w-4 animate-spin text-muted-foreground" }),
|
|
132
|
+
R.isError && /* @__PURE__ */ y("p", {
|
|
133
133
|
className: "text-xs text-destructive",
|
|
134
|
-
children:
|
|
134
|
+
children: t(R.error)
|
|
135
135
|
}),
|
|
136
|
-
/* @__PURE__ */
|
|
136
|
+
/* @__PURE__ */ y("div", {
|
|
137
137
|
className: "max-h-96 space-y-2 overflow-y-auto",
|
|
138
138
|
"data-testid": "sql-console-tables",
|
|
139
|
-
children: (
|
|
139
|
+
children: (R.data?.tables ?? []).map((e) => /* @__PURE__ */ b("details", {
|
|
140
140
|
className: "rounded border p-2",
|
|
141
|
-
open:
|
|
142
|
-
children: [/* @__PURE__ */
|
|
141
|
+
open: R.data?.tables.length === 1,
|
|
142
|
+
children: [/* @__PURE__ */ y("summary", {
|
|
143
143
|
className: "cursor-pointer truncate font-mono text-xs font-medium",
|
|
144
144
|
children: e.name
|
|
145
|
-
}), /* @__PURE__ */
|
|
145
|
+
}), /* @__PURE__ */ b("ul", {
|
|
146
146
|
className: "mt-2 space-y-1",
|
|
147
|
-
children: [e.columns.map((e) => /* @__PURE__ */
|
|
147
|
+
children: [e.columns.map((e) => /* @__PURE__ */ y("li", { children: /* @__PURE__ */ b("button", {
|
|
148
148
|
type: "button",
|
|
149
149
|
className: "flex w-full items-center justify-between gap-2 rounded px-1 text-left font-mono text-xs hover:bg-muted",
|
|
150
|
-
onClick: () =>
|
|
150
|
+
onClick: () => ee(e.name),
|
|
151
151
|
title: e.description ?? void 0,
|
|
152
|
-
children: [/* @__PURE__ */
|
|
152
|
+
children: [/* @__PURE__ */ y("span", {
|
|
153
153
|
className: "truncate",
|
|
154
154
|
children: e.name
|
|
155
|
-
}), /* @__PURE__ */
|
|
155
|
+
}), /* @__PURE__ */ y("span", {
|
|
156
156
|
className: "shrink-0 text-[10px] text-muted-foreground",
|
|
157
157
|
children: e.kind === "METRIC" ? e.aggregation ?? "METRIC" : e.dataType
|
|
158
158
|
})]
|
|
159
|
-
}) }, e.name)), e.columns.length === 0 && /* @__PURE__ */
|
|
159
|
+
}) }, e.name)), e.columns.length === 0 && /* @__PURE__ */ y("li", {
|
|
160
160
|
className: "text-xs text-muted-foreground",
|
|
161
|
-
children:
|
|
161
|
+
children: N("semanticfed.queryConsole.schema.noColumns", "No dimensions or metrics registered")
|
|
162
162
|
})]
|
|
163
163
|
})]
|
|
164
164
|
}, e.name))
|
|
165
165
|
})
|
|
166
166
|
]
|
|
167
167
|
})]
|
|
168
|
-
}), /* @__PURE__ */
|
|
168
|
+
}), /* @__PURE__ */ b("div", {
|
|
169
169
|
className: "min-w-0 space-y-4",
|
|
170
170
|
children: [
|
|
171
|
-
/* @__PURE__ */
|
|
171
|
+
/* @__PURE__ */ b(w, { children: [/* @__PURE__ */ y(E, {
|
|
172
172
|
className: "pb-3",
|
|
173
|
-
children: /* @__PURE__ */
|
|
173
|
+
children: /* @__PURE__ */ b("div", {
|
|
174
174
|
className: "flex flex-wrap items-center justify-between gap-2",
|
|
175
|
-
children: [/* @__PURE__ */
|
|
175
|
+
children: [/* @__PURE__ */ y(D, {
|
|
176
176
|
className: "text-base",
|
|
177
|
-
children:
|
|
178
|
-
}), /* @__PURE__ */
|
|
177
|
+
children: N("semanticfed.queryConsole.editor.title", "Query Editor")
|
|
178
|
+
}), /* @__PURE__ */ b("div", {
|
|
179
179
|
className: "flex items-center gap-2",
|
|
180
180
|
children: [
|
|
181
|
-
/* @__PURE__ */
|
|
181
|
+
/* @__PURE__ */ y("label", {
|
|
182
182
|
className: "sr-only",
|
|
183
183
|
htmlFor: "sql-console-max-rows",
|
|
184
|
-
children:
|
|
184
|
+
children: N("semanticfed.queryConsole.editor.maxRowsLabel", "Maximum rows")
|
|
185
185
|
}),
|
|
186
|
-
/* @__PURE__ */
|
|
186
|
+
/* @__PURE__ */ y("select", {
|
|
187
187
|
id: "sql-console-max-rows",
|
|
188
188
|
className: "rounded border bg-background p-1 text-xs",
|
|
189
|
-
value:
|
|
190
|
-
onChange: (e) =>
|
|
191
|
-
children:
|
|
189
|
+
value: W,
|
|
190
|
+
onChange: (e) => G(Number(e.target.value)),
|
|
191
|
+
children: O.map((e) => /* @__PURE__ */ y("option", {
|
|
192
192
|
value: e,
|
|
193
|
-
children:
|
|
193
|
+
children: N("semanticfed.queryConsole.editor.maxRowsOption", "Max {count} rows", { count: e.toLocaleString() })
|
|
194
194
|
}, e))
|
|
195
195
|
}),
|
|
196
|
-
/* @__PURE__ */
|
|
196
|
+
/* @__PURE__ */ b(C, {
|
|
197
197
|
size: "sm",
|
|
198
|
-
onClick: () => void
|
|
199
|
-
disabled: !
|
|
198
|
+
onClick: () => void $(),
|
|
199
|
+
disabled: !L || H.trim() === "" || z.isPending,
|
|
200
200
|
"data-testid": "sql-console-run",
|
|
201
|
-
children: [
|
|
201
|
+
children: [z.isPending ? /* @__PURE__ */ y(f, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ y(p, { className: "mr-2 h-4 w-4" }), N("semanticfed.queryConsole.actions.execute", "Execute")]
|
|
202
202
|
})
|
|
203
203
|
]
|
|
204
204
|
})]
|
|
205
205
|
})
|
|
206
|
-
}), /* @__PURE__ */
|
|
207
|
-
"aria-label":
|
|
206
|
+
}), /* @__PURE__ */ b(T, { children: [/* @__PURE__ */ y("textarea", {
|
|
207
|
+
"aria-label": N("semanticfed.queryConsole.editor.ariaLabel", "SQL statement"),
|
|
208
208
|
"data-testid": "sql-console-editor",
|
|
209
209
|
className: "w-full rounded border bg-muted/30 p-4 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary",
|
|
210
210
|
rows: 8,
|
|
211
|
-
value:
|
|
212
|
-
onChange: (e) =>
|
|
211
|
+
value: H,
|
|
212
|
+
onChange: (e) => U(e.target.value),
|
|
213
213
|
onKeyDown: (e) => {
|
|
214
|
-
(e.metaKey || e.ctrlKey) && e.key === "Enter" && (e.preventDefault(),
|
|
214
|
+
(e.metaKey || e.ctrlKey) && e.key === "Enter" && (e.preventDefault(), $());
|
|
215
215
|
},
|
|
216
216
|
spellCheck: !1,
|
|
217
217
|
placeholder: "SELECT region, SUM(revenue) FROM orders GROUP BY region"
|
|
218
|
-
}), /* @__PURE__ */
|
|
218
|
+
}), /* @__PURE__ */ b("div", {
|
|
219
219
|
className: "mt-2 flex flex-wrap items-center gap-4 text-xs text-muted-foreground",
|
|
220
220
|
children: [
|
|
221
|
-
/* @__PURE__ */
|
|
222
|
-
/* @__PURE__ */
|
|
223
|
-
/* @__PURE__ */
|
|
221
|
+
/* @__PURE__ */ y("span", { children: N("semanticfed.queryConsole.editor.shortcut", "Ctrl/Cmd + Enter to run") }),
|
|
222
|
+
/* @__PURE__ */ y("span", { children: N("semanticfed.queryConsole.editor.timeout", "Timeout: 30s") }),
|
|
223
|
+
/* @__PURE__ */ y("span", { children: N("semanticfed.queryConsole.editor.supported", "SELECT, JOIN … ON, WHERE … AND, GROUP BY, ORDER BY, LIMIT/OFFSET") })
|
|
224
224
|
]
|
|
225
225
|
})] })] }),
|
|
226
|
-
|
|
226
|
+
J && /* @__PURE__ */ y(w, {
|
|
227
227
|
"data-testid": "sql-console-error",
|
|
228
|
-
children: /* @__PURE__ */
|
|
228
|
+
children: /* @__PURE__ */ b(T, {
|
|
229
229
|
className: "flex items-start gap-3 p-4 text-sm text-destructive",
|
|
230
|
-
children: [/* @__PURE__ */
|
|
230
|
+
children: [/* @__PURE__ */ y(_, { className: "mt-0.5 h-4 w-4 shrink-0" }), /* @__PURE__ */ y("span", {
|
|
231
231
|
className: "break-words",
|
|
232
|
-
children:
|
|
232
|
+
children: J
|
|
233
233
|
})]
|
|
234
234
|
})
|
|
235
235
|
}),
|
|
236
|
-
|
|
236
|
+
K && /* @__PURE__ */ b(w, {
|
|
237
237
|
"data-testid": "sql-console-result",
|
|
238
|
-
children: [/* @__PURE__ */
|
|
238
|
+
children: [/* @__PURE__ */ y(E, {
|
|
239
239
|
className: "pb-3",
|
|
240
|
-
children: /* @__PURE__ */
|
|
240
|
+
children: /* @__PURE__ */ b("div", {
|
|
241
241
|
className: "flex flex-wrap items-center gap-3 text-sm",
|
|
242
242
|
children: [
|
|
243
|
-
/* @__PURE__ */
|
|
244
|
-
/* @__PURE__ */
|
|
243
|
+
/* @__PURE__ */ y(c, { className: "h-4 w-4 text-primary" }),
|
|
244
|
+
/* @__PURE__ */ y("span", {
|
|
245
245
|
className: "font-medium",
|
|
246
246
|
"data-testid": "sql-console-row-count",
|
|
247
|
-
children:
|
|
247
|
+
children: N("semanticfed.queryConsole.result.rows", "{count} rows", { count: K.rowCount.toLocaleString() })
|
|
248
248
|
}),
|
|
249
|
-
/* @__PURE__ */
|
|
249
|
+
/* @__PURE__ */ b("span", {
|
|
250
250
|
className: "text-muted-foreground",
|
|
251
|
-
children: [Math.round(
|
|
251
|
+
children: [Math.round(K.durationMs), "ms"]
|
|
252
252
|
}),
|
|
253
|
-
/* @__PURE__ */
|
|
253
|
+
/* @__PURE__ */ y("span", {
|
|
254
254
|
className: "text-muted-foreground",
|
|
255
|
-
children:
|
|
255
|
+
children: N("semanticfed.queryConsole.result.sources", "{count} sources", { count: K.sourcesTouched })
|
|
256
256
|
}),
|
|
257
|
-
|
|
257
|
+
K.truncated && /* @__PURE__ */ b(S, {
|
|
258
258
|
variant: "outline",
|
|
259
259
|
className: "gap-1",
|
|
260
|
-
children: [/* @__PURE__ */
|
|
260
|
+
children: [/* @__PURE__ */ y(s, { className: "h-3 w-3" }), N("semanticfed.queryConsole.result.truncated", "Truncated — more rows matched")]
|
|
261
261
|
})
|
|
262
262
|
]
|
|
263
263
|
})
|
|
264
|
-
}), /* @__PURE__ */
|
|
264
|
+
}), /* @__PURE__ */ y(T, { children: /* @__PURE__ */ y("div", {
|
|
265
265
|
className: "max-h-[28rem] overflow-auto rounded border",
|
|
266
|
-
children: /* @__PURE__ */
|
|
266
|
+
children: /* @__PURE__ */ b("table", {
|
|
267
267
|
className: "w-full text-left text-xs",
|
|
268
|
-
children: [/* @__PURE__ */
|
|
268
|
+
children: [/* @__PURE__ */ y("thead", {
|
|
269
269
|
className: "sticky top-0 bg-muted",
|
|
270
|
-
children: /* @__PURE__ */
|
|
270
|
+
children: /* @__PURE__ */ y("tr", { children: K.columns.map((e) => /* @__PURE__ */ b("th", {
|
|
271
271
|
className: "whitespace-nowrap px-3 py-2 font-medium",
|
|
272
|
-
children: [/* @__PURE__ */
|
|
272
|
+
children: [/* @__PURE__ */ b("span", {
|
|
273
273
|
className: "inline-flex items-center gap-1",
|
|
274
|
-
children: [e.name, e.masked && /* @__PURE__ */
|
|
274
|
+
children: [e.name, e.masked && /* @__PURE__ */ y(d, {
|
|
275
275
|
className: "h-3 w-3 text-muted-foreground",
|
|
276
|
-
"aria-label":
|
|
276
|
+
"aria-label": N("semanticfed.queryConsole.result.masked", "Masked by policy ({mask})", { mask: e.mask ?? "" })
|
|
277
277
|
})]
|
|
278
|
-
}), /* @__PURE__ */
|
|
278
|
+
}), /* @__PURE__ */ y("span", {
|
|
279
279
|
className: "block text-[10px] font-normal text-muted-foreground",
|
|
280
280
|
children: e.aggregation ?? e.dataType
|
|
281
281
|
})]
|
|
282
282
|
}, e.name)) })
|
|
283
|
-
}), /* @__PURE__ */
|
|
283
|
+
}), /* @__PURE__ */ b("tbody", { children: [K.rows.map((e, t) => /* @__PURE__ */ y("tr", {
|
|
284
284
|
className: "border-t",
|
|
285
|
-
children:
|
|
285
|
+
children: K.columns.map((t) => /* @__PURE__ */ y("td", {
|
|
286
286
|
className: "whitespace-nowrap px-3 py-1.5 font-mono",
|
|
287
|
-
children:
|
|
287
|
+
children: j(e[t.name])
|
|
288
288
|
}, t.name))
|
|
289
|
-
}, t)),
|
|
290
|
-
colSpan:
|
|
289
|
+
}, t)), K.rows.length === 0 && /* @__PURE__ */ y("tr", { children: /* @__PURE__ */ y("td", {
|
|
290
|
+
colSpan: K.columns.length,
|
|
291
291
|
className: "px-3 py-4 text-center text-muted-foreground",
|
|
292
|
-
children:
|
|
292
|
+
children: N("semanticfed.queryConsole.result.empty", "No rows matched")
|
|
293
293
|
}) })] })]
|
|
294
294
|
})
|
|
295
295
|
}) })]
|
|
296
296
|
}),
|
|
297
|
-
/* @__PURE__ */
|
|
297
|
+
/* @__PURE__ */ b(w, { children: [/* @__PURE__ */ y(E, { children: /* @__PURE__ */ b(D, {
|
|
298
298
|
className: "flex items-center gap-2 text-base",
|
|
299
|
-
children: [/* @__PURE__ */
|
|
300
|
-
}) }), /* @__PURE__ */
|
|
299
|
+
children: [/* @__PURE__ */ y(l, { className: "h-4 w-4" }), N("semanticfed.queryConsole.history.title", "Query History")]
|
|
300
|
+
}) }), /* @__PURE__ */ y(T, { children: X.length === 0 ? /* @__PURE__ */ y("p", {
|
|
301
301
|
className: "text-xs text-muted-foreground",
|
|
302
|
-
children:
|
|
303
|
-
}) : /* @__PURE__ */
|
|
302
|
+
children: N("semanticfed.queryConsole.history.empty", "Statements you run in this session appear here.")
|
|
303
|
+
}) : /* @__PURE__ */ y("div", {
|
|
304
304
|
className: "space-y-2",
|
|
305
|
-
children:
|
|
305
|
+
children: X.map((e) => /* @__PURE__ */ b("button", {
|
|
306
306
|
type: "button",
|
|
307
307
|
className: "flex w-full items-start gap-3 rounded border p-3 text-left hover:bg-muted",
|
|
308
|
-
onClick: () =>
|
|
309
|
-
children: [e.ok ? /* @__PURE__ */
|
|
308
|
+
onClick: () => U(e.sql),
|
|
309
|
+
children: [e.ok ? /* @__PURE__ */ y(c, { className: "mt-0.5 h-4 w-4 shrink-0 text-primary" }) : /* @__PURE__ */ y(_, { className: "mt-0.5 h-4 w-4 shrink-0 text-destructive" }), /* @__PURE__ */ b("div", {
|
|
310
310
|
className: "min-w-0 flex-1",
|
|
311
|
-
children: [/* @__PURE__ */
|
|
311
|
+
children: [/* @__PURE__ */ y("p", {
|
|
312
312
|
className: "truncate font-mono text-xs",
|
|
313
313
|
children: e.sql
|
|
314
|
-
}), /* @__PURE__ */
|
|
314
|
+
}), /* @__PURE__ */ b("div", {
|
|
315
315
|
className: "mt-1 flex flex-wrap items-center gap-3 text-xs text-muted-foreground",
|
|
316
316
|
children: [
|
|
317
|
-
/* @__PURE__ */
|
|
318
|
-
e.ok ? /* @__PURE__ */
|
|
317
|
+
/* @__PURE__ */ y("span", { children: e.modelName }),
|
|
318
|
+
e.ok ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y("span", { children: N("semanticfed.queryConsole.history.results", "{count} results", { count: e.rowCount.toLocaleString() }) }), /* @__PURE__ */ b("span", { children: [e.durationMs, "ms"] })] }) : /* @__PURE__ */ y("span", {
|
|
319
319
|
className: "truncate",
|
|
320
320
|
children: e.message
|
|
321
321
|
}),
|
|
322
|
-
/* @__PURE__ */
|
|
322
|
+
/* @__PURE__ */ y("span", { children: e.executedAt })
|
|
323
323
|
]
|
|
324
324
|
})]
|
|
325
325
|
})]
|
|
326
326
|
}, e.id))
|
|
327
327
|
}) })] }),
|
|
328
|
-
/* @__PURE__ */
|
|
328
|
+
/* @__PURE__ */ b(w, { children: [/* @__PURE__ */ y(E, {
|
|
329
329
|
className: "pb-2",
|
|
330
|
-
children: /* @__PURE__ */
|
|
330
|
+
children: /* @__PURE__ */ b(D, {
|
|
331
331
|
className: "flex items-center gap-2 text-base",
|
|
332
|
-
children: [/* @__PURE__ */
|
|
332
|
+
children: [/* @__PURE__ */ y(m, { className: "h-4 w-4" }), N("semanticfed.queryConsole.connect.title", "Connect BI tools and notebooks")]
|
|
333
333
|
})
|
|
334
|
-
}), /* @__PURE__ */
|
|
334
|
+
}), /* @__PURE__ */ b(T, {
|
|
335
335
|
className: "space-y-2 text-xs text-muted-foreground",
|
|
336
|
-
children: [/* @__PURE__ */
|
|
336
|
+
children: [/* @__PURE__ */ y("p", { children: N("semanticfed.queryConsole.connect.body", "The same SQL runs over HTTPS: POST the semExecuteSql operation to the workspace API with a workspace token. Power BI (Web connector), Tableau (Web Data Connector), Python/pandas, Jupyter and reverse-ETL HTTP sources can all call it; see the SQL endpoint guide in the SemanticFed docs.") }), /* @__PURE__ */ y("pre", {
|
|
337
337
|
className: "overflow-x-auto rounded bg-muted p-3 font-mono text-[11px] text-foreground",
|
|
338
|
-
children: `mutation { semExecuteSql(input: { modelId: "${
|
|
338
|
+
children: `mutation { semExecuteSql(input: { modelId: "${L ?? "<model-id>"}", sql: "SELECT ..." }) { columns { name dataType } rows truncated } }`
|
|
339
339
|
})]
|
|
340
340
|
})] })
|
|
341
341
|
]
|
|
@@ -345,6 +345,6 @@ function j() {
|
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
//#endregion
|
|
348
|
-
export {
|
|
348
|
+
export { M as QueryConsolePage };
|
|
349
349
|
|
|
350
350
|
//# sourceMappingURL=QueryConsolePage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryConsolePage.js","names":[],"sources":["../../../src/semanticfed/pages/QueryConsolePage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { Badge, Button, Card, CardContent, CardHeader, CardTitle } from '@burdenoff/fe-libs/ui';\nimport {\n AlertTriangle,\n CheckCircle2,\n Clock,\n Database,\n EyeOff,\n Loader2,\n Play,\n Plug,\n Table2,\n Terminal,\n XCircle,\n} from 'lucide-react';\n\nimport {\n type SemSqlCatalogTable,\n type SemSqlResult,\n useSemExecuteSql,\n useSemSqlCatalog,\n useSemSqlModels,\n} from '../hooks/useSqlConsole';\nimport { translateWithFallback } from '../utils/i18n';\n\n/** Row caps offered in the console (the endpoint allows up to 10,000). */\nconst ROW_LIMIT_OPTIONS = [100, 1000, 10000] as const;\n/** Session history entries kept on the page. */\nconst HISTORY_LIMIT = 10;\n\ninterface HistoryEntry {\n id: number;\n sql: string;\n modelName: string;\n ok: boolean;\n rowCount: number;\n durationMs: number;\n message: string | null;\n executedAt: string;\n}\n\nfunction starterSql(table: SemSqlCatalogTable | undefined): string {\n if (!table) return '';\n const dimension = table.columns.find((c) => c.kind === 'DIMENSION');\n const metric = table.columns.find((c) => c.kind === 'METRIC');\n const quote = (name: string) =>\n /^[A-Za-z_][A-Za-z0-9_]*$/.test(name) ? name : `\"${name.replace(/\"/g, '\"\"')}\"`;\n const tableName = quote(table.name);\n if (dimension && metric) {\n const fn =\n metric.aggregation && ['SUM', 'AVG', 'MIN', 'MAX', 'COUNT'].includes(metric.aggregation)\n ? metric.aggregation\n : 'SUM';\n return `SELECT ${quote(dimension.name)}, ${fn}(${quote(metric.name)}) AS ${quote(`${fn.toLowerCase()}_${metric.name}`)}\\nFROM ${tableName}\\nGROUP BY ${quote(dimension.name)}\\nORDER BY 2 DESC\\nLIMIT 100;`;\n }\n return `SELECT *\\nFROM ${tableName}\\nLIMIT 100;`;\n}\n\nfunction formatCell(value: unknown): string {\n if (value === null || value === undefined) return 'NULL';\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n}\n\nexport function QueryConsolePage() {\n const { t } = useI18n();\n const tx = (key: string, fallback: string, params?: Record<string, string | number>) =>\n translateWithFallback(t, key, fallback, params);\n\n const models = useSemSqlModels();\n // The user's model choice; until they pick one, the first model is used.\n const [chosenModelId, setChosenModelId] = useState<string | null>(null);\n const modelId = chosenModelId ?? models.data?.[0]?.id ?? null;\n const catalog = useSemSqlCatalog(modelId);\n const execute = useSemExecuteSql();\n // `null` = untouched: the editor shows a runnable starter statement for the model.\n const [typedSql, setTypedSql] = useState<string | null>(null);\n const sql = typedSql ?? starterSql(catalog.data?.tables[0]);\n const setSql = (value: string) => setTypedSql(value);\n const [maxRows, setMaxRows] = useState<number>(1000);\n const [result, setResult] = useState<SemSqlResult | null>(null);\n const [error, setError] = useState<string | null>(null);\n const [history, setHistory] = useState<HistoryEntry[]>([]);\n\n const modelName = useMemo(\n () => models.data?.find((m) => m.id === modelId)?.name ?? '',\n [models.data, modelId]\n );\n\n const run = async () => {\n if (!modelId || sql.trim() === '' || execute.isPending) return;\n setError(null);\n const statement = sql;\n const entryBase = {\n id: Date.now(),\n sql: statement,\n modelName,\n executedAt: new Date().toLocaleTimeString(),\n };\n try {\n const data = await execute.mutateAsync({ sql: statement, modelId, maxRows });\n setResult(data);\n setHistory((h) =>\n [\n {\n ...entryBase,\n ok: true,\n rowCount: data.rowCount,\n durationMs: Math.round(data.durationMs),\n message: null,\n },\n ...h,\n ].slice(0, HISTORY_LIMIT)\n );\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n setResult(null);\n setError(message);\n setHistory((h) =>\n [{ ...entryBase, ok: false, rowCount: 0, durationMs: 0, message }, ...h].slice(\n 0,\n HISTORY_LIMIT\n )\n );\n }\n };\n\n const insertText = (text: string) => setSql(sql.trim() === '' ? text : `${sql}${text}`);\n\n const noModels = models.isSuccess && models.data.length === 0;\n\n return (\n <div className=\"space-y-6 p-6\">\n <div\n className=\"flex flex-wrap items-center justify-between gap-3\"\n data-tour=\"semanticfed-query-console-header\"\n >\n <div>\n <h1 className=\"text-2xl font-semibold\">\n {tx('semanticfed.queryConsole.title', 'Query Console')}\n </h1>\n <p className=\"text-sm text-muted-foreground\">\n {tx(\n 'semanticfed.queryConsole.sqlDescription',\n 'Run read-only SQL against a semantic model. Every statement is federated across its data sources with your access policies applied.'\n )}\n </p>\n </div>\n <div className=\"flex gap-2\">\n <Badge variant=\"outline\" className=\"gap-1\">\n <Terminal className=\"h-3 w-3\" /> SQL SELECT\n </Badge>\n <Badge variant=\"outline\" className=\"gap-1\">\n <Plug className=\"h-3 w-3\" />\n {tx('semanticfed.queryConsole.badges.httpApi', 'HTTP SQL API')}\n </Badge>\n </div>\n </div>\n\n {noModels && (\n <Card>\n <CardContent className=\"flex items-center gap-3 p-6 text-sm text-muted-foreground\">\n <Database className=\"h-5 w-5\" />\n {tx(\n 'semanticfed.queryConsole.noModels',\n 'No semantic model yet. Create a model with entities, dimensions and metrics, then query it here with SQL.'\n )}\n </CardContent>\n </Card>\n )}\n\n <div className=\"grid gap-4 lg:grid-cols-[18rem_minmax(0,1fr)]\">\n <Card className=\"min-w-0\">\n <CardHeader className=\"pb-3\">\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <Table2 className=\"h-4 w-4\" />\n {tx('semanticfed.queryConsole.schema.title', 'Tables')}\n </CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-3\">\n <label\n className=\"block text-xs font-medium text-muted-foreground\"\n htmlFor=\"sql-console-model\"\n >\n {tx('semanticfed.queryConsole.schema.model', 'Semantic model')}\n </label>\n <select\n id=\"sql-console-model\"\n data-testid=\"sql-console-model\"\n className=\"w-full rounded border bg-background p-2 text-sm\"\n value={modelId ?? ''}\n onChange={(e) => {\n setChosenModelId(e.target.value || null);\n setTypedSql(null);\n setResult(null);\n setError(null);\n }}\n disabled={!models.data || models.data.length === 0}\n >\n {(models.data ?? []).map((m) => (\n <option key={m.id} value={m.id}>\n {m.name}\n </option>\n ))}\n </select>\n {models.isError && (\n <p className=\"text-xs text-destructive\">{(models.error as Error).message}</p>\n )}\n {catalog.isLoading && (\n <Loader2 className=\"h-4 w-4 animate-spin text-muted-foreground\" />\n )}\n {catalog.isError && (\n <p className=\"text-xs text-destructive\">{(catalog.error as Error).message}</p>\n )}\n <div className=\"max-h-96 space-y-2 overflow-y-auto\" data-testid=\"sql-console-tables\">\n {(catalog.data?.tables ?? []).map((table) => (\n <details\n key={table.name}\n className=\"rounded border p-2\"\n open={catalog.data?.tables.length === 1}\n >\n <summary className=\"cursor-pointer truncate font-mono text-xs font-medium\">\n {table.name}\n </summary>\n <ul className=\"mt-2 space-y-1\">\n {table.columns.map((column) => (\n <li key={column.name}>\n <button\n type=\"button\"\n className=\"flex w-full items-center justify-between gap-2 rounded px-1 text-left font-mono text-xs hover:bg-muted\"\n onClick={() => insertText(column.name)}\n title={column.description ?? undefined}\n >\n <span className=\"truncate\">{column.name}</span>\n <span className=\"shrink-0 text-[10px] text-muted-foreground\">\n {column.kind === 'METRIC'\n ? (column.aggregation ?? 'METRIC')\n : column.dataType}\n </span>\n </button>\n </li>\n ))}\n {table.columns.length === 0 && (\n <li className=\"text-xs text-muted-foreground\">\n {tx(\n 'semanticfed.queryConsole.schema.noColumns',\n 'No dimensions or metrics registered'\n )}\n </li>\n )}\n </ul>\n </details>\n ))}\n </div>\n </CardContent>\n </Card>\n\n <div className=\"min-w-0 space-y-4\">\n <Card>\n <CardHeader className=\"pb-3\">\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <CardTitle className=\"text-base\">\n {tx('semanticfed.queryConsole.editor.title', 'Query Editor')}\n </CardTitle>\n <div className=\"flex items-center gap-2\">\n <label className=\"sr-only\" htmlFor=\"sql-console-max-rows\">\n {tx('semanticfed.queryConsole.editor.maxRowsLabel', 'Maximum rows')}\n </label>\n <select\n id=\"sql-console-max-rows\"\n className=\"rounded border bg-background p-1 text-xs\"\n value={maxRows}\n onChange={(e) => setMaxRows(Number(e.target.value))}\n >\n {ROW_LIMIT_OPTIONS.map((n) => (\n <option key={n} value={n}>\n {tx('semanticfed.queryConsole.editor.maxRowsOption', 'Max {count} rows', {\n count: n.toLocaleString(),\n })}\n </option>\n ))}\n </select>\n <Button\n size=\"sm\"\n onClick={() => void run()}\n disabled={!modelId || sql.trim() === '' || execute.isPending}\n data-testid=\"sql-console-run\"\n >\n {execute.isPending ? (\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n ) : (\n <Play className=\"mr-2 h-4 w-4\" />\n )}\n {tx('semanticfed.queryConsole.actions.execute', 'Execute')}\n </Button>\n </div>\n </div>\n </CardHeader>\n <CardContent>\n <textarea\n aria-label={tx('semanticfed.queryConsole.editor.ariaLabel', 'SQL statement')}\n data-testid=\"sql-console-editor\"\n className=\"w-full rounded border bg-muted/30 p-4 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary\"\n rows={8}\n value={sql}\n onChange={(e) => setSql(e.target.value)}\n onKeyDown={(e) => {\n if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {\n e.preventDefault();\n void run();\n }\n }}\n spellCheck={false}\n placeholder=\"SELECT region, SUM(revenue) FROM orders GROUP BY region\"\n />\n <div className=\"mt-2 flex flex-wrap items-center gap-4 text-xs text-muted-foreground\">\n <span>\n {tx('semanticfed.queryConsole.editor.shortcut', 'Ctrl/Cmd + Enter to run')}\n </span>\n <span>{tx('semanticfed.queryConsole.editor.timeout', 'Timeout: 30s')}</span>\n <span>\n {tx(\n 'semanticfed.queryConsole.editor.supported',\n 'SELECT, JOIN … ON, WHERE … AND, GROUP BY, ORDER BY, LIMIT/OFFSET'\n )}\n </span>\n </div>\n </CardContent>\n </Card>\n\n {error && (\n <Card data-testid=\"sql-console-error\">\n <CardContent className=\"flex items-start gap-3 p-4 text-sm text-destructive\">\n <XCircle className=\"mt-0.5 h-4 w-4 shrink-0\" />\n <span className=\"break-words\">{error}</span>\n </CardContent>\n </Card>\n )}\n\n {result && (\n <Card data-testid=\"sql-console-result\">\n <CardHeader className=\"pb-3\">\n <div className=\"flex flex-wrap items-center gap-3 text-sm\">\n <CheckCircle2 className=\"h-4 w-4 text-primary\" />\n <span className=\"font-medium\" data-testid=\"sql-console-row-count\">\n {tx('semanticfed.queryConsole.result.rows', '{count} rows', {\n count: result.rowCount.toLocaleString(),\n })}\n </span>\n <span className=\"text-muted-foreground\">{Math.round(result.durationMs)}ms</span>\n <span className=\"text-muted-foreground\">\n {tx('semanticfed.queryConsole.result.sources', '{count} sources', {\n count: result.sourcesTouched,\n })}\n </span>\n {result.truncated && (\n <Badge variant=\"outline\" className=\"gap-1\">\n <AlertTriangle className=\"h-3 w-3\" />\n {tx(\n 'semanticfed.queryConsole.result.truncated',\n 'Truncated — more rows matched'\n )}\n </Badge>\n )}\n </div>\n </CardHeader>\n <CardContent>\n <div className=\"max-h-[28rem] overflow-auto rounded border\">\n <table className=\"w-full text-left text-xs\">\n <thead className=\"sticky top-0 bg-muted\">\n <tr>\n {result.columns.map((column) => (\n <th key={column.name} className=\"whitespace-nowrap px-3 py-2 font-medium\">\n <span className=\"inline-flex items-center gap-1\">\n {column.name}\n {column.masked && (\n <EyeOff\n className=\"h-3 w-3 text-muted-foreground\"\n aria-label={tx(\n 'semanticfed.queryConsole.result.masked',\n 'Masked by policy ({mask})',\n {\n mask: column.mask ?? '',\n }\n )}\n />\n )}\n </span>\n <span className=\"block text-[10px] font-normal text-muted-foreground\">\n {column.aggregation ?? column.dataType}\n </span>\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {result.rows.map((row, index) => (\n <tr key={index} className=\"border-t\">\n {result.columns.map((column) => (\n <td\n key={column.name}\n className=\"whitespace-nowrap px-3 py-1.5 font-mono\"\n >\n {formatCell(row[column.name])}\n </td>\n ))}\n </tr>\n ))}\n {result.rows.length === 0 && (\n <tr>\n <td\n colSpan={result.columns.length}\n className=\"px-3 py-4 text-center text-muted-foreground\"\n >\n {tx('semanticfed.queryConsole.result.empty', 'No rows matched')}\n </td>\n </tr>\n )}\n </tbody>\n </table>\n </div>\n </CardContent>\n </Card>\n )}\n\n <Card>\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <Clock className=\"h-4 w-4\" />\n {tx('semanticfed.queryConsole.history.title', 'Query History')}\n </CardTitle>\n </CardHeader>\n <CardContent>\n {history.length === 0 ? (\n <p className=\"text-xs text-muted-foreground\">\n {tx(\n 'semanticfed.queryConsole.history.empty',\n 'Statements you run in this session appear here.'\n )}\n </p>\n ) : (\n <div className=\"space-y-2\">\n {history.map((entry) => (\n <button\n type=\"button\"\n key={entry.id}\n className=\"flex w-full items-start gap-3 rounded border p-3 text-left hover:bg-muted\"\n onClick={() => setSql(entry.sql)}\n >\n {entry.ok ? (\n <CheckCircle2 className=\"mt-0.5 h-4 w-4 shrink-0 text-primary\" />\n ) : (\n <XCircle className=\"mt-0.5 h-4 w-4 shrink-0 text-destructive\" />\n )}\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate font-mono text-xs\">{entry.sql}</p>\n <div className=\"mt-1 flex flex-wrap items-center gap-3 text-xs text-muted-foreground\">\n <span>{entry.modelName}</span>\n {entry.ok ? (\n <>\n <span>\n {tx('semanticfed.queryConsole.history.results', '{count} results', {\n count: entry.rowCount.toLocaleString(),\n })}\n </span>\n <span>{entry.durationMs}ms</span>\n </>\n ) : (\n <span className=\"truncate\">{entry.message}</span>\n )}\n <span>{entry.executedAt}</span>\n </div>\n </div>\n </button>\n ))}\n </div>\n )}\n </CardContent>\n </Card>\n\n <Card>\n <CardHeader className=\"pb-2\">\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <Plug className=\"h-4 w-4\" />\n {tx('semanticfed.queryConsole.connect.title', 'Connect BI tools and notebooks')}\n </CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-2 text-xs text-muted-foreground\">\n <p>\n {tx(\n 'semanticfed.queryConsole.connect.body',\n 'The same SQL runs over HTTPS: POST the semExecuteSql operation to the workspace API with a workspace token. Power BI (Web connector), Tableau (Web Data Connector), Python/pandas, Jupyter and reverse-ETL HTTP sources can all call it; see the SQL endpoint guide in the SemanticFed docs.'\n )}\n </p>\n <pre className=\"overflow-x-auto rounded bg-muted p-3 font-mono text-[11px] text-foreground\">\n {`mutation { semExecuteSql(input: { modelId: \"${modelId ?? '<model-id>'}\", sql: \"SELECT ...\" }) { columns { name dataType } rows truncated } }`}\n </pre>\n </CardContent>\n </Card>\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AA2BA,IAAM,IAAoB;CAAC;CAAK;CAAM;CAAM,EAEtC,IAAgB;AAatB,SAAS,EAAW,GAA+C;AACjE,KAAI,CAAC,EAAO,QAAO;CACnB,IAAM,IAAY,EAAM,QAAQ,MAAM,MAAM,EAAE,SAAS,YAAY,EAC7D,IAAS,EAAM,QAAQ,MAAM,MAAM,EAAE,SAAS,SAAS,EACvD,KAAS,MACb,2BAA2B,KAAK,EAAK,GAAG,IAAO,IAAI,EAAK,QAAQ,MAAM,OAAK,CAAC,IACxE,IAAY,EAAM,EAAM,KAAK;AACnC,KAAI,KAAa,GAAQ;EACvB,IAAM,IACJ,EAAO,eAAe;GAAC;GAAO;GAAO;GAAO;GAAO;GAAQ,CAAC,SAAS,EAAO,YAAY,GACpF,EAAO,cACP;AACN,SAAO,UAAU,EAAM,EAAU,KAAK,CAAC,IAAI,EAAG,GAAG,EAAM,EAAO,KAAK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AiC,CACrE;;OACD,CAAA,EACb,kBAAC,GAAD;OAAa,WAAU;iBAAvB,CACE,kBAAC,KAAD,EAAA,UACG,EACC,yCACA,+RACD,EACC,CAAA,EACJ,kBAAC,OAAD;QAAK,WAAU;kBACZ,+CAA+C,KAAW,aAAa;QACpE,CAAA,CACM;SACT,EAAA,CAAA;MACH;OACF;;GACF"}
|
|
1
|
+
{"version":3,"file":"QueryConsolePage.js","names":[],"sources":["../../../src/semanticfed/pages/QueryConsolePage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { Badge, Button, Card, CardContent, CardHeader, CardTitle } from '@burdenoff/fe-libs/ui';\nimport {\n AlertTriangle,\n CheckCircle2,\n Clock,\n Database,\n EyeOff,\n Loader2,\n Play,\n Plug,\n Table2,\n Terminal,\n XCircle,\n} from 'lucide-react';\n\nimport {\n type SemSqlCatalogTable,\n type SemSqlResult,\n sqlErrorMessage,\n useSemExecuteSql,\n useSemSqlCatalog,\n useSemSqlModels,\n} from '../hooks/useSqlConsole';\nimport { translateWithFallback } from '../utils/i18n';\n\n/** Row caps offered in the console (the endpoint allows up to 10,000). */\nconst ROW_LIMIT_OPTIONS = [100, 1000, 10000] as const;\n/** Session history entries kept on the page. */\nconst HISTORY_LIMIT = 10;\n\ninterface HistoryEntry {\n id: number;\n sql: string;\n modelName: string;\n ok: boolean;\n rowCount: number;\n durationMs: number;\n message: string | null;\n executedAt: string;\n}\n\nfunction starterSql(table: SemSqlCatalogTable | undefined): string {\n if (!table) return '';\n const dimension = table.columns.find((c) => c.kind === 'DIMENSION');\n const metric = table.columns.find((c) => c.kind === 'METRIC');\n const quote = (name: string) =>\n /^[A-Za-z_][A-Za-z0-9_]*$/.test(name) ? name : `\"${name.replace(/\"/g, '\"\"')}\"`;\n const tableName = quote(table.name);\n if (dimension && metric) {\n const fn =\n metric.aggregation && ['SUM', 'AVG', 'MIN', 'MAX', 'COUNT'].includes(metric.aggregation)\n ? metric.aggregation\n : 'SUM';\n return `SELECT ${quote(dimension.name)}, ${fn}(${quote(metric.name)}) AS ${quote(`${fn.toLowerCase()}_${metric.name}`)}\\nFROM ${tableName}\\nGROUP BY ${quote(dimension.name)}\\nORDER BY 2 DESC\\nLIMIT 100;`;\n }\n return `SELECT *\\nFROM ${tableName}\\nLIMIT 100;`;\n}\n\nfunction formatCell(value: unknown): string {\n if (value === null || value === undefined) return 'NULL';\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n}\n\nexport function QueryConsolePage() {\n const { t } = useI18n();\n const tx = (key: string, fallback: string, params?: Record<string, string | number>) =>\n translateWithFallback(t, key, fallback, params);\n\n const models = useSemSqlModels();\n // The user's model choice; until they pick one, the first model is used.\n const [chosenModelId, setChosenModelId] = useState<string | null>(null);\n const modelId = chosenModelId ?? models.data?.[0]?.id ?? null;\n const catalog = useSemSqlCatalog(modelId);\n const execute = useSemExecuteSql();\n // `null` = untouched: the editor shows a runnable starter statement for the model.\n const [typedSql, setTypedSql] = useState<string | null>(null);\n const sql = typedSql ?? starterSql(catalog.data?.tables[0]);\n const setSql = (value: string) => setTypedSql(value);\n const [maxRows, setMaxRows] = useState<number>(1000);\n const [result, setResult] = useState<SemSqlResult | null>(null);\n const [error, setError] = useState<string | null>(null);\n const [history, setHistory] = useState<HistoryEntry[]>([]);\n\n const modelName = useMemo(\n () => models.data?.find((m) => m.id === modelId)?.name ?? '',\n [models.data, modelId]\n );\n\n const run = async () => {\n if (!modelId || sql.trim() === '' || execute.isPending) return;\n setError(null);\n const statement = sql;\n const entryBase = {\n id: Date.now(),\n sql: statement,\n modelName,\n executedAt: new Date().toLocaleTimeString(),\n };\n try {\n const data = await execute.mutateAsync({ sql: statement, modelId, maxRows });\n setResult(data);\n setHistory((h) =>\n [\n {\n ...entryBase,\n ok: true,\n rowCount: data.rowCount,\n durationMs: Math.round(data.durationMs),\n message: null,\n },\n ...h,\n ].slice(0, HISTORY_LIMIT)\n );\n } catch (e) {\n const message = sqlErrorMessage(e);\n setResult(null);\n setError(message);\n setHistory((h) =>\n [{ ...entryBase, ok: false, rowCount: 0, durationMs: 0, message }, ...h].slice(\n 0,\n HISTORY_LIMIT\n )\n );\n }\n };\n\n const insertText = (text: string) => setSql(sql.trim() === '' ? text : `${sql}${text}`);\n\n const noModels = models.isSuccess && models.data.length === 0;\n\n return (\n <div className=\"space-y-6 p-6\">\n <div\n className=\"flex flex-wrap items-center justify-between gap-3\"\n data-tour=\"semanticfed-query-console-header\"\n >\n <div>\n <h1 className=\"text-2xl font-semibold\">\n {tx('semanticfed.queryConsole.title', 'Query Console')}\n </h1>\n <p className=\"text-sm text-muted-foreground\">\n {tx(\n 'semanticfed.queryConsole.sqlDescription',\n 'Run read-only SQL against a semantic model. Every statement is federated across its data sources with your access policies applied.'\n )}\n </p>\n </div>\n <div className=\"flex gap-2\">\n <Badge variant=\"outline\" className=\"gap-1\">\n <Terminal className=\"h-3 w-3\" /> SQL SELECT\n </Badge>\n <Badge variant=\"outline\" className=\"gap-1\">\n <Plug className=\"h-3 w-3\" />\n {tx('semanticfed.queryConsole.badges.httpApi', 'HTTP SQL API')}\n </Badge>\n </div>\n </div>\n\n {noModels && (\n <Card>\n <CardContent className=\"flex items-center gap-3 p-6 text-sm text-muted-foreground\">\n <Database className=\"h-5 w-5\" />\n {tx(\n 'semanticfed.queryConsole.noModels',\n 'No semantic model yet. Create a model with entities, dimensions and metrics, then query it here with SQL.'\n )}\n </CardContent>\n </Card>\n )}\n\n <div className=\"grid gap-4 lg:grid-cols-[18rem_minmax(0,1fr)]\">\n <Card className=\"min-w-0\">\n <CardHeader className=\"pb-3\">\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <Table2 className=\"h-4 w-4\" />\n {tx('semanticfed.queryConsole.schema.title', 'Tables')}\n </CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-3\">\n <label\n className=\"block text-xs font-medium text-muted-foreground\"\n htmlFor=\"sql-console-model\"\n >\n {tx('semanticfed.queryConsole.schema.model', 'Semantic model')}\n </label>\n <select\n id=\"sql-console-model\"\n data-testid=\"sql-console-model\"\n className=\"w-full rounded border bg-background p-2 text-sm\"\n value={modelId ?? ''}\n onChange={(e) => {\n setChosenModelId(e.target.value || null);\n setTypedSql(null);\n setResult(null);\n setError(null);\n }}\n disabled={!models.data || models.data.length === 0}\n >\n {(models.data ?? []).map((m) => (\n <option key={m.id} value={m.id}>\n {m.name}\n </option>\n ))}\n </select>\n {models.isError && (\n <p className=\"text-xs text-destructive\">{sqlErrorMessage(models.error)}</p>\n )}\n {catalog.isLoading && (\n <Loader2 className=\"h-4 w-4 animate-spin text-muted-foreground\" />\n )}\n {catalog.isError && (\n <p className=\"text-xs text-destructive\">{sqlErrorMessage(catalog.error)}</p>\n )}\n <div className=\"max-h-96 space-y-2 overflow-y-auto\" data-testid=\"sql-console-tables\">\n {(catalog.data?.tables ?? []).map((table) => (\n <details\n key={table.name}\n className=\"rounded border p-2\"\n open={catalog.data?.tables.length === 1}\n >\n <summary className=\"cursor-pointer truncate font-mono text-xs font-medium\">\n {table.name}\n </summary>\n <ul className=\"mt-2 space-y-1\">\n {table.columns.map((column) => (\n <li key={column.name}>\n <button\n type=\"button\"\n className=\"flex w-full items-center justify-between gap-2 rounded px-1 text-left font-mono text-xs hover:bg-muted\"\n onClick={() => insertText(column.name)}\n title={column.description ?? undefined}\n >\n <span className=\"truncate\">{column.name}</span>\n <span className=\"shrink-0 text-[10px] text-muted-foreground\">\n {column.kind === 'METRIC'\n ? (column.aggregation ?? 'METRIC')\n : column.dataType}\n </span>\n </button>\n </li>\n ))}\n {table.columns.length === 0 && (\n <li className=\"text-xs text-muted-foreground\">\n {tx(\n 'semanticfed.queryConsole.schema.noColumns',\n 'No dimensions or metrics registered'\n )}\n </li>\n )}\n </ul>\n </details>\n ))}\n </div>\n </CardContent>\n </Card>\n\n <div className=\"min-w-0 space-y-4\">\n <Card>\n <CardHeader className=\"pb-3\">\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <CardTitle className=\"text-base\">\n {tx('semanticfed.queryConsole.editor.title', 'Query Editor')}\n </CardTitle>\n <div className=\"flex items-center gap-2\">\n <label className=\"sr-only\" htmlFor=\"sql-console-max-rows\">\n {tx('semanticfed.queryConsole.editor.maxRowsLabel', 'Maximum rows')}\n </label>\n <select\n id=\"sql-console-max-rows\"\n className=\"rounded border bg-background p-1 text-xs\"\n value={maxRows}\n onChange={(e) => setMaxRows(Number(e.target.value))}\n >\n {ROW_LIMIT_OPTIONS.map((n) => (\n <option key={n} value={n}>\n {tx('semanticfed.queryConsole.editor.maxRowsOption', 'Max {count} rows', {\n count: n.toLocaleString(),\n })}\n </option>\n ))}\n </select>\n <Button\n size=\"sm\"\n onClick={() => void run()}\n disabled={!modelId || sql.trim() === '' || execute.isPending}\n data-testid=\"sql-console-run\"\n >\n {execute.isPending ? (\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n ) : (\n <Play className=\"mr-2 h-4 w-4\" />\n )}\n {tx('semanticfed.queryConsole.actions.execute', 'Execute')}\n </Button>\n </div>\n </div>\n </CardHeader>\n <CardContent>\n <textarea\n aria-label={tx('semanticfed.queryConsole.editor.ariaLabel', 'SQL statement')}\n data-testid=\"sql-console-editor\"\n className=\"w-full rounded border bg-muted/30 p-4 font-mono text-sm leading-relaxed focus:outline-none focus:ring-2 focus:ring-primary\"\n rows={8}\n value={sql}\n onChange={(e) => setSql(e.target.value)}\n onKeyDown={(e) => {\n if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {\n e.preventDefault();\n void run();\n }\n }}\n spellCheck={false}\n placeholder=\"SELECT region, SUM(revenue) FROM orders GROUP BY region\"\n />\n <div className=\"mt-2 flex flex-wrap items-center gap-4 text-xs text-muted-foreground\">\n <span>\n {tx('semanticfed.queryConsole.editor.shortcut', 'Ctrl/Cmd + Enter to run')}\n </span>\n <span>{tx('semanticfed.queryConsole.editor.timeout', 'Timeout: 30s')}</span>\n <span>\n {tx(\n 'semanticfed.queryConsole.editor.supported',\n 'SELECT, JOIN … ON, WHERE … AND, GROUP BY, ORDER BY, LIMIT/OFFSET'\n )}\n </span>\n </div>\n </CardContent>\n </Card>\n\n {error && (\n <Card data-testid=\"sql-console-error\">\n <CardContent className=\"flex items-start gap-3 p-4 text-sm text-destructive\">\n <XCircle className=\"mt-0.5 h-4 w-4 shrink-0\" />\n <span className=\"break-words\">{error}</span>\n </CardContent>\n </Card>\n )}\n\n {result && (\n <Card data-testid=\"sql-console-result\">\n <CardHeader className=\"pb-3\">\n <div className=\"flex flex-wrap items-center gap-3 text-sm\">\n <CheckCircle2 className=\"h-4 w-4 text-primary\" />\n <span className=\"font-medium\" data-testid=\"sql-console-row-count\">\n {tx('semanticfed.queryConsole.result.rows', '{count} rows', {\n count: result.rowCount.toLocaleString(),\n })}\n </span>\n <span className=\"text-muted-foreground\">{Math.round(result.durationMs)}ms</span>\n <span className=\"text-muted-foreground\">\n {tx('semanticfed.queryConsole.result.sources', '{count} sources', {\n count: result.sourcesTouched,\n })}\n </span>\n {result.truncated && (\n <Badge variant=\"outline\" className=\"gap-1\">\n <AlertTriangle className=\"h-3 w-3\" />\n {tx(\n 'semanticfed.queryConsole.result.truncated',\n 'Truncated — more rows matched'\n )}\n </Badge>\n )}\n </div>\n </CardHeader>\n <CardContent>\n <div className=\"max-h-[28rem] overflow-auto rounded border\">\n <table className=\"w-full text-left text-xs\">\n <thead className=\"sticky top-0 bg-muted\">\n <tr>\n {result.columns.map((column) => (\n <th key={column.name} className=\"whitespace-nowrap px-3 py-2 font-medium\">\n <span className=\"inline-flex items-center gap-1\">\n {column.name}\n {column.masked && (\n <EyeOff\n className=\"h-3 w-3 text-muted-foreground\"\n aria-label={tx(\n 'semanticfed.queryConsole.result.masked',\n 'Masked by policy ({mask})',\n {\n mask: column.mask ?? '',\n }\n )}\n />\n )}\n </span>\n <span className=\"block text-[10px] font-normal text-muted-foreground\">\n {column.aggregation ?? column.dataType}\n </span>\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {result.rows.map((row, index) => (\n <tr key={index} className=\"border-t\">\n {result.columns.map((column) => (\n <td\n key={column.name}\n className=\"whitespace-nowrap px-3 py-1.5 font-mono\"\n >\n {formatCell(row[column.name])}\n </td>\n ))}\n </tr>\n ))}\n {result.rows.length === 0 && (\n <tr>\n <td\n colSpan={result.columns.length}\n className=\"px-3 py-4 text-center text-muted-foreground\"\n >\n {tx('semanticfed.queryConsole.result.empty', 'No rows matched')}\n </td>\n </tr>\n )}\n </tbody>\n </table>\n </div>\n </CardContent>\n </Card>\n )}\n\n <Card>\n <CardHeader>\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <Clock className=\"h-4 w-4\" />\n {tx('semanticfed.queryConsole.history.title', 'Query History')}\n </CardTitle>\n </CardHeader>\n <CardContent>\n {history.length === 0 ? (\n <p className=\"text-xs text-muted-foreground\">\n {tx(\n 'semanticfed.queryConsole.history.empty',\n 'Statements you run in this session appear here.'\n )}\n </p>\n ) : (\n <div className=\"space-y-2\">\n {history.map((entry) => (\n <button\n type=\"button\"\n key={entry.id}\n className=\"flex w-full items-start gap-3 rounded border p-3 text-left hover:bg-muted\"\n onClick={() => setSql(entry.sql)}\n >\n {entry.ok ? (\n <CheckCircle2 className=\"mt-0.5 h-4 w-4 shrink-0 text-primary\" />\n ) : (\n <XCircle className=\"mt-0.5 h-4 w-4 shrink-0 text-destructive\" />\n )}\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate font-mono text-xs\">{entry.sql}</p>\n <div className=\"mt-1 flex flex-wrap items-center gap-3 text-xs text-muted-foreground\">\n <span>{entry.modelName}</span>\n {entry.ok ? (\n <>\n <span>\n {tx('semanticfed.queryConsole.history.results', '{count} results', {\n count: entry.rowCount.toLocaleString(),\n })}\n </span>\n <span>{entry.durationMs}ms</span>\n </>\n ) : (\n <span className=\"truncate\">{entry.message}</span>\n )}\n <span>{entry.executedAt}</span>\n </div>\n </div>\n </button>\n ))}\n </div>\n )}\n </CardContent>\n </Card>\n\n <Card>\n <CardHeader className=\"pb-2\">\n <CardTitle className=\"flex items-center gap-2 text-base\">\n <Plug className=\"h-4 w-4\" />\n {tx('semanticfed.queryConsole.connect.title', 'Connect BI tools and notebooks')}\n </CardTitle>\n </CardHeader>\n <CardContent className=\"space-y-2 text-xs text-muted-foreground\">\n <p>\n {tx(\n 'semanticfed.queryConsole.connect.body',\n 'The same SQL runs over HTTPS: POST the semExecuteSql operation to the workspace API with a workspace token. Power BI (Web connector), Tableau (Web Data Connector), Python/pandas, Jupyter and reverse-ETL HTTP sources can all call it; see the SQL endpoint guide in the SemanticFed docs.'\n )}\n </p>\n <pre className=\"overflow-x-auto rounded bg-muted p-3 font-mono text-[11px] text-foreground\">\n {`mutation { semExecuteSql(input: { modelId: \"${modelId ?? '<model-id>'}\", sql: \"SELECT ...\" }) { columns { name dataType } rows truncated } }`}\n </pre>\n </CardContent>\n </Card>\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AA4BA,IAAM,IAAoB;CAAC;CAAK;CAAM;CAAM,EAEtC,IAAgB;AAatB,SAAS,EAAW,GAA+C;AACjE,KAAI,CAAC,EAAO,QAAO;CACnB,IAAM,IAAY,EAAM,QAAQ,MAAM,MAAM,EAAE,SAAS,YAAY,EAC7D,IAAS,EAAM,QAAQ,MAAM,MAAM,EAAE,SAAS,SAAS,EACvD,KAAS,MACb,2BAA2B,KAAK,EAAK,GAAG,IAAO,IAAI,EAAK,QAAQ,MAAM,OAAK,CAAC,IACxE,IAAY,EAAM,EAAM,KAAK;AACnC,KAAI,KAAa,GAAQ;EACvB,IAAM,IACJ,EAAO,eAAe;GAAC;GAAO;GAAO;GAAO;GAAO;GAAQ,CAAC,SAAS,EAAO,YAAY,GACpF,EAAO,cACP;AACN,SAAO,UAAU,EAAM,EAAU,KAAK,CAAC,IAAI,EAAG,GAAG,EAAM,EAAO,KAAK,CAAC,OAAO,EAAM,GAAG,EAAG,aAAa,CAAC,GAAG,EAAO,OAAO,CAAC,SAAS,EAAU,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