@polyglot-sql/sdk 0.1.10 → 0.1.12

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
@@ -49,6 +49,10 @@ declare type AggFunc = {
49
49
  * LIMIT inside aggregate (e.g., ARRAY_AGG(x ORDER BY y LIMIT 2))
50
50
  */
51
51
  limit?: Expression | null;
52
+ /**
53
+ * Inferred data type from type annotation
54
+ */
55
+ inferred_type?: DataType | null;
52
56
  };
53
57
 
54
58
  /**
@@ -93,6 +97,10 @@ declare type AggregateFunction = {
93
97
  * IGNORE NULLS / RESPECT NULLS
94
98
  */
95
99
  ignore_nulls?: boolean | null;
100
+ /**
101
+ * Inferred data type from type annotation
102
+ */
103
+ inferred_type?: DataType | null;
96
104
  };
97
105
 
98
106
  /**
@@ -146,6 +154,10 @@ declare type Alias = {
146
154
  * Trailing comments that appeared after the alias
147
155
  */
148
156
  trailing_comments: Array<string>;
157
+ /**
158
+ * Inferred data type from type annotation
159
+ */
160
+ inferred_type?: DataType | null;
149
161
  };
150
162
 
151
163
  /** Create an expr AS name alias expression. */
@@ -614,6 +626,51 @@ declare type Annotated = {
614
626
  trailing_comments: Array<string>;
615
627
  };
616
628
 
629
+ /**
630
+ * Parse SQL and annotate the AST with inferred type information.
631
+ *
632
+ * Parses the given SQL and runs bottom-up type inference, populating the
633
+ * `inferred_type` field on value-producing AST nodes (columns, operators,
634
+ * functions, casts, etc.). Use `ast.getInferredType(expr)` to read the
635
+ * inferred type from any expression node.
636
+ *
637
+ * @param sql - The SQL string to parse and annotate
638
+ * @param dialect - The dialect to use for parsing (default: Generic)
639
+ * @param schema - Optional schema for column type resolution
640
+ *
641
+ * @example
642
+ * ```typescript
643
+ * import { annotateTypes, ast, Dialect } from '@polyglot-sql/sdk';
644
+ *
645
+ * const result = annotateTypes(
646
+ * "SELECT a + b FROM t",
647
+ * Dialect.PostgreSQL,
648
+ * { tables: { t: { a: "INT", b: "DOUBLE" } } }
649
+ * );
650
+ *
651
+ * if (result.success) {
652
+ * // Walk the AST and inspect inferred types
653
+ * ast.walk(result.ast![0], (node) => {
654
+ * const dt = ast.getInferredType(node);
655
+ * if (dt) {
656
+ * console.log(ast.getExprType(node), "=>", dt);
657
+ * }
658
+ * });
659
+ * }
660
+ * ```
661
+ */
662
+ export declare function annotateTypes(sql: string, dialect?: Dialect, schema?: Schema): AnnotateTypesResult;
663
+
664
+ /**
665
+ * Result of an annotateTypes operation
666
+ */
667
+ export declare interface AnnotateTypesResult {
668
+ success: boolean;
669
+ /** The AST with `inferred_type` fields populated on value-producing nodes */
670
+ ast?: Expression[];
671
+ error?: string;
672
+ }
673
+
617
674
  /**
618
675
  * Anonymous
619
676
  */
@@ -834,6 +891,7 @@ export declare namespace ast {
834
891
  ExpressionType,
835
892
  getExprData,
836
893
  getExprType,
894
+ getInferredType,
837
895
  isExpressionValue,
838
896
  makeExpr,
839
897
  Alias,
@@ -1139,6 +1197,10 @@ declare type BinaryFunc = {
1139
1197
  * Original function name for round-trip preservation (e.g., NVL vs IFNULL)
1140
1198
  */
1141
1199
  original_name?: string | null;
1200
+ /**
1201
+ * Inferred data type from type annotation
1202
+ */
1203
+ inferred_type?: DataType | null;
1142
1204
  };
1143
1205
 
1144
1206
  /**
@@ -1165,6 +1227,10 @@ declare type BinaryOp = {
1165
1227
  * Comments after the right operand
1166
1228
  */
1167
1229
  trailing_comments: Array<string>;
1230
+ /**
1231
+ * Inferred data type from type annotation
1232
+ */
1233
+ inferred_type?: DataType | null;
1168
1234
  };
1169
1235
 
1170
1236
  /**
@@ -1270,6 +1336,10 @@ declare type Case = {
1270
1336
  * Comments from the CASE keyword (emitted after END)
1271
1337
  */
1272
1338
  comments?: Array<string>;
1339
+ /**
1340
+ * Inferred data type from type annotation
1341
+ */
1342
+ inferred_type?: DataType | null;
1273
1343
  };
1274
1344
 
1275
1345
  /**
@@ -1339,6 +1409,10 @@ declare type Cast = {
1339
1409
  * DEFAULT value ON CONVERSION ERROR (Oracle): CAST(x AS type DEFAULT val ON CONVERSION ERROR)
1340
1410
  */
1341
1411
  default?: Expression | null;
1412
+ /**
1413
+ * Inferred data type from type annotation
1414
+ */
1415
+ inferred_type?: DataType | null;
1342
1416
  };
1343
1417
 
1344
1418
  /** Create a CAST(expr AS type) expression. */
@@ -1465,6 +1539,13 @@ declare type ClusterBy = {
1465
1539
  expressions: Array<Ordered>;
1466
1540
  };
1467
1541
 
1542
+ /**
1543
+ * BigQuery CLUSTER BY property in CREATE TABLE statements.
1544
+ */
1545
+ declare type ClusterByColumnsProperty = {
1546
+ columns: Array<Identifier>;
1547
+ };
1548
+
1468
1549
  /**
1469
1550
  * ClusteredByProperty
1470
1551
  */
@@ -1528,6 +1609,10 @@ declare type Column = {
1528
1609
  * Source position span
1529
1610
  */
1530
1611
  span?: Span | null;
1612
+ /**
1613
+ * Inferred data type from type annotation
1614
+ */
1615
+ inferred_type?: DataType | null;
1531
1616
  };
1532
1617
 
1533
1618
  /**
@@ -3138,9 +3223,11 @@ declare const _default: {
3138
3223
  tokenize: typeof tokenize;
3139
3224
  generate: typeof generate;
3140
3225
  format: typeof format;
3226
+ annotateTypes: typeof annotateTypes;
3141
3227
  getDialects: typeof getDialects;
3142
3228
  getVersion: typeof getVersion;
3143
3229
  lineage: typeof lineage;
3230
+ lineageWithSchema: typeof lineageWithSchema;
3144
3231
  getSourceTables: typeof getSourceTables;
3145
3232
  diff: typeof diff;
3146
3233
  hasChanges: typeof hasChanges;
@@ -3326,12 +3413,6 @@ declare type Detach = {
3326
3413
  exists: boolean;
3327
3414
  };
3328
3415
 
3329
- /**
3330
- * Polyglot SQL Dialect Translator
3331
- *
3332
- * A WebAssembly-powered SQL dialect translator that can convert SQL
3333
- * between different database dialects (PostgreSQL, MySQL, BigQuery, etc.)
3334
- */
3335
3416
  /**
3336
3417
  * Supported SQL dialects
3337
3418
  */
@@ -5092,8 +5173,12 @@ declare type Expression = {
5092
5173
  "on_commit_property": OnCommitProperty;
5093
5174
  } | {
5094
5175
  "partitioned_by_property": PartitionedByProperty;
5176
+ } | {
5177
+ "partition_by_property": PartitionByProperty;
5095
5178
  } | {
5096
5179
  "partitioned_by_bucket": PartitionedByBucket;
5180
+ } | {
5181
+ "cluster_by_columns_property": ClusterByColumnsProperty;
5097
5182
  } | {
5098
5183
  "partition_by_truncate": PartitionByTruncate;
5099
5184
  } | {
@@ -5186,6 +5271,8 @@ declare type Expression = {
5186
5271
  "include_property": IncludeProperty;
5187
5272
  } | {
5188
5273
  "properties": Properties;
5274
+ } | {
5275
+ "options_property": OptionsProperty;
5189
5276
  } | {
5190
5277
  "input_output_format": InputOutputFormat;
5191
5278
  } | {
@@ -6209,6 +6296,10 @@ declare type Function_2 = {
6209
6296
  * Source position span
6210
6297
  */
6211
6298
  span?: Span | null;
6299
+ /**
6300
+ * Inferred data type from type annotation
6301
+ */
6302
+ inferred_type?: DataType | null;
6212
6303
  };
6213
6304
 
6214
6305
  /**
@@ -6531,6 +6622,27 @@ declare function getFunctions(node: Expression): Expression[];
6531
6622
  */
6532
6623
  declare function getIdentifiers(node: Expression): Expression[];
6533
6624
 
6625
+ /**
6626
+ * Get the inferred data type from an Expression, if it has been type-annotated.
6627
+ *
6628
+ * After calling `annotateTypes()`, value-producing expressions (columns, operators,
6629
+ * functions, casts, etc.) carry an `inferred_type` field with their resolved SQL type.
6630
+ *
6631
+ * @example
6632
+ * ```typescript
6633
+ * const result = annotateTypes("SELECT 1 + 2", Dialect.Generic);
6634
+ * if (result.success) {
6635
+ * const addExpr = result.ast![0]; // the SELECT
6636
+ * // Navigate to the "1 + 2" expression and check its type:
6637
+ * const dt = getInferredType(someExpr);
6638
+ * // dt => { data_type: "int", length: null, integer_spelling: false }
6639
+ * }
6640
+ * ```
6641
+ *
6642
+ * @returns The inferred DataType, or `undefined` if not annotated or not a value-producing expression.
6643
+ */
6644
+ export declare function getInferredType(expr: Expression): DataType | undefined;
6645
+
6534
6646
  /**
6535
6647
  * Get all literals in the AST (via WASM)
6536
6648
  */
@@ -8521,6 +8633,10 @@ declare type LikeOp = {
8521
8633
  * Quantifier: ANY, ALL, or SOME
8522
8634
  */
8523
8635
  quantifier: string | null;
8636
+ /**
8637
+ * Inferred data type from type annotation
8638
+ */
8639
+ inferred_type?: DataType | null;
8524
8640
  };
8525
8641
 
8526
8642
  /**
@@ -8597,6 +8713,36 @@ export declare interface LineageResult {
8597
8713
  error?: string;
8598
8714
  }
8599
8715
 
8716
+ /**
8717
+ * Trace the lineage of a column through a SQL query using schema metadata.
8718
+ *
8719
+ * When a schema is provided, columns are fully qualified and type-annotated.
8720
+ * Each `LineageNode.expression` will have its `inferred_type` field populated
8721
+ * with the resolved SQL data type. Use `ast.getInferredType(node.expression)`
8722
+ * to read it.
8723
+ *
8724
+ * @param column - Column name to trace
8725
+ * @param sql - SQL string to analyze
8726
+ * @param schema - ValidationSchema-compatible schema object
8727
+ * @param dialect - Dialect for parsing/qualification (default: 'generic')
8728
+ * @param trimSelects - Trim SELECT to only target column (default: false)
8729
+ *
8730
+ * @example
8731
+ * ```typescript
8732
+ * import { lineageWithSchema, ast } from '@polyglot-sql/sdk';
8733
+ *
8734
+ * const result = lineageWithSchema("name", "SELECT name FROM users", {
8735
+ * tables: { users: { name: "TEXT", id: "INT" } }
8736
+ * });
8737
+ *
8738
+ * if (result.success) {
8739
+ * const dt = ast.getInferredType(result.lineage!.expression);
8740
+ * // dt => { data_type: "text" }
8741
+ * }
8742
+ * ```
8743
+ */
8744
+ export declare function lineageWithSchema(column: string, sql: string, schema: Schema, dialect?: string, trimSelects?: boolean): LineageResult;
8745
+
8600
8746
  /**
8601
8747
  * List
8602
8748
  */
@@ -9470,6 +9616,21 @@ declare type Operator = {
9470
9616
  comments?: Array<string>;
9471
9617
  };
9472
9618
 
9619
+ /**
9620
+ * Key/value pair in a BigQuery OPTIONS (...) clause.
9621
+ */
9622
+ declare type OptionEntry = {
9623
+ key: Identifier;
9624
+ value: Expression;
9625
+ };
9626
+
9627
+ /**
9628
+ * Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
9629
+ */
9630
+ declare type OptionsProperty = {
9631
+ entries: Array<OptionEntry>;
9632
+ };
9633
+
9473
9634
  /** Chain multiple conditions with OR. */
9474
9635
  export declare function or(...conditions: ExprInput[]): Expr;
9475
9636
 
@@ -9793,6 +9954,13 @@ declare type PartitionByListProperty = {
9793
9954
  create_expressions: Expression | null;
9794
9955
  };
9795
9956
 
9957
+ /**
9958
+ * BigQuery PARTITION BY property in CREATE TABLE statements.
9959
+ */
9960
+ declare type PartitionByProperty = {
9961
+ expressions: Array<Expression>;
9962
+ };
9963
+
9796
9964
  /**
9797
9965
  * PartitionByRangeProperty
9798
9966
  */
@@ -10091,6 +10259,10 @@ export declare class Polyglot {
10091
10259
  * Get library version.
10092
10260
  */
10093
10261
  getVersion(): string;
10262
+ /**
10263
+ * Parse SQL and annotate the AST with inferred type information.
10264
+ */
10265
+ annotateTypes(sql: string, dialect?: Dialect, schema?: Schema): AnnotateTypesResult;
10094
10266
  }
10095
10267
 
10096
10268
  /**
@@ -12129,6 +12301,10 @@ declare type Subquery = {
12129
12301
  * Trailing comments after the closing paren
12130
12302
  */
12131
12303
  trailing_comments: Array<string>;
12304
+ /**
12305
+ * Inferred data type from type annotation
12306
+ */
12307
+ inferred_type?: DataType | null;
12132
12308
  };
12133
12309
 
12134
12310
  /**
@@ -13265,6 +13441,10 @@ declare type UnaryFunc = {
13265
13441
  * Original function name for round-trip preservation (e.g., CHAR_LENGTH vs LENGTH)
13266
13442
  */
13267
13443
  original_name?: string | null;
13444
+ /**
13445
+ * Inferred data type from type annotation
13446
+ */
13447
+ inferred_type?: DataType | null;
13268
13448
  };
13269
13449
 
13270
13450
  /**
@@ -13277,6 +13457,10 @@ declare type UnaryOp = {
13277
13457
  * The operand expression.
13278
13458
  */
13279
13459
  this: Expression;
13460
+ /**
13461
+ * Inferred data type from type annotation
13462
+ */
13463
+ inferred_type?: DataType | null;
13280
13464
  };
13281
13465
 
13282
13466
  /**
@@ -13801,6 +13985,10 @@ declare type VarArgFunc = {
13801
13985
  * Original function name for round-trip preservation (e.g., COALESCE vs IFNULL)
13802
13986
  */
13803
13987
  original_name?: string | null;
13988
+ /**
13989
+ * Inferred data type from type annotation
13990
+ */
13991
+ inferred_type?: DataType | null;
13804
13992
  };
13805
13993
 
13806
13994
  /**
@@ -14577,6 +14765,10 @@ declare type WindowFunction = {
14577
14765
  * Oracle KEEP clause: KEEP (DENSE_RANK FIRST|LAST ORDER BY ...)
14578
14766
  */
14579
14767
  keep?: Keep | null;
14768
+ /**
14769
+ * Inferred data type from type annotation
14770
+ */
14771
+ inferred_type?: DataType | null;
14580
14772
  };
14581
14773
 
14582
14774
  /**
package/dist/index.js CHANGED
@@ -1587,6 +1587,66 @@ class WasmWindowDefBuilder {
1587
1587
  }
1588
1588
  if (Symbol.dispose) WasmWindowDefBuilder.prototype[Symbol.dispose] = WasmWindowDefBuilder.prototype.free;
1589
1589
 
1590
+ /**
1591
+ * Annotate types on a parsed SQL AST in-place.
1592
+ *
1593
+ * Parses the given SQL, runs type annotation (and optionally uses a schema
1594
+ * for column type resolution), and returns the AST with `inferred_type`
1595
+ * fields populated on value-producing nodes.
1596
+ *
1597
+ * # Arguments
1598
+ * * `sql` - SQL string to parse
1599
+ * * `dialect` - Dialect for parsing
1600
+ * * `schema_json` - Optional JSON schema (same format as `lineage_sql_with_schema`)
1601
+ *
1602
+ * # Returns
1603
+ * JSON string containing `ParseValueResult` with annotated AST
1604
+ * @param {string} sql
1605
+ * @param {string} dialect
1606
+ * @param {string} schema_json
1607
+ * @returns {string}
1608
+ */
1609
+ function annotate_types$1(sql, dialect, schema_json) {
1610
+ let deferred4_0;
1611
+ let deferred4_1;
1612
+ try {
1613
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
1614
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1615
+ const len0 = WASM_VECTOR_LEN;
1616
+ const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1617
+ const len1 = WASM_VECTOR_LEN;
1618
+ const ptr2 = passStringToWasm0(schema_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1619
+ const len2 = WASM_VECTOR_LEN;
1620
+ wasm$3.annotate_types(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
1621
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1622
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1623
+ deferred4_0 = r0;
1624
+ deferred4_1 = r1;
1625
+ return getStringFromWasm0(r0, r1);
1626
+ } finally {
1627
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
1628
+ wasm$3.__wbindgen_export4(deferred4_0, deferred4_1, 1);
1629
+ }
1630
+ }
1631
+
1632
+ /**
1633
+ * Annotate types on a parsed SQL AST, returning a JsValue.
1634
+ * @param {string} sql
1635
+ * @param {string} dialect
1636
+ * @param {string} schema_json
1637
+ * @returns {any}
1638
+ */
1639
+ function annotate_types_value$1(sql, dialect, schema_json) {
1640
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1641
+ const len0 = WASM_VECTOR_LEN;
1642
+ const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1643
+ const len1 = WASM_VECTOR_LEN;
1644
+ const ptr2 = passStringToWasm0(schema_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1645
+ const len2 = WASM_VECTOR_LEN;
1646
+ const ret = wasm$3.annotate_types_value(ptr0, len0, ptr1, len1, ptr2, len2);
1647
+ return takeObject(ret);
1648
+ }
1649
+
1590
1650
  /**
1591
1651
  * Add a WHERE condition to a SELECT AST.
1592
1652
  * @param {string} ast_json
@@ -2221,6 +2281,50 @@ function lineage_sql$1(sql, column, dialect, trim_selects) {
2221
2281
  }
2222
2282
  }
2223
2283
 
2284
+ /**
2285
+ * Trace column lineage through a SQL query using schema metadata.
2286
+ *
2287
+ * # Arguments
2288
+ * * `sql` - SQL string to analyze
2289
+ * * `column` - Column name to trace
2290
+ * * `schema_json` - Schema JSON matching `ValidationSchema`
2291
+ * * `dialect` - Dialect for parsing/qualification
2292
+ * * `trim_selects` - Trim SELECT to only target column
2293
+ *
2294
+ * # Returns
2295
+ * JSON string containing LineageResult
2296
+ * @param {string} sql
2297
+ * @param {string} column
2298
+ * @param {string} schema_json
2299
+ * @param {string} dialect
2300
+ * @param {boolean} trim_selects
2301
+ * @returns {string}
2302
+ */
2303
+ function lineage_sql_with_schema$1(sql, column, schema_json, dialect, trim_selects) {
2304
+ let deferred5_0;
2305
+ let deferred5_1;
2306
+ try {
2307
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
2308
+ const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2309
+ const len0 = WASM_VECTOR_LEN;
2310
+ const ptr1 = passStringToWasm0(column, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2311
+ const len1 = WASM_VECTOR_LEN;
2312
+ const ptr2 = passStringToWasm0(schema_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2313
+ const len2 = WASM_VECTOR_LEN;
2314
+ const ptr3 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2315
+ const len3 = WASM_VECTOR_LEN;
2316
+ wasm$3.lineage_sql_with_schema(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, trim_selects);
2317
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2318
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2319
+ deferred5_0 = r0;
2320
+ deferred5_1 = r1;
2321
+ return getStringFromWasm0(r0, r1);
2322
+ } finally {
2323
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
2324
+ wasm$3.__wbindgen_export4(deferred5_0, deferred5_1, 1);
2325
+ }
2326
+ }
2327
+
2224
2328
  /**
2225
2329
  * Parse SQL into an AST (returned as JSON).
2226
2330
  *
@@ -3379,6 +3483,8 @@ const __wbg_wasmselectbuilder_free = __vite__wasmModule.__wbg_wasmselectbuilder_
3379
3483
  const __wbg_wasmsetopbuilder_free = __vite__wasmModule.__wbg_wasmsetopbuilder_free;
3380
3484
  const __wbg_wasmupdatebuilder_free = __vite__wasmModule.__wbg_wasmupdatebuilder_free;
3381
3485
  const __wbg_wasmwindowdefbuilder_free = __vite__wasmModule.__wbg_wasmwindowdefbuilder_free;
3486
+ const annotate_types = __vite__wasmModule.annotate_types;
3487
+ const annotate_types_value = __vite__wasmModule.annotate_types_value;
3382
3488
  const ast_add_where = __vite__wasmModule.ast_add_where;
3383
3489
  const ast_get_aggregate_functions = __vite__wasmModule.ast_get_aggregate_functions;
3384
3490
  const ast_get_column_names = __vite__wasmModule.ast_get_column_names;
@@ -3404,6 +3510,7 @@ const generate_value = __vite__wasmModule.generate_value;
3404
3510
  const get_dialects = __vite__wasmModule.get_dialects;
3405
3511
  const get_dialects_value = __vite__wasmModule.get_dialects_value;
3406
3512
  const lineage_sql = __vite__wasmModule.lineage_sql;
3513
+ const lineage_sql_with_schema = __vite__wasmModule.lineage_sql_with_schema;
3407
3514
  const parse$1 = __vite__wasmModule.parse;
3408
3515
  const parse_value = __vite__wasmModule.parse_value;
3409
3516
  const plan$1 = __vite__wasmModule.plan;
@@ -3565,6 +3672,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3565
3672
  __wbindgen_export2,
3566
3673
  __wbindgen_export3,
3567
3674
  __wbindgen_export4,
3675
+ annotate_types,
3676
+ annotate_types_value,
3568
3677
  ast_add_where,
3569
3678
  ast_get_aggregate_functions,
3570
3679
  ast_get_column_names,
@@ -3590,6 +3699,7 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3590
3699
  get_dialects,
3591
3700
  get_dialects_value,
3592
3701
  lineage_sql,
3702
+ lineage_sql_with_schema,
3593
3703
  memory,
3594
3704
  parse: parse$1,
3595
3705
  parse_value,
@@ -3747,6 +3857,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
3747
3857
  WasmSetOpBuilder,
3748
3858
  WasmUpdateBuilder,
3749
3859
  WasmWindowDefBuilder,
3860
+ annotate_types: annotate_types$1,
3861
+ annotate_types_value: annotate_types_value$1,
3750
3862
  ast_add_where: ast_add_where$1,
3751
3863
  ast_get_aggregate_functions: ast_get_aggregate_functions$1,
3752
3864
  ast_get_column_names: ast_get_column_names$1,
@@ -3772,6 +3884,7 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
3772
3884
  get_dialects: get_dialects$1,
3773
3885
  get_dialects_value: get_dialects_value$1,
3774
3886
  lineage_sql: lineage_sql$1,
3887
+ lineage_sql_with_schema: lineage_sql_with_schema$1,
3775
3888
  parse: parse$2,
3776
3889
  parse_value: parse_value$1,
3777
3890
  plan: plan$2,
@@ -3822,6 +3935,16 @@ function isExpressionValue(value) {
3822
3935
  function makeExpr(type, data) {
3823
3936
  return { [type]: data };
3824
3937
  }
3938
+ function getInferredType(expr) {
3939
+ const data = getExprData(expr);
3940
+ if (data && typeof data === "object" && "inferred_type" in data) {
3941
+ const it = data["inferred_type"];
3942
+ if (it != null) {
3943
+ return it;
3944
+ }
3945
+ }
3946
+ return void 0;
3947
+ }
3825
3948
 
3826
3949
  function isType(type) {
3827
3950
  return (expr) => type in expr;
@@ -4404,6 +4527,7 @@ const index$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4404
4527
  getExprType,
4405
4528
  getFunctions,
4406
4529
  getIdentifiers,
4530
+ getInferredType,
4407
4531
  getLiterals,
4408
4532
  getNodeDepth,
4409
4533
  getParent,
@@ -5389,6 +5513,16 @@ function lineage(column, sql, dialect = "generic", trimSelects = false) {
5389
5513
  const resultJson = lineage_sql$1(sql, column, dialect, trimSelects);
5390
5514
  return JSON.parse(resultJson);
5391
5515
  }
5516
+ function lineageWithSchema(column, sql, schema, dialect = "generic", trimSelects = false) {
5517
+ const resultJson = lineage_sql_with_schema$1(
5518
+ sql,
5519
+ column,
5520
+ JSON.stringify(schema),
5521
+ dialect,
5522
+ trimSelects
5523
+ );
5524
+ return JSON.parse(resultJson);
5525
+ }
5392
5526
  function getSourceTables(column, sql, dialect = "generic") {
5393
5527
  const resultJson = source_tables$1(sql, column, dialect);
5394
5528
  return JSON.parse(resultJson);
@@ -5577,6 +5711,30 @@ function getDialects() {
5577
5711
  function getVersion() {
5578
5712
  return wasm.version();
5579
5713
  }
5714
+ function annotateTypes(sql, dialect = "generic" /* Generic */, schema) {
5715
+ try {
5716
+ const schemaJson = schema ? JSON.stringify(schema) : "";
5717
+ if (typeof wasm.annotate_types_value === "function") {
5718
+ return decodeWasmPayload(
5719
+ wasm.annotate_types_value(sql, dialect, schemaJson)
5720
+ );
5721
+ }
5722
+ if (typeof wasm.annotate_types === "function") {
5723
+ return JSON.parse(
5724
+ wasm.annotate_types(sql, dialect, schemaJson)
5725
+ );
5726
+ }
5727
+ return {
5728
+ success: false,
5729
+ error: "annotate_types not available in this WASM build"
5730
+ };
5731
+ } catch (error) {
5732
+ return {
5733
+ success: false,
5734
+ error: `WASM annotate_types failed: ${errorMessage(error)}`
5735
+ };
5736
+ }
5737
+ }
5580
5738
  class Polyglot {
5581
5739
  static instance = null;
5582
5740
  constructor() {
@@ -5644,6 +5802,12 @@ class Polyglot {
5644
5802
  getVersion() {
5645
5803
  return getVersion();
5646
5804
  }
5805
+ /**
5806
+ * Parse SQL and annotate the AST with inferred type information.
5807
+ */
5808
+ annotateTypes(sql, dialect = "generic" /* Generic */, schema) {
5809
+ return annotateTypes(sql, dialect, schema);
5810
+ }
5647
5811
  }
5648
5812
  const index = {
5649
5813
  init,
@@ -5653,9 +5817,11 @@ const index = {
5653
5817
  tokenize,
5654
5818
  generate,
5655
5819
  format,
5820
+ annotateTypes,
5656
5821
  getDialects,
5657
5822
  getVersion,
5658
5823
  lineage: lineage,
5824
+ lineageWithSchema: lineageWithSchema,
5659
5825
  getSourceTables: getSourceTables,
5660
5826
  diff: diff,
5661
5827
  hasChanges: hasChanges,
@@ -5665,4 +5831,4 @@ const index = {
5665
5831
  Polyglot
5666
5832
  };
5667
5833
 
5668
- export { CaseBuilder, DeleteBuilder, Dialect, Expr, InsertBuilder, MergeBuilder, Polyglot, SelectBuilder, SetOpBuilder, UpdateBuilder, ValidationSeverity, WindowDefBuilder, abs, alias, and, 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, getSourceTables, getVersion, greatest, hasChanges, ifNull, init, initcap, insert, insertInto, intersect, isColumn, isFunction, isInitialized, isLiteral, isSelect, least, length, lineage, lit, ln, lower, ltrim, max, mergeInto, min, not, nullIf, 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 };
5834
+ 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, 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 };
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyglot-sql/sdk",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "SQL dialect translator powered by WebAssembly",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -14,6 +14,7 @@
14
14
  "import": "./dist/index.d.ts",
15
15
  "require": "./dist/index.d.cts"
16
16
  },
17
+ "browser": "./dist/index.js",
17
18
  "import": "./dist/index.js",
18
19
  "require": "./dist/index.cjs"
19
20
  },