@tetrascience-npm/tetrascience-react-ui 0.4.0-beta.9.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +58 -4
  2. package/dist/athena.d.ts +167 -0
  3. package/dist/databricks.d.ts +129 -0
  4. package/dist/exceptions-DN25pCDi.cjs +2 -0
  5. package/dist/exceptions-DN25pCDi.cjs.map +1 -0
  6. package/dist/exceptions-jCQ6h5C8.js +33 -0
  7. package/dist/exceptions-jCQ6h5C8.js.map +1 -0
  8. package/dist/index.cjs +2021 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.css +1 -1
  11. package/dist/index.d.ts +2165 -2020
  12. package/dist/index.js +9461 -2
  13. package/dist/index.js.map +1 -0
  14. package/dist/logo.png +0 -0
  15. package/dist/providers/athena.cjs +2 -0
  16. package/dist/providers/athena.cjs.map +1 -0
  17. package/dist/providers/athena.d.ts +7 -77
  18. package/dist/providers/athena.js +160 -0
  19. package/dist/providers/athena.js.map +1 -0
  20. package/dist/providers/databricks.cjs +2 -0
  21. package/dist/providers/databricks.cjs.map +1 -0
  22. package/dist/providers/databricks.d.ts +7 -41
  23. package/dist/providers/databricks.js +85 -0
  24. package/dist/providers/databricks.js.map +1 -0
  25. package/dist/providers/snowflake.cjs +2 -0
  26. package/dist/providers/snowflake.cjs.map +1 -0
  27. package/dist/providers/snowflake.d.ts +7 -38
  28. package/dist/providers/snowflake.js +122 -0
  29. package/dist/providers/snowflake.js.map +1 -0
  30. package/dist/server.cjs +2 -0
  31. package/dist/server.cjs.map +1 -0
  32. package/dist/server.d.ts +537 -522
  33. package/dist/server.js +266 -0
  34. package/dist/server.js.map +1 -0
  35. package/dist/{providers/types-Ck4uFaGp.d.ts → snowflake.d.ts} +125 -82
  36. package/dist/vite.svg +1 -0
  37. package/package.json +32 -52
  38. package/dist/cjs/index.js +0 -2001
  39. package/dist/cjs/index.js.map +0 -1
  40. package/dist/cjs/providers/athena.js +0 -2
  41. package/dist/cjs/providers/athena.js.map +0 -1
  42. package/dist/cjs/providers/databricks.js +0 -2
  43. package/dist/cjs/providers/databricks.js.map +0 -1
  44. package/dist/cjs/providers/exceptions-CYktpdqW.js +0 -2
  45. package/dist/cjs/providers/exceptions-CYktpdqW.js.map +0 -1
  46. package/dist/cjs/providers/snowflake.js +0 -2
  47. package/dist/cjs/providers/snowflake.js.map +0 -1
  48. package/dist/cjs/server.js +0 -2
  49. package/dist/cjs/server.js.map +0 -1
  50. package/dist/esm/index.js +0 -2001
  51. package/dist/esm/index.js.map +0 -1
  52. package/dist/esm/providers/athena.js +0 -2
  53. package/dist/esm/providers/athena.js.map +0 -1
  54. package/dist/esm/providers/databricks.js +0 -2
  55. package/dist/esm/providers/databricks.js.map +0 -1
  56. package/dist/esm/providers/exceptions-C3uFWZB2.js +0 -2
  57. package/dist/esm/providers/exceptions-C3uFWZB2.js.map +0 -1
  58. package/dist/esm/providers/snowflake.js +0 -2
  59. package/dist/esm/providers/snowflake.js.map +0 -1
  60. package/dist/esm/server.js +0 -2
  61. package/dist/esm/server.js.map +0 -1
package/dist/logo.png ADDED
Binary file
@@ -0,0 +1,2 @@
1
+ "use strict";var g=Object.create;var p=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var k=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of S(t))!T.call(e,n)&&n!==r&&p(e,n,{get:()=>t[n],enumerable:!(o=f(t,n))||o.enumerable});return e};var v=(e,t,r)=>(r=e!=null?g(C(e)):{},k(t||!e||!e.__esModule?p(r,"default",{value:e,enumerable:!0}):r,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../exceptions-DN25pCDi.cjs"),x=1e3;async function Q(){try{return await import("@aws-sdk/client-athena")}catch{throw new i.InvalidProviderConfigurationError("The '@aws-sdk/client-athena' package is required to use the Athena provider. Please install it: npm install @aws-sdk/client-athena")}}const _=262144;class m{client;sdk;workgroup;database;outputLocation;constructor(t,r,o,n,a){this.client=t,this.sdk=r,this.workgroup=o,this.database=n,this.outputLocation=a}async query(t,r={}){if(t.length>_)throw new Error("Query length exceeds the maximum allowed limit.");const o=new this.sdk.StartQueryExecutionCommand({QueryString:t,WorkGroup:this.workgroup,QueryExecutionContext:{Database:this.database},ResultConfiguration:this.outputLocation?{OutputLocation:this.outputLocation}:void 0}),a=(await this.client.send(o)).QueryExecutionId;if(!a)throw new i.QueryError("Failed to start query execution");return await this.waitForQueryCompletion(a,t),this.fetchAllResults(a)}async waitForQueryCompletion(t,r){const a=Date.now();for(;Date.now()-a<3e5;){const l=new this.sdk.GetQueryExecutionCommand({QueryExecutionId:t}),s=await this.client.send(l),u=s.QueryExecution?.Status?.State;if(u===this.sdk.QueryExecutionState.SUCCEEDED)return;if(u===this.sdk.QueryExecutionState.FAILED||u===this.sdk.QueryExecutionState.CANCELLED){const c=s.QueryExecution?.Status?.StateChangeReason??"Unknown error";if(c.includes("TABLE_NOT_FOUND")){const h=c.split(":").pop()?.trim()??"";throw new i.MissingTableError("Athena is unable to find the table. If the table is created by a tetraflow, make sure that the tetraflow has run successfully. "+h+".")}throw new i.QueryError(`Query failed: ${r}. Reason: ${c}`)}await new Promise(c=>setTimeout(c,1e3))}throw new i.QueryError(`Query timed out after ${3e5/x} seconds`)}async fetchAllResults(t){const r=[];let o,n=[],a=!0;do{const l=new this.sdk.GetQueryResultsCommand({QueryExecutionId:t,NextToken:o}),s=await this.client.send(l);a&&s.ResultSet?.ResultSetMetadata?.ColumnInfo&&(n=s.ResultSet.ResultSetMetadata.ColumnInfo.map((h,w)=>{const d=h.Name;return d&&d.trim()!==""?d:`column_${w}`}));const u=s.ResultSet?.Rows??[],c=a?u.slice(1):u;for(const h of c){const w={};h.Data?.forEach((d,E)=>{const y=n[E]??`column_${E}`;w[y]=d.VarCharValue??null}),r.push(w)}o=s.NextToken,a=!1}while(o);return r}async close(){this.client.destroy()}}async function A(){const e=await Q(),t=process.env.ORG_SLUG??"",r=t.replace(/-/g,"_"),o=process.env.ATHENA_S3_OUTPUT_LOCATION,n=process.env.AWS_REGION,a=`${r}__tss__default`,l=t,s=new e.AthenaClient({region:n});try{return await s.send(new e.GetWorkGroupCommand({WorkGroup:l})),new m(s,e,l,a)}catch{if(!o)throw new Error("ATHENA_S3_OUTPUT_LOCATION environment variable is required when using the 'primary' workgroup. Either set this variable or ensure the org-specific workgroup exists.");const u=`s3://${o}/${r}/`;return new m(s,e,"primary",a,u)}}exports.InvalidProviderConfigurationError=i.InvalidProviderConfigurationError;exports.MissingTableError=i.MissingTableError;exports.ProviderConnectionError=i.ProviderConnectionError;exports.ProviderError=i.ProviderError;exports.QueryError=i.QueryError;exports.AthenaProvider=m;exports.getTdpAthenaProvider=A;
2
+ //# sourceMappingURL=athena.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"athena.cjs","sources":["../../src/server/providers/AthenaProvider.ts"],"sourcesContent":["/**\n * Athena Data Provider\n *\n * TypeScript equivalent of AthenaProvider from\n * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py\n *\n * @remarks\n * This provider requires the `@aws-sdk/client-athena` package to be installed.\n * It is an optional peer dependency - install it only if you need Athena support:\n * ```bash\n * npm install @aws-sdk/client-athena\n * # or\n * yarn add @aws-sdk/client-athena\n * ```\n */\n\nimport {\n QueryError,\n MissingTableError,\n InvalidProviderConfigurationError,\n} from \"./exceptions\";\n\n/** Milliseconds per second */\nconst MILLISECONDS_PER_SECOND = 1000;\n\n// Type imports for @aws-sdk/client-athena (these don't require the package at runtime)\ntype AthenaClient = import(\"@aws-sdk/client-athena\").AthenaClient;\ntype AthenaSDK = typeof import(\"@aws-sdk/client-athena\");\n\n/**\n * Dynamically import @aws-sdk/client-athena\n * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed\n */\nasync function getAthenaSDK(): Promise<AthenaSDK> {\n try {\n return await import(\"@aws-sdk/client-athena\");\n } catch {\n throw new InvalidProviderConfigurationError(\n \"The '@aws-sdk/client-athena' package is required to use the Athena provider. \" +\n \"Please install it: npm install @aws-sdk/client-athena\",\n );\n }\n}\n\n/** Maximum query length allowed by Athena */\nconst MAX_QUERY_LENGTH = 262144;\n\n/**\n * Athena data provider\n */\nexport class AthenaProvider {\n private client: AthenaClient;\n private sdk: AthenaSDK;\n private workgroup: string;\n private database: string;\n private outputLocation?: string;\n\n /**\n * Initialize the Athena data provider\n *\n * @param client - AWS Athena client\n * @param sdk - AWS Athena SDK module (for accessing command classes)\n * @param workgroup - Athena workgroup to use\n * @param database - Default database/schema\n * @param outputLocation - Optional S3 output location\n */\n constructor(\n client: AthenaClient,\n sdk: AthenaSDK,\n workgroup: string,\n database: string,\n outputLocation?: string,\n ) {\n this.client = client;\n this.sdk = sdk;\n this.workgroup = workgroup;\n this.database = database;\n this.outputLocation = outputLocation;\n }\n\n /**\n * Query the Athena database\n *\n * @param sqlQuery - SQL query to execute\n * @param _params - Parameters to pass to the query (currently not used - Athena doesn't support parameterized queries)\n * @returns Promise resolving to array of row objects\n *\n * @remarks\n * **Security Note:** AWS Athena does not support parameterized queries.\n * Unlike traditional databases, there is no native way to use bind parameters\n * with Athena. Callers are responsible for properly sanitizing any user input\n * before constructing the SQL query string. This is a known limitation of the\n * Athena service, not a design flaw in this implementation.\n */\n async query(\n sqlQuery: string,\n _params: Record<string, unknown> = {},\n ): Promise<Array<Record<string, unknown>>> {\n if (sqlQuery.length > MAX_QUERY_LENGTH) {\n throw new Error(\"Query length exceeds the maximum allowed limit.\");\n }\n\n // Start query execution\n // Note: Athena does not support parameterized queries. The sqlQuery is passed\n // directly to Athena. Callers must sanitize user input before constructing queries.\n const startCommand = new this.sdk.StartQueryExecutionCommand({\n QueryString: sqlQuery,\n WorkGroup: this.workgroup,\n QueryExecutionContext: {\n Database: this.database,\n },\n ResultConfiguration: this.outputLocation\n ? { OutputLocation: this.outputLocation }\n : undefined,\n });\n\n const startResponse = await this.client.send(startCommand);\n const queryExecutionId = startResponse.QueryExecutionId;\n\n if (!queryExecutionId) {\n throw new QueryError(\"Failed to start query execution\");\n }\n\n // Wait for query to complete\n await this.waitForQueryCompletion(queryExecutionId, sqlQuery);\n\n // Fetch results\n return this.fetchAllResults(queryExecutionId);\n }\n\n /**\n * Wait for query to complete\n */\n private async waitForQueryCompletion(\n queryExecutionId: string,\n originalQuery: string,\n ): Promise<void> {\n const maxWaitTime = 300000; // 5 minutes\n const pollInterval = 1000; // 1 second\n const startTime = Date.now();\n\n while (Date.now() - startTime < maxWaitTime) {\n const command = new this.sdk.GetQueryExecutionCommand({\n QueryExecutionId: queryExecutionId,\n });\n const response = await this.client.send(command);\n const state = response.QueryExecution?.Status?.State;\n\n if (state === this.sdk.QueryExecutionState.SUCCEEDED) {\n return;\n }\n\n if (\n state === this.sdk.QueryExecutionState.FAILED ||\n state === this.sdk.QueryExecutionState.CANCELLED\n ) {\n const reason =\n response.QueryExecution?.Status?.StateChangeReason ?? \"Unknown error\";\n\n if (reason.includes(\"TABLE_NOT_FOUND\")) {\n const errorTail = reason.split(\":\").pop()?.trim() ?? \"\";\n throw new MissingTableError(\n \"Athena is unable to find the table. If the table is created by a \" +\n \"tetraflow, make sure that the tetraflow has run successfully. \" +\n errorTail +\n \".\",\n );\n }\n\n throw new QueryError(\n `Query failed: ${originalQuery}. Reason: ${reason}`,\n );\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollInterval));\n }\n\n throw new QueryError(\n `Query timed out after ${maxWaitTime / MILLISECONDS_PER_SECOND} seconds`,\n );\n }\n\n /**\n * Fetch all results from a completed query\n */\n private async fetchAllResults(\n queryExecutionId: string,\n ): Promise<Array<Record<string, unknown>>> {\n const results: Array<Record<string, unknown>> = [];\n let nextToken: string | undefined;\n let columnNames: string[] = [];\n let isFirstPage = true;\n\n do {\n const command = new this.sdk.GetQueryResultsCommand({\n QueryExecutionId: queryExecutionId,\n NextToken: nextToken,\n });\n\n const response = await this.client.send(command);\n\n if (isFirstPage && response.ResultSet?.ResultSetMetadata?.ColumnInfo) {\n columnNames = response.ResultSet.ResultSetMetadata.ColumnInfo.map(\n (col, idx) => {\n // Handle empty or missing column names by using a fallback\n const name = col.Name;\n return name && name.trim() !== \"\" ? name : `column_${idx}`;\n },\n );\n }\n\n const rows = response.ResultSet?.Rows ?? [];\n // Skip header row on first page\n const dataRows = isFirstPage ? rows.slice(1) : rows;\n\n for (const row of dataRows) {\n const rowData: Record<string, unknown> = {};\n row.Data?.forEach((cell, index) => {\n // columnNames already has fallback values, so we can use them directly\n const columnName = columnNames[index] ?? `column_${index}`;\n rowData[columnName] = cell.VarCharValue ?? null;\n });\n results.push(rowData);\n }\n\n nextToken = response.NextToken;\n isFirstPage = false;\n } while (nextToken);\n\n return results;\n }\n\n /**\n * Close the Athena client (no-op for AWS SDK clients)\n */\n async close(): Promise<void> {\n this.client.destroy();\n }\n}\n\n/**\n * Get the TDP Athena provider\n *\n * Creates an Athena provider using TDP environment configuration\n *\n * @returns Promise resolving to Athena data provider\n * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed\n * @throws {Error} If ATHENA_S3_OUTPUT_LOCATION is not set when using the 'primary' workgroup\n */\nexport async function getTdpAthenaProvider(): Promise<AthenaProvider> {\n // Dynamically import @aws-sdk/client-athena\n const athenaSDK = await getAthenaSDK();\n\n const orgSlug = process.env.ORG_SLUG ?? \"\";\n const orgSlugDbFriendly = orgSlug.replace(/-/g, \"_\");\n const athenaQueryBucket = process.env.ATHENA_S3_OUTPUT_LOCATION;\n const athenaRegion = process.env.AWS_REGION;\n const athenaSchema = `${orgSlugDbFriendly}__tss__default`;\n const athenaWorkgroup = orgSlug;\n\n const client = new athenaSDK.AthenaClient({\n region: athenaRegion,\n });\n\n // Check if the org-specific workgroup exists\n try {\n await client.send(\n new athenaSDK.GetWorkGroupCommand({\n WorkGroup: athenaWorkgroup,\n }),\n );\n\n // Workgroup exists, use it\n return new AthenaProvider(client, athenaSDK, athenaWorkgroup, athenaSchema);\n } catch {\n // Workgroup doesn't exist or access denied, use 'primary' workgroup\n // The 'primary' workgroup requires an explicit output location\n if (!athenaQueryBucket) {\n throw new Error(\n \"ATHENA_S3_OUTPUT_LOCATION environment variable is required when using the 'primary' workgroup. \" +\n \"Either set this variable or ensure the org-specific workgroup exists.\",\n );\n }\n\n const athenaOutputLocation = `s3://${athenaQueryBucket}/${orgSlugDbFriendly}/`;\n return new AthenaProvider(\n client,\n athenaSDK,\n \"primary\",\n athenaSchema,\n athenaOutputLocation,\n );\n }\n}\n\n"],"names":["MILLISECONDS_PER_SECOND","getAthenaSDK","InvalidProviderConfigurationError","MAX_QUERY_LENGTH","AthenaProvider","client","sdk","workgroup","database","outputLocation","sqlQuery","_params","startCommand","queryExecutionId","QueryError","originalQuery","startTime","command","response","state","reason","errorTail","MissingTableError","resolve","results","nextToken","columnNames","isFirstPage","col","idx","name","rows","dataRows","row","rowData","cell","index","columnName","getTdpAthenaProvider","athenaSDK","orgSlug","orgSlugDbFriendly","athenaQueryBucket","athenaRegion","athenaSchema","athenaWorkgroup","athenaOutputLocation"],"mappings":"ykBAuBMA,EAA0B,IAUhC,eAAeC,GAAmC,CAChD,GAAI,CACF,OAAO,KAAM,QAAO,wBAAwB,CAC9C,MAAQ,CACN,MAAM,IAAIC,EAAAA,kCACR,oIAAA,CAGJ,CACF,CAGA,MAAMC,EAAmB,OAKlB,MAAMC,CAAe,CAClB,OACA,IACA,UACA,SACA,eAWR,YACEC,EACAC,EACAC,EACAC,EACAC,EACA,CACA,KAAK,OAASJ,EACd,KAAK,IAAMC,EACX,KAAK,UAAYC,EACjB,KAAK,SAAWC,EAChB,KAAK,eAAiBC,CACxB,CAgBA,MAAM,MACJC,EACAC,EAAmC,GACM,CACzC,GAAID,EAAS,OAASP,EACpB,MAAM,IAAI,MAAM,iDAAiD,EAMnE,MAAMS,EAAe,IAAI,KAAK,IAAI,2BAA2B,CAC3D,YAAaF,EACb,UAAW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H,MAAM,IAAI,MACR,sKAAA,EAKJ,MAAMI,EAAuB,QAAQJ,CAAiB,IAAID,CAAiB,IAC3E,OAAO,IAAIrC,EACTC,EACAkC,EACA,UACAK,EACAE,CAAA,CAEJ,CACF"}
@@ -1,79 +1,9 @@
1
- import * as _aws_sdk_client_athena from '@aws-sdk/client-athena';
2
- export { I as InvalidProviderConfigurationError, M as MissingTableError, P as ProviderConfiguration, a as ProviderConnectionError, b as ProviderError, Q as QueryError, c as QueryResult } from './types-Ck4uFaGp.js';
1
+ export * from '../server/providers/entries/athena'
2
+ export {}
3
3
 
4
- /**
5
- * Athena Data Provider
6
- *
7
- * TypeScript equivalent of AthenaProvider from
8
- * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py
9
- *
10
- * @remarks
11
- * This provider requires the `@aws-sdk/client-athena` package to be installed.
12
- * It is an optional peer dependency - install it only if you need Athena support:
13
- * ```bash
14
- * npm install @aws-sdk/client-athena
15
- * # or
16
- * yarn add @aws-sdk/client-athena
17
- * ```
18
- */
19
- type AthenaClient = _aws_sdk_client_athena.AthenaClient;
20
- type AthenaSDK = typeof _aws_sdk_client_athena;
21
- /**
22
- * Athena data provider
23
- */
24
- declare class AthenaProvider {
25
- private client;
26
- private sdk;
27
- private workgroup;
28
- private database;
29
- private outputLocation?;
30
- /**
31
- * Initialize the Athena data provider
32
- *
33
- * @param client - AWS Athena client
34
- * @param sdk - AWS Athena SDK module (for accessing command classes)
35
- * @param workgroup - Athena workgroup to use
36
- * @param database - Default database/schema
37
- * @param outputLocation - Optional S3 output location
38
- */
39
- constructor(client: AthenaClient, sdk: AthenaSDK, workgroup: string, database: string, outputLocation?: string);
40
- /**
41
- * Query the Athena database
42
- *
43
- * @param sqlQuery - SQL query to execute
44
- * @param _params - Parameters to pass to the query (currently not used - Athena doesn't support parameterized queries)
45
- * @returns Promise resolving to array of row objects
46
- *
47
- * @remarks
48
- * **Security Note:** AWS Athena does not support parameterized queries.
49
- * Unlike traditional databases, there is no native way to use bind parameters
50
- * with Athena. Callers are responsible for properly sanitizing any user input
51
- * before constructing the SQL query string. This is a known limitation of the
52
- * Athena service, not a design flaw in this implementation.
53
- */
54
- query(sqlQuery: string, _params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
55
- /**
56
- * Wait for query to complete
57
- */
58
- private waitForQueryCompletion;
59
- /**
60
- * Fetch all results from a completed query
61
- */
62
- private fetchAllResults;
63
- /**
64
- * Close the Athena client (no-op for AWS SDK clients)
65
- */
66
- close(): Promise<void>;
67
- }
68
- /**
69
- * Get the TDP Athena provider
70
- *
71
- * Creates an Athena provider using TDP environment configuration
72
- *
73
- * @returns Promise resolving to Athena data provider
74
- * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed
75
- * @throws {Error} If ATHENA_S3_OUTPUT_LOCATION is not set when using the 'primary' workgroup
76
- */
77
- declare function getTdpAthenaProvider(): Promise<AthenaProvider>;
78
4
 
79
- export { AthenaProvider, getTdpAthenaProvider };
5
+ declare module "styled-components" {
6
+ interface DefaultTheme {
7
+ position: ToastPosition;
8
+ }
9
+ }
@@ -0,0 +1,160 @@
1
+ import { Q as m, M as y, I as f } from "../exceptions-jCQ6h5C8.js";
2
+ import { P as Q, a as R } from "../exceptions-jCQ6h5C8.js";
3
+ const S = 1e3;
4
+ async function g() {
5
+ try {
6
+ return await import("@aws-sdk/client-athena");
7
+ } catch {
8
+ throw new f(
9
+ "The '@aws-sdk/client-athena' package is required to use the Athena provider. Please install it: npm install @aws-sdk/client-athena"
10
+ );
11
+ }
12
+ }
13
+ const k = 262144;
14
+ class p {
15
+ client;
16
+ sdk;
17
+ workgroup;
18
+ database;
19
+ outputLocation;
20
+ /**
21
+ * Initialize the Athena data provider
22
+ *
23
+ * @param client - AWS Athena client
24
+ * @param sdk - AWS Athena SDK module (for accessing command classes)
25
+ * @param workgroup - Athena workgroup to use
26
+ * @param database - Default database/schema
27
+ * @param outputLocation - Optional S3 output location
28
+ */
29
+ constructor(e, a, o, r, t) {
30
+ this.client = e, this.sdk = a, this.workgroup = o, this.database = r, this.outputLocation = t;
31
+ }
32
+ /**
33
+ * Query the Athena database
34
+ *
35
+ * @param sqlQuery - SQL query to execute
36
+ * @param _params - Parameters to pass to the query (currently not used - Athena doesn't support parameterized queries)
37
+ * @returns Promise resolving to array of row objects
38
+ *
39
+ * @remarks
40
+ * **Security Note:** AWS Athena does not support parameterized queries.
41
+ * Unlike traditional databases, there is no native way to use bind parameters
42
+ * with Athena. Callers are responsible for properly sanitizing any user input
43
+ * before constructing the SQL query string. This is a known limitation of the
44
+ * Athena service, not a design flaw in this implementation.
45
+ */
46
+ async query(e, a = {}) {
47
+ if (e.length > k)
48
+ throw new Error("Query length exceeds the maximum allowed limit.");
49
+ const o = new this.sdk.StartQueryExecutionCommand({
50
+ QueryString: e,
51
+ WorkGroup: this.workgroup,
52
+ QueryExecutionContext: {
53
+ Database: this.database
54
+ },
55
+ ResultConfiguration: this.outputLocation ? { OutputLocation: this.outputLocation } : void 0
56
+ }), t = (await this.client.send(o)).QueryExecutionId;
57
+ if (!t)
58
+ throw new m("Failed to start query execution");
59
+ return await this.waitForQueryCompletion(t, e), this.fetchAllResults(t);
60
+ }
61
+ /**
62
+ * Wait for query to complete
63
+ */
64
+ async waitForQueryCompletion(e, a) {
65
+ const t = Date.now();
66
+ for (; Date.now() - t < 3e5; ) {
67
+ const u = new this.sdk.GetQueryExecutionCommand({
68
+ QueryExecutionId: e
69
+ }), n = await this.client.send(u), s = n.QueryExecution?.Status?.State;
70
+ if (s === this.sdk.QueryExecutionState.SUCCEEDED)
71
+ return;
72
+ if (s === this.sdk.QueryExecutionState.FAILED || s === this.sdk.QueryExecutionState.CANCELLED) {
73
+ const i = n.QueryExecution?.Status?.StateChangeReason ?? "Unknown error";
74
+ if (i.includes("TABLE_NOT_FOUND")) {
75
+ const l = i.split(":").pop()?.trim() ?? "";
76
+ throw new y(
77
+ "Athena is unable to find the table. If the table is created by a tetraflow, make sure that the tetraflow has run successfully. " + l + "."
78
+ );
79
+ }
80
+ throw new m(
81
+ `Query failed: ${a}. Reason: ${i}`
82
+ );
83
+ }
84
+ await new Promise((i) => setTimeout(i, 1e3));
85
+ }
86
+ throw new m(
87
+ `Query timed out after ${3e5 / S} seconds`
88
+ );
89
+ }
90
+ /**
91
+ * Fetch all results from a completed query
92
+ */
93
+ async fetchAllResults(e) {
94
+ const a = [];
95
+ let o, r = [], t = !0;
96
+ do {
97
+ const u = new this.sdk.GetQueryResultsCommand({
98
+ QueryExecutionId: e,
99
+ NextToken: o
100
+ }), n = await this.client.send(u);
101
+ t && n.ResultSet?.ResultSetMetadata?.ColumnInfo && (r = n.ResultSet.ResultSetMetadata.ColumnInfo.map(
102
+ (l, d) => {
103
+ const h = l.Name;
104
+ return h && h.trim() !== "" ? h : `column_${d}`;
105
+ }
106
+ ));
107
+ const s = n.ResultSet?.Rows ?? [], i = t ? s.slice(1) : s;
108
+ for (const l of i) {
109
+ const d = {};
110
+ l.Data?.forEach((h, w) => {
111
+ const E = r[w] ?? `column_${w}`;
112
+ d[E] = h.VarCharValue ?? null;
113
+ }), a.push(d);
114
+ }
115
+ o = n.NextToken, t = !1;
116
+ } while (o);
117
+ return a;
118
+ }
119
+ /**
120
+ * Close the Athena client (no-op for AWS SDK clients)
121
+ */
122
+ async close() {
123
+ this.client.destroy();
124
+ }
125
+ }
126
+ async function C() {
127
+ const c = await g(), e = process.env.ORG_SLUG ?? "", a = e.replace(/-/g, "_"), o = process.env.ATHENA_S3_OUTPUT_LOCATION, r = process.env.AWS_REGION, t = `${a}__tss__default`, u = e, n = new c.AthenaClient({
128
+ region: r
129
+ });
130
+ try {
131
+ return await n.send(
132
+ new c.GetWorkGroupCommand({
133
+ WorkGroup: u
134
+ })
135
+ ), new p(n, c, u, t);
136
+ } catch {
137
+ if (!o)
138
+ throw new Error(
139
+ "ATHENA_S3_OUTPUT_LOCATION environment variable is required when using the 'primary' workgroup. Either set this variable or ensure the org-specific workgroup exists."
140
+ );
141
+ const s = `s3://${o}/${a}/`;
142
+ return new p(
143
+ n,
144
+ c,
145
+ "primary",
146
+ t,
147
+ s
148
+ );
149
+ }
150
+ }
151
+ export {
152
+ p as AthenaProvider,
153
+ f as InvalidProviderConfigurationError,
154
+ y as MissingTableError,
155
+ Q as ProviderConnectionError,
156
+ R as ProviderError,
157
+ m as QueryError,
158
+ C as getTdpAthenaProvider
159
+ };
160
+ //# sourceMappingURL=athena.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"athena.js","sources":["../../src/server/providers/AthenaProvider.ts"],"sourcesContent":["/**\n * Athena Data Provider\n *\n * TypeScript equivalent of AthenaProvider from\n * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py\n *\n * @remarks\n * This provider requires the `@aws-sdk/client-athena` package to be installed.\n * It is an optional peer dependency - install it only if you need Athena support:\n * ```bash\n * npm install @aws-sdk/client-athena\n * # or\n * yarn add @aws-sdk/client-athena\n * ```\n */\n\nimport {\n QueryError,\n MissingTableError,\n InvalidProviderConfigurationError,\n} from \"./exceptions\";\n\n/** Milliseconds per second */\nconst MILLISECONDS_PER_SECOND = 1000;\n\n// Type imports for @aws-sdk/client-athena (these don't require the package at runtime)\ntype AthenaClient = import(\"@aws-sdk/client-athena\").AthenaClient;\ntype AthenaSDK = typeof import(\"@aws-sdk/client-athena\");\n\n/**\n * Dynamically import @aws-sdk/client-athena\n * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed\n */\nasync function getAthenaSDK(): Promise<AthenaSDK> {\n try {\n return await import(\"@aws-sdk/client-athena\");\n } catch {\n throw new InvalidProviderConfigurationError(\n \"The '@aws-sdk/client-athena' package is required to use the Athena provider. \" +\n \"Please install it: npm install @aws-sdk/client-athena\",\n );\n }\n}\n\n/** Maximum query length allowed by Athena */\nconst MAX_QUERY_LENGTH = 262144;\n\n/**\n * Athena data provider\n */\nexport class AthenaProvider {\n private client: AthenaClient;\n private sdk: AthenaSDK;\n private workgroup: string;\n private database: string;\n private outputLocation?: string;\n\n /**\n * Initialize the Athena data provider\n *\n * @param client - AWS Athena client\n * @param sdk - AWS Athena SDK module (for accessing command classes)\n * @param workgroup - Athena workgroup to use\n * @param database - Default database/schema\n * @param outputLocation - Optional S3 output location\n */\n constructor(\n client: AthenaClient,\n sdk: AthenaSDK,\n workgroup: string,\n database: string,\n outputLocation?: string,\n ) {\n this.client = client;\n this.sdk = sdk;\n this.workgroup = workgroup;\n this.database = database;\n this.outputLocation = outputLocation;\n }\n\n /**\n * Query the Athena database\n *\n * @param sqlQuery - SQL query to execute\n * @param _params - Parameters to pass to the query (currently not used - Athena doesn't support parameterized queries)\n * @returns Promise resolving to array of row objects\n *\n * @remarks\n * **Security Note:** AWS Athena does not support parameterized queries.\n * Unlike traditional databases, there is no native way to use bind parameters\n * with Athena. Callers are responsible for properly sanitizing any user input\n * before constructing the SQL query string. This is a known limitation of the\n * Athena service, not a design flaw in this implementation.\n */\n async query(\n sqlQuery: string,\n _params: Record<string, unknown> = {},\n ): Promise<Array<Record<string, unknown>>> {\n if (sqlQuery.length > MAX_QUERY_LENGTH) {\n throw new Error(\"Query length exceeds the maximum allowed limit.\");\n }\n\n // Start query execution\n // Note: Athena does not support parameterized queries. The sqlQuery is passed\n // directly to Athena. Callers must sanitize user input before constructing queries.\n const startCommand = new this.sdk.StartQueryExecutionCommand({\n QueryString: sqlQuery,\n WorkGroup: this.workgroup,\n QueryExecutionContext: {\n Database: this.database,\n },\n ResultConfiguration: this.outputLocation\n ? { OutputLocation: this.outputLocation }\n : undefined,\n });\n\n const startResponse = await this.client.send(startCommand);\n const queryExecutionId = startResponse.QueryExecutionId;\n\n if (!queryExecutionId) {\n throw new QueryError(\"Failed to start query execution\");\n }\n\n // Wait for query to complete\n await this.waitForQueryCompletion(queryExecutionId, sqlQuery);\n\n // Fetch results\n return this.fetchAllResults(queryExecutionId);\n }\n\n /**\n * Wait for query to complete\n */\n private async waitForQueryCompletion(\n queryExecutionId: string,\n originalQuery: string,\n ): Promise<void> {\n const maxWaitTime = 300000; // 5 minutes\n const pollInterval = 1000; // 1 second\n const startTime = Date.now();\n\n while (Date.now() - startTime < maxWaitTime) {\n const command = new this.sdk.GetQueryExecutionCommand({\n QueryExecutionId: queryExecutionId,\n });\n const response = await this.client.send(command);\n const state = response.QueryExecution?.Status?.State;\n\n if (state === this.sdk.QueryExecutionState.SUCCEEDED) {\n return;\n }\n\n if (\n state === this.sdk.QueryExecutionState.FAILED ||\n state === this.sdk.QueryExecutionState.CANCELLED\n ) {\n const reason =\n response.QueryExecution?.Status?.StateChangeReason ?? \"Unknown error\";\n\n if (reason.includes(\"TABLE_NOT_FOUND\")) {\n const errorTail = reason.split(\":\").pop()?.trim() ?? \"\";\n throw new MissingTableError(\n \"Athena is unable to find the table. If the table is created by a \" +\n \"tetraflow, make sure that the tetraflow has run successfully. \" +\n errorTail +\n \".\",\n );\n }\n\n throw new QueryError(\n `Query failed: ${originalQuery}. Reason: ${reason}`,\n );\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollInterval));\n }\n\n throw new QueryError(\n `Query timed out after ${maxWaitTime / MILLISECONDS_PER_SECOND} seconds`,\n );\n }\n\n /**\n * Fetch all results from a completed query\n */\n private async fetchAllResults(\n queryExecutionId: string,\n ): Promise<Array<Record<string, unknown>>> {\n const results: Array<Record<string, unknown>> = [];\n let nextToken: string | undefined;\n let columnNames: string[] = [];\n let isFirstPage = true;\n\n do {\n const command = new this.sdk.GetQueryResultsCommand({\n QueryExecutionId: queryExecutionId,\n NextToken: nextToken,\n });\n\n const response = await this.client.send(command);\n\n if (isFirstPage && response.ResultSet?.ResultSetMetadata?.ColumnInfo) {\n columnNames = response.ResultSet.ResultSetMetadata.ColumnInfo.map(\n (col, idx) => {\n // Handle empty or missing column names by using a fallback\n const name = col.Name;\n return name && name.trim() !== \"\" ? name : `column_${idx}`;\n },\n );\n }\n\n const rows = response.ResultSet?.Rows ?? [];\n // Skip header row on first page\n const dataRows = isFirstPage ? rows.slice(1) : rows;\n\n for (const row of dataRows) {\n const rowData: Record<string, unknown> = {};\n row.Data?.forEach((cell, index) => {\n // columnNames already has fallback values, so we can use them directly\n const columnName = columnNames[index] ?? `column_${index}`;\n rowData[columnName] = cell.VarCharValue ?? null;\n });\n results.push(rowData);\n }\n\n nextToken = response.NextToken;\n isFirstPage = false;\n } while (nextToken);\n\n return results;\n }\n\n /**\n * Close the Athena client (no-op for AWS SDK clients)\n */\n async close(): Promise<void> {\n this.client.destroy();\n }\n}\n\n/**\n * Get the TDP Athena provider\n *\n * Creates an Athena provider using TDP environment configuration\n *\n * @returns Promise resolving to Athena data provider\n * @throws {InvalidProviderConfigurationError} If @aws-sdk/client-athena is not installed\n * @throws {Error} If ATHENA_S3_OUTPUT_LOCATION is not set when using the 'primary' workgroup\n */\nexport async function getTdpAthenaProvider(): Promise<AthenaProvider> {\n // Dynamically import @aws-sdk/client-athena\n const athenaSDK = await getAthenaSDK();\n\n const orgSlug = process.env.ORG_SLUG ?? \"\";\n const orgSlugDbFriendly = orgSlug.replace(/-/g, \"_\");\n const athenaQueryBucket = process.env.ATHENA_S3_OUTPUT_LOCATION;\n const athenaRegion = process.env.AWS_REGION;\n const athenaSchema = `${orgSlugDbFriendly}__tss__default`;\n const athenaWorkgroup = orgSlug;\n\n const client = new athenaSDK.AthenaClient({\n region: athenaRegion,\n });\n\n // Check if the org-specific workgroup exists\n try {\n await client.send(\n new athenaSDK.GetWorkGroupCommand({\n WorkGroup: athenaWorkgroup,\n }),\n );\n\n // Workgroup exists, use it\n return new AthenaProvider(client, athenaSDK, athenaWorkgroup, athenaSchema);\n } catch {\n // Workgroup doesn't exist or access denied, use 'primary' workgroup\n // The 'primary' workgroup requires an explicit output location\n if (!athenaQueryBucket) {\n throw new Error(\n \"ATHENA_S3_OUTPUT_LOCATION environment variable is required when using the 'primary' workgroup. \" +\n \"Either set this variable or ensure the org-specific workgroup exists.\",\n );\n }\n\n const athenaOutputLocation = `s3://${athenaQueryBucket}/${orgSlugDbFriendly}/`;\n return new AthenaProvider(\n client,\n athenaSDK,\n \"primary\",\n athenaSchema,\n athenaOutputLocation,\n );\n }\n}\n\n"],"names":["MILLISECONDS_PER_SECOND","getAthenaSDK","InvalidProviderConfigurationError","MAX_QUERY_LENGTH","AthenaProvider","client","sdk","workgroup","database","outputLocation","sqlQuery","_params","startCommand","queryExecutionId","QueryError","originalQuery","startTime","command","response","state","reason","errorTail","MissingTableError","resolve","results","nextToken","columnNames","isFirstPage","col","idx","name","rows","dataRows","row","rowData","cell","index","columnName","getTdpAthenaProvider","athenaSDK","orgSlug","orgSlugDbFriendly","athenaQueryBucket","athenaRegion","athenaSchema","athenaWorkgroup","athenaOutputLocation"],"mappings":";;AAuBA,MAAMA,IAA0B;AAUhC,eAAeC,IAAmC;AAChD,MAAI;AACF,WAAO,MAAM,OAAO,wBAAwB;AAAA,EAC9C,QAAQ;AACN,UAAM,IAAIC;AAAA,MACR;AAAA,IAAA;AAAA,EAGJ;AACF;AAGA,MAAMC,IAAmB;AAKlB,MAAMC,EAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWR,YACEC,GACAC,GACAC,GACAC,GACAC,GACA;AACA,SAAK,SAASJ,GACd,KAAK,MAAMC,GACX,KAAK,YAAYC,GACjB,KAAK,WAAWC,GAChB,KAAK,iBAAiBC;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,MACJC,GACAC,IAAmC,IACM;AACzC,QAAID,EAAS,SAASP;AACpB,YAAM,IAAI,MAAM,iDAAiD;AAMnE,UAAMS,IAAe,IAAI,KAAK,IAAI,2BAA2B;AAAA,MAC3D,aAAaF;AAAA,MACb,WAAW,KAAK;AAAA,MAChB,uBAAuB;AAAA,QACrB,UAAU,KAAK;AAAA,MAAA;AAAA,MAEjB,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AAAA,EAAA,CACT;AAGD,MAAI;AACF,iBAAMtC,EAAO;AAAA,MACX,IAAIkC,EAAU,oBAAoB;AAAA,QAChC,WAAWM;AAAA,MAAA,CACZ;AAAA,IAAA,GAII,IAAIzC,EAAeC,GAAQkC,GAAWM,GAAiBD,CAAY;AAAA,EAC5E,QAAQ;AAGN,QAAI,CAACF;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAKJ,UAAMI,IAAuB,QAAQJ,CAAiB,IAAID,CAAiB;AAC3E,WAAO,IAAIrC;AAAA,MACTC;AAAA,MACAkC;AAAA,MACA;AAAA,MACAK;AAAA,MACAE;AAAA,IAAA;AAAA,EAEJ;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";var b=Object.create;var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var P=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of f(e))!y.call(t,i)&&i!==r&&c(t,i,{get:()=>e[i],enumerable:!(s=g(e,i))||s.enumerable});return t};var S=(t,e,r)=>(r=t!=null?b(w(t)):{},P(e||!t||!t.__esModule?c(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../exceptions-DN25pCDi.cjs");async function _(){try{return await import("@databricks/sql")}catch{throw new o.InvalidProviderConfigurationError("The '@databricks/sql' package is required to use the Databricks provider. Please install it: npm install @databricks/sql")}}class l{client;session;constructor(e,r){this.client=e,this.session=r}async query(e,r={}){const s=await this.session.executeStatement(e);try{return await s.fetchAll()}finally{await s.close()}}async close(){await this.session.close(),await this.client.close()}}function m(){return`${(process.env.ORG_SLUG??"").replace(/-/g,"_")}__tss__default`}async function E(t){const{DBSQLClient:e}=await _(),r=["server_hostname","http_path","client_id","client_secret","catalog"];for(const n of r)if(!t.fields[n])throw new o.InvalidProviderConfigurationError(`Missing field '${n}' in the provider '${t.name}' to connect to Databricks.`);const s=t.fields.server_hostname,i=t.fields.http_path,d=t.fields.client_id,u=t.fields.client_secret,h=t.fields.catalog,v=t.fields.schema??m(),a=new e;await a.connect({host:s,path:i,authType:"databricks-oauth",oauthClientId:d,oauthClientSecret:u});const p=await a.openSession({initialCatalog:h,initialSchema:v});return new l(a,p)}exports.InvalidProviderConfigurationError=o.InvalidProviderConfigurationError;exports.MissingTableError=o.MissingTableError;exports.ProviderConnectionError=o.ProviderConnectionError;exports.ProviderError=o.ProviderError;exports.QueryError=o.QueryError;exports.DatabricksProvider=l;exports.buildDatabricksProvider=E;
2
+ //# sourceMappingURL=databricks.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"databricks.cjs","sources":["../../src/server/providers/DatabricksProvider.ts"],"sourcesContent":["/**\n * Databricks Data Provider\n *\n * TypeScript equivalent of DatabricksProvider from\n * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py\n *\n * @remarks\n * This provider requires the `@databricks/sql` package to be installed.\n * It is an optional peer dependency - install it only if you need Databricks support:\n * ```bash\n * npm install @databricks/sql\n * # or\n * yarn add @databricks/sql\n * ```\n */\n\nimport { InvalidProviderConfigurationError } from \"./exceptions\";\n\nimport type { ProviderConfiguration } from \"./types\";\n\n// Type imports for @databricks/sql (these don't require the package at runtime)\ntype DBSQLClient = import(\"@databricks/sql\").DBSQLClient;\ntype IDBSQLSession = import(\"@databricks/sql/dist/contracts/IDBSQLSession\").default;\n\n/**\n * Dynamically import @databricks/sql\n * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed\n */\nasync function getDatabricksSQL(): Promise<typeof import(\"@databricks/sql\")> {\n try {\n return await import(\"@databricks/sql\");\n } catch {\n throw new InvalidProviderConfigurationError(\n \"The '@databricks/sql' package is required to use the Databricks provider. \" +\n \"Please install it: npm install @databricks/sql\",\n );\n }\n}\n\n/**\n * Databricks data provider\n */\nexport class DatabricksProvider {\n private client: DBSQLClient;\n private session: IDBSQLSession;\n\n /**\n * Initialize the Databricks data provider\n *\n * @param client - Databricks SQL client\n * @param session - Databricks SQL session\n */\n constructor(client: DBSQLClient, session: IDBSQLSession) {\n this.client = client;\n this.session = session;\n }\n\n /**\n * Query the Databricks database\n *\n * @param sqlQuery - SQL query to execute\n * @param _params - Parameters to pass to the query (currently not used)\n * @returns Promise resolving to array of row objects\n */\n async query(\n sqlQuery: string,\n _params: Record<string, unknown> = {},\n ): Promise<Array<Record<string, unknown>>> {\n const operation = await this.session.executeStatement(sqlQuery);\n try {\n const result = await operation.fetchAll();\n return result as Array<Record<string, unknown>>;\n } finally {\n // Always close the operation to avoid leaking server-side resources\n await operation.close();\n }\n }\n\n /**\n * Close the Databricks connection\n */\n async close(): Promise<void> {\n await this.session.close();\n await this.client.close();\n }\n}\n\n/**\n * Get the default Athena schema from environment\n */\nfunction getDefaultSchema(): string {\n const orgSlug = process.env.ORG_SLUG ?? \"\";\n const orgSlugDbFriendly = orgSlug.replace(/-/g, \"_\");\n return `${orgSlugDbFriendly}__tss__default`;\n}\n\n/**\n * Build a Databricks data provider from the configuration\n *\n * @param config - Provider configuration\n * @returns Promise resolving to Databricks data provider\n * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed or config is invalid\n */\nexport async function buildDatabricksProvider(\n config: ProviderConfiguration,\n): Promise<DatabricksProvider> {\n // Dynamically import @databricks/sql\n const { DBSQLClient } = await getDatabricksSQL();\n\n const requiredFields = [\n \"server_hostname\",\n \"http_path\",\n \"client_id\",\n \"client_secret\",\n \"catalog\",\n ] as const;\n\n for (const field of requiredFields) {\n if (!config.fields[field]) {\n throw new InvalidProviderConfigurationError(\n `Missing field '${field}' in the provider '${config.name}' to connect to Databricks.`,\n );\n }\n }\n\n const serverHostname = config.fields[\"server_hostname\"]!;\n const httpPath = config.fields[\"http_path\"]!;\n const clientId = config.fields[\"client_id\"]!;\n const clientSecret = config.fields[\"client_secret\"]!;\n const catalog = config.fields[\"catalog\"]!;\n const schema = config.fields[\"schema\"] ?? getDefaultSchema();\n\n const client = new DBSQLClient();\n\n await client.connect({\n host: serverHostname,\n path: httpPath,\n authType: \"databricks-oauth\",\n oauthClientId: clientId,\n oauthClientSecret: clientSecret,\n });\n\n const session = await client.openSession({\n initialCatalog: catalog,\n initialSchema: schema,\n });\n\n return new DatabricksProvider(client, session);\n}\n\n"],"names":["getDatabricksSQL","InvalidProviderConfigurationError","DatabricksProvider","client","session","sqlQuery","_params","operation","getDefaultSchema","buildDatabricksProvider","config","DBSQLClient","requiredFields","field","serverHostname","httpPath","clientId","clientSecret","catalog","schema"],"mappings":"ykBA4BA,eAAeA,GAA8D,CAC3E,GAAI,CACF,OAAO,KAAM,QAAO,iBAAiB,CACvC,MAAQ,CACN,MAAM,IAAIC,EAAAA,kCACR,0HAAA,CAGJ,CACF,CAKO,MAAMC,CAAmB,CACtB,OACA,QAQR,YAAYC,EAAqBC,EAAwB,CACvD,KAAK,OAASD,EACd,KAAK,QAAUC,CACjB,CASA,MAAM,MACJC,EACAC,EAAmC,GACM,CACzC,MAAMC,EAAY,MAAM,KAAK,QAAQ,iBAAiBF,CAAQ,EAC9D,GAAI,CAEF,OADe,MAAME,EAAU,SAAA,CAEjC,QAAA,CAEE,MAAMA,EAAU,MAAA,CAClB,CACF,CAKA,MAAM,OAAuB,CAC3B,MAAM,KAAK,QAAQ,MAAA,EACnB,MAAM,KAAK,OAAO,MAAA,CACpB,CACF,CAKA,SAASC,GAA2B,CAGlC,MAAO,IAFS,QAAQ,IAAI,UAAY,IACN,QAAQ,KAAM,GAAG,CACxB,gBAC7B,CASA,eAAsBC,EACpBC,EAC6B,CAE7B,KAAM,CAAE,YAAAC,GAAgB,MAAMX,EAAA,EAExBY,EAAiB,CACrB,kBACA,YACA,YACA,gBACA,SAAA,EAGF,UAAWC,KAASD,EAClB,GAAI,CAACF,EAAO,OAAOG,CAAK,EACtB,MAAM,IAAIZ,EAAAA,kCACR,kBAAkBY,CAAK,sBAAsBH,EAAO,IAAI,6BAAA,EAK9D,MAAMI,EAAiBJ,EAAO,OAAO,gBAC/BK,EAAWL,EAAO,OAAO,UACzBM,EAAWN,EAAO,OAAO,UACzBO,EAAeP,EAAO,OAAO,cAC7BQ,EAAUR,EAAO,OAAO,QACxBS,EAAST,EAAO,OAAO,QAAaF,EAAA,EAEpCL,EAAS,IAAIQ,EAEnB,MAAMR,EAAO,QAAQ,CACnB,KAAMW,EACN,KAAMC,EACN,SAAU,mBACV,cAAeC,EACf,kBAAmBC,CAAA,CACpB,EAED,MAAMb,EAAU,MAAMD,EAAO,YAAY,CACvC,eAAgBe,EAChB,cAAeC,CAAA,CAChB,EAED,OAAO,IAAIjB,EAAmBC,EAAQC,CAAO,CAC/C"}
@@ -1,43 +1,9 @@
1
- import * as _databricks_sql_dist_contracts_IDBSQLSession from '@databricks/sql/dist/contracts/IDBSQLSession';
2
- import * as _databricks_sql from '@databricks/sql';
3
- import { P as ProviderConfiguration } from './types-Ck4uFaGp.js';
4
- export { I as InvalidProviderConfigurationError, M as MissingTableError, a as ProviderConnectionError, b as ProviderError, Q as QueryError, c as QueryResult } from './types-Ck4uFaGp.js';
1
+ export * from '../server/providers/entries/databricks'
2
+ export {}
5
3
 
6
- type DBSQLClient = _databricks_sql.DBSQLClient;
7
- type IDBSQLSession = _databricks_sql_dist_contracts_IDBSQLSession.default;
8
- /**
9
- * Databricks data provider
10
- */
11
- declare class DatabricksProvider {
12
- private client;
13
- private session;
14
- /**
15
- * Initialize the Databricks data provider
16
- *
17
- * @param client - Databricks SQL client
18
- * @param session - Databricks SQL session
19
- */
20
- constructor(client: DBSQLClient, session: IDBSQLSession);
21
- /**
22
- * Query the Databricks database
23
- *
24
- * @param sqlQuery - SQL query to execute
25
- * @param _params - Parameters to pass to the query (currently not used)
26
- * @returns Promise resolving to array of row objects
27
- */
28
- query(sqlQuery: string, _params?: Record<string, unknown>): Promise<Array<Record<string, unknown>>>;
29
- /**
30
- * Close the Databricks connection
31
- */
32
- close(): Promise<void>;
33
- }
34
- /**
35
- * Build a Databricks data provider from the configuration
36
- *
37
- * @param config - Provider configuration
38
- * @returns Promise resolving to Databricks data provider
39
- * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed or config is invalid
40
- */
41
- declare function buildDatabricksProvider(config: ProviderConfiguration): Promise<DatabricksProvider>;
42
4
 
43
- export { DatabricksProvider, ProviderConfiguration, buildDatabricksProvider };
5
+ declare module "styled-components" {
6
+ interface DefaultTheme {
7
+ position: ToastPosition;
8
+ }
9
+ }
@@ -0,0 +1,85 @@
1
+ import { I as o } from "../exceptions-jCQ6h5C8.js";
2
+ import { M as g, P as v, a as y, Q as k } from "../exceptions-jCQ6h5C8.js";
3
+ async function p() {
4
+ try {
5
+ return await import("@databricks/sql");
6
+ } catch {
7
+ throw new o(
8
+ "The '@databricks/sql' package is required to use the Databricks provider. Please install it: npm install @databricks/sql"
9
+ );
10
+ }
11
+ }
12
+ class f {
13
+ client;
14
+ session;
15
+ /**
16
+ * Initialize the Databricks data provider
17
+ *
18
+ * @param client - Databricks SQL client
19
+ * @param session - Databricks SQL session
20
+ */
21
+ constructor(e, s) {
22
+ this.client = e, this.session = s;
23
+ }
24
+ /**
25
+ * Query the Databricks database
26
+ *
27
+ * @param sqlQuery - SQL query to execute
28
+ * @param _params - Parameters to pass to the query (currently not used)
29
+ * @returns Promise resolving to array of row objects
30
+ */
31
+ async query(e, s = {}) {
32
+ const a = await this.session.executeStatement(e);
33
+ try {
34
+ return await a.fetchAll();
35
+ } finally {
36
+ await a.close();
37
+ }
38
+ }
39
+ /**
40
+ * Close the Databricks connection
41
+ */
42
+ async close() {
43
+ await this.session.close(), await this.client.close();
44
+ }
45
+ }
46
+ function m() {
47
+ return `${(process.env.ORG_SLUG ?? "").replace(/-/g, "_")}__tss__default`;
48
+ }
49
+ async function _(t) {
50
+ const { DBSQLClient: e } = await p(), s = [
51
+ "server_hostname",
52
+ "http_path",
53
+ "client_id",
54
+ "client_secret",
55
+ "catalog"
56
+ ];
57
+ for (const n of s)
58
+ if (!t.fields[n])
59
+ throw new o(
60
+ `Missing field '${n}' in the provider '${t.name}' to connect to Databricks.`
61
+ );
62
+ const a = t.fields.server_hostname, i = t.fields.http_path, c = t.fields.client_id, l = t.fields.client_secret, d = t.fields.catalog, h = t.fields.schema ?? m(), r = new e();
63
+ await r.connect({
64
+ host: a,
65
+ path: i,
66
+ authType: "databricks-oauth",
67
+ oauthClientId: c,
68
+ oauthClientSecret: l
69
+ });
70
+ const u = await r.openSession({
71
+ initialCatalog: d,
72
+ initialSchema: h
73
+ });
74
+ return new f(r, u);
75
+ }
76
+ export {
77
+ f as DatabricksProvider,
78
+ o as InvalidProviderConfigurationError,
79
+ g as MissingTableError,
80
+ v as ProviderConnectionError,
81
+ y as ProviderError,
82
+ k as QueryError,
83
+ _ as buildDatabricksProvider
84
+ };
85
+ //# sourceMappingURL=databricks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"databricks.js","sources":["../../src/server/providers/DatabricksProvider.ts"],"sourcesContent":["/**\n * Databricks Data Provider\n *\n * TypeScript equivalent of DatabricksProvider from\n * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py\n *\n * @remarks\n * This provider requires the `@databricks/sql` package to be installed.\n * It is an optional peer dependency - install it only if you need Databricks support:\n * ```bash\n * npm install @databricks/sql\n * # or\n * yarn add @databricks/sql\n * ```\n */\n\nimport { InvalidProviderConfigurationError } from \"./exceptions\";\n\nimport type { ProviderConfiguration } from \"./types\";\n\n// Type imports for @databricks/sql (these don't require the package at runtime)\ntype DBSQLClient = import(\"@databricks/sql\").DBSQLClient;\ntype IDBSQLSession = import(\"@databricks/sql/dist/contracts/IDBSQLSession\").default;\n\n/**\n * Dynamically import @databricks/sql\n * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed\n */\nasync function getDatabricksSQL(): Promise<typeof import(\"@databricks/sql\")> {\n try {\n return await import(\"@databricks/sql\");\n } catch {\n throw new InvalidProviderConfigurationError(\n \"The '@databricks/sql' package is required to use the Databricks provider. \" +\n \"Please install it: npm install @databricks/sql\",\n );\n }\n}\n\n/**\n * Databricks data provider\n */\nexport class DatabricksProvider {\n private client: DBSQLClient;\n private session: IDBSQLSession;\n\n /**\n * Initialize the Databricks data provider\n *\n * @param client - Databricks SQL client\n * @param session - Databricks SQL session\n */\n constructor(client: DBSQLClient, session: IDBSQLSession) {\n this.client = client;\n this.session = session;\n }\n\n /**\n * Query the Databricks database\n *\n * @param sqlQuery - SQL query to execute\n * @param _params - Parameters to pass to the query (currently not used)\n * @returns Promise resolving to array of row objects\n */\n async query(\n sqlQuery: string,\n _params: Record<string, unknown> = {},\n ): Promise<Array<Record<string, unknown>>> {\n const operation = await this.session.executeStatement(sqlQuery);\n try {\n const result = await operation.fetchAll();\n return result as Array<Record<string, unknown>>;\n } finally {\n // Always close the operation to avoid leaking server-side resources\n await operation.close();\n }\n }\n\n /**\n * Close the Databricks connection\n */\n async close(): Promise<void> {\n await this.session.close();\n await this.client.close();\n }\n}\n\n/**\n * Get the default Athena schema from environment\n */\nfunction getDefaultSchema(): string {\n const orgSlug = process.env.ORG_SLUG ?? \"\";\n const orgSlugDbFriendly = orgSlug.replace(/-/g, \"_\");\n return `${orgSlugDbFriendly}__tss__default`;\n}\n\n/**\n * Build a Databricks data provider from the configuration\n *\n * @param config - Provider configuration\n * @returns Promise resolving to Databricks data provider\n * @throws {InvalidProviderConfigurationError} If @databricks/sql is not installed or config is invalid\n */\nexport async function buildDatabricksProvider(\n config: ProviderConfiguration,\n): Promise<DatabricksProvider> {\n // Dynamically import @databricks/sql\n const { DBSQLClient } = await getDatabricksSQL();\n\n const requiredFields = [\n \"server_hostname\",\n \"http_path\",\n \"client_id\",\n \"client_secret\",\n \"catalog\",\n ] as const;\n\n for (const field of requiredFields) {\n if (!config.fields[field]) {\n throw new InvalidProviderConfigurationError(\n `Missing field '${field}' in the provider '${config.name}' to connect to Databricks.`,\n );\n }\n }\n\n const serverHostname = config.fields[\"server_hostname\"]!;\n const httpPath = config.fields[\"http_path\"]!;\n const clientId = config.fields[\"client_id\"]!;\n const clientSecret = config.fields[\"client_secret\"]!;\n const catalog = config.fields[\"catalog\"]!;\n const schema = config.fields[\"schema\"] ?? getDefaultSchema();\n\n const client = new DBSQLClient();\n\n await client.connect({\n host: serverHostname,\n path: httpPath,\n authType: \"databricks-oauth\",\n oauthClientId: clientId,\n oauthClientSecret: clientSecret,\n });\n\n const session = await client.openSession({\n initialCatalog: catalog,\n initialSchema: schema,\n });\n\n return new DatabricksProvider(client, session);\n}\n\n"],"names":["getDatabricksSQL","InvalidProviderConfigurationError","DatabricksProvider","client","session","sqlQuery","_params","operation","getDefaultSchema","buildDatabricksProvider","config","DBSQLClient","requiredFields","field","serverHostname","httpPath","clientId","clientSecret","catalog","schema"],"mappings":";;AA4BA,eAAeA,IAA8D;AAC3E,MAAI;AACF,WAAO,MAAM,OAAO,iBAAiB;AAAA,EACvC,QAAQ;AACN,UAAM,IAAIC;AAAA,MACR;AAAA,IAAA;AAAA,EAGJ;AACF;AAKO,MAAMC,EAAmB;AAAA,EACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQR,YAAYC,GAAqBC,GAAwB;AACvD,SAAK,SAASD,GACd,KAAK,UAAUC;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,MACJC,GACAC,IAAmC,IACM;AACzC,UAAMC,IAAY,MAAM,KAAK,QAAQ,iBAAiBF,CAAQ;AAC9D,QAAI;AAEF,aADe,MAAME,EAAU,SAAA;AAAA,IAEjC,UAAA;AAEE,YAAMA,EAAU,MAAA;AAAA,IAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAuB;AAC3B,UAAM,KAAK,QAAQ,MAAA,GACnB,MAAM,KAAK,OAAO,MAAA;AAAA,EACpB;AACF;AAKA,SAASC,IAA2B;AAGlC,SAAO,IAFS,QAAQ,IAAI,YAAY,IACN,QAAQ,MAAM,GAAG,CACxB;AAC7B;AASA,eAAsBC,EACpBC,GAC6B;AAE7B,QAAM,EAAE,aAAAC,MAAgB,MAAMX,EAAA,GAExBY,IAAiB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,aAAWC,KAASD;AAClB,QAAI,CAACF,EAAO,OAAOG,CAAK;AACtB,YAAM,IAAIZ;AAAA,QACR,kBAAkBY,CAAK,sBAAsBH,EAAO,IAAI;AAAA,MAAA;AAK9D,QAAMI,IAAiBJ,EAAO,OAAO,iBAC/BK,IAAWL,EAAO,OAAO,WACzBM,IAAWN,EAAO,OAAO,WACzBO,IAAeP,EAAO,OAAO,eAC7BQ,IAAUR,EAAO,OAAO,SACxBS,IAAST,EAAO,OAAO,UAAaF,EAAA,GAEpCL,IAAS,IAAIQ,EAAA;AAEnB,QAAMR,EAAO,QAAQ;AAAA,IACnB,MAAMW;AAAA,IACN,MAAMC;AAAA,IACN,UAAU;AAAA,IACV,eAAeC;AAAA,IACf,mBAAmBC;AAAA,EAAA,CACpB;AAED,QAAMb,IAAU,MAAMD,EAAO,YAAY;AAAA,IACvC,gBAAgBe;AAAA,IAChB,eAAeC;AAAA,EAAA,CAChB;AAED,SAAO,IAAIjB,EAAmBC,GAAQC,CAAO;AAC/C;"}
@@ -0,0 +1,2 @@
1
+ "use strict";var f=Object.create;var u=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var k=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of E(r))!h.call(e,n)&&n!==o&&u(e,n,{get:()=>r[n],enumerable:!(t=v(r,n))||t.enumerable});return e};var m=(e,r,o)=>(o=e!=null?f(P(e)):{},k(r||!e||!e.__esModule?u(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../exceptions-DN25pCDi.cjs");async function S(){try{const e=await import("snowflake-sdk");return e.default||e}catch{throw new i.InvalidProviderConfigurationError("The 'snowflake-sdk' package is required to use the Snowflake provider. Please install it: npm install snowflake-sdk")}}class w{connection;constructor(r){this.connection=r}async query(r,o={}){const t=(Array.isArray(o),o);return new Promise((n,a)=>{this.connection.execute({sqlText:r,binds:t,complete:(c,d,s)=>{if(c){a(new i.QueryError(`Snowflake provider failed to query the database. Reason: ${c.message}`));return}n(s??[])}})})}async close(){return new Promise((r,o)=>{this.connection.destroy(t=>{if(t){o(t);return}r()})})}}async function y(e){const r=await S(),o=["user","password","account","warehouse","database","schema","role"];for(const n of o)if(!e.fields[n])throw new i.InvalidProviderConfigurationError(`Missing field '${n}' in the provider '${e.name}' to connect to Snowflake using password based authentication.`);const t={account:e.fields.account,username:e.fields.user,password:e.fields.password,warehouse:e.fields.warehouse,database:e.fields.database,schema:e.fields.schema,role:e.fields.role};return new Promise((n,a)=>{r.createConnection(t).connect((d,s)=>{if(d){a(new i.ProviderConnectionError(`Unable to connect to Snowflake. Reason: ${d.message}`));return}s.execute({sqlText:"ALTER SESSION SET TIMEZONE = 'UTC'",complete:l=>{l&&console.warn(`Warning: Failed to set timezone to UTC: ${l.message}`),n(new w(s))}})})})}exports.InvalidProviderConfigurationError=i.InvalidProviderConfigurationError;exports.MissingTableError=i.MissingTableError;exports.ProviderConnectionError=i.ProviderConnectionError;exports.ProviderError=i.ProviderError;exports.QueryError=i.QueryError;exports.SnowflakeProvider=w;exports.buildSnowflakeProvider=y;
2
+ //# sourceMappingURL=snowflake.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snowflake.cjs","sources":["../../src/server/providers/SnowflakeProvider.ts"],"sourcesContent":["/**\n * Snowflake Data Provider\n *\n * TypeScript equivalent of SnowflakeProvider from\n * ts-lib-ui-kit-streamlit/tetrascience/data_app_providers/provider.py\n *\n * @remarks\n * This provider requires the `snowflake-sdk` package to be installed.\n * It is an optional peer dependency - install it only if you need Snowflake support:\n * ```bash\n * npm install snowflake-sdk\n * # or\n * yarn add snowflake-sdk\n * ```\n */\n\nimport {\n QueryError,\n ProviderConnectionError,\n InvalidProviderConfigurationError,\n} from \"./exceptions\";\n\nimport type { ProviderConfiguration } from \"./types\";\n\n// Type imports for snowflake-sdk (these don't require the package at runtime)\ntype SnowflakeSDK = typeof import(\"snowflake-sdk\");\ntype SnowflakeConnection = import(\"snowflake-sdk\").Connection;\ntype SnowflakeBinds = import(\"snowflake-sdk\").Binds;\ntype SnowflakeError = import(\"snowflake-sdk\").SnowflakeError;\ntype SnowflakeConnectionOptions = import(\"snowflake-sdk\").ConnectionOptions;\ntype SnowflakeRowStatement = import(\"snowflake-sdk\").RowStatement;\ntype SnowflakeFileAndStageBindStatement =\n import(\"snowflake-sdk\").FileAndStageBindStatement;\n\n/**\n * Dynamically import snowflake-sdk\n * @throws {InvalidProviderConfigurationError} If snowflake-sdk is not installed\n */\nasync function getSnowflakeSDK(): Promise<SnowflakeSDK> {\n try {\n const snowflake = await import(\"snowflake-sdk\");\n return snowflake.default || snowflake;\n } catch {\n throw new InvalidProviderConfigurationError(\n \"The 'snowflake-sdk' package is required to use the Snowflake provider. \" +\n \"Please install it: npm install snowflake-sdk\",\n );\n }\n}\n\n/**\n * Snowflake data provider\n */\nexport class SnowflakeProvider {\n private connection: SnowflakeConnection;\n\n /**\n * Initialize the Snowflake data provider\n *\n * @param connection - Snowflake connection\n */\n constructor(connection: SnowflakeConnection) {\n this.connection = connection;\n }\n\n /**\n * Query the Snowflake database\n *\n * @param sqlText - SQL query to execute\n * @param params - Parameters to pass to the query. For positional binds, use an array.\n * For named binds, use an object with keys matching the bind variable names.\n * @returns Promise resolving to array of row objects\n */\n async query(\n sqlText: string,\n params: Record<string, unknown> | unknown[] = {},\n ): Promise<Array<Record<string, unknown>>> {\n // Snowflake SDK supports both positional binds (array) and named binds (object)\n // Pass params directly to preserve named bind semantics\n const binds = Array.isArray(params)\n ? (params as unknown as SnowflakeBinds)\n : (params as unknown as SnowflakeBinds);\n\n return new Promise((resolve, reject) => {\n this.connection.execute({\n sqlText,\n binds,\n complete: (\n err: SnowflakeError | undefined,\n _stmt: SnowflakeRowStatement | SnowflakeFileAndStageBindStatement,\n rows?: Array<Record<string, unknown>>,\n ) => {\n if (err) {\n reject(\n new QueryError(\n `Snowflake provider failed to query the database. Reason: ${err.message}`,\n ),\n );\n return;\n }\n resolve(rows ?? []);\n },\n });\n });\n }\n\n /**\n * Close the Snowflake connection\n */\n async close(): Promise<void> {\n return new Promise((resolve, reject) => {\n this.connection.destroy((err: SnowflakeError | undefined) => {\n if (err) {\n reject(err);\n return;\n }\n resolve();\n });\n });\n }\n}\n\n/**\n * Build a Snowflake data provider from the configuration\n *\n * @param config - Provider configuration\n * @returns Promise resolving to Snowflake data provider\n * @throws {InvalidProviderConfigurationError} If snowflake-sdk is not installed or config is invalid\n */\nexport async function buildSnowflakeProvider(\n config: ProviderConfiguration,\n): Promise<SnowflakeProvider> {\n // Dynamically import snowflake-sdk\n const snowflake = await getSnowflakeSDK();\n\n const requiredFields = [\n \"user\",\n \"password\",\n \"account\",\n \"warehouse\",\n \"database\",\n \"schema\",\n \"role\",\n ] as const;\n\n for (const field of requiredFields) {\n if (!config.fields[field]) {\n throw new InvalidProviderConfigurationError(\n `Missing field '${field}' in the provider '${config.name}' to connect to Snowflake ` +\n \"using password based authentication.\",\n );\n }\n }\n\n const connectionOptions: SnowflakeConnectionOptions = {\n account: config.fields[\"account\"]!,\n username: config.fields[\"user\"]!,\n password: config.fields[\"password\"]!,\n warehouse: config.fields[\"warehouse\"]!,\n database: config.fields[\"database\"]!,\n schema: config.fields[\"schema\"]!,\n role: config.fields[\"role\"]!,\n };\n\n return new Promise((resolve, reject) => {\n const connection = snowflake.createConnection(connectionOptions);\n\n connection.connect(\n (err: SnowflakeError | undefined, conn: SnowflakeConnection) => {\n if (err) {\n reject(\n new ProviderConnectionError(\n `Unable to connect to Snowflake. Reason: ${err.message}`,\n ),\n );\n return;\n }\n\n // Set timezone to UTC after connection.\n // The default timezone is America/Los_Angeles. Timestamps from delta tables will be\n // returned with the timezone `timezone`. NOTE, this is not a timezone conversion.\n // The timezone is replaced without translating the clock time. `timezone` is set UTC\n // to match the timezone of delta table timestamps.\n conn.execute({\n sqlText: \"ALTER SESSION SET TIMEZONE = 'UTC'\",\n complete: (tzErr: SnowflakeError | undefined) => {\n if (tzErr) {\n // Log warning but don't fail - timezone setting is not critical\n console.warn(\n `Warning: Failed to set timezone to UTC: ${tzErr.message}`,\n );\n }\n resolve(new SnowflakeProvider(conn));\n },\n });\n },\n );\n });\n}\n\n"],"names":["getSnowflakeSDK","snowflake","InvalidProviderConfigurationError","SnowflakeProvider","connection","sqlText","params","binds","resolve","reject","err","_stmt","rows","QueryError","buildSnowflakeProvider","config","requiredFields","field","connectionOptions","conn","ProviderConnectionError","tzErr"],"mappings":"ykBAsCA,eAAeA,GAAyC,CACtD,GAAI,CACF,MAAMC,EAAY,KAAM,QAAO,eAAe,EAC9C,OAAOA,EAAU,SAAWA,CAC9B,MAAQ,CACN,MAAM,IAAIC,EAAAA,kCACR,qHAAA,CAGJ,CACF,CAKO,MAAMC,CAAkB,CACrB,WAOR,YAAYC,EAAiC,CAC3C,KAAK,WAAaA,CACpB,CAUA,MAAM,MACJC,EACAC,EAA8C,GACL,CAGzC,MAAMC,GAAQ,MAAM,QAAQD,CAAM,EAC7BA,GAGL,OAAO,IAAI,QAAQ,CAACE,EAASC,IAAW,CACtC,KAAK,WAAW,QAAQ,CACtB,QAAAJ,EACA,MAAAE,EACA,SAAU,CACRG,EACAC,EACAC,IACG,CACH,GAAIF,EAAK,CACPD,EACE,IAAII,EAAAA,WACF,4DAA4DH,EAAI,OAAO,EAAA,CACzE,EAEF,MACF,CACAF,EAAQI,GAAQ,EAAE,CACpB,CAAA,CACD,CACH,CAAC,CACH,CAKA,MAAM,OAAuB,CAC3B,OAAO,IAAI,QAAQ,CAACJ,EAASC,IAAW,CACtC,KAAK,WAAW,QAASC,GAAoC,CAC3D,GAAIA,EAAK,CACPD,EAAOC,CAAG,EACV,MACF,CACAF,EAAA,CACF,CAAC,CACH,CAAC,CACH,CACF,CASA,eAAsBM,EACpBC,EAC4B,CAE5B,MAAMd,EAAY,MAAMD,EAAA,EAElBgB,EAAiB,CACrB,OACA,WACA,UACA,YACA,WACA,SACA,MAAA,EAGF,UAAWC,KAASD,EAClB,GAAI,CAACD,EAAO,OAAOE,CAAK,EACtB,MAAM,IAAIf,EAAAA,kCACR,kBAAkBe,CAAK,sBAAsBF,EAAO,IAAI,gEAAA,EAM9D,MAAMG,EAAgD,CACpD,QAASH,EAAO,OAAO,QACvB,SAAUA,EAAO,OAAO,KACxB,SAAUA,EAAO,OAAO,SACxB,UAAWA,EAAO,OAAO,UACzB,SAAUA,EAAO,OAAO,SACxB,OAAQA,EAAO,OAAO,OACtB,KAAMA,EAAO,OAAO,IAAM,EAG5B,OAAO,IAAI,QAAQ,CAACP,EAASC,IAAW,CACnBR,EAAU,iBAAiBiB,CAAiB,EAEpD,QACT,CAACR,EAAiCS,IAA8B,CAC9D,GAAIT,EAAK,CACPD,EACE,IAAIW,EAAAA,wBACF,2CAA2CV,EAAI,OAAO,EAAA,CACxD,EAEF,MACF,CAOAS,EAAK,QAAQ,CACX,QAAS,qCACT,SAAWE,GAAsC,CAC3CA,GAEF,QAAQ,KACN,2CAA2CA,EAAM,OAAO,EAAA,EAG5Db,EAAQ,IAAIL,EAAkBgB,CAAI,CAAC,CACrC,CAAA,CACD,CACH,CAAA,CAEJ,CAAC,CACH"}
@@ -1,40 +1,9 @@
1
- import * as snowflake_sdk from 'snowflake-sdk';
2
- import { P as ProviderConfiguration } from './types-Ck4uFaGp.js';
3
- export { I as InvalidProviderConfigurationError, M as MissingTableError, a as ProviderConnectionError, b as ProviderError, Q as QueryError, c as QueryResult } from './types-Ck4uFaGp.js';
1
+ export * from '../server/providers/entries/snowflake'
2
+ export {}
4
3
 
5
- type SnowflakeConnection = snowflake_sdk.Connection;
6
- /**
7
- * Snowflake data provider
8
- */
9
- declare class SnowflakeProvider {
10
- private connection;
11
- /**
12
- * Initialize the Snowflake data provider
13
- *
14
- * @param connection - Snowflake connection
15
- */
16
- constructor(connection: SnowflakeConnection);
17
- /**
18
- * Query the Snowflake database
19
- *
20
- * @param sqlText - SQL query to execute
21
- * @param params - Parameters to pass to the query. For positional binds, use an array.
22
- * For named binds, use an object with keys matching the bind variable names.
23
- * @returns Promise resolving to array of row objects
24
- */
25
- query(sqlText: string, params?: Record<string, unknown> | unknown[]): Promise<Array<Record<string, unknown>>>;
26
- /**
27
- * Close the Snowflake connection
28
- */
29
- close(): Promise<void>;
30
- }
31
- /**
32
- * Build a Snowflake data provider from the configuration
33
- *
34
- * @param config - Provider configuration
35
- * @returns Promise resolving to Snowflake data provider
36
- * @throws {InvalidProviderConfigurationError} If snowflake-sdk is not installed or config is invalid
37
- */
38
- declare function buildSnowflakeProvider(config: ProviderConfiguration): Promise<SnowflakeProvider>;
39
4
 
40
- export { ProviderConfiguration, SnowflakeProvider, buildSnowflakeProvider };
5
+ declare module "styled-components" {
6
+ interface DefaultTheme {
7
+ position: ToastPosition;
8
+ }
9
+ }