@jterrazz/test 5.3.2 → 6.1.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.
@@ -0,0 +1,312 @@
1
+ import { copyFileSync, existsSync, readFileSync, unlinkSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { resolve } from "node:path";
4
+ import { Client } from "pg";
5
+ import Database from "better-sqlite3";
6
+ //#region src/adapters/postgres.adapter.ts
7
+ var PostgresHandle = class {
8
+ type = "postgres";
9
+ composeName;
10
+ defaultPort = 5432;
11
+ defaultImage;
12
+ environment;
13
+ connectionString = "";
14
+ started = false;
15
+ client = null;
16
+ originalConnectionString = "";
17
+ schema = "public";
18
+ constructor(options = {}) {
19
+ this.composeName = options.compose ?? null;
20
+ this.defaultImage = options.image ?? "postgres:17";
21
+ this.environment = {
22
+ POSTGRES_DB: "test",
23
+ POSTGRES_PASSWORD: "test",
24
+ POSTGRES_USER: "test",
25
+ ...options.env
26
+ };
27
+ }
28
+ buildConnectionString(host, port) {
29
+ return `postgresql://${this.environment.POSTGRES_USER ?? "test"}:${this.environment.POSTGRES_PASSWORD ?? "test"}@${host}:${port}/${this.environment.POSTGRES_DB ?? "test"}`;
30
+ }
31
+ createDatabaseAdapter() {
32
+ return this;
33
+ }
34
+ async healthcheck() {
35
+ if (!this.connectionString) throw new Error("postgres: cannot healthcheck — no connection string");
36
+ try {
37
+ const client = new Client({ connectionString: this.connectionString });
38
+ await client.connect();
39
+ await client.query("SELECT 1");
40
+ await client.end();
41
+ } catch (error) {
42
+ throw new Error(`postgres healthcheck failed: ${error.message || error.code || String(error)}`, { cause: error });
43
+ }
44
+ }
45
+ async initialize(composeDir) {
46
+ if (!this.composeName) return;
47
+ const initPaths = [resolve(composeDir, `${this.composeName}/init.sql`), resolve(composeDir, "postgres/init.sql")];
48
+ for (const initPath of initPaths) if (existsSync(initPath)) {
49
+ const sql = readFileSync(initPath, "utf8");
50
+ try {
51
+ await this.seed(sql);
52
+ } catch (error) {
53
+ throw new Error(`postgres init script failed (${initPath}):\n${error.message}`, { cause: error });
54
+ }
55
+ return;
56
+ }
57
+ }
58
+ async getClient() {
59
+ if (this.client) return this.client;
60
+ const client = new Client({ connectionString: this.connectionString });
61
+ client.on("error", () => {
62
+ this.client = null;
63
+ });
64
+ await client.connect();
65
+ this.client = client;
66
+ return client;
67
+ }
68
+ async seed(sql) {
69
+ await (await this.getClient()).query(sql);
70
+ }
71
+ async reset() {
72
+ const client = await this.getClient();
73
+ const result = await client.query(`
74
+ SELECT tablename FROM pg_tables
75
+ WHERE schemaname = '${this.schema}'
76
+ AND tablename NOT LIKE '_prisma%'
77
+ `);
78
+ for (const row of result.rows) await client.query(`TRUNCATE "${this.schema}"."${row.tablename}" CASCADE`);
79
+ }
80
+ async query(table, columns) {
81
+ const client = await this.getClient();
82
+ const columnList = columns.join(", ");
83
+ return (await client.query(`SELECT ${columnList} FROM "${this.schema}"."${table}" ORDER BY 1`)).rows.map((row) => columns.map((col) => row[col]));
84
+ }
85
+ isolation() {
86
+ return {
87
+ acquire: async (workerId) => {
88
+ const workerSchema = `worker_${workerId}`;
89
+ this.originalConnectionString = this.connectionString;
90
+ const client = await this.getClient();
91
+ await client.query(`DROP SCHEMA IF EXISTS "${workerSchema}" CASCADE`);
92
+ await client.query(`CREATE SCHEMA "${workerSchema}"`);
93
+ const tables = await client.query(`
94
+ SELECT tablename FROM pg_tables
95
+ WHERE schemaname = 'public'
96
+ AND tablename NOT LIKE '_prisma%'
97
+ `);
98
+ for (const row of tables.rows) await client.query(`CREATE TABLE "${workerSchema}"."${row.tablename}" (LIKE "public"."${row.tablename}" INCLUDING ALL)`);
99
+ this.schema = workerSchema;
100
+ await client.query(`SET search_path TO "${workerSchema}", public`);
101
+ const url = new URL(this.connectionString);
102
+ url.searchParams.set("options", `-c search_path=${workerSchema},public`);
103
+ this.connectionString = url.toString();
104
+ },
105
+ reset: async () => {
106
+ await this.reset();
107
+ },
108
+ release: async () => {
109
+ const client = await this.getClient();
110
+ const workerSchema = this.schema;
111
+ this.schema = "public";
112
+ this.connectionString = this.originalConnectionString;
113
+ await client.query(`SET search_path TO public`);
114
+ await client.query(`DROP SCHEMA IF EXISTS "${workerSchema}" CASCADE`);
115
+ }
116
+ };
117
+ }
118
+ };
119
+ /**
120
+ * Create a PostgreSQL service handle.
121
+ *
122
+ * @example
123
+ * const db = postgres({ compose: "db" });
124
+ * // After start: db.connectionString is populated
125
+ */
126
+ function postgres(options = {}) {
127
+ return new PostgresHandle(options);
128
+ }
129
+ //#endregion
130
+ //#region src/adapters/redis.adapter.ts
131
+ var RedisHandle = class {
132
+ type = "redis";
133
+ composeName;
134
+ defaultPort = 6379;
135
+ defaultImage;
136
+ environment = {};
137
+ connectionString = "";
138
+ started = false;
139
+ dbIndex = 0;
140
+ constructor(options = {}) {
141
+ this.composeName = options.compose ?? null;
142
+ this.defaultImage = options.image ?? "redis:7";
143
+ }
144
+ buildConnectionString(host, port) {
145
+ return `redis://${host}:${port}`;
146
+ }
147
+ createDatabaseAdapter() {
148
+ return null;
149
+ }
150
+ async healthcheck() {
151
+ if (!this.connectionString) throw new Error("redis: cannot healthcheck — no connection string");
152
+ try {
153
+ const { createClient } = await import("redis");
154
+ const client = createClient({ url: this.connectionString });
155
+ await client.connect();
156
+ await client.ping();
157
+ await client.disconnect();
158
+ } catch (error) {
159
+ throw new Error(`redis healthcheck failed: ${error.message || error.code || String(error)}`, { cause: error });
160
+ }
161
+ }
162
+ async initialize() {}
163
+ async reset() {
164
+ const { createClient } = await import("redis");
165
+ const client = createClient({
166
+ url: this.connectionString,
167
+ database: this.dbIndex
168
+ });
169
+ await client.connect();
170
+ try {
171
+ await client.flushDb();
172
+ } finally {
173
+ await client.disconnect();
174
+ }
175
+ }
176
+ isolation() {
177
+ return {
178
+ acquire: async (workerId) => {
179
+ this.dbIndex = (Number.parseInt(workerId, 10) || 0) % 15 + 1;
180
+ },
181
+ reset: async () => {
182
+ await this.reset();
183
+ },
184
+ release: async () => {
185
+ await this.reset();
186
+ this.dbIndex = 0;
187
+ }
188
+ };
189
+ }
190
+ };
191
+ /**
192
+ * Create a Redis service handle.
193
+ *
194
+ * @example
195
+ * const cache = redis({ compose: "cache" });
196
+ * // After start: cache.connectionString is populated
197
+ */
198
+ function redis(options = {}) {
199
+ return new RedisHandle(options);
200
+ }
201
+ //#endregion
202
+ //#region src/adapters/sqlite.adapter.ts
203
+ var SqliteHandle = class {
204
+ type = "sqlite";
205
+ composeName = null;
206
+ defaultPort = 0;
207
+ defaultImage = "";
208
+ environment = {};
209
+ connectionString = "";
210
+ started = false;
211
+ db = null;
212
+ templatePath = "";
213
+ workerDbPath = "";
214
+ initSql;
215
+ prismaSchema;
216
+ constructor(options = {}) {
217
+ this.initSql = options.init ?? null;
218
+ this.prismaSchema = options.prismaSchema ?? null;
219
+ }
220
+ buildConnectionString() {
221
+ return `file:${this.workerDbPath || this.templatePath}`;
222
+ }
223
+ createDatabaseAdapter() {
224
+ return this;
225
+ }
226
+ async healthcheck() {}
227
+ async initialize() {
228
+ this.templatePath = resolve(tmpdir(), `test-template-${Date.now()}.sqlite`);
229
+ if (this.prismaSchema) {
230
+ const { execSync } = await import("node:child_process");
231
+ execSync("npx prisma db push --force-reset --skip-generate", {
232
+ env: {
233
+ ...process.env,
234
+ DATABASE_URL: `file:${this.templatePath}`
235
+ },
236
+ stdio: "pipe"
237
+ });
238
+ } else if (this.initSql) {
239
+ const sql = readFileSync(this.initSql, "utf8");
240
+ const templateDb = new Database(this.templatePath);
241
+ templateDb.exec(sql);
242
+ templateDb.close();
243
+ } else new Database(this.templatePath).close();
244
+ this.connectionString = `file:${this.templatePath}`;
245
+ this.started = true;
246
+ }
247
+ getDb() {
248
+ const dbPath = this.workerDbPath || this.templatePath;
249
+ if (!this.db) {
250
+ this.db = new Database(dbPath);
251
+ this.db.pragma("journal_mode = WAL");
252
+ }
253
+ return this.db;
254
+ }
255
+ closeDb() {
256
+ if (this.db) {
257
+ this.db.close();
258
+ this.db = null;
259
+ }
260
+ }
261
+ async seed(sql) {
262
+ this.getDb().exec(sql);
263
+ }
264
+ async query(table, columns) {
265
+ const columnList = columns.join(", ");
266
+ return this.getDb().prepare(`SELECT ${columnList} FROM "${table}" ORDER BY 1`).all().map((row) => columns.map((col) => row[col]));
267
+ }
268
+ async reset() {
269
+ const db = this.getDb();
270
+ const tables = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE '_prisma%' AND name != 'sqlite_sequence'`).all();
271
+ for (const { name } of tables) db.exec(`DELETE FROM "${name}"`);
272
+ }
273
+ isolation() {
274
+ return {
275
+ acquire: async (workerId) => {
276
+ this.closeDb();
277
+ this.workerDbPath = resolve(tmpdir(), `test-worker-${workerId}-${Date.now()}.sqlite`);
278
+ copyFileSync(this.templatePath, this.workerDbPath);
279
+ this.connectionString = `file:${this.workerDbPath}`;
280
+ },
281
+ reset: async () => {
282
+ await this.reset();
283
+ },
284
+ release: async () => {
285
+ this.closeDb();
286
+ if (this.workerDbPath && existsSync(this.workerDbPath)) unlinkSync(this.workerDbPath);
287
+ this.workerDbPath = "";
288
+ this.connectionString = `file:${this.templatePath}`;
289
+ }
290
+ };
291
+ }
292
+ };
293
+ /**
294
+ * Create a SQLite service handle. Uses file-copy isolation for parallel tests.
295
+ *
296
+ * @example
297
+ * // With Prisma schema
298
+ * const db = sqlite({ prismaSchema: './prisma/schema' });
299
+ *
300
+ * // With raw SQL init
301
+ * const db = sqlite({ init: './schema.sql' });
302
+ *
303
+ * // Empty database
304
+ * const db = sqlite();
305
+ */
306
+ function sqlite(options = {}) {
307
+ return new SqliteHandle(options);
308
+ }
309
+ //#endregion
310
+ export { redis as n, postgres as r, sqlite as t };
311
+
312
+ //# sourceMappingURL=sqlite.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.adapter.js","names":[],"sources":["../src/adapters/postgres.adapter.ts","../src/adapters/redis.adapter.ts","../src/adapters/sqlite.adapter.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { Client } from 'pg';\n\nimport type { DatabasePort } from '../ports/database.port.js';\nimport type { IsolationStrategy } from '../ports/isolation.port.js';\nimport type { ServiceHandle } from '../ports/service.port.js';\n\nexport interface PostgresOptions {\n /** Map to a service in docker-compose.test.yaml. */\n compose?: string;\n /** Override image. */\n image?: string;\n /** Override environment variables. */\n env?: Record<string, string>;\n}\n\nexport class PostgresHandle implements DatabasePort, ServiceHandle {\n readonly type = 'postgres';\n readonly composeName: null | string;\n readonly defaultPort = 5432;\n readonly defaultImage: string;\n readonly environment: Record<string, string>;\n\n connectionString = '';\n started = false;\n\n private client: Client | null = null;\n private originalConnectionString = '';\n private schema = 'public';\n\n constructor(options: PostgresOptions = {}) {\n this.composeName = options.compose ?? null;\n this.defaultImage = options.image ?? 'postgres:17';\n this.environment = {\n POSTGRES_DB: 'test',\n POSTGRES_PASSWORD: 'test',\n POSTGRES_USER: 'test',\n ...options.env,\n };\n }\n\n buildConnectionString(host: string, port: number): string {\n const user = this.environment.POSTGRES_USER ?? 'test';\n const password = this.environment.POSTGRES_PASSWORD ?? 'test';\n const db = this.environment.POSTGRES_DB ?? 'test';\n return `postgresql://${user}:${password}@${host}:${port}/${db}`;\n }\n\n createDatabaseAdapter(): DatabasePort {\n return this;\n }\n\n async healthcheck(): Promise<void> {\n if (!this.connectionString) {\n throw new Error('postgres: cannot healthcheck — no connection string');\n }\n\n // Healthcheck uses a throwaway client (connection might not be established yet)\n try {\n const client = new Client({ connectionString: this.connectionString });\n await client.connect();\n await client.query('SELECT 1');\n await client.end();\n } catch (error: any) {\n throw new Error(\n `postgres healthcheck failed: ${error.message || error.code || String(error)}`,\n { cause: error },\n );\n }\n }\n\n async initialize(composeDir: string): Promise<void> {\n if (!this.composeName) {\n return;\n }\n\n const initPaths = [\n resolve(composeDir, `${this.composeName}/init.sql`),\n resolve(composeDir, 'postgres/init.sql'),\n ];\n\n for (const initPath of initPaths) {\n if (existsSync(initPath)) {\n const sql = readFileSync(initPath, 'utf8');\n try {\n await this.seed(sql);\n } catch (error: any) {\n throw new Error(\n `postgres init script failed (${initPath}):\\n${error.message}`,\n {\n cause: error,\n },\n );\n }\n return;\n }\n }\n }\n\n private async getClient(): Promise<Client> {\n if (this.client) {\n return this.client;\n }\n const client = new Client({ connectionString: this.connectionString });\n client.on('error', () => {\n // Connection dropped (container stopped) — reset so next call reconnects\n this.client = null;\n });\n await client.connect();\n this.client = client;\n return client;\n }\n\n async seed(sql: string): Promise<void> {\n const client = await this.getClient();\n await client.query(sql);\n }\n\n async reset(): Promise<void> {\n const client = await this.getClient();\n const result = await client.query(`\n SELECT tablename FROM pg_tables\n WHERE schemaname = '${this.schema}'\n AND tablename NOT LIKE '_prisma%'\n `);\n for (const row of result.rows) {\n await client.query(`TRUNCATE \"${this.schema}\".\"${row.tablename}\" CASCADE`);\n }\n }\n\n async query(table: string, columns: string[]): Promise<unknown[][]> {\n const client = await this.getClient();\n const columnList = columns.join(', ');\n const result = await client.query(\n `SELECT ${columnList} FROM \"${this.schema}\".\"${table}\" ORDER BY 1`,\n );\n return result.rows.map((row: Record<string, unknown>) => columns.map((col) => row[col]));\n }\n\n isolation(): IsolationStrategy {\n return {\n acquire: async (workerId: string) => {\n const workerSchema = `worker_${workerId}`;\n this.originalConnectionString = this.connectionString;\n const client = await this.getClient();\n\n // Create schema by cloning all tables from public\n await client.query(`DROP SCHEMA IF EXISTS \"${workerSchema}\" CASCADE`);\n await client.query(`CREATE SCHEMA \"${workerSchema}\"`);\n\n // Copy table structures (no data) from public\n const tables = await client.query(`\n SELECT tablename FROM pg_tables\n WHERE schemaname = 'public'\n AND tablename NOT LIKE '_prisma%'\n `);\n for (const row of tables.rows) {\n await client.query(\n `CREATE TABLE \"${workerSchema}\".\"${row.tablename}\" (LIKE \"public\".\"${row.tablename}\" INCLUDING ALL)`,\n );\n }\n\n // Switch this handle to use the worker schema\n this.schema = workerSchema;\n await client.query(`SET search_path TO \"${workerSchema}\", public`);\n\n // Update connectionString so app connections also use the worker schema\n const url = new URL(this.connectionString);\n url.searchParams.set('options', `-c search_path=${workerSchema},public`);\n this.connectionString = url.toString();\n },\n\n reset: async () => {\n await this.reset();\n },\n\n release: async () => {\n const client = await this.getClient();\n const workerSchema = this.schema;\n this.schema = 'public';\n this.connectionString = this.originalConnectionString;\n await client.query(`SET search_path TO public`);\n await client.query(`DROP SCHEMA IF EXISTS \"${workerSchema}\" CASCADE`);\n },\n };\n }\n}\n\n/**\n * Create a PostgreSQL service handle.\n *\n * @example\n * const db = postgres({ compose: \"db\" });\n * // After start: db.connectionString is populated\n */\nexport function postgres(options: PostgresOptions = {}): PostgresHandle {\n return new PostgresHandle(options);\n}\n","import type { DatabasePort } from '../ports/database.port.js';\nimport type { IsolationStrategy } from '../ports/isolation.port.js';\nimport type { ServiceHandle } from '../ports/service.port.js';\n\nexport interface RedisOptions {\n /** Map to a service in docker-compose.test.yaml. */\n compose?: string;\n /** Override image. */\n image?: string;\n}\n\nexport class RedisHandle implements ServiceHandle {\n readonly type = 'redis';\n readonly composeName: null | string;\n readonly defaultPort = 6379;\n readonly defaultImage: string;\n readonly environment: Record<string, string> = {};\n\n connectionString = '';\n started = false;\n\n private dbIndex = 0;\n\n constructor(options: RedisOptions = {}) {\n this.composeName = options.compose ?? null;\n this.defaultImage = options.image ?? 'redis:7';\n }\n\n buildConnectionString(host: string, port: number): string {\n return `redis://${host}:${port}`;\n }\n\n createDatabaseAdapter(): DatabasePort | null {\n return null;\n }\n\n async healthcheck(): Promise<void> {\n if (!this.connectionString) {\n throw new Error('redis: cannot healthcheck — no connection string');\n }\n\n try {\n const { createClient } = await import('redis');\n const client = createClient({ url: this.connectionString });\n await client.connect();\n await client.ping();\n await client.disconnect();\n } catch (error: any) {\n throw new Error(\n `redis healthcheck failed: ${error.message || error.code || String(error)}`,\n {\n cause: error,\n },\n );\n }\n }\n\n async initialize(): Promise<void> {\n // Redis doesn't need initialization scripts\n }\n\n async reset(): Promise<void> {\n const { createClient } = await import('redis');\n const client = createClient({ url: this.connectionString, database: this.dbIndex });\n await client.connect();\n try {\n await client.flushDb();\n } finally {\n await client.disconnect();\n }\n }\n\n isolation(): IsolationStrategy {\n return {\n acquire: async (workerId: string) => {\n // Use Redis database index 1-15 for workers (0 is default/shared)\n const numericId = Number.parseInt(workerId, 10) || 0;\n this.dbIndex = (numericId % 15) + 1;\n },\n\n reset: async () => {\n await this.reset();\n },\n\n release: async () => {\n await this.reset();\n this.dbIndex = 0;\n },\n };\n }\n}\n\n/**\n * Create a Redis service handle.\n *\n * @example\n * const cache = redis({ compose: \"cache\" });\n * // After start: cache.connectionString is populated\n */\nexport function redis(options: RedisOptions = {}): RedisHandle {\n return new RedisHandle(options);\n}\n","import Database from 'better-sqlite3';\nimport { copyFileSync, existsSync, readFileSync, unlinkSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { resolve } from 'node:path';\n\nimport type { DatabasePort } from '../ports/database.port.js';\nimport type { IsolationStrategy } from '../ports/isolation.port.js';\nimport type { ServiceHandle } from '../ports/service.port.js';\n\nexport interface SqliteOptions {\n /**\n * Path to a SQL file used to initialize the database schema.\n * Mutually exclusive with `prismaSchema`.\n */\n init?: string;\n /**\n * Path to a Prisma schema directory or file.\n * The adapter runs `prisma db push` to create the template.\n * Mutually exclusive with `init`.\n */\n prismaSchema?: string;\n}\n\nexport class SqliteHandle implements DatabasePort, ServiceHandle {\n readonly type = 'sqlite';\n readonly composeName = null;\n readonly defaultPort = 0;\n readonly defaultImage = '';\n readonly environment: Record<string, string> = {};\n\n connectionString = '';\n started = false;\n\n private db: Database.Database | null = null;\n private templatePath = '';\n private workerDbPath = '';\n private initSql: null | string;\n private prismaSchema: null | string;\n\n constructor(options: SqliteOptions = {}) {\n this.initSql = options.init ?? null;\n this.prismaSchema = options.prismaSchema ?? null;\n }\n\n buildConnectionString(): string {\n return `file:${this.workerDbPath || this.templatePath}`;\n }\n\n createDatabaseAdapter(): DatabasePort {\n return this;\n }\n\n async healthcheck(): Promise<void> {\n // SQLite is always ready — it's a file\n }\n\n async initialize(): Promise<void> {\n // Create the template database\n this.templatePath = resolve(tmpdir(), `test-template-${Date.now()}.sqlite`);\n\n if (this.prismaSchema) {\n // Use Prisma to create schema\n const { execSync } = await import('node:child_process');\n execSync('npx prisma db push --force-reset --skip-generate', {\n env: {\n ...process.env,\n DATABASE_URL: `file:${this.templatePath}`,\n },\n stdio: 'pipe',\n });\n } else if (this.initSql) {\n // Use raw SQL to create schema\n const sql = readFileSync(this.initSql, 'utf8');\n const templateDb = new Database(this.templatePath);\n templateDb.exec(sql);\n templateDb.close();\n } else {\n // Empty database — consumer will seed\n const templateDb = new Database(this.templatePath);\n templateDb.close();\n }\n\n this.connectionString = `file:${this.templatePath}`;\n this.started = true;\n }\n\n private getDb(): Database.Database {\n const dbPath = this.workerDbPath || this.templatePath;\n if (!this.db) {\n this.db = new Database(dbPath);\n this.db.pragma('journal_mode = WAL');\n }\n return this.db;\n }\n\n private closeDb(): void {\n if (this.db) {\n this.db.close();\n this.db = null;\n }\n }\n\n async seed(sql: string): Promise<void> {\n this.getDb().exec(sql);\n }\n\n async query(table: string, columns: string[]): Promise<unknown[][]> {\n const columnList = columns.join(', ');\n const rows = this.getDb()\n .prepare(`SELECT ${columnList} FROM \"${table}\" ORDER BY 1`)\n .all() as Record<string, unknown>[];\n return rows.map((row) => columns.map((col) => row[col]));\n }\n\n async reset(): Promise<void> {\n const db = this.getDb();\n const tables = db\n .prepare(\n `SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE '_prisma%' AND name != 'sqlite_sequence'`,\n )\n .all() as { name: string }[];\n for (const { name } of tables) {\n db.exec(`DELETE FROM \"${name}\"`);\n }\n }\n\n isolation(): IsolationStrategy {\n return {\n acquire: async (workerId: string) => {\n this.closeDb();\n this.workerDbPath = resolve(\n tmpdir(),\n `test-worker-${workerId}-${Date.now()}.sqlite`,\n );\n copyFileSync(this.templatePath, this.workerDbPath);\n this.connectionString = `file:${this.workerDbPath}`;\n },\n\n reset: async () => {\n await this.reset();\n },\n\n release: async () => {\n this.closeDb();\n if (this.workerDbPath && existsSync(this.workerDbPath)) {\n unlinkSync(this.workerDbPath);\n }\n this.workerDbPath = '';\n this.connectionString = `file:${this.templatePath}`;\n },\n };\n }\n}\n\n/**\n * Create a SQLite service handle. Uses file-copy isolation for parallel tests.\n *\n * @example\n * // With Prisma schema\n * const db = sqlite({ prismaSchema: './prisma/schema' });\n *\n * // With raw SQL init\n * const db = sqlite({ init: './schema.sql' });\n *\n * // Empty database\n * const db = sqlite();\n */\nexport function sqlite(options: SqliteOptions = {}): SqliteHandle {\n return new SqliteHandle(options);\n}\n"],"mappings":";;;;;;AAiBA,IAAa,iBAAb,MAAmE;CAC/D,OAAgB;CAChB;CACA,cAAuB;CACvB;CACA;CAEA,mBAAmB;CACnB,UAAU;CAEV,SAAgC;CAChC,2BAAmC;CACnC,SAAiB;CAEjB,YAAY,UAA2B,EAAE,EAAE;AACvC,OAAK,cAAc,QAAQ,WAAW;AACtC,OAAK,eAAe,QAAQ,SAAS;AACrC,OAAK,cAAc;GACf,aAAa;GACb,mBAAmB;GACnB,eAAe;GACf,GAAG,QAAQ;GACd;;CAGL,sBAAsB,MAAc,MAAsB;AAItD,SAAO,gBAHM,KAAK,YAAY,iBAAiB,OAGnB,GAFX,KAAK,YAAY,qBAAqB,OAEf,GAAG,KAAK,GAAG,KAAK,GAD7C,KAAK,YAAY,eAAe;;CAI/C,wBAAsC;AAClC,SAAO;;CAGX,MAAM,cAA6B;AAC/B,MAAI,CAAC,KAAK,iBACN,OAAM,IAAI,MAAM,sDAAsD;AAI1E,MAAI;GACA,MAAM,SAAS,IAAI,OAAO,EAAE,kBAAkB,KAAK,kBAAkB,CAAC;AACtE,SAAM,OAAO,SAAS;AACtB,SAAM,OAAO,MAAM,WAAW;AAC9B,SAAM,OAAO,KAAK;WACb,OAAY;AACjB,SAAM,IAAI,MACN,gCAAgC,MAAM,WAAW,MAAM,QAAQ,O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;AAC3B,SAAO;GACH,SAAS,OAAO,aAAqB;AACjC,SAAK,SAAS;AACd,SAAK,eAAe,QAChB,QAAQ,EACR,eAAe,SAAS,GAAG,KAAK,KAAK,CAAC,SACzC;AACD,iBAAa,KAAK,cAAc,KAAK,aAAa;AAClD,SAAK,mBAAmB,QAAQ,KAAK;;GAGzC,OAAO,YAAY;AACf,UAAM,KAAK,OAAO;;GAGtB,SAAS,YAAY;AACjB,SAAK,SAAS;AACd,QAAI,KAAK,gBAAgB,WAAW,KAAK,aAAa,CAClD,YAAW,KAAK,aAAa;AAEjC,SAAK,eAAe;AACpB,SAAK,mBAAmB,QAAQ,KAAK;;GAE5C;;;;;;;;;;;;;;;;AAiBT,SAAgB,OAAO,UAAyB,EAAE,EAAgB;AAC9D,QAAO,IAAI,aAAa,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jterrazz/test",
3
- "version": "5.3.2",
3
+ "version": "6.1.0",
4
4
  "author": "Jean-Baptiste Terrazzoni <contact@jterrazz.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,18 +14,28 @@
14
14
  ".": {
15
15
  "require": "./dist/index.cjs",
16
16
  "import": "./dist/index.js"
17
+ },
18
+ "./services": {
19
+ "require": "./dist/services.cjs",
20
+ "import": "./dist/services.js"
21
+ },
22
+ "./mock": {
23
+ "require": "./dist/mock.cjs",
24
+ "import": "./dist/mock.js"
17
25
  }
18
26
  },
19
27
  "publishConfig": {
20
28
  "registry": "https://registry.npmjs.org/"
21
29
  },
22
30
  "scripts": {
23
- "build": "typescript bundle",
31
+ "build": "tsdown --config tsdown.config.ts",
32
+ "docs": "typescript docs",
24
33
  "lint": "codestyle check",
25
34
  "lint:fix": "codestyle fix",
26
35
  "test": "vitest --run"
27
36
  },
28
37
  "dependencies": {
38
+ "better-sqlite3": "^12.9.0",
29
39
  "mockdate": "^3.0.5",
30
40
  "pg": "^8.20.0",
31
41
  "redis": "^5.11.0",
@@ -35,15 +45,13 @@
35
45
  },
36
46
  "devDependencies": {
37
47
  "@hono/node-server": "^1.19.11",
38
- "@jterrazz/codestyle": "^3.0.9",
39
- "@jterrazz/typescript": "^5.2.0",
48
+ "@jterrazz/codestyle": "^3.3.0",
49
+ "@jterrazz/typescript": "^5.3.0",
50
+ "@types/better-sqlite3": "^7.6.13",
40
51
  "@types/node": "^25.5.0",
41
52
  "@types/pg": "^8.20.0",
42
53
  "hono": "^4.12.9",
43
- "typedoc": "^0.28.18",
44
- "typedoc-plugin-markdown": "^4.11.0",
45
- "vitepress": "^1.6.4",
46
- "vitepress-plugin-llms": "^1.12.0",
54
+ "tsdown": "^0.21.8",
47
55
  "vitest": "^4.1.2"
48
56
  },
49
57
  "peerDependencies": {