durable-db 0.0.2 → 0.0.4
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/cli/bin.js +6 -6
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +6 -6
- package/dist/{cli-Cr9686BF.js → cli-AzoPlqMA.js} +6 -6
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +2 -2
- package/dist/{context-BuIiIQ6K.js → context-BcWMofTp.js} +1 -1
- package/dist/db/index.d.ts +3 -3
- package/dist/db/index.js +52 -11
- package/dist/{defineDatabase-jBv90-Pk.d.ts → defineDatabase-B8do9yYZ.d.ts} +1 -1
- package/dist/{defineDatabase-CONf4xFC.js → defineDatabase-C91B-LMQ.js} +1 -1
- package/dist/{generator-BUPP9scJ.js → generator-B4yBWHRz.js} +24 -2
- package/dist/{index-BFM5d0FP.d.ts → index-nm3-NwUh.d.ts} +23 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/migrations/generator.d.ts +1 -1
- package/dist/migrations/generator.js +2 -2
- package/dist/migrations/snapshot.d.ts +1 -1
- package/dist/migrations/snapshot.js +1 -1
- package/dist/out-CuoxKfaH.js +7446 -0
- package/dist/{push-BgQ5cnfH.js → push-BymAOkB9.js} +4 -4
- package/dist/push-CT2aX_AM.js +8 -0
- package/dist/registry.d.ts +3 -1
- package/dist/registry.js +3 -3
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/{state-BCcvNN-M.js → state-BUCIODvB.js} +1 -1
- package/dist/transport/protocol.js +1 -1
- package/dist/transport/websocket.js +1 -1
- package/dist/vite/durableDb.js +42 -12
- package/dist/{websocket-Dx1fqwnF.js → websocket-Cwc7933g.js} +1 -1
- package/package.json +1 -1
- package/dist/push-BkkaslPd.js +0 -8
- /package/dist/{index-CqVMaMYY.d.ts → index-DN2vKPw_.d.ts} +0 -0
- /package/dist/{parser-CbX54Flt.js → parser-qOiKNcYc.js} +0 -0
- /package/dist/{protocol-g_plhPOY.js → protocol-v7B4_9xU.js} +0 -0
- /package/dist/{schema-CpzTOfZ6.d.ts → schema-CjGvnsaZ.d.ts} +0 -0
- /package/dist/{schema-BOtrGnzM.js → schema-ou5L5I9Y.js} +0 -0
- /package/dist/{snapshot-D170nL7i.js → snapshot-CgEvcMZb.js} +0 -0
- /package/dist/{snapshot-C162qYoA.d.ts → snapshot-oD3wAJF2.d.ts} +0 -0
- /package/dist/{state-FOEjpgJ6.js → state-DDHYOyvD.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as init_debug, t as debugCli } from "./debug-BZJbKybf.js";
|
|
2
|
-
import { d as init_state, f as loadDevMigrations, h as saveDevMigration, n as clearDevMigrations } from "./state-
|
|
3
|
-
import { n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema } from "./snapshot-
|
|
4
|
-
import { s as loadSnapshot, t as buildAndLoadSchema } from "./generator-
|
|
5
|
-
import { a as resolveImportPath, i as readFile, n as parseDatabaseFile, r as discoverDatabaseFiles } from "./parser-
|
|
2
|
+
import { d as init_state, f as loadDevMigrations, h as saveDevMigration, n as clearDevMigrations } from "./state-DDHYOyvD.js";
|
|
3
|
+
import { n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema } from "./snapshot-CgEvcMZb.js";
|
|
4
|
+
import { s as loadSnapshot, t as buildAndLoadSchema } from "./generator-B4yBWHRz.js";
|
|
5
|
+
import { a as resolveImportPath, i as readFile, n as parseDatabaseFile, r as discoverDatabaseFiles } from "./parser-qOiKNcYc.js";
|
|
6
6
|
import * as path from "node:path";
|
|
7
7
|
import * as crypto from "node:crypto";
|
|
8
8
|
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type } from "arktype";
|
|
2
|
+
|
|
1
3
|
//#region src/registry.d.ts
|
|
2
4
|
interface ActionDefinition {
|
|
3
5
|
validator: (args: unknown) => unknown;
|
|
@@ -25,4 +27,4 @@ declare function runWithDoContext<T>(store: DoContext, fn: () => T): T;
|
|
|
25
27
|
*/
|
|
26
28
|
declare function callAction(db: unknown, targetDb: string, actionName: string, args: unknown, ctx: RpcContext): Promise<unknown>;
|
|
27
29
|
//#endregion
|
|
28
|
-
export { ActionDefinition, DoContext, RpcContext, callAction, getAction, getDoContext, registerAction, runWithDoContext };
|
|
30
|
+
export { ActionDefinition, DoContext, RpcContext, callAction, getAction, getDoContext, registerAction, runWithDoContext, type };
|
package/dist/registry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as type } from "./out-CuoxKfaH.js";
|
|
2
|
+
import { n as WebSocketTransport } from "./websocket-Cwc7933g.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
|
|
5
5
|
//#region src/registry.ts
|
|
@@ -69,4 +69,4 @@ async function callAction(db, targetDb, actionName, args, ctx) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
//#endregion
|
|
72
|
-
export { callAction, getAction, getDoContext, registerAction, runWithDoContext };
|
|
72
|
+
export { callAction, getAction, getDoContext, registerAction, runWithDoContext, type };
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-
|
|
1
|
+
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-CjGvnsaZ.js";
|
|
2
2
|
export { AnySQLiteColumn, blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex };
|
package/dist/schema.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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-
|
|
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-ou5L5I9Y.js";
|
|
2
2
|
|
|
3
3
|
export { blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./debug-BZJbKybf.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-
|
|
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-DDHYOyvD.js";
|
|
3
3
|
|
|
4
4
|
init_state();
|
|
5
5
|
export { loadDevMigrations };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as encodeResponse, n as decodeResponse, r as encodeRequest, t as decodeRequest } from "../protocol-
|
|
1
|
+
import { i as encodeResponse, n as decodeResponse, r as encodeRequest, t as decodeRequest } from "../protocol-v7B4_9xU.js";
|
|
2
2
|
|
|
3
3
|
export { decodeRequest, decodeResponse, encodeRequest, encodeResponse };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as WebSocketTransport, t as DEFAULT_WS_REQUEST_TIMEOUT_MS } from "../websocket-
|
|
1
|
+
import { n as WebSocketTransport, t as DEFAULT_WS_REQUEST_TIMEOUT_MS } from "../websocket-Cwc7933g.js";
|
|
2
2
|
|
|
3
3
|
export { DEFAULT_WS_REQUEST_TIMEOUT_MS, WebSocketTransport };
|
package/dist/vite/durableDb.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as init_debug, r as debugVite } from "../debug-BZJbKybf.js";
|
|
2
|
-
import { _ as saveDevState, c as getDevPaths, d as init_state, m as loadDevState } from "../state-
|
|
3
|
-
import "../snapshot-
|
|
4
|
-
import { a as loadMigrationFiles } from "../generator-
|
|
5
|
-
import { i as readFile, n as parseDatabaseFile, r as discoverDatabaseFiles, t as BABEL_PARSER_PLUGINS } from "../parser-
|
|
2
|
+
import { _ as saveDevState, c as getDevPaths, d as init_state, m as loadDevState } from "../state-DDHYOyvD.js";
|
|
3
|
+
import "../snapshot-CgEvcMZb.js";
|
|
4
|
+
import { a as loadMigrationFiles } from "../generator-B4yBWHRz.js";
|
|
5
|
+
import { i as readFile, n as parseDatabaseFile, r as discoverDatabaseFiles, t as BABEL_PARSER_PLUGINS } from "../parser-qOiKNcYc.js";
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
7
|
import * as path from "node:path";
|
|
8
8
|
import { parse } from "@babel/parser";
|
|
@@ -217,7 +217,8 @@ function checkWranglerConfig(projectRoot, databases) {
|
|
|
217
217
|
configPath,
|
|
218
218
|
missingBindings: [],
|
|
219
219
|
missingSqliteClasses: [],
|
|
220
|
-
ok: true
|
|
220
|
+
ok: true,
|
|
221
|
+
tomlOnly: !configPath && fs.existsSync(path.join(projectRoot, "wrangler.toml"))
|
|
221
222
|
};
|
|
222
223
|
let config = {};
|
|
223
224
|
if (configPath) try {
|
|
@@ -238,7 +239,7 @@ function checkWranglerConfig(projectRoot, databases) {
|
|
|
238
239
|
new_sqlite_classes: result.missingSqliteClasses
|
|
239
240
|
}] }
|
|
240
241
|
}, null, 2);
|
|
241
|
-
const hasToml =
|
|
242
|
+
const hasToml = result.tomlOnly;
|
|
242
243
|
const where = configPath ? path.basename(configPath) : hasToml ? "wrangler.toml (not supported — only wrangler.jsonc/json can be verified or patched)" : "wrangler.jsonc";
|
|
243
244
|
console.warn(`[durable-db] ${where} is missing Durable Object config for your database(s). Add ${hasToml ? "the equivalent of " : ""}this${configPath || hasToml ? "" : " to a new wrangler.jsonc"}:\n${snippet}\n` + (hasToml ? "" : `Or let the plugin write it for you: durableDb({ patchWranglerConfig: true })`));
|
|
244
245
|
}
|
|
@@ -596,13 +597,13 @@ function buildStubBodyStatements(config) {
|
|
|
596
597
|
function applyActionTransforms(body, ctx) {
|
|
597
598
|
const { dbName, database, actionsInFile, contextImport, registryImport } = ctx;
|
|
598
599
|
if (actionsInFile.length === 0) return false;
|
|
599
|
-
ensureNamedImports(body, "arktype", ["type"]);
|
|
600
600
|
ensureNamedImports(body, contextImport, ["getTenantId"]);
|
|
601
601
|
ensureNamedImports(body, "cloudflare:workers", ["env"]);
|
|
602
602
|
ensureNamedImports(body, registryImport, [
|
|
603
603
|
"registerAction",
|
|
604
604
|
"getDoContext",
|
|
605
|
-
"callAction"
|
|
605
|
+
"callAction",
|
|
606
|
+
"type"
|
|
606
607
|
]);
|
|
607
608
|
ensureNamedImports(body, DEV_EPOCH_IMPORT, ["applyDevEpoch"]);
|
|
608
609
|
if (database.transport === "websocket") ensureNamedImports(body, "durable-db/transport/websocket", ["WebSocketTransport"]);
|
|
@@ -752,9 +753,24 @@ var PluginState = class {
|
|
|
752
753
|
projectRoot = "";
|
|
753
754
|
config;
|
|
754
755
|
devServer = null;
|
|
756
|
+
selfDevStateWriteUntil = 0;
|
|
755
757
|
constructor(options) {
|
|
756
758
|
this.options = options;
|
|
757
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Mark an imminent write to the dev cache made by the plugin itself
|
|
762
|
+
* (persisting a freshly minted epoch on first run). The cache watcher
|
|
763
|
+
* ignores events inside this window — without it, the plugin's own
|
|
764
|
+
* bootstrap write would trigger a full reload on the very first dev-server
|
|
765
|
+
* run, before any client (or the Cloudflare worker's hot channel
|
|
766
|
+
* WebSocket) is connected.
|
|
767
|
+
*/
|
|
768
|
+
markSelfDevStateWrite() {
|
|
769
|
+
this.selfDevStateWriteUntil = Date.now() + 1500;
|
|
770
|
+
}
|
|
771
|
+
isWithinSelfDevStateWriteWindow() {
|
|
772
|
+
return Date.now() <= this.selfDevStateWriteUntil;
|
|
773
|
+
}
|
|
758
774
|
registerDatabaseFile(filePath, dbName) {
|
|
759
775
|
const abs = path.normalize(filePath);
|
|
760
776
|
this.databaseFilePaths.set(abs, dbName);
|
|
@@ -809,7 +825,10 @@ var PluginState = class {
|
|
|
809
825
|
debugVite("Found %d database(s)", this.databases.size);
|
|
810
826
|
const databases = Array.from(this.databases.values());
|
|
811
827
|
if (this.options.patchWranglerConfig) patchWranglerConfig(this.projectRoot, databases);
|
|
812
|
-
else
|
|
828
|
+
else {
|
|
829
|
+
const check = checkWranglerConfig(this.projectRoot, databases);
|
|
830
|
+
if (!check.ok && !check.tomlOnly && this.config.command === "build") throw new Error(`[durable-db] wrangler config is missing Durable Object bindings/migrations for discovered database(s) — deploying this build would ship a worker without them. Add the JSON from the warning above to ${check.configPath ? path.basename(check.configPath) : "wrangler.jsonc"}, or opt in to automatic patching with durableDb({ patchWranglerConfig: true }).`);
|
|
831
|
+
}
|
|
813
832
|
}
|
|
814
833
|
this.initialized = true;
|
|
815
834
|
}
|
|
@@ -818,7 +837,7 @@ var PluginState = class {
|
|
|
818
837
|
const isDev = this.config.command === "serve";
|
|
819
838
|
db.migrations = loadMigrationFiles(migrationsDir);
|
|
820
839
|
if (isDev) try {
|
|
821
|
-
const { loadDevMigrations } = await import("../state-
|
|
840
|
+
const { loadDevMigrations } = await import("../state-BUCIODvB.js");
|
|
822
841
|
const devMigrations = loadDevMigrations(this.projectRoot, db.name);
|
|
823
842
|
for (const [name, chunks] of devMigrations) db.migrations.set(`_dev_${name}`, chunks);
|
|
824
843
|
if (devMigrations.size > 0) debugVite("Loaded %d dev migration(s) for %s", devMigrations.size, db.name);
|
|
@@ -856,7 +875,11 @@ var PluginState = class {
|
|
|
856
875
|
triggerFullReload() {
|
|
857
876
|
if (!this.devServer) return;
|
|
858
877
|
const environments = this.devServer.environments;
|
|
859
|
-
if (environments) for (const env of Object.
|
|
878
|
+
if (environments) for (const [name, env] of Object.entries(environments)) try {
|
|
879
|
+
env.hot?.send({ type: "full-reload" });
|
|
880
|
+
} catch (error) {
|
|
881
|
+
debugVite("Skipped full-reload for environment %s (hot channel not ready): %O", name, error);
|
|
882
|
+
}
|
|
860
883
|
else this.devServer.ws.send({ type: "full-reload" });
|
|
861
884
|
}
|
|
862
885
|
};
|
|
@@ -899,6 +922,10 @@ function durableDb(options = {}) {
|
|
|
899
922
|
fs.mkdirSync(devPaths.cacheDir, { recursive: true });
|
|
900
923
|
let reloadTimer = null;
|
|
901
924
|
const onDevStateChange = () => {
|
|
925
|
+
if (state.isWithinSelfDevStateWriteWindow()) {
|
|
926
|
+
debugVite("Ignoring dev cache event caused by the plugin itself");
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
902
929
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
903
930
|
reloadTimer = setTimeout(() => {
|
|
904
931
|
debugVite("Dev state changed; reloading durable-db modules");
|
|
@@ -931,7 +958,10 @@ function durableDb(options = {}) {
|
|
|
931
958
|
let epoch = null;
|
|
932
959
|
if (isDev$1) {
|
|
933
960
|
const devState = loadDevState(state.projectRoot);
|
|
934
|
-
if (!fs.existsSync(getDevPaths(state.projectRoot).stateFile))
|
|
961
|
+
if (!fs.existsSync(getDevPaths(state.projectRoot).stateFile)) {
|
|
962
|
+
state.markSelfDevStateWrite();
|
|
963
|
+
saveDevState(state.projectRoot, devState);
|
|
964
|
+
}
|
|
935
965
|
epoch = devState.epoch;
|
|
936
966
|
}
|
|
937
967
|
return { code: generateDevEpochModule(epoch) };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as decodeResponse, r as encodeRequest } from "./protocol-
|
|
1
|
+
import { n as decodeResponse, r as encodeRequest } from "./protocol-v7B4_9xU.js";
|
|
2
2
|
|
|
3
3
|
//#region src/transport/websocket.ts
|
|
4
4
|
/** Default timeout (ms) after which a pending WebSocket request rejects. */
|
package/package.json
CHANGED
package/dist/push-BkkaslPd.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|