rwsdk 0.2.0-alpha.6-test.20250806102744 → 0.2.0-alpha.6-test.20250806132021
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
|
-
import { requestInfo } from "../../requestInfo/worker.js";
|
|
2
|
+
import { requestInfo, waitForRequestInfo } from "../../requestInfo/worker.js";
|
|
3
3
|
import { DOWorkerDialect } from "./DOWorkerDialect.js";
|
|
4
|
-
const moduleLevelDbCache = new Map();
|
|
5
4
|
const createDurableObjectDb = (durableObjectBinding, name = "main") => {
|
|
6
5
|
const durableObjectId = durableObjectBinding.idFromName(name);
|
|
7
6
|
const stub = durableObjectBinding.get(durableObjectId);
|
|
@@ -11,23 +10,26 @@ const createDurableObjectDb = (durableObjectBinding, name = "main") => {
|
|
|
11
10
|
});
|
|
12
11
|
};
|
|
13
12
|
export function createDb(durableObjectBinding, name = "main") {
|
|
14
|
-
const
|
|
15
|
-
|
|
13
|
+
const cacheKey = `${durableObjectBinding}_${name}`;
|
|
14
|
+
const doCreateDb = () => {
|
|
15
|
+
if (!requestInfo.rw) {
|
|
16
|
+
throw new Error(`
|
|
17
|
+
rwsdk: A database created using createDb() was accessed before requestInfo was available.
|
|
18
|
+
|
|
19
|
+
Please make sure database access is happening in a request handler or action handler.
|
|
20
|
+
`);
|
|
21
|
+
}
|
|
22
|
+
let db = requestInfo.rw.databases.get(cacheKey);
|
|
16
23
|
if (!db) {
|
|
17
24
|
db = createDurableObjectDb(durableObjectBinding, name);
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
if (requestInfo.rw) {
|
|
21
|
-
if (!requestInfo.rw.databases) {
|
|
22
|
-
requestInfo.rw.databases = new Map();
|
|
23
|
-
}
|
|
24
|
-
requestInfo.rw.databases.set(name, db);
|
|
25
|
+
requestInfo.rw.databases.set(cacheKey, db);
|
|
25
26
|
}
|
|
26
27
|
return db;
|
|
27
28
|
};
|
|
29
|
+
waitForRequestInfo().then(() => doCreateDb());
|
|
28
30
|
return new Proxy({}, {
|
|
29
|
-
get(target, prop) {
|
|
30
|
-
const db =
|
|
31
|
+
get(target, prop, receiver) {
|
|
32
|
+
const db = doCreateDb();
|
|
31
33
|
const value = db[prop];
|
|
32
34
|
if (typeof value === "function") {
|
|
33
35
|
return value.bind(db);
|
|
@@ -109,9 +109,9 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
|
|
|
109
109
|
}
|
|
110
110
|
log("Fetched SSR module code length: %d", code?.length || 0);
|
|
111
111
|
const { imports, dynamicImports } = findSsrImportSpecifiers(idForFetch, code || "", log);
|
|
112
|
-
const allSpecifiers = [
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
const allSpecifiers = [...new Set([...imports, ...dynamicImports])]
|
|
113
|
+
.filter((id) => !id.includes("node_modules"))
|
|
114
|
+
.map((id) => id.startsWith("/@id/") ? id.slice("/@id/".length) : id);
|
|
115
115
|
const switchCases = allSpecifiers
|
|
116
116
|
.map((specifier) => ` case "${specifier}": void import("${VIRTUAL_SSR_PREFIX}${specifier}");`)
|
|
117
117
|
.join("\n");
|
package/package.json
CHANGED