@allbluecn/database 0.14.16 → 0.14.17
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/database",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.17",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"pglite-seed.ts",
|
|
52
52
|
"index.ts",
|
|
53
53
|
"get-prisma.ts",
|
|
54
|
-
"pg-client.ts"
|
|
54
|
+
"pg-client.ts",
|
|
55
|
+
"scripts"
|
|
55
56
|
],
|
|
56
57
|
"publishConfig": {
|
|
57
58
|
"access": "public"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Prisma 7 在 Cloudflare Workers 上的 WASM 变通(prisma/orm#28657 未修):
|
|
2
|
+
// workerd 禁止动态 WASM 编译(new WebAssembly.Module(bytes) 抛
|
|
3
|
+
// "Wasm code generation disallowed by embedder"),而生成的
|
|
4
|
+
// internal/class.ts 默认对 base64 内联 wasm 运行时解码。
|
|
5
|
+
//
|
|
6
|
+
// 本脚本在 `prisma generate` 之后运行(package.json generate 链):
|
|
7
|
+
// 1. 把 @prisma/client/runtime/*.wasm-base64.mjs 的内联 wasm 解码为
|
|
8
|
+
// generated/prisma-query-compiler.postgresql.wasm 真实文件;
|
|
9
|
+
// 2. 给 getQueryCompilerWasmModule 加双路径:workerd(navigator.userAgent
|
|
10
|
+
// === "Cloudflare-Workers",官方检测口径)走 wasm 模块导入(@cloudflare/
|
|
11
|
+
// vite-plugin 构建期处理为 WasmModule,无需动态编译);Node/Vercel/desktop
|
|
12
|
+
// 保持 base64 原路,行为不变。
|
|
13
|
+
//
|
|
14
|
+
// 幂等:patch 标记存在即跳过。generated/ 为生成产物,重新 generate 后须重跑
|
|
15
|
+
// (已挂进 generate 脚本链)。
|
|
16
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
|
|
20
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const pkgDir = join(here, "..");
|
|
22
|
+
const classFile = join(pkgDir, "generated", "internal", "class.ts");
|
|
23
|
+
const wasmFile = join(pkgDir, "generated", "prisma-query-compiler.postgresql.wasm");
|
|
24
|
+
|
|
25
|
+
const MARKER = "PRISMA_WORKERD_WASM_PATCH_V1";
|
|
26
|
+
let code = readFileSync(classFile, "utf8");
|
|
27
|
+
if (code.includes(MARKER)) {
|
|
28
|
+
console.log("[patch-workerd-wasm] already patched, skip");
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const base64Module = "@prisma/client/runtime/query_compiler_fast_bg.postgresql.wasm-base64.mjs";
|
|
33
|
+
const importRe = new RegExp(
|
|
34
|
+
String.raw`const \{ wasm \} = await import\("${base64Module.replace(/[./]/g, "\\$&")}"\)\s*;?\s*return await decodeBase64AsWasm\(wasm\)`,
|
|
35
|
+
);
|
|
36
|
+
if (!importRe.test(code)) {
|
|
37
|
+
console.error("[patch-workerd-wasm] 未找到预期的 base64 加载块——生成器输出结构可能已变更,请人工核对");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 解码 wasm 文件(从内联模块读取 base64 常量;包内 node_modules symlink 直达)
|
|
42
|
+
const base64ModulePath = join(
|
|
43
|
+
pkgDir,
|
|
44
|
+
"node_modules",
|
|
45
|
+
"@prisma/client/runtime/query_compiler_fast_bg.postgresql.wasm-base64.mjs",
|
|
46
|
+
);
|
|
47
|
+
const base64Src = readFileSync(base64ModulePath, "utf8").match(
|
|
48
|
+
/"([A-Za-z0-9+/=]{100,})"/,
|
|
49
|
+
);
|
|
50
|
+
if (!base64Src) {
|
|
51
|
+
throw new Error("未能从 wasm-base64 模块中提取 base64 常量");
|
|
52
|
+
}
|
|
53
|
+
writeFileSync(wasmFile, Buffer.from(base64Src[1], "base64"));
|
|
54
|
+
|
|
55
|
+
const patched = code.replace(
|
|
56
|
+
importRe,
|
|
57
|
+
[
|
|
58
|
+
`// ${MARKER}: workerd 禁动态 WASM 编译(prisma/orm#28657),`,
|
|
59
|
+
`// Cloudflare-Workers 环境走 vite-plugin 处理的 wasm 模块导入;`,
|
|
60
|
+
`// Node/Vercel/desktop 保持 base64 原路(decodeBase64AsWasm)。`,
|
|
61
|
+
`if (typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") {`,
|
|
62
|
+
` const wasmNs = (await import("../prisma-query-compiler.postgresql.wasm")) as unknown as { default: WebAssembly.Module };`,
|
|
63
|
+
` return wasmNs.default ?? (wasmNs as unknown as WebAssembly.Module);`,
|
|
64
|
+
`}`,
|
|
65
|
+
`const { wasm } = await import("${base64Module}");`,
|
|
66
|
+
`return await decodeBase64AsWasm(wasm)`,
|
|
67
|
+
].join("\n"),
|
|
68
|
+
);
|
|
69
|
+
writeFileSync(classFile, patched);
|
|
70
|
+
console.log("[patch-workerd-wasm] patched + wasm extracted:", wasmFile);
|