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.
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +11 -13
- package/dist/runtime/lib/db/DOWorkerDialect.js +1 -1
- package/dist/runtime/lib/db/createDb.d.ts +2 -1
- package/dist/runtime/lib/db/createDb.js +9 -35
- package/dist/runtime/lib/db/index.d.ts +1 -0
- package/dist/runtime/lib/db/index.js +1 -0
- package/dist/runtime/lib/router.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
}
|
|
@@ -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(
|
|
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
|