@zauso-ai/capstan-db 0.1.2 → 0.1.4

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/dist/client.d.ts CHANGED
@@ -1,18 +1,25 @@
1
- import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
2
1
  import type { DatabaseConfig } from "./types.js";
3
2
  export interface DatabaseInstance {
4
3
  /** The Drizzle ORM database instance. */
5
- db: BetterSQLite3Database;
4
+ db: unknown;
6
5
  /** Close the underlying database connection. */
7
6
  close: () => void;
8
7
  }
9
8
  /**
10
9
  * Create a Drizzle database instance backed by better-sqlite3.
11
10
  *
11
+ * Both `better-sqlite3` and `drizzle-orm` are optional peer dependencies. They
12
+ * are loaded lazily so that `@zauso-ai/capstan-db` can be installed even when
13
+ * native compilation of `better-sqlite3` fails. The actual database features
14
+ * will not work until the peer dependencies are installed.
15
+ *
12
16
  * @param config - Database configuration. Currently only `sqlite` provider is
13
17
  * supported. The `url` field should be a file path (or `:memory:` for an
14
18
  * in-memory database).
15
19
  *
20
+ * @throws If `better-sqlite3` or `drizzle-orm` are not installed, throws an
21
+ * error with installation instructions.
22
+ *
16
23
  * @example
17
24
  * const { db, close } = createDatabase({ provider: "sqlite", url: "./data.db" });
18
25
  * // ... use db ...
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,EAAE,EAAE,qBAAqB,CAAC;IAC1B,gDAAgD;IAChD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB,CAoBvE"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,EAAE,EAAE,OAAO,CAAC;IACZ,gDAAgD;IAChD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB,CA6CvE"}
package/dist/client.js CHANGED
@@ -1,12 +1,20 @@
1
- import { drizzle } from "drizzle-orm/better-sqlite3";
2
- import Database from "better-sqlite3";
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
3
  /**
4
4
  * Create a Drizzle database instance backed by better-sqlite3.
5
5
  *
6
+ * Both `better-sqlite3` and `drizzle-orm` are optional peer dependencies. They
7
+ * are loaded lazily so that `@zauso-ai/capstan-db` can be installed even when
8
+ * native compilation of `better-sqlite3` fails. The actual database features
9
+ * will not work until the peer dependencies are installed.
10
+ *
6
11
  * @param config - Database configuration. Currently only `sqlite` provider is
7
12
  * supported. The `url` field should be a file path (or `:memory:` for an
8
13
  * in-memory database).
9
14
  *
15
+ * @throws If `better-sqlite3` or `drizzle-orm` are not installed, throws an
16
+ * error with installation instructions.
17
+ *
10
18
  * @example
11
19
  * const { db, close } = createDatabase({ provider: "sqlite", url: "./data.db" });
12
20
  * // ... use db ...
@@ -16,7 +24,28 @@ export function createDatabase(config) {
16
24
  if (config.provider !== "sqlite") {
17
25
  throw new Error(`@zauso-ai/capstan-db: Unsupported database provider "${config.provider}". Only "sqlite" is currently supported.`);
18
26
  }
19
- const sqlite = new Database(config.url);
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ let BetterSqlite3;
29
+ try {
30
+ BetterSqlite3 = require("better-sqlite3");
31
+ }
32
+ catch {
33
+ throw new Error(`@zauso-ai/capstan-db: "better-sqlite3" is required for SQLite support but is not installed.\n` +
34
+ `Install it with: npm install better-sqlite3\n` +
35
+ `Note: this package requires native compilation (node-gyp). ` +
36
+ `Make sure you have a C++ build toolchain installed.`);
37
+ }
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ let drizzle;
40
+ try {
41
+ const drizzleModule = require("drizzle-orm/better-sqlite3");
42
+ drizzle = drizzleModule.drizzle;
43
+ }
44
+ catch {
45
+ throw new Error(`@zauso-ai/capstan-db: "drizzle-orm" is required for database support but is not installed.\n` +
46
+ `Install it with: npm install drizzle-orm`);
47
+ }
48
+ const sqlite = new BetterSqlite3(config.url);
20
49
  // Enable WAL mode for better concurrent read performance.
21
50
  sqlite.pragma("journal_mode = WAL");
22
51
  const db = drizzle({ client: sqlite });
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAUtC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB;IACnD,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,wDAAwD,MAAM,CAAC,QAAQ,0CAA0C,CAClH,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAExC,0DAA0D;IAC1D,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAEpC,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAEvC,OAAO;QACL,EAAE;QACF,KAAK;YACH,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"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name": "@zauso-ai/capstan-db",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -14,10 +14,18 @@
14
14
  "build": "tsc -p tsconfig.json",
15
15
  "typecheck": "tsc -p tsconfig.json --noEmit"
16
16
  },
17
- "dependencies": {
17
+ "peerDependencies": {
18
18
  "drizzle-orm": "^0.44.0",
19
19
  "better-sqlite3": "^11.0.0"
20
20
  },
21
+ "peerDependenciesMeta": {
22
+ "drizzle-orm": {
23
+ "optional": true
24
+ },
25
+ "better-sqlite3": {
26
+ "optional": true
27
+ }
28
+ },
21
29
  "description": "Database layer for Capstan — Drizzle ORM, defineModel, auto CRUD generation",
22
30
  "files": [
23
31
  "dist"