@polyglot-sql/sdk 0.5.0 → 0.5.1

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/index.d.ts CHANGED
@@ -593,6 +593,18 @@ declare type AnalyzeListChainedRows = {
593
593
  expression: Expression | null;
594
594
  };
595
595
 
596
+ /**
597
+ * Return compact query analysis facts for a SELECT or set operation.
598
+ */
599
+ export declare function analyzeQuery(sql: string, options?: AnalyzeQueryOptions): QueryAnalysisResult;
600
+
601
+ export declare interface AnalyzeQueryOptions {
602
+ /** Dialect used for parsing and dialect-aware rendering */
603
+ dialect?: Dialect | string;
604
+ /** Optional schema used for qualification and type annotation */
605
+ schema?: Schema;
606
+ }
607
+
596
608
  /**
597
609
  * AnalyzeSample
598
610
  */
@@ -1817,6 +1829,16 @@ declare type ColumnPrefix = {
1817
1829
  expression: Expression;
1818
1830
  };
1819
1831
 
1832
+ export declare interface ColumnReferenceFact {
1833
+ sourceName?: string;
1834
+ sourceAlias?: string;
1835
+ sourceKind: QueryAnalysisSourceKind;
1836
+ table?: string;
1837
+ column: string;
1838
+ unqualified: boolean;
1839
+ confidence: ReferenceConfidence;
1840
+ }
1841
+
1820
1842
  /**
1821
1843
  * Columns
1822
1844
  */
@@ -3021,7 +3043,7 @@ declare type DataDeletionProperty = {
3021
3043
  * Types that do not match any known variant fall through to `Custom { name }`,
3022
3044
  * preserving the original type name for round-trip fidelity.
3023
3045
  */
3024
- declare type DataType = {
3046
+ export declare type DataType = {
3025
3047
  "data_type": "boolean";
3026
3048
  } | {
3027
3049
  "data_type": "tiny_int";
@@ -3158,6 +3180,23 @@ declare type DataType = {
3158
3180
  "data_type": "unknown";
3159
3181
  };
3160
3182
 
3183
+ /**
3184
+ * Result of a standalone data type parse operation
3185
+ */
3186
+ export declare interface DataTypeResult {
3187
+ success: boolean;
3188
+ dataType?: DataType;
3189
+ error?: string;
3190
+ /** 1-based line number where the error occurred */
3191
+ errorLine?: number;
3192
+ /** 1-based column number where the error occurred */
3193
+ errorColumn?: number;
3194
+ /** Start byte offset of the error range */
3195
+ errorStart?: number;
3196
+ /** End byte offset of the error range (exclusive) */
3197
+ errorEnd?: number;
3198
+ }
3199
+
3161
3200
  /**
3162
3201
  * DATE_ADD / DATE_SUB function
3163
3202
  */
@@ -3366,10 +3405,13 @@ declare const _default: {
3366
3405
  isInitialized: typeof isInitialized;
3367
3406
  transpile: typeof transpile;
3368
3407
  parse: typeof parse;
3408
+ parseDataType: typeof parseDataType;
3369
3409
  tokenize: typeof tokenize;
3370
3410
  generate: typeof generate;
3411
+ generateDataType: typeof generateDataType;
3371
3412
  format: typeof format;
3372
3413
  annotateTypes: typeof annotateTypes;
3414
+ analyzeQuery: typeof analyzeQuery;
3373
3415
  getDialects: typeof getDialects;
3374
3416
  getVersion: typeof getVersion;
3375
3417
  lineage: typeof lineage;
@@ -6702,6 +6744,39 @@ declare type GeneratedAsRowColumnConstraint = {
6702
6744
  hidden: Expression | null;
6703
6745
  };
6704
6746
 
6747
+ /**
6748
+ * Generate SQL from a standalone DataType AST node.
6749
+ *
6750
+ * @param dataType - The DataType object to render
6751
+ * @param dialect - The target dialect
6752
+ * @returns The generated data type SQL
6753
+ *
6754
+ * @example
6755
+ * ```typescript
6756
+ * const parsed = parseDataType("VARCHAR(255)", Dialect.DuckDB);
6757
+ * const rendered = generateDataType(parsed.dataType!, Dialect.PostgreSQL);
6758
+ * // rendered.sql = "VARCHAR(255)"
6759
+ * ```
6760
+ */
6761
+ export declare function generateDataType(dataType: DataType, dialect?: Dialect): GenerateDataTypeResult;
6762
+
6763
+ /**
6764
+ * Result of a standalone data type generation operation
6765
+ */
6766
+ export declare interface GenerateDataTypeResult {
6767
+ success: boolean;
6768
+ sql?: string;
6769
+ error?: string;
6770
+ /** 1-based line number where the error occurred */
6771
+ errorLine?: number;
6772
+ /** 1-based column number where the error occurred */
6773
+ errorColumn?: number;
6774
+ /** Start byte offset of the error range */
6775
+ errorStart?: number;
6776
+ /** End byte offset of the error range (exclusive) */
6777
+ errorEnd?: number;
6778
+ }
6779
+
6705
6780
  /**
6706
6781
  * GenerateDateArray
6707
6782
  */
@@ -10227,6 +10302,21 @@ declare type Paren = {
10227
10302
  */
10228
10303
  export declare function parse(sql: string, dialect?: Dialect): ParseResult;
10229
10304
 
10305
+ /**
10306
+ * Parse a standalone SQL data type.
10307
+ *
10308
+ * @param sql - The data type string to parse
10309
+ * @param dialect - The dialect to use
10310
+ * @returns The parsed DataType AST node
10311
+ *
10312
+ * @example
10313
+ * ```typescript
10314
+ * const result = parseDataType("DECIMAL(10, 2)", Dialect.DuckDB);
10315
+ * console.log(result.dataType);
10316
+ * ```
10317
+ */
10318
+ export declare function parseDataType(sql: string, dialect?: Dialect): DataTypeResult;
10319
+
10230
10320
  /**
10231
10321
  * ParseDatetime
10232
10322
  */
@@ -10595,6 +10685,10 @@ export declare class Polyglot {
10595
10685
  * Parse SQL into an AST.
10596
10686
  */
10597
10687
  parse(sql: string, dialect?: Dialect): ParseResult;
10688
+ /**
10689
+ * Parse a standalone SQL data type.
10690
+ */
10691
+ parseDataType(sql: string, dialect?: Dialect): DataTypeResult;
10598
10692
  /**
10599
10693
  * Tokenize SQL into a token stream.
10600
10694
  */
@@ -10603,6 +10697,10 @@ export declare class Polyglot {
10603
10697
  * Generate SQL from an AST.
10604
10698
  */
10605
10699
  generate(ast: any, dialect?: Dialect): TranspileResult;
10700
+ /**
10701
+ * Generate SQL from a standalone DataType AST node.
10702
+ */
10703
+ generateDataType(dataType: DataType, dialect?: Dialect): GenerateDataTypeResult;
10606
10704
  /**
10607
10705
  * Format SQL.
10608
10706
  */
@@ -10624,6 +10722,10 @@ export declare class Polyglot {
10624
10722
  * Parse SQL and annotate the AST with inferred type information.
10625
10723
  */
10626
10724
  annotateTypes(sql: string, dialect?: Dialect, schema?: Schema): AnnotateTypesResult;
10725
+ /**
10726
+ * Return compact query analysis facts for a SELECT or set operation.
10727
+ */
10728
+ analyzeQuery(sql: string, options?: AnalyzeQueryOptions): QueryAnalysisResult;
10627
10729
  }
10628
10730
 
10629
10731
  /**
@@ -10759,6 +10861,17 @@ declare type ProjectionDef = {
10759
10861
  expression: Expression;
10760
10862
  };
10761
10863
 
10864
+ export declare interface ProjectionFact {
10865
+ index: number;
10866
+ name?: string;
10867
+ isStar: boolean;
10868
+ starTable?: string;
10869
+ transformKind: TransformKind;
10870
+ castType?: string;
10871
+ typeHint?: string;
10872
+ upstream: ColumnReferenceFact[];
10873
+ }
10874
+
10762
10875
  /**
10763
10876
  * Properties
10764
10877
  */
@@ -10887,6 +11000,22 @@ declare type Quantile = {
10887
11000
  quantile: Expression | null;
10888
11001
  };
10889
11002
 
11003
+ export declare interface QueryAnalysis {
11004
+ shape: QueryShape;
11005
+ ctes: string[];
11006
+ projections: ProjectionFact[];
11007
+ relations: RelationFact[];
11008
+ setOperations: SetOperationFact[];
11009
+ }
11010
+
11011
+ export declare interface QueryAnalysisResult {
11012
+ success: boolean;
11013
+ analysis?: QueryAnalysis;
11014
+ error?: string;
11015
+ }
11016
+
11017
+ export declare type QueryAnalysisSourceKind = 'root' | 'table' | 'derived_table' | 'cte' | 'virtual' | 'unknown';
11018
+
10890
11019
  /**
10891
11020
  * QueryBand
10892
11021
  */
@@ -10916,6 +11045,8 @@ export declare interface QueryPlan {
10916
11045
  leaves: PlanStep[];
10917
11046
  }
10918
11047
 
11048
+ export declare type QueryShape = 'select' | 'set_operation';
11049
+
10919
11050
  /**
10920
11051
  * QueryTransform
10921
11052
  */
@@ -11048,6 +11179,8 @@ declare type Reference = {
11048
11179
  options: Array<Expression>;
11049
11180
  };
11050
11181
 
11182
+ export declare type ReferenceConfidence = 'resolved' | 'ambiguous' | 'unknown';
11183
+
11051
11184
  /**
11052
11185
  * Union of all reference expression types (identifiers, columns, tables)
11053
11186
  */
@@ -11271,6 +11404,13 @@ declare type RegrValy = {
11271
11404
  expression: Expression;
11272
11405
  };
11273
11406
 
11407
+ export declare interface RelationFact {
11408
+ name: string;
11409
+ alias?: string;
11410
+ kind: QueryAnalysisSourceKind;
11411
+ columns: string[];
11412
+ }
11413
+
11274
11414
  /**
11275
11415
  * RemoteWithConnectionModelProperty
11276
11416
  */
@@ -12141,11 +12281,24 @@ declare type SetOperation = {
12141
12281
  on: Expression | null;
12142
12282
  };
12143
12283
 
12284
+ export declare interface SetOperationBranchFact {
12285
+ index: number;
12286
+ projections: ProjectionFact[];
12287
+ }
12288
+
12144
12289
  /**
12145
12290
  * Union of all set operation expression types
12146
12291
  */
12147
12292
  declare type SetOperationExpression = ExpressionByType<'union'> | ExpressionByType<'intersect'> | ExpressionByType<'except'>;
12148
12293
 
12294
+ export declare interface SetOperationFact {
12295
+ kind: 'union' | 'intersect' | 'except' | string;
12296
+ all: boolean;
12297
+ distinct: boolean;
12298
+ outputColumns: string[];
12299
+ branches: SetOperationBranchFact[];
12300
+ }
12301
+
12149
12302
  export declare type SetOperationType = 'union' | 'union_all' | 'intersect' | 'except';
12150
12303
 
12151
12304
  /**
@@ -13561,6 +13714,8 @@ declare type TransformFunc = {
13561
13714
  transform: Expression;
13562
13715
  };
13563
13716
 
13717
+ export declare type TransformKind = 'direct' | 'cast' | 'aggregation' | 'constant' | 'expression' | 'star';
13718
+
13564
13719
  /**
13565
13720
  * TransformModelProperty
13566
13721
  */
package/dist/index.js CHANGED
@@ -1592,6 +1592,46 @@ class WasmWindowDefBuilder {
1592
1592
  }
1593
1593
  if (Symbol.dispose) WasmWindowDefBuilder.prototype[Symbol.dispose] = WasmWindowDefBuilder.prototype.free;
1594
1594
 
1595
+ /**
1596
+ * Return compact query analysis facts for a SELECT or set operation.
1597
+ * @param {string} sql
1598
+ * @param {string} options_json
1599
+ * @returns {string}
1600
+ */
1601
+ function analyze_query$1(sql, options_json) {
1602
+ let deferred3_0;
1603
+ let deferred3_1;
1604
+ try {
1605
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
1606
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1607
+ const len0 = WASM_VECTOR_LEN;
1608
+ const ptr1 = passStringToWasm0(options_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1609
+ const len1 = WASM_VECTOR_LEN;
1610
+ wasm$3.analyze_query(retptr, ptr0, len0, ptr1, len1);
1611
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1612
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1613
+ deferred3_0 = r0;
1614
+ deferred3_1 = r1;
1615
+ return getStringFromWasm0(r0, r1);
1616
+ } finally {
1617
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
1618
+ wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
1619
+ }
1620
+ }
1621
+
1622
+ /**
1623
+ * Return compact query analysis facts as a structured JS value.
1624
+ * @param {string} sql
1625
+ * @param {any} options
1626
+ * @returns {any}
1627
+ */
1628
+ function analyze_query_value$1(sql, options) {
1629
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1630
+ const len0 = WASM_VECTOR_LEN;
1631
+ const ret = wasm$3.analyze_query_value(ptr0, len0, addHeapObject(options));
1632
+ return takeObject(ret);
1633
+ }
1634
+
1595
1635
  /**
1596
1636
  * Annotate types on a parsed SQL AST in-place.
1597
1637
  *
@@ -2257,6 +2297,46 @@ function generate$2(ast_json, dialect) {
2257
2297
  }
2258
2298
  }
2259
2299
 
2300
+ /**
2301
+ * Generate SQL from a standalone DataType JSON object.
2302
+ * @param {string} data_type_json
2303
+ * @param {string} dialect
2304
+ * @returns {string}
2305
+ */
2306
+ function generate_data_type$1(data_type_json, dialect) {
2307
+ let deferred3_0;
2308
+ let deferred3_1;
2309
+ try {
2310
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
2311
+ const ptr0 = passStringToWasm0(data_type_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2312
+ const len0 = WASM_VECTOR_LEN;
2313
+ const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2314
+ const len1 = WASM_VECTOR_LEN;
2315
+ wasm$3.generate_data_type(retptr, ptr0, len0, ptr1, len1);
2316
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2317
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2318
+ deferred3_0 = r0;
2319
+ deferred3_1 = r1;
2320
+ return getStringFromWasm0(r0, r1);
2321
+ } finally {
2322
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
2323
+ wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
2324
+ }
2325
+ }
2326
+
2327
+ /**
2328
+ * Generate SQL from a standalone DataType represented as a structured JS value.
2329
+ * @param {any} data_type
2330
+ * @param {string} dialect
2331
+ * @returns {any}
2332
+ */
2333
+ function generate_data_type_value$1(data_type, dialect) {
2334
+ const ptr0 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2335
+ const len0 = WASM_VECTOR_LEN;
2336
+ const ret = wasm$3.generate_data_type_value(addHeapObject(data_type), ptr0, len0);
2337
+ return takeObject(ret);
2338
+ }
2339
+
2260
2340
  /**
2261
2341
  * Generate SQL from an AST represented as a structured JS value.
2262
2342
  * @param {any} ast
@@ -2502,6 +2582,48 @@ function parse$2(sql, dialect) {
2502
2582
  }
2503
2583
  }
2504
2584
 
2585
+ /**
2586
+ * Parse a standalone SQL data type and return a JSON string payload.
2587
+ * @param {string} sql
2588
+ * @param {string} dialect
2589
+ * @returns {string}
2590
+ */
2591
+ function parse_data_type$1(sql, dialect) {
2592
+ let deferred3_0;
2593
+ let deferred3_1;
2594
+ try {
2595
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
2596
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2597
+ const len0 = WASM_VECTOR_LEN;
2598
+ const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2599
+ const len1 = WASM_VECTOR_LEN;
2600
+ wasm$3.parse_data_type(retptr, ptr0, len0, ptr1, len1);
2601
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2602
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2603
+ deferred3_0 = r0;
2604
+ deferred3_1 = r1;
2605
+ return getStringFromWasm0(r0, r1);
2606
+ } finally {
2607
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
2608
+ wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
2609
+ }
2610
+ }
2611
+
2612
+ /**
2613
+ * Parse a standalone SQL data type and return a structured JS value payload.
2614
+ * @param {string} sql
2615
+ * @param {string} dialect
2616
+ * @returns {any}
2617
+ */
2618
+ function parse_data_type_value$1(sql, dialect) {
2619
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2620
+ const len0 = WASM_VECTOR_LEN;
2621
+ const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2622
+ const len1 = WASM_VECTOR_LEN;
2623
+ const ret = wasm$3.parse_data_type_value(ptr0, len0, ptr1, len1);
2624
+ return takeObject(ret);
2625
+ }
2626
+
2505
2627
  /**
2506
2628
  * Parse SQL and return a structured JS object with AST values.
2507
2629
  * @param {string} sql
@@ -3678,6 +3800,8 @@ const __wbg_wasmselectbuilder_free = __vite__wasmModule.__wbg_wasmselectbuilder_
3678
3800
  const __wbg_wasmsetopbuilder_free = __vite__wasmModule.__wbg_wasmsetopbuilder_free;
3679
3801
  const __wbg_wasmupdatebuilder_free = __vite__wasmModule.__wbg_wasmupdatebuilder_free;
3680
3802
  const __wbg_wasmwindowdefbuilder_free = __vite__wasmModule.__wbg_wasmwindowdefbuilder_free;
3803
+ const analyze_query = __vite__wasmModule.analyze_query;
3804
+ const analyze_query_value = __vite__wasmModule.analyze_query_value;
3681
3805
  const annotate_types = __vite__wasmModule.annotate_types;
3682
3806
  const annotate_types_value = __vite__wasmModule.annotate_types_value;
3683
3807
  const ast_add_where = __vite__wasmModule.ast_add_where;
@@ -3703,6 +3827,8 @@ const format_sql_value = __vite__wasmModule.format_sql_value;
3703
3827
  const format_sql_with_options = __vite__wasmModule.format_sql_with_options;
3704
3828
  const format_sql_with_options_value = __vite__wasmModule.format_sql_with_options_value;
3705
3829
  const generate$1 = __vite__wasmModule.generate;
3830
+ const generate_data_type = __vite__wasmModule.generate_data_type;
3831
+ const generate_data_type_value = __vite__wasmModule.generate_data_type_value;
3706
3832
  const generate_value = __vite__wasmModule.generate_value;
3707
3833
  const get_dialects = __vite__wasmModule.get_dialects;
3708
3834
  const get_dialects_value = __vite__wasmModule.get_dialects_value;
@@ -3712,6 +3838,8 @@ const openlineage_column_lineage = __vite__wasmModule.openlineage_column_lineage
3712
3838
  const openlineage_job_event = __vite__wasmModule.openlineage_job_event;
3713
3839
  const openlineage_run_event = __vite__wasmModule.openlineage_run_event;
3714
3840
  const parse$1 = __vite__wasmModule.parse;
3841
+ const parse_data_type = __vite__wasmModule.parse_data_type;
3842
+ const parse_data_type_value = __vite__wasmModule.parse_data_type_value;
3715
3843
  const parse_value = __vite__wasmModule.parse_value;
3716
3844
  const plan$1 = __vite__wasmModule.plan;
3717
3845
  const source_tables = __vite__wasmModule.source_tables;
@@ -3874,6 +4002,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3874
4002
  __wbindgen_export2,
3875
4003
  __wbindgen_export3,
3876
4004
  __wbindgen_export4,
4005
+ analyze_query,
4006
+ analyze_query_value,
3877
4007
  annotate_types,
3878
4008
  annotate_types_value,
3879
4009
  ast_add_where,
@@ -3899,6 +4029,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3899
4029
  format_sql_with_options,
3900
4030
  format_sql_with_options_value,
3901
4031
  generate: generate$1,
4032
+ generate_data_type,
4033
+ generate_data_type_value,
3902
4034
  generate_value,
3903
4035
  get_dialects,
3904
4036
  get_dialects_value,
@@ -3909,6 +4041,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3909
4041
  openlineage_job_event,
3910
4042
  openlineage_run_event,
3911
4043
  parse: parse$1,
4044
+ parse_data_type,
4045
+ parse_data_type_value,
3912
4046
  parse_value,
3913
4047
  plan: plan$1,
3914
4048
  source_tables,
@@ -4066,6 +4200,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
4066
4200
  WasmSetOpBuilder,
4067
4201
  WasmUpdateBuilder,
4068
4202
  WasmWindowDefBuilder,
4203
+ analyze_query: analyze_query$1,
4204
+ analyze_query_value: analyze_query_value$1,
4069
4205
  annotate_types: annotate_types$1,
4070
4206
  annotate_types_value: annotate_types_value$1,
4071
4207
  ast_add_where: ast_add_where$1,
@@ -4091,6 +4227,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
4091
4227
  format_sql_with_options: format_sql_with_options$1,
4092
4228
  format_sql_with_options_value: format_sql_with_options_value$1,
4093
4229
  generate: generate$2,
4230
+ generate_data_type: generate_data_type$1,
4231
+ generate_data_type_value: generate_data_type_value$1,
4094
4232
  generate_value: generate_value$1,
4095
4233
  get_dialects: get_dialects$1,
4096
4234
  get_dialects_value: get_dialects_value$1,
@@ -4100,6 +4238,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
4100
4238
  openlineage_job_event: openlineage_job_event$1,
4101
4239
  openlineage_run_event: openlineage_run_event$1,
4102
4240
  parse: parse$2,
4241
+ parse_data_type: parse_data_type$1,
4242
+ parse_data_type_value: parse_data_type_value$1,
4103
4243
  parse_value: parse_value$1,
4104
4244
  plan: plan$2,
4105
4245
  source_tables: source_tables$1,
@@ -5866,12 +6006,37 @@ function parseFailure(context, error) {
5866
6006
  errorColumn: void 0
5867
6007
  };
5868
6008
  }
6009
+ function dataTypeFailure(context, error) {
6010
+ return {
6011
+ success: false,
6012
+ dataType: void 0,
6013
+ error: `WASM ${context} failed: ${errorMessage(error)}`,
6014
+ errorLine: void 0,
6015
+ errorColumn: void 0
6016
+ };
6017
+ }
6018
+ function generateDataTypeFailure(context, error) {
6019
+ return {
6020
+ success: false,
6021
+ sql: void 0,
6022
+ error: `WASM ${context} failed: ${errorMessage(error)}`,
6023
+ errorLine: void 0,
6024
+ errorColumn: void 0
6025
+ };
6026
+ }
5869
6027
  function decodeWasmPayload(payload) {
5870
6028
  if (typeof payload === "string") {
5871
6029
  return JSON.parse(payload);
5872
6030
  }
5873
6031
  return payload;
5874
6032
  }
6033
+ function queryAnalysisFailure(context, error) {
6034
+ return {
6035
+ success: false,
6036
+ analysis: void 0,
6037
+ error: `WASM ${context} failed: ${errorMessage(error)}`
6038
+ };
6039
+ }
5875
6040
  async function init() {
5876
6041
  return Promise.resolve();
5877
6042
  }
@@ -5921,6 +6086,24 @@ function parse(sql, dialect = "generic" /* Generic */) {
5921
6086
  return parseFailure("parse", error);
5922
6087
  }
5923
6088
  }
6089
+ function parseDataType(sql, dialect = "generic" /* Generic */) {
6090
+ try {
6091
+ if (typeof wasm.parse_data_type_value === "function") {
6092
+ return decodeWasmPayload(
6093
+ wasm.parse_data_type_value(sql, dialect)
6094
+ );
6095
+ }
6096
+ const result = JSON.parse(
6097
+ wasm.parse_data_type(sql, dialect)
6098
+ );
6099
+ if (result.success && typeof result.dataType === "string") {
6100
+ result.dataType = JSON.parse(result.dataType);
6101
+ }
6102
+ return result;
6103
+ } catch (error) {
6104
+ return dataTypeFailure("parseDataType", error);
6105
+ }
6106
+ }
5924
6107
  function tokenize(sql, dialect = "generic" /* Generic */) {
5925
6108
  try {
5926
6109
  if (typeof wasm.tokenize_value === "function") {
@@ -5950,6 +6133,21 @@ function generate(ast2, dialect = "generic" /* Generic */) {
5950
6133
  return transpileFailure("generate", error);
5951
6134
  }
5952
6135
  }
6136
+ function generateDataType(dataType, dialect = "generic" /* Generic */) {
6137
+ try {
6138
+ if (typeof wasm.generate_data_type_value === "function") {
6139
+ return decodeWasmPayload(
6140
+ wasm.generate_data_type_value(dataType, dialect)
6141
+ );
6142
+ }
6143
+ const dataTypeJson = JSON.stringify(dataType);
6144
+ return JSON.parse(
6145
+ wasm.generate_data_type(dataTypeJson, dialect)
6146
+ );
6147
+ } catch (error) {
6148
+ return generateDataTypeFailure("generateDataType", error);
6149
+ }
6150
+ }
5953
6151
  function format(sql, dialect = "generic" /* Generic */) {
5954
6152
  return formatWithOptions(sql, dialect, {});
5955
6153
  }
@@ -5984,6 +6182,30 @@ function getDialects() {
5984
6182
  function getVersion() {
5985
6183
  return wasm.version();
5986
6184
  }
6185
+ function analyzeQuery(sql, options = {}) {
6186
+ try {
6187
+ const normalized = {
6188
+ dialect: "generic" /* Generic */,
6189
+ ...options
6190
+ };
6191
+ if (typeof wasm.analyze_query_value === "function") {
6192
+ return decodeWasmPayload(
6193
+ wasm.analyze_query_value(sql, normalized)
6194
+ );
6195
+ }
6196
+ if (typeof wasm.analyze_query === "function") {
6197
+ return JSON.parse(
6198
+ wasm.analyze_query(sql, JSON.stringify(normalized))
6199
+ );
6200
+ }
6201
+ return {
6202
+ success: false,
6203
+ error: "analyze_query not available in this WASM build"
6204
+ };
6205
+ } catch (error) {
6206
+ return queryAnalysisFailure("analyzeQuery", error);
6207
+ }
6208
+ }
5987
6209
  function annotateTypes(sql, dialect = "generic" /* Generic */, schema) {
5988
6210
  try {
5989
6211
  const schemaJson = schema ? JSON.stringify(schema) : "";
@@ -6038,6 +6260,12 @@ class Polyglot {
6038
6260
  parse(sql, dialect = "generic" /* Generic */) {
6039
6261
  return parse(sql, dialect);
6040
6262
  }
6263
+ /**
6264
+ * Parse a standalone SQL data type.
6265
+ */
6266
+ parseDataType(sql, dialect = "generic" /* Generic */) {
6267
+ return parseDataType(sql, dialect);
6268
+ }
6041
6269
  /**
6042
6270
  * Tokenize SQL into a token stream.
6043
6271
  */
@@ -6050,6 +6278,12 @@ class Polyglot {
6050
6278
  generate(ast2, dialect = "generic" /* Generic */) {
6051
6279
  return generate(ast2, dialect);
6052
6280
  }
6281
+ /**
6282
+ * Generate SQL from a standalone DataType AST node.
6283
+ */
6284
+ generateDataType(dataType, dialect = "generic" /* Generic */) {
6285
+ return generateDataType(dataType, dialect);
6286
+ }
6053
6287
  /**
6054
6288
  * Format SQL.
6055
6289
  */
@@ -6081,16 +6315,25 @@ class Polyglot {
6081
6315
  annotateTypes(sql, dialect = "generic" /* Generic */, schema) {
6082
6316
  return annotateTypes(sql, dialect, schema);
6083
6317
  }
6318
+ /**
6319
+ * Return compact query analysis facts for a SELECT or set operation.
6320
+ */
6321
+ analyzeQuery(sql, options = {}) {
6322
+ return analyzeQuery(sql, options);
6323
+ }
6084
6324
  }
6085
6325
  const index = {
6086
6326
  init,
6087
6327
  isInitialized,
6088
6328
  transpile,
6089
6329
  parse,
6330
+ parseDataType,
6090
6331
  tokenize,
6091
6332
  generate,
6333
+ generateDataType,
6092
6334
  format,
6093
6335
  annotateTypes,
6336
+ analyzeQuery,
6094
6337
  getDialects,
6095
6338
  getVersion,
6096
6339
  lineage: lineage,
@@ -6107,4 +6350,4 @@ const index = {
6107
6350
  Polyglot
6108
6351
  };
6109
6352
 
6110
- export { CaseBuilder, DeleteBuilder, Dialect, Expr, InsertBuilder, MergeBuilder, Polyglot, SelectBuilder, SetOpBuilder, UpdateBuilder, ValidationSeverity, WindowDefBuilder, abs, alias, and, annotateTypes, index$1 as ast, avg, boolean, caseOf, caseWhen, cast, ceil, changesOnly, coalesce, col, concatWs, condition, count, countDistinct, currentDate, currentTime, currentTimestamp, index as default, del, deleteFrom, denseRank, diff, except, exp, extract, findAll, floor, format, formatWithOptions, func, generate, getColumns, getDialects, getInferredType, getSourceTables, getVersion, greatest, hasChanges, ifNull, init, initcap, insert, insertInto, intersect, isColumn, isFunction, isInitialized, isLiteral, isSelect, least, length, lineage, lineageWithSchema, lit, ln, lower, ltrim, max, mergeInto, min, not, nullIf, openLineageColumnLineage, openLineageJobEvent, openLineageRunEvent, or, parse, plan, power, rank, renameColumns, replace, reverse, round, rowNumber, rtrim, select, sign, sqlExpr, sqlNull, sqrt, star, subquery, substring, sum, table, tokenize, transform, transpile, trim, union, unionAll, update, upper, validate, validateWithSchema, walk };
6353
+ export { CaseBuilder, DeleteBuilder, Dialect, Expr, InsertBuilder, MergeBuilder, Polyglot, SelectBuilder, SetOpBuilder, UpdateBuilder, ValidationSeverity, WindowDefBuilder, abs, alias, analyzeQuery, and, annotateTypes, index$1 as ast, avg, boolean, caseOf, caseWhen, cast, ceil, changesOnly, coalesce, col, concatWs, condition, count, countDistinct, currentDate, currentTime, currentTimestamp, index as default, del, deleteFrom, denseRank, diff, except, exp, extract, findAll, floor, format, formatWithOptions, func, generate, generateDataType, getColumns, getDialects, getInferredType, getSourceTables, getVersion, greatest, hasChanges, ifNull, init, initcap, insert, insertInto, intersect, isColumn, isFunction, isInitialized, isLiteral, isSelect, least, length, lineage, lineageWithSchema, lit, ln, lower, ltrim, max, mergeInto, min, not, nullIf, openLineageColumnLineage, openLineageJobEvent, openLineageRunEvent, or, parse, parseDataType, plan, power, rank, renameColumns, replace, reverse, round, rowNumber, rtrim, select, sign, sqlExpr, sqlNull, sqrt, star, subquery, substring, sum, table, tokenize, transform, transpile, trim, union, unionAll, update, upper, validate, validateWithSchema, walk };