durable-db 0.2.2 → 0.4.0
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/README.md +175 -25
- package/dist/{arktypeConfig-DxP0OcV_.js → actionArgs-1hEaDUia.js} +35 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/index.d.ts +204 -62
- package/dist/cli/index.js +4 -3
- package/dist/{cli-BUSZTS2D.js → cli-CVS0b2im.js} +272 -95
- package/dist/context/index.js +14 -8
- package/dist/db/index.d.ts +2 -3
- package/dist/db/index.js +216 -25
- package/dist/defineDatabase-D_RpcKj1.js +109 -0
- package/dist/{defineDatabase-IUthY3Ex.d.ts → defineDatabase-zrUJrMd5.d.ts} +10 -3
- package/dist/{index-BdrcuAU7.d.ts → index-CJ6Focq4.d.ts} +70 -17
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/{kysely-Be6KwFZC.js → kysely-CYmmiwDm.js} +25 -5
- package/dist/migrations/generator.d.ts +1 -1
- package/dist/migrations/generator.js +1 -1
- package/dist/migrations/snapshot.d.ts +2 -2
- package/dist/migrations/snapshot.js +1 -91
- package/dist/{parser-DR57GOjv.js → parser-DyepmXzE.js} +1 -1
- package/dist/registry.d.ts +29 -2
- package/dist/registry.js +2 -2
- package/dist/snapshot-B9Ae2TrS.d.ts +180 -0
- package/dist/snapshot-D_z95s6E.js +459 -0
- package/dist/{state-OVuoHRC9.js → state-DGYycIoJ.js} +106 -9
- package/dist/testing/index.d.ts +8 -1
- package/dist/testing/index.js +30 -11
- package/dist/vite/durableDb.d.ts +130 -1
- package/dist/vite/durableDb.js +733 -180
- package/package.json +15 -14
- package/virtual.d.ts +4 -2
- package/dist/arktypeConfig-AXvobTPL.d.ts +0 -5
- package/dist/defineDatabase-CHmzpzFf.js +0 -70
- package/dist/snapshot-CaG5xnE2.d.ts +0 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "durable-db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/eagerpatch/durable-db.git"
|
|
@@ -78,39 +78,40 @@
|
|
|
78
78
|
"changeset": "changeset"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@babel/generator": "^
|
|
82
|
-
"@babel/parser": "^
|
|
83
|
-
"@babel/traverse": "^
|
|
84
|
-
"@babel/types": "^
|
|
81
|
+
"@babel/generator": "^8.0.6",
|
|
82
|
+
"@babel/parser": "^8.0.7",
|
|
83
|
+
"@babel/traverse": "^8.0.7",
|
|
84
|
+
"@babel/types": "^8.0.6",
|
|
85
85
|
"@outerbase/browsable-durable-object": "^0.1.0",
|
|
86
86
|
"arktype": "^2.2.8",
|
|
87
87
|
"commander": "^15.0.0",
|
|
88
88
|
"drizzle-kit": "^0.31.11",
|
|
89
|
-
"drizzle-orm": "^0.
|
|
89
|
+
"drizzle-orm": "^0.45.4",
|
|
90
90
|
"esbuild": "^0.27.1",
|
|
91
|
+
"jsonc-parser": "^3.3.1",
|
|
91
92
|
"kysely": "^0.29.6",
|
|
92
93
|
"libsql": "^0.5.0",
|
|
93
94
|
"magic-string": "^0.30.21"
|
|
94
95
|
},
|
|
95
96
|
"peerDependencies": {
|
|
96
|
-
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
97
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
97
98
|
},
|
|
98
99
|
"devDependencies": {
|
|
99
|
-
"@babel/generator": "^
|
|
100
|
-
"@babel/parser": "^
|
|
101
|
-
"@babel/traverse": "^
|
|
102
|
-
"@babel/types": "^
|
|
100
|
+
"@babel/generator": "^8.0.6",
|
|
101
|
+
"@babel/parser": "^8.0.7",
|
|
102
|
+
"@babel/traverse": "^8.0.7",
|
|
103
|
+
"@babel/types": "^8.0.6",
|
|
103
104
|
"@changesets/cli": "^3.0.3",
|
|
104
|
-
"@cloudflare/vitest-pool-workers": "^0.23.0",
|
|
105
105
|
"@cloudflare/workers-types": "^5.20261016.1",
|
|
106
106
|
"@types/babel__generator": "^7.6.8",
|
|
107
107
|
"@types/babel__traverse": "^7.20.6",
|
|
108
108
|
"@types/node": "^26.6.5",
|
|
109
|
-
"drizzle-kit": "^0.
|
|
109
|
+
"drizzle-kit": "^0.31.11",
|
|
110
110
|
"esbuild": "^0.27.1",
|
|
111
111
|
"tsdown": "^0.23.1",
|
|
112
112
|
"typescript": "^7.0.2",
|
|
113
113
|
"vite": "^8.3.4",
|
|
114
|
-
"vitest": "^5.0.5"
|
|
114
|
+
"vitest": "^5.0.5",
|
|
115
|
+
"@cloudflare/vitest-plugin": "^1.4.4"
|
|
115
116
|
}
|
|
116
117
|
}
|
package/virtual.d.ts
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
declare module "virtual:durable-db/__durableObjects";
|
|
6
6
|
|
|
7
7
|
// Dev-epoch helpers baked in at build time. `applyDevEpoch` suffixes instance
|
|
8
|
-
// keys with the
|
|
8
|
+
// keys with the database's dev epoch — its own after `db reset --database`,
|
|
9
|
+
// else the project's (identity in production builds).
|
|
9
10
|
declare module "virtual:durable-db/__devEpoch" {
|
|
10
11
|
export const devEpoch: string | null;
|
|
11
|
-
export
|
|
12
|
+
export const devEpochs: Record<string, string>;
|
|
13
|
+
export function applyDevEpoch(key: string, dbName?: string): string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/** @deprecated Use "virtual:durable-db/__durableObjects" instead. */
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { t as type } from "./arktypeConfig-DxP0OcV_.js";
|
|
2
|
-
//#region src/db/defineDatabase.ts
|
|
3
|
-
/**
|
|
4
|
-
* Non-enumerable property the source `action()` stashes on the function it
|
|
5
|
-
* returns, carrying the original `{ args, handler }` config plus the compiled
|
|
6
|
-
* arktype validator. The production Vite transform replaces `action()`
|
|
7
|
-
* call-sites entirely, so this only ever exists in the UNTRANSFORMED world —
|
|
8
|
-
* i.e. tests. The `durable-db/testing` harness reads it to run a handler
|
|
9
|
-
* against a real in-memory database. See src/testing/index.ts.
|
|
10
|
-
*/
|
|
11
|
-
const ACTION_TEST_META = Symbol.for("durable-db.actionTestMeta");
|
|
12
|
-
/**
|
|
13
|
-
* Define a database with its schema and migrations.
|
|
14
|
-
*
|
|
15
|
-
* This function is transformed at build time by the durable-db Vite plugin.
|
|
16
|
-
* At runtime, the actions returned will be RPC stubs that call into the
|
|
17
|
-
* generated Durable Object.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { defineDatabase } from 'durable-db';
|
|
22
|
-
* import { users, posts } from './schema';
|
|
23
|
-
*
|
|
24
|
-
* export const { action } = defineDatabase({
|
|
25
|
-
* schema: { users, posts },
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* export const createUser = action({
|
|
29
|
-
* args: { name: 'string', email: 'string.email' },
|
|
30
|
-
* handler: async (db, args) => {
|
|
31
|
-
* return db.insertInto('users').values({
|
|
32
|
-
* id: crypto.randomUUID(),
|
|
33
|
-
* name: args.name,
|
|
34
|
-
* email: args.email
|
|
35
|
-
* }).returningAll().executeTakeFirst();
|
|
36
|
-
* },
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
function defineDatabase(_config) {
|
|
41
|
-
const action = (actionConfig) => {
|
|
42
|
-
const validator = type(actionConfig.args);
|
|
43
|
-
const argKeys = Object.keys(actionConfig.args);
|
|
44
|
-
const argsHint = argKeys.length > 0 ? `args: { ${argKeys.join(", ")} }` : "args: {}";
|
|
45
|
-
const actionFn = async (args) => {
|
|
46
|
-
const result = validator(args);
|
|
47
|
-
if (result instanceof type.errors) throw new Error(`Invalid args for action (${argsHint}): ${result.summary}`);
|
|
48
|
-
throw new Error(`Action (${argsHint}) called without transformation. Make sure the durable-db plugin is configured in your Vite config.`);
|
|
49
|
-
};
|
|
50
|
-
Object.defineProperty(actionFn, ACTION_TEST_META, {
|
|
51
|
-
value: {
|
|
52
|
-
args: actionConfig.args,
|
|
53
|
-
handler: actionConfig.handler,
|
|
54
|
-
validator
|
|
55
|
-
},
|
|
56
|
-
enumerable: false,
|
|
57
|
-
configurable: true
|
|
58
|
-
});
|
|
59
|
-
return actionFn;
|
|
60
|
-
};
|
|
61
|
-
const destroyDatabase = async () => {
|
|
62
|
-
throw new Error("destroyDatabase() called without transformation. Make sure the durable-db plugin is configured in your Vite config.");
|
|
63
|
-
};
|
|
64
|
-
return {
|
|
65
|
-
action,
|
|
66
|
-
destroyDatabase
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//#endregion
|
|
70
|
-
export { defineDatabase as n, ACTION_TEST_META as t };
|
|
@@ -1,48 +0,0 @@
|
|
|
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 };
|