sqlscope-rs 0.5.0 → 0.6.0

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 CHANGED
@@ -15,7 +15,7 @@ npm install sqlscope-rs
15
15
  | --- | --- |
16
16
  | `applyRowFilter` | Filter every in-scope table by a predicate (row-level security). |
17
17
  | `injectCtes` | Prepend CTE definitions to a query's root `WITH`. |
18
- | `rewriteTables` | Replace table references with derived tables. |
18
+ | `rewriteTables` | Replace table references with other tables or derived tables. |
19
19
  | `columnOrigins` | Source columns whose values reach the result (column lineage). |
20
20
  | `outputColumns` | Names of the columns a statement outputs. |
21
21
  | `referencedColumns` | Columns referenced anywhere (filters included), per table. |
package/dist/api.d.ts CHANGED
@@ -64,12 +64,16 @@ export interface UnionRewrite {
64
64
  }
65
65
  /**
66
66
  * Replaces references to `matchKey` (`schema.table`). Set exactly one of
67
- * `inline`, which becomes `(SELECT * FROM inline)`, or `union`.
67
+ * `inline`, `union`, or `rename`.
68
68
  */
69
69
  export interface TableRewrite {
70
70
  matchKey: string;
71
71
  inline?: TableRef;
72
72
  union?: UnionRewrite;
73
+ /** Column names for inline; an empty list selects all columns. */
74
+ columns?: readonly string[];
75
+ /** Replace the table name directly. */
76
+ rename?: TableRef;
73
77
  }
74
78
  /** The SQL clause that contains a column reference. */
75
79
  export type Clause = "SELECT" | "FROM" | "JOIN_ON" | "JOIN_USING" | "WHERE" | "GROUP_BY" | "HAVING" | "QUALIFY" | "WINDOW" | "ORDER_BY" | "SORT_BY" | "DISTRIBUTE_BY" | "CLUSTER_BY" | "CONNECT_BY" | "LATERAL_VIEW" | "UPDATE_SET_TARGET" | "UPDATE_SET_VALUE" | "MERGE_ON" | "MERGE_WHEN" | "RETURNING";
@@ -101,7 +105,7 @@ export declare function injectCtes(sql: string, ctes: Iterable<CteDef | readonly
101
105
  /**
102
106
  * Replace physical table references according to `rewrites`.
103
107
  *
104
- * Matched references become derived tables that keep their alias (or bare
108
+ * Matched references keep their alias (or bare
105
109
  * name); qualified column references are rebound onto it. Returns the input
106
110
  * unchanged when nothing matches.
107
111
  */
package/dist/api.js CHANGED
@@ -49,7 +49,7 @@ export function injectCtes(sql, ctes, options = {}) {
49
49
  /**
50
50
  * Replace physical table references according to `rewrites`.
51
51
  *
52
- * Matched references become derived tables that keep their alias (or bare
52
+ * Matched references keep their alias (or bare
53
53
  * name); qualified column references are rebound onto it. Returns the input
54
54
  * unchanged when nothing matches.
55
55
  */
@@ -57,6 +57,8 @@ export function rewriteTables(sql, rewrites, options = {}) {
57
57
  const plan = Array.from(rewrites, (rewrite) => ({
58
58
  matchKey: rewrite.matchKey,
59
59
  inline: rewrite.inline && table(rewrite.inline),
60
+ rename: rewrite.rename && table(rewrite.rename),
61
+ columns: rewrite.columns,
60
62
  union: rewrite.union && {
61
63
  tableAlias: rewrite.union.tableAlias,
62
64
  columns: Array.from(rewrite.union.columns),
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * | --- | --- |
6
6
  * | {@link applyRowFilter} | Filter every in-scope table by a predicate. |
7
7
  * | {@link injectCtes} | Prepend CTE definitions to a query's root `WITH`. |
8
- * | {@link rewriteTables} | Replace table references with derived tables. |
8
+ * | {@link rewriteTables} | Replace table references with other tables or derived tables. |
9
9
  * | {@link columnOrigins} | Source columns whose values reach the result (lineage). |
10
10
  * | {@link outputColumns} | Names of the columns a statement outputs. |
11
11
  * | {@link referencedColumns} | Columns referenced anywhere, per table. |
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * | --- | --- |
6
6
  * | {@link applyRowFilter} | Filter every in-scope table by a predicate. |
7
7
  * | {@link injectCtes} | Prepend CTE definitions to a query's root `WITH`. |
8
- * | {@link rewriteTables} | Replace table references with derived tables. |
8
+ * | {@link rewriteTables} | Replace table references with other tables or derived tables. |
9
9
  * | {@link columnOrigins} | Source columns whose values reach the result (lineage). |
10
10
  * | {@link outputColumns} | Names of the columns a statement outputs. |
11
11
  * | {@link referencedColumns} | Columns referenced anywhere, per table. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlscope-rs",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Scope-aware SQL analysis and rewriting: row filters, CTE injection, table rewrites, column lineage.",
5
5
  "keywords": [
6
6
  "sql",
Binary file