durable-db 0.2.0 → 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 +27 -29
- package/dist/cli/index.js +4 -9
- package/dist/{cli-DnsOTcrH.js → cli-BUSZTS2D.js} +196 -19
- 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-DtkM6k1S.d.ts → defineDatabase-CHmTgZTx.d.ts} +4 -5
- package/dist/{defineDatabase-BD3k1L7d.js → defineDatabase-CHmzpzFf.js} +2 -4
- package/dist/{discovery-DfimBbS_.d.ts → discovery-gHeLq8jk.d.ts} +1 -1
- package/dist/{index-BHLOQ7uV.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-BdV7Zqcv.js → parser-DR57GOjv.js} +21 -19
- 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 +6 -7
- package/dist/vite/durableDb.js +23 -28
- package/package.json +12 -12
- package/dist/arktypeConfig-zgI5p6zF.d.ts +0 -6
- package/dist/context-kIVZbhye.js +0 -121
- package/dist/generator-KHBZaOI1.js +0 -202
- package/dist/index-zzQS_psa.d.ts +0 -51
- package/dist/protocol-DEubbBbR.js +0 -35
- package/dist/push-BhrMZaQx.js +0 -190
- package/dist/push-cUJBpv5y.js +0 -8
- package/dist/schema-C2yy5KCT.d.ts +0 -6
- package/dist/schema-IFq7ovQq.js +0 -8
- package/dist/snapshot-DMW6j2Ix.js +0 -93
- package/dist/snapshot-DsSRYFe-.d.ts +0 -125
- package/dist/state-vav3VCId.js +0 -5
- package/dist/websocket-eao2rnHL.js +0 -104
|
@@ -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 };
|