@culpritsql/plans 0.0.0-stage → 0.5.6

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.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -2
  3. package/package.json +46 -4
  4. package/pkg/THIRD-PARTY-LICENSES.txt +9021 -0
  5. package/pkg/build-report.json +583 -0
  6. package/pkg/index.d.ts +26 -0
  7. package/pkg/index.js +37 -0
  8. package/pkg/models/ActualSummary.d.ts +16 -0
  9. package/pkg/models/CachedStatementContext.d.ts +9 -0
  10. package/pkg/models/CachedStatementIdentity.d.ts +7 -0
  11. package/pkg/models/ChangeKind.d.ts +3 -0
  12. package/pkg/models/CollectionStop.d.ts +3 -0
  13. package/pkg/models/CollectionTarget.d.ts +5 -0
  14. package/pkg/models/CompareContext.d.ts +12 -0
  15. package/pkg/models/DatabaseIdentity.d.ts +5 -0
  16. package/pkg/models/DatabaseLocation.d.ts +3 -0
  17. package/pkg/models/Deadlock.d.ts +23 -0
  18. package/pkg/models/DeadlockFix.d.ts +16 -0
  19. package/pkg/models/DeadlockFixKind.d.ts +6 -0
  20. package/pkg/models/DeadlockPattern.d.ts +3 -0
  21. package/pkg/models/DeadlockProcess.d.ts +23 -0
  22. package/pkg/models/DeadlockResource.d.ts +12 -0
  23. package/pkg/models/DeliveryProblem.d.ts +3 -0
  24. package/pkg/models/DocdbMetrics.d.ts +7 -0
  25. package/pkg/models/Engine.d.ts +3 -0
  26. package/pkg/models/Error.d.ts +5 -0
  27. package/pkg/models/ErrorCode.d.ts +3 -0
  28. package/pkg/models/ErrorDetail.d.ts +10 -0
  29. package/pkg/models/ExecutionProtection.d.ts +3 -0
  30. package/pkg/models/ExportFile.d.ts +7 -0
  31. package/pkg/models/ExportFormat.d.ts +3 -0
  32. package/pkg/models/ExportNote.d.ts +11 -0
  33. package/pkg/models/ExportOptions.d.ts +12 -0
  34. package/pkg/models/Guess.d.ts +6 -0
  35. package/pkg/models/InsightArea.d.ts +6 -0
  36. package/pkg/models/LexError.d.ts +6 -0
  37. package/pkg/models/LockHolder.d.ts +3 -0
  38. package/pkg/models/Metric.d.ts +10 -0
  39. package/pkg/models/MssqlCatalogIndexColumn.d.ts +3 -0
  40. package/pkg/models/MssqlCurrentTableType.d.ts +10 -0
  41. package/pkg/models/MssqlCurrentTypeColumn.d.ts +7 -0
  42. package/pkg/models/MssqlCurrentTypeIndex.d.ts +4 -0
  43. package/pkg/models/MssqlCurrentTypeModule.d.ts +4 -0
  44. package/pkg/models/MssqlCurrentTypeParameter.d.ts +3 -0
  45. package/pkg/models/MssqlCurrentTypeSchema.d.ts +11 -0
  46. package/pkg/models/MssqlCurrentTypeSchemaStatus.d.ts +3 -0
  47. package/pkg/models/MssqlIndexParentKind.d.ts +3 -0
  48. package/pkg/models/MssqlObjectIdentity.d.ts +7 -0
  49. package/pkg/models/NativeIdentity.d.ts +3 -0
  50. package/pkg/models/NativePlanIdentity.d.ts +4 -0
  51. package/pkg/models/NativeQueryIdentity.d.ts +3 -0
  52. package/pkg/models/NativeReadContext.d.ts +13 -0
  53. package/pkg/models/NodeKind.d.ts +3 -0
  54. package/pkg/models/NodeMatch.d.ts +3 -0
  55. package/pkg/models/NodeRuntime.d.ts +28 -0
  56. package/pkg/models/OutboxProblem.d.ts +3 -0
  57. package/pkg/models/Plan.d.ts +11 -0
  58. package/pkg/models/PlanAccessRows.d.ts +13 -0
  59. package/pkg/models/PlanAutomaticIndex.d.ts +3 -0
  60. package/pkg/models/PlanChange.d.ts +17 -0
  61. package/pkg/models/PlanChangedColumn.d.ts +3 -0
  62. package/pkg/models/PlanConversion.d.ts +4 -0
  63. package/pkg/models/PlanConversionIssue.d.ts +3 -0
  64. package/pkg/models/PlanCurrentTypeSchemaView.d.ts +6 -0
  65. package/pkg/models/PlanDiff.d.ts +13 -0
  66. package/pkg/models/PlanExecutionMode.d.ts +3 -0
  67. package/pkg/models/PlanFacts.d.ts +36 -0
  68. package/pkg/models/PlanIndexColumns.d.ts +3 -0
  69. package/pkg/models/PlanIndexHint.d.ts +3 -0
  70. package/pkg/models/PlanInsight.d.ts +44 -0
  71. package/pkg/models/PlanInsightShare.d.ts +3 -0
  72. package/pkg/models/PlanInsights.d.ts +8 -0
  73. package/pkg/models/PlanKind.d.ts +3 -0
  74. package/pkg/models/PlanMeasurementRef.d.ts +3 -0
  75. package/pkg/models/PlanMemoryGrantFeedback.d.ts +15 -0
  76. package/pkg/models/PlanMemoryGrantFeedbackIssue.d.ts +3 -0
  77. package/pkg/models/PlanMemoryGrantFeedbackState.d.ts +3 -0
  78. package/pkg/models/PlanNode.d.ts +7 -0
  79. package/pkg/models/PlanNodeFacts.d.ts +63 -0
  80. package/pkg/models/PlanOperatorView.d.ts +5 -0
  81. package/pkg/models/PlanPageServerIo.d.ts +16 -0
  82. package/pkg/models/PlanPageServerIoIssue.d.ts +4 -0
  83. package/pkg/models/PlanPageServerIoView.d.ts +7 -0
  84. package/pkg/models/PlanPageServerMetric.d.ts +3 -0
  85. package/pkg/models/PlanParameter.d.ts +10 -0
  86. package/pkg/models/PlanParameterComparison.d.ts +3 -0
  87. package/pkg/models/PlanParameterContext.d.ts +15 -0
  88. package/pkg/models/PlanParameterIssue.d.ts +3 -0
  89. package/pkg/models/PlanParameterUse.d.ts +4 -0
  90. package/pkg/models/PlanParameterUseKind.d.ts +3 -0
  91. package/pkg/models/PlanParameterValueState.d.ts +3 -0
  92. package/pkg/models/PlanParentRelationship.d.ts +3 -0
  93. package/pkg/models/PlanRegion.d.ts +7 -0
  94. package/pkg/models/PlanSampleSource.d.ts +6 -0
  95. package/pkg/models/PlanScanCompletion.d.ts +8 -0
  96. package/pkg/models/PlanScanThread.d.ts +3 -0
  97. package/pkg/models/PlanTemporaryTableUse.d.ts +7 -0
  98. package/pkg/models/PlanView.d.ts +9 -0
  99. package/pkg/models/PlanWarning.d.ts +3 -0
  100. package/pkg/models/RelationalInput.d.ts +5 -0
  101. package/pkg/models/RelationalInputKind.d.ts +3 -0
  102. package/pkg/models/RelationalInputProvenance.d.ts +3 -0
  103. package/pkg/models/RetainedPlanProvenance.d.ts +11 -0
  104. package/pkg/models/Scenario.d.ts +11 -0
  105. package/pkg/models/ScenarioKind.d.ts +3 -0
  106. package/pkg/models/Severity.d.ts +3 -0
  107. package/pkg/models/SharedResourceIdentity.d.ts +11 -0
  108. package/pkg/models/SharedResourceKind.d.ts +3 -0
  109. package/pkg/models/SourcePartition.d.ts +8 -0
  110. package/pkg/models/StatementOrigin.d.ts +6 -0
  111. package/pkg/models/StatementProblem.d.ts +4 -0
  112. package/pkg/models/StatisticsInfo.d.ts +3 -0
  113. package/pkg/models/TriggerTiming.d.ts +3 -0
  114. package/pkg/models/Unit.d.ts +3 -0
  115. package/pkg/models/WorkerSkew.d.ts +3 -0
  116. package/pkg/native/culprit_wasm.d.ts +49 -0
  117. package/pkg/native/culprit_wasm.js +378 -0
  118. package/pkg/native/culprit_wasm_bg.wasm +0 -0
  119. package/pkg/native/culprit_wasm_bg.wasm.d.ts +11 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cristian Pufu
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,120 @@
1
- # Temporary Holding Version
1
+ # @culpritsql/plans
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Portable WebAssembly execution plan parser, comparator, deadlock parser, and exporter extracted from [Culprit SQL Studio](https://github.com/culpritsql/culprit-sql-studio).
4
+
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`).
6
+
7
+ ## Supported Formats
8
+
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 |
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install @culpritsql/plans
21
+ ```
22
+
23
+ ## Quickstart
24
+
25
+ Initialize the WebAssembly module once, then call the synchronous operations:
26
+
27
+ ```ts
28
+ import {
29
+ init,
30
+ parsePlan,
31
+ diffPlans,
32
+ parseDeadlock,
33
+ exportPlan,
34
+ ParserError,
35
+ } from "@culpritsql/plans";
36
+
37
+ await init();
38
+
39
+ const before = parsePlan(beforePlanText);
40
+ const after = parsePlan(afterPlanText, "postgres");
41
+ const diff = diffPlans(before, "before", after, "after");
42
+
43
+ const deadlocks = parseDeadlock(deadlockLogText);
44
+ const exported = exportPlan(after, "checkout-query", "markdown", {
45
+ redact: true,
46
+ notes: [],
47
+ });
48
+ ```
49
+
50
+ ### Node.js and Custom Asset URLs
51
+
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:
53
+
54
+ ```ts
55
+ import { readFile } from "node:fs/promises";
56
+ import { init, parsePlan } from "@culpritsql/plans";
57
+
58
+ const wasmBytes = await readFile(
59
+ new URL(
60
+ "./node_modules/@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm",
61
+ import.meta.url,
62
+ ),
63
+ );
64
+ await init({ module_or_path: wasmBytes });
65
+
66
+ const plan = parsePlan("QUERY PLAN\n`--SCAN orders", "sqlite");
67
+ ```
68
+
69
+ With Vite or Next.js static asset imports:
70
+
71
+ ```ts
72
+ import wasmUrl from "@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm?url";
73
+ import { init } from "@culpritsql/plans";
74
+
75
+ await init({ module_or_path: wasmUrl });
76
+ ```
77
+
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
112
+
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`).
114
+
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)
117
+
118
+ ## License
119
+
120
+ MIT. Third-party Rust crate notices are distributed in `pkg/THIRD-PARTY-LICENSES.txt`.
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@culpritsql/plans",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.6",
4
+ "description": "Portable WebAssembly execution plan parser, comparator, deadlock parser, and exporter for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "pkg"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./pkg/index.d.ts",
14
+ "import": "./pkg/index.js"
15
+ }
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/culpritsql/culprit-plans.git"
20
+ },
21
+ "homepage": "https://culpritsql.com",
22
+ "bugs": {
23
+ "url": "https://github.com/culpritsql/culprit-plans/issues"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "provenance": true
28
+ },
29
+ "keywords": [
30
+ "sql",
31
+ "execution-plan",
32
+ "query-plan",
33
+ "explain",
34
+ "showplan",
35
+ "sqlplan",
36
+ "deadlock",
37
+ "wasm",
38
+ "webassembly",
39
+ "postgres",
40
+ "postgresql",
41
+ "mssql",
42
+ "sql-server",
43
+ "mysql",
44
+ "mariadb",
45
+ "yugabytedb",
46
+ "sqlite"
47
+ ]
48
+ }