@polyglot-sql/sdk 0.5.3 → 0.5.4

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.cjs CHANGED
@@ -1699,6 +1699,24 @@ function ast_get_table_names$1(ast_json) {
1699
1699
  wasm$3.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1700
1700
  }
1701
1701
  }
1702
+ function ast_get_tables$1(ast_json) {
1703
+ let deferred2_0;
1704
+ let deferred2_1;
1705
+ try {
1706
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
1707
+ const ptr0 = passStringToWasm0(ast_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1708
+ const len0 = WASM_VECTOR_LEN;
1709
+ wasm$3.ast_get_tables(retptr, ptr0, len0);
1710
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1711
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1712
+ deferred2_0 = r0;
1713
+ deferred2_1 = r1;
1714
+ return getStringFromWasm0(r0, r1);
1715
+ } finally {
1716
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
1717
+ wasm$3.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1718
+ }
1719
+ }
1702
1720
  function ast_get_window_functions$1(ast_json) {
1703
1721
  let deferred2_0;
1704
1722
  let deferred2_1;
@@ -1891,6 +1909,44 @@ function ast_set_limit$1(ast_json, limit) {
1891
1909
  wasm$3.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1892
1910
  }
1893
1911
  }
1912
+ function ast_set_offset$1(ast_json, offset) {
1913
+ let deferred2_0;
1914
+ let deferred2_1;
1915
+ try {
1916
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
1917
+ const ptr0 = passStringToWasm0(ast_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1918
+ const len0 = WASM_VECTOR_LEN;
1919
+ wasm$3.ast_set_offset(retptr, ptr0, len0, offset);
1920
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1921
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1922
+ deferred2_0 = r0;
1923
+ deferred2_1 = r1;
1924
+ return getStringFromWasm0(r0, r1);
1925
+ } finally {
1926
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
1927
+ wasm$3.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1928
+ }
1929
+ }
1930
+ function ast_set_order_by$1(ast_json, order_by_json) {
1931
+ let deferred3_0;
1932
+ let deferred3_1;
1933
+ try {
1934
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
1935
+ const ptr0 = passStringToWasm0(ast_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1936
+ const len0 = WASM_VECTOR_LEN;
1937
+ const ptr1 = passStringToWasm0(order_by_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1938
+ const len1 = WASM_VECTOR_LEN;
1939
+ wasm$3.ast_set_order_by(retptr, ptr0, len0, ptr1, len1);
1940
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1941
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1942
+ deferred3_0 = r0;
1943
+ deferred3_1 = r1;
1944
+ return getStringFromWasm0(r0, r1);
1945
+ } finally {
1946
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
1947
+ wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
1948
+ }
1949
+ }
1894
1950
  function diff_sql$1(source_sql, target_sql, dialect, delta_only, f, t) {
1895
1951
  let deferred4_0;
1896
1952
  let deferred4_1;
@@ -2623,10 +2679,6 @@ function __wbg_call_389efe28435a9388() {
2623
2679
  return addHeapObject(ret);
2624
2680
  }, arguments);
2625
2681
  }
2626
- function __wbg_codePointAt_bf59dbf74d8db275(arg0, arg1) {
2627
- const ret = getObject(arg0).codePointAt(arg1 >>> 0);
2628
- return addHeapObject(ret);
2629
- }
2630
2682
  function __wbg_done_57b39ecd9addfe81(arg0) {
2631
2683
  const ret = getObject(arg0).done;
2632
2684
  return ret;
@@ -2716,10 +2768,6 @@ function __wbg_length_35a7bace40f36eac(arg0) {
2716
2768
  const ret = getObject(arg0).length;
2717
2769
  return ret;
2718
2770
  }
2719
- function __wbg_length_68dc7c5cf1b6d349(arg0) {
2720
- const ret = getObject(arg0).length;
2721
- return ret;
2722
- }
2723
2771
  function __wbg_new_361308b2356cecd0() {
2724
2772
  const ret = new Object();
2725
2773
  return addHeapObject(ret);
@@ -3048,9 +3096,7 @@ const __vite__wasmImports = { "./polyglot_sql_wasm_bg.js": {
3048
3096
  "__wbg_call_389efe28435a9388": __wbg_call_389efe28435a9388,
3049
3097
  "__wbg_next_418f80d8f5303233": __wbg_next_418f80d8f5303233,
3050
3098
  "__wbg_next_3482f54c49e8af19": __wbg_next_3482f54c49e8af19,
3051
- "__wbg_codePointAt_bf59dbf74d8db275": __wbg_codePointAt_bf59dbf74d8db275,
3052
3099
  "__wbg_fromCodePoint_22365db7b7d6ac39": __wbg_fromCodePoint_22365db7b7d6ac39,
3053
- "__wbg_length_68dc7c5cf1b6d349": __wbg_length_68dc7c5cf1b6d349,
3054
3100
  "__wbg___wbindgen_in_47fa6863be6f2f25": __wbg___wbindgen_in_47fa6863be6f2f25,
3055
3101
  "__wbg___wbindgen_throw_be289d5034ed271b": __wbg___wbindgen_throw_be289d5034ed271b,
3056
3102
  "__wbg___wbindgen_is_null_ac34f5003991759a": __wbg___wbindgen_is_null_ac34f5003991759a,
@@ -3105,6 +3151,7 @@ async function __polyglot_init_wasm() {
3105
3151
  ast_get_literals = __vite__wasmModule.ast_get_literals;
3106
3152
  ast_get_subqueries = __vite__wasmModule.ast_get_subqueries;
3107
3153
  ast_get_table_names = __vite__wasmModule.ast_get_table_names;
3154
+ ast_get_tables = __vite__wasmModule.ast_get_tables;
3108
3155
  ast_get_window_functions = __vite__wasmModule.ast_get_window_functions;
3109
3156
  ast_node_count = __vite__wasmModule.ast_node_count;
3110
3157
  ast_qualify_columns = __vite__wasmModule.ast_qualify_columns;
@@ -3115,6 +3162,8 @@ async function __polyglot_init_wasm() {
3115
3162
  ast_rename_tables_with_options = __vite__wasmModule.ast_rename_tables_with_options;
3116
3163
  ast_set_distinct = __vite__wasmModule.ast_set_distinct;
3117
3164
  ast_set_limit = __vite__wasmModule.ast_set_limit;
3165
+ ast_set_offset = __vite__wasmModule.ast_set_offset;
3166
+ ast_set_order_by = __vite__wasmModule.ast_set_order_by;
3118
3167
  diff_sql = __vite__wasmModule.diff_sql;
3119
3168
  format_sql = __vite__wasmModule.format_sql;
3120
3169
  format_sql_value = __vite__wasmModule.format_sql_value;
@@ -3304,6 +3353,7 @@ let ast_get_functions;
3304
3353
  let ast_get_literals;
3305
3354
  let ast_get_subqueries;
3306
3355
  let ast_get_table_names;
3356
+ let ast_get_tables;
3307
3357
  let ast_get_window_functions;
3308
3358
  let ast_node_count;
3309
3359
  let ast_qualify_columns;
@@ -3314,6 +3364,8 @@ let ast_rename_tables;
3314
3364
  let ast_rename_tables_with_options;
3315
3365
  let ast_set_distinct;
3316
3366
  let ast_set_limit;
3367
+ let ast_set_offset;
3368
+ let ast_set_order_by;
3317
3369
  let diff_sql;
3318
3370
  let format_sql;
3319
3371
  let format_sql_value;
@@ -3505,6 +3557,7 @@ const wasm$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
3505
3557
  ast_get_literals,
3506
3558
  ast_get_subqueries,
3507
3559
  ast_get_table_names,
3560
+ ast_get_tables,
3508
3561
  ast_get_window_functions,
3509
3562
  ast_node_count,
3510
3563
  ast_qualify_columns,
@@ -3515,6 +3568,8 @@ const wasm$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
3515
3568
  ast_rename_tables_with_options,
3516
3569
  ast_set_distinct,
3517
3570
  ast_set_limit,
3571
+ ast_set_offset,
3572
+ ast_set_order_by,
3518
3573
  diff_sql,
3519
3574
  format_sql,
3520
3575
  format_sql_value,
@@ -3698,6 +3753,7 @@ const wasmModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
3698
3753
  ast_get_literals: ast_get_literals$1,
3699
3754
  ast_get_subqueries: ast_get_subqueries$1,
3700
3755
  ast_get_table_names: ast_get_table_names$1,
3756
+ ast_get_tables: ast_get_tables$1,
3701
3757
  ast_get_window_functions: ast_get_window_functions$1,
3702
3758
  ast_node_count: ast_node_count$1,
3703
3759
  ast_qualify_columns: ast_qualify_columns$1,
@@ -3708,6 +3764,8 @@ const wasmModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
3708
3764
  ast_rename_tables_with_options: ast_rename_tables_with_options$1,
3709
3765
  ast_set_distinct: ast_set_distinct$1,
3710
3766
  ast_set_limit: ast_set_limit$1,
3767
+ ast_set_offset: ast_set_offset$1,
3768
+ ast_set_order_by: ast_set_order_by$1,
3711
3769
  diff_sql: diff_sql$1,
3712
3770
  format_sql: format_sql$1,
3713
3771
  format_sql_value: format_sql_value$1,
@@ -3891,6 +3949,69 @@ function parseAstResult(json) {
3891
3949
  const result = JSON.parse(json);
3892
3950
  return result.success ? JSON.parse(result.ast) : null;
3893
3951
  }
3952
+ function isQueryWithOuterClauses(node) {
3953
+ return ["select", "union", "intersect", "except"].includes(getExprType(node));
3954
+ }
3955
+ function applyLimitExpr(node, limit) {
3956
+ const type = getExprType(node);
3957
+ if (!isQueryWithOuterClauses(node)) {
3958
+ return node;
3959
+ }
3960
+ const data = getExprData(node);
3961
+ if (type === "select") {
3962
+ return makeExpr("select", {
3963
+ ...data,
3964
+ limit: { this: limit, percent: false, comments: [] }
3965
+ });
3966
+ }
3967
+ return makeExpr(type, {
3968
+ ...data,
3969
+ limit
3970
+ });
3971
+ }
3972
+ function applyOffsetExpr(node, offset) {
3973
+ const type = getExprType(node);
3974
+ if (!isQueryWithOuterClauses(node)) {
3975
+ return node;
3976
+ }
3977
+ const data = getExprData(node);
3978
+ if (type === "select") {
3979
+ return makeExpr("select", {
3980
+ ...data,
3981
+ offset: { this: offset, rows: null }
3982
+ });
3983
+ }
3984
+ return makeExpr(type, {
3985
+ ...data,
3986
+ offset
3987
+ });
3988
+ }
3989
+ function applyOrderBy(node, orderBy) {
3990
+ const type = getExprType(node);
3991
+ if (!isQueryWithOuterClauses(node)) {
3992
+ return node;
3993
+ }
3994
+ const expressions = orderBy.map((expression) => {
3995
+ if (getExprType(expression) === "ordered") {
3996
+ return getExprData(expression);
3997
+ }
3998
+ return {
3999
+ this: expression,
4000
+ desc: false,
4001
+ nulls_first: null,
4002
+ explicit_asc: false,
4003
+ with_fill: null
4004
+ };
4005
+ });
4006
+ return makeExpr(type, {
4007
+ ...getExprData(node),
4008
+ order_by: {
4009
+ expressions,
4010
+ siblings: false,
4011
+ comments: []
4012
+ }
4013
+ });
4014
+ }
3894
4015
  function transformValue(value, config, parent) {
3895
4016
  if (value === null || value === void 0) return value;
3896
4017
  if (Array.isArray(value)) {
@@ -4060,25 +4181,21 @@ function setLimit(node, limit) {
4060
4181
  const result = parseAstResult(ast_set_limit$1(exprToJson$1(node), limit));
4061
4182
  return result ?? node;
4062
4183
  }
4063
- if (getExprType(node) !== "select") {
4064
- return node;
4065
- }
4066
- const selectData = getExprData(node);
4067
- return makeExpr("select", {
4068
- ...selectData,
4069
- limit: { this: limit }
4070
- });
4184
+ return applyLimitExpr(node, limit);
4071
4185
  }
4072
4186
  function setOffset(node, offset) {
4073
- if (getExprType(node) !== "select") {
4074
- return node;
4187
+ if (typeof offset === "number") {
4188
+ const result = parseAstResult(ast_set_offset$1(exprToJson$1(node), offset));
4189
+ return result ?? node;
4075
4190
  }
4076
- const selectData = getExprData(node);
4077
- const offsetExpr = typeof offset === "number" ? makeExpr("literal", { literal_type: "number", value: String(offset) }) : offset;
4078
- return makeExpr("select", {
4079
- ...selectData,
4080
- offset: { this: offsetExpr }
4081
- });
4191
+ return applyOffsetExpr(node, offset);
4192
+ }
4193
+ function setOrderBy(node, orderBy) {
4194
+ const orderByExpressions = Array.isArray(orderBy) ? orderBy : [orderBy];
4195
+ const result = parseAstResult(
4196
+ ast_set_order_by$1(exprToJson$1(node), JSON.stringify(orderByExpressions))
4197
+ );
4198
+ return result ?? applyOrderBy(node, orderByExpressions);
4082
4199
  }
4083
4200
  function removeLimitOffset(node) {
4084
4201
  if (getExprType(node) !== "select") {
@@ -4245,7 +4362,8 @@ function getColumns(node) {
4245
4362
  return findByType(node, "column");
4246
4363
  }
4247
4364
  function getTables(node) {
4248
- return findByType(node, "table");
4365
+ const result = JSON.parse(ast_get_tables$1(exprToJson(node)));
4366
+ return result.success ? JSON.parse(result.ast) : [];
4249
4367
  }
4250
4368
  function getIdentifiers(node) {
4251
4369
  return findByType(node, "identifier");
@@ -4478,6 +4596,7 @@ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
4478
4596
  setDistinct,
4479
4597
  setLimit,
4480
4598
  setOffset,
4599
+ setOrderBy,
4481
4600
  some,
4482
4601
  transform,
4483
4602
  walk
package/dist/index.d.cts CHANGED
@@ -1065,6 +1065,7 @@ export declare namespace ast {
1065
1065
  setDistinct,
1066
1066
  setLimit,
1067
1067
  setOffset,
1068
+ setOrderBy,
1068
1069
  transform,
1069
1070
  NodePath,
1070
1071
  NodePredicate,
@@ -10877,6 +10878,7 @@ export declare interface ProjectionFact {
10877
10878
  isStar: boolean;
10878
10879
  starTable?: string;
10879
10880
  transformKind: TransformKind;
10881
+ transformFunction?: TransformFunctionFact;
10880
10882
  castType?: string;
10881
10883
  typeHint?: string;
10882
10884
  nullability: ProjectionNullability;
@@ -11422,9 +11424,12 @@ declare type RegrValy = {
11422
11424
 
11423
11425
  export declare interface RelationFact {
11424
11426
  name: string;
11425
- alias?: string;
11427
+ alias?: string | null;
11426
11428
  kind: QueryAnalysisSourceKind;
11427
11429
  columns: string[];
11430
+ catalog?: string | null;
11431
+ schema?: string | null;
11432
+ table?: string | null;
11428
11433
  }
11429
11434
 
11430
11435
  /**
@@ -12317,6 +12322,14 @@ export declare interface SetOperationFact {
12317
12322
 
12318
12323
  export declare type SetOperationType = 'union' | 'union_all' | 'intersect' | 'except';
12319
12324
 
12325
+ /**
12326
+ * Set or update the ORDER BY clause.
12327
+ *
12328
+ * Bare expressions are normalized to ascending order entries. Existing
12329
+ * `ordered` expression nodes preserve their direction and null ordering.
12330
+ */
12331
+ declare function setOrderBy(node: Expression, orderBy: Expression | Expression[]): Expression;
12332
+
12320
12333
  /**
12321
12334
  * SetProperty
12322
12335
  */
@@ -13736,6 +13749,12 @@ declare type TransformFunc = {
13736
13749
  transform: Expression;
13737
13750
  };
13738
13751
 
13752
+ export declare interface TransformFunctionFact {
13753
+ name: string;
13754
+ literalArgs: string[];
13755
+ columnArgs: ColumnReferenceFact[];
13756
+ }
13757
+
13739
13758
  export declare type TransformKind = 'direct' | 'cast' | 'aggregation' | 'constant' | 'expression' | 'star';
13740
13759
 
13741
13760
  /**
package/dist/index.d.ts CHANGED
@@ -1065,6 +1065,7 @@ export declare namespace ast {
1065
1065
  setDistinct,
1066
1066
  setLimit,
1067
1067
  setOffset,
1068
+ setOrderBy,
1068
1069
  transform,
1069
1070
  NodePath,
1070
1071
  NodePredicate,
@@ -10877,6 +10878,7 @@ export declare interface ProjectionFact {
10877
10878
  isStar: boolean;
10878
10879
  starTable?: string;
10879
10880
  transformKind: TransformKind;
10881
+ transformFunction?: TransformFunctionFact;
10880
10882
  castType?: string;
10881
10883
  typeHint?: string;
10882
10884
  nullability: ProjectionNullability;
@@ -11422,9 +11424,12 @@ declare type RegrValy = {
11422
11424
 
11423
11425
  export declare interface RelationFact {
11424
11426
  name: string;
11425
- alias?: string;
11427
+ alias?: string | null;
11426
11428
  kind: QueryAnalysisSourceKind;
11427
11429
  columns: string[];
11430
+ catalog?: string | null;
11431
+ schema?: string | null;
11432
+ table?: string | null;
11428
11433
  }
11429
11434
 
11430
11435
  /**
@@ -12317,6 +12322,14 @@ export declare interface SetOperationFact {
12317
12322
 
12318
12323
  export declare type SetOperationType = 'union' | 'union_all' | 'intersect' | 'except';
12319
12324
 
12325
+ /**
12326
+ * Set or update the ORDER BY clause.
12327
+ *
12328
+ * Bare expressions are normalized to ascending order entries. Existing
12329
+ * `ordered` expression nodes preserve their direction and null ordering.
12330
+ */
12331
+ declare function setOrderBy(node: Expression, orderBy: Expression | Expression[]): Expression;
12332
+
12320
12333
  /**
12321
12334
  * SetProperty
12322
12335
  */
@@ -13736,6 +13749,12 @@ declare type TransformFunc = {
13736
13749
  transform: Expression;
13737
13750
  };
13738
13751
 
13752
+ export declare interface TransformFunctionFact {
13753
+ name: string;
13754
+ literalArgs: string[];
13755
+ columnArgs: ColumnReferenceFact[];
13756
+ }
13757
+
13739
13758
  export declare type TransformKind = 'direct' | 'cast' | 'aggregation' | 'constant' | 'expression' | 'star';
13740
13759
 
13741
13760
  /**
package/dist/index.js CHANGED
@@ -1864,6 +1864,30 @@ function ast_get_table_names$1(ast_json) {
1864
1864
  }
1865
1865
  }
1866
1866
 
1867
+ /**
1868
+ * Get all table nodes from an AST (as JSON string).
1869
+ * @param {string} ast_json
1870
+ * @returns {string}
1871
+ */
1872
+ function ast_get_tables$1(ast_json) {
1873
+ let deferred2_0;
1874
+ let deferred2_1;
1875
+ try {
1876
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
1877
+ const ptr0 = passStringToWasm0(ast_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
1878
+ const len0 = WASM_VECTOR_LEN;
1879
+ wasm$3.ast_get_tables(retptr, ptr0, len0);
1880
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1881
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1882
+ deferred2_0 = r0;
1883
+ deferred2_1 = r1;
1884
+ return getStringFromWasm0(r0, r1);
1885
+ } finally {
1886
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
1887
+ wasm$3.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1888
+ }
1889
+ }
1890
+
1867
1891
  /**
1868
1892
  * Get all window functions from an AST (as JSON string).
1869
1893
  * @param {string} ast_json
@@ -2124,6 +2148,58 @@ function ast_set_limit$1(ast_json, limit) {
2124
2148
  }
2125
2149
  }
2126
2150
 
2151
+ /**
2152
+ * Set the OFFSET on a SELECT or set-operation AST.
2153
+ * @param {string} ast_json
2154
+ * @param {number} offset
2155
+ * @returns {string}
2156
+ */
2157
+ function ast_set_offset$1(ast_json, offset) {
2158
+ let deferred2_0;
2159
+ let deferred2_1;
2160
+ try {
2161
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
2162
+ const ptr0 = passStringToWasm0(ast_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2163
+ const len0 = WASM_VECTOR_LEN;
2164
+ wasm$3.ast_set_offset(retptr, ptr0, len0, offset);
2165
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2166
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2167
+ deferred2_0 = r0;
2168
+ deferred2_1 = r1;
2169
+ return getStringFromWasm0(r0, r1);
2170
+ } finally {
2171
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
2172
+ wasm$3.__wbindgen_export4(deferred2_0, deferred2_1, 1);
2173
+ }
2174
+ }
2175
+
2176
+ /**
2177
+ * Set the ORDER BY clause on a SELECT or set-operation AST.
2178
+ * @param {string} ast_json
2179
+ * @param {string} order_by_json
2180
+ * @returns {string}
2181
+ */
2182
+ function ast_set_order_by$1(ast_json, order_by_json) {
2183
+ let deferred3_0;
2184
+ let deferred3_1;
2185
+ try {
2186
+ const retptr = wasm$3.__wbindgen_add_to_stack_pointer(-16);
2187
+ const ptr0 = passStringToWasm0(ast_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2188
+ const len0 = WASM_VECTOR_LEN;
2189
+ const ptr1 = passStringToWasm0(order_by_json, wasm$3.__wbindgen_export, wasm$3.__wbindgen_export2);
2190
+ const len1 = WASM_VECTOR_LEN;
2191
+ wasm$3.ast_set_order_by(retptr, ptr0, len0, ptr1, len1);
2192
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2193
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2194
+ deferred3_0 = r0;
2195
+ deferred3_1 = r1;
2196
+ return getStringFromWasm0(r0, r1);
2197
+ } finally {
2198
+ wasm$3.__wbindgen_add_to_stack_pointer(16);
2199
+ wasm$3.__wbindgen_export4(deferred3_0, deferred3_1, 1);
2200
+ }
2201
+ }
2202
+
2127
2203
  /**
2128
2204
  * Diff two SQL statements and return edit operations.
2129
2205
  *
@@ -3307,10 +3383,6 @@ function __wbg_call_389efe28435a9388() { return handleError(function (arg0, arg1
3307
3383
  const ret = getObject(arg0).call(getObject(arg1));
3308
3384
  return addHeapObject(ret);
3309
3385
  }, arguments); }
3310
- function __wbg_codePointAt_bf59dbf74d8db275(arg0, arg1) {
3311
- const ret = getObject(arg0).codePointAt(arg1 >>> 0);
3312
- return addHeapObject(ret);
3313
- }
3314
3386
  function __wbg_done_57b39ecd9addfe81(arg0) {
3315
3387
  const ret = getObject(arg0).done;
3316
3388
  return ret;
@@ -3396,10 +3468,6 @@ function __wbg_length_35a7bace40f36eac(arg0) {
3396
3468
  const ret = getObject(arg0).length;
3397
3469
  return ret;
3398
3470
  }
3399
- function __wbg_length_68dc7c5cf1b6d349(arg0) {
3400
- const ret = getObject(arg0).length;
3401
- return ret;
3402
- }
3403
3471
  function __wbg_new_361308b2356cecd0() {
3404
3472
  const ret = new Object();
3405
3473
  return addHeapObject(ret);
@@ -3764,9 +3832,7 @@ const __vite__wasmModule = await __vite__initWasm({ "./polyglot_sql_wasm_bg.js":
3764
3832
  "__wbg_call_389efe28435a9388": __wbg_call_389efe28435a9388,
3765
3833
  "__wbg_next_418f80d8f5303233": __wbg_next_418f80d8f5303233,
3766
3834
  "__wbg_next_3482f54c49e8af19": __wbg_next_3482f54c49e8af19,
3767
- "__wbg_codePointAt_bf59dbf74d8db275": __wbg_codePointAt_bf59dbf74d8db275,
3768
3835
  "__wbg_fromCodePoint_22365db7b7d6ac39": __wbg_fromCodePoint_22365db7b7d6ac39,
3769
- "__wbg_length_68dc7c5cf1b6d349": __wbg_length_68dc7c5cf1b6d349,
3770
3836
  "__wbg___wbindgen_in_47fa6863be6f2f25": __wbg___wbindgen_in_47fa6863be6f2f25,
3771
3837
  "__wbg___wbindgen_throw_be289d5034ed271b": __wbg___wbindgen_throw_be289d5034ed271b,
3772
3838
  "__wbg___wbindgen_is_null_ac34f5003991759a": __wbg___wbindgen_is_null_ac34f5003991759a,
@@ -3811,6 +3877,7 @@ const ast_get_functions = __vite__wasmModule.ast_get_functions;
3811
3877
  const ast_get_literals = __vite__wasmModule.ast_get_literals;
3812
3878
  const ast_get_subqueries = __vite__wasmModule.ast_get_subqueries;
3813
3879
  const ast_get_table_names = __vite__wasmModule.ast_get_table_names;
3880
+ const ast_get_tables = __vite__wasmModule.ast_get_tables;
3814
3881
  const ast_get_window_functions = __vite__wasmModule.ast_get_window_functions;
3815
3882
  const ast_node_count = __vite__wasmModule.ast_node_count;
3816
3883
  const ast_qualify_columns = __vite__wasmModule.ast_qualify_columns;
@@ -3821,6 +3888,8 @@ const ast_rename_tables = __vite__wasmModule.ast_rename_tables;
3821
3888
  const ast_rename_tables_with_options = __vite__wasmModule.ast_rename_tables_with_options;
3822
3889
  const ast_set_distinct = __vite__wasmModule.ast_set_distinct;
3823
3890
  const ast_set_limit = __vite__wasmModule.ast_set_limit;
3891
+ const ast_set_offset = __vite__wasmModule.ast_set_offset;
3892
+ const ast_set_order_by = __vite__wasmModule.ast_set_order_by;
3824
3893
  const diff_sql = __vite__wasmModule.diff_sql;
3825
3894
  const format_sql = __vite__wasmModule.format_sql;
3826
3895
  const format_sql_value = __vite__wasmModule.format_sql_value;
@@ -4013,6 +4082,7 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4013
4082
  ast_get_literals,
4014
4083
  ast_get_subqueries,
4015
4084
  ast_get_table_names,
4085
+ ast_get_tables,
4016
4086
  ast_get_window_functions,
4017
4087
  ast_node_count,
4018
4088
  ast_qualify_columns,
@@ -4023,6 +4093,8 @@ const wasm$2 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4023
4093
  ast_rename_tables_with_options,
4024
4094
  ast_set_distinct,
4025
4095
  ast_set_limit,
4096
+ ast_set_offset,
4097
+ ast_set_order_by,
4026
4098
  diff_sql,
4027
4099
  format_sql,
4028
4100
  format_sql_value,
@@ -4211,6 +4283,7 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
4211
4283
  ast_get_literals: ast_get_literals$1,
4212
4284
  ast_get_subqueries: ast_get_subqueries$1,
4213
4285
  ast_get_table_names: ast_get_table_names$1,
4286
+ ast_get_tables: ast_get_tables$1,
4214
4287
  ast_get_window_functions: ast_get_window_functions$1,
4215
4288
  ast_node_count: ast_node_count$1,
4216
4289
  ast_qualify_columns: ast_qualify_columns$1,
@@ -4221,6 +4294,8 @@ const wasmModule = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty
4221
4294
  ast_rename_tables_with_options: ast_rename_tables_with_options$1,
4222
4295
  ast_set_distinct: ast_set_distinct$1,
4223
4296
  ast_set_limit: ast_set_limit$1,
4297
+ ast_set_offset: ast_set_offset$1,
4298
+ ast_set_order_by: ast_set_order_by$1,
4224
4299
  diff_sql: diff_sql$1,
4225
4300
  format_sql: format_sql$1,
4226
4301
  format_sql_value: format_sql_value$1,
@@ -4407,6 +4482,69 @@ function parseAstResult(json) {
4407
4482
  const result = JSON.parse(json);
4408
4483
  return result.success ? JSON.parse(result.ast) : null;
4409
4484
  }
4485
+ function isQueryWithOuterClauses(node) {
4486
+ return ["select", "union", "intersect", "except"].includes(getExprType(node));
4487
+ }
4488
+ function applyLimitExpr(node, limit) {
4489
+ const type = getExprType(node);
4490
+ if (!isQueryWithOuterClauses(node)) {
4491
+ return node;
4492
+ }
4493
+ const data = getExprData(node);
4494
+ if (type === "select") {
4495
+ return makeExpr("select", {
4496
+ ...data,
4497
+ limit: { this: limit, percent: false, comments: [] }
4498
+ });
4499
+ }
4500
+ return makeExpr(type, {
4501
+ ...data,
4502
+ limit
4503
+ });
4504
+ }
4505
+ function applyOffsetExpr(node, offset) {
4506
+ const type = getExprType(node);
4507
+ if (!isQueryWithOuterClauses(node)) {
4508
+ return node;
4509
+ }
4510
+ const data = getExprData(node);
4511
+ if (type === "select") {
4512
+ return makeExpr("select", {
4513
+ ...data,
4514
+ offset: { this: offset, rows: null }
4515
+ });
4516
+ }
4517
+ return makeExpr(type, {
4518
+ ...data,
4519
+ offset
4520
+ });
4521
+ }
4522
+ function applyOrderBy(node, orderBy) {
4523
+ const type = getExprType(node);
4524
+ if (!isQueryWithOuterClauses(node)) {
4525
+ return node;
4526
+ }
4527
+ const expressions = orderBy.map((expression) => {
4528
+ if (getExprType(expression) === "ordered") {
4529
+ return getExprData(expression);
4530
+ }
4531
+ return {
4532
+ this: expression,
4533
+ desc: false,
4534
+ nulls_first: null,
4535
+ explicit_asc: false,
4536
+ with_fill: null
4537
+ };
4538
+ });
4539
+ return makeExpr(type, {
4540
+ ...getExprData(node),
4541
+ order_by: {
4542
+ expressions,
4543
+ siblings: false,
4544
+ comments: []
4545
+ }
4546
+ });
4547
+ }
4410
4548
  function transformValue(value, config, parent) {
4411
4549
  if (value === null || value === void 0) return value;
4412
4550
  if (Array.isArray(value)) {
@@ -4576,25 +4714,21 @@ function setLimit(node, limit) {
4576
4714
  const result = parseAstResult(ast_set_limit$1(exprToJson$1(node), limit));
4577
4715
  return result ?? node;
4578
4716
  }
4579
- if (getExprType(node) !== "select") {
4580
- return node;
4581
- }
4582
- const selectData = getExprData(node);
4583
- return makeExpr("select", {
4584
- ...selectData,
4585
- limit: { this: limit }
4586
- });
4717
+ return applyLimitExpr(node, limit);
4587
4718
  }
4588
4719
  function setOffset(node, offset) {
4589
- if (getExprType(node) !== "select") {
4590
- return node;
4720
+ if (typeof offset === "number") {
4721
+ const result = parseAstResult(ast_set_offset$1(exprToJson$1(node), offset));
4722
+ return result ?? node;
4591
4723
  }
4592
- const selectData = getExprData(node);
4593
- const offsetExpr = typeof offset === "number" ? makeExpr("literal", { literal_type: "number", value: String(offset) }) : offset;
4594
- return makeExpr("select", {
4595
- ...selectData,
4596
- offset: { this: offsetExpr }
4597
- });
4724
+ return applyOffsetExpr(node, offset);
4725
+ }
4726
+ function setOrderBy(node, orderBy) {
4727
+ const orderByExpressions = Array.isArray(orderBy) ? orderBy : [orderBy];
4728
+ const result = parseAstResult(
4729
+ ast_set_order_by$1(exprToJson$1(node), JSON.stringify(orderByExpressions))
4730
+ );
4731
+ return result ?? applyOrderBy(node, orderByExpressions);
4598
4732
  }
4599
4733
  function removeLimitOffset(node) {
4600
4734
  if (getExprType(node) !== "select") {
@@ -4762,7 +4896,8 @@ function getColumns(node) {
4762
4896
  return findByType(node, "column");
4763
4897
  }
4764
4898
  function getTables(node) {
4765
- return findByType(node, "table");
4899
+ const result = JSON.parse(ast_get_tables$1(exprToJson(node)));
4900
+ return result.success ? JSON.parse(result.ast) : [];
4766
4901
  }
4767
4902
  function getIdentifiers(node) {
4768
4903
  return findByType(node, "identifier");
@@ -4996,6 +5131,7 @@ const index$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4996
5131
  setDistinct,
4997
5132
  setLimit,
4998
5133
  setOffset,
5134
+ setOrderBy,
4999
5135
  some,
5000
5136
  transform,
5001
5137
  walk