@polyglot-sql/sdk 0.1.8 → 0.1.10
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 +110 -2
- package/dist/cdn/polyglot.esm.js +2108 -2009
- package/dist/index.cjs +5375 -0
- package/dist/index.d.cts +14760 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +177 -4
- package/dist/polyglot_sql_wasm_bg.wasm +0 -0
- package/package.json +10 -5
package/dist/index.d.ts
CHANGED
|
@@ -1524,6 +1524,10 @@ declare type Column = {
|
|
|
1524
1524
|
* Trailing comments that appeared after this column reference
|
|
1525
1525
|
*/
|
|
1526
1526
|
trailing_comments: Array<string>;
|
|
1527
|
+
/**
|
|
1528
|
+
* Source position span
|
|
1529
|
+
*/
|
|
1530
|
+
span?: Span | null;
|
|
1527
1531
|
};
|
|
1528
1532
|
|
|
1529
1533
|
/**
|
|
@@ -3131,6 +3135,7 @@ declare const _default: {
|
|
|
3131
3135
|
isInitialized: typeof isInitialized;
|
|
3132
3136
|
transpile: typeof transpile;
|
|
3133
3137
|
parse: typeof parse;
|
|
3138
|
+
tokenize: typeof tokenize;
|
|
3134
3139
|
generate: typeof generate;
|
|
3135
3140
|
format: typeof format;
|
|
3136
3141
|
getDialects: typeof getDialects;
|
|
@@ -6089,6 +6094,20 @@ declare type Format = {
|
|
|
6089
6094
|
*/
|
|
6090
6095
|
export declare function format(sql: string, dialect?: Dialect): TranspileResult;
|
|
6091
6096
|
|
|
6097
|
+
/**
|
|
6098
|
+
* Guard options for formatting very large/complex SQL safely.
|
|
6099
|
+
*/
|
|
6100
|
+
export declare interface FormatOptions {
|
|
6101
|
+
/** Maximum SQL input size in bytes */
|
|
6102
|
+
maxInputBytes?: number;
|
|
6103
|
+
/** Maximum token count after tokenization */
|
|
6104
|
+
maxTokens?: number;
|
|
6105
|
+
/** Maximum AST node count after parsing */
|
|
6106
|
+
maxAstNodes?: number;
|
|
6107
|
+
/** Maximum set-operation count (UNION/INTERSECT/EXCEPT) before parse */
|
|
6108
|
+
maxSetOpChain?: number;
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6092
6111
|
/**
|
|
6093
6112
|
* Format override for a column in Teradata
|
|
6094
6113
|
*/
|
|
@@ -6097,6 +6116,13 @@ declare type FormatPhrase = {
|
|
|
6097
6116
|
format: string;
|
|
6098
6117
|
};
|
|
6099
6118
|
|
|
6119
|
+
/**
|
|
6120
|
+
* Format/pretty-print SQL with explicit guard limits.
|
|
6121
|
+
*
|
|
6122
|
+
* This can be used to tune handling for very large SQL inputs.
|
|
6123
|
+
*/
|
|
6124
|
+
export declare function formatWithOptions(sql: string, dialect?: Dialect, options?: FormatOptions): TranspileResult;
|
|
6125
|
+
|
|
6100
6126
|
/**
|
|
6101
6127
|
* FreespaceProperty
|
|
6102
6128
|
*/
|
|
@@ -6179,6 +6205,10 @@ declare type Function_2 = {
|
|
|
6179
6205
|
* Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
|
|
6180
6206
|
*/
|
|
6181
6207
|
quoted: boolean;
|
|
6208
|
+
/**
|
|
6209
|
+
* Source position span
|
|
6210
|
+
*/
|
|
6211
|
+
span?: Span | null;
|
|
6182
6212
|
};
|
|
6183
6213
|
|
|
6184
6214
|
/**
|
|
@@ -6841,6 +6871,10 @@ declare type Identifier = {
|
|
|
6841
6871
|
*/
|
|
6842
6872
|
quoted: boolean;
|
|
6843
6873
|
trailing_comments: Array<string>;
|
|
6874
|
+
/**
|
|
6875
|
+
* Source position span (populated during parsing, None for programmatically constructed nodes)
|
|
6876
|
+
*/
|
|
6877
|
+
span?: Span | null;
|
|
6844
6878
|
};
|
|
6845
6879
|
|
|
6846
6880
|
/**
|
|
@@ -9709,6 +9743,10 @@ export declare interface ParseResult {
|
|
|
9709
9743
|
errorLine?: number;
|
|
9710
9744
|
/** 1-based column number where the error occurred */
|
|
9711
9745
|
errorColumn?: number;
|
|
9746
|
+
/** Start byte offset of the error range */
|
|
9747
|
+
errorStart?: number;
|
|
9748
|
+
/** End byte offset of the error range (exclusive) */
|
|
9749
|
+
errorEnd?: number;
|
|
9712
9750
|
}
|
|
9713
9751
|
|
|
9714
9752
|
/**
|
|
@@ -10028,6 +10066,10 @@ export declare class Polyglot {
|
|
|
10028
10066
|
* Parse SQL into an AST.
|
|
10029
10067
|
*/
|
|
10030
10068
|
parse(sql: string, dialect?: Dialect): ParseResult;
|
|
10069
|
+
/**
|
|
10070
|
+
* Tokenize SQL into a token stream.
|
|
10071
|
+
*/
|
|
10072
|
+
tokenize(sql: string, dialect?: Dialect): TokenizeResult;
|
|
10031
10073
|
/**
|
|
10032
10074
|
* Generate SQL from an AST.
|
|
10033
10075
|
*/
|
|
@@ -10036,6 +10078,10 @@ export declare class Polyglot {
|
|
|
10036
10078
|
* Format SQL.
|
|
10037
10079
|
*/
|
|
10038
10080
|
format(sql: string, dialect?: Dialect): TranspileResult;
|
|
10081
|
+
/**
|
|
10082
|
+
* Format SQL with explicit guard limits.
|
|
10083
|
+
*/
|
|
10084
|
+
formatWithOptions(sql: string, dialect?: Dialect, options?: FormatOptions): TranspileResult;
|
|
10039
10085
|
/**
|
|
10040
10086
|
* Get supported dialects in this build.
|
|
10041
10087
|
* Per-dialect builds return only `"generic"` and the selected dialect.
|
|
@@ -11690,6 +11736,38 @@ export declare interface SourceTablesResult {
|
|
|
11690
11736
|
error?: string;
|
|
11691
11737
|
}
|
|
11692
11738
|
|
|
11739
|
+
/**
|
|
11740
|
+
* Represents a position in the source SQL
|
|
11741
|
+
*/
|
|
11742
|
+
declare type Span = {
|
|
11743
|
+
/**
|
|
11744
|
+
* Starting byte offset
|
|
11745
|
+
*/
|
|
11746
|
+
start: number;
|
|
11747
|
+
/**
|
|
11748
|
+
* Ending byte offset (exclusive)
|
|
11749
|
+
*/
|
|
11750
|
+
end: number;
|
|
11751
|
+
/**
|
|
11752
|
+
* Line number (1-based)
|
|
11753
|
+
*/
|
|
11754
|
+
line: number;
|
|
11755
|
+
/**
|
|
11756
|
+
* Column number (1-based)
|
|
11757
|
+
*/
|
|
11758
|
+
column: number;
|
|
11759
|
+
};
|
|
11760
|
+
|
|
11761
|
+
/**
|
|
11762
|
+
* Span information for a token, indicating its position in the source SQL.
|
|
11763
|
+
*/
|
|
11764
|
+
export declare interface SpanInfo {
|
|
11765
|
+
start: number;
|
|
11766
|
+
end: number;
|
|
11767
|
+
line: number;
|
|
11768
|
+
column: number;
|
|
11769
|
+
}
|
|
11770
|
+
|
|
11693
11771
|
/**
|
|
11694
11772
|
* SPLIT function
|
|
11695
11773
|
*/
|
|
@@ -11817,6 +11895,10 @@ declare type Star = {
|
|
|
11817
11895
|
* Trailing comments that appeared after the star
|
|
11818
11896
|
*/
|
|
11819
11897
|
trailing_comments?: Array<string>;
|
|
11898
|
+
/**
|
|
11899
|
+
* Source position span
|
|
11900
|
+
*/
|
|
11901
|
+
span?: Span | null;
|
|
11820
11902
|
};
|
|
11821
11903
|
|
|
11822
11904
|
/** Create a star (*) expression. */
|
|
@@ -12396,6 +12478,10 @@ declare type TableRef = {
|
|
|
12396
12478
|
* Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
|
|
12397
12479
|
*/
|
|
12398
12480
|
version?: Version | null;
|
|
12481
|
+
/**
|
|
12482
|
+
* Source position span
|
|
12483
|
+
*/
|
|
12484
|
+
span?: Span | null;
|
|
12399
12485
|
};
|
|
12400
12486
|
|
|
12401
12487
|
/**
|
|
@@ -12686,6 +12772,53 @@ declare type ToFile = {
|
|
|
12686
12772
|
safe: Expression | null;
|
|
12687
12773
|
};
|
|
12688
12774
|
|
|
12775
|
+
/**
|
|
12776
|
+
* A single token from the SQL token stream.
|
|
12777
|
+
*/
|
|
12778
|
+
export declare interface TokenInfo {
|
|
12779
|
+
tokenType: string;
|
|
12780
|
+
text: string;
|
|
12781
|
+
span: SpanInfo;
|
|
12782
|
+
comments: string[];
|
|
12783
|
+
trailingComments: string[];
|
|
12784
|
+
}
|
|
12785
|
+
|
|
12786
|
+
/**
|
|
12787
|
+
* Tokenize SQL into a token stream.
|
|
12788
|
+
*
|
|
12789
|
+
* @param sql - The SQL string to tokenize
|
|
12790
|
+
* @param dialect - The dialect to use for tokenization
|
|
12791
|
+
* @returns The token stream
|
|
12792
|
+
*
|
|
12793
|
+
* @example
|
|
12794
|
+
* ```typescript
|
|
12795
|
+
* const result = tokenize("SELECT a, b FROM t", Dialect.PostgreSQL);
|
|
12796
|
+
* if (result.success) {
|
|
12797
|
+
* for (const token of result.tokens!) {
|
|
12798
|
+
* console.log(token.tokenType, token.text, token.span);
|
|
12799
|
+
* }
|
|
12800
|
+
* }
|
|
12801
|
+
* ```
|
|
12802
|
+
*/
|
|
12803
|
+
export declare function tokenize(sql: string, dialect?: Dialect): TokenizeResult;
|
|
12804
|
+
|
|
12805
|
+
/**
|
|
12806
|
+
* Result of a tokenize operation
|
|
12807
|
+
*/
|
|
12808
|
+
export declare interface TokenizeResult {
|
|
12809
|
+
success: boolean;
|
|
12810
|
+
tokens?: TokenInfo[];
|
|
12811
|
+
error?: string;
|
|
12812
|
+
/** 1-based line number where the error occurred */
|
|
12813
|
+
errorLine?: number;
|
|
12814
|
+
/** 1-based column number where the error occurred */
|
|
12815
|
+
errorColumn?: number;
|
|
12816
|
+
/** Start byte offset of the error range */
|
|
12817
|
+
errorStart?: number;
|
|
12818
|
+
/** End byte offset of the error range (exclusive) */
|
|
12819
|
+
errorEnd?: number;
|
|
12820
|
+
}
|
|
12821
|
+
|
|
12689
12822
|
/**
|
|
12690
12823
|
* ToMap - Materialize-style map constructor
|
|
12691
12824
|
* Can hold either:
|
|
@@ -12874,6 +13007,10 @@ export declare interface TranspileResult {
|
|
|
12874
13007
|
errorLine?: number;
|
|
12875
13008
|
/** 1-based column number where the error occurred */
|
|
12876
13009
|
errorColumn?: number;
|
|
13010
|
+
/** Start byte offset of the error range */
|
|
13011
|
+
errorStart?: number;
|
|
13012
|
+
/** End byte offset of the error range (exclusive) */
|
|
13013
|
+
errorEnd?: number;
|
|
12877
13014
|
}
|
|
12878
13015
|
|
|
12879
13016
|
/**
|
|
@@ -13561,6 +13698,10 @@ export declare interface ValidationError {
|
|
|
13561
13698
|
severity: ValidationSeverity;
|
|
13562
13699
|
/** Error code (e.g., "E001", "W001") */
|
|
13563
13700
|
code: string;
|
|
13701
|
+
/** Start byte offset of the error range */
|
|
13702
|
+
start?: number;
|
|
13703
|
+
/** End byte offset of the error range (exclusive) */
|
|
13704
|
+
end?: number;
|
|
13564
13705
|
}
|
|
13565
13706
|
|
|
13566
13707
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2055,6 +2055,52 @@ function format_sql_value$1(sql, dialect) {
|
|
|
2055
2055
|
return takeObject(ret);
|
|
2056
2056
|
}
|
|
2057
2057
|
|
|
2058
|
+
/**
|
|
2059
|
+
* Format SQL with explicit guard options supplied as JSON.
|
|
2060
|
+
* @param {string} sql
|
|
2061
|
+
* @param {string} dialect
|
|
2062
|
+
* @param {string} options_json
|
|
2063
|
+
* @returns {string}
|
|
2064
|
+
*/
|
|
2065
|
+
function format_sql_with_options$1(sql, dialect, options_json) {
|
|
2066
|
+
let deferred4_0;
|
|
2067
|
+
let deferred4_1;
|
|
2068
|
+
try {
|
|
2069
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
2070
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2071
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2072
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2073
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2074
|
+
const ptr2 = passStringToWasm0(options_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2075
|
+
const len2 = WASM_VECTOR_LEN;
|
|
2076
|
+
wasm$3.format_sql_with_options(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
2077
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2078
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2079
|
+
deferred4_0 = r0;
|
|
2080
|
+
deferred4_1 = r1;
|
|
2081
|
+
return getStringFromWasm0(r0, r1);
|
|
2082
|
+
} finally {
|
|
2083
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
2084
|
+
wasm$3.__wbindgen_export4(deferred4_0, deferred4_1, 1);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* Format SQL with explicit guard options supplied as a JS object.
|
|
2090
|
+
* @param {string} sql
|
|
2091
|
+
* @param {string} dialect
|
|
2092
|
+
* @param {any} options
|
|
2093
|
+
* @returns {any}
|
|
2094
|
+
*/
|
|
2095
|
+
function format_sql_with_options_value$1(sql, dialect, options) {
|
|
2096
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2097
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2098
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2099
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2100
|
+
const ret = wasm$3.format_sql_with_options_value(ptr0, len0, ptr1, len1, addHeapObject(options));
|
|
2101
|
+
return takeObject(ret);
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2058
2104
|
/**
|
|
2059
2105
|
* Generate SQL from an AST (provided as JSON).
|
|
2060
2106
|
*
|
|
@@ -2296,6 +2342,55 @@ function source_tables$1(sql, column, dialect) {
|
|
|
2296
2342
|
}
|
|
2297
2343
|
}
|
|
2298
2344
|
|
|
2345
|
+
/**
|
|
2346
|
+
* Tokenize SQL into a token stream (returned as JSON).
|
|
2347
|
+
*
|
|
2348
|
+
* # Arguments
|
|
2349
|
+
* * `sql` - The SQL string to tokenize
|
|
2350
|
+
* * `dialect` - The dialect to use for tokenization
|
|
2351
|
+
*
|
|
2352
|
+
* # Returns
|
|
2353
|
+
* A JSON string containing the TokenizeResult
|
|
2354
|
+
* @param {string} sql
|
|
2355
|
+
* @param {string} dialect
|
|
2356
|
+
* @returns {string}
|
|
2357
|
+
*/
|
|
2358
|
+
function tokenize$2(sql, dialect) {
|
|
2359
|
+
let deferred3_0;
|
|
2360
|
+
let deferred3_1;
|
|
2361
|
+
try {
|
|
2362
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
2363
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2364
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2365
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2366
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2367
|
+
wasm$3.tokenize(retptr, ptr0, len0, ptr1, len1);
|
|
2368
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2369
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2370
|
+
deferred3_0 = r0;
|
|
2371
|
+
deferred3_1 = r1;
|
|
2372
|
+
return getStringFromWasm0(r0, r1);
|
|
2373
|
+
} finally {
|
|
2374
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
2375
|
+
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
/**
|
|
2380
|
+
* Tokenize SQL and return a structured JS object.
|
|
2381
|
+
* @param {string} sql
|
|
2382
|
+
* @param {string} dialect
|
|
2383
|
+
* @returns {any}
|
|
2384
|
+
*/
|
|
2385
|
+
function tokenize_value$1(sql, dialect) {
|
|
2386
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2387
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2388
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2389
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2390
|
+
const ret = wasm$3.tokenize_value(ptr0, len0, ptr1, len1);
|
|
2391
|
+
return takeObject(ret);
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2299
2394
|
/**
|
|
2300
2395
|
* Transpile SQL from one dialect to another.
|
|
2301
2396
|
*
|
|
@@ -3302,6 +3397,8 @@ const ast_set_limit = __vite__wasmModule.ast_set_limit;
|
|
|
3302
3397
|
const diff_sql = __vite__wasmModule.diff_sql;
|
|
3303
3398
|
const format_sql = __vite__wasmModule.format_sql;
|
|
3304
3399
|
const format_sql_value = __vite__wasmModule.format_sql_value;
|
|
3400
|
+
const format_sql_with_options = __vite__wasmModule.format_sql_with_options;
|
|
3401
|
+
const format_sql_with_options_value = __vite__wasmModule.format_sql_with_options_value;
|
|
3305
3402
|
const generate$1 = __vite__wasmModule.generate;
|
|
3306
3403
|
const generate_value = __vite__wasmModule.generate_value;
|
|
3307
3404
|
const get_dialects = __vite__wasmModule.get_dialects;
|
|
@@ -3311,6 +3408,8 @@ const parse$1 = __vite__wasmModule.parse;
|
|
|
3311
3408
|
const parse_value = __vite__wasmModule.parse_value;
|
|
3312
3409
|
const plan$1 = __vite__wasmModule.plan;
|
|
3313
3410
|
const source_tables = __vite__wasmModule.source_tables;
|
|
3411
|
+
const tokenize$1 = __vite__wasmModule.tokenize;
|
|
3412
|
+
const tokenize_value = __vite__wasmModule.tokenize_value;
|
|
3314
3413
|
const transpile$1 = __vite__wasmModule.transpile;
|
|
3315
3414
|
const transpile_value = __vite__wasmModule.transpile_value;
|
|
3316
3415
|
const validate$1 = __vite__wasmModule.validate;
|
|
@@ -3484,6 +3583,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
3484
3583
|
diff_sql,
|
|
3485
3584
|
format_sql,
|
|
3486
3585
|
format_sql_value,
|
|
3586
|
+
format_sql_with_options,
|
|
3587
|
+
format_sql_with_options_value,
|
|
3487
3588
|
generate: generate$1,
|
|
3488
3589
|
generate_value,
|
|
3489
3590
|
get_dialects,
|
|
@@ -3494,6 +3595,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
3494
3595
|
parse_value,
|
|
3495
3596
|
plan: plan$1,
|
|
3496
3597
|
source_tables,
|
|
3598
|
+
tokenize: tokenize$1,
|
|
3599
|
+
tokenize_value,
|
|
3497
3600
|
transpile: transpile$1,
|
|
3498
3601
|
transpile_value,
|
|
3499
3602
|
validate: validate$1,
|
|
@@ -3662,6 +3765,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
|
|
|
3662
3765
|
diff_sql: diff_sql$1,
|
|
3663
3766
|
format_sql: format_sql$1,
|
|
3664
3767
|
format_sql_value: format_sql_value$1,
|
|
3768
|
+
format_sql_with_options: format_sql_with_options$1,
|
|
3769
|
+
format_sql_with_options_value: format_sql_with_options_value$1,
|
|
3665
3770
|
generate: generate$2,
|
|
3666
3771
|
generate_value: generate_value$1,
|
|
3667
3772
|
get_dialects: get_dialects$1,
|
|
@@ -3671,6 +3776,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
|
|
|
3671
3776
|
parse_value: parse_value$1,
|
|
3672
3777
|
plan: plan$2,
|
|
3673
3778
|
source_tables: source_tables$1,
|
|
3779
|
+
tokenize: tokenize$2,
|
|
3780
|
+
tokenize_value: tokenize_value$1,
|
|
3674
3781
|
transpile: transpile$2,
|
|
3675
3782
|
transpile_value: transpile_value$1,
|
|
3676
3783
|
validate: validate$2,
|
|
@@ -5134,10 +5241,16 @@ function validateSelect(select, _options) {
|
|
|
5134
5241
|
const errors = [];
|
|
5135
5242
|
const stars = findByType(select, "star");
|
|
5136
5243
|
if (stars.length > 0) {
|
|
5244
|
+
const starData = getExprData(stars[0]);
|
|
5245
|
+
const span = starData?.span;
|
|
5137
5246
|
errors.push({
|
|
5138
5247
|
message: "SELECT * is discouraged; specify columns explicitly for better performance and maintainability",
|
|
5139
5248
|
severity: "warning",
|
|
5140
|
-
code: "W001"
|
|
5249
|
+
code: "W001",
|
|
5250
|
+
line: span?.line,
|
|
5251
|
+
column: span?.column,
|
|
5252
|
+
start: span?.start,
|
|
5253
|
+
end: span?.end
|
|
5141
5254
|
});
|
|
5142
5255
|
}
|
|
5143
5256
|
const selectData = getExprData(select);
|
|
@@ -5153,10 +5266,22 @@ function validateSelect(select, _options) {
|
|
|
5153
5266
|
return false;
|
|
5154
5267
|
});
|
|
5155
5268
|
if (hasNonAggregateColumn && aggregateFunctions.length > 0) {
|
|
5269
|
+
const firstNonAgg = selectCols.find((col) => {
|
|
5270
|
+
const colType = getExprType(col);
|
|
5271
|
+
if (colType === "column" || colType === "identifier") {
|
|
5272
|
+
return getAggregateFunctions(col).length === 0;
|
|
5273
|
+
}
|
|
5274
|
+
return false;
|
|
5275
|
+
});
|
|
5276
|
+
const colSpan = firstNonAgg ? getExprData(firstNonAgg)?.span : void 0;
|
|
5156
5277
|
errors.push({
|
|
5157
5278
|
message: "Mixing aggregate functions with non-aggregated columns without GROUP BY may cause errors in strict SQL mode",
|
|
5158
5279
|
severity: "warning",
|
|
5159
|
-
code: "W002"
|
|
5280
|
+
code: "W002",
|
|
5281
|
+
line: colSpan?.line,
|
|
5282
|
+
column: colSpan?.column,
|
|
5283
|
+
start: colSpan?.start,
|
|
5284
|
+
end: colSpan?.end
|
|
5160
5285
|
});
|
|
5161
5286
|
}
|
|
5162
5287
|
}
|
|
@@ -5168,10 +5293,16 @@ function validateSelect(select, _options) {
|
|
|
5168
5293
|
});
|
|
5169
5294
|
}
|
|
5170
5295
|
if (selectData.limit && !selectData.order_by) {
|
|
5296
|
+
const limitExpr = selectData.limit;
|
|
5297
|
+
const limitSpan = limitExpr ? getExprData(limitExpr)?.span : void 0;
|
|
5171
5298
|
errors.push({
|
|
5172
5299
|
message: "LIMIT without ORDER BY produces non-deterministic results",
|
|
5173
5300
|
severity: "warning",
|
|
5174
|
-
code: "W004"
|
|
5301
|
+
code: "W004",
|
|
5302
|
+
line: limitSpan?.line,
|
|
5303
|
+
column: limitSpan?.column,
|
|
5304
|
+
start: limitSpan?.start,
|
|
5305
|
+
end: limitSpan?.end
|
|
5175
5306
|
});
|
|
5176
5307
|
}
|
|
5177
5308
|
return errors;
|
|
@@ -5383,6 +5514,22 @@ function parse(sql, dialect = "generic" /* Generic */) {
|
|
|
5383
5514
|
return parseFailure("parse", error);
|
|
5384
5515
|
}
|
|
5385
5516
|
}
|
|
5517
|
+
function tokenize(sql, dialect = "generic" /* Generic */) {
|
|
5518
|
+
try {
|
|
5519
|
+
if (typeof wasm.tokenize_value === "function") {
|
|
5520
|
+
return decodeWasmPayload(
|
|
5521
|
+
wasm.tokenize_value(sql, dialect)
|
|
5522
|
+
);
|
|
5523
|
+
}
|
|
5524
|
+
return JSON.parse(wasm.tokenize(sql, dialect));
|
|
5525
|
+
} catch (error) {
|
|
5526
|
+
return {
|
|
5527
|
+
success: false,
|
|
5528
|
+
tokens: void 0,
|
|
5529
|
+
error: `WASM tokenize failed: ${errorMessage(error)}`
|
|
5530
|
+
};
|
|
5531
|
+
}
|
|
5532
|
+
}
|
|
5386
5533
|
function generate(ast2, dialect = "generic" /* Generic */) {
|
|
5387
5534
|
try {
|
|
5388
5535
|
if (typeof wasm.generate_value === "function" && Array.isArray(ast2)) {
|
|
@@ -5397,7 +5544,20 @@ function generate(ast2, dialect = "generic" /* Generic */) {
|
|
|
5397
5544
|
}
|
|
5398
5545
|
}
|
|
5399
5546
|
function format(sql, dialect = "generic" /* Generic */) {
|
|
5547
|
+
return formatWithOptions(sql, dialect, {});
|
|
5548
|
+
}
|
|
5549
|
+
function formatWithOptions(sql, dialect = "generic" /* Generic */, options = {}) {
|
|
5400
5550
|
try {
|
|
5551
|
+
if (typeof wasm.format_sql_with_options_value === "function") {
|
|
5552
|
+
return decodeWasmPayload(
|
|
5553
|
+
wasm.format_sql_with_options_value(sql, dialect, options)
|
|
5554
|
+
);
|
|
5555
|
+
}
|
|
5556
|
+
if (typeof wasm.format_sql_with_options === "function") {
|
|
5557
|
+
return JSON.parse(
|
|
5558
|
+
wasm.format_sql_with_options(sql, dialect, JSON.stringify(options))
|
|
5559
|
+
);
|
|
5560
|
+
}
|
|
5401
5561
|
if (typeof wasm.format_sql_value === "function") {
|
|
5402
5562
|
return decodeWasmPayload(
|
|
5403
5563
|
wasm.format_sql_value(sql, dialect)
|
|
@@ -5447,6 +5607,12 @@ class Polyglot {
|
|
|
5447
5607
|
parse(sql, dialect = "generic" /* Generic */) {
|
|
5448
5608
|
return parse(sql, dialect);
|
|
5449
5609
|
}
|
|
5610
|
+
/**
|
|
5611
|
+
* Tokenize SQL into a token stream.
|
|
5612
|
+
*/
|
|
5613
|
+
tokenize(sql, dialect = "generic" /* Generic */) {
|
|
5614
|
+
return tokenize(sql, dialect);
|
|
5615
|
+
}
|
|
5450
5616
|
/**
|
|
5451
5617
|
* Generate SQL from an AST.
|
|
5452
5618
|
*/
|
|
@@ -5459,6 +5625,12 @@ class Polyglot {
|
|
|
5459
5625
|
format(sql, dialect = "generic" /* Generic */) {
|
|
5460
5626
|
return format(sql, dialect);
|
|
5461
5627
|
}
|
|
5628
|
+
/**
|
|
5629
|
+
* Format SQL with explicit guard limits.
|
|
5630
|
+
*/
|
|
5631
|
+
formatWithOptions(sql, dialect = "generic" /* Generic */, options = {}) {
|
|
5632
|
+
return formatWithOptions(sql, dialect, options);
|
|
5633
|
+
}
|
|
5462
5634
|
/**
|
|
5463
5635
|
* Get supported dialects in this build.
|
|
5464
5636
|
* Per-dialect builds return only `"generic"` and the selected dialect.
|
|
@@ -5478,6 +5650,7 @@ const index = {
|
|
|
5478
5650
|
isInitialized,
|
|
5479
5651
|
transpile,
|
|
5480
5652
|
parse,
|
|
5653
|
+
tokenize,
|
|
5481
5654
|
generate,
|
|
5482
5655
|
format,
|
|
5483
5656
|
getDialects,
|
|
@@ -5492,4 +5665,4 @@ const index = {
|
|
|
5492
5665
|
Polyglot
|
|
5493
5666
|
};
|
|
5494
5667
|
|
|
5495
|
-
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, 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, transform, transpile, trim, union, unionAll, update, upper, validate, validateWithSchema, walk };
|
|
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 };
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyglot-sql/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "SQL dialect translator powered by WebAssembly",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"unpkg": "./dist/cdn/polyglot.esm.js",
|
|
10
10
|
"jsdelivr": "./dist/cdn/polyglot.esm.js",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"types":
|
|
14
|
-
|
|
13
|
+
"types": {
|
|
14
|
+
"import": "./dist/index.d.ts",
|
|
15
|
+
"require": "./dist/index.d.cts"
|
|
16
|
+
},
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
15
19
|
},
|
|
16
20
|
"./cdn": {
|
|
17
21
|
"types": "./dist/index.d.ts",
|
|
@@ -62,10 +66,11 @@
|
|
|
62
66
|
"build:bindings": "cd ../.. && make generate-bindings",
|
|
63
67
|
"build:wasm": "cd ../../crates/polyglot-sql-wasm && wasm-pack build --target bundler --release --out-dir ../../packages/sdk/wasm",
|
|
64
68
|
"build:esm": "vite build",
|
|
69
|
+
"build:cjs": "vite build --config vite.config.cjs.ts && cp dist/index.d.ts dist/index.d.cts",
|
|
65
70
|
"build:umd": "vite build --config vite.config.umd.ts",
|
|
66
71
|
"build:dialect": "vite build --config vite.config.dialect.ts",
|
|
67
72
|
"build:dialects": "for d in postgresql mysql bigquery snowflake duckdb tsql clickhouse; do POLYGLOT_DIALECT=$d pnpm run build:dialect; done",
|
|
68
|
-
"build": "pnpm run build:esm && pnpm run build:umd",
|
|
73
|
+
"build": "pnpm run build:esm && pnpm run build:cjs && pnpm run build:umd",
|
|
69
74
|
"build:all": "pnpm run build && pnpm run build:dialects",
|
|
70
75
|
"test": "vitest run",
|
|
71
76
|
"test:watch": "vitest",
|