@polyglot-sql/sdk 0.1.9 → 0.1.11
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 +88 -3
- package/dist/cdn/polyglot.esm.js +2066 -1976
- package/dist/index.cjs +5415 -0
- package/dist/index.d.cts +14807 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.js +164 -4
- package/dist/polyglot_sql_wasm_bg.wasm +0 -0
- package/package.json +11 -5
package/dist/index.d.ts
CHANGED
|
@@ -1465,6 +1465,13 @@ declare type ClusterBy = {
|
|
|
1465
1465
|
expressions: Array<Ordered>;
|
|
1466
1466
|
};
|
|
1467
1467
|
|
|
1468
|
+
/**
|
|
1469
|
+
* BigQuery CLUSTER BY property in CREATE TABLE statements.
|
|
1470
|
+
*/
|
|
1471
|
+
declare type ClusterByColumnsProperty = {
|
|
1472
|
+
columns: Array<Identifier>;
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1468
1475
|
/**
|
|
1469
1476
|
* ClusteredByProperty
|
|
1470
1477
|
*/
|
|
@@ -1524,6 +1531,10 @@ declare type Column = {
|
|
|
1524
1531
|
* Trailing comments that appeared after this column reference
|
|
1525
1532
|
*/
|
|
1526
1533
|
trailing_comments: Array<string>;
|
|
1534
|
+
/**
|
|
1535
|
+
* Source position span
|
|
1536
|
+
*/
|
|
1537
|
+
span?: Span | null;
|
|
1527
1538
|
};
|
|
1528
1539
|
|
|
1529
1540
|
/**
|
|
@@ -3131,11 +3142,13 @@ declare const _default: {
|
|
|
3131
3142
|
isInitialized: typeof isInitialized;
|
|
3132
3143
|
transpile: typeof transpile;
|
|
3133
3144
|
parse: typeof parse;
|
|
3145
|
+
tokenize: typeof tokenize;
|
|
3134
3146
|
generate: typeof generate;
|
|
3135
3147
|
format: typeof format;
|
|
3136
3148
|
getDialects: typeof getDialects;
|
|
3137
3149
|
getVersion: typeof getVersion;
|
|
3138
3150
|
lineage: typeof lineage;
|
|
3151
|
+
lineageWithSchema: typeof lineageWithSchema;
|
|
3139
3152
|
getSourceTables: typeof getSourceTables;
|
|
3140
3153
|
diff: typeof diff;
|
|
3141
3154
|
hasChanges: typeof hasChanges;
|
|
@@ -5087,8 +5100,12 @@ declare type Expression = {
|
|
|
5087
5100
|
"on_commit_property": OnCommitProperty;
|
|
5088
5101
|
} | {
|
|
5089
5102
|
"partitioned_by_property": PartitionedByProperty;
|
|
5103
|
+
} | {
|
|
5104
|
+
"partition_by_property": PartitionByProperty;
|
|
5090
5105
|
} | {
|
|
5091
5106
|
"partitioned_by_bucket": PartitionedByBucket;
|
|
5107
|
+
} | {
|
|
5108
|
+
"cluster_by_columns_property": ClusterByColumnsProperty;
|
|
5092
5109
|
} | {
|
|
5093
5110
|
"partition_by_truncate": PartitionByTruncate;
|
|
5094
5111
|
} | {
|
|
@@ -5181,6 +5198,8 @@ declare type Expression = {
|
|
|
5181
5198
|
"include_property": IncludeProperty;
|
|
5182
5199
|
} | {
|
|
5183
5200
|
"properties": Properties;
|
|
5201
|
+
} | {
|
|
5202
|
+
"options_property": OptionsProperty;
|
|
5184
5203
|
} | {
|
|
5185
5204
|
"input_output_format": InputOutputFormat;
|
|
5186
5205
|
} | {
|
|
@@ -6200,6 +6219,10 @@ declare type Function_2 = {
|
|
|
6200
6219
|
* Whether the function name was quoted (e.g., `p.d.UdF` in BigQuery)
|
|
6201
6220
|
*/
|
|
6202
6221
|
quoted: boolean;
|
|
6222
|
+
/**
|
|
6223
|
+
* Source position span
|
|
6224
|
+
*/
|
|
6225
|
+
span?: Span | null;
|
|
6203
6226
|
};
|
|
6204
6227
|
|
|
6205
6228
|
/**
|
|
@@ -6862,6 +6885,10 @@ declare type Identifier = {
|
|
|
6862
6885
|
*/
|
|
6863
6886
|
quoted: boolean;
|
|
6864
6887
|
trailing_comments: Array<string>;
|
|
6888
|
+
/**
|
|
6889
|
+
* Source position span (populated during parsing, None for programmatically constructed nodes)
|
|
6890
|
+
*/
|
|
6891
|
+
span?: Span | null;
|
|
6865
6892
|
};
|
|
6866
6893
|
|
|
6867
6894
|
/**
|
|
@@ -8584,6 +8611,17 @@ export declare interface LineageResult {
|
|
|
8584
8611
|
error?: string;
|
|
8585
8612
|
}
|
|
8586
8613
|
|
|
8614
|
+
/**
|
|
8615
|
+
* Trace the lineage of a column through a SQL query using schema metadata.
|
|
8616
|
+
*
|
|
8617
|
+
* @param column - Column name to trace
|
|
8618
|
+
* @param sql - SQL string to analyze
|
|
8619
|
+
* @param schema - ValidationSchema-compatible schema object
|
|
8620
|
+
* @param dialect - Dialect for parsing/qualification (default: 'generic')
|
|
8621
|
+
* @param trimSelects - Trim SELECT to only target column (default: false)
|
|
8622
|
+
*/
|
|
8623
|
+
export declare function lineageWithSchema(column: string, sql: string, schema: Schema, dialect?: string, trimSelects?: boolean): LineageResult;
|
|
8624
|
+
|
|
8587
8625
|
/**
|
|
8588
8626
|
* List
|
|
8589
8627
|
*/
|
|
@@ -9457,6 +9495,21 @@ declare type Operator = {
|
|
|
9457
9495
|
comments?: Array<string>;
|
|
9458
9496
|
};
|
|
9459
9497
|
|
|
9498
|
+
/**
|
|
9499
|
+
* Key/value pair in a BigQuery OPTIONS (...) clause.
|
|
9500
|
+
*/
|
|
9501
|
+
declare type OptionEntry = {
|
|
9502
|
+
key: Identifier;
|
|
9503
|
+
value: Expression;
|
|
9504
|
+
};
|
|
9505
|
+
|
|
9506
|
+
/**
|
|
9507
|
+
* Typed BigQuery OPTIONS (...) property for CREATE TABLE and related DDL.
|
|
9508
|
+
*/
|
|
9509
|
+
declare type OptionsProperty = {
|
|
9510
|
+
entries: Array<OptionEntry>;
|
|
9511
|
+
};
|
|
9512
|
+
|
|
9460
9513
|
/** Chain multiple conditions with OR. */
|
|
9461
9514
|
export declare function or(...conditions: ExprInput[]): Expr;
|
|
9462
9515
|
|
|
@@ -9730,6 +9783,10 @@ export declare interface ParseResult {
|
|
|
9730
9783
|
errorLine?: number;
|
|
9731
9784
|
/** 1-based column number where the error occurred */
|
|
9732
9785
|
errorColumn?: number;
|
|
9786
|
+
/** Start byte offset of the error range */
|
|
9787
|
+
errorStart?: number;
|
|
9788
|
+
/** End byte offset of the error range (exclusive) */
|
|
9789
|
+
errorEnd?: number;
|
|
9733
9790
|
}
|
|
9734
9791
|
|
|
9735
9792
|
/**
|
|
@@ -9776,6 +9833,13 @@ declare type PartitionByListProperty = {
|
|
|
9776
9833
|
create_expressions: Expression | null;
|
|
9777
9834
|
};
|
|
9778
9835
|
|
|
9836
|
+
/**
|
|
9837
|
+
* BigQuery PARTITION BY property in CREATE TABLE statements.
|
|
9838
|
+
*/
|
|
9839
|
+
declare type PartitionByProperty = {
|
|
9840
|
+
expressions: Array<Expression>;
|
|
9841
|
+
};
|
|
9842
|
+
|
|
9779
9843
|
/**
|
|
9780
9844
|
* PartitionByRangeProperty
|
|
9781
9845
|
*/
|
|
@@ -10049,6 +10113,10 @@ export declare class Polyglot {
|
|
|
10049
10113
|
* Parse SQL into an AST.
|
|
10050
10114
|
*/
|
|
10051
10115
|
parse(sql: string, dialect?: Dialect): ParseResult;
|
|
10116
|
+
/**
|
|
10117
|
+
* Tokenize SQL into a token stream.
|
|
10118
|
+
*/
|
|
10119
|
+
tokenize(sql: string, dialect?: Dialect): TokenizeResult;
|
|
10052
10120
|
/**
|
|
10053
10121
|
* Generate SQL from an AST.
|
|
10054
10122
|
*/
|
|
@@ -11715,6 +11783,38 @@ export declare interface SourceTablesResult {
|
|
|
11715
11783
|
error?: string;
|
|
11716
11784
|
}
|
|
11717
11785
|
|
|
11786
|
+
/**
|
|
11787
|
+
* Represents a position in the source SQL
|
|
11788
|
+
*/
|
|
11789
|
+
declare type Span = {
|
|
11790
|
+
/**
|
|
11791
|
+
* Starting byte offset
|
|
11792
|
+
*/
|
|
11793
|
+
start: number;
|
|
11794
|
+
/**
|
|
11795
|
+
* Ending byte offset (exclusive)
|
|
11796
|
+
*/
|
|
11797
|
+
end: number;
|
|
11798
|
+
/**
|
|
11799
|
+
* Line number (1-based)
|
|
11800
|
+
*/
|
|
11801
|
+
line: number;
|
|
11802
|
+
/**
|
|
11803
|
+
* Column number (1-based)
|
|
11804
|
+
*/
|
|
11805
|
+
column: number;
|
|
11806
|
+
};
|
|
11807
|
+
|
|
11808
|
+
/**
|
|
11809
|
+
* Span information for a token, indicating its position in the source SQL.
|
|
11810
|
+
*/
|
|
11811
|
+
export declare interface SpanInfo {
|
|
11812
|
+
start: number;
|
|
11813
|
+
end: number;
|
|
11814
|
+
line: number;
|
|
11815
|
+
column: number;
|
|
11816
|
+
}
|
|
11817
|
+
|
|
11718
11818
|
/**
|
|
11719
11819
|
* SPLIT function
|
|
11720
11820
|
*/
|
|
@@ -11842,6 +11942,10 @@ declare type Star = {
|
|
|
11842
11942
|
* Trailing comments that appeared after the star
|
|
11843
11943
|
*/
|
|
11844
11944
|
trailing_comments?: Array<string>;
|
|
11945
|
+
/**
|
|
11946
|
+
* Source position span
|
|
11947
|
+
*/
|
|
11948
|
+
span?: Span | null;
|
|
11845
11949
|
};
|
|
11846
11950
|
|
|
11847
11951
|
/** Create a star (*) expression. */
|
|
@@ -12421,6 +12525,10 @@ declare type TableRef = {
|
|
|
12421
12525
|
* Time travel version clause: FOR VERSION AS OF / FOR TIMESTAMP AS OF (Presto/Trino, BigQuery, Databricks)
|
|
12422
12526
|
*/
|
|
12423
12527
|
version?: Version | null;
|
|
12528
|
+
/**
|
|
12529
|
+
* Source position span
|
|
12530
|
+
*/
|
|
12531
|
+
span?: Span | null;
|
|
12424
12532
|
};
|
|
12425
12533
|
|
|
12426
12534
|
/**
|
|
@@ -12711,6 +12819,53 @@ declare type ToFile = {
|
|
|
12711
12819
|
safe: Expression | null;
|
|
12712
12820
|
};
|
|
12713
12821
|
|
|
12822
|
+
/**
|
|
12823
|
+
* A single token from the SQL token stream.
|
|
12824
|
+
*/
|
|
12825
|
+
export declare interface TokenInfo {
|
|
12826
|
+
tokenType: string;
|
|
12827
|
+
text: string;
|
|
12828
|
+
span: SpanInfo;
|
|
12829
|
+
comments: string[];
|
|
12830
|
+
trailingComments: string[];
|
|
12831
|
+
}
|
|
12832
|
+
|
|
12833
|
+
/**
|
|
12834
|
+
* Tokenize SQL into a token stream.
|
|
12835
|
+
*
|
|
12836
|
+
* @param sql - The SQL string to tokenize
|
|
12837
|
+
* @param dialect - The dialect to use for tokenization
|
|
12838
|
+
* @returns The token stream
|
|
12839
|
+
*
|
|
12840
|
+
* @example
|
|
12841
|
+
* ```typescript
|
|
12842
|
+
* const result = tokenize("SELECT a, b FROM t", Dialect.PostgreSQL);
|
|
12843
|
+
* if (result.success) {
|
|
12844
|
+
* for (const token of result.tokens!) {
|
|
12845
|
+
* console.log(token.tokenType, token.text, token.span);
|
|
12846
|
+
* }
|
|
12847
|
+
* }
|
|
12848
|
+
* ```
|
|
12849
|
+
*/
|
|
12850
|
+
export declare function tokenize(sql: string, dialect?: Dialect): TokenizeResult;
|
|
12851
|
+
|
|
12852
|
+
/**
|
|
12853
|
+
* Result of a tokenize operation
|
|
12854
|
+
*/
|
|
12855
|
+
export declare interface TokenizeResult {
|
|
12856
|
+
success: boolean;
|
|
12857
|
+
tokens?: TokenInfo[];
|
|
12858
|
+
error?: string;
|
|
12859
|
+
/** 1-based line number where the error occurred */
|
|
12860
|
+
errorLine?: number;
|
|
12861
|
+
/** 1-based column number where the error occurred */
|
|
12862
|
+
errorColumn?: number;
|
|
12863
|
+
/** Start byte offset of the error range */
|
|
12864
|
+
errorStart?: number;
|
|
12865
|
+
/** End byte offset of the error range (exclusive) */
|
|
12866
|
+
errorEnd?: number;
|
|
12867
|
+
}
|
|
12868
|
+
|
|
12714
12869
|
/**
|
|
12715
12870
|
* ToMap - Materialize-style map constructor
|
|
12716
12871
|
* Can hold either:
|
|
@@ -12899,6 +13054,10 @@ export declare interface TranspileResult {
|
|
|
12899
13054
|
errorLine?: number;
|
|
12900
13055
|
/** 1-based column number where the error occurred */
|
|
12901
13056
|
errorColumn?: number;
|
|
13057
|
+
/** Start byte offset of the error range */
|
|
13058
|
+
errorStart?: number;
|
|
13059
|
+
/** End byte offset of the error range (exclusive) */
|
|
13060
|
+
errorEnd?: number;
|
|
12902
13061
|
}
|
|
12903
13062
|
|
|
12904
13063
|
/**
|
|
@@ -13586,6 +13745,10 @@ export declare interface ValidationError {
|
|
|
13586
13745
|
severity: ValidationSeverity;
|
|
13587
13746
|
/** Error code (e.g., "E001", "W001") */
|
|
13588
13747
|
code: string;
|
|
13748
|
+
/** Start byte offset of the error range */
|
|
13749
|
+
start?: number;
|
|
13750
|
+
/** End byte offset of the error range (exclusive) */
|
|
13751
|
+
end?: number;
|
|
13589
13752
|
}
|
|
13590
13753
|
|
|
13591
13754
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2221,6 +2221,50 @@ function lineage_sql$1(sql, column, dialect, trim_selects) {
|
|
|
2221
2221
|
}
|
|
2222
2222
|
}
|
|
2223
2223
|
|
|
2224
|
+
/**
|
|
2225
|
+
* Trace column lineage through a SQL query using schema metadata.
|
|
2226
|
+
*
|
|
2227
|
+
* # Arguments
|
|
2228
|
+
* * `sql` - SQL string to analyze
|
|
2229
|
+
* * `column` - Column name to trace
|
|
2230
|
+
* * `schema_json` - Schema JSON matching `ValidationSchema`
|
|
2231
|
+
* * `dialect` - Dialect for parsing/qualification
|
|
2232
|
+
* * `trim_selects` - Trim SELECT to only target column
|
|
2233
|
+
*
|
|
2234
|
+
* # Returns
|
|
2235
|
+
* JSON string containing LineageResult
|
|
2236
|
+
* @param {string} sql
|
|
2237
|
+
* @param {string} column
|
|
2238
|
+
* @param {string} schema_json
|
|
2239
|
+
* @param {string} dialect
|
|
2240
|
+
* @param {boolean} trim_selects
|
|
2241
|
+
* @returns {string}
|
|
2242
|
+
*/
|
|
2243
|
+
function lineage_sql_with_schema$1(sql, column, schema_json, dialect, trim_selects) {
|
|
2244
|
+
let deferred5_0;
|
|
2245
|
+
let deferred5_1;
|
|
2246
|
+
try {
|
|
2247
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
2248
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2249
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2250
|
+
const ptr1 = passStringToWasm0(column, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2251
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2252
|
+
const ptr2 = passStringToWasm0(schema_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2253
|
+
const len2 = WASM_VECTOR_LEN;
|
|
2254
|
+
const ptr3 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2255
|
+
const len3 = WASM_VECTOR_LEN;
|
|
2256
|
+
wasm$3.lineage_sql_with_schema(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, trim_selects);
|
|
2257
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2258
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2259
|
+
deferred5_0 = r0;
|
|
2260
|
+
deferred5_1 = r1;
|
|
2261
|
+
return getStringFromWasm0(r0, r1);
|
|
2262
|
+
} finally {
|
|
2263
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
2264
|
+
wasm$3.__wbindgen_export4(deferred5_0, deferred5_1, 1);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2224
2268
|
/**
|
|
2225
2269
|
* Parse SQL into an AST (returned as JSON).
|
|
2226
2270
|
*
|
|
@@ -2342,6 +2386,55 @@ function source_tables$1(sql, column, dialect) {
|
|
|
2342
2386
|
}
|
|
2343
2387
|
}
|
|
2344
2388
|
|
|
2389
|
+
/**
|
|
2390
|
+
* Tokenize SQL into a token stream (returned as JSON).
|
|
2391
|
+
*
|
|
2392
|
+
* # Arguments
|
|
2393
|
+
* * `sql` - The SQL string to tokenize
|
|
2394
|
+
* * `dialect` - The dialect to use for tokenization
|
|
2395
|
+
*
|
|
2396
|
+
* # Returns
|
|
2397
|
+
* A JSON string containing the TokenizeResult
|
|
2398
|
+
* @param {string} sql
|
|
2399
|
+
* @param {string} dialect
|
|
2400
|
+
* @returns {string}
|
|
2401
|
+
*/
|
|
2402
|
+
function tokenize$2(sql, dialect) {
|
|
2403
|
+
let deferred3_0;
|
|
2404
|
+
let deferred3_1;
|
|
2405
|
+
try {
|
|
2406
|
+
const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
|
|
2407
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2408
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2409
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2410
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2411
|
+
wasm$3.tokenize(retptr, ptr0, len0, ptr1, len1);
|
|
2412
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
2413
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
2414
|
+
deferred3_0 = r0;
|
|
2415
|
+
deferred3_1 = r1;
|
|
2416
|
+
return getStringFromWasm0(r0, r1);
|
|
2417
|
+
} finally {
|
|
2418
|
+
wasm$3.__wbindgen_add_to_stack_pointer(16);
|
|
2419
|
+
wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
/**
|
|
2424
|
+
* Tokenize SQL and return a structured JS object.
|
|
2425
|
+
* @param {string} sql
|
|
2426
|
+
* @param {string} dialect
|
|
2427
|
+
* @returns {any}
|
|
2428
|
+
*/
|
|
2429
|
+
function tokenize_value$1(sql, dialect) {
|
|
2430
|
+
const ptr0 = passStringToWasm0(sql, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2431
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2432
|
+
const ptr1 = passStringToWasm0(dialect, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
|
|
2433
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2434
|
+
const ret = wasm$3.tokenize_value(ptr0, len0, ptr1, len1);
|
|
2435
|
+
return takeObject(ret);
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2345
2438
|
/**
|
|
2346
2439
|
* Transpile SQL from one dialect to another.
|
|
2347
2440
|
*
|
|
@@ -3355,10 +3448,13 @@ const generate_value = __vite__wasmModule.generate_value;
|
|
|
3355
3448
|
const get_dialects = __vite__wasmModule.get_dialects;
|
|
3356
3449
|
const get_dialects_value = __vite__wasmModule.get_dialects_value;
|
|
3357
3450
|
const lineage_sql = __vite__wasmModule.lineage_sql;
|
|
3451
|
+
const lineage_sql_with_schema = __vite__wasmModule.lineage_sql_with_schema;
|
|
3358
3452
|
const parse$1 = __vite__wasmModule.parse;
|
|
3359
3453
|
const parse_value = __vite__wasmModule.parse_value;
|
|
3360
3454
|
const plan$1 = __vite__wasmModule.plan;
|
|
3361
3455
|
const source_tables = __vite__wasmModule.source_tables;
|
|
3456
|
+
const tokenize$1 = __vite__wasmModule.tokenize;
|
|
3457
|
+
const tokenize_value = __vite__wasmModule.tokenize_value;
|
|
3362
3458
|
const transpile$1 = __vite__wasmModule.transpile;
|
|
3363
3459
|
const transpile_value = __vite__wasmModule.transpile_value;
|
|
3364
3460
|
const validate$1 = __vite__wasmModule.validate;
|
|
@@ -3539,11 +3635,14 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
3539
3635
|
get_dialects,
|
|
3540
3636
|
get_dialects_value,
|
|
3541
3637
|
lineage_sql,
|
|
3638
|
+
lineage_sql_with_schema,
|
|
3542
3639
|
memory,
|
|
3543
3640
|
parse: parse$1,
|
|
3544
3641
|
parse_value,
|
|
3545
3642
|
plan: plan$1,
|
|
3546
3643
|
source_tables,
|
|
3644
|
+
tokenize: tokenize$1,
|
|
3645
|
+
tokenize_value,
|
|
3547
3646
|
transpile: transpile$1,
|
|
3548
3647
|
transpile_value,
|
|
3549
3648
|
validate: validate$1,
|
|
@@ -3719,10 +3818,13 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
|
|
|
3719
3818
|
get_dialects: get_dialects$1,
|
|
3720
3819
|
get_dialects_value: get_dialects_value$1,
|
|
3721
3820
|
lineage_sql: lineage_sql$1,
|
|
3821
|
+
lineage_sql_with_schema: lineage_sql_with_schema$1,
|
|
3722
3822
|
parse: parse$2,
|
|
3723
3823
|
parse_value: parse_value$1,
|
|
3724
3824
|
plan: plan$2,
|
|
3725
3825
|
source_tables: source_tables$1,
|
|
3826
|
+
tokenize: tokenize$2,
|
|
3827
|
+
tokenize_value: tokenize_value$1,
|
|
3726
3828
|
transpile: transpile$2,
|
|
3727
3829
|
transpile_value: transpile_value$1,
|
|
3728
3830
|
validate: validate$2,
|
|
@@ -5186,10 +5288,16 @@ function validateSelect(select, _options) {
|
|
|
5186
5288
|
const errors = [];
|
|
5187
5289
|
const stars = findByType(select, "star");
|
|
5188
5290
|
if (stars.length > 0) {
|
|
5291
|
+
const starData = getExprData(stars[0]);
|
|
5292
|
+
const span = starData?.span;
|
|
5189
5293
|
errors.push({
|
|
5190
5294
|
message: "SELECT * is discouraged; specify columns explicitly for better performance and maintainability",
|
|
5191
5295
|
severity: "warning",
|
|
5192
|
-
code: "W001"
|
|
5296
|
+
code: "W001",
|
|
5297
|
+
line: span?.line,
|
|
5298
|
+
column: span?.column,
|
|
5299
|
+
start: span?.start,
|
|
5300
|
+
end: span?.end
|
|
5193
5301
|
});
|
|
5194
5302
|
}
|
|
5195
5303
|
const selectData = getExprData(select);
|
|
@@ -5205,10 +5313,22 @@ function validateSelect(select, _options) {
|
|
|
5205
5313
|
return false;
|
|
5206
5314
|
});
|
|
5207
5315
|
if (hasNonAggregateColumn && aggregateFunctions.length > 0) {
|
|
5316
|
+
const firstNonAgg = selectCols.find((col) => {
|
|
5317
|
+
const colType = getExprType(col);
|
|
5318
|
+
if (colType === "column" || colType === "identifier") {
|
|
5319
|
+
return getAggregateFunctions(col).length === 0;
|
|
5320
|
+
}
|
|
5321
|
+
return false;
|
|
5322
|
+
});
|
|
5323
|
+
const colSpan = firstNonAgg ? getExprData(firstNonAgg)?.span : void 0;
|
|
5208
5324
|
errors.push({
|
|
5209
5325
|
message: "Mixing aggregate functions with non-aggregated columns without GROUP BY may cause errors in strict SQL mode",
|
|
5210
5326
|
severity: "warning",
|
|
5211
|
-
code: "W002"
|
|
5327
|
+
code: "W002",
|
|
5328
|
+
line: colSpan?.line,
|
|
5329
|
+
column: colSpan?.column,
|
|
5330
|
+
start: colSpan?.start,
|
|
5331
|
+
end: colSpan?.end
|
|
5212
5332
|
});
|
|
5213
5333
|
}
|
|
5214
5334
|
}
|
|
@@ -5220,10 +5340,16 @@ function validateSelect(select, _options) {
|
|
|
5220
5340
|
});
|
|
5221
5341
|
}
|
|
5222
5342
|
if (selectData.limit && !selectData.order_by) {
|
|
5343
|
+
const limitExpr = selectData.limit;
|
|
5344
|
+
const limitSpan = limitExpr ? getExprData(limitExpr)?.span : void 0;
|
|
5223
5345
|
errors.push({
|
|
5224
5346
|
message: "LIMIT without ORDER BY produces non-deterministic results",
|
|
5225
5347
|
severity: "warning",
|
|
5226
|
-
code: "W004"
|
|
5348
|
+
code: "W004",
|
|
5349
|
+
line: limitSpan?.line,
|
|
5350
|
+
column: limitSpan?.column,
|
|
5351
|
+
start: limitSpan?.start,
|
|
5352
|
+
end: limitSpan?.end
|
|
5227
5353
|
});
|
|
5228
5354
|
}
|
|
5229
5355
|
return errors;
|
|
@@ -5310,6 +5436,16 @@ function lineage(column, sql, dialect = "generic", trimSelects = false) {
|
|
|
5310
5436
|
const resultJson = lineage_sql$1(sql, column, dialect, trimSelects);
|
|
5311
5437
|
return JSON.parse(resultJson);
|
|
5312
5438
|
}
|
|
5439
|
+
function lineageWithSchema(column, sql, schema, dialect = "generic", trimSelects = false) {
|
|
5440
|
+
const resultJson = lineage_sql_with_schema$1(
|
|
5441
|
+
sql,
|
|
5442
|
+
column,
|
|
5443
|
+
JSON.stringify(schema),
|
|
5444
|
+
dialect,
|
|
5445
|
+
trimSelects
|
|
5446
|
+
);
|
|
5447
|
+
return JSON.parse(resultJson);
|
|
5448
|
+
}
|
|
5313
5449
|
function getSourceTables(column, sql, dialect = "generic") {
|
|
5314
5450
|
const resultJson = source_tables$1(sql, column, dialect);
|
|
5315
5451
|
return JSON.parse(resultJson);
|
|
@@ -5435,6 +5571,22 @@ function parse(sql, dialect = "generic" /* Generic */) {
|
|
|
5435
5571
|
return parseFailure("parse", error);
|
|
5436
5572
|
}
|
|
5437
5573
|
}
|
|
5574
|
+
function tokenize(sql, dialect = "generic" /* Generic */) {
|
|
5575
|
+
try {
|
|
5576
|
+
if (typeof wasm.tokenize_value === "function") {
|
|
5577
|
+
return decodeWasmPayload(
|
|
5578
|
+
wasm.tokenize_value(sql, dialect)
|
|
5579
|
+
);
|
|
5580
|
+
}
|
|
5581
|
+
return JSON.parse(wasm.tokenize(sql, dialect));
|
|
5582
|
+
} catch (error) {
|
|
5583
|
+
return {
|
|
5584
|
+
success: false,
|
|
5585
|
+
tokens: void 0,
|
|
5586
|
+
error: `WASM tokenize failed: ${errorMessage(error)}`
|
|
5587
|
+
};
|
|
5588
|
+
}
|
|
5589
|
+
}
|
|
5438
5590
|
function generate(ast2, dialect = "generic" /* Generic */) {
|
|
5439
5591
|
try {
|
|
5440
5592
|
if (typeof wasm.generate_value === "function" && Array.isArray(ast2)) {
|
|
@@ -5512,6 +5664,12 @@ class Polyglot {
|
|
|
5512
5664
|
parse(sql, dialect = "generic" /* Generic */) {
|
|
5513
5665
|
return parse(sql, dialect);
|
|
5514
5666
|
}
|
|
5667
|
+
/**
|
|
5668
|
+
* Tokenize SQL into a token stream.
|
|
5669
|
+
*/
|
|
5670
|
+
tokenize(sql, dialect = "generic" /* Generic */) {
|
|
5671
|
+
return tokenize(sql, dialect);
|
|
5672
|
+
}
|
|
5515
5673
|
/**
|
|
5516
5674
|
* Generate SQL from an AST.
|
|
5517
5675
|
*/
|
|
@@ -5549,11 +5707,13 @@ const index = {
|
|
|
5549
5707
|
isInitialized,
|
|
5550
5708
|
transpile,
|
|
5551
5709
|
parse,
|
|
5710
|
+
tokenize,
|
|
5552
5711
|
generate,
|
|
5553
5712
|
format,
|
|
5554
5713
|
getDialects,
|
|
5555
5714
|
getVersion,
|
|
5556
5715
|
lineage: lineage,
|
|
5716
|
+
lineageWithSchema: lineageWithSchema,
|
|
5557
5717
|
getSourceTables: getSourceTables,
|
|
5558
5718
|
diff: diff,
|
|
5559
5719
|
hasChanges: hasChanges,
|
|
@@ -5563,4 +5723,4 @@ const index = {
|
|
|
5563
5723
|
Polyglot
|
|
5564
5724
|
};
|
|
5565
5725
|
|
|
5566
|
-
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, transform, transpile, trim, union, unionAll, update, upper, validate, validateWithSchema, walk };
|
|
5726
|
+
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, 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,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyglot-sql/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
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
|
+
"browser": "./dist/index.js",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
15
20
|
},
|
|
16
21
|
"./cdn": {
|
|
17
22
|
"types": "./dist/index.d.ts",
|
|
@@ -62,10 +67,11 @@
|
|
|
62
67
|
"build:bindings": "cd ../.. && make generate-bindings",
|
|
63
68
|
"build:wasm": "cd ../../crates/polyglot-sql-wasm && wasm-pack build --target bundler --release --out-dir ../../packages/sdk/wasm",
|
|
64
69
|
"build:esm": "vite build",
|
|
70
|
+
"build:cjs": "vite build --config vite.config.cjs.ts && cp dist/index.d.ts dist/index.d.cts",
|
|
65
71
|
"build:umd": "vite build --config vite.config.umd.ts",
|
|
66
72
|
"build:dialect": "vite build --config vite.config.dialect.ts",
|
|
67
73
|
"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",
|
|
74
|
+
"build": "pnpm run build:esm && pnpm run build:cjs && pnpm run build:umd",
|
|
69
75
|
"build:all": "pnpm run build && pnpm run build:dialects",
|
|
70
76
|
"test": "vitest run",
|
|
71
77
|
"test:watch": "vitest",
|