@jamesaphoenix/tx-test-utils 0.4.3 → 0.5.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/README.md +154 -299
- package/dist/chaos/chaos-utilities.js +3 -4
- package/dist/chaos/chaos-utilities.js.map +1 -1
- package/dist/database/test-database.d.ts +7 -7
- package/dist/database/test-database.d.ts.map +1 -1
- package/dist/database/test-database.js +41 -115
- package/dist/database/test-database.js.map +1 -1
- package/dist/factories/factories.test.d.ts +8 -0
- package/dist/factories/factories.test.d.ts.map +1 -0
- package/dist/factories/factories.test.js +419 -0
- package/dist/factories/factories.test.js.map +1 -0
- package/dist/factories/index.d.ts +3 -0
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/factories/index.js +6 -0
- package/dist/factories/index.js.map +1 -1
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/shared-test-layer.d.ts +7 -12
- package/dist/helpers/shared-test-layer.d.ts.map +1 -1
- package/dist/helpers/shared-test-layer.js +14 -8
- package/dist/helpers/shared-test-layer.js.map +1 -1
- package/dist/helpers/sqlite-factory.d.ts +6 -31
- package/dist/helpers/sqlite-factory.d.ts.map +1 -1
- package/dist/helpers/sqlite-factory.js +9 -47
- package/dist/helpers/sqlite-factory.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +11 -2
- package/dist/adapters/better-sqlite3-adapter.d.ts +0 -36
- package/dist/adapters/better-sqlite3-adapter.d.ts.map +0 -1
- package/dist/adapters/better-sqlite3-adapter.js +0 -78
- package/dist/adapters/better-sqlite3-adapter.js.map +0 -1
|
@@ -1,49 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SQLite database factory for tests.
|
|
3
3
|
*
|
|
4
|
-
* Creates
|
|
5
|
-
*
|
|
6
|
-
* from "bun:sqlite".
|
|
7
|
-
*
|
|
8
|
-
* Uses the SqliteDatabase interface from @tx/core, which is what SqliteClient
|
|
9
|
-
* provides via Effect layers. This means databases created here can be used
|
|
10
|
-
* directly with Layer.succeed(SqliteClient, db) — no `as any` needed.
|
|
4
|
+
* Creates database instances for use in tests. Since we run tests with
|
|
5
|
+
* `bunx --bun vitest run`, bun:sqlite is always available.
|
|
11
6
|
*
|
|
12
7
|
* @module @tx/test-utils/helpers/sqlite-factory
|
|
13
8
|
*/
|
|
14
|
-
import type { SqliteDatabase } from "@jamesaphoenix/tx-core";
|
|
15
9
|
/**
|
|
16
|
-
* Create
|
|
17
|
-
*
|
|
18
|
-
* - Under Vitest: uses better-sqlite3, wrapped via the adapter
|
|
19
|
-
* - Under Bun test: uses bun:sqlite
|
|
20
|
-
*
|
|
21
|
-
* PRAGMAs (journal_mode, foreign_keys, busy_timeout) are set automatically.
|
|
10
|
+
* Create an in-memory SQLite database with PRAGMAs set.
|
|
22
11
|
* Migrations are NOT applied — call applyMigrations(db) yourself if needed.
|
|
23
12
|
*
|
|
24
13
|
* @param path - Database file path, or ":memory:" (default)
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import { createSqliteDatabase } from "@jamesaphoenix/tx-test-utils"
|
|
29
|
-
* import { applyMigrations, SqliteClient } from "@jamesaphoenix/tx-core"
|
|
30
|
-
* import { Layer } from "effect"
|
|
31
|
-
*
|
|
32
|
-
* // Raw database for migration tests
|
|
33
|
-
* const db = await createSqliteDatabase()
|
|
34
|
-
* applyMigrations(db)
|
|
35
|
-
*
|
|
36
|
-
* // Use with Effect layers
|
|
37
|
-
* const infra = Layer.succeed(SqliteClient, db)
|
|
38
|
-
* ```
|
|
39
14
|
*/
|
|
40
|
-
export declare const createSqliteDatabase: (path?: string) => Promise<
|
|
15
|
+
export declare const createSqliteDatabase: (path?: string) => Promise<import("bun:sqlite").Database>;
|
|
41
16
|
/**
|
|
42
|
-
* Create a
|
|
17
|
+
* Create a SQLite database with all migrations applied.
|
|
43
18
|
*
|
|
44
19
|
* Convenience wrapper around createSqliteDatabase + applyMigrations.
|
|
45
20
|
*
|
|
46
21
|
* @param path - Database file path, or ":memory:" (default)
|
|
47
22
|
*/
|
|
48
|
-
export declare const createMigratedSqliteDatabase: (path?: string) => Promise<
|
|
23
|
+
export declare const createMigratedSqliteDatabase: (path?: string) => Promise<import("bun:sqlite").Database>;
|
|
49
24
|
//# sourceMappingURL=sqlite-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/sqlite-factory.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sqlite-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/sqlite-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAU,aAAiB,2CAS3D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GAAU,aAAiB,2CAKnE,CAAA"}
|
|
@@ -1,65 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SQLite database factory for tests.
|
|
3
3
|
*
|
|
4
|
-
* Creates
|
|
5
|
-
*
|
|
6
|
-
* from "bun:sqlite".
|
|
7
|
-
*
|
|
8
|
-
* Uses the SqliteDatabase interface from @tx/core, which is what SqliteClient
|
|
9
|
-
* provides via Effect layers. This means databases created here can be used
|
|
10
|
-
* directly with Layer.succeed(SqliteClient, db) — no `as any` needed.
|
|
4
|
+
* Creates database instances for use in tests. Since we run tests with
|
|
5
|
+
* `bunx --bun vitest run`, bun:sqlite is always available.
|
|
11
6
|
*
|
|
12
7
|
* @module @tx/test-utils/helpers/sqlite-factory
|
|
13
8
|
*/
|
|
14
9
|
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
const isVitest = () => typeof process !== "undefined" && process.env.VITEST === "true";
|
|
18
|
-
/**
|
|
19
|
-
* Create a SqliteDatabase instance.
|
|
20
|
-
*
|
|
21
|
-
* - Under Vitest: uses better-sqlite3, wrapped via the adapter
|
|
22
|
-
* - Under Bun test: uses bun:sqlite
|
|
23
|
-
*
|
|
24
|
-
* PRAGMAs (journal_mode, foreign_keys, busy_timeout) are set automatically.
|
|
10
|
+
* Create an in-memory SQLite database with PRAGMAs set.
|
|
25
11
|
* Migrations are NOT applied — call applyMigrations(db) yourself if needed.
|
|
26
12
|
*
|
|
27
13
|
* @param path - Database file path, or ":memory:" (default)
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* import { createSqliteDatabase } from "@jamesaphoenix/tx-test-utils"
|
|
32
|
-
* import { applyMigrations, SqliteClient } from "@jamesaphoenix/tx-core"
|
|
33
|
-
* import { Layer } from "effect"
|
|
34
|
-
*
|
|
35
|
-
* // Raw database for migration tests
|
|
36
|
-
* const db = await createSqliteDatabase()
|
|
37
|
-
* applyMigrations(db)
|
|
38
|
-
*
|
|
39
|
-
* // Use with Effect layers
|
|
40
|
-
* const infra = Layer.succeed(SqliteClient, db)
|
|
41
|
-
* ```
|
|
42
14
|
*/
|
|
43
15
|
export const createSqliteDatabase = async (path = ":memory:") => {
|
|
44
|
-
if (isVitest()) {
|
|
45
|
-
const { wrapBetterSqlite3 } = await import("../adapters/better-sqlite3-adapter.js");
|
|
46
|
-
const Database = (await import("better-sqlite3")).default;
|
|
47
|
-
const raw = new Database(path);
|
|
48
|
-
raw.pragma("journal_mode = WAL");
|
|
49
|
-
raw.pragma("foreign_keys = ON");
|
|
50
|
-
raw.pragma("busy_timeout = " + (process.env.TX_DB_BUSY_TIMEOUT || "5000"));
|
|
51
|
-
return wrapBetterSqlite3(raw);
|
|
52
|
-
}
|
|
53
|
-
// Bun test
|
|
54
16
|
const { Database } = await import("bun:sqlite");
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
17
|
+
const db = new Database(path);
|
|
18
|
+
db.run("PRAGMA journal_mode = WAL");
|
|
19
|
+
db.run("PRAGMA foreign_keys = ON");
|
|
20
|
+
db.run("PRAGMA busy_timeout = " + (process.env.TX_DB_BUSY_TIMEOUT || "5000"));
|
|
21
|
+
return db;
|
|
60
22
|
};
|
|
61
23
|
/**
|
|
62
|
-
* Create a
|
|
24
|
+
* Create a SQLite database with all migrations applied.
|
|
63
25
|
*
|
|
64
26
|
* Convenience wrapper around createSqliteDatabase + applyMigrations.
|
|
65
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-factory.js","sourceRoot":"","sources":["../../src/helpers/sqlite-factory.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sqlite-factory.js","sourceRoot":"","sources":["../../src/helpers/sqlite-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,IAAI,GAAG,UAAU,EAAE,EAAE;IAC9D,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAA;IAC/C,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC7B,EAAE,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IACnC,EAAE,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;IAClC,EAAE,CAAC,GAAG,CACJ,wBAAwB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAC,CACtE,CAAA;IACD,OAAO,EAAE,CAAA;AACX,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,EAAE,IAAI,GAAG,UAAU,EAAE,EAAE;IACtE,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAA;IAClE,MAAM,EAAE,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAC3C,eAAe,CAAC,EAAE,CAAC,CAAA;IACnB,OAAO,EAAE,CAAA;AACX,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
export { fixtureId, namespacedFixtureId, sequentialFixtureIds, contentFixtureId } from "./fixtures/index.js";
|
|
19
19
|
export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer, wrapDbAsTestDatabase } from "./database/index.js";
|
|
20
20
|
export type { TestDatabase } from "./database/index.js";
|
|
21
|
-
export { TaskFactory, createTestTask, createTestTasks, type CreateTaskOptions, LearningFactory, createTestLearning, createTestLearnings, type CreateLearningOptions, } from "./factories/index.js";
|
|
21
|
+
export { TaskFactory, createTestTask, createTestTasks, type CreateTaskOptions, LearningFactory, createTestLearning, createTestLearnings, type CreateLearningOptions, EdgeFactory, createTestEdge, createEdgeBetweenLearnings, type CreateEdgeOptions, AnchorFactory, createTestAnchor, type CreateAnchorOptions, CandidateFactory, createTestCandidate, type CreateCandidateOptions, type LearningCandidate, type CandidateConfidence, type CandidateStatus } from "./factories/index.js";
|
|
22
22
|
export { hashInput, cachedLLMCall, withLLMCache, configureLLMCache, getCacheConfig, resetCacheConfig, getCacheStats, clearCache, formatCacheStats, getCacheEntry, listCacheEntries } from "./llm-cache/index.js";
|
|
23
23
|
export type { CacheEntry, CachedLLMCallOptions, WithLLMCacheOptions, CacheStats, ClearCacheOptions } from "./llm-cache/index.js";
|
|
24
24
|
export { runEffect, runEffectFail, runEffectEither, expectEffectSuccess, expectEffectFailure, mergeLayers, createTestContext, type RunEffectOptions, type EffectResult } from "./helpers/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACL,SAAS,EAC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,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,13 @@ export {
|
|
|
24
24
|
// Task
|
|
25
25
|
TaskFactory, createTestTask, createTestTasks,
|
|
26
26
|
// Learning
|
|
27
|
-
LearningFactory, createTestLearning, createTestLearnings,
|
|
27
|
+
LearningFactory, createTestLearning, createTestLearnings,
|
|
28
|
+
// Edge
|
|
29
|
+
EdgeFactory, createTestEdge, createEdgeBetweenLearnings,
|
|
30
|
+
// Anchor
|
|
31
|
+
AnchorFactory, createTestAnchor,
|
|
32
|
+
// Candidate
|
|
33
|
+
CandidateFactory, createTestCandidate } from "./factories/index.js";
|
|
28
34
|
// LLM Cache - SHA256-based response caching
|
|
29
35
|
export {
|
|
30
36
|
// Core functions
|
|
@@ -35,7 +41,7 @@ getCacheStats, clearCache, formatCacheStats, getCacheEntry, listCacheEntries } f
|
|
|
35
41
|
export { runEffect, runEffectFail, runEffectEither, expectEffectSuccess, expectEffectFailure, mergeLayers, createTestContext } from "./helpers/index.js";
|
|
36
42
|
// Shared Test Layer - memory-efficient integration testing
|
|
37
43
|
export { createSharedTestLayer } from "./helpers/index.js";
|
|
38
|
-
// SQLite database factory
|
|
44
|
+
// SQLite database factory for tests
|
|
39
45
|
export { createSqliteDatabase, createMigratedSqliteDatabase } from "./helpers/index.js";
|
|
40
46
|
// Singleton Test Database - ONE DB for entire test suite
|
|
41
47
|
export { getSharedTestLayer, resetTestDb, closeTestDb, isTestDbInitialized } from "./singleton.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAE5B,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,qBAAqB,CAAA;AAG5B,YAAY;AACZ,OAAO;AACL,OAAO;AACP,WAAW,EACX,cAAc,EACd,eAAe;AAEf,WAAW;AACX,eAAe,EACf,kBAAkB,EAClB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAE5B,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,qBAAqB,CAAA;AAG5B,YAAY;AACZ,OAAO;AACL,OAAO;AACP,WAAW,EACX,cAAc,EACd,eAAe;AAEf,WAAW;AACX,eAAe,EACf,kBAAkB,EAClB,mBAAmB;AAEnB,OAAO;AACP,WAAW,EACX,cAAc,EACd,0BAA0B;AAE1B,SAAS;AACT,aAAa,EACb,gBAAgB;AAEhB,YAAY;AACZ,gBAAgB,EAChB,mBAAmB,EAKpB,MAAM,sBAAsB,CAAA;AAE7B,4CAA4C;AAC5C,OAAO;AACL,iBAAiB;AACjB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB;AAChB,gBAAgB;AAChB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAS7B,iBAAiB;AACjB,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EAGlB,MAAM,oBAAoB,CAAA;AAE3B,2DAA2D;AAC3D,OAAO,EACL,qBAAqB,EAGtB,MAAM,oBAAoB,CAAA;AAE3B,oCAAoC;AACpC,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,oBAAoB,CAAA;AAE3B,yDAAyD;AACzD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,gBAAgB,CAAA;AAEvB,iCAAiC;AACjC,qGAAqG;AACrG,oDAAoD;AAEpD,QAAQ;AACR,OAAO,EACL,mBAAmB,EACnB,gCAAgC,EAMhC,gBAAgB,EAChB,6BAA6B,EAC7B,gCAAgC,EAMjC,MAAM,kBAAkB,CAAA;AACzB,gDAAgD;AAChD,wDAAwD;AACxD,oDAAoD;AAEpD,4BAA4B;AAC5B,4DAA4D;AAE5D,8BAA8B;AAC9B,OAAO;AACL,mBAAmB;AACnB,KAAK;AACL,6BAA6B;AAC7B,UAAU,EACV,oBAAoB;AAGpB,gCAAgC;AAChC,aAAa,EACb,yBAAyB;AAEzB,yBAAyB;AACzB,WAAW;AAGX,mBAAmB;AACnB,YAAY;AAGZ,eAAe;AACf,WAAW;AAIX,4BAA4B;AAC5B,cAAc;AAGd,2BAA2B;AAC3B,YAAY;AAGZ,wBAAwB;AACxB,YAAY;AAGZ,iBAAiB;AACjB,UAAU,EAGX,MAAM,kBAAkB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,44 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamesaphoenix/tx-test-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Test utilities, factories, fixtures, and helpers for tx monorepo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"bun": "./src/index.ts",
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.js"
|
|
12
13
|
},
|
|
13
14
|
"./database": {
|
|
15
|
+
"bun": "./src/database/index.ts",
|
|
14
16
|
"types": "./dist/database/index.d.ts",
|
|
15
17
|
"import": "./dist/database/index.js"
|
|
16
18
|
},
|
|
17
19
|
"./factories": {
|
|
20
|
+
"bun": "./src/factories/index.ts",
|
|
18
21
|
"types": "./dist/factories/index.d.ts",
|
|
19
22
|
"import": "./dist/factories/index.js"
|
|
20
23
|
},
|
|
21
24
|
"./fixtures": {
|
|
25
|
+
"bun": "./src/fixtures/index.ts",
|
|
22
26
|
"types": "./dist/fixtures/index.d.ts",
|
|
23
27
|
"import": "./dist/fixtures/index.js"
|
|
24
28
|
},
|
|
25
29
|
"./llm-cache": {
|
|
30
|
+
"bun": "./src/llm-cache/index.ts",
|
|
26
31
|
"types": "./dist/llm-cache/index.d.ts",
|
|
27
32
|
"import": "./dist/llm-cache/index.js"
|
|
28
33
|
},
|
|
29
34
|
"./mocks": {
|
|
35
|
+
"bun": "./src/mocks/index.ts",
|
|
30
36
|
"types": "./dist/mocks/index.d.ts",
|
|
31
37
|
"import": "./dist/mocks/index.js"
|
|
32
38
|
},
|
|
33
39
|
"./helpers": {
|
|
40
|
+
"bun": "./src/helpers/index.ts",
|
|
34
41
|
"types": "./dist/helpers/index.d.ts",
|
|
35
42
|
"import": "./dist/helpers/index.js"
|
|
36
43
|
},
|
|
37
44
|
"./setup": {
|
|
45
|
+
"bun": "./src/setup/index.ts",
|
|
38
46
|
"types": "./dist/setup/index.d.ts",
|
|
39
47
|
"import": "./dist/setup/index.js"
|
|
40
48
|
},
|
|
41
49
|
"./chaos": {
|
|
50
|
+
"bun": "./src/chaos/index.ts",
|
|
42
51
|
"types": "./dist/chaos/index.d.ts",
|
|
43
52
|
"import": "./dist/chaos/index.js"
|
|
44
53
|
}
|
|
@@ -51,7 +60,7 @@
|
|
|
51
60
|
"build": "tsc -b",
|
|
52
61
|
"typecheck": "tsc --noEmit",
|
|
53
62
|
"lint": "eslint src/",
|
|
54
|
-
"test": "bun
|
|
63
|
+
"test": "bunx --bun vitest run"
|
|
55
64
|
},
|
|
56
65
|
"dependencies": {
|
|
57
66
|
"@jamesaphoenix/tx-core": "*",
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* better-sqlite3 adapter for Vitest compatibility
|
|
3
|
-
*
|
|
4
|
-
* Wraps better-sqlite3 to match the SqliteDatabase interface used by @tx/core.
|
|
5
|
-
* This allows tests to use Vitest (with proper parallelization) while production
|
|
6
|
-
* uses bun:sqlite.
|
|
7
|
-
*
|
|
8
|
-
* The SqliteDatabase interface abstracts away the implementation, so this adapter
|
|
9
|
-
* makes better-sqlite3 compatible with the existing code.
|
|
10
|
-
*/
|
|
11
|
-
import type { SqliteDatabase } from "@jamesaphoenix/tx-core";
|
|
12
|
-
type BetterSqlite3Database = {
|
|
13
|
-
prepare(sql: string): {
|
|
14
|
-
run(...params: unknown[]): {
|
|
15
|
-
lastInsertRowid: number | bigint;
|
|
16
|
-
changes: number;
|
|
17
|
-
};
|
|
18
|
-
get(...params: unknown[]): unknown;
|
|
19
|
-
all(...params: unknown[]): unknown[];
|
|
20
|
-
};
|
|
21
|
-
exec(sql: string): void;
|
|
22
|
-
close(): void;
|
|
23
|
-
pragma(key: string, value?: unknown): unknown;
|
|
24
|
-
transaction<T>(fn: () => T): () => T;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Wrap a better-sqlite3 Database to match SqliteDatabase interface
|
|
28
|
-
*/
|
|
29
|
-
export declare function wrapBetterSqlite3(db: BetterSqlite3Database): SqliteDatabase;
|
|
30
|
-
/**
|
|
31
|
-
* Create an in-memory better-sqlite3 database wrapped as SqliteDatabase
|
|
32
|
-
* with migrations applied.
|
|
33
|
-
*/
|
|
34
|
-
export declare function createBetterSqlite3Database(): Promise<SqliteDatabase>;
|
|
35
|
-
export {};
|
|
36
|
-
//# sourceMappingURL=better-sqlite3-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"better-sqlite3-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/better-sqlite3-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoC,MAAM,wBAAwB,CAAA;AAG9F,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG;QACpB,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG;YAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;QAChF,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;QAClC,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAA;KACrC,CAAA;IACD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,KAAK,IAAI,IAAI,CAAA;IACb,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;IAC7C,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;CACrC,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,qBAAqB,GAAG,cAAc,CA8C3E;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,cAAc,CAAC,CAe3E"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* better-sqlite3 adapter for Vitest compatibility
|
|
3
|
-
*
|
|
4
|
-
* Wraps better-sqlite3 to match the SqliteDatabase interface used by @tx/core.
|
|
5
|
-
* This allows tests to use Vitest (with proper parallelization) while production
|
|
6
|
-
* uses bun:sqlite.
|
|
7
|
-
*
|
|
8
|
-
* The SqliteDatabase interface abstracts away the implementation, so this adapter
|
|
9
|
-
* makes better-sqlite3 compatible with the existing code.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Wrap a better-sqlite3 Database to match SqliteDatabase interface
|
|
13
|
-
*/
|
|
14
|
-
export function wrapBetterSqlite3(db) {
|
|
15
|
-
return {
|
|
16
|
-
prepare(sql) {
|
|
17
|
-
const stmt = db.prepare(sql);
|
|
18
|
-
return {
|
|
19
|
-
run(...params) {
|
|
20
|
-
const result = stmt.run(...params);
|
|
21
|
-
return {
|
|
22
|
-
lastInsertRowid: result.lastInsertRowid ?? 0,
|
|
23
|
-
changes: result.changes ?? 0
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
get(...params) {
|
|
27
|
-
return stmt.get(...params) ?? null;
|
|
28
|
-
},
|
|
29
|
-
all(...params) {
|
|
30
|
-
return stmt.all(...params);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
run(sql, ...params) {
|
|
35
|
-
// Handle PRAGMA statements — better-sqlite3 uses .pragma("key = value") as a single string
|
|
36
|
-
const trimmed = sql.trim();
|
|
37
|
-
if (trimmed.toUpperCase().startsWith("PRAGMA")) {
|
|
38
|
-
// Strip the "PRAGMA " prefix and pass the rest directly to .pragma()
|
|
39
|
-
const pragmaArg = trimmed.slice(6).trim();
|
|
40
|
-
db.pragma(pragmaArg);
|
|
41
|
-
return { lastInsertRowid: 0, changes: 0 };
|
|
42
|
-
}
|
|
43
|
-
// Regular SQL statements
|
|
44
|
-
const result = db.prepare(sql).run(...params);
|
|
45
|
-
return {
|
|
46
|
-
lastInsertRowid: result.lastInsertRowid ?? 0,
|
|
47
|
-
changes: result.changes ?? 0
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
exec(sql) {
|
|
51
|
-
db.exec(sql);
|
|
52
|
-
},
|
|
53
|
-
close() {
|
|
54
|
-
db.close();
|
|
55
|
-
},
|
|
56
|
-
transaction(fn) {
|
|
57
|
-
return db.transaction(fn);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create an in-memory better-sqlite3 database wrapped as SqliteDatabase
|
|
63
|
-
* with migrations applied.
|
|
64
|
-
*/
|
|
65
|
-
export async function createBetterSqlite3Database() {
|
|
66
|
-
// Dynamic import to avoid requiring better-sqlite3 at module load time
|
|
67
|
-
// (only needed when running tests with Vitest)
|
|
68
|
-
const Database = (await import("better-sqlite3")).default;
|
|
69
|
-
const { applyMigrations } = await import("@jamesaphoenix/tx-core");
|
|
70
|
-
const db = new Database(":memory:");
|
|
71
|
-
db.pragma("journal_mode = WAL");
|
|
72
|
-
db.pragma("foreign_keys = ON");
|
|
73
|
-
db.pragma("busy_timeout = 5000");
|
|
74
|
-
const wrapped = wrapBetterSqlite3(db);
|
|
75
|
-
applyMigrations(wrapped);
|
|
76
|
-
return wrapped;
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=better-sqlite3-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"better-sqlite3-adapter.js","sourceRoot":"","sources":["../../src/adapters/better-sqlite3-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAyB;IACzD,OAAO;QACL,OAAO,CAAc,GAAW;YAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC5B,OAAO;gBACL,GAAG,CAAC,GAAG,MAAiB;oBACtB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAA0D,CAAA;oBAC3F,OAAO;wBACL,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,CAAC;wBAC5C,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC;qBAC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