@apex-stack/data 0.1.3 → 0.1.5

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/index.d.ts CHANGED
@@ -26,7 +26,8 @@ type CreateDbConfig = string | {
26
26
  * Open a database and wrap it with Drizzle behind a driver-agnostic handle.
27
27
  * All drivers use Drizzle's async query API, so `defineResource` works unchanged
28
28
  * across SQLite (libSQL/Turso), Postgres (Supabase/Neon) and embedded PGlite.
29
- * Postgres/PGlite drivers are loaded on demand — install only what you use.
29
+ * Every driver is an OPTIONAL peer dependency, loaded on demand — install only
30
+ * the one your database uses (`@libsql/client`, `postgres`, or `@electric-sql/pglite`).
30
31
  */
31
32
  declare function createDb(config: CreateDbConfig): Promise<ApexDbHandle>;
32
33
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { existsSync, readdirSync, readFileSync } from "fs";
2
+ import { existsSync, readFileSync, readdirSync } from "fs";
3
3
  import { join } from "path";
4
4
  import { defineApexRoute } from "@apex-stack/core";
5
5
  import { eq } from "drizzle-orm";
@@ -7,10 +7,19 @@ import { z } from "zod";
7
7
  function libsqlUrl(pathOrUrl) {
8
8
  return /^(file:|libsql:|https?:|:memory:)/.test(pathOrUrl) ? pathOrUrl : `file:${pathOrUrl}`;
9
9
  }
10
+ async function loadDriver(spec) {
11
+ try {
12
+ return await import(spec);
13
+ } catch {
14
+ throw new Error(
15
+ `@apex-stack/data: the "${spec}" driver isn't installed. Install only the driver your database needs \u2014 e.g. \`npm i ${spec}\`.`
16
+ );
17
+ }
18
+ }
10
19
  async function createDb(config) {
11
20
  const cfg = typeof config === "string" ? { driver: "libsql", url: config } : config;
12
21
  if (cfg.driver === "sqlite" || cfg.driver === "libsql") {
13
- const { createClient } = await import("@libsql/client");
22
+ const { createClient } = await loadDriver("@libsql/client");
14
23
  const { drizzle: drizzle2 } = await import("drizzle-orm/libsql");
15
24
  const client2 = createClient({ url: libsqlUrl(cfg.url) });
16
25
  return {
@@ -26,7 +35,7 @@ async function createDb(config) {
26
35
  };
27
36
  }
28
37
  if (cfg.driver === "postgres") {
29
- const postgres = (await import("postgres")).default;
38
+ const postgres = (await loadDriver("postgres")).default;
30
39
  const { drizzle: drizzle2 } = await import("drizzle-orm/postgres-js");
31
40
  const client2 = postgres(cfg.url);
32
41
  return {
@@ -41,7 +50,7 @@ async function createDb(config) {
41
50
  }
42
51
  };
43
52
  }
44
- const { PGlite } = await import("@electric-sql/pglite");
53
+ const { PGlite } = await loadDriver("@electric-sql/pglite");
45
54
  const { drizzle } = await import("drizzle-orm/pglite");
46
55
  const client = new PGlite(cfg.dir ?? "memory://");
47
56
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apex-stack/data",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Data layer for Apex JS — Drizzle-backed resources that are REST + MCP by default",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,18 +34,32 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@libsql/client": "^0.17.4",
38
- "better-sqlite3": "^11.0.0",
39
- "drizzle-orm": "^0.38.0",
37
+ "drizzle-orm": "^0.45.2",
40
38
  "zod": "^4.4.3",
41
- "@apex-stack/core": "0.1.6"
39
+ "@apex-stack/core": "0.2.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@electric-sql/pglite": "^0.5.0",
43
+ "@libsql/client": "^0.17.0",
44
+ "postgres": "^3.4.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@libsql/client": {
48
+ "optional": true
49
+ },
50
+ "postgres": {
51
+ "optional": true
52
+ },
53
+ "@electric-sql/pglite": {
54
+ "optional": true
55
+ }
42
56
  },
43
57
  "engines": {
44
58
  "node": ">=20.19"
45
59
  },
46
60
  "devDependencies": {
47
61
  "@electric-sql/pglite": "^0.5.4",
48
- "@types/better-sqlite3": "^7.6.13",
62
+ "@libsql/client": "^0.17.4",
49
63
  "postgres": "^3.4.9"
50
64
  },
51
65
  "scripts": {