durable-db 0.1.13 → 0.2.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.
Files changed (52) hide show
  1. package/dist/arktypeConfig-DdIO8VV1.d.ts +6130 -0
  2. package/dist/{arktypeConfig-CTCJm4vA.js → arktypeConfig-DxP0OcV_.js} +1014 -1033
  3. package/dist/cli/bin.d.ts +1 -1
  4. package/dist/cli/bin.js +2 -10
  5. package/dist/cli/index.d.ts +40 -34
  6. package/dist/cli/index.js +4 -9
  7. package/dist/{cli-m2H7mQpa.js → cli-BUSZTS2D.js} +213 -49
  8. package/dist/context/index.d.ts +50 -2
  9. package/dist/context/index.js +119 -5
  10. package/dist/db/index.d.ts +4 -4
  11. package/dist/db/index.js +10 -12
  12. package/dist/{debug-DmBrUmwe.js → debug-Cz8KzMft.js} +23 -27
  13. package/dist/{defineDatabase-Bjws1Jkd.d.ts → defineDatabase-CHmTgZTx.d.ts} +4 -5
  14. package/dist/{defineDatabase-BD3k1L7d.js → defineDatabase-CHmzpzFf.js} +2 -4
  15. package/dist/discovery-gHeLq8jk.d.ts +11 -0
  16. package/dist/{index-AbdSa1Mk.d.ts → index-M4Jp_PFM.d.ts} +2 -1
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.js +5 -8
  19. package/dist/{kysely-BH7QZBZw.js → kysely-Be6KwFZC.js} +45 -31
  20. package/dist/migrations/generator.d.ts +14 -17
  21. package/dist/migrations/generator.js +202 -5
  22. package/dist/migrations/snapshot.d.ts +1 -1
  23. package/dist/migrations/snapshot.js +91 -3
  24. package/dist/{parser-CL3Nlmsy.js → parser-DR57GOjv.js} +58 -61
  25. package/dist/registry.d.ts +10 -11
  26. package/dist/registry.js +3 -5
  27. package/dist/schema.d.ts +5 -2
  28. package/dist/schema.js +6 -3
  29. package/dist/snapshot-CaG5xnE2.d.ts +48 -0
  30. package/dist/{state-DtZ70cBR.js → state-OVuoHRC9.js} +3 -5
  31. package/dist/testing/index.d.ts +4 -5
  32. package/dist/testing/index.js +6 -10
  33. package/dist/transport/protocol.d.ts +7 -8
  34. package/dist/transport/protocol.js +34 -3
  35. package/dist/transport/websocket.d.ts +4 -5
  36. package/dist/transport/websocket.js +103 -3
  37. package/dist/vite/durableDb.d.ts +7 -7
  38. package/dist/vite/durableDb.js +29 -31
  39. package/package.json +12 -12
  40. package/dist/arktypeConfig--4OgOv4U.d.ts +0 -6
  41. package/dist/context-kIVZbhye.js +0 -121
  42. package/dist/generator-KHBZaOI1.js +0 -202
  43. package/dist/index-BhRiKZ4j.d.ts +0 -51
  44. package/dist/protocol-DEubbBbR.js +0 -35
  45. package/dist/push-BY3lfh-R.js +0 -8
  46. package/dist/push-DiHH52-G.js +0 -190
  47. package/dist/schema-BCjqTRvV.d.ts +0 -6
  48. package/dist/schema-IFq7ovQq.js +0 -8
  49. package/dist/snapshot-DMW6j2Ix.js +0 -93
  50. package/dist/snapshot-DOerumb7.d.ts +0 -125
  51. package/dist/state-vav3VCId.js +0 -5
  52. package/dist/websocket-eao2rnHL.js +0 -104
package/dist/schema.js CHANGED
@@ -1,3 +1,6 @@
1
- import { a as numeric, c as table, i as integer, l as text, n as foreignKey, o as primaryKey, r as index, s as real, t as blob, u as uniqueIndex } from "./schema-IFq7ovQq.js";
2
-
3
- export { blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex };
1
+ import { blob, foreignKey, index, integer, numeric, primaryKey, real, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
2
+ import { toSnakeCase } from "drizzle-orm/casing";
3
+ //#region src/schema.ts
4
+ const table = ((name, columns, extraConfig) => sqliteTable(toSnakeCase(name), columns, extraConfig));
5
+ //#endregion
6
+ export { blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex };
@@ -0,0 +1,48 @@
1
+ import { DrizzleSQLiteSnapshotJSON } from "drizzle-kit/api";
2
+ //#region src/migrations/snapshot.d.ts
3
+ type Snapshot = DrizzleSQLiteSnapshotJSON;
4
+ /**
5
+ * Create an empty snapshot (for initial migration from nothing)
6
+ */
7
+ declare function createEmptySnapshot(): Snapshot;
8
+ /**
9
+ * Generate a unique snapshot ID based on timestamp
10
+ */
11
+ declare function generateSnapshotId(): string;
12
+ /**
13
+ * Generate a snapshot from Drizzle schema objects
14
+ *
15
+ * @param schema - Object containing Drizzle table definitions
16
+ * @returns Snapshot representing the current schema state
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { users, posts } from './schema';
21
+ * const snapshot = await generateSnapshotFromSchema({ users, posts });
22
+ * ```
23
+ */
24
+ declare function generateSnapshotFromSchema(schema: Record<string, unknown>): Promise<any>;
25
+ /**
26
+ * Generate SQL migration statements from two snapshots
27
+ *
28
+ * @param from - Previous schema state (or empty for initial migration)
29
+ * @param to - Target schema state
30
+ * @returns Array of SQL statements to migrate from `from` to `to`
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const statements = await generateMigrationStatements(prevSnapshot, newSnapshot);
35
+ * // ['CREATE TABLE users (...)', 'CREATE INDEX ...']
36
+ * ```
37
+ */
38
+ declare function generateMigrationStatements(from: Snapshot, to: Snapshot): Promise<string[]>;
39
+ /**
40
+ * Check if two snapshots are equivalent (no migration needed)
41
+ */
42
+ declare function snapshotsEqual(a: Snapshot, b: Snapshot): boolean;
43
+ /**
44
+ * Create a hash of a snapshot for quick comparison
45
+ */
46
+ declare function hashSnapshot(snapshot: Snapshot): string;
47
+ //#endregion
48
+ export { generateSnapshotId as a, generateSnapshotFromSchema as i, createEmptySnapshot as n, hashSnapshot as o, generateMigrationStatements as r, snapshotsEqual as s, Snapshot as t };
@@ -1,9 +1,8 @@
1
- import { a as __esmMin, i as init_debug, o as __export, t as debugCli } from "./debug-DmBrUmwe.js";
1
+ import { a as __esmMin, i as init_debug, o as __exportAll, t as debugCli } from "./debug-Cz8KzMft.js";
2
2
  import * as fs from "node:fs";
3
3
  import * as path$1 from "node:path";
4
-
5
4
  //#region src/cli/state.ts
6
- var state_exports = /* @__PURE__ */ __export({
5
+ var state_exports = /* @__PURE__ */ __exportAll({
7
6
  clearDatabaseDevState: () => clearDatabaseDevState,
8
7
  clearDevMigrations: () => clearDevMigrations,
9
8
  createEmptyDevState: () => createEmptyDevState,
@@ -198,6 +197,5 @@ var init_state = __esmMin((() => {
198
197
  DEV_SNAPSHOT_FILE = "_snapshot.json";
199
198
  BREAKPOINT_MARKER = /^-->\s*breakpoint\s*$/im;
200
199
  }));
201
-
202
200
  //#endregion
203
- export { saveDevState as _, generateEpoch as a, getDevPaths as c, init_state as d, loadDevMigrations as f, saveDevSnapshot as g, saveDevMigration as h, findNodeModules as i, getInstanceKey as l, loadDevState as m, clearDevMigrations as n, getDatabaseDevState as o, loadDevSnapshot as p, createEmptyDevState as r, getDevEpoch as s, clearDatabaseDevState as t, hasProdSnapshotChanged as u, state_exports as v };
201
+ export { getDevPaths as a, loadDevMigrations as c, saveDevState as d, state_exports as f, getDevEpoch as i, loadDevState as l, clearDevMigrations as n, getInstanceKey as o, generateEpoch as r, init_state as s, clearDatabaseDevState as t, saveDevMigration as u };
@@ -1,10 +1,9 @@
1
1
  import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
2
2
  import { Kysely } from "kysely";
3
3
  import { DatabaseSync } from "node:sqlite";
4
-
5
4
  //#region src/testing/index.d.ts
6
5
  type Schema = Record<string, SQLiteTableWithColumns<any>>;
7
- interface CreateTestDatabaseOptions {
6
+ export interface CreateTestDatabaseOptions {
8
7
  /**
9
8
  * The drizzle schema (the same object passed to `defineDatabase({ schema })`).
10
9
  * Tables are created from it automatically.
@@ -22,7 +21,7 @@ interface CreateTestDatabaseOptions {
22
21
  */
23
22
  tenantId?: string;
24
23
  }
25
- interface TestDatabase<TSchema = any> {
24
+ export interface TestDatabase<TSchema = any> {
26
25
  /** The Kysely instance, for direct seeding and assertions. */
27
26
  db: Kysely<TSchema>;
28
27
  /**
@@ -52,6 +51,6 @@ interface TestDatabase<TSchema = any> {
52
51
  * t.destroy();
53
52
  * ```
54
53
  */
55
- declare function createTestDatabase<TSchema = any>(options: CreateTestDatabaseOptions): Promise<TestDatabase<TSchema>>;
54
+ export declare function createTestDatabase<TSchema = any>(options: CreateTestDatabaseOptions): Promise<TestDatabase<TSchema>>;
56
55
  //#endregion
57
- export { CreateTestDatabaseOptions, TestDatabase, createTestDatabase };
56
+ export {};
@@ -1,12 +1,9 @@
1
- import "../debug-DmBrUmwe.js";
2
- import { t as type } from "../arktypeConfig-CTCJm4vA.js";
3
- import { t as ACTION_TEST_META } from "../defineDatabase-BD3k1L7d.js";
4
- import "../state-DtZ70cBR.js";
5
- import { a as setTenantIdResolver } from "../context-kIVZbhye.js";
6
- import { t as createKyselyFromSql } from "../kysely-BH7QZBZw.js";
7
- import { n as generateMigrationStatements, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-DMW6j2Ix.js";
1
+ import { t as type } from "../arktypeConfig-DxP0OcV_.js";
2
+ import { t as ACTION_TEST_META } from "../defineDatabase-CHmzpzFf.js";
3
+ import { setTenantIdResolver } from "../context/index.js";
4
+ import { t as createKyselyFromSql } from "../kysely-Be6KwFZC.js";
5
+ import { createEmptySnapshot, generateMigrationStatements, generateSnapshotFromSchema } from "../migrations/snapshot.js";
8
6
  import { createRequire } from "node:module";
9
-
10
7
  //#region src/testing/index.ts
11
8
  const loadSqlite = () => createRequire(import.meta.url)("node:sqlite");
12
9
  /**
@@ -67,6 +64,5 @@ async function createTestDatabase(options) {
67
64
  }
68
65
  };
69
66
  }
70
-
71
67
  //#endregion
72
- export { createTestDatabase };
68
+ export { createTestDatabase };
@@ -4,13 +4,13 @@
4
4
  *
5
5
  * JSON text frames with request-response correlation via `id`.
6
6
  */
7
- interface WsActionRequest {
7
+ export interface WsActionRequest {
8
8
  id: string;
9
9
  action: string;
10
10
  args: unknown;
11
11
  instanceKey: string;
12
12
  }
13
- type WsActionResponse = {
13
+ export type WsActionResponse = {
14
14
  id: string;
15
15
  ok: true;
16
16
  result: unknown;
@@ -19,9 +19,8 @@ type WsActionResponse = {
19
19
  ok: false;
20
20
  error: string;
21
21
  };
22
- declare function encodeRequest(req: WsActionRequest): string;
23
- declare function decodeRequest(data: string): WsActionRequest;
24
- declare function encodeResponse(res: WsActionResponse): string;
25
- declare function decodeResponse(data: string): WsActionResponse;
26
- //#endregion
27
- export { WsActionRequest, WsActionResponse, decodeRequest, decodeResponse, encodeRequest, encodeResponse };
22
+ export declare function encodeRequest(req: WsActionRequest): string;
23
+ export declare function decodeRequest(data: string): WsActionRequest;
24
+ export declare function encodeResponse(res: WsActionResponse): string;
25
+ export declare function decodeResponse(data: string): WsActionResponse;
26
+ //#endregion
@@ -1,3 +1,34 @@
1
- import { i as encodeResponse, n as decodeResponse, r as encodeRequest, t as decodeRequest } from "../protocol-DEubbBbR.js";
2
-
3
- export { decodeRequest, decodeResponse, encodeRequest, encodeResponse };
1
+ //#region src/transport/protocol.ts
2
+ function encodeRequest(req) {
3
+ return JSON.stringify(req);
4
+ }
5
+ function decodeRequest(data) {
6
+ const parsed = JSON.parse(data);
7
+ if (typeof parsed !== "object" || parsed === null) throw new Error(`Invalid WsActionRequest: expected object, got ${parsed === null ? "null" : typeof parsed}`);
8
+ const obj = parsed;
9
+ for (const field of [
10
+ "id",
11
+ "action",
12
+ "instanceKey"
13
+ ]) if (typeof obj[field] !== "string") throw new Error(`Invalid WsActionRequest: '${field}' must be a string, got ${describeType(obj[field])}`);
14
+ return obj;
15
+ }
16
+ function encodeResponse(res) {
17
+ return JSON.stringify(res);
18
+ }
19
+ function decodeResponse(data) {
20
+ const parsed = JSON.parse(data);
21
+ if (typeof parsed !== "object" || parsed === null) throw new Error(`Invalid WsActionResponse: expected object, got ${parsed === null ? "null" : typeof parsed}`);
22
+ const obj = parsed;
23
+ if (typeof obj.id !== "string") throw new Error(`Invalid WsActionResponse: 'id' must be a string, got ${describeType(obj.id)}`);
24
+ if (typeof obj.ok !== "boolean") throw new Error(`Invalid WsActionResponse: 'ok' must be a boolean, got ${describeType(obj.ok)}`);
25
+ if (!obj.ok && typeof obj.error !== "string") throw new Error(`Invalid WsActionResponse: 'error' must be a string when ok=false, got ${describeType(obj.error)}`);
26
+ return obj;
27
+ }
28
+ function describeType(value) {
29
+ if (value === null) return "null";
30
+ if (Array.isArray(value)) return "array";
31
+ return typeof value;
32
+ }
33
+ //#endregion
34
+ export { decodeRequest, decodeResponse, encodeRequest, encodeResponse };
@@ -1,7 +1,7 @@
1
1
  //#region src/transport/websocket.d.ts
2
2
  /** Default timeout (ms) after which a pending WebSocket request rejects. */
3
- declare const DEFAULT_WS_REQUEST_TIMEOUT_MS = 30000;
4
- interface WebSocketTransportOptions {
3
+ export declare const DEFAULT_WS_REQUEST_TIMEOUT_MS = 30000;
4
+ export interface WebSocketTransportOptions {
5
5
  /** Per-request timeout in ms. Set to 0 or Infinity to disable. */
6
6
  requestTimeoutMs?: number;
7
7
  }
@@ -11,7 +11,7 @@ interface WebSocketTransportOptions {
11
11
  * Manages a single WebSocket connection to a Durable Object stub,
12
12
  * with request-response correlation via message IDs.
13
13
  */
14
- declare class WebSocketTransport {
14
+ export declare class WebSocketTransport {
15
15
  private stub;
16
16
  private ws;
17
17
  private pending;
@@ -27,5 +27,4 @@ declare class WebSocketTransport {
27
27
  private onClose;
28
28
  close(): void;
29
29
  }
30
- //#endregion
31
- export { DEFAULT_WS_REQUEST_TIMEOUT_MS, WebSocketTransport, WebSocketTransportOptions };
30
+ //#endregion
@@ -1,3 +1,103 @@
1
- import { n as WebSocketTransport, t as DEFAULT_WS_REQUEST_TIMEOUT_MS } from "../websocket-eao2rnHL.js";
2
-
3
- export { DEFAULT_WS_REQUEST_TIMEOUT_MS, WebSocketTransport };
1
+ import { decodeResponse, encodeRequest } from "./protocol.js";
2
+ //#region src/transport/websocket.ts
3
+ /** Default timeout (ms) after which a pending WebSocket request rejects. */
4
+ const DEFAULT_WS_REQUEST_TIMEOUT_MS = 3e4;
5
+ /**
6
+ * Client-side WebSocket transport for calling DO actions over WebSocket.
7
+ *
8
+ * Manages a single WebSocket connection to a Durable Object stub,
9
+ * with request-response correlation via message IDs.
10
+ */
11
+ var WebSocketTransport = class {
12
+ stub;
13
+ ws = null;
14
+ pending = /* @__PURE__ */ new Map();
15
+ connectPromise = null;
16
+ requestTimeoutMs;
17
+ constructor(stub, options = {}) {
18
+ this.stub = stub;
19
+ this.requestTimeoutMs = options.requestTimeoutMs ?? 3e4;
20
+ }
21
+ async call(action, args, instanceKey) {
22
+ await this.ensureConnected();
23
+ const id = crypto.randomUUID();
24
+ const message = encodeRequest({
25
+ id,
26
+ action,
27
+ args,
28
+ instanceKey
29
+ });
30
+ return new Promise((resolve, reject) => {
31
+ const timer = this.requestTimeoutMs > 0 && Number.isFinite(this.requestTimeoutMs) ? setTimeout(() => {
32
+ const entry = this.pending.get(id);
33
+ if (!entry) return;
34
+ this.pending.delete(id);
35
+ entry.reject(/* @__PURE__ */ new Error(`[db] WebSocket request '${action}' timed out after ${this.requestTimeoutMs}ms`));
36
+ }, this.requestTimeoutMs) : null;
37
+ this.pending.set(id, {
38
+ resolve,
39
+ reject,
40
+ timer
41
+ });
42
+ this.ws.send(message);
43
+ });
44
+ }
45
+ async ensureConnected() {
46
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) return;
47
+ if (this.connectPromise) return this.connectPromise;
48
+ this.connectPromise = this.connect();
49
+ try {
50
+ await this.connectPromise;
51
+ } finally {
52
+ this.connectPromise = null;
53
+ }
54
+ }
55
+ async connect() {
56
+ const ws = (await this.stub.fetch(new Request("https://do/ws", { headers: { Upgrade: "websocket" } }))).webSocket;
57
+ if (!ws) throw new Error("WebSocket upgrade failed: no webSocket on response");
58
+ ws.accept();
59
+ this.ws = ws;
60
+ ws.addEventListener("message", (event) => {
61
+ this.onMessage(event);
62
+ });
63
+ ws.addEventListener("close", () => {
64
+ this.onClose();
65
+ });
66
+ ws.addEventListener("error", () => {
67
+ this.onClose();
68
+ });
69
+ }
70
+ onMessage(event) {
71
+ const raw = typeof event.data === "string" ? event.data : String(event.data);
72
+ let response;
73
+ try {
74
+ response = decodeResponse(raw);
75
+ } catch (e) {
76
+ const message = e instanceof Error ? e.message : String(e);
77
+ console.warn(`[db] WebSocket received malformed message (ignored): ${message}. First 120 chars: ${raw.slice(0, 120)}`);
78
+ return;
79
+ }
80
+ const pending = this.pending.get(response.id);
81
+ if (!pending) return;
82
+ this.pending.delete(response.id);
83
+ if (pending.timer) clearTimeout(pending.timer);
84
+ if (response.ok) pending.resolve(response.result);
85
+ else pending.reject(new Error(response.error));
86
+ }
87
+ onClose() {
88
+ this.ws = null;
89
+ for (const [, entry] of this.pending) {
90
+ if (entry.timer) clearTimeout(entry.timer);
91
+ entry.reject(/* @__PURE__ */ new Error("WebSocket connection closed"));
92
+ }
93
+ this.pending.clear();
94
+ }
95
+ close() {
96
+ if (this.ws) {
97
+ this.ws.close(1e3, "Client closing");
98
+ this.ws = null;
99
+ }
100
+ }
101
+ };
102
+ //#endregion
103
+ export { DEFAULT_WS_REQUEST_TIMEOUT_MS, WebSocketTransport };
@@ -1,13 +1,13 @@
1
+ import { t as DatabaseSource } from "../discovery-gHeLq8jk.js";
1
2
  import { Plugin } from "vite";
2
-
3
3
  //#region src/vite/durableDb.d.ts
4
- interface DurableDbOptions {
4
+ export interface DurableDbOptions {
5
5
  /** Import path for the context module. Default: 'durable-db/context' */
6
6
  contextImport?: string;
7
7
  /** Import path for the registry module. Default: 'durable-db/registry' */
8
8
  registryImport?: string;
9
9
  /** Directory containing database definitions. Default: 'src/databases' */
10
- databasesDir?: string;
10
+ databasesDir?: string | DatabaseSource[];
11
11
  /** Directory for production migrations, relative to project root. Default: 'migrations' */
12
12
  migrationsDir?: string;
13
13
  /**
@@ -18,10 +18,10 @@ interface DurableDbOptions {
18
18
  */
19
19
  patchWranglerConfig?: boolean;
20
20
  }
21
- declare function durableDb(options?: DurableDbOptions): Plugin;
21
+ export declare function durableDb(options?: DurableDbOptions): Plugin;
22
22
  /** @deprecated Renamed to {@link durableDb}. */
23
- declare const databasePlugin: typeof durableDb;
23
+ export declare const databasePlugin: typeof durableDb;
24
24
  /** @deprecated Renamed to {@link DurableDbOptions}. */
25
- type DatabasePluginOptions = DurableDbOptions;
25
+ export type DatabasePluginOptions = DurableDbOptions;
26
26
  //#endregion
27
- export { DatabasePluginOptions, DurableDbOptions, databasePlugin, durableDb as default, durableDb };
27
+ export { type DatabaseSource, durableDb as default };
@@ -1,15 +1,12 @@
1
- import { i as init_debug, r as debugVite } from "../debug-DmBrUmwe.js";
2
- import { _ as saveDevState, c as getDevPaths, d as init_state, m as loadDevState } from "../state-DtZ70cBR.js";
3
- import "../snapshot-DMW6j2Ix.js";
4
- import { a as loadMigrationFiles } from "../generator-KHBZaOI1.js";
5
- import { a as readFile, i as discoverDatabaseFiles, n as parseDatabaseFile, r as discoverActionFiles, t as BABEL_PARSER_PLUGINS } from "../parser-CL3Nlmsy.js";
1
+ import { i as init_debug, r as debugVite } from "../debug-Cz8KzMft.js";
2
+ import { a as getDevPaths, d as saveDevState, l as loadDevState, s as init_state } from "../state-OVuoHRC9.js";
3
+ import { loadMigrationFiles } from "../migrations/generator.js";
4
+ import { a as discoverDatabaseFiles, i as discoverActionFiles, n as parseDatabaseFile, o as readFile, r as databaseSources, t as BABEL_PARSER_PLUGINS } from "../parser-DR57GOjv.js";
6
5
  import * as fs from "node:fs";
7
- import * as path$1 from "node:path";
8
- import path from "node:path";
6
+ import path, * as path$1 from "node:path";
9
7
  import { parse } from "@babel/parser";
10
8
  import _generate from "@babel/generator";
11
9
  import * as t from "@babel/types";
12
-
13
10
  //#region src/vite/modules/wrangler.ts
14
11
  init_debug();
15
12
  /**
@@ -262,7 +259,6 @@ function generateRequiredConfig(databases) {
262
259
  }]
263
260
  };
264
261
  }
265
-
266
262
  //#endregion
267
263
  //#region src/vite/modules/generator.ts
268
264
  const generate = typeof _generate === "function" ? _generate : _generate.default;
@@ -281,7 +277,8 @@ function parseProgram(code) {
281
277
  });
282
278
  }
283
279
  function parseExpression(code) {
284
- const stmt = parse(`(${code.trim().replace(/;\s*$/, "")})`, {
280
+ const wrapped = `(${code.trim().replace(/;\s*$/, "")})`;
281
+ const stmt = parse(wrapped, {
285
282
  sourceType: "module",
286
283
  plugins: BABEL_PARSER_PLUGINS
287
284
  }).program.body[0];
@@ -420,8 +417,8 @@ function buildDurableObjectStatements(db, bindingNamesExpr, dbTransportsExpr, is
420
417
  const classMethods = [rpcMethod, buildSysMethod()];
421
418
  if (db.transport === "websocket") classMethods.push(buildWebSocketMessageMethod(db, bindingNamesExpr, dbTransportsExpr));
422
419
  if (!isBrowsable) {
423
- const classDecl$1 = t.classDeclaration(t.identifier(db.className), t.identifier("SqliteDurableObject"), t.classBody([...dataProperties, ...classMethods]));
424
- return [t.exportNamedDeclaration(classDecl$1)];
420
+ const classDecl = t.classDeclaration(t.identifier(db.className), t.identifier("SqliteDurableObject"), t.classBody([...dataProperties, ...classMethods]));
421
+ return [t.exportNamedDeclaration(classDecl)];
425
422
  }
426
423
  const baseName = `_${db.className}_Base`;
427
424
  const innerClass = t.classExpression(null, t.identifier("SqliteDurableObject"), t.classBody([...dataProperties]));
@@ -767,7 +764,6 @@ function applyDestroyDatabaseTransform(body, database, contextImport) {
767
764
  function isDefineDatabaseCallNode(node) {
768
765
  return t.isCallExpression(node) && t.isIdentifier(node.callee) && node.callee.name === "defineDatabase";
769
766
  }
770
-
771
767
  //#endregion
772
768
  //#region src/vite/durableDb.ts
773
769
  init_debug();
@@ -798,6 +794,7 @@ function generateDevEpochModule(epoch) {
798
794
  ].join("\n");
799
795
  }
800
796
  var PluginState = class {
797
+ options;
801
798
  databases = /* @__PURE__ */ new Map();
802
799
  actions = /* @__PURE__ */ new Map();
803
800
  databaseFilePaths = /* @__PURE__ */ new Map();
@@ -874,7 +871,10 @@ var PluginState = class {
874
871
  });
875
872
  for (const file of files) {
876
873
  const code = readFile(file.absolutePath);
877
- const parsed = parseDatabaseFile(file.absolutePath, code, { aliases: this.aliases });
874
+ const parsed = parseDatabaseFile(file.absolutePath, code, {
875
+ aliases: this.aliases,
876
+ namePrefix: file.prefix
877
+ });
878
878
  if (parsed.database) {
879
879
  parsed.database.migrationsDir = path$1.resolve(this.projectRoot, this.options.migrationsDir, parsed.database.name);
880
880
  this.databases.set(parsed.database.name, parsed.database);
@@ -898,7 +898,7 @@ var PluginState = class {
898
898
  const isDev = this.config.command === "serve";
899
899
  db.migrations = loadMigrationFiles(migrationsDir);
900
900
  if (isDev) try {
901
- const { loadDevMigrations } = await import("../state-vav3VCId.js");
901
+ const { loadDevMigrations } = await import("../state-OVuoHRC9.js").then((n) => (n.s(), n.f));
902
902
  const devMigrations = loadDevMigrations(this.projectRoot, db.name);
903
903
  for (const [name, chunks] of devMigrations) db.migrations.set(`_dev_${name}`, chunks);
904
904
  if (devMigrations.size > 0) debugVite("Loaded %d dev migration(s) for %s", devMigrations.size, db.name);
@@ -974,10 +974,10 @@ function durableDb(options = {}) {
974
974
  configureServer(server) {
975
975
  state.devServer = server;
976
976
  state.reset();
977
- const absoluteDbDir = path$1.join(state.projectRoot, state.options.databasesDir);
977
+ const absoluteDbDirs = databaseSources(state.options.databasesDir).map((source) => path$1.resolve(state.projectRoot, source.dir));
978
978
  server.watcher.on("change", (file) => {
979
979
  const normalized = path$1.normalize(file);
980
- if (normalized.startsWith(absoluteDbDir) && /\.tsx?$/.test(normalized)) state.invalidateDOModule();
980
+ if (absoluteDbDirs.some((dir) => normalized.startsWith(dir)) && /\.tsx?$/.test(normalized)) state.invalidateDOModule();
981
981
  });
982
982
  const devPaths = getDevPaths(state.projectRoot);
983
983
  fs.mkdirSync(devPaths.cacheDir, { recursive: true });
@@ -1015,9 +1015,9 @@ function durableDb(options = {}) {
1015
1015
  },
1016
1016
  async load(id) {
1017
1017
  if (id === VIRTUAL_DEV_EPOCH_MODULE_ID) {
1018
- const isDev$1 = state.config.command === "serve";
1018
+ const isDev = state.config.command === "serve";
1019
1019
  let epoch = null;
1020
- if (isDev$1) {
1020
+ if (isDev) {
1021
1021
  const devState = loadDevState(state.projectRoot);
1022
1022
  if (!fs.existsSync(getDevPaths(state.projectRoot).stateFile)) {
1023
1023
  state.markSelfDevStateWrite();
@@ -1048,20 +1048,20 @@ function durableDb(options = {}) {
1048
1048
  const cleanId = path$1.normalize(id.split("?", 1)[0]);
1049
1049
  const dbNameForPath = state.getDatabaseNameForPath(cleanId);
1050
1050
  if (dbNameForPath) {
1051
- const database$1 = state.databases.get(dbNameForPath);
1052
- if (!database$1) return null;
1053
- const parsed$1 = parseDatabaseFile(cleanId, code, { aliases: state.aliases });
1054
- for (const action of parsed$1.actions) state.registerAction(action, dbNameForPath, cleanId);
1055
- const result$1 = transformDatabaseFile({
1051
+ const database = state.databases.get(dbNameForPath);
1052
+ if (!database) return null;
1053
+ const parsed = parseDatabaseFile(cleanId, code, { aliases: state.aliases });
1054
+ for (const action of parsed.actions) state.registerAction(action, dbNameForPath, cleanId);
1055
+ const result = transformDatabaseFile({
1056
1056
  code,
1057
1057
  sourceFileName: cleanId,
1058
- database: database$1,
1059
- actionsInFile: parsed$1.actions,
1058
+ database,
1059
+ actionsInFile: parsed.actions,
1060
1060
  contextImport: state.options.contextImport,
1061
1061
  registryImport: state.options.registryImport
1062
1062
  });
1063
- if (result$1 && parsed$1.actions.length > 0 && state.config.command === "serve") state.invalidateDOModule();
1064
- return result$1;
1063
+ if (result && parsed.actions.length > 0 && state.config.command === "serve") state.invalidateDOModule();
1064
+ return result;
1065
1065
  }
1066
1066
  const parsed = parseDatabaseFile(cleanId, code, { aliases: state.aliases });
1067
1067
  if (parsed.actions.length === 0) return null;
@@ -1089,7 +1089,5 @@ function durableDb(options = {}) {
1089
1089
  }
1090
1090
  /** @deprecated Renamed to {@link durableDb}. */
1091
1091
  const databasePlugin = durableDb;
1092
- var durableDb_default = durableDb;
1093
-
1094
1092
  //#endregion
1095
- export { databasePlugin, durableDb_default as default, durableDb };
1093
+ export { databasePlugin, durableDb as default, durableDb };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durable-db",
3
- "version": "0.1.13",
3
+ "version": "0.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eagerpatch/durable-db.git"
@@ -83,12 +83,12 @@
83
83
  "@babel/traverse": "^7.0.0",
84
84
  "@babel/types": "^7.0.0",
85
85
  "@outerbase/browsable-durable-object": "^0.1.0",
86
- "arktype": "^2.1.28",
86
+ "arktype": "^2.2.8",
87
87
  "commander": "^15.0.0",
88
- "drizzle-kit": "^0.30.0",
88
+ "drizzle-kit": "^0.31.11",
89
89
  "drizzle-orm": "^0.38.0",
90
90
  "esbuild": "^0.27.1",
91
- "kysely": "^0.27.0",
91
+ "kysely": "^0.29.6",
92
92
  "libsql": "^0.5.0",
93
93
  "magic-string": "^0.30.21"
94
94
  },
@@ -100,17 +100,17 @@
100
100
  "@babel/parser": "^7.26.0",
101
101
  "@babel/traverse": "^7.26.0",
102
102
  "@babel/types": "^7.26.0",
103
- "@changesets/cli": "^2.29.8",
104
- "@cloudflare/vitest-pool-workers": "^0.8.71",
105
- "@cloudflare/workers-types": "^4.20241127.0",
103
+ "@changesets/cli": "^3.0.3",
104
+ "@cloudflare/vitest-pool-workers": "^0.23.0",
105
+ "@cloudflare/workers-types": "^5.20261016.1",
106
106
  "@types/babel__generator": "^7.6.8",
107
107
  "@types/babel__traverse": "^7.20.6",
108
- "@types/node": "^24.0.0",
108
+ "@types/node": "^26.6.5",
109
109
  "drizzle-kit": "^0.30.0",
110
110
  "esbuild": "^0.27.1",
111
- "tsdown": "^0.17.2",
112
- "typescript": "^5.7.0",
113
- "vite": "^7.0.0",
114
- "vitest": "^2.1.0"
111
+ "tsdown": "^0.23.1",
112
+ "typescript": "^7.0.2",
113
+ "vite": "^8.3.4",
114
+ "vitest": "^5.0.5"
115
115
  }
116
116
  }
@@ -1,6 +0,0 @@
1
- import { type } from "arktype";
2
-
3
- //#region src/arktypeConfig.d.ts
4
- declare const type$1: typeof type;
5
- //#endregion
6
- export { type$1 as t };