rwsdk 0.2.0-alpha.6-test.20250806100800 → 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,41 +10,26 @@ const createDurableObjectDb = (durableObjectBinding, name = "main") => {
11
10
  });
12
11
  };
13
12
  export function createDb(durableObjectBinding, name = "main") {
14
- const cacheKey = `${durableObjectBinding.toString()}_${name}`;
15
- const getDb = () => {
16
- // requestInfo is available
17
- if (requestInfo.rw) {
18
- if (!requestInfo.rw.databases) {
19
- requestInfo.rw.databases = new Map();
20
- }
21
- let db = requestInfo.rw.databases.get(cacheKey);
22
- // db is in requestInfo cache
23
- if (db) {
24
- return db;
25
- }
26
- // db is in module-level cache
27
- const moduleDb = moduleLevelDbCache.get(cacheKey);
28
- if (moduleDb) {
29
- requestInfo.rw.databases.set(cacheKey, moduleDb);
30
- moduleLevelDbCache.delete(cacheKey);
31
- return moduleDb;
32
- }
33
- // db is not in any cache
34
- db = createDurableObjectDb(durableObjectBinding, name);
35
- requestInfo.rw.databases.set(cacheKey, db);
36
- return db;
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
+ `);
37
21
  }
38
- // requestInfo is not available, use module-level cache
39
- let db = moduleLevelDbCache.get(cacheKey);
22
+ let db = requestInfo.rw.databases.get(cacheKey);
40
23
  if (!db) {
41
24
  db = createDurableObjectDb(durableObjectBinding, name);
42
- moduleLevelDbCache.set(cacheKey, db);
25
+ requestInfo.rw.databases.set(cacheKey, db);
43
26
  }
44
27
  return db;
45
28
  };
29
+ waitForRequestInfo().then(() => doCreateDb());
46
30
  return new Proxy({}, {
47
- get(target, prop) {
48
- const db = getDb();
31
+ get(target, prop, receiver) {
32
+ const db = doCreateDb();
49
33
  const value = db[prop];
50
34
  if (typeof value === "function") {
51
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
- ...new Set([...imports, ...dynamicImports]),
114
- ].map((id) => id.startsWith("/@id/") ? id.slice("/@id/".length) : id);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.2.0-alpha.6-test.20250806100800",
3
+ "version": "0.2.0-alpha.6-test.20250806132021",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {