@culpritsql/plans 0.5.6 → 0.5.7

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
@@ -1,28 +1,36 @@
1
- # @culpritsql/plans
1
+ <div align="center">
2
2
 
3
- Portable WebAssembly execution plan parser, comparator, deadlock parser, and exporter extracted from [Culprit SQL Studio](https://github.com/culpritsql/culprit-sql-studio).
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plans/main/assets/hero-dark.png">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plans/main/assets/hero-light.png">
6
+ <img alt="@culpritsql/plans" src="https://raw.githubusercontent.com/culpritsql/culprit-plans/main/assets/hero-light.png" width="100%">
7
+ </picture>
4
8
 
5
- Runs locally in browsers and JavaScript runtimes with zero runtime npm dependencies, no database drivers, and no network calls. TypeScript declarations are generated directly from Culprit's Rust domain model (`ts-rs`).
9
+ <br />
6
10
 
7
- ## Supported Formats
11
+ [![npm](https://img.shields.io/npm/v/%40culpritsql%2Fplans?style=flat-square&label=npm&color=ffcf33&labelColor=181715)](https://www.npmjs.com/package/@culpritsql/plans)
12
+ [![Runtime: Rust + Wasm](https://img.shields.io/badge/runtime-Rust%20%2B%20Wasm-dea584?style=flat-square&labelColor=181715)](https://webassembly.org)
13
+ [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-4cbb84?style=flat-square&labelColor=181715)](https://www.npmjs.com/package/@culpritsql/plans?activeTab=dependencies)
14
+ [![TypeScript](https://img.shields.io/badge/types-ts--rs-3178c6?style=flat-square&labelColor=181715)](https://github.com/culpritsql/culprit-sql-studio)
15
+ [![License: MIT](https://img.shields.io/badge/license-MIT-4cbb84?style=flat-square&labelColor=181715)](./LICENSE)
8
16
 
9
- | Engine | Execution Plans | Deadlocks |
10
- | --- | --- | --- |
11
- | SQL Server | XML Showplan (`.sqlplan`) | XML deadlock graphs |
12
- | PostgreSQL | `EXPLAIN (FORMAT JSON)`, `EXPLAIN (ANALYZE, BUFFERS)` text | Server log deadlock excerpts |
13
- | MySQL & MariaDB | `EXPLAIN FORMAT=JSON`, `EXPLAIN ANALYZE` tree text | `SHOW ENGINE INNODB STATUS` deadlocks |
14
- | YugabyteDB | `EXPLAIN (FORMAT JSON)`, text plans | PostgreSQL-compatible deadlock logs |
15
- | SQLite | `EXPLAIN QUERY PLAN` text | Not applicable |
17
+ **Portable WebAssembly execution plan parser, structural differ, deadlock parser, and exporter.**
18
+ <br />
19
+ Compiled directly from [Culprit SQL Studio](https://github.com/culpritsql/culprit-sql-studio) and paired with [`@culpritsql/plan-viewer`](https://github.com/culpritsql/culprit-plan-viewer).
20
+
21
+ [Quickstart](#quickstart) · [Supported Engines](#supported-engines) · [API Reference](#api-reference) · [Node.js & Bundlers](#nodejs--bundlers) · [Security & Limits](#security--limits)
16
22
 
17
- ## Install
23
+ </div>
24
+
25
+ ---
26
+
27
+ ## Quickstart
18
28
 
19
29
  ```sh
20
30
  npm install @culpritsql/plans
21
31
  ```
22
32
 
23
- ## Quickstart
24
-
25
- Initialize the WebAssembly module once, then call the synchronous operations:
33
+ Initialize the WebAssembly module once, then call the synchronous parser, comparison, deadlock, and export operations:
26
34
 
27
35
  ```ts
28
36
  import {
@@ -31,14 +39,13 @@ import {
31
39
  diffPlans,
32
40
  parseDeadlock,
33
41
  exportPlan,
34
- ParserError,
35
42
  } from "@culpritsql/plans";
36
43
 
37
44
  await init();
38
45
 
39
46
  const before = parsePlan(beforePlanText);
40
47
  const after = parsePlan(afterPlanText, "postgres");
41
- const diff = diffPlans(before, "before", after, "after");
48
+ const diff = diffPlans(before, "Before", after, "After");
42
49
 
43
50
  const deadlocks = parseDeadlock(deadlockLogText);
44
51
  const exported = exportPlan(after, "checkout-query", "markdown", {
@@ -47,9 +54,66 @@ const exported = exportPlan(after, "checkout-query", "markdown", {
47
54
  });
48
55
  ```
49
56
 
50
- ### Node.js and Custom Asset URLs
57
+ > Rendering in React? Pass `Plan`, `PlanDiff`, and `Deadlock` directly to [`@culpritsql/plan-viewer`](https://www.npmjs.com/package/@culpritsql/plan-viewer). Both packages share the exact same generated `ts-rs` model types.
58
+
59
+ ---
60
+
61
+ ## Supported Engines
62
+
63
+ | Engine | Execution Plans | Deadlocks |
64
+ | --- | --- | --- |
65
+ | **SQL Server** | `.sqlplan` Showplan XML | XML deadlock graphs |
66
+ | **PostgreSQL** | `EXPLAIN (FORMAT JSON)`, `EXPLAIN (ANALYZE, BUFFERS)` text | Server log deadlock excerpts |
67
+ | **MySQL & MariaDB** | `EXPLAIN FORMAT=JSON`, `EXPLAIN ANALYZE` tree text | `SHOW ENGINE INNODB STATUS` |
68
+ | **YugabyteDB** | `EXPLAIN (FORMAT JSON)` + DocDB RPC/storage metrics | PostgreSQL-compatible logs |
69
+ | **SQLite** | `EXPLAIN QUERY PLAN` text | Not applicable |
70
+
71
+ ---
72
+
73
+ ## API Reference
74
+
75
+ | Export | Signature | Description |
76
+ | --- | --- | --- |
77
+ | `init` | `init(input?): Promise<void>` | Instantiates the Wasm module once; subsequent calls reuse the live instance |
78
+ | `parsePlan` | `parsePlan(input: string, engine?: Engine): Plan` | Auto-detects format or validates strictly against `"mssql" \| "postgres" \| "mysql" \| "yugabyte" \| "sqlite"` |
79
+ | `diffPlans` | `diffPlans(a: Plan, nameA: string, b: Plan, nameB: string, context?: CompareContext): PlanDiff` | Computes structural operator changes, access-path flips, cardinality shifts, and speedup/cost verdicts |
80
+ | `parseDeadlock` | `parseDeadlock(input: string): Deadlock[]` | Extracts victim selection, participant sessions, held/waited locks, and original timestamps |
81
+ | `exportPlan` | `exportPlan(plan: Plan, title: string, format: ExportFormat, options: ExportOptions): ExportFile` | Exports `"markdown"`, `"html"`, or `"native"` with optional SQL literal redaction |
82
+ | `ParserError` | `class ParserError extends Error` | Structured refusal error (`error.error` carries `{ code, message, hint, detail }`) instead of Wasm traps |
83
+
84
+ ### Redacted Exports
51
85
 
52
- In browsers, `init()` resolves `culprit_wasm_bg.wasm` relative to `import.meta.url` via `fetch`. In Node.js, or when a bundler emits the `.wasm` asset at a custom URL, pass `module_or_path` explicitly:
86
+ Setting `redact: true` scrubs SQL string and numeric literals from statements, filter predicates, and native Showplan XML parameter lists before returning the file:
87
+
88
+ ```ts
89
+ const file = exportPlan(plan, "Order Lookup", "html", {
90
+ redact: true,
91
+ notes: [],
92
+ });
93
+ // file => { name: "order-lookup.html", format: "html", contents: "<!doctype html>..." }
94
+ ```
95
+
96
+ ### Structured Error Handling
97
+
98
+ Malformed XML/JSON, mismatched engine hints, DTD attempts, or over-depth trees throw `ParserError` cleanly without corrupting the Wasm instance:
99
+
100
+ ```ts
101
+ import { parsePlan, ParserError } from "@culpritsql/plans";
102
+
103
+ try {
104
+ const plan = parsePlan(untrustedInput, "postgres");
105
+ } catch (err) {
106
+ if (err instanceof ParserError) {
107
+ console.error(err.error.code, err.error.message, err.error.hint);
108
+ }
109
+ }
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Node.js & Bundlers
115
+
116
+ In browsers, `init()` resolves `culprit_wasm_bg.wasm` relative to `import.meta.url` via `fetch`. In Node.js or custom bundler setups, pass `module_or_path` explicitly:
53
117
 
54
118
  ```ts
55
119
  import { readFile } from "node:fs/promises";
@@ -66,7 +130,7 @@ await init({ module_or_path: wasmBytes });
66
130
  const plan = parsePlan("QUERY PLAN\n`--SCAN orders", "sqlite");
67
131
  ```
68
132
 
69
- With Vite or Next.js static asset imports:
133
+ With **Vite** or **Next.js** static asset URLs:
70
134
 
71
135
  ```ts
72
136
  import wasmUrl from "@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm?url";
@@ -75,45 +139,15 @@ import { init } from "@culpritsql/plans";
75
139
  await init({ module_or_path: wasmUrl });
76
140
  ```
77
141
 
78
- ## API
79
-
80
- ### `init(input?): Promise<void>`
81
-
82
- Loads and instantiates the WebAssembly module. Safe to call more than once; subsequent calls reuse the initialized instance.
83
-
84
- ### `parsePlan(input: string, engine?: Engine): Plan`
85
-
86
- Parses raw plan text into a typed `Plan` tree (`"mssql" | "postgres" | "mysql" | "yugabyte" | "sqlite"`). When `engine` is omitted, the format is detected from the input. When `engine` is provided, incompatible inputs are rejected.
87
-
88
- ### `diffPlans(a: Plan, nameA: string, b: Plan, nameB: string, context?: CompareContext): PlanDiff`
89
-
90
- Compares two parsed plans structurally and across operator estimates, actual row counts, and costs. Optional `CompareContext` supplies explicit table statistics without touching a database connection.
91
-
92
- ### `parseDeadlock(input: string): Deadlock[]`
93
-
94
- Parses native deadlock XML or server log text into typed `Deadlock` observations, preserving participant processes, held/waited locks, victim selection, and original timestamps when present.
95
-
96
- ### `exportPlan(plan: Plan, title: string, format: ExportFormat, options: ExportOptions): ExportFile`
97
-
98
- Formats a `Plan` as `"markdown"`, `"html"`, or `"native"` (`ExportFile` with `name`, `format`, `contents`). Setting `options.redact = true` scrubs SQL string and numeric literals from statements, predicates, and native XML parameters, and HTML exports escape all user and plan strings.
99
-
100
- ### `ParserError`
101
-
102
- Invalid, empty, malformed, over-depth, or mismatched inputs throw `ParserError` rather than trapping the WebAssembly instance. Inspect `.error` for the structured Culprit error (`{ code, message, hint, detail }`).
103
-
104
- ## Runtime and Security Notes
105
-
106
- - Serve `.wasm` files with `Content-Type: application/wasm`.
107
- - Under a strict Content Security Policy, include `'wasm-unsafe-eval'` in `script-src`.
108
- - XML DTD declarations and entity expansions are rejected. Inputs are bounded to 1024 nested XML elements and 56 plan operator levels.
109
- - Compressed payload size is ~1.41 MB gzip (~1.00 MB Brotli) with 108 generated TypeScript model declarations.
110
-
111
- ## Source Repository
142
+ ---
112
143
 
113
- This repository is synced automatically from [`culpritsql/culprit-sql-studio`](https://github.com/culpritsql/culprit-sql-studio) (`crates/culprit-plans`, `crates/culprit-wasm`, and `packages/culprit-wasm`).
144
+ ## Security & Limits
114
145
 
115
- - Website: [culpritsql.com](https://culpritsql.com)
116
- - Parser and engine source: [github.com/culpritsql/culprit-sql-studio](https://github.com/culpritsql/culprit-sql-studio)
146
+ - **Zero runtime dependencies**: Pure Rust compiled to `wasm32-unknown-unknown` with zero npm dependencies, no database drivers, and no network calls.
147
+ - **Hardened XML & JSON bounds**: Rejects XML `<!DOCTYPE>` / entity expansion (`XXE`) and enforces deterministic depth ceilings (`1,024` XML elements, `56` plan operator levels) on a dedicated 32 MiB Wasm linear stack.
148
+ - **HTML-safe exports**: HTML plan exports escape every identifier, predicate, and title string.
149
+ - **CSP compatibility**: Serve `.wasm` assets with `Content-Type: application/wasm` and include `'wasm-unsafe-eval'` in `script-src` under strict Content Security Policies.
150
+ - **Single source of truth**: Synced automatically from [`culpritsql/culprit-sql-studio`](https://github.com/culpritsql/culprit-sql-studio) (`crates/culprit-plans`, `crates/culprit-wasm`, `packages/culprit-wasm`).
117
151
 
118
152
  ## License
119
153
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@culpritsql/plans",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Portable WebAssembly execution plan parser, comparator, deadlock parser, and exporter for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -2832,7 +2832,7 @@ DEALINGS IN THE SOFTWARE.
2832
2832
 
2833
2833
  ----------------------------------------------------------------------------------------------------
2834
2834
  MIT License
2835
- Used by: cookie 0.18.2
2835
+ Used by: cookie 0.18.3
2836
2836
 
2837
2837
  Copyright (c) 2017 Sergio Benitez
2838
2838
  Copyright (c) 2014 Alex Crichton
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "bindgen_cli_version": "0.2.129"
14
14
  },
15
- "cargo_lock_sha256": "b75908ca6a5a76bf703f834c03baaba077d5216e31725c35dac1a1a5bd2df19f",
15
+ "cargo_lock_sha256": "b13161d22fc2692986196c3aa713342276830a970a4d10be0eb68598cddc47ca",
16
16
  "models": [
17
17
  {
18
18
  "name": "ActualSummary",
@@ -41,14 +41,19 @@
41
41
  },
42
42
  {
43
43
  "name": "CollectionTarget",
44
- "source_sha256": "6455ac83e7cdf121ab4736b99db8a4cecc2f90c8d02a85357c5562b763e6fc74",
45
- "package_sha256": "7cd0d5997416f67361bffa0ac52d0efdbeb9f02bbbeaff01acd809e907e676ab"
44
+ "source_sha256": "3eb165bc2b0022238c79bf7c1699f455fddd6f776b28b0ee880583ea952cbc5e",
45
+ "package_sha256": "3658c40df8f47f9fed380dc36a1aae77e89e9d2c9138f09d4a4e750e0f549c58"
46
46
  },
47
47
  {
48
48
  "name": "CompareContext",
49
49
  "source_sha256": "4188737bbbe0de2017e46d108eaf99cacac58201c7515123e8a47bf969c7de3d",
50
50
  "package_sha256": "2116e99cff20ae494bce38abff9d753d43d4935ffa37cec8f4368c04545a2531"
51
51
  },
52
+ {
53
+ "name": "ConfiguredConnectionIdentity",
54
+ "source_sha256": "9f80714258513488cbe64c2b89d7a208fe039024bff3d356330a952b31a8d83a",
55
+ "package_sha256": "3a2b6e58f0f7753c1350abd7ad9cf2d1e9653f2e8d0ff5af7de0c9824c1eb53f"
56
+ },
52
57
  {
53
58
  "name": "DatabaseIdentity",
54
59
  "source_sha256": "498c192dc4e4b1c65e005f0ca44cc7b0b4cb1abf260037743c16f340a17fcdf6",
@@ -573,10 +578,10 @@
573
578
  "sha256": "3bb76e45db8e62c5c0e7bc95f0f13e488dbd9649d818ca615fd513ecefb1a738"
574
579
  },
575
580
  "native/culprit_wasm_bg.wasm": {
576
- "bytes": 4693928,
577
- "gzip_bytes": 1410395,
578
- "brotli_bytes": 1001381,
579
- "sha256": "d3afb72175fc9bf04db4908a89bc06c634041cf6e567c6a8adb2fffb1d780a61"
581
+ "bytes": 4794869,
582
+ "gzip_bytes": 1437444,
583
+ "brotli_bytes": 1021868,
584
+ "sha256": "ca16659cf13960eba9648691acfa738710c682824f19e703c1f44a4520461244"
580
585
  }
581
586
  },
582
587
  "native_or_database_work": false
@@ -1,5 +1,6 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { ConfiguredConnectionIdentity } from "./ConfiguredConnectionIdentity.js";
2
3
  import type { DatabaseIdentity } from "./DatabaseIdentity.js";
3
4
  import type { SharedResourceIdentity } from "./SharedResourceIdentity.js";
4
5
 
5
- export type CollectionTarget = { "scope": "database", "identity": DatabaseIdentity } | { "scope": "shared", "identity": SharedResourceIdentity };
6
+ export type CollectionTarget = { "scope": "database", "identity": DatabaseIdentity } | { "scope": "shared", "identity": SharedResourceIdentity } | { "scope": "configured-connection", "identity": ConfiguredConnectionIdentity };
@@ -0,0 +1,7 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { Engine } from "./Engine.js";
3
+
4
+ /**
5
+ * Frozen saved metadata only. This target establishes no database, replica, session or native member identity.
6
+ */
7
+ export type ConfiguredConnectionIdentity = { id: string, route_revision: string, name: string, engine: Engine, };
Binary file