rwsdk 0.2.0-alpha.7 → 0.2.0-alpha.9

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,23 +1,21 @@
1
- import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler, Driver, DatabaseConnection } from "kysely";
1
+ import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler, Driver, DatabaseConnection, QueryResult } from "kysely";
2
+ type DOWorkerDialectConfig = {
3
+ kyselyExecuteQuery: (compiledQuery: {
4
+ sql: string;
5
+ parameters: readonly unknown[];
6
+ }) => Promise<QueryResult<any>>;
7
+ };
2
8
  export declare class DOWorkerDialect {
3
- config: {
4
- stub: any;
5
- };
6
- constructor(config: {
7
- stub: any;
8
- });
9
+ config: DOWorkerDialectConfig;
10
+ constructor(config: DOWorkerDialectConfig);
9
11
  createAdapter(): SqliteAdapter;
10
12
  createDriver(): DOWorkerDriver;
11
13
  createQueryCompiler(): SqliteQueryCompiler;
12
14
  createIntrospector(db: any): SqliteIntrospector;
13
15
  }
14
16
  declare class DOWorkerDriver implements Driver {
15
- config: {
16
- stub: any;
17
- };
18
- constructor(config: {
19
- stub: any;
20
- });
17
+ config: DOWorkerDialectConfig;
18
+ constructor(config: DOWorkerDialectConfig);
21
19
  init(): Promise<void>;
22
20
  acquireConnection(): Promise<DatabaseConnection>;
23
21
  beginTransaction(conn: any): Promise<any>;
@@ -24,7 +24,7 @@ class DOWorkerDriver {
24
24
  }
25
25
  async init() { }
26
26
  async acquireConnection() {
27
- return new DOWorkerConnection(this.config.stub.kyselyExecuteQuery);
27
+ return new DOWorkerConnection(this.config.kyselyExecuteQuery);
28
28
  }
29
29
  async beginTransaction(conn) {
30
30
  return await conn.beginTransaction();
@@ -1,2 +1,3 @@
1
1
  import { Kysely } from "kysely";
2
- export declare function createDb<T>(durableObjectBinding: any, name?: string): Kysely<T>;
2
+ import { type SqliteDurableObject } from "./index.js";
3
+ export declare function createDb<T>(durableObjectBinding: DurableObjectNamespace<SqliteDurableObject>, name?: string): Kysely<T>;
@@ -1,40 +1,14 @@
1
1
  import { Kysely } from "kysely";
2
- import { requestInfo, waitForRequestInfo } from "../../requestInfo/worker.js";
3
2
  import { DOWorkerDialect } from "./DOWorkerDialect.js";
4
- const createDurableObjectDb = (durableObjectBinding, name = "main") => {
5
- const durableObjectId = durableObjectBinding.idFromName(name);
6
- const stub = durableObjectBinding.get(durableObjectId);
7
- stub.initialize();
8
- return new Kysely({
9
- dialect: new DOWorkerDialect({ stub }),
10
- });
11
- };
12
3
  export function createDb(durableObjectBinding, name = "main") {
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);
23
- if (!db) {
24
- db = createDurableObjectDb(durableObjectBinding, name);
25
- requestInfo.rw.databases.set(cacheKey, db);
26
- }
27
- return db;
28
- };
29
- waitForRequestInfo().then(() => doCreateDb());
30
- return new Proxy({}, {
31
- get(target, prop, receiver) {
32
- const db = doCreateDb();
33
- const value = db[prop];
34
- if (typeof value === "function") {
35
- return value.bind(db);
36
- }
37
- return value;
38
- },
4
+ return new Kysely({
5
+ dialect: new DOWorkerDialect({
6
+ kyselyExecuteQuery: (...args) => {
7
+ const durableObjectId = durableObjectBinding.idFromName(name);
8
+ const stub = durableObjectBinding.get(durableObjectId);
9
+ stub.initialize();
10
+ return stub.kyselyExecuteQuery(...args);
11
+ },
12
+ }),
39
13
  });
40
14
  }
@@ -2,3 +2,4 @@ export * from "./migrations.js";
2
2
  export * from "./SqliteDurableObject.js";
3
3
  export * from "./createDb.js";
4
4
  export type * from "./typeInference/database.js";
5
+ export { sql } from "kysely";
@@ -1,3 +1,4 @@
1
1
  export * from "./migrations.js";
2
2
  export * from "./SqliteDurableObject.js";
3
3
  export * from "./createDb.js";
4
+ export { sql } from "kysely";
@@ -98,7 +98,7 @@ export function defineRoutes(routes) {
98
98
  if (isRouteComponent(h)) {
99
99
  const requestInfo = getRequestInfo();
100
100
  const WrappedComponent = wrapWithLayouts(wrapHandlerToThrowResponses(h), layouts || [], requestInfo);
101
- if (!isClientReference(WrappedComponent)) {
101
+ if (!isClientReference(h)) {
102
102
  // context(justinvdm, 31 Jul 2025): We now know we're dealing with a page route,
103
103
  // so we create a deferred so that we can signal when we're done determining whether
104
104
  // we're returning a response or a react element
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.2.0-alpha.7",
3
+ "version": "0.2.0-alpha.9",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {