sqlscope-rs 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +108 -2
- package/dist/api.d.ts +126 -0
- package/dist/api.js +96 -0
- package/dist/engine.d.ts +51 -0
- package/dist/engine.js +88 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +21 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +5 -0
- package/package.json +51 -4
- package/wasm/sqlscope_wasm.d.ts +47 -0
- package/wasm/sqlscope_wasm.js +234 -0
- package/wasm/sqlscope_wasm_bg.wasm +0 -0
- package/wasm/sqlscope_wasm_bg.wasm.d.ts +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dcalsky
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sqlscope-rs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scope-aware SQL analysis and rewriting for TypeScript and JavaScript: row
|
|
4
|
+
filters, CTE injection, table rewrites and column lineage over 30+ SQL
|
|
5
|
+
dialects. It runs [sqlscope](https://github.com/dcalsky/sqlscope) (Rust, built
|
|
6
|
+
on the [polyglot](https://github.com/tobilg/polyglot) SQL engine) as a
|
|
7
|
+
WebAssembly module bundled in the package: no native library, no install
|
|
8
|
+
scripts.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install sqlscope-rs
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Function | Purpose |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `applyRowFilter` | Filter every in-scope table by a predicate (row-level security). |
|
|
17
|
+
| `injectCtes` | Prepend CTE definitions to a query's root `WITH`. |
|
|
18
|
+
| `rewriteTables` | Replace table references with derived tables. |
|
|
19
|
+
| `columnOrigins` | Source columns whose values reach the result (column lineage). |
|
|
20
|
+
| `outputColumns` | Names of the columns a statement outputs. |
|
|
21
|
+
| `referencedColumns` | Columns referenced anywhere (filters included), per table. |
|
|
22
|
+
| `columnUsages` | Column references together with the clause they appear in. |
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { applyRowFilter, columnOrigins, columnUsages, injectCtes, rewriteTables } from "sqlscope-rs";
|
|
28
|
+
|
|
29
|
+
applyRowFilter("SELECT id FROM orders", "tenant_id = 7", { dialect: "postgres" });
|
|
30
|
+
// 'SELECT id FROM (SELECT * FROM orders WHERE tenant_id = 7) AS orders'
|
|
31
|
+
|
|
32
|
+
applyRowFilter("SELECT * FROM a JOIN b ON a.id = b.id", "tenant_id = 7", { tableNames: ["a"] });
|
|
33
|
+
|
|
34
|
+
columnOrigins(
|
|
35
|
+
"SELECT o.id, p.amount FROM orders o JOIN payments p ON o.id = p.order_id WHERE o.status = 'PAID'",
|
|
36
|
+
);
|
|
37
|
+
// { orders: ['id'], payments: ['amount'] }
|
|
38
|
+
|
|
39
|
+
columnOrigins("SELECT * FROM orders", { schema: { orders: ["id", "status"] } });
|
|
40
|
+
// { orders: ['id', 'status'] }
|
|
41
|
+
|
|
42
|
+
columnUsages("SELECT id FROM orders WHERE status = 'PAID'");
|
|
43
|
+
// [{ table: 'orders', column: 'id', clause: 'SELECT' },
|
|
44
|
+
// { table: 'orders', column: 'status', clause: 'WHERE' }]
|
|
45
|
+
|
|
46
|
+
injectCtes("SELECT * FROM foo", [{ name: "foo", query: "SELECT id FROM t" }]);
|
|
47
|
+
// 'WITH foo AS (SELECT id FROM t) SELECT * FROM foo'
|
|
48
|
+
|
|
49
|
+
rewriteTables("SELECT col1 FROM myschema.mytable", [
|
|
50
|
+
{ matchKey: "myschema.mytable", inline: { table: "view1", schema: "vsch" } },
|
|
51
|
+
]);
|
|
52
|
+
// 'SELECT col1 FROM (SELECT * FROM vsch.view1) AS mytable'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Every function is synchronous. Options:
|
|
56
|
+
|
|
57
|
+
| Option | Read by |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `dialect` | all (default `"trino"`; `"postgres"`, `"mysql"`, `"spark"`, `"snowflake"`, `"bigquery"`, ...) |
|
|
60
|
+
| `schema` | `columnOrigins`, `outputColumns`, `referencedColumns`, `columnUsages` |
|
|
61
|
+
| `tableNames`, `tablePatterns`, `defaultDb` | `applyRowFilter` |
|
|
62
|
+
| `stripCatalogs` | `rewriteTables` |
|
|
63
|
+
|
|
64
|
+
`schema` maps table names (bare, `schema.table` or `catalog.schema.table`) to
|
|
65
|
+
their ordered columns, as an object or a `Map`.
|
|
66
|
+
|
|
67
|
+
Errors are thrown as `InvalidArgumentError`, `ParseError`, `UnsupportedError`
|
|
68
|
+
or `InternalError`, all subclasses of `SqlscopeError`.
|
|
69
|
+
|
|
70
|
+
The [sqlscope README](https://github.com/dcalsky/sqlscope#operations)
|
|
71
|
+
describes each operation in detail.
|
|
72
|
+
|
|
73
|
+
## Runtimes
|
|
74
|
+
|
|
75
|
+
**Node.js (≥ 20.19), Deno and Bun** load the WebAssembly module when the
|
|
76
|
+
package is imported (`import` or `require`); just call the functions.
|
|
77
|
+
|
|
78
|
+
**Browsers, workers and edge runtimes** load it asynchronously: `await init()`
|
|
79
|
+
once before calling anything else.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { init, outputColumns } from "sqlscope-rs";
|
|
83
|
+
|
|
84
|
+
await init(); // fetches sqlscope.wasm next to the package
|
|
85
|
+
outputColumns("SELECT a, b FROM t");
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`init()` resolves `sqlscope.wasm` with `new URL(..., import.meta.url)`, which
|
|
89
|
+
webpack, Rollup and esbuild handle. With Vite, import the module's URL
|
|
90
|
+
explicitly:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { init } from "sqlscope-rs";
|
|
94
|
+
import wasmUrl from "sqlscope-rs/sqlscope.wasm?url";
|
|
95
|
+
|
|
96
|
+
await init(wasmUrl);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`init` also accepts a `Response`, the bytes, or a compiled
|
|
100
|
+
`WebAssembly.Module`; `initSync(bytes)` loads synchronously. Calling `init()`
|
|
101
|
+
under Node.js is harmless, so the same code runs everywhere.
|
|
102
|
+
|
|
103
|
+
The module is about 9 MB (2.5 MB gzipped). V8 compiles it lazily; under
|
|
104
|
+
sustained load its optimizing compiler can hold several hundred MB of
|
|
105
|
+
optimized code. Run Node.js with `--liftoff-only` to trade speed for memory.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Table name (bare, `schema.table` or `catalog.schema.table`) -> ordered column names. */
|
|
2
|
+
export type Schema = Readonly<Record<string, readonly string[]>> | ReadonlyMap<string, readonly string[]>;
|
|
3
|
+
/** One name, or several. */
|
|
4
|
+
export type Names = string | Iterable<string>;
|
|
5
|
+
/** Options accepted by every operation. */
|
|
6
|
+
export interface DialectOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The SQL dialect: "trino" (the default), "postgres", "mysql", "starrocks",
|
|
9
|
+
* "spark", "hive", "snowflake", "bigquery", "duckdb", ...
|
|
10
|
+
*/
|
|
11
|
+
dialect?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Options of the analysis operations. */
|
|
14
|
+
export interface SchemaOptions extends DialectOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Table schemas. They expand wildcards and attribute unqualified columns.
|
|
17
|
+
* A table listed with no columns has zero columns; an absent table is
|
|
18
|
+
* unknown.
|
|
19
|
+
*/
|
|
20
|
+
schema?: Schema;
|
|
21
|
+
}
|
|
22
|
+
/** Options of {@link applyRowFilter}. */
|
|
23
|
+
export interface RowFilterOptions extends DialectOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Filter only these tables: bare (`orders`), schema-qualified
|
|
26
|
+
* (`sales.orders`) or catalog-qualified (`iceberg.sales.orders`), matched
|
|
27
|
+
* case-insensitively. Composes additively with `tablePatterns`.
|
|
28
|
+
*/
|
|
29
|
+
tableNames?: Names;
|
|
30
|
+
/** Filter only tables whose bare or fully qualified name matches one of these regular expressions. */
|
|
31
|
+
tablePatterns?: Names;
|
|
32
|
+
/** The schema of unqualified table references, matched against schema-qualified `tableNames`. */
|
|
33
|
+
defaultDb?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Options of {@link rewriteTables}. */
|
|
36
|
+
export interface RewriteOptions extends DialectOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Catalogs that are transparent while matching: with `["hive"]`,
|
|
39
|
+
* `hive.sales.orders` matches the match key `sales.orders`.
|
|
40
|
+
*/
|
|
41
|
+
stripCatalogs?: Names;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A common table expression `name AS (query)`.
|
|
45
|
+
*
|
|
46
|
+
* `name` is an identifier value, not SQL text; it is quoted as needed.
|
|
47
|
+
*/
|
|
48
|
+
export interface CteDef {
|
|
49
|
+
name: string;
|
|
50
|
+
query: string;
|
|
51
|
+
}
|
|
52
|
+
/** A table name, optionally schema- and catalog-qualified. */
|
|
53
|
+
export interface TableRef {
|
|
54
|
+
table: string;
|
|
55
|
+
schema?: string;
|
|
56
|
+
catalog?: string;
|
|
57
|
+
}
|
|
58
|
+
/** A derived table backed by `UNION DISTINCT` over `branches`. */
|
|
59
|
+
export interface UnionRewrite {
|
|
60
|
+
/** The alias used for references without an alias of their own. */
|
|
61
|
+
tableAlias: string;
|
|
62
|
+
columns: readonly string[];
|
|
63
|
+
branches: readonly TableRef[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Replaces references to `matchKey` (`schema.table`). Set exactly one of
|
|
67
|
+
* `inline`, which becomes `(SELECT * FROM inline)`, or `union`.
|
|
68
|
+
*/
|
|
69
|
+
export interface TableRewrite {
|
|
70
|
+
matchKey: string;
|
|
71
|
+
inline?: TableRef;
|
|
72
|
+
union?: UnionRewrite;
|
|
73
|
+
}
|
|
74
|
+
/** The SQL clause that contains a column reference. */
|
|
75
|
+
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";
|
|
76
|
+
/** One distinct use of a root table column in a clause. */
|
|
77
|
+
export interface ColumnUsage {
|
|
78
|
+
table: string;
|
|
79
|
+
column: string;
|
|
80
|
+
clause: Clause;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Wrap every in-scope table of a query in a derived table filtered by `predicate`.
|
|
84
|
+
*
|
|
85
|
+
* `SELECT * FROM a` becomes `SELECT * FROM (SELECT * FROM a WHERE <predicate>) AS a`.
|
|
86
|
+
* By default every physical table is filtered; `tableNames`, `tablePatterns`
|
|
87
|
+
* and `defaultDb` restrict the scope. CTE references, table functions and
|
|
88
|
+
* `DUAL` are never wrapped. `predicate` is parsed as one boolean expression;
|
|
89
|
+
* bind or escape its values before calling. Returns the input unchanged when
|
|
90
|
+
* no table is in scope.
|
|
91
|
+
*/
|
|
92
|
+
export declare function applyRowFilter(sql: string, predicate: string, options?: RowFilterOptions): string;
|
|
93
|
+
/**
|
|
94
|
+
* Add CTE definitions to the root `WITH` of a query, before existing CTEs.
|
|
95
|
+
*
|
|
96
|
+
* Definitions keep their order, so each may use earlier ones. A name that
|
|
97
|
+
* repeats another definition or an existing root CTE is rejected.
|
|
98
|
+
*/
|
|
99
|
+
export declare function injectCtes(sql: string, ctes: Iterable<CteDef | readonly [name: string, query: string]>, options?: DialectOptions): string;
|
|
100
|
+
/**
|
|
101
|
+
* Replace physical table references according to `rewrites`.
|
|
102
|
+
*
|
|
103
|
+
* Matched references become derived tables that keep their alias (or bare
|
|
104
|
+
* name); qualified column references are rebound onto it. Returns the input
|
|
105
|
+
* unchanged when nothing matches.
|
|
106
|
+
*/
|
|
107
|
+
export declare function rewriteTables(sql: string, rewrites: Iterable<TableRewrite>, options?: RewriteOptions): string;
|
|
108
|
+
/**
|
|
109
|
+
* Source columns whose values flow into the result, keyed by root table.
|
|
110
|
+
*
|
|
111
|
+
* Filter-only positions (WHERE, JOIN ON, GROUP BY, HAVING, ORDER BY) and the
|
|
112
|
+
* right side of INTERSECT / EXCEPT are excluded. Every table read is present,
|
|
113
|
+
* possibly with an empty list.
|
|
114
|
+
*/
|
|
115
|
+
export declare function columnOrigins(sql: string, options?: SchemaOptions): Record<string, string[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Names of the columns a statement outputs, in order.
|
|
118
|
+
*
|
|
119
|
+
* Unaliased expressions are named `_col{i}`; `*` expands from `schema` or
|
|
120
|
+
* stays `"*"`. Returns `null` for statements without columns.
|
|
121
|
+
*/
|
|
122
|
+
export declare function outputColumns(sql: string, options?: SchemaOptions): string[] | null;
|
|
123
|
+
/** Columns referenced anywhere in a statement (including filters), keyed by root table. */
|
|
124
|
+
export declare function referencedColumns(sql: string, options?: SchemaOptions): Record<string, string[]>;
|
|
125
|
+
/** Every distinct `(table, column, clause)` use in a statement, sorted. */
|
|
126
|
+
export declare function columnUsages(sql: string, options?: SchemaOptions): ColumnUsage[];
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The sqlscope operations.
|
|
2
|
+
import { call } from "./engine.js";
|
|
3
|
+
function names(values) {
|
|
4
|
+
if (values === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
return typeof values === "string" ? [values] : Array.from(values);
|
|
7
|
+
}
|
|
8
|
+
function schema(value) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
return value instanceof Map ? Object.fromEntries(value) : value;
|
|
12
|
+
}
|
|
13
|
+
function table(ref) {
|
|
14
|
+
return { table: ref.table, schema: ref.schema, catalog: ref.catalog };
|
|
15
|
+
}
|
|
16
|
+
/** Calls `operation`; undefined fields and options are omitted. */
|
|
17
|
+
function run(operation, sql, fields, options) {
|
|
18
|
+
return call(operation, { sql, ...fields, options });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Wrap every in-scope table of a query in a derived table filtered by `predicate`.
|
|
22
|
+
*
|
|
23
|
+
* `SELECT * FROM a` becomes `SELECT * FROM (SELECT * FROM a WHERE <predicate>) AS a`.
|
|
24
|
+
* By default every physical table is filtered; `tableNames`, `tablePatterns`
|
|
25
|
+
* and `defaultDb` restrict the scope. CTE references, table functions and
|
|
26
|
+
* `DUAL` are never wrapped. `predicate` is parsed as one boolean expression;
|
|
27
|
+
* bind or escape its values before calling. Returns the input unchanged when
|
|
28
|
+
* no table is in scope.
|
|
29
|
+
*/
|
|
30
|
+
export function applyRowFilter(sql, predicate, options = {}) {
|
|
31
|
+
return run("apply_row_filter", sql, { predicate }, {
|
|
32
|
+
dialect: options.dialect,
|
|
33
|
+
tableNames: names(options.tableNames),
|
|
34
|
+
tablePatterns: names(options.tablePatterns),
|
|
35
|
+
defaultDb: options.defaultDb,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add CTE definitions to the root `WITH` of a query, before existing CTEs.
|
|
40
|
+
*
|
|
41
|
+
* Definitions keep their order, so each may use earlier ones. A name that
|
|
42
|
+
* repeats another definition or an existing root CTE is rejected.
|
|
43
|
+
*/
|
|
44
|
+
export function injectCtes(sql, ctes, options = {}) {
|
|
45
|
+
const defs = Array.from(ctes, (cte) => "name" in cte ? { name: cte.name, query: cte.query } : { name: cte[0], query: cte[1] });
|
|
46
|
+
return run("inject_ctes", sql, { ctes: defs }, { dialect: options.dialect });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Replace physical table references according to `rewrites`.
|
|
50
|
+
*
|
|
51
|
+
* Matched references become derived tables that keep their alias (or bare
|
|
52
|
+
* name); qualified column references are rebound onto it. Returns the input
|
|
53
|
+
* unchanged when nothing matches.
|
|
54
|
+
*/
|
|
55
|
+
export function rewriteTables(sql, rewrites, options = {}) {
|
|
56
|
+
const plan = Array.from(rewrites, (rewrite) => ({
|
|
57
|
+
matchKey: rewrite.matchKey,
|
|
58
|
+
inline: rewrite.inline && table(rewrite.inline),
|
|
59
|
+
union: rewrite.union && {
|
|
60
|
+
tableAlias: rewrite.union.tableAlias,
|
|
61
|
+
columns: Array.from(rewrite.union.columns),
|
|
62
|
+
branches: Array.from(rewrite.union.branches, table),
|
|
63
|
+
},
|
|
64
|
+
}));
|
|
65
|
+
return run("rewrite_tables", sql, { rewrites: plan }, { dialect: options.dialect, stripCatalogs: names(options.stripCatalogs) });
|
|
66
|
+
}
|
|
67
|
+
function analyze(operation, sql, options) {
|
|
68
|
+
return run(operation, sql, {}, { dialect: options.dialect, schema: schema(options.schema) });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Source columns whose values flow into the result, keyed by root table.
|
|
72
|
+
*
|
|
73
|
+
* Filter-only positions (WHERE, JOIN ON, GROUP BY, HAVING, ORDER BY) and the
|
|
74
|
+
* right side of INTERSECT / EXCEPT are excluded. Every table read is present,
|
|
75
|
+
* possibly with an empty list.
|
|
76
|
+
*/
|
|
77
|
+
export function columnOrigins(sql, options = {}) {
|
|
78
|
+
return analyze("column_origins", sql, options);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Names of the columns a statement outputs, in order.
|
|
82
|
+
*
|
|
83
|
+
* Unaliased expressions are named `_col{i}`; `*` expands from `schema` or
|
|
84
|
+
* stays `"*"`. Returns `null` for statements without columns.
|
|
85
|
+
*/
|
|
86
|
+
export function outputColumns(sql, options = {}) {
|
|
87
|
+
return analyze("output_columns", sql, options);
|
|
88
|
+
}
|
|
89
|
+
/** Columns referenced anywhere in a statement (including filters), keyed by root table. */
|
|
90
|
+
export function referencedColumns(sql, options = {}) {
|
|
91
|
+
return analyze("referenced_columns", sql, options);
|
|
92
|
+
}
|
|
93
|
+
/** Every distinct `(table, column, clause)` use in a statement, sorted. */
|
|
94
|
+
export function columnUsages(sql, options = {}) {
|
|
95
|
+
return analyze("column_usages", sql, options);
|
|
96
|
+
}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Base class of every sqlscope error. */
|
|
2
|
+
export declare class SqlscopeError extends Error {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
/** An option or argument is invalid. */
|
|
6
|
+
export declare class InvalidArgumentError extends SqlscopeError {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
/** The SQL text could not be parsed. */
|
|
10
|
+
export declare class ParseError extends SqlscopeError {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
/** The statement shape is not supported, or the input exceeded a safety limit. */
|
|
14
|
+
export declare class UnsupportedError extends SqlscopeError {
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/** sqlscope produced an invalid result or crashed (a bug). */
|
|
18
|
+
export declare class InternalError extends SqlscopeError {
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
/** The bytes of the WebAssembly module. */
|
|
22
|
+
export type WasmBytes = ArrayBuffer | ArrayBufferView;
|
|
23
|
+
/** A `Response` to the WebAssembly module, such as `fetch(url)` returns. */
|
|
24
|
+
export interface WasmResponse {
|
|
25
|
+
readonly url: string;
|
|
26
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
27
|
+
}
|
|
28
|
+
/** A compiled `WebAssembly.Module`. */
|
|
29
|
+
export type WasmModule = typeof globalThis extends {
|
|
30
|
+
WebAssembly: {
|
|
31
|
+
Module: abstract new (...args: never) => infer M;
|
|
32
|
+
};
|
|
33
|
+
} ? M : never;
|
|
34
|
+
/** What {@link init} accepts: a URL or response to fetch, the bytes, or a compiled module. */
|
|
35
|
+
export type WasmSource = string | URL | WasmResponse | WasmBytes | WasmModule;
|
|
36
|
+
/**
|
|
37
|
+
* Load the WebAssembly module. Resolves immediately when it is loaded.
|
|
38
|
+
*
|
|
39
|
+
* Under Node.js (and Deno and Bun) the module is loaded when the package is
|
|
40
|
+
* imported, so calling `init` is never needed. Elsewhere, await it once before
|
|
41
|
+
* any other call. Without `source` it fetches `sqlscope.wasm` next to the
|
|
42
|
+
* package, which bundlers resolve; pass a URL or the bytes to serve it from
|
|
43
|
+
* somewhere else.
|
|
44
|
+
*/
|
|
45
|
+
export declare function init(source?: WasmSource | Promise<WasmSource>): Promise<void>;
|
|
46
|
+
/** Load the WebAssembly module synchronously from its bytes or a compiled module. */
|
|
47
|
+
export declare function initSync(source: WasmBytes | WasmModule): void;
|
|
48
|
+
/** The sqlscope version of the WebAssembly module ("X.Y.Z"). */
|
|
49
|
+
export declare function version(): string;
|
|
50
|
+
/** Run one operation and return its decoded result, throwing on error. */
|
|
51
|
+
export declare function call(operation: string, request: object): unknown;
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Runs operations on the sqlscope WebAssembly module.
|
|
2
|
+
import initWasm, { call as wasmCall, initSync as initWasmSync, version as wasmVersion } from "../wasm/sqlscope_wasm.js";
|
|
3
|
+
/** Base class of every sqlscope error. */
|
|
4
|
+
export class SqlscopeError extends Error {
|
|
5
|
+
name = "SqlscopeError";
|
|
6
|
+
}
|
|
7
|
+
/** An option or argument is invalid. */
|
|
8
|
+
export class InvalidArgumentError extends SqlscopeError {
|
|
9
|
+
name = "InvalidArgumentError";
|
|
10
|
+
}
|
|
11
|
+
/** The SQL text could not be parsed. */
|
|
12
|
+
export class ParseError extends SqlscopeError {
|
|
13
|
+
name = "ParseError";
|
|
14
|
+
}
|
|
15
|
+
/** The statement shape is not supported, or the input exceeded a safety limit. */
|
|
16
|
+
export class UnsupportedError extends SqlscopeError {
|
|
17
|
+
name = "UnsupportedError";
|
|
18
|
+
}
|
|
19
|
+
/** sqlscope produced an invalid result or crashed (a bug). */
|
|
20
|
+
export class InternalError extends SqlscopeError {
|
|
21
|
+
name = "InternalError";
|
|
22
|
+
}
|
|
23
|
+
const ERRORS = {
|
|
24
|
+
invalid_argument: InvalidArgumentError,
|
|
25
|
+
parse: ParseError,
|
|
26
|
+
unsupported: UnsupportedError,
|
|
27
|
+
};
|
|
28
|
+
let ready = false;
|
|
29
|
+
let pending;
|
|
30
|
+
/**
|
|
31
|
+
* Load the WebAssembly module. Resolves immediately when it is loaded.
|
|
32
|
+
*
|
|
33
|
+
* Under Node.js (and Deno and Bun) the module is loaded when the package is
|
|
34
|
+
* imported, so calling `init` is never needed. Elsewhere, await it once before
|
|
35
|
+
* any other call. Without `source` it fetches `sqlscope.wasm` next to the
|
|
36
|
+
* package, which bundlers resolve; pass a URL or the bytes to serve it from
|
|
37
|
+
* somewhere else.
|
|
38
|
+
*/
|
|
39
|
+
export function init(source) {
|
|
40
|
+
if (ready)
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
const input = source === undefined ? undefined : { module_or_path: source };
|
|
43
|
+
pending ??= initWasm(input).then(() => {
|
|
44
|
+
ready = true;
|
|
45
|
+
}, (error) => {
|
|
46
|
+
pending = undefined;
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
return pending;
|
|
50
|
+
}
|
|
51
|
+
/** Load the WebAssembly module synchronously from its bytes or a compiled module. */
|
|
52
|
+
export function initSync(source) {
|
|
53
|
+
if (ready)
|
|
54
|
+
return;
|
|
55
|
+
initWasmSync({ module: source });
|
|
56
|
+
ready = true;
|
|
57
|
+
}
|
|
58
|
+
function engine() {
|
|
59
|
+
if (!ready) {
|
|
60
|
+
throw new SqlscopeError("sqlscope is not initialized: await init() before calling it");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** The sqlscope version of the WebAssembly module ("X.Y.Z"). */
|
|
64
|
+
export function version() {
|
|
65
|
+
engine();
|
|
66
|
+
return wasmVersion();
|
|
67
|
+
}
|
|
68
|
+
/** Run one operation and return its decoded result, throwing on error. */
|
|
69
|
+
export function call(operation, request) {
|
|
70
|
+
engine();
|
|
71
|
+
let text;
|
|
72
|
+
try {
|
|
73
|
+
text = wasmCall(operation, JSON.stringify(request));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
// A panic traps; the module may be unusable afterwards.
|
|
77
|
+
if (error instanceof WebAssembly.RuntimeError) {
|
|
78
|
+
throw new InternalError(`sqlscope crashed: ${error.message}`, { cause: error });
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
const response = JSON.parse(text);
|
|
83
|
+
if ("error" in response) {
|
|
84
|
+
const { kind, message } = response.error;
|
|
85
|
+
throw new (ERRORS[kind] ?? InternalError)(message);
|
|
86
|
+
}
|
|
87
|
+
return response.ok;
|
|
88
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope-aware SQL analysis and rewriting.
|
|
3
|
+
*
|
|
4
|
+
* | Function | Purpose |
|
|
5
|
+
* | --- | --- |
|
|
6
|
+
* | {@link applyRowFilter} | Filter every in-scope table by a predicate. |
|
|
7
|
+
* | {@link injectCtes} | Prepend CTE definitions to a query's root `WITH`. |
|
|
8
|
+
* | {@link rewriteTables} | Replace table references with derived tables. |
|
|
9
|
+
* | {@link columnOrigins} | Source columns whose values reach the result (lineage). |
|
|
10
|
+
* | {@link outputColumns} | Names of the columns a statement outputs. |
|
|
11
|
+
* | {@link referencedColumns} | Columns referenced anywhere, per table. |
|
|
12
|
+
* | {@link columnUsages} | Column references with the clause they appear in. |
|
|
13
|
+
*
|
|
14
|
+
* The SQL engine is a WebAssembly module shipped in this package. Node.js,
|
|
15
|
+
* Deno and Bun load it on import; browsers and other runtimes `await init()`
|
|
16
|
+
* first.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
export * from "./api.js";
|
|
21
|
+
export { InternalError, InvalidArgumentError, ParseError, SqlscopeError, UnsupportedError, init, initSync, version, } from "./engine.js";
|
|
22
|
+
export type { WasmBytes, WasmModule, WasmResponse, WasmSource } from "./engine.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope-aware SQL analysis and rewriting.
|
|
3
|
+
*
|
|
4
|
+
* | Function | Purpose |
|
|
5
|
+
* | --- | --- |
|
|
6
|
+
* | {@link applyRowFilter} | Filter every in-scope table by a predicate. |
|
|
7
|
+
* | {@link injectCtes} | Prepend CTE definitions to a query's root `WITH`. |
|
|
8
|
+
* | {@link rewriteTables} | Replace table references with derived tables. |
|
|
9
|
+
* | {@link columnOrigins} | Source columns whose values reach the result (lineage). |
|
|
10
|
+
* | {@link outputColumns} | Names of the columns a statement outputs. |
|
|
11
|
+
* | {@link referencedColumns} | Columns referenced anywhere, per table. |
|
|
12
|
+
* | {@link columnUsages} | Column references with the clause they appear in. |
|
|
13
|
+
*
|
|
14
|
+
* The SQL engine is a WebAssembly module shipped in this package. Node.js,
|
|
15
|
+
* Deno and Bun load it on import; browsers and other runtimes `await init()`
|
|
16
|
+
* first.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
export * from "./api.js";
|
|
21
|
+
export { InternalError, InvalidArgumentError, ParseError, SqlscopeError, UnsupportedError, init, initSync, version, } from "./engine.js";
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./index.js";
|
package/dist/node.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlscope-rs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Scope-aware SQL analysis and rewriting: row filters, CTE injection, table rewrites, column lineage.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sql",
|
|
7
|
+
"lineage",
|
|
8
|
+
"row-level-security",
|
|
9
|
+
"parser",
|
|
10
|
+
"wasm"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "dcalsky <dcalsky@gmail.com>",
|
|
14
|
+
"homepage": "https://github.com/dcalsky/sqlscope",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/dcalsky/sqlscope.git",
|
|
18
|
+
"directory": "typescript"
|
|
19
|
+
},
|
|
20
|
+
"bugs": "https://github.com/dcalsky/sqlscope/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"node": "./dist/node.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./sqlscope.wasm": "./wasm/sqlscope_wasm_bg.wasm",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"wasm/sqlscope_wasm.js",
|
|
35
|
+
"wasm/sqlscope_wasm.d.ts",
|
|
36
|
+
"wasm/sqlscope_wasm_bg.wasm",
|
|
37
|
+
"wasm/sqlscope_wasm_bg.wasm.d.ts"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.19"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build:wasm": "make -C .. build-wasm",
|
|
44
|
+
"build": "tsc -p tsconfig.build.json",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "node --test \"test/*.test.ts\"",
|
|
47
|
+
"prepack": "node -e \"require('fs').accessSync('wasm/sqlscope_wasm_bg.wasm')\" && npm run build"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^24.19.1",
|
|
51
|
+
"typescript": "^5.9.3"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Runs `operation` on the JSON `request` and returns the JSON response.
|
|
6
|
+
*/
|
|
7
|
+
export function call(operation: string, request: string): string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The sqlscope version ("X.Y.Z").
|
|
11
|
+
*/
|
|
12
|
+
export function version(): string;
|
|
13
|
+
|
|
14
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
15
|
+
|
|
16
|
+
export interface InitOutput {
|
|
17
|
+
readonly memory: WebAssembly.Memory;
|
|
18
|
+
readonly call: (a: number, b: number, c: number, d: number) => [number, number];
|
|
19
|
+
readonly version: () => [number, number];
|
|
20
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
21
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
22
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
23
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
24
|
+
readonly __wbindgen_start: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
31
|
+
* a precompiled `WebAssembly.Module`.
|
|
32
|
+
*
|
|
33
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
34
|
+
*
|
|
35
|
+
* @returns {InitOutput}
|
|
36
|
+
*/
|
|
37
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
41
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
42
|
+
*
|
|
43
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
44
|
+
*
|
|
45
|
+
* @returns {Promise<InitOutput>}
|
|
46
|
+
*/
|
|
47
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/* @ts-self-types="./sqlscope_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs `operation` on the JSON `request` and returns the JSON response.
|
|
5
|
+
* @param {string} operation
|
|
6
|
+
* @param {string} request
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
export function call(operation, request) {
|
|
10
|
+
let deferred3_0;
|
|
11
|
+
let deferred3_1;
|
|
12
|
+
try {
|
|
13
|
+
const ptr0 = passStringToWasm0(operation, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
14
|
+
const len0 = WASM_VECTOR_LEN;
|
|
15
|
+
const ptr1 = passStringToWasm0(request, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
16
|
+
const len1 = WASM_VECTOR_LEN;
|
|
17
|
+
const ret = wasm.call(ptr0, len0, ptr1, len1);
|
|
18
|
+
deferred3_0 = ret[0];
|
|
19
|
+
deferred3_1 = ret[1];
|
|
20
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
21
|
+
} finally {
|
|
22
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The sqlscope version ("X.Y.Z").
|
|
28
|
+
* @returns {string}
|
|
29
|
+
*/
|
|
30
|
+
export function version() {
|
|
31
|
+
let deferred1_0;
|
|
32
|
+
let deferred1_1;
|
|
33
|
+
try {
|
|
34
|
+
const ret = wasm.version();
|
|
35
|
+
deferred1_0 = ret[0];
|
|
36
|
+
deferred1_1 = ret[1];
|
|
37
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
38
|
+
} finally {
|
|
39
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function __wbg_get_imports() {
|
|
43
|
+
const import0 = {
|
|
44
|
+
__proto__: null,
|
|
45
|
+
__wbindgen_init_externref_table: function() {
|
|
46
|
+
const table = wasm.__wbindgen_externrefs;
|
|
47
|
+
const offset = table.grow(4);
|
|
48
|
+
table.set(0, undefined);
|
|
49
|
+
table.set(offset + 0, undefined);
|
|
50
|
+
table.set(offset + 1, null);
|
|
51
|
+
table.set(offset + 2, true);
|
|
52
|
+
table.set(offset + 3, false);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
__proto__: null,
|
|
57
|
+
"./sqlscope_wasm_bg.js": import0,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getStringFromWasm0(ptr, len) {
|
|
62
|
+
return decodeText(ptr >>> 0, len);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let cachedUint8ArrayMemory0 = null;
|
|
66
|
+
function getUint8ArrayMemory0() {
|
|
67
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
68
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
69
|
+
}
|
|
70
|
+
return cachedUint8ArrayMemory0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
74
|
+
if (realloc === undefined) {
|
|
75
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
76
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
77
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
78
|
+
WASM_VECTOR_LEN = buf.length;
|
|
79
|
+
return ptr;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let len = arg.length;
|
|
83
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
84
|
+
|
|
85
|
+
const mem = getUint8ArrayMemory0();
|
|
86
|
+
|
|
87
|
+
let offset = 0;
|
|
88
|
+
|
|
89
|
+
for (; offset < len; offset++) {
|
|
90
|
+
const code = arg.charCodeAt(offset);
|
|
91
|
+
if (code > 0x7F) break;
|
|
92
|
+
mem[ptr + offset] = code;
|
|
93
|
+
}
|
|
94
|
+
if (offset !== len) {
|
|
95
|
+
if (offset !== 0) {
|
|
96
|
+
arg = arg.slice(offset);
|
|
97
|
+
}
|
|
98
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
99
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
100
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
101
|
+
|
|
102
|
+
offset += ret.written;
|
|
103
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
WASM_VECTOR_LEN = offset;
|
|
107
|
+
return ptr;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
111
|
+
cachedTextDecoder.decode();
|
|
112
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
113
|
+
let numBytesDecoded = 0;
|
|
114
|
+
function decodeText(ptr, len) {
|
|
115
|
+
numBytesDecoded += len;
|
|
116
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
117
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
118
|
+
cachedTextDecoder.decode();
|
|
119
|
+
numBytesDecoded = len;
|
|
120
|
+
}
|
|
121
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const cachedTextEncoder = new TextEncoder();
|
|
125
|
+
|
|
126
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
127
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
128
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
129
|
+
view.set(buf);
|
|
130
|
+
return {
|
|
131
|
+
read: arg.length,
|
|
132
|
+
written: buf.length
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let WASM_VECTOR_LEN = 0;
|
|
138
|
+
|
|
139
|
+
let wasmModule, wasmInstance, wasm;
|
|
140
|
+
function __wbg_finalize_init(instance, module) {
|
|
141
|
+
wasmInstance = instance;
|
|
142
|
+
wasm = instance.exports;
|
|
143
|
+
wasmModule = module;
|
|
144
|
+
cachedUint8ArrayMemory0 = null;
|
|
145
|
+
wasm.__wbindgen_start();
|
|
146
|
+
return wasm;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function __wbg_load(module, imports) {
|
|
150
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
151
|
+
if (!module.ok) {
|
|
152
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
156
|
+
try {
|
|
157
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
const validResponse = expectedResponseType(module.type);
|
|
160
|
+
|
|
161
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
162
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
163
|
+
|
|
164
|
+
} else { throw e; }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const bytes = await module.arrayBuffer();
|
|
169
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
170
|
+
} else {
|
|
171
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
172
|
+
|
|
173
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
174
|
+
return { instance, module };
|
|
175
|
+
} else {
|
|
176
|
+
return instance;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function expectedResponseType(type) {
|
|
181
|
+
switch (type) {
|
|
182
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function initSync(module) {
|
|
189
|
+
if (wasm !== undefined) return wasm;
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if (module !== undefined) {
|
|
193
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
194
|
+
({module} = module)
|
|
195
|
+
} else {
|
|
196
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const imports = __wbg_get_imports();
|
|
201
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
202
|
+
module = new WebAssembly.Module(module);
|
|
203
|
+
}
|
|
204
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
205
|
+
return __wbg_finalize_init(instance, module);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function __wbg_init(module_or_path) {
|
|
209
|
+
if (wasm !== undefined) return wasm;
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if (module_or_path !== undefined) {
|
|
213
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
214
|
+
({module_or_path} = module_or_path)
|
|
215
|
+
} else {
|
|
216
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (module_or_path === undefined) {
|
|
221
|
+
module_or_path = new URL('sqlscope_wasm_bg.wasm', import.meta.url);
|
|
222
|
+
}
|
|
223
|
+
const imports = __wbg_get_imports();
|
|
224
|
+
|
|
225
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
226
|
+
module_or_path = fetch(module_or_path);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
230
|
+
|
|
231
|
+
return __wbg_finalize_init(instance, module);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const call: (a: number, b: number, c: number, d: number) => [number, number];
|
|
5
|
+
export const version: () => [number, number];
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
8
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
9
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
10
|
+
export const __wbindgen_start: () => void;
|