@culpritsql/test 0.0.0-stage → 0.0.1

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 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,132 @@
1
- # Temporary Holding Version
1
+ <div align="center">
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
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-test/main/assets/hero-dark.png">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-test/main/assets/hero-light.png">
6
+ <img alt="@culpritsql/test" src="https://raw.githubusercontent.com/culpritsql/culprit-test/main/assets/hero-light.png" width="100%">
7
+ </picture>
8
+
9
+ <br />
10
+
11
+ [![npm](https://img.shields.io/npm/v/%40culpritsql%2Ftest?style=flat-square&label=npm&color=ffcf33&labelColor=181715)](https://www.npmjs.com/package/@culpritsql/test)
12
+ [![Engine: @culpritsql/plans](https://img.shields.io/badge/parser-Rust%20%2B%20Wasm-dea584?style=flat-square&labelColor=181715)](https://www.npmjs.com/package/@culpritsql/plans)
13
+ [![Driver Deps: 0](https://img.shields.io/badge/driver%20deps-0-4cbb84?style=flat-square&labelColor=181715)](https://www.npmjs.com/package/@culpritsql/test?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)
16
+
17
+ **Execution plan regression assertions, Vitest/Jest matchers, and safe `EXPLAIN` runners for CI.**
18
+ <br />
19
+ Powered by [`@culpritsql/plans`](https://github.com/culpritsql/culprit-plans) and paired with [`@culpritsql/plan-viewer`](https://github.com/culpritsql/culprit-plan-viewer).
20
+
21
+ [Quickstart](#quickstart) · [Matchers](#matchers) · [Supported Drivers](#supported-drivers) · [Standalone Assertions](#standalone-assertions) · [Safety & Security](#safety--security)
22
+
23
+ </div>
24
+
25
+ ---
26
+
27
+ ## Quickstart
28
+
29
+ ```sh
30
+ npm install -D @culpritsql/test
31
+ ```
32
+
33
+ Register `culpritMatchers` once in your Vitest, Jest, or Bun test setup, then assert directly against live `EXPLAIN` queries from raw SQL, **Reylo** `.sql` modules, or **Drizzle / Kysely / Knex** builders:
34
+
35
+ ```ts
36
+ import { expect, test } from "vitest";
37
+ import { culpritMatchers, explain, explainText } from "@culpritsql/test";
38
+ import getRecentOrders from "./queries/getRecentOrders.sql";
39
+
40
+ expect.extend(culpritMatchers);
41
+
42
+ test("checkout orders query uses composite index without spills", async () => {
43
+ // Works with Reylo { sql } modules, Drizzle/Kysely .toSQL(), or raw SQL strings
44
+ const plan = await explain(pgPool, getRecentOrders, ["shipped"], {
45
+ analyze: true, // Runs EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) inside BEGIN READ ONLY ... ROLLBACK
46
+ });
47
+
48
+ expect(plan).toUseIndex("orders_status_created_idx");
49
+ expect(plan).not.toScanTable("orders");
50
+ expect(plan).toHaveZeroSpills();
51
+ expect(plan).toHaveZeroWarnings();
52
+ expect(plan).toReadAtMostPages(250);
53
+ });
54
+
55
+ test("candidate plan does not regress from golden baseline", async () => {
56
+ const baseline = await explainText(baselinePlanJson, "postgres");
57
+ const candidate = await explain(
58
+ pgPool,
59
+ db.select().from(orders).where(eq(orders.status, "shipped")).limit(20),
60
+ );
61
+
62
+ expect(candidate).toNotRegressFrom(baseline, { maxCostRatio: 1.2 });
63
+ });
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Matchers
69
+
70
+ Every matcher supports `.not` negation and prints rich failure diagnostics with the offending node ID, operator, target relation, row estimates/actuals, and engine index hints.
71
+
72
+ | Matcher | Inspects | Typical CI Guard |
73
+ | --- | --- | --- |
74
+ | `toUseIndex(name?: string \| RegExp)` | `Index Scan`, `Index Seek`, `Index Only Scan`, `Bitmap Index Scan`, MySQL index lookups, SQLite `SEARCH ... USING INDEX` | `expect(plan).toUseIndex("orders_customer_idx")` |
75
+ | `toScanTable(table?: string \| RegExp)` | `Seq Scan`, `Table Scan`, `Clustered Index Scan`, MySQL `ALL`, SQLite `SCAN` without index | `expect(plan).not.toScanTable("orders")` |
76
+ | `toHaveZeroSpills()` | `runtime.spill_pages`, `facts.sort_on_disk`, `facts.exchange_spill`, hash batches, disk sort properties, and `"spill"` warnings | `expect(plan).toHaveZeroSpills()` |
77
+ | `toCostLessThan(maxTotalCost)` | `plan.total_cost` | `expect(plan).toCostLessThan(500)` |
78
+ | `toCompleteWithin(maxElapsedMs)` | `plan.facts.elapsed_ms` (measured runtime) | `expect(plan).toCompleteWithin(25)` |
79
+ | `toReadAtMostPages(maxLogicalReads)` | Total `runtime.logical_reads` across all plan nodes | `expect(plan).toReadAtMostPages(100)` |
80
+ | `toHaveZeroWarnings()` | `plan.warnings`, node warnings, and `facts.conversions` (`CONVERT_IMPLICIT` / seek-blocking casts) | `expect(plan).toHaveZeroWarnings()` |
81
+ | `toNotRegressFrom(baseline, opts?)` | Structural `diffPlans()` access-path flips (`seek` to `scan`) and `cost_ratio` spikes | `expect(plan).toNotRegressFrom(baseline)` |
82
+
83
+ ---
84
+
85
+ ## Supported Drivers
86
+
87
+ `@culpritsql/test` carries **zero database driver dependencies**. It inspects structural client capabilities at runtime or respects an explicit `options.engine` override:
88
+
89
+ | Engine | Client Libraries | Default Command | With `{ analyze: true }` |
90
+ | --- | --- | --- | --- |
91
+ | **PostgreSQL & YugabyteDB** | `pg` (`Pool` / `Client`), `postgres.js`, `Bun.sql` | `EXPLAIN (FORMAT JSON)` | `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)` inside `BEGIN READ ONLY ... ROLLBACK` |
92
+ | **MySQL & MariaDB** | `mysql2/promise` (`Pool` / `Connection`) | `EXPLAIN FORMAT=JSON` | `EXPLAIN ANALYZE` |
93
+ | **SQLite** | `better-sqlite3`, `node:sqlite`, `bun:sqlite`, LibSQL, Cloudflare D1 | `EXPLAIN QUERY PLAN` (formatted to tree text) | `EXPLAIN QUERY PLAN` |
94
+ | **SQL Server** | Offline `.sqlplan` XML via `explainText(xml, "mssql")` | Native Showplan XML | Actual Showplan XML (`RunTimeInformation`) |
95
+
96
+ ### Query Input Adapters
97
+
98
+ - **Raw SQL**: `explain(pool, "SELECT * FROM orders WHERE customer_id = $1", [42])`
99
+ - **Named Parameters**: `explain(pool, "SELECT * FROM orders WHERE status = :status", { status: "shipped" })`
100
+ - **Reylo `.sql` Modules**: `explain(pool, { sql: "SELECT * FROM orders WHERE id = $1" }, [42])`
101
+ - **Drizzle / Kysely / Knex**: `explain(pool, queryBuilder)` (automatically extracts `.toSQL()`)
102
+
103
+ ---
104
+
105
+ ## Standalone Assertions
106
+
107
+ Running outside Vitest or Jest (for example in `node:test`, custom migration gates, or CI scripts)? Use `assertPlan(plan)` for a zero-framework fluent API:
108
+
109
+ ```ts
110
+ import { assertPlan, explainText } from "@culpritsql/test";
111
+
112
+ const plan = await explainText(sqlplanXml, "mssql");
113
+
114
+ assertPlan(plan)
115
+ .toUseIndex("ix_customers_email")
116
+ .not.toScanTable("customers")
117
+ .toHaveZeroSpills()
118
+ .toHaveZeroWarnings()
119
+ .toCostLessThan(1.0);
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Safety & Security
125
+
126
+ - **Read-only rollback protection**: On PostgreSQL and YugabyteDB, `{ analyze: true }` pins a dedicated session (`pool.connect()`, `sql.reserve()`, or `sql.begin()`) and wraps `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)` inside `BEGIN READ ONLY ... ROLLBACK`. Drivers without session-pinned transaction control are refused unless `{ allowMutatingAnalyze: true }` is set explicitly.
127
+ - **Single-statement SQL guard**: A lexical SQL scanner validates non-empty queries and rejects multi-statement `;` injection attempts while leaving quoted strings, PostgreSQL `$$` dollar quotes, `::type` casts, and SQL comments intact.
128
+ - **Hardened WebAssembly parser**: Plan and diff operations run inside `@culpritsql/plans` with deterministic XML/JSON depth bounds and XXE/DTD refusal.
129
+
130
+ ## License
131
+
132
+ MIT.
@@ -0,0 +1,67 @@
1
+ import { type Plan, type PlanNode } from "./wasm.js";
2
+ export interface RegressionOptions {
3
+ /**
4
+ * Maximum allowed `candidateCost / baselineCost` ratio when both plans report comparable
5
+ * optimizer costs. Defaults to `1.25` (25% cost increase tolerance).
6
+ */
7
+ maxCostRatio?: number;
8
+ /**
9
+ * Allow selective index access (`seek`) to flip into a scan (`Seq Scan`, `Table Scan`,
10
+ * `Clustered Index Scan`, `Index Scan`, SQLite `SCAN`) without failing. Defaults to `false`.
11
+ */
12
+ allowScanFlip?: boolean;
13
+ }
14
+ export interface AssertionEvaluation {
15
+ pass: boolean;
16
+ positiveMessage: string;
17
+ negatedMessage: string;
18
+ }
19
+ /** Error thrown when a standalone `assertPlan(plan)` assertion fails. */
20
+ export declare class PlanAssertionError extends Error {
21
+ readonly plan: Plan;
22
+ constructor(message: string, plan: Plan);
23
+ }
24
+ export declare function assertIsPlan(value: unknown): asserts value is Plan;
25
+ /** Collects every `PlanNode` in pre-order traversal starting at `plan.root`. */
26
+ export declare function collectPlanNodes(plan: Plan): PlanNode[];
27
+ /** Formats a single `PlanNode` with id, operator, object, index, row counts, and cost. */
28
+ export declare function formatNodeDiagnostic(node: PlanNode): string;
29
+ /**
30
+ * Returns true if `node` uses an index (`Index Scan`, `Index Seek`, `Index Only Scan`,
31
+ * `Bitmap Index Scan`, MySQL index lookups, or SQLite `SEARCH/SCAN ... USING [COVERING] INDEX`).
32
+ */
33
+ export declare function isIndexAccessNode(node: PlanNode): boolean;
34
+ /**
35
+ * Returns true if `node` performs a full table or clustered index scan (`Seq Scan`, `Table Scan`,
36
+ * `Clustered Index Scan`, MySQL `ALL`, or SQLite `SCAN` without an index).
37
+ */
38
+ export declare function isFullTableScanNode(node: PlanNode): boolean;
39
+ export declare function evaluateToUseIndex(plan: Plan, indexName?: string | RegExp): AssertionEvaluation;
40
+ export declare function evaluateToScanTable(plan: Plan, tableName?: string | RegExp): AssertionEvaluation;
41
+ export declare function evaluateToHaveZeroSpills(plan: Plan): AssertionEvaluation;
42
+ export declare function evaluateToCostLessThan(plan: Plan, maxTotalCost: number): AssertionEvaluation;
43
+ export declare function evaluateToCompleteWithin(plan: Plan, maxElapsedMs: number): AssertionEvaluation;
44
+ export declare function evaluateToReadAtMostPages(plan: Plan, maxLogicalReads: number): AssertionEvaluation;
45
+ export declare function evaluateToHaveZeroWarnings(plan: Plan): AssertionEvaluation;
46
+ export declare function evaluateToNotRegressFrom(candidatePlan: Plan, baselinePlan: Plan, opts?: RegressionOptions): AssertionEvaluation;
47
+ /**
48
+ * Fluent framework-agnostic assertion wrapper for a parsed `Plan`.
49
+ * Supports chaining and single-step `.not` negation (`assertPlan(plan).not.toScanTable("orders").toUseIndex("idx")`).
50
+ */
51
+ export declare class PlanAssertions {
52
+ #private;
53
+ constructor(plan: Plan, negated?: boolean, positiveSelf?: PlanAssertions);
54
+ /** Negates the next assertion in the chain. */
55
+ get not(): PlanAssertions;
56
+ toUseIndex(indexName?: string | RegExp): PlanAssertions;
57
+ toScanTable(tableName?: string | RegExp): PlanAssertions;
58
+ toHaveZeroSpills(): PlanAssertions;
59
+ toCostLessThan(maxTotalCost: number): PlanAssertions;
60
+ toCompleteWithin(maxElapsedMs: number): PlanAssertions;
61
+ toReadAtMostPages(maxLogicalReads: number): PlanAssertions;
62
+ toHaveZeroWarnings(): PlanAssertions;
63
+ toNotRegressFrom(baselinePlan: Plan, opts?: RegressionOptions): PlanAssertions;
64
+ }
65
+ /** Creates a fluent, framework-agnostic assertion chain for a `@culpritsql/plans` `Plan`. */
66
+ export declare function assertPlan(plan: Plan): PlanAssertions;
67
+ //# sourceMappingURL=assertions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EAET,KAAK,QAAQ,EAEd,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,yEAAyE;AACzE,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;gBAER,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI;CAKxC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO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;IAOtE,+CAA+C;IAC/C,IAAI,GAAG,IAAI,cAAc,CAExB;IAaD,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc;IAIvD,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc;IAIxD,gBAAgB,IAAI,cAAc;IAIlC,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc;IAIpD,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc;IAItD,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,cAAc;IAI1D,kBAAkB,IAAI,cAAc;IAIpC,gBAAgB,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,cAAc;CAG/E;AAED,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,cAAc,CAErD"}
@@ -0,0 +1,94 @@
1
+ import { type QueryInput, type QueryParams } from "./query.js";
2
+ import { type Engine, type Plan } from "./wasm.js";
3
+ /** `pg` PoolClient checked out from `pool.connect()`. */
4
+ export interface PgPoolClientLike {
5
+ query(text: string, values?: unknown[]): Promise<{
6
+ rows: Record<string, unknown>[];
7
+ }>;
8
+ release(err?: unknown): void;
9
+ }
10
+ /** `pg` Pool or Client shape. */
11
+ export interface PgClientLike {
12
+ query(text: string, values?: unknown[]): Promise<{
13
+ rows: Record<string, unknown>[];
14
+ }>;
15
+ connect?(): Promise<PgPoolClientLike | void>;
16
+ totalCount?: number;
17
+ idleCount?: number;
18
+ processID?: number;
19
+ supportsTransactions?: boolean;
20
+ }
21
+ /** Reserved connection or transaction handle for `postgres.js` / `Bun.sql`. */
22
+ export interface UnsafeTxLike {
23
+ unsafe(query: string, params?: unknown[]): Promise<unknown[]>;
24
+ release?(): void | Promise<void>;
25
+ }
26
+ /** `postgres.js` or `Bun.sql` client shape. */
27
+ export interface PostgresUnsafeClientLike {
28
+ unsafe(query: string, params?: unknown[]): Promise<unknown[]>;
29
+ reserve?(): Promise<UnsafeTxLike>;
30
+ begin?<T>(callback: (tx: UnsafeTxLike) => Promise<T>): Promise<T>;
31
+ }
32
+ /** `mysql2/promise` Pool or Connection shape. */
33
+ export interface Mysql2ClientLike {
34
+ query(sql: string, values?: unknown[]): Promise<unknown>;
35
+ execute?(sql: string, values?: unknown[]): Promise<unknown>;
36
+ }
37
+ /** Prepared statement shape for `better-sqlite3`, `node:sqlite`, `bun:sqlite`, or Cloudflare D1. */
38
+ export interface SqlitePreparedStatementLike {
39
+ all(...params: unknown[]): unknown;
40
+ bind?(...params: unknown[]): SqlitePreparedStatementLike;
41
+ }
42
+ /** SQLite client shape (`better-sqlite3`, `node:sqlite`, `bun:sqlite`, `sqlite`, LibSQL, Cloudflare D1). */
43
+ export type SqliteClientLike = {
44
+ prepare(sql: string): SqlitePreparedStatementLike;
45
+ batch?: unknown;
46
+ } | {
47
+ all(sql: string, params?: unknown[]): unknown;
48
+ } | {
49
+ execute(stmt: {
50
+ sql: string;
51
+ args?: unknown[];
52
+ } | string): Promise<{
53
+ rows: unknown[];
54
+ }>;
55
+ };
56
+ /** Union of all zero-dependency database client shapes supported by `explain()`. */
57
+ export type SupportedDriverClient = PgClientLike | PostgresUnsafeClientLike | Mysql2ClientLike | SqliteClientLike | ((...args: never[]) => unknown);
58
+ export interface ExplainOptions {
59
+ /** Override engine auto-detection (`"postgres" | "yugabyte" | "mysql" | "sqlite" | "mssql"`). */
60
+ engine?: Engine;
61
+ /**
62
+ * Execute the query (`EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)` on PostgreSQL/YugabyteDB,
63
+ * `EXPLAIN ANALYZE` on MySQL 8+). On PostgreSQL/YugabyteDB, wraps execution in a safe
64
+ * `BEGIN READ ONLY ... ROLLBACK` transaction.
65
+ */
66
+ analyze?: boolean;
67
+ /** Request buffer counters on PostgreSQL/YugabyteDB (defaults to `true` when `analyze: true`). */
68
+ buffers?: boolean;
69
+ /**
70
+ * Explicitly allow `analyze: true` on a PostgreSQL driver that lacks session-pinned transaction
71
+ * control (`connect()`, `reserve()`, or `begin()`). Defaults to `false`.
72
+ */
73
+ allowMutatingAnalyze?: boolean;
74
+ }
75
+ /**
76
+ * Parses raw plan text (PostgreSQL JSON/text, SQL Server `.sqlplan` XML, MySQL JSON/tree,
77
+ * YugabyteDB JSON, or SQLite `EXPLAIN QUERY PLAN`) via `@culpritsql/plans`, automatically
78
+ * initializing WebAssembly if needed.
79
+ */
80
+ export declare function explainText(rawPlan: string, engine?: Engine): Promise<Plan>;
81
+ /**
82
+ * Formats SQLite `EXPLAIN QUERY PLAN` row objects (`{ id, parent, notused, detail }`,
83
+ * legacy `{ selectid, order, from, detail }`, or `[id, parent, notused, detail]` tuples)
84
+ * into canonical `QUERY PLAN` tree text accepted by `@culpritsql/plans`.
85
+ */
86
+ export declare function formatSqliteExplainRows(rows: readonly unknown[]): string;
87
+ /**
88
+ * Runs `EXPLAIN` against a live database client (`pg`, `postgres.js`, `Bun.sql`, `mysql2`,
89
+ * `better-sqlite3`, `node:sqlite`, `bun:sqlite`, LibSQL, or Cloudflare D1) and parses the
90
+ * resulting plan into a typed `@culpritsql/plans` `Plan`.
91
+ */
92
+ export declare function explain(client: SupportedDriverClient, query: QueryInput, options?: ExplainOptions): Promise<Plan>;
93
+ export declare function explain(client: SupportedDriverClient, query: QueryInput, params: QueryParams | undefined, options?: ExplainOptions): Promise<Plan>;
94
+ //# sourceMappingURL=drivers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drivers.d.ts","sourceRoot":"","sources":["../src/drivers.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAA6B,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAE9E,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,M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E,OAAO,CAAC;IAClB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAgBD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CA2ExE;AA+XD;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,MAAM,EAAE,qBAAqB,EAC7B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC,CAAC;AACjB,wBAAsB,OAAO,CAC3B,MAAM,EAAE,qBAAqB,EAC7B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { assertIsPlan, assertPlan, collectPlanNodes, evaluateToCompleteWithin, evaluateToCostLessThan, evaluateToHaveZeroSpills, evaluateToHaveZeroWarnings, evaluateToNotRegressFrom, evaluateToReadAtMostPages, evaluateToScanTable, evaluateToUseIndex, formatNodeDiagnostic, isFullTableScanNode, isIndexAccessNode, PlanAssertionError, PlanAssertions, type AssertionEvaluation, type RegressionOptions, } from "./assertions.js";
2
+ export { explain, explainText, formatSqliteExplainRows, type ExplainOptions, type Mysql2ClientLike, type PgClientLike, type PgPoolClientLike, type PostgresUnsafeClientLike, type SqliteClientLike, type SqlitePreparedStatementLike, type SupportedDriverClient, type UnsafeTxLike, } from "./drivers.js";
3
+ export { culpritMatchers, type CustomMatchers, type MatcherResult, } from "./matchers.js";
4
+ export { bindNamedParams, extractNamedParameters, extractRawQuery, normalizeQuery, validateSingleStatementSql, type NormalizedQuery, type ParameterStyle, type QueryInput, type QueryParams, type ReyloQueryModule, type SqlQueryBuilder, } from "./query.js";
5
+ export { diffPlans, ensureWasmInit, exportPlan, init, initWasm, isWasmReady, ParserError, parseDeadlock, parsePlan, type ChangeKind, type CompareContext, type CoreError, type Deadlock, type Engine, type ExportFile, type ExportFormat, type ExportOptions, type NodeKind, type NodeRuntime, type Plan, type PlanChange, type PlanConversion, type PlanDiff, type PlanFacts, type PlanIndexHint, type PlanKind, type PlanNode, type PlanNodeFacts, type PlanWarning, } from "./wasm.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,eAAe,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,0BAA0B,EAC1B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MA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