@polyglot-sql/sdk 0.5.0 → 0.5.2
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/README.md +54 -0
- package/dist/cdn/polyglot.esm.js +1591 -1439
- package/dist/index.cjs +213 -0
- package/dist/index.d.cts +160 -1
- package/dist/index.d.ts +160 -1
- package/dist/index.js +247 -1
- package/dist/index.node.js +207 -0
- package/dist/manual.js +235 -1
- package/dist/polyglot_sql.wasm +0 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1513,6 +1513,32 @@ class WasmWindowDefBuilder {
|
|
|
1513
1513
|
}
|
|
1514
1514
|
}
|
|
1515
1515
|
if (Symbol.dispose) WasmWindowDefBuilder.prototype[Symbol.dispose] = WasmWindowDefBuilder.prototype.free;
|
|
1516
|
+
function analyze_query$1(sql, options_json) {
|
|
1517
|
+
let deferred3_0;
|
|
1518
|
+
let deferred3_1;
|
|
1519
|
+
try {
|
|
1520
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
1521
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
1522
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1523
|
+
const ptr1 = passStringToWasm0(options_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
1524
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1525
|
+
wasm$3.analyze_query(retptr, ptr0, len0, ptr1, len1);
|
|
1526
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1527
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1528
|
+
deferred3_0 = r0;
|
|
1529
|
+
deferred3_1 = r1;
|
|
1530
|
+
return getStringFromWasm0(r0, r1);
|
|
1531
|
+
} finally {
|
|
1532
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
1533
|
+
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
function analyze_query_value$1(sql, options) {
|
|
1537
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
1538
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1539
|
+
const ret = wasm$3.analyze_query_value(ptr0, len0, addHeapObject(options));
|
|
1540
|
+
return takeObject(ret);
|
|
1541
|
+
}
|
|
1516
1542
|
function annotate_types$1(sql, dialect, schema_json) {
|
|
1517
1543
|
let deferred4_0;
|
|
1518
1544
|
let deferred4_1;
|
|
@@ -1965,6 +1991,32 @@ function generate$2(ast_json, dialect) {
|
|
|
1965
1991
|
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
1966
1992
|
}
|
|
1967
1993
|
}
|
|
1994
|
+
function generate_data_type$1(data_type_json, dialect) {
|
|
1995
|
+
let deferred3_0;
|
|
1996
|
+
let deferred3_1;
|
|
1997
|
+
try {
|
|
1998
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
1999
|
+
const ptr0 = passStringToWasm0(data_type_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2000
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2001
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2002
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2003
|
+
wasm$3.generate_data_type(retptr, ptr0, len0, ptr1, len1);
|
|
2004
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2005
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2006
|
+
deferred3_0 = r0;
|
|
2007
|
+
deferred3_1 = r1;
|
|
2008
|
+
return getStringFromWasm0(r0, r1);
|
|
2009
|
+
} finally {
|
|
2010
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
2011
|
+
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
function generate_data_type_value$1(data_type, dialect) {
|
|
2015
|
+
const ptr0 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2016
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2017
|
+
const ret = wasm$3.generate_data_type_value(addHeapObject(data_type), ptr0, len0);
|
|
2018
|
+
return takeObject(ret);
|
|
2019
|
+
}
|
|
1968
2020
|
function generate_value$1(ast, dialect) {
|
|
1969
2021
|
const ptr0 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
1970
2022
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -2117,6 +2169,34 @@ function parse$2(sql, dialect) {
|
|
|
2117
2169
|
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
2118
2170
|
}
|
|
2119
2171
|
}
|
|
2172
|
+
function parse_data_type$1(sql, dialect) {
|
|
2173
|
+
let deferred3_0;
|
|
2174
|
+
let deferred3_1;
|
|
2175
|
+
try {
|
|
2176
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
2177
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2178
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2179
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2180
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2181
|
+
wasm$3.parse_data_type(retptr, ptr0, len0, ptr1, len1);
|
|
2182
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2183
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2184
|
+
deferred3_0 = r0;
|
|
2185
|
+
deferred3_1 = r1;
|
|
2186
|
+
return getStringFromWasm0(r0, r1);
|
|
2187
|
+
} finally {
|
|
2188
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
2189
|
+
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
function parse_data_type_value$1(sql, dialect) {
|
|
2193
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2194
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2195
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2196
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2197
|
+
const ret = wasm$3.parse_data_type_value(ptr0, len0, ptr1, len1);
|
|
2198
|
+
return takeObject(ret);
|
|
2199
|
+
}
|
|
2120
2200
|
function parse_value$1(sql, dialect) {
|
|
2121
2201
|
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2122
2202
|
const len0 = WASM_VECTOR_LEN;
|
|
@@ -3014,6 +3094,8 @@ async function __polyglot_init_wasm() {
|
|
|
3014
3094
|
__wbg_wasmsetopbuilder_free = __vite__wasmModule.__wbg_wasmsetopbuilder_free;
|
|
3015
3095
|
__wbg_wasmupdatebuilder_free = __vite__wasmModule.__wbg_wasmupdatebuilder_free;
|
|
3016
3096
|
__wbg_wasmwindowdefbuilder_free = __vite__wasmModule.__wbg_wasmwindowdefbuilder_free;
|
|
3097
|
+
analyze_query = __vite__wasmModule.analyze_query;
|
|
3098
|
+
analyze_query_value = __vite__wasmModule.analyze_query_value;
|
|
3017
3099
|
annotate_types = __vite__wasmModule.annotate_types;
|
|
3018
3100
|
annotate_types_value = __vite__wasmModule.annotate_types_value;
|
|
3019
3101
|
ast_add_where = __vite__wasmModule.ast_add_where;
|
|
@@ -3039,6 +3121,8 @@ async function __polyglot_init_wasm() {
|
|
|
3039
3121
|
format_sql_with_options = __vite__wasmModule.format_sql_with_options;
|
|
3040
3122
|
format_sql_with_options_value = __vite__wasmModule.format_sql_with_options_value;
|
|
3041
3123
|
generate$1 = __vite__wasmModule.generate;
|
|
3124
|
+
generate_data_type = __vite__wasmModule.generate_data_type;
|
|
3125
|
+
generate_data_type_value = __vite__wasmModule.generate_data_type_value;
|
|
3042
3126
|
generate_value = __vite__wasmModule.generate_value;
|
|
3043
3127
|
get_dialects = __vite__wasmModule.get_dialects;
|
|
3044
3128
|
get_dialects_value = __vite__wasmModule.get_dialects_value;
|
|
@@ -3048,6 +3132,8 @@ async function __polyglot_init_wasm() {
|
|
|
3048
3132
|
openlineage_job_event = __vite__wasmModule.openlineage_job_event;
|
|
3049
3133
|
openlineage_run_event = __vite__wasmModule.openlineage_run_event;
|
|
3050
3134
|
parse$1 = __vite__wasmModule.parse;
|
|
3135
|
+
parse_data_type = __vite__wasmModule.parse_data_type;
|
|
3136
|
+
parse_data_type_value = __vite__wasmModule.parse_data_type_value;
|
|
3051
3137
|
parse_value = __vite__wasmModule.parse_value;
|
|
3052
3138
|
plan$1 = __vite__wasmModule.plan;
|
|
3053
3139
|
source_tables = __vite__wasmModule.source_tables;
|
|
@@ -3207,6 +3293,8 @@ let __wbg_wasmselectbuilder_free;
|
|
|
3207
3293
|
let __wbg_wasmsetopbuilder_free;
|
|
3208
3294
|
let __wbg_wasmupdatebuilder_free;
|
|
3209
3295
|
let __wbg_wasmwindowdefbuilder_free;
|
|
3296
|
+
let analyze_query;
|
|
3297
|
+
let analyze_query_value;
|
|
3210
3298
|
let annotate_types;
|
|
3211
3299
|
let annotate_types_value;
|
|
3212
3300
|
let ast_add_where;
|
|
@@ -3232,6 +3320,8 @@ let format_sql_value;
|
|
|
3232
3320
|
let format_sql_with_options;
|
|
3233
3321
|
let format_sql_with_options_value;
|
|
3234
3322
|
let generate$1;
|
|
3323
|
+
let generate_data_type;
|
|
3324
|
+
let generate_data_type_value;
|
|
3235
3325
|
let generate_value;
|
|
3236
3326
|
let get_dialects;
|
|
3237
3327
|
let get_dialects_value;
|
|
@@ -3241,6 +3331,8 @@ let openlineage_column_lineage;
|
|
|
3241
3331
|
let openlineage_job_event;
|
|
3242
3332
|
let openlineage_run_event;
|
|
3243
3333
|
let parse$1;
|
|
3334
|
+
let parse_data_type;
|
|
3335
|
+
let parse_data_type_value;
|
|
3244
3336
|
let parse_value;
|
|
3245
3337
|
let plan$1;
|
|
3246
3338
|
let source_tables;
|
|
@@ -3402,6 +3494,8 @@ const wasm$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
3402
3494
|
__wbindgen_export2,
|
|
3403
3495
|
__wbindgen_export3,
|
|
3404
3496
|
__wbindgen_export4,
|
|
3497
|
+
analyze_query,
|
|
3498
|
+
analyze_query_value,
|
|
3405
3499
|
annotate_types,
|
|
3406
3500
|
annotate_types_value,
|
|
3407
3501
|
ast_add_where,
|
|
@@ -3427,6 +3521,8 @@ const wasm$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
3427
3521
|
format_sql_with_options,
|
|
3428
3522
|
format_sql_with_options_value,
|
|
3429
3523
|
generate: generate$1,
|
|
3524
|
+
generate_data_type,
|
|
3525
|
+
generate_data_type_value,
|
|
3430
3526
|
generate_value,
|
|
3431
3527
|
get_dialects,
|
|
3432
3528
|
get_dialects_value,
|
|
@@ -3437,6 +3533,8 @@ const wasm$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
3437
3533
|
openlineage_job_event,
|
|
3438
3534
|
openlineage_run_event,
|
|
3439
3535
|
parse: parse$1,
|
|
3536
|
+
parse_data_type,
|
|
3537
|
+
parse_data_type_value,
|
|
3440
3538
|
parse_value,
|
|
3441
3539
|
plan: plan$1,
|
|
3442
3540
|
source_tables,
|
|
@@ -3589,6 +3687,8 @@ const wasmModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
3589
3687
|
WasmSetOpBuilder,
|
|
3590
3688
|
WasmUpdateBuilder,
|
|
3591
3689
|
WasmWindowDefBuilder,
|
|
3690
|
+
analyze_query: analyze_query$1,
|
|
3691
|
+
analyze_query_value: analyze_query_value$1,
|
|
3592
3692
|
annotate_types: annotate_types$1,
|
|
3593
3693
|
annotate_types_value: annotate_types_value$1,
|
|
3594
3694
|
ast_add_where: ast_add_where$1,
|
|
@@ -3614,6 +3714,8 @@ const wasmModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
3614
3714
|
format_sql_with_options: format_sql_with_options$1,
|
|
3615
3715
|
format_sql_with_options_value: format_sql_with_options_value$1,
|
|
3616
3716
|
generate: generate$2,
|
|
3717
|
+
generate_data_type: generate_data_type$1,
|
|
3718
|
+
generate_data_type_value: generate_data_type_value$1,
|
|
3617
3719
|
generate_value: generate_value$1,
|
|
3618
3720
|
get_dialects: get_dialects$1,
|
|
3619
3721
|
get_dialects_value: get_dialects_value$1,
|
|
@@ -3623,6 +3725,8 @@ const wasmModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
3623
3725
|
openlineage_job_event: openlineage_job_event$1,
|
|
3624
3726
|
openlineage_run_event: openlineage_run_event$1,
|
|
3625
3727
|
parse: parse$2,
|
|
3728
|
+
parse_data_type: parse_data_type$1,
|
|
3729
|
+
parse_data_type_value: parse_data_type_value$1,
|
|
3626
3730
|
parse_value: parse_value$1,
|
|
3627
3731
|
plan: plan$2,
|
|
3628
3732
|
source_tables: source_tables$1,
|
|
@@ -5374,12 +5478,46 @@ function parseFailure(context, error) {
|
|
|
5374
5478
|
errorColumn: void 0
|
|
5375
5479
|
};
|
|
5376
5480
|
}
|
|
5481
|
+
function dataTypeFailure(context, error) {
|
|
5482
|
+
return {
|
|
5483
|
+
success: false,
|
|
5484
|
+
dataType: void 0,
|
|
5485
|
+
error: `WASM ${context} failed: ${errorMessage(error)}`,
|
|
5486
|
+
errorLine: void 0,
|
|
5487
|
+
errorColumn: void 0
|
|
5488
|
+
};
|
|
5489
|
+
}
|
|
5490
|
+
function generateDataTypeFailure(context, error) {
|
|
5491
|
+
return {
|
|
5492
|
+
success: false,
|
|
5493
|
+
sql: void 0,
|
|
5494
|
+
error: `WASM ${context} failed: ${errorMessage(error)}`,
|
|
5495
|
+
errorLine: void 0,
|
|
5496
|
+
errorColumn: void 0
|
|
5497
|
+
};
|
|
5498
|
+
}
|
|
5377
5499
|
function decodeWasmPayload(payload) {
|
|
5378
5500
|
if (typeof payload === "string") {
|
|
5379
5501
|
return JSON.parse(payload);
|
|
5380
5502
|
}
|
|
5381
5503
|
return payload;
|
|
5382
5504
|
}
|
|
5505
|
+
function queryAnalysisFailure(context, error) {
|
|
5506
|
+
return {
|
|
5507
|
+
success: false,
|
|
5508
|
+
analysis: void 0,
|
|
5509
|
+
error: `WASM ${context} failed: ${errorMessage(error)}`
|
|
5510
|
+
};
|
|
5511
|
+
}
|
|
5512
|
+
function normalizeAnalyzeQueryOptions(optionsOrDialect = {}) {
|
|
5513
|
+
if (typeof optionsOrDialect === "string") {
|
|
5514
|
+
return { dialect: optionsOrDialect };
|
|
5515
|
+
}
|
|
5516
|
+
return {
|
|
5517
|
+
dialect: "generic",
|
|
5518
|
+
...optionsOrDialect
|
|
5519
|
+
};
|
|
5520
|
+
}
|
|
5383
5521
|
async function init() {
|
|
5384
5522
|
await __polyglot_init_wasm();
|
|
5385
5523
|
}
|
|
@@ -5429,6 +5567,24 @@ function parse(sql, dialect = "generic") {
|
|
|
5429
5567
|
return parseFailure("parse", error);
|
|
5430
5568
|
}
|
|
5431
5569
|
}
|
|
5570
|
+
function parseDataType(sql, dialect = "generic") {
|
|
5571
|
+
try {
|
|
5572
|
+
if (typeof wasm.parse_data_type_value === "function") {
|
|
5573
|
+
return decodeWasmPayload(
|
|
5574
|
+
wasm.parse_data_type_value(sql, dialect)
|
|
5575
|
+
);
|
|
5576
|
+
}
|
|
5577
|
+
const result = JSON.parse(
|
|
5578
|
+
wasm.parse_data_type(sql, dialect)
|
|
5579
|
+
);
|
|
5580
|
+
if (result.success && typeof result.dataType === "string") {
|
|
5581
|
+
result.dataType = JSON.parse(result.dataType);
|
|
5582
|
+
}
|
|
5583
|
+
return result;
|
|
5584
|
+
} catch (error) {
|
|
5585
|
+
return dataTypeFailure("parseDataType", error);
|
|
5586
|
+
}
|
|
5587
|
+
}
|
|
5432
5588
|
function tokenize(sql, dialect = "generic") {
|
|
5433
5589
|
try {
|
|
5434
5590
|
if (typeof wasm.tokenize_value === "function") {
|
|
@@ -5458,6 +5614,21 @@ function generate(ast2, dialect = "generic") {
|
|
|
5458
5614
|
return transpileFailure("generate", error);
|
|
5459
5615
|
}
|
|
5460
5616
|
}
|
|
5617
|
+
function generateDataType(dataType, dialect = "generic") {
|
|
5618
|
+
try {
|
|
5619
|
+
if (typeof wasm.generate_data_type_value === "function") {
|
|
5620
|
+
return decodeWasmPayload(
|
|
5621
|
+
wasm.generate_data_type_value(dataType, dialect)
|
|
5622
|
+
);
|
|
5623
|
+
}
|
|
5624
|
+
const dataTypeJson = JSON.stringify(dataType);
|
|
5625
|
+
return JSON.parse(
|
|
5626
|
+
wasm.generate_data_type(dataTypeJson, dialect)
|
|
5627
|
+
);
|
|
5628
|
+
} catch (error) {
|
|
5629
|
+
return generateDataTypeFailure("generateDataType", error);
|
|
5630
|
+
}
|
|
5631
|
+
}
|
|
5461
5632
|
function format(sql, dialect = "generic") {
|
|
5462
5633
|
return formatWithOptions(sql, dialect, {});
|
|
5463
5634
|
}
|
|
@@ -5492,6 +5663,27 @@ function getDialects() {
|
|
|
5492
5663
|
function getVersion() {
|
|
5493
5664
|
return wasm.version();
|
|
5494
5665
|
}
|
|
5666
|
+
function analyzeQuery(sql, optionsOrDialect = {}) {
|
|
5667
|
+
try {
|
|
5668
|
+
const normalized = normalizeAnalyzeQueryOptions(optionsOrDialect);
|
|
5669
|
+
if (typeof wasm.analyze_query_value === "function") {
|
|
5670
|
+
return decodeWasmPayload(
|
|
5671
|
+
wasm.analyze_query_value(sql, normalized)
|
|
5672
|
+
);
|
|
5673
|
+
}
|
|
5674
|
+
if (typeof wasm.analyze_query === "function") {
|
|
5675
|
+
return JSON.parse(
|
|
5676
|
+
wasm.analyze_query(sql, JSON.stringify(normalized))
|
|
5677
|
+
);
|
|
5678
|
+
}
|
|
5679
|
+
return {
|
|
5680
|
+
success: false,
|
|
5681
|
+
error: "analyze_query not available in this WASM build"
|
|
5682
|
+
};
|
|
5683
|
+
} catch (error) {
|
|
5684
|
+
return queryAnalysisFailure("analyzeQuery", error);
|
|
5685
|
+
}
|
|
5686
|
+
}
|
|
5495
5687
|
function annotateTypes(sql, dialect = "generic", schema) {
|
|
5496
5688
|
try {
|
|
5497
5689
|
const schemaJson = schema ? JSON.stringify(schema) : "";
|
|
@@ -5546,6 +5738,12 @@ class Polyglot {
|
|
|
5546
5738
|
parse(sql, dialect = "generic") {
|
|
5547
5739
|
return parse(sql, dialect);
|
|
5548
5740
|
}
|
|
5741
|
+
/**
|
|
5742
|
+
* Parse a standalone SQL data type.
|
|
5743
|
+
*/
|
|
5744
|
+
parseDataType(sql, dialect = "generic") {
|
|
5745
|
+
return parseDataType(sql, dialect);
|
|
5746
|
+
}
|
|
5549
5747
|
/**
|
|
5550
5748
|
* Tokenize SQL into a token stream.
|
|
5551
5749
|
*/
|
|
@@ -5558,6 +5756,12 @@ class Polyglot {
|
|
|
5558
5756
|
generate(ast2, dialect = "generic") {
|
|
5559
5757
|
return generate(ast2, dialect);
|
|
5560
5758
|
}
|
|
5759
|
+
/**
|
|
5760
|
+
* Generate SQL from a standalone DataType AST node.
|
|
5761
|
+
*/
|
|
5762
|
+
generateDataType(dataType, dialect = "generic") {
|
|
5763
|
+
return generateDataType(dataType, dialect);
|
|
5764
|
+
}
|
|
5561
5765
|
/**
|
|
5562
5766
|
* Format SQL.
|
|
5563
5767
|
*/
|
|
@@ -5589,16 +5793,22 @@ class Polyglot {
|
|
|
5589
5793
|
annotateTypes(sql, dialect = "generic", schema) {
|
|
5590
5794
|
return annotateTypes(sql, dialect, schema);
|
|
5591
5795
|
}
|
|
5796
|
+
analyzeQuery(sql, optionsOrDialect = {}) {
|
|
5797
|
+
return analyzeQuery(sql, normalizeAnalyzeQueryOptions(optionsOrDialect));
|
|
5798
|
+
}
|
|
5592
5799
|
}
|
|
5593
5800
|
const index = {
|
|
5594
5801
|
init,
|
|
5595
5802
|
isInitialized,
|
|
5596
5803
|
transpile,
|
|
5597
5804
|
parse,
|
|
5805
|
+
parseDataType,
|
|
5598
5806
|
tokenize,
|
|
5599
5807
|
generate,
|
|
5808
|
+
generateDataType,
|
|
5600
5809
|
format,
|
|
5601
5810
|
annotateTypes,
|
|
5811
|
+
analyzeQuery,
|
|
5602
5812
|
getDialects,
|
|
5603
5813
|
getVersion,
|
|
5604
5814
|
lineage,
|
|
@@ -5628,6 +5838,7 @@ exports.ValidationSeverity = ValidationSeverity;
|
|
|
5628
5838
|
exports.WindowDefBuilder = WindowDefBuilder;
|
|
5629
5839
|
exports.abs = abs;
|
|
5630
5840
|
exports.alias = alias;
|
|
5841
|
+
exports.analyzeQuery = analyzeQuery;
|
|
5631
5842
|
exports.and = and;
|
|
5632
5843
|
exports.annotateTypes = annotateTypes;
|
|
5633
5844
|
exports.ast = index$1;
|
|
@@ -5661,6 +5872,7 @@ exports.format = format;
|
|
|
5661
5872
|
exports.formatWithOptions = formatWithOptions;
|
|
5662
5873
|
exports.func = func;
|
|
5663
5874
|
exports.generate = generate;
|
|
5875
|
+
exports.generateDataType = generateDataType;
|
|
5664
5876
|
exports.getColumns = getColumns;
|
|
5665
5877
|
exports.getDialects = getDialects;
|
|
5666
5878
|
exports.getInferredType = getInferredType;
|
|
@@ -5697,6 +5909,7 @@ exports.openLineageJobEvent = openLineageJobEvent;
|
|
|
5697
5909
|
exports.openLineageRunEvent = openLineageRunEvent;
|
|
5698
5910
|
exports.or = or;
|
|
5699
5911
|
exports.parse = parse;
|
|
5912
|
+
exports.parseDataType = parseDataType;
|
|
5700
5913
|
exports.plan = plan;
|
|
5701
5914
|
exports.power = power;
|
|
5702
5915
|
exports.rank = rank;
|
package/dist/index.d.cts
CHANGED
|
@@ -593,6 +593,20 @@ 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, dialect: Dialect | string): QueryAnalysisResult;
|
|
600
|
+
|
|
601
|
+
export declare function analyzeQuery(sql: string, options?: AnalyzeQueryOptions): QueryAnalysisResult;
|
|
602
|
+
|
|
603
|
+
export declare interface AnalyzeQueryOptions {
|
|
604
|
+
/** Dialect used for parsing and dialect-aware rendering */
|
|
605
|
+
dialect?: Dialect | string;
|
|
606
|
+
/** Optional schema used for qualification and type annotation */
|
|
607
|
+
schema?: Schema;
|
|
608
|
+
}
|
|
609
|
+
|
|
596
610
|
/**
|
|
597
611
|
* AnalyzeSample
|
|
598
612
|
*/
|
|
@@ -1817,6 +1831,16 @@ declare type ColumnPrefix = {
|
|
|
1817
1831
|
expression: Expression;
|
|
1818
1832
|
};
|
|
1819
1833
|
|
|
1834
|
+
export declare interface ColumnReferenceFact {
|
|
1835
|
+
sourceName?: string;
|
|
1836
|
+
sourceAlias?: string;
|
|
1837
|
+
sourceKind: QueryAnalysisSourceKind;
|
|
1838
|
+
table?: string;
|
|
1839
|
+
column: string;
|
|
1840
|
+
unqualified: boolean;
|
|
1841
|
+
confidence: ReferenceConfidence;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1820
1844
|
/**
|
|
1821
1845
|
* Columns
|
|
1822
1846
|
*/
|
|
@@ -3021,7 +3045,7 @@ declare type DataDeletionProperty = {
|
|
|
3021
3045
|
* Types that do not match any known variant fall through to `Custom { name }`,
|
|
3022
3046
|
* preserving the original type name for round-trip fidelity.
|
|
3023
3047
|
*/
|
|
3024
|
-
declare type DataType = {
|
|
3048
|
+
export declare type DataType = {
|
|
3025
3049
|
"data_type": "boolean";
|
|
3026
3050
|
} | {
|
|
3027
3051
|
"data_type": "tiny_int";
|
|
@@ -3158,6 +3182,23 @@ declare type DataType = {
|
|
|
3158
3182
|
"data_type": "unknown";
|
|
3159
3183
|
};
|
|
3160
3184
|
|
|
3185
|
+
/**
|
|
3186
|
+
* Result of a standalone data type parse operation
|
|
3187
|
+
*/
|
|
3188
|
+
export declare interface DataTypeResult {
|
|
3189
|
+
success: boolean;
|
|
3190
|
+
dataType?: DataType;
|
|
3191
|
+
error?: string;
|
|
3192
|
+
/** 1-based line number where the error occurred */
|
|
3193
|
+
errorLine?: number;
|
|
3194
|
+
/** 1-based column number where the error occurred */
|
|
3195
|
+
errorColumn?: number;
|
|
3196
|
+
/** Start byte offset of the error range */
|
|
3197
|
+
errorStart?: number;
|
|
3198
|
+
/** End byte offset of the error range (exclusive) */
|
|
3199
|
+
errorEnd?: number;
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3161
3202
|
/**
|
|
3162
3203
|
* DATE_ADD / DATE_SUB function
|
|
3163
3204
|
*/
|
|
@@ -3366,10 +3407,13 @@ declare const _default: {
|
|
|
3366
3407
|
isInitialized: typeof isInitialized;
|
|
3367
3408
|
transpile: typeof transpile;
|
|
3368
3409
|
parse: typeof parse;
|
|
3410
|
+
parseDataType: typeof parseDataType;
|
|
3369
3411
|
tokenize: typeof tokenize;
|
|
3370
3412
|
generate: typeof generate;
|
|
3413
|
+
generateDataType: typeof generateDataType;
|
|
3371
3414
|
format: typeof format;
|
|
3372
3415
|
annotateTypes: typeof annotateTypes;
|
|
3416
|
+
analyzeQuery: typeof analyzeQuery;
|
|
3373
3417
|
getDialects: typeof getDialects;
|
|
3374
3418
|
getVersion: typeof getVersion;
|
|
3375
3419
|
lineage: typeof lineage;
|
|
@@ -6702,6 +6746,39 @@ declare type GeneratedAsRowColumnConstraint = {
|
|
|
6702
6746
|
hidden: Expression | null;
|
|
6703
6747
|
};
|
|
6704
6748
|
|
|
6749
|
+
/**
|
|
6750
|
+
* Generate SQL from a standalone DataType AST node.
|
|
6751
|
+
*
|
|
6752
|
+
* @param dataType - The DataType object to render
|
|
6753
|
+
* @param dialect - The target dialect
|
|
6754
|
+
* @returns The generated data type SQL
|
|
6755
|
+
*
|
|
6756
|
+
* @example
|
|
6757
|
+
* ```typescript
|
|
6758
|
+
* const parsed = parseDataType("VARCHAR(255)", Dialect.DuckDB);
|
|
6759
|
+
* const rendered = generateDataType(parsed.dataType!, Dialect.PostgreSQL);
|
|
6760
|
+
* // rendered.sql = "VARCHAR(255)"
|
|
6761
|
+
* ```
|
|
6762
|
+
*/
|
|
6763
|
+
export declare function generateDataType(dataType: DataType, dialect?: Dialect): GenerateDataTypeResult;
|
|
6764
|
+
|
|
6765
|
+
/**
|
|
6766
|
+
* Result of a standalone data type generation operation
|
|
6767
|
+
*/
|
|
6768
|
+
export declare interface GenerateDataTypeResult {
|
|
6769
|
+
success: boolean;
|
|
6770
|
+
sql?: string;
|
|
6771
|
+
error?: string;
|
|
6772
|
+
/** 1-based line number where the error occurred */
|
|
6773
|
+
errorLine?: number;
|
|
6774
|
+
/** 1-based column number where the error occurred */
|
|
6775
|
+
errorColumn?: number;
|
|
6776
|
+
/** Start byte offset of the error range */
|
|
6777
|
+
errorStart?: number;
|
|
6778
|
+
/** End byte offset of the error range (exclusive) */
|
|
6779
|
+
errorEnd?: number;
|
|
6780
|
+
}
|
|
6781
|
+
|
|
6705
6782
|
/**
|
|
6706
6783
|
* GenerateDateArray
|
|
6707
6784
|
*/
|
|
@@ -10227,6 +10304,21 @@ declare type Paren = {
|
|
|
10227
10304
|
*/
|
|
10228
10305
|
export declare function parse(sql: string, dialect?: Dialect): ParseResult;
|
|
10229
10306
|
|
|
10307
|
+
/**
|
|
10308
|
+
* Parse a standalone SQL data type.
|
|
10309
|
+
*
|
|
10310
|
+
* @param sql - The data type string to parse
|
|
10311
|
+
* @param dialect - The dialect to use
|
|
10312
|
+
* @returns The parsed DataType AST node
|
|
10313
|
+
*
|
|
10314
|
+
* @example
|
|
10315
|
+
* ```typescript
|
|
10316
|
+
* const result = parseDataType("DECIMAL(10, 2)", Dialect.DuckDB);
|
|
10317
|
+
* console.log(result.dataType);
|
|
10318
|
+
* ```
|
|
10319
|
+
*/
|
|
10320
|
+
export declare function parseDataType(sql: string, dialect?: Dialect): DataTypeResult;
|
|
10321
|
+
|
|
10230
10322
|
/**
|
|
10231
10323
|
* ParseDatetime
|
|
10232
10324
|
*/
|
|
@@ -10595,6 +10687,10 @@ export declare class Polyglot {
|
|
|
10595
10687
|
* Parse SQL into an AST.
|
|
10596
10688
|
*/
|
|
10597
10689
|
parse(sql: string, dialect?: Dialect): ParseResult;
|
|
10690
|
+
/**
|
|
10691
|
+
* Parse a standalone SQL data type.
|
|
10692
|
+
*/
|
|
10693
|
+
parseDataType(sql: string, dialect?: Dialect): DataTypeResult;
|
|
10598
10694
|
/**
|
|
10599
10695
|
* Tokenize SQL into a token stream.
|
|
10600
10696
|
*/
|
|
@@ -10603,6 +10699,10 @@ export declare class Polyglot {
|
|
|
10603
10699
|
* Generate SQL from an AST.
|
|
10604
10700
|
*/
|
|
10605
10701
|
generate(ast: any, dialect?: Dialect): TranspileResult;
|
|
10702
|
+
/**
|
|
10703
|
+
* Generate SQL from a standalone DataType AST node.
|
|
10704
|
+
*/
|
|
10705
|
+
generateDataType(dataType: DataType, dialect?: Dialect): GenerateDataTypeResult;
|
|
10606
10706
|
/**
|
|
10607
10707
|
* Format SQL.
|
|
10608
10708
|
*/
|
|
@@ -10624,6 +10724,11 @@ export declare class Polyglot {
|
|
|
10624
10724
|
* Parse SQL and annotate the AST with inferred type information.
|
|
10625
10725
|
*/
|
|
10626
10726
|
annotateTypes(sql: string, dialect?: Dialect, schema?: Schema): AnnotateTypesResult;
|
|
10727
|
+
/**
|
|
10728
|
+
* Return compact query analysis facts for a SELECT or set operation.
|
|
10729
|
+
*/
|
|
10730
|
+
analyzeQuery(sql: string, dialect: Dialect | string): QueryAnalysisResult;
|
|
10731
|
+
analyzeQuery(sql: string, options?: AnalyzeQueryOptions): QueryAnalysisResult;
|
|
10627
10732
|
}
|
|
10628
10733
|
|
|
10629
10734
|
/**
|
|
@@ -10759,6 +10864,17 @@ declare type ProjectionDef = {
|
|
|
10759
10864
|
expression: Expression;
|
|
10760
10865
|
};
|
|
10761
10866
|
|
|
10867
|
+
export declare interface ProjectionFact {
|
|
10868
|
+
index: number;
|
|
10869
|
+
name?: string;
|
|
10870
|
+
isStar: boolean;
|
|
10871
|
+
starTable?: string;
|
|
10872
|
+
transformKind: TransformKind;
|
|
10873
|
+
castType?: string;
|
|
10874
|
+
typeHint?: string;
|
|
10875
|
+
upstream: ColumnReferenceFact[];
|
|
10876
|
+
}
|
|
10877
|
+
|
|
10762
10878
|
/**
|
|
10763
10879
|
* Properties
|
|
10764
10880
|
*/
|
|
@@ -10887,6 +11003,23 @@ declare type Quantile = {
|
|
|
10887
11003
|
quantile: Expression | null;
|
|
10888
11004
|
};
|
|
10889
11005
|
|
|
11006
|
+
export declare interface QueryAnalysis {
|
|
11007
|
+
shape: QueryShape;
|
|
11008
|
+
ctes: string[];
|
|
11009
|
+
projections: ProjectionFact[];
|
|
11010
|
+
relations: RelationFact[];
|
|
11011
|
+
baseTables: RelationFact[];
|
|
11012
|
+
setOperations: SetOperationFact[];
|
|
11013
|
+
}
|
|
11014
|
+
|
|
11015
|
+
export declare interface QueryAnalysisResult {
|
|
11016
|
+
success: boolean;
|
|
11017
|
+
analysis?: QueryAnalysis;
|
|
11018
|
+
error?: string;
|
|
11019
|
+
}
|
|
11020
|
+
|
|
11021
|
+
export declare type QueryAnalysisSourceKind = 'root' | 'table' | 'derived_table' | 'cte' | 'virtual' | 'unknown';
|
|
11022
|
+
|
|
10890
11023
|
/**
|
|
10891
11024
|
* QueryBand
|
|
10892
11025
|
*/
|
|
@@ -10916,6 +11049,8 @@ export declare interface QueryPlan {
|
|
|
10916
11049
|
leaves: PlanStep[];
|
|
10917
11050
|
}
|
|
10918
11051
|
|
|
11052
|
+
export declare type QueryShape = 'select' | 'set_operation';
|
|
11053
|
+
|
|
10919
11054
|
/**
|
|
10920
11055
|
* QueryTransform
|
|
10921
11056
|
*/
|
|
@@ -11048,6 +11183,8 @@ declare type Reference = {
|
|
|
11048
11183
|
options: Array<Expression>;
|
|
11049
11184
|
};
|
|
11050
11185
|
|
|
11186
|
+
export declare type ReferenceConfidence = 'resolved' | 'ambiguous' | 'unknown';
|
|
11187
|
+
|
|
11051
11188
|
/**
|
|
11052
11189
|
* Union of all reference expression types (identifiers, columns, tables)
|
|
11053
11190
|
*/
|
|
@@ -11271,6 +11408,13 @@ declare type RegrValy = {
|
|
|
11271
11408
|
expression: Expression;
|
|
11272
11409
|
};
|
|
11273
11410
|
|
|
11411
|
+
export declare interface RelationFact {
|
|
11412
|
+
name: string;
|
|
11413
|
+
alias?: string;
|
|
11414
|
+
kind: QueryAnalysisSourceKind;
|
|
11415
|
+
columns: string[];
|
|
11416
|
+
}
|
|
11417
|
+
|
|
11274
11418
|
/**
|
|
11275
11419
|
* RemoteWithConnectionModelProperty
|
|
11276
11420
|
*/
|
|
@@ -12141,11 +12285,24 @@ declare type SetOperation = {
|
|
|
12141
12285
|
on: Expression | null;
|
|
12142
12286
|
};
|
|
12143
12287
|
|
|
12288
|
+
export declare interface SetOperationBranchFact {
|
|
12289
|
+
index: number;
|
|
12290
|
+
projections: ProjectionFact[];
|
|
12291
|
+
}
|
|
12292
|
+
|
|
12144
12293
|
/**
|
|
12145
12294
|
* Union of all set operation expression types
|
|
12146
12295
|
*/
|
|
12147
12296
|
declare type SetOperationExpression = ExpressionByType<'union'> | ExpressionByType<'intersect'> | ExpressionByType<'except'>;
|
|
12148
12297
|
|
|
12298
|
+
export declare interface SetOperationFact {
|
|
12299
|
+
kind: 'union' | 'intersect' | 'except' | string;
|
|
12300
|
+
all: boolean;
|
|
12301
|
+
distinct: boolean;
|
|
12302
|
+
outputColumns: string[];
|
|
12303
|
+
branches: SetOperationBranchFact[];
|
|
12304
|
+
}
|
|
12305
|
+
|
|
12149
12306
|
export declare type SetOperationType = 'union' | 'union_all' | 'intersect' | 'except';
|
|
12150
12307
|
|
|
12151
12308
|
/**
|
|
@@ -13561,6 +13718,8 @@ declare type TransformFunc = {
|
|
|
13561
13718
|
transform: Expression;
|
|
13562
13719
|
};
|
|
13563
13720
|
|
|
13721
|
+
export declare type TransformKind = 'direct' | 'cast' | 'aggregation' | 'constant' | 'expression' | 'star';
|
|
13722
|
+
|
|
13564
13723
|
/**
|
|
13565
13724
|
* TransformModelProperty
|
|
13566
13725
|
*/
|