diff --git a/bun.lock b/bun.lock index ccf67a8..4794b8d 100644 --- a/bun.lock +++ b/bun.lock @@ -12,7 +12,7 @@ "@types/react-dom": "^19.2.3", "happy-dom": "^20.10.6", "husky": "^9.1.7", - "mongodb": "6", + "mongodb": "7", "pg": "^8.22.0", "react": "^19.2.7", "react-dom": "^19.2.7", @@ -154,11 +154,11 @@ "@types/whatwg-mimetype": ["@types/whatwg-mimetype@3.0.2", "", {}, "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA=="], - "@types/whatwg-url": ["@types/whatwg-url@11.0.5", "", { "dependencies": { "@types/webidl-conversions": "*" } }, "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ=="], + "@types/whatwg-url": ["@types/whatwg-url@13.0.0", "", { "dependencies": { "@types/webidl-conversions": "*" } }, "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q=="], "@types/ws": ["@types/ws@8.18.1", "", { "dependencies": { "@types/node": "*" } }, "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg=="], - "bson": ["bson@6.10.4", "", {}, "sha512-WIsKqkSC0ABoBJuT1LEX+2HEvNmNKKgnTAyd0fL8qzK4SH2i9NXg+t08YtdZp/V9IZ33cxe3iV4yM0qg8lMQng=="], + "bson": ["bson@7.3.1", "", {}, "sha512-h/C0qe6857pQhcSJHLfsR1uYGj98Ge3wKAD3Ed9KqH3wcVh+BM4Jq4xISD7vs9OPuT07n+q3QQVjslJ286j6ag=="], "buffer-image-size": ["buffer-image-size@0.6.4", "", { "dependencies": { "@types/node": "*" } }, "sha512-nEh+kZOPY1w+gcCMobZ6ETUp9WfibndnosbpwB1iJk/8Gt5ZF2bhS6+B6bPYz424KtwsR6Rflc3tCz1/ghX2dQ=="], @@ -176,9 +176,9 @@ "memory-pager": ["memory-pager@1.5.0", "", {}, "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg=="], - "mongodb": ["mongodb@6.21.0", "", { "dependencies": { "@mongodb-js/saslprep": "^1.3.0", "bson": "^6.10.4", "mongodb-connection-string-url": "^3.0.2" }, "peerDependencies": { "@aws-sdk/credential-providers": "^3.188.0", "@mongodb-js/zstd": "^1.1.0 || ^2.0.0", "gcp-metadata": "^5.2.0", "kerberos": "^2.0.1", "mongodb-client-encryption": ">=6.0.0 <7", "snappy": "^7.3.2", "socks": "^2.7.1" }, "optionalPeers": ["@aws-sdk/credential-providers", "@mongodb-js/zstd", "gcp-metadata", "kerberos", "mongodb-client-encryption", "snappy", "socks"] }, "sha512-URyb/VXMjJ4da46OeSXg+puO39XH9DeQpWCslifrRn9JWugy0D+DvvBvkm2WxmHe61O/H19JM66p1z7RHVkZ6A=="], + "mongodb": ["mongodb@7.4.0", "", { "dependencies": { "@mongodb-js/saslprep": "^1.3.0", "bson": "^7.2.0", "mongodb-connection-string-url": "^7.0.0" }, "peerDependencies": { "@aws-sdk/credential-providers": "^3.806.0", "@mongodb-js/zstd": "^7.0.0", "gcp-metadata": "^7.0.1", "kerberos": "^7.0.0", "mongodb-client-encryption": ">=7.0.0 <7.1.0", "snappy": "^7.3.2", "socks": "^2.8.6" }, "optionalPeers": ["@aws-sdk/credential-providers", "@mongodb-js/zstd", "gcp-metadata", "kerberos", "mongodb-client-encryption", "snappy", "socks"] }, "sha512-giySkkdYiwoBFo/oCc8nzov3xOYZ/sB8OpAYk5GINRLEjVw0LDsm8xgQL0XMTyU4extQlDZjhdUr1ZEwKFaazw=="], - "mongodb-connection-string-url": ["mongodb-connection-string-url@3.0.2", "", { "dependencies": { "@types/whatwg-url": "^11.0.2", "whatwg-url": "^14.1.0 || ^13.0.0" } }, "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA=="], + "mongodb-connection-string-url": ["mongodb-connection-string-url@7.0.1", "", { "dependencies": { "@types/whatwg-url": "^13.0.0", "whatwg-url": "^14.1.0" } }, "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ=="], "pg": ["pg@8.22.0", "", { "dependencies": { "pg-connection-string": "^2.14.0", "pg-pool": "^3.14.0", "pg-protocol": "^1.15.0", "pg-types": "2.2.0", "pgpass": "1.0.5" }, "optionalDependencies": { "pg-cloudflare": "^1.4.0" }, "peerDependencies": { "pg-native": ">=3.0.1" }, "optionalPeers": ["pg-native"] }, "sha512-8wih1vVIBMxoUM2oB4soJsD9tDnDpLv4OXBJ+EJzFsvycD+lfyIreC2gGHq78f8jbLLt+bvlPTFdFZfJkOuzAA=="], diff --git a/package.json b/package.json index e21861a..b2519d7 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "@types/react-dom": "^19.2.3", "happy-dom": "^20.10.6", "husky": "^9.1.7", - "mongodb": "6", + "mongodb": "7", "pg": "^8.22.0", "react": "^19.2.7", "react-dom": "^19.2.7", diff --git a/tests/integration.test.ts b/tests/integration.test.ts index 45f2e9f..66612b2 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -1,5 +1,5 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import { MongoClient } from "mongodb"; +import type { MongoClient } from "mongodb"; import { Pool } from "pg"; import { createClient, type RedisClientType } from "redis"; import { mongodbStore, ensureMongoIndexes } from "../packages/mongodb/src/index"; @@ -21,7 +21,7 @@ let redis: RedisClientType; integration("real adapter integrations", () => { beforeAll(async () => { pg = new Pool({ connectionString: pgUrl }); - mongo = new MongoClient(mongoUrl); + mongo = await createMongoClient(mongoUrl); redis = createClient({ url: redisUrl }); await Promise.all([mongo.connect(), redis.connect()]); @@ -134,6 +134,42 @@ integration("real adapter integrations", () => { }); }); +async function createMongoClient(url: string): Promise { + patchBunV8SnapshotProbe(); + const { MongoClient } = await import("mongodb"); + return new MongoClient(url); +} + +let bunV8SnapshotProbePatched = false; + +function patchBunV8SnapshotProbe(): void { + if (bunV8SnapshotProbePatched) return; + bunV8SnapshotProbePatched = true; + + const getBuiltinModule = Reflect.get(process, "getBuiltinModule"); + if (typeof getBuiltinModule !== "function") return; + + const patchedGetBuiltinModule = (name: string): unknown => { + const module: unknown = Reflect.apply(getBuiltinModule, process, [name]); + if (name !== "v8" || !isRecord(module)) return module; + + const startupSnapshot = isRecord(module.startupSnapshot) ? module.startupSnapshot : {}; + return { + ...module, + startupSnapshot: { + ...startupSnapshot, + isBuildingSnapshot: () => false, + }, + }; + }; + + Reflect.set(process, "getBuiltinModule", patchedGetBuiltinModule); +} + +function isRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null; +} + async function setupPostgres(pool: Pool): Promise { await pool.query(` DROP TABLE IF EXISTS author_audit_logs, author_relations, author_permissions, author_roles;