diff --git a/Makefile b/Makefile index 34e3630928c3..44b88df0aead 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ test-libsql-sqlite: dev-libsql-sqlite test-qe-st test-driver-adapter-libsql: test-libsql-sqlite -dev-libsql-sqlite-wasm: build-qe-napi build-connector-kit-js +dev-libsql-sqlite-wasm: build-qe-wasm build-connector-kit-js cp $(CONFIG_PATH)/libsql-sqlite-wasm $(CONFIG_FILE) test-libsql-sqlite-wasm: dev-libsql-sqlite-wasm test-qe-st @@ -126,14 +126,14 @@ start-postgres13: dev-postgres13: start-postgres13 cp $(CONFIG_PATH)/postgres13 $(CONFIG_FILE) -start-pg-postgres13: build-qe-napi build-connector-kit-js start-postgres13 +start-pg-postgres13: start-postgres13 -dev-pg-postgres13: start-pg-postgres13 +dev-pg-postgres13: start-pg-postgres13 build-qe-napi build-connector-kit-js cp $(CONFIG_PATH)/pg-postgres13 $(CONFIG_FILE) test-pg-postgres13: dev-pg-postgres13 test-qe-st -dev-pg-postgres13-wasm: start-pg-postgres13 +dev-pg-postgres13-wasm: start-pg-postgres13 build-qe-wasm build-connector-kit-js cp $(CONFIG_PATH)/pg-postgres13-wasm $(CONFIG_FILE) test-pg-postgres13-wasm: dev-pg-postgres13-wasm test-qe-st @@ -148,7 +148,7 @@ dev-neon-ws-postgres13: start-neon-postgres13 build-qe-napi build-connector-kit- test-neon-ws-postgres13: dev-neon-ws-postgres13 test-qe-st -dev-neon-ws-postgres13-wasm: start-neon-postgres13 build-qe-napi build-connector-kit-js +dev-neon-ws-postgres13-wasm: start-neon-postgres13 build-qe-wasm build-connector-kit-js cp $(CONFIG_PATH)/neon-ws-postgres13-wasm $(CONFIG_FILE) test-neon-ws-postgres13-wasm: dev-neon-ws-postgres13-wasm test-qe-st @@ -285,7 +285,7 @@ dev-planetscale-vitess8: start-planetscale-vitess8 build-qe-napi build-connector test-planetscale-vitess8: dev-planetscale-vitess8 test-qe-st -dev-planetscale-vitess8-wasm: start-planetscale-vitess8 build-qe-napi build-connector-kit-js +dev-planetscale-vitess8-wasm: start-planetscale-vitess8 build-qe-wasm build-connector-kit-js cp $(CONFIG_PATH)/planetscale-vitess8-wasm $(CONFIG_FILE) test-planetscale-vitess8-wasm: dev-planetscale-vitess8-wasm test-qe-st @@ -299,6 +299,9 @@ test-driver-adapter-planetscale: test-planetscale-vitess8 build-qe-napi: cargo build --package query-engine-node-api +build-qe-wasm: + cd query-engine/query-engine-wasm && ./build.sh + build-connector-kit-js: build-driver-adapters cd query-engine/driver-adapters && pnpm i && pnpm build diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/config.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/config.rs index 751e0dd23c25..731ec491fc51 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/config.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/config.rs @@ -8,17 +8,17 @@ use std::{convert::TryFrom, env, fmt::Display, fs::File, io::Read, path::PathBuf static TEST_CONFIG_FILE_NAME: &str = ".test_config"; #[derive(Debug, Default, Deserialize, Clone)] -enum TestExecutorEngine { +pub enum TestExecutorEngine { #[default] - NAPI, - WASM, + Napi, + Wasm, } impl Display for TestExecutorEngine { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - TestExecutorEngine::NAPI => f.write_str("NAPI"), - TestExecutorEngine::WASM => f.write_str("WASM"), + TestExecutorEngine::Napi => f.write_str("Napi"), + TestExecutorEngine::Wasm => f.write_str("Wasm"), } } } @@ -130,7 +130,7 @@ impl TestConfig { println!("* CI? {}", self.is_ci); if self.external_test_executor.as_ref().is_some() { println!("* External test executor: {}", self.external_test_executor().unwrap_or_default()); - println!("* External test executor engine: {:?}", self.external_test_executor().unwrap_or_default()); + println!("* External test executor engine: {:?}", self.external_test_executor_engine().unwrap_or_default()); println!("* Driver adapter: {}", self.driver_adapter().unwrap_or_default()); println!("* Driver adapter url override: {}", self.json_stringify_driver_adapter_config()); } @@ -296,6 +296,10 @@ impl TestConfig { self.external_test_executor.as_deref() } + pub fn external_test_executor_engine(&self) -> Option { + self.external_test_executor_engine.clone() + } + pub fn driver_adapter(&self) -> Option<&str> { self.driver_adapter.as_deref() } diff --git a/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite b/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite index 4d24cd29e41d..164ddbb84cdf 100644 --- a/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite +++ b/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite @@ -2,5 +2,5 @@ "connector": "sqlite", "driver_adapter": "libsql", "external_test_executor": "default", - "external_test_executor_engine": "NAPI" + "external_test_executor_engine": "Napi" } \ No newline at end of file diff --git a/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite-wasm b/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite-wasm index 32ef323e444c..d6e6a6030158 100644 --- a/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite-wasm +++ b/query-engine/connector-test-kit-rs/test-configs/libsql-sqlite-wasm @@ -2,5 +2,5 @@ "connector": "sqlite", "driver_adapter": "libsql", "external_test_executor": "default", - "external_test_executor_engine": "WASM" + "external_test_executor_engine": "Wasm" } \ No newline at end of file diff --git a/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13 b/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13 index c96a593dc19e..a980e0081657 100644 --- a/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13 +++ b/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13 @@ -4,5 +4,5 @@ "driver_adapter": "neon:ws", "driver_adapter_config": { "proxyUrl": "127.0.0.1:5488/v1" }, "external_test_executor": "default", - "external_test_executor_engine": "NAPI" + "external_test_executor_engine": "Napi" } \ No newline at end of file diff --git a/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13-wasm b/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13-wasm index fcc42e0db7a5..241995984391 100644 --- a/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13-wasm +++ b/query-engine/connector-test-kit-rs/test-configs/neon-ws-postgres13-wasm @@ -4,5 +4,5 @@ "driver_adapter": "neon:ws", "driver_adapter_config": { "proxyUrl": "127.0.0.1:5488/v1" }, "external_test_executor": "default", - "external_test_executor_engine": "WASM" + "external_test_executor_engine": "Wasm" } \ No newline at end of file diff --git a/query-engine/connector-test-kit-rs/test-configs/pg-postgres13 b/query-engine/connector-test-kit-rs/test-configs/pg-postgres13 index b5d4c9faf822..959c8718eb62 100644 --- a/query-engine/connector-test-kit-rs/test-configs/pg-postgres13 +++ b/query-engine/connector-test-kit-rs/test-configs/pg-postgres13 @@ -3,5 +3,5 @@ "version": "13", "driver_adapter": "pg", "external_test_executor": "default", - "external_test_executor_engine": "NAPI" + "external_test_executor_engine": "Napi" } \ No newline at end of file diff --git a/query-engine/connector-test-kit-rs/test-configs/pg-postgres13-wasm b/query-engine/connector-test-kit-rs/test-configs/pg-postgres13-wasm index 33999aadbde3..2ab31dd95b79 100644 --- a/query-engine/connector-test-kit-rs/test-configs/pg-postgres13-wasm +++ b/query-engine/connector-test-kit-rs/test-configs/pg-postgres13-wasm @@ -3,5 +3,5 @@ "version": "13", "driver_adapter": "pg", "external_test_executor": "default", - "external_test_executor_engine": "WASM" + "external_test_executor_engine": "Wasm" } \ No newline at end of file diff --git a/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8 b/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8 index 012d898d86bb..4aded9398d46 100644 --- a/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8 +++ b/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8 @@ -4,5 +4,5 @@ "driver_adapter": "planetscale", "driver_adapter_config": { "proxyUrl": "http://root:root@127.0.0.1:8085" }, "external_test_executor": "default", - "external_test_executor_engine": "NAPI" + "external_test_executor_engine": "Napi" } diff --git a/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8-wasm b/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8-wasm index 75080f7386e4..5baac55dd962 100644 --- a/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8-wasm +++ b/query-engine/connector-test-kit-rs/test-configs/planetscale-vitess8-wasm @@ -4,5 +4,5 @@ "driver_adapter": "planetscale", "driver_adapter_config": { "proxyUrl": "http://root:root@127.0.0.1:8085" }, "external_test_executor": "default", - "external_test_executor_engine": "WASM" + "external_test_executor_engine": "Wasm" } diff --git a/query-engine/driver-adapters/connector-test-kit-executor/package.json b/query-engine/driver-adapters/connector-test-kit-executor/package.json index 4648887f5063..e872d5684450 100644 --- a/query-engine/driver-adapters/connector-test-kit-executor/package.json +++ b/query-engine/driver-adapters/connector-test-kit-executor/package.json @@ -12,6 +12,11 @@ "scripts": { "build": "tsup ./src/index.ts --format esm --dts" }, + "tsup": { + "external": [ + "../../../query-engine-wasm/pkg/query_engine_bg.js" + ] + }, "keywords": [], "author": "", "sideEffects": false, diff --git a/query-engine/driver-adapters/connector-test-kit-executor/src/index.ts b/query-engine/driver-adapters/connector-test-kit-executor/src/index.ts index d84382b7cd26..3ea8aaf147b9 100644 --- a/query-engine/driver-adapters/connector-test-kit-executor/src/index.ts +++ b/query-engine/driver-adapters/connector-test-kit-executor/src/index.ts @@ -217,7 +217,7 @@ function respondOk(requestId: number, payload: unknown) { async function initQe(url: string, prismaSchema: string, logCallback: qe.QueryLogCallback): Promise<[qe.QueryEngine, ErrorCapturingDriverAdapter]> { const adapter = await adapterFromEnv(url) as DriverAdapter const errorCapturingAdapter = bindAdapter(adapter) - const engineInstance = qe.initQueryEngine(errorCapturingAdapter, prismaSchema, logCallback, debug) + const engineInstance = await qe.initQueryEngine(errorCapturingAdapter, prismaSchema, logCallback, debug) return [engineInstance, errorCapturingAdapter]; } diff --git a/query-engine/driver-adapters/connector-test-kit-executor/src/qe.ts b/query-engine/driver-adapters/connector-test-kit-executor/src/qe.ts index 109cdf635dc2..5b7ad4fc01b8 100644 --- a/query-engine/driver-adapters/connector-test-kit-executor/src/qe.ts +++ b/query-engine/driver-adapters/connector-test-kit-executor/src/qe.ts @@ -1,5 +1,4 @@ import type { ErrorCapturingDriverAdapter } from '@prisma/driver-adapter-utils' -import { WasmQueryEngine } from './wasm' import * as napi from './engines/Library' import * as os from 'node:os' import * as path from 'node:path' @@ -19,7 +18,7 @@ export interface QueryEngine { export type QueryLogCallback = (log: string) => void -export function initQueryEngine(adapter: ErrorCapturingDriverAdapter, datamodel: string, queryLogCallback: QueryLogCallback, debug: (...args: any[]) => void): QueryEngine { +export async function initQueryEngine(adapter: ErrorCapturingDriverAdapter, datamodel: string, queryLogCallback: QueryLogCallback, debug: (...args: any[]) => void): QueryEngine { const queryEngineOptions = { datamodel, @@ -40,14 +39,15 @@ export function initQueryEngine(adapter: ErrorCapturingDriverAdapter, datamodel: debug(parsed) } - const engineFromEnv = process.env.EXTERNAL_TEST_EXECUTOR_ENGINE ?? 'napi' - if (engineFromEnv === 'WASM') { + const engineFromEnv = process.env.EXTERNAL_TEST_EXECUTOR_ENGINE ?? 'Napi' + if (engineFromEnv === 'Wasm') { + const { WasmQueryEngine } = await import('./wasm') return new WasmQueryEngine(queryEngineOptions, logCallback, adapter) - } else if (engineFromEnv === 'NAPI') { + } else if (engineFromEnv === 'Napi') { const { QueryEngine } = loadNapiEngine() return new QueryEngine(queryEngineOptions, logCallback, adapter) } else { - throw new TypeError(`Invalid EXTERNAL_TEST_EXECUTOR_ENGINE value: ${engineFromEnv}. Expected NAPI or WASM`) + throw new TypeError(`Invalid EXTERNAL_TEST_EXECUTOR_ENGINE value: ${engineFromEnv}. Expected Napi or Wasm`) }