rwsdk 0.1.31 → 0.1.33
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/scripts/debug-sync.mjs +11 -12
- package/dist/vite/miniflareHMRPlugin.mjs +6 -4
- 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
|
}
|
|
@@ -24,21 +24,12 @@ const getPackageManagerInfo = (targetDir) => {
|
|
|
24
24
|
}
|
|
25
25
|
return pnpmResult;
|
|
26
26
|
};
|
|
27
|
-
const performFullSync = async (sdkDir, targetDir
|
|
27
|
+
const performFullSync = async (sdkDir, targetDir) => {
|
|
28
28
|
const sdkPackageJsonPath = path.join(sdkDir, "package.json");
|
|
29
29
|
let originalSdkPackageJson = null;
|
|
30
30
|
let tarballPath = "";
|
|
31
31
|
let tarballName = "";
|
|
32
32
|
try {
|
|
33
|
-
if (cacheBust) {
|
|
34
|
-
console.log("💥 Cache-busting version for full sync...");
|
|
35
|
-
originalSdkPackageJson = await fs.readFile(sdkPackageJsonPath, "utf-8");
|
|
36
|
-
const packageJson = JSON.parse(originalSdkPackageJson);
|
|
37
|
-
const now = Date.now();
|
|
38
|
-
// This is a temporary version used for cache busting
|
|
39
|
-
packageJson.version = `${packageJson.version}-dev.${now}`;
|
|
40
|
-
await fs.writeFile(sdkPackageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
41
|
-
}
|
|
42
33
|
console.log("📦 Packing SDK...");
|
|
43
34
|
const packResult = await $({ cwd: sdkDir }) `npm pack`;
|
|
44
35
|
tarballName = packResult.stdout?.trim() ?? "";
|
|
@@ -109,13 +100,17 @@ const performFastSync = async (sdkDir, targetDir) => {
|
|
|
109
100
|
// Always copy package.json
|
|
110
101
|
await fs.copyFile(path.join(sdkDir, "package.json"), path.join(targetDir, "node_modules/rwsdk/package.json"));
|
|
111
102
|
};
|
|
103
|
+
const areDependenciesEqual = (deps1, deps2) => {
|
|
104
|
+
// Simple string comparison for this use case is sufficient
|
|
105
|
+
return JSON.stringify(deps1 ?? {}) === JSON.stringify(deps2 ?? {});
|
|
106
|
+
};
|
|
112
107
|
const performSync = async (sdkDir, targetDir) => {
|
|
113
108
|
console.log("🏗️ Rebuilding SDK...");
|
|
114
109
|
await $ `pnpm build`;
|
|
115
110
|
const forceFullSync = Boolean(process.env.RWSDK_FORCE_FULL_SYNC);
|
|
116
111
|
if (forceFullSync) {
|
|
117
112
|
console.log("🏃 Force full sync mode is enabled.");
|
|
118
|
-
await performFullSync(sdkDir, targetDir
|
|
113
|
+
await performFullSync(sdkDir, targetDir);
|
|
119
114
|
console.log("✅ Done syncing");
|
|
120
115
|
return;
|
|
121
116
|
}
|
|
@@ -125,7 +120,11 @@ const performSync = async (sdkDir, targetDir) => {
|
|
|
125
120
|
if (existsSync(installedSdkPackageJsonPath)) {
|
|
126
121
|
const sdkPackageJsonContent = await fs.readFile(sdkPackageJsonPath, "utf-8");
|
|
127
122
|
const installedSdkPackageJsonContent = await fs.readFile(installedSdkPackageJsonPath, "utf-8");
|
|
128
|
-
|
|
123
|
+
const sdkPkg = JSON.parse(sdkPackageJsonContent);
|
|
124
|
+
const installedPkg = JSON.parse(installedSdkPackageJsonContent);
|
|
125
|
+
if (areDependenciesEqual(sdkPkg.dependencies, installedPkg.dependencies) &&
|
|
126
|
+
areDependenciesEqual(sdkPkg.devDependencies, installedPkg.devDependencies) &&
|
|
127
|
+
areDependenciesEqual(sdkPkg.peerDependencies, installedPkg.peerDependencies)) {
|
|
129
128
|
packageJsonChanged = false;
|
|
130
129
|
}
|
|
131
130
|
}
|
|
@@ -109,19 +109,19 @@ export const miniflareHMRPlugin = (givenOptions) => [
|
|
|
109
109
|
let clientDirectiveChanged = false;
|
|
110
110
|
let serverDirectiveChanged = false;
|
|
111
111
|
if (!clientFiles.has(ctx.file) && hasClientDirective) {
|
|
112
|
-
clientFiles.add(ctx.file);
|
|
112
|
+
clientFiles.add(normalizeModulePath(ctx.file, givenOptions.rootDir));
|
|
113
113
|
clientDirectiveChanged = true;
|
|
114
114
|
}
|
|
115
115
|
else if (clientFiles.has(ctx.file) && !hasClientDirective) {
|
|
116
|
-
clientFiles.delete(ctx.file);
|
|
116
|
+
clientFiles.delete(normalizeModulePath(ctx.file, givenOptions.rootDir));
|
|
117
117
|
clientDirectiveChanged = true;
|
|
118
118
|
}
|
|
119
119
|
if (!serverFiles.has(ctx.file) && hasServerDirective) {
|
|
120
|
-
serverFiles.add(ctx.file);
|
|
120
|
+
serverFiles.add(normalizeModulePath(ctx.file, givenOptions.rootDir));
|
|
121
121
|
serverDirectiveChanged = true;
|
|
122
122
|
}
|
|
123
123
|
else if (serverFiles.has(ctx.file) && !hasServerDirective) {
|
|
124
|
-
serverFiles.delete(ctx.file);
|
|
124
|
+
serverFiles.delete(normalizeModulePath(ctx.file, givenOptions.rootDir));
|
|
125
125
|
serverDirectiveChanged = true;
|
|
126
126
|
}
|
|
127
127
|
if (clientDirectiveChanged) {
|
|
@@ -129,12 +129,14 @@ export const miniflareHMRPlugin = (givenOptions) => [
|
|
|
129
129
|
invalidateModule(ctx.server, environment, "virtual:use-client-lookup.js");
|
|
130
130
|
});
|
|
131
131
|
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX + "/@id/virtual:use-client-lookup.js");
|
|
132
|
+
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX + "virtual:use-client-lookup.js");
|
|
132
133
|
}
|
|
133
134
|
if (serverDirectiveChanged) {
|
|
134
135
|
["client", "ssr", environment].forEach((environment) => {
|
|
135
136
|
invalidateModule(ctx.server, environment, "virtual:use-server-lookup.js");
|
|
136
137
|
});
|
|
137
138
|
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX + "/@id/virtual:use-server-lookup.js");
|
|
139
|
+
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX + "virtual:use-server-lookup.js");
|
|
138
140
|
}
|
|
139
141
|
// todo(justinvdm, 12 Dec 2024): Skip client references
|
|
140
142
|
const modules = Array.from(ctx.server.environments[environment].moduleGraph.getModulesByFile(ctx.file) ?? []);
|