Platform detection utility for Prisma's internal use that detects operating system, architecture, and Linux distribution information to determine appropriate binary targets for Prisma engines.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Node.js API compatibility validation utilities for ensuring proper engine type selection based on platform capabilities. This module provides functions to validate Node API support and generate platform-specific library names.
Validates whether Node API is supported on the current platform and throws an error if not supported.
/**
* Determines whether Node API is supported on the current platform and throws if not
* @throws Error if Node API is not supported (specifically on 32-bit platforms)
*/
function assertNodeAPISupported(): void;Usage Examples:
import { assertNodeAPISupported } from "@prisma/get-platform";
try {
assertNodeAPISupported();
console.log("Node API is supported on this platform");
// Proceed with Node API engine type
} catch (error) {
console.error("Node API not supported:", error.message);
// Fall back to binary engine type
}Error Conditions:
The function throws an error in the following cases:
process.arch === 'ia32' and no custom library path is setPRISMA_QUERY_ENGINE_LIBRARY is set but the file doesn't existError Message:
The default query engine type (Node-API, "library") is currently not supported for 32bit Node. Please set `engineType = "binary"` in the "generator" block of your "schema.prisma" file (or use the environment variables "PRISMA_CLIENT_ENGINE_TYPE=binary" and/or "PRISMA_CLI_QUERY_ENGINE_TYPE=binary".)Gets the Node-API library filename based on the binary target and intended usage (filesystem or URL).
/**
* Gets Node-API Library name depending on the binary target
* @param binaryTarget - The target platform identifier
* @param type - 'fs' for filesystem usage, 'url' for S3 download URLs
* @returns Platform-specific library filename
*/
function getNodeAPIName(binaryTarget: BinaryTarget, type: 'url' | 'fs'): string;Usage Examples:
import { getNodeAPIName, getBinaryTargetForCurrentPlatform } from "@prisma/get-platform";
const target = await getBinaryTargetForCurrentPlatform();
// Get filename for filesystem usage
const fsName = getNodeAPIName(target, 'fs');
console.log(fsName);
// Examples:
// "libquery_engine-darwin-arm64.dylib.node" (macOS ARM64)
// "libquery_engine-debian-openssl-1.1.x.so.node" (Linux)
// "query_engine-windows.dll.node" (Windows)
// Get filename for download URLs
const urlName = getNodeAPIName(target, 'url');
console.log(urlName);
// Examples:
// "libquery_engine.dylib.node" (macOS)
// "libquery_engine.so.node" (Linux)
// "query_engine.dll.node" (Windows)Platform-Specific Naming:
The function generates names based on platform conventions:
Windows platforms (target.includes('windows')):
query_engine-${binaryTarget}.dll.nodequery_engine.dll.nodemacOS platforms (target.includes('darwin')):
libquery_engine-${binaryTarget}.dylib.nodelibquery_engine.dylib.nodeLinux and other platforms:
libquery_engine-${binaryTarget}.so.nodelibquery_engine.so.nodeThe Node API support system recognizes these environment variables:
Path to a custom query engine library file. When set and the file exists, Node API support validation is bypassed.
export PRISMA_QUERY_ENGINE_LIBRARY="/path/to/custom/libquery_engine.so.node"Usage in validation:
const customLibraryPath = process.env.PRISMA_QUERY_ENGINE_LIBRARY;
const customLibraryExists = customLibraryPath && fs.existsSync(customLibraryPath);
if (!customLibraryExists && process.arch === 'ia32') {
throw new Error(/* ... */);
}While not directly used by this module, these environment variables control engine type selection:
PRISMA_CLIENT_ENGINE_TYPE: Controls client engine type ("library" or "binary")PRISMA_CLI_QUERY_ENGINE_TYPE: Controls CLI engine type ("library" or "binary")When Node API is not supported, these should be set to "binary".
Node API support works together with platform detection:
import {
assertNodeAPISupported,
getNodeAPIName,
getBinaryTargetForCurrentPlatform
} from "@prisma/get-platform";
async function setupQueryEngine() {
try {
// Check if Node API is supported
assertNodeAPISupported();
// Get the binary target for current platform
const binaryTarget = await getBinaryTargetForCurrentPlatform();
// Generate the appropriate library name
const libraryName = getNodeAPIName(binaryTarget, 'fs');
console.log(`Using Node API library: ${libraryName}`);
return { engineType: 'library', libraryName };
} catch (error) {
console.warn("Node API not supported, falling back to binary engine");
return { engineType: 'binary', libraryName: null };
}
}PRISMA_QUERY_ENGINE_LIBRARYInstall with Tessl CLI
npx tessl i tessl/npm-prisma--get-platform