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.
- package/dist/arktypeConfig-DdIO8VV1.d.ts +6130 -0
- package/dist/{arktypeConfig-CTCJm4vA.js → arktypeConfig-DxP0OcV_.js} +1014 -1033
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +2 -10
- package/dist/cli/index.d.ts +40 -34
- package/dist/cli/index.js +4 -9
- package/dist/{cli-m2H7mQpa.js → cli-BUSZTS2D.js} +213 -49
- package/dist/context/index.d.ts +50 -2
- package/dist/context/index.js +119 -5
- package/dist/db/index.d.ts +4 -4
- package/dist/db/index.js +10 -12
- package/dist/{debug-DmBrUmwe.js → debug-Cz8KzMft.js} +23 -27
- package/dist/{defineDatabase-Bjws1Jkd.d.ts → defineDatabase-CHmTgZTx.d.ts} +4 -5
- package/dist/{defineDatabase-BD3k1L7d.js → defineDatabase-CHmzpzFf.js} +2 -4
- package/dist/discovery-gHeLq8jk.d.ts +11 -0
- package/dist/{index-AbdSa1Mk.d.ts → index-M4Jp_PFM.d.ts} +2 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -8
- package/dist/{kysely-BH7QZBZw.js → kysely-Be6KwFZC.js} +45 -31
- package/dist/migrations/generator.d.ts +14 -17
- package/dist/migrations/generator.js +202 -5
- package/dist/migrations/snapshot.d.ts +1 -1
- package/dist/migrations/snapshot.js +91 -3
- package/dist/{parser-CL3Nlmsy.js → parser-DR57GOjv.js} +58 -61
- package/dist/registry.d.ts +10 -11
- package/dist/registry.js +3 -5
- package/dist/schema.d.ts +5 -2
- package/dist/schema.js +6 -3
- package/dist/snapshot-CaG5xnE2.d.ts +48 -0
- package/dist/{state-DtZ70cBR.js → state-OVuoHRC9.js} +3 -5
- package/dist/testing/index.d.ts +4 -5
- package/dist/testing/index.js +6 -10
- package/dist/transport/protocol.d.ts +7 -8
- package/dist/transport/protocol.js +34 -3
- package/dist/transport/websocket.d.ts +4 -5
- package/dist/transport/websocket.js +103 -3
- package/dist/vite/durableDb.d.ts +7 -7
- package/dist/vite/durableDb.js +29 -31
- package/package.json +12 -12
- package/dist/arktypeConfig--4OgOv4U.d.ts +0 -6
- package/dist/context-kIVZbhye.js +0 -121
- package/dist/generator-KHBZaOI1.js +0 -202
- package/dist/index-BhRiKZ4j.d.ts +0 -51
- package/dist/protocol-DEubbBbR.js +0 -35
- package/dist/push-BY3lfh-R.js +0 -8
- package/dist/push-DiHH52-G.js +0 -190
- package/dist/schema-BCjqTRvV.d.ts +0 -6
- package/dist/schema-IFq7ovQq.js +0 -8
- package/dist/snapshot-DMW6j2Ix.js +0 -93
- package/dist/snapshot-DOerumb7.d.ts +0 -125
- package/dist/state-vav3VCId.js +0 -5
- package/dist/websocket-eao2rnHL.js +0 -104
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
//#region src/migrations/snapshot.ts
|
|
4
|
-
const { generateSQLiteDrizzleJson, generateSQLiteMigration } = createRequire(import.meta.url)("drizzle-kit/api");
|
|
5
|
-
/**
|
|
6
|
-
* Create an empty snapshot (for initial migration from nothing)
|
|
7
|
-
*/
|
|
8
|
-
function createEmptySnapshot() {
|
|
9
|
-
return {
|
|
10
|
-
views: {},
|
|
11
|
-
version: "6",
|
|
12
|
-
dialect: "sqlite",
|
|
13
|
-
id: "0000000000000",
|
|
14
|
-
prevId: "",
|
|
15
|
-
tables: {},
|
|
16
|
-
enums: {},
|
|
17
|
-
_meta: {
|
|
18
|
-
tables: {},
|
|
19
|
-
columns: {}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Generate a unique snapshot ID based on timestamp
|
|
25
|
-
*/
|
|
26
|
-
function generateSnapshotId() {
|
|
27
|
-
return Date.now().toString(36).padStart(13, "0");
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate a snapshot from Drizzle schema objects
|
|
31
|
-
*
|
|
32
|
-
* @param schema - Object containing Drizzle table definitions
|
|
33
|
-
* @returns Snapshot representing the current schema state
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { users, posts } from './schema';
|
|
38
|
-
* const snapshot = await generateSnapshotFromSchema({ users, posts });
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
async function generateSnapshotFromSchema(schema) {
|
|
42
|
-
return generateSQLiteDrizzleJson(schema, void 0, "snake_case");
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Generate SQL migration statements from two snapshots
|
|
46
|
-
*
|
|
47
|
-
* @param from - Previous schema state (or empty for initial migration)
|
|
48
|
-
* @param to - Target schema state
|
|
49
|
-
* @returns Array of SQL statements to migrate from `from` to `to`
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* const statements = await generateMigrationStatements(prevSnapshot, newSnapshot);
|
|
54
|
-
* // ['CREATE TABLE users (...)', 'CREATE INDEX ...']
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
async function generateMigrationStatements(from, to) {
|
|
58
|
-
return await generateSQLiteMigration(from, to);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Serialize the schema-relevant parts of a snapshot for comparison/hashing.
|
|
62
|
-
* Includes tables, views, and enums so that changes to any of them are
|
|
63
|
-
* detected — previously only `tables` was considered.
|
|
64
|
-
*/
|
|
65
|
-
function serializeSchemaShape(snapshot) {
|
|
66
|
-
return JSON.stringify({
|
|
67
|
-
tables: snapshot.tables ?? {},
|
|
68
|
-
views: snapshot.views ?? {},
|
|
69
|
-
enums: snapshot.enums ?? {}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check if two snapshots are equivalent (no migration needed)
|
|
74
|
-
*/
|
|
75
|
-
function snapshotsEqual(a, b) {
|
|
76
|
-
return serializeSchemaShape(a) === serializeSchemaShape(b);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Create a hash of a snapshot for quick comparison
|
|
80
|
-
*/
|
|
81
|
-
function hashSnapshot(snapshot) {
|
|
82
|
-
const content = serializeSchemaShape(snapshot);
|
|
83
|
-
let hash = 0;
|
|
84
|
-
for (let i = 0; i < content.length; i++) {
|
|
85
|
-
const char = content.charCodeAt(i);
|
|
86
|
-
hash = (hash << 5) - hash + char;
|
|
87
|
-
hash = hash & hash;
|
|
88
|
-
}
|
|
89
|
-
return Math.abs(hash).toString(36);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
export { hashSnapshot as a, generateSnapshotId as i, generateMigrationStatements as n, snapshotsEqual as o, generateSnapshotFromSchema as r, createEmptySnapshot as t };
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { DrizzleSQLiteSnapshotJSON } from "drizzle-kit/api";
|
|
2
|
-
|
|
3
|
-
//#region src/migrations/snapshot.d.ts
|
|
4
|
-
type Snapshot = DrizzleSQLiteSnapshotJSON;
|
|
5
|
-
/**
|
|
6
|
-
* Create an empty snapshot (for initial migration from nothing)
|
|
7
|
-
*/
|
|
8
|
-
declare function createEmptySnapshot(): Snapshot;
|
|
9
|
-
/**
|
|
10
|
-
* Generate a unique snapshot ID based on timestamp
|
|
11
|
-
*/
|
|
12
|
-
declare function generateSnapshotId(): string;
|
|
13
|
-
/**
|
|
14
|
-
* Generate a snapshot from Drizzle schema objects
|
|
15
|
-
*
|
|
16
|
-
* @param schema - Object containing Drizzle table definitions
|
|
17
|
-
* @returns Snapshot representing the current schema state
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { users, posts } from './schema';
|
|
22
|
-
* const snapshot = await generateSnapshotFromSchema({ users, posts });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
declare function generateSnapshotFromSchema(schema: Record<string, unknown>): Promise<{
|
|
26
|
-
tables: Record<string, {
|
|
27
|
-
name: string;
|
|
28
|
-
columns: Record<string, {
|
|
29
|
-
name: string;
|
|
30
|
-
type: string;
|
|
31
|
-
primaryKey: boolean;
|
|
32
|
-
notNull: boolean;
|
|
33
|
-
default?: any;
|
|
34
|
-
autoincrement?: boolean | undefined;
|
|
35
|
-
generated?: {
|
|
36
|
-
type: "stored" | "virtual";
|
|
37
|
-
as: string;
|
|
38
|
-
} | undefined;
|
|
39
|
-
}>;
|
|
40
|
-
indexes: Record<string, {
|
|
41
|
-
name: string;
|
|
42
|
-
columns: string[];
|
|
43
|
-
isUnique: boolean;
|
|
44
|
-
where?: string | undefined;
|
|
45
|
-
}>;
|
|
46
|
-
foreignKeys: Record<string, {
|
|
47
|
-
name: string;
|
|
48
|
-
tableFrom: string;
|
|
49
|
-
columnsFrom: string[];
|
|
50
|
-
tableTo: string;
|
|
51
|
-
columnsTo: string[];
|
|
52
|
-
onUpdate?: string | undefined;
|
|
53
|
-
onDelete?: string | undefined;
|
|
54
|
-
}>;
|
|
55
|
-
compositePrimaryKeys: Record<string, {
|
|
56
|
-
columns: string[];
|
|
57
|
-
name?: string | undefined;
|
|
58
|
-
}>;
|
|
59
|
-
uniqueConstraints: Record<string, {
|
|
60
|
-
name: string;
|
|
61
|
-
columns: string[];
|
|
62
|
-
}>;
|
|
63
|
-
checkConstraints: Record<string, {
|
|
64
|
-
name: string;
|
|
65
|
-
value: string;
|
|
66
|
-
}>;
|
|
67
|
-
}>;
|
|
68
|
-
id: string;
|
|
69
|
-
prevId: string;
|
|
70
|
-
version: "6";
|
|
71
|
-
dialect: "sqlite";
|
|
72
|
-
_meta: {
|
|
73
|
-
columns: Record<string, string>;
|
|
74
|
-
tables: Record<string, string>;
|
|
75
|
-
};
|
|
76
|
-
views: Record<string, {
|
|
77
|
-
name: string;
|
|
78
|
-
columns: Record<string, {
|
|
79
|
-
name: string;
|
|
80
|
-
type: string;
|
|
81
|
-
primaryKey: boolean;
|
|
82
|
-
notNull: boolean;
|
|
83
|
-
default?: any;
|
|
84
|
-
autoincrement?: boolean | undefined;
|
|
85
|
-
generated?: {
|
|
86
|
-
type: "stored" | "virtual";
|
|
87
|
-
as: string;
|
|
88
|
-
} | undefined;
|
|
89
|
-
}>;
|
|
90
|
-
isExisting: boolean;
|
|
91
|
-
definition?: string | undefined;
|
|
92
|
-
}>;
|
|
93
|
-
enums: {};
|
|
94
|
-
internal?: {
|
|
95
|
-
indexes?: Record<string, {
|
|
96
|
-
columns: Record<string, {
|
|
97
|
-
isExpression?: boolean | undefined;
|
|
98
|
-
} | undefined>;
|
|
99
|
-
} | undefined> | undefined;
|
|
100
|
-
} | undefined;
|
|
101
|
-
}>;
|
|
102
|
-
/**
|
|
103
|
-
* Generate SQL migration statements from two snapshots
|
|
104
|
-
*
|
|
105
|
-
* @param from - Previous schema state (or empty for initial migration)
|
|
106
|
-
* @param to - Target schema state
|
|
107
|
-
* @returns Array of SQL statements to migrate from `from` to `to`
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const statements = await generateMigrationStatements(prevSnapshot, newSnapshot);
|
|
112
|
-
* // ['CREATE TABLE users (...)', 'CREATE INDEX ...']
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
declare function generateMigrationStatements(from: Snapshot, to: Snapshot): Promise<string[]>;
|
|
116
|
-
/**
|
|
117
|
-
* Check if two snapshots are equivalent (no migration needed)
|
|
118
|
-
*/
|
|
119
|
-
declare function snapshotsEqual(a: Snapshot, b: Snapshot): boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Create a hash of a snapshot for quick comparison
|
|
122
|
-
*/
|
|
123
|
-
declare function hashSnapshot(snapshot: Snapshot): string;
|
|
124
|
-
//#endregion
|
|
125
|
-
export { generateSnapshotId as a, generateSnapshotFromSchema as i, createEmptySnapshot as n, hashSnapshot as o, generateMigrationStatements as r, snapshotsEqual as s, Snapshot as t };
|
package/dist/state-vav3VCId.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import "./debug-DmBrUmwe.js";
|
|
2
|
-
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, d as init_state, f as loadDevMigrations, g as saveDevSnapshot, h as saveDevMigration, i as findNodeModules, l as getInstanceKey, m as loadDevState, n as clearDevMigrations, o as getDatabaseDevState, p as loadDevSnapshot, r as createEmptyDevState, s as getDevEpoch, t as clearDatabaseDevState, u as hasProdSnapshotChanged } from "./state-DtZ70cBR.js";
|
|
3
|
-
|
|
4
|
-
init_state();
|
|
5
|
-
export { loadDevMigrations };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { n as decodeResponse, r as encodeRequest } from "./protocol-DEubbBbR.js";
|
|
2
|
-
|
|
3
|
-
//#region src/transport/websocket.ts
|
|
4
|
-
/** Default timeout (ms) after which a pending WebSocket request rejects. */
|
|
5
|
-
const DEFAULT_WS_REQUEST_TIMEOUT_MS = 3e4;
|
|
6
|
-
/**
|
|
7
|
-
* Client-side WebSocket transport for calling DO actions over WebSocket.
|
|
8
|
-
*
|
|
9
|
-
* Manages a single WebSocket connection to a Durable Object stub,
|
|
10
|
-
* with request-response correlation via message IDs.
|
|
11
|
-
*/
|
|
12
|
-
var WebSocketTransport = class {
|
|
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 ?? DEFAULT_WS_REQUEST_TIMEOUT_MS;
|
|
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
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
export { WebSocketTransport as n, DEFAULT_WS_REQUEST_TIMEOUT_MS as t };
|