rwsdk 0.1.19-test.20250717130914 → 0.1.19
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/SqliteDurableObject.js +1 -7
- package/dist/runtime/lib/db/createDb.js +2 -9
- package/dist/runtime/requestInfo/worker.d.ts +3 -6
- package/dist/runtime/requestInfo/worker.js +3 -11
- package/dist/runtime/script.d.ts +2 -2
- package/dist/runtime/script.js +3 -6
- package/dist/scripts/debug-sync.mjs +5 -3
- package/dist/scripts/worker-run.mjs +10 -21
- package/package.json +1 -1
|
@@ -22,13 +22,7 @@ export class SqliteDurableObject extends DurableObject {
|
|
|
22
22
|
}
|
|
23
23
|
log("Initializing Durable Object database");
|
|
24
24
|
const migrator = createMigrator(this.kysely, this.migrations, this.migrationTableName);
|
|
25
|
-
|
|
26
|
-
if (result.error) {
|
|
27
|
-
console.log("rwsdk/db: Migrations failed, rolling back and throwing with the migration error: %O", result.results);
|
|
28
|
-
await migrator.migrateDown();
|
|
29
|
-
throw result.error;
|
|
30
|
-
}
|
|
31
|
-
log("Migrations results", result.results);
|
|
25
|
+
await migrator.migrateToLatest();
|
|
32
26
|
this.initialized = true;
|
|
33
27
|
log("Database initialization complete");
|
|
34
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
|
-
import { requestInfo
|
|
2
|
+
import { requestInfo } from "../../requestInfo/worker.js";
|
|
3
3
|
import { DOWorkerDialect } from "./DOWorkerDialect.js";
|
|
4
4
|
const createDurableObjectDb = (durableObjectBinding, name = "main") => {
|
|
5
5
|
const durableObjectId = durableObjectBinding.idFromName(name);
|
|
@@ -12,13 +12,6 @@ const createDurableObjectDb = (durableObjectBinding, name = "main") => {
|
|
|
12
12
|
export function createDb(durableObjectBinding, name = "main") {
|
|
13
13
|
const cacheKey = `${durableObjectBinding}_${name}`;
|
|
14
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
15
|
let db = requestInfo.rw.databases.get(cacheKey);
|
|
23
16
|
if (!db) {
|
|
24
17
|
db = createDurableObjectDb(durableObjectBinding, name);
|
|
@@ -26,7 +19,7 @@ export function createDb(durableObjectBinding, name = "main") {
|
|
|
26
19
|
}
|
|
27
20
|
return db;
|
|
28
21
|
};
|
|
29
|
-
|
|
22
|
+
doCreateDb();
|
|
30
23
|
return new Proxy({}, {
|
|
31
24
|
get(target, prop, receiver) {
|
|
32
25
|
const db = doCreateDb();
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { RequestInfo, DefaultAppContext } from "./types";
|
|
2
|
-
|
|
3
|
-
export declare const requestInfo: DefaultRequestInfo;
|
|
2
|
+
export declare const requestInfo: RequestInfo<DefaultAppContext>;
|
|
4
3
|
export declare function getRequestInfo(): RequestInfo;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function runWithRequestInfoOverrides<Result>(overrides: Partial<DefaultRequestInfo>, fn: () => Result): Result;
|
|
8
|
-
export {};
|
|
4
|
+
export declare function runWithRequestInfo<Result>(context: Record<string, any>, fn: () => Result): Result;
|
|
5
|
+
export declare function runWithRequestInfoOverrides<Result>(overrides: Record<string, any>, fn: () => Result): Result;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
-
const requestInfoDeferred = Promise.withResolvers();
|
|
3
2
|
const requestInfoStore = new AsyncLocalStorage();
|
|
4
3
|
const requestInfoBase = {};
|
|
5
4
|
const REQUEST_INFO_KEYS = ["request", "params", "ctx", "headers", "rw", "cf"];
|
|
@@ -21,15 +20,8 @@ export function getRequestInfo() {
|
|
|
21
20
|
}
|
|
22
21
|
return store;
|
|
23
22
|
}
|
|
24
|
-
export function
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
export function runWithRequestInfo(nextRequestInfo, fn) {
|
|
28
|
-
const runWithRequestInfoFn = () => {
|
|
29
|
-
requestInfoDeferred.resolve(nextRequestInfo);
|
|
30
|
-
return fn();
|
|
31
|
-
};
|
|
32
|
-
return requestInfoStore.run(nextRequestInfo, runWithRequestInfoFn);
|
|
23
|
+
export function runWithRequestInfo(context, fn) {
|
|
24
|
+
return requestInfoStore.run(context, fn);
|
|
33
25
|
}
|
|
34
26
|
export function runWithRequestInfoOverrides(overrides, fn) {
|
|
35
27
|
const requestInfo = requestInfoStore.getStore();
|
|
@@ -37,5 +29,5 @@ export function runWithRequestInfoOverrides(overrides, fn) {
|
|
|
37
29
|
...requestInfo,
|
|
38
30
|
...overrides,
|
|
39
31
|
};
|
|
40
|
-
return
|
|
32
|
+
return requestInfoStore.run(newRequestInfo, fn);
|
|
41
33
|
}
|
package/dist/runtime/script.d.ts
CHANGED
package/dist/runtime/script.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { defineApp } from "./worker";
|
|
2
|
-
import { env } from "cloudflare:workers";
|
|
3
1
|
export const defineScript = (fn) => {
|
|
4
|
-
|
|
5
|
-
async ()
|
|
2
|
+
return {
|
|
3
|
+
async fetch(request, env) {
|
|
6
4
|
await fn({ env });
|
|
7
5
|
return new Response("Done!");
|
|
8
6
|
},
|
|
9
|
-
|
|
10
|
-
return app;
|
|
7
|
+
};
|
|
11
8
|
};
|
|
@@ -136,8 +136,10 @@ export const debugSync = async (opts) => {
|
|
|
136
136
|
throw e;
|
|
137
137
|
}
|
|
138
138
|
// Initial sync for watch mode. We do it *after* acquiring the lock.
|
|
139
|
+
let initialSyncOk = false;
|
|
139
140
|
try {
|
|
140
141
|
await performSync(sdkDir, targetDir);
|
|
142
|
+
initialSyncOk = true;
|
|
141
143
|
}
|
|
142
144
|
catch (error) {
|
|
143
145
|
console.error("❌ Initial sync failed:", error);
|
|
@@ -194,9 +196,9 @@ export const debugSync = async (opts) => {
|
|
|
194
196
|
};
|
|
195
197
|
process.on("SIGINT", cleanup);
|
|
196
198
|
process.on("SIGTERM", cleanup);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
if (initialSyncOk) {
|
|
200
|
+
runWatchedCommand();
|
|
201
|
+
}
|
|
200
202
|
};
|
|
201
203
|
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
202
204
|
const args = process.argv.slice(2);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import { resolve } from "path";
|
|
3
2
|
import { writeFile } from "fs/promises";
|
|
4
3
|
import { unstable_readConfig } from "wrangler";
|
|
@@ -24,38 +23,27 @@ export const runWorkerScript = async (relativeScriptPath) => {
|
|
|
24
23
|
const workerConfig = unstable_readConfig({
|
|
25
24
|
config: workerConfigPath,
|
|
26
25
|
});
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const tmpDir = await tmp.dir({
|
|
30
|
-
prefix: "rw-worker-run-",
|
|
31
|
-
unsafeCleanup: true,
|
|
26
|
+
const tmpWorkerPath = await tmp.file({
|
|
27
|
+
postfix: ".json",
|
|
32
28
|
});
|
|
33
|
-
const relativeTmpWorkerEntryPath = "worker.tsx";
|
|
34
|
-
const tmpWorkerPath = path.join(tmpDir.path, "wrangler.json");
|
|
35
|
-
const tmpWorkerEntryPath = path.join(tmpDir.path, relativeTmpWorkerEntryPath);
|
|
36
29
|
const scriptWorkerConfig = {
|
|
37
30
|
...workerConfig,
|
|
38
|
-
configPath: tmpWorkerPath,
|
|
39
|
-
userConfigPath: tmpWorkerPath,
|
|
40
|
-
main:
|
|
31
|
+
configPath: tmpWorkerPath.path,
|
|
32
|
+
userConfigPath: tmpWorkerPath.path,
|
|
33
|
+
main: scriptPath,
|
|
41
34
|
};
|
|
42
35
|
try {
|
|
43
|
-
await writeFile(tmpWorkerPath, JSON.stringify(scriptWorkerConfig, null, 2));
|
|
44
|
-
|
|
45
|
-
export * from "${workerEntryPath}";
|
|
46
|
-
export { default } from "${scriptPath}";
|
|
47
|
-
`);
|
|
48
|
-
debug("Worker config written to: %s", tmpWorkerPath);
|
|
49
|
-
debug("Worker entry written to: %s", tmpWorkerEntryPath);
|
|
36
|
+
await writeFile(tmpWorkerPath.path, JSON.stringify(scriptWorkerConfig, null, 2));
|
|
37
|
+
debug("Worker config written to: %s", tmpWorkerPath.path);
|
|
50
38
|
process.env.RWSDK_WORKER_RUN = "1";
|
|
51
39
|
const server = await createViteServer({
|
|
52
40
|
configFile: false,
|
|
53
41
|
plugins: [
|
|
54
42
|
redwood({
|
|
55
|
-
configPath: tmpWorkerPath,
|
|
43
|
+
configPath: tmpWorkerPath.path,
|
|
56
44
|
includeCloudflarePlugin: true,
|
|
57
45
|
entry: {
|
|
58
|
-
worker:
|
|
46
|
+
worker: scriptPath,
|
|
59
47
|
},
|
|
60
48
|
}),
|
|
61
49
|
],
|
|
@@ -83,6 +71,7 @@ export { default } from "${scriptPath}";
|
|
|
83
71
|
}
|
|
84
72
|
finally {
|
|
85
73
|
debug("Closing inspector servers...");
|
|
74
|
+
await tmpWorkerPath.cleanup();
|
|
86
75
|
debug("Temporary files cleaned up");
|
|
87
76
|
}
|
|
88
77
|
// todo(justinvdm, 01 Apr 2025): Investigate what handles are remaining open
|