@prisma/client-generator-ts 6.6.0-dev.95 → 6.6.0-dev.96

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.
@@ -1,9 +1,3 @@
1
1
  export interface Generable {
2
- toJS?(): string;
3
2
  toTS(): string;
4
- toBrowserJS?(): string;
5
- toTSWithoutNamespace?(): string;
6
3
  }
7
- export declare function JS(gen: Generable): string;
8
- export declare function BrowserJS(gen: Generable): string;
9
- export declare function TS(gen: Generable): string;
@@ -4,7 +4,7 @@ import { DMMFHelper } from '../dmmf';
4
4
  import { GenerateClientOptions } from '../generateClient';
5
5
  import { GenericArgsInfo } from '../GenericsArgsInfo';
6
6
  import { type Generable } from './Generable';
7
- type RuntimeName = 'binary' | 'library' | 'wasm' | 'edge' | 'react-native' | 'client' | (string & {});
7
+ export type RuntimeName = 'binary' | 'library' | 'wasm' | 'edge' | 'react-native' | 'client' | (string & {});
8
8
  export type TSClientOptions = O.Required<GenerateClientOptions, 'runtimeBase'> & {
9
9
  /** The name of the runtime bundle to use */
10
10
  runtimeName: RuntimeName;
@@ -14,8 +14,6 @@ export type TSClientOptions = O.Required<GenerateClientOptions, 'runtimeBase'> &
14
14
  deno: boolean;
15
15
  /** When we are generating an /edge client */
16
16
  edge: boolean;
17
- /** When we are generating a /wasm client */
18
- wasm: boolean;
19
17
  /** result of getEnvPaths call */
20
18
  envPaths: EnvPaths;
21
19
  };
@@ -28,4 +26,3 @@ export declare class TSClient implements Generable {
28
26
  toTS(): string;
29
27
  toBrowserJS(): string;
30
28
  }
31
- export {};
@@ -1,5 +1,4 @@
1
1
  export { Enum } from './Enum';
2
- export { BrowserJS, JS, TS } from './Generable';
3
2
  export { InputField, InputType } from './Input';
4
3
  export { Model, ModelDelegate } from './Model';
5
4
  export { TSClient } from './TSClient';
@@ -2,6 +2,7 @@ import type * as DMMF from '@prisma/dmmf';
2
2
  import type { ActiveConnectorType, BinaryPaths, DataSource, GeneratorConfig, SqlQueryOutput } from '@prisma/generator';
3
3
  import { EnvPaths } from '@prisma/internals';
4
4
  import type { O } from 'ts-toolbelt';
5
+ import { RuntimeTarget } from './runtime-targets';
5
6
  export declare class DenylistError extends Error {
6
7
  constructor(message: string);
7
8
  }
@@ -24,6 +25,7 @@ export interface GenerateClientOptions {
24
25
  /** False when --no-engine is passed via CLI */
25
26
  copyEngine?: boolean;
26
27
  typedSql?: SqlQueryOutput[];
28
+ target: RuntimeTarget;
27
29
  }
28
30
  export interface FileMap {
29
31
  [name: string]: string | FileMap;
@@ -32,5 +34,5 @@ export interface BuildClientResult {
32
34
  fileMap: FileMap;
33
35
  prismaClientDmmf: DMMF.Document;
34
36
  }
35
- export declare function buildClient({ schemaPath, runtimeBase, datamodel, binaryPaths, outputDir, generator, dmmf, datasources, engineVersion, clientVersion, activeProvider, postinstall, copyEngine, envPaths, typedSql, }: O.Required<GenerateClientOptions, 'runtimeBase'>): BuildClientResult;
37
+ export declare function buildClient({ schemaPath, runtimeBase, datamodel, binaryPaths, outputDir, generator, dmmf, datasources, engineVersion, clientVersion, activeProvider, postinstall, copyEngine, envPaths, typedSql, target, }: O.Required<GenerateClientOptions, 'runtimeBase'>): BuildClientResult;
36
38
  export declare function generateClient(options: GenerateClientOptions): Promise<void>;
package/dist/index.d.mts CHANGED
@@ -24,7 +24,7 @@ export declare function externalToInternalDmmf(document: DMMF.Document): DMMF.Do
24
24
 
25
25
  export declare function generateClient(options: GenerateClientOptions): Promise<void>;
26
26
 
27
- declare interface GenerateClientOptions {
27
+ export declare interface GenerateClientOptions {
28
28
  datamodel: string;
29
29
  schemaPath: string;
30
30
  /** Runtime path used in runtime/type imports */
@@ -43,6 +43,7 @@ declare interface GenerateClientOptions {
43
43
  /** False when --no-engine is passed via CLI */
44
44
  copyEngine?: boolean;
45
45
  typedSql?: SqlQueryOutput[];
46
+ target: RuntimeTarget;
46
47
  }
47
48
 
48
49
  export declare function getDMMF(options: GetDMMFOptions): Promise<DMMF.Document>;
@@ -53,4 +54,8 @@ export declare class PrismaClientTsGenerator implements Generator_2 {
53
54
  generate(options: GeneratorOptions): Promise<void>;
54
55
  }
55
56
 
57
+ declare type RuntimeTarget = (typeof supportedRuntimes)[number];
58
+
59
+ declare const supportedRuntimes: readonly ["nodejs", "deno", "deno-deploy", "bun", "workerd", "edge-light", "react-native"];
60
+
56
61
  export { }
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare function externalToInternalDmmf(document: DMMF.Document): DMMF.Do
24
24
 
25
25
  export declare function generateClient(options: GenerateClientOptions): Promise<void>;
26
26
 
27
- declare interface GenerateClientOptions {
27
+ export declare interface GenerateClientOptions {
28
28
  datamodel: string;
29
29
  schemaPath: string;
30
30
  /** Runtime path used in runtime/type imports */
@@ -43,6 +43,7 @@ declare interface GenerateClientOptions {
43
43
  /** False when --no-engine is passed via CLI */
44
44
  copyEngine?: boolean;
45
45
  typedSql?: SqlQueryOutput[];
46
+ target: RuntimeTarget;
46
47
  }
47
48
 
48
49
  export declare function getDMMF(options: GetDMMFOptions): Promise<DMMF.Document>;
@@ -53,4 +54,8 @@ export declare class PrismaClientTsGenerator implements Generator_2 {
53
54
  generate(options: GeneratorOptions): Promise<void>;
54
55
  }
55
56
 
57
+ declare type RuntimeTarget = (typeof supportedRuntimes)[number];
58
+
59
+ declare const supportedRuntimes: readonly ["nodejs", "deno", "deno-deploy", "bun", "workerd", "edge-light", "react-native"];
60
+
56
61
  export { }
package/dist/index.js CHANGED
@@ -2336,17 +2336,6 @@ export type ${type.name} = (typeof ${type.name})[keyof typeof ${type.name}]
2336
2336
  }
2337
2337
  };
2338
2338
 
2339
- // src/TSClient/Generable.ts
2340
- function JS(gen) {
2341
- return gen.toJS?.() ?? "";
2342
- }
2343
- function BrowserJS(gen) {
2344
- return gen.toBrowserJS?.() ?? "";
2345
- }
2346
- function TS(gen) {
2347
- return gen.toTS();
2348
- }
2349
-
2350
2339
  // src/TSClient/Input.ts
2351
2340
  var import_client_common3 = require("@prisma/client-common");
2352
2341
  var ts2 = __toESM(require("@prisma/ts-builders"));
@@ -4297,56 +4286,50 @@ config.runtimeDataModel = JSON.parse(${JSON.stringify(datamodelString)})
4297
4286
  defineDmmfProperty(exports.Prisma, config.runtimeDataModel)`;
4298
4287
  }
4299
4288
 
4300
- // src/utils/buildGetQueryCompilerWasmModule.ts
4301
- function buildQueryCompilerWasmModule(wasm, copyCompiler, runtimeName) {
4302
- if (copyCompiler && runtimeName === "client") {
4303
- return `config.compilerWasm = {
4304
- getRuntime: () => require('./query_compiler_bg.js'),
4305
- getQueryCompilerWasmModule: async () => {
4306
- const queryCompilerWasmFilePath = require('path').join(config.dirname, 'query_compiler_bg.wasm')
4307
- const queryCompilerWasmFileBytes = require('fs').readFileSync(queryCompilerWasmFilePath)
4308
-
4309
- return new WebAssembly.Module(queryCompilerWasmFileBytes)
4310
- }
4311
- }`;
4312
- }
4313
- if (copyCompiler && runtimeName === "client" && wasm === true) {
4314
- return `config.compilerWasm = {
4315
- getRuntime: () => require('./query_compiler_bg.js'),
4316
- getQueryCompilerWasmModule: async () => {
4317
- const loader = (await import('#wasm-compiler-loader')).default
4318
- const compiler = (await loader).default
4319
- return compiler
4289
+ // src/utils/buildGetWasmModule.ts
4290
+ var import_client_common11 = require("@prisma/client-common");
4291
+ var import_ts_pattern = require("ts-pattern");
4292
+ function buildGetWasmModule({
4293
+ component,
4294
+ runtimeName,
4295
+ runtimeBase,
4296
+ target,
4297
+ activeProvider
4298
+ }) {
4299
+ const capitalizedComponent = (0, import_client_common11.capitalize)(component);
4300
+ const wasmPathBase = `${runtimeBase}/query_compiler_bg.${activeProvider}`;
4301
+ const wasmBindingsPath = `${wasmPathBase}.mjs`;
4302
+ const wasmModulePath = `${wasmPathBase}.wasm`;
4303
+ const buildNodeLoader = (0, import_ts_pattern.match)(runtimeName).with("library", () => component === "engine" && !!process.env.PRISMA_CLIENT_FORCE_WASM).with("client", () => component === "compiler").otherwise(() => false);
4304
+ const buildEdgeLoader = runtimeName === "wasm" && component === "engine";
4305
+ if (buildNodeLoader) {
4306
+ return `config.${component}Wasm = {
4307
+ getRuntime: async () => await import(${JSON.stringify(wasmBindingsPath)}),
4308
+
4309
+ getQuery${capitalizedComponent}WasmModule: async () => {
4310
+ const { createRequire } = await import('node:module')
4311
+ const { readFile } = await import('node:fs/promises')
4312
+
4313
+ const require = createRequire(import.meta.url)
4314
+ const wasmModulePath = require.resolve(${JSON.stringify(wasmModulePath)})
4315
+ const wasmModuleBytes = await readFile(wasmModulePath)
4316
+
4317
+ return new globalThis.WebAssembly.Module(wasmModuleBytes)
4320
4318
  }
4321
4319
  }`;
4322
4320
  }
4323
- return `config.compilerWasm = undefined`;
4324
- }
4325
-
4326
- // src/utils/buildGetQueryEngineWasmModule.ts
4327
- function buildQueryEngineWasmModule(wasm, copyEngine, runtimeName) {
4328
- if (copyEngine && runtimeName === "library" && process.env.PRISMA_CLIENT_FORCE_WASM) {
4329
- return `config.engineWasm = {
4330
- getRuntime: () => require('./query_engine_bg.js'),
4331
- getQueryEngineWasmModule: async () => {
4332
- const queryEngineWasmFilePath = require('path').join(config.dirname, 'query_engine_bg.wasm')
4333
- const queryEngineWasmFileBytes = require('fs').readFileSync(queryEngineWasmFilePath)
4321
+ if (buildEdgeLoader) {
4322
+ const fullWasmModulePath = target === "edge-light" ? `${wasmModulePath}?module` : wasmModulePath;
4323
+ return `config.${component}Wasm = {
4324
+ getRuntime: async () => await import(${JSON.stringify(wasmBindingsPath)}),
4334
4325
 
4335
- return new WebAssembly.Module(queryEngineWasmFileBytes)
4336
- }
4337
- }`;
4338
- }
4339
- if (copyEngine && wasm === true) {
4340
- return `config.engineWasm = {
4341
- getRuntime: () => require('./query_engine_bg.js'),
4342
- getQueryEngineWasmModule: async () => {
4343
- const loader = (await import('#wasm-engine-loader')).default
4344
- const engine = (await loader).default
4345
- return engine
4326
+ getQuery${capitalizedComponent}WasmModule: async () => {
4327
+ const { default: module } = await import(${JSON.stringify(fullWasmModulePath)})
4328
+ return module
4346
4329
  }
4347
4330
  }`;
4348
4331
  }
4349
- return `config.engineWasm = undefined`;
4332
+ return `config.${component}Wasm = undefined`;
4350
4333
  }
4351
4334
 
4352
4335
  // src/utils/buildNFTAnnotations.ts
@@ -5091,7 +5074,7 @@ var GenerateContext = class {
5091
5074
  };
5092
5075
 
5093
5076
  // src/TSClient/PrismaClient.ts
5094
- var import_client_common12 = require("@prisma/client-common");
5077
+ var import_client_common13 = require("@prisma/client-common");
5095
5078
  var import_internals6 = require("@prisma/internals");
5096
5079
  var ts11 = __toESM(require("@prisma/ts-builders"));
5097
5080
  var import_indent_string7 = __toESM(require("indent-string"));
@@ -5120,13 +5103,13 @@ ${(0, import_indent_string6.default)(sources.map((s) => `${s.name}?: Datasource`
5120
5103
  };
5121
5104
 
5122
5105
  // src/TSClient/globalOmit.ts
5123
- var import_client_common11 = require("@prisma/client-common");
5106
+ var import_client_common12 = require("@prisma/client-common");
5124
5107
  var ts10 = __toESM(require("@prisma/ts-builders"));
5125
5108
  function globalOmitConfig(dmmf) {
5126
5109
  const objectType9 = ts10.objectType().addMultiple(
5127
5110
  dmmf.datamodel.models.map((model) => {
5128
5111
  const type = ts10.namedType(getOmitName(model.name));
5129
- return ts10.property((0, import_client_common11.lowerCase)(model.name), type).optional();
5112
+ return ts10.property((0, import_client_common12.lowerCase)(model.name), type).optional();
5130
5113
  })
5131
5114
  );
5132
5115
  return ts10.moduleExport(ts10.typeDeclaration("GlobalOmitConfig", objectType9));
@@ -5139,7 +5122,7 @@ function clientTypeMapModelsDefinition(context) {
5139
5122
  if (modelNames.length === 0) {
5140
5123
  meta.add(ts11.property("modelProps", ts11.neverType));
5141
5124
  } else {
5142
- meta.add(ts11.property("modelProps", ts11.unionType(modelNames.map((name) => ts11.stringLiteral((0, import_client_common12.lowerCase)(name))))));
5125
+ meta.add(ts11.property("modelProps", ts11.unionType(modelNames.map((name) => ts11.stringLiteral((0, import_client_common13.lowerCase)(name))))));
5143
5126
  }
5144
5127
  const isolationLevel = context.dmmf.hasEnumInNamespace("TransactionIsolationLevel", "prisma") ? ts11.namedType("Prisma.TransactionIsolationLevel") : ts11.neverType;
5145
5128
  meta.add(ts11.property("txIsolationLevel", isolationLevel));
@@ -5449,7 +5432,7 @@ var PrismaClientClass = class {
5449
5432
  * \`\`\`
5450
5433
  * const prisma = new PrismaClient()
5451
5434
  * // Fetch zero or more ${capitalize2(example.plural)}
5452
- * const ${(0, import_client_common12.lowerCase)(example.plural)} = await prisma.${(0, import_client_common12.lowerCase)(example.model)}.findMany()
5435
+ * const ${(0, import_client_common13.lowerCase)(example.plural)} = await prisma.${(0, import_client_common13.lowerCase)(example.model)}.findMany()
5453
5436
  * \`\`\`
5454
5437
  *
5455
5438
  *
@@ -5502,7 +5485,7 @@ ${[
5502
5485
 
5503
5486
  ${(0, import_indent_string7.default)(
5504
5487
  dmmf.mappings.modelOperations.filter((m) => m.findMany).map((m) => {
5505
- let methodName = (0, import_client_common12.lowerCase)(m.model);
5488
+ let methodName = (0, import_client_common13.lowerCase)(m.model);
5506
5489
  if (methodName === "constructor") {
5507
5490
  methodName = '["constructor"]';
5508
5491
  }
@@ -5512,7 +5495,7 @@ ${[
5512
5495
  * Example usage:
5513
5496
  * \`\`\`ts
5514
5497
  * // Fetch zero or more ${capitalize2(m.plural)}
5515
- * const ${(0, import_client_common12.lowerCase)(m.plural)} = await prisma.${methodName}.findMany()
5498
+ * const ${(0, import_client_common13.lowerCase)(m.plural)} = await prisma.${methodName}.findMany()
5516
5499
  * \`\`\`
5517
5500
  */
5518
5501
  get ${methodName}(): Prisma.${m.model}Delegate<${generics.join(", ")}>;`;
@@ -5684,7 +5667,6 @@ var TSClient = class {
5684
5667
  toJS() {
5685
5668
  const {
5686
5669
  edge,
5687
- wasm,
5688
5670
  binaryPaths,
5689
5671
  generator,
5690
5672
  outputDir,
@@ -5694,7 +5676,9 @@ var TSClient = class {
5694
5676
  datasources,
5695
5677
  deno,
5696
5678
  copyEngine = true,
5697
- envPaths
5679
+ envPaths,
5680
+ target,
5681
+ activeProvider
5698
5682
  } = this.options;
5699
5683
  const relativeEnvPaths = {
5700
5684
  rootEnvPath: envPaths.rootEnvPath && (0, import_internals7.pathToPosix)(import_path2.default.relative(outputDir, envPaths.rootEnvPath)),
@@ -5745,8 +5729,8 @@ ${new Enum(
5745
5729
  const config = ${JSON.stringify(config, null, 2)}
5746
5730
  ${buildDirname(edge, relativeOutdir)}
5747
5731
  ${buildRuntimeDataModel(this.dmmf.datamodel, runtimeName)}
5748
- ${buildQueryEngineWasmModule(wasm, copyEngine, runtimeName)}
5749
- ${buildQueryCompilerWasmModule(wasm, copyEngine, runtimeName)}
5732
+ ${buildGetWasmModule({ component: "engine", runtimeBase, runtimeName, target, activeProvider })}
5733
+ ${buildGetWasmModule({ component: "compiler", runtimeBase, runtimeName, target, activeProvider })}
5750
5734
  ${buildInjectableEdgeEnv(edge, datasources)}
5751
5735
  ${buildWarnEnvConflicts(edge, runtimeBase, runtimeName)}
5752
5736
  ${buildDebugInitialization(edge)}
@@ -6250,10 +6234,12 @@ function buildClient({
6250
6234
  postinstall,
6251
6235
  copyEngine,
6252
6236
  envPaths,
6253
- typedSql
6237
+ typedSql,
6238
+ target
6254
6239
  }) {
6255
6240
  const clientEngineType = (0, import_internals10.getClientEngineType)(generator);
6256
- const baseClientOptions = {
6241
+ const runtimeName = getRuntimeNameForTarget(target, clientEngineType, generator.previewFeatures);
6242
+ const clientOptions = {
6257
6243
  dmmf: getPrismaClientDMMF(dmmf),
6258
6244
  envPaths: envPaths ?? { rootEnvPath: null, schemaEnvPath: void 0 },
6259
6245
  datasources,
@@ -6270,86 +6256,25 @@ function buildClient({
6270
6256
  datamodel,
6271
6257
  browser: false,
6272
6258
  deno: false,
6273
- edge: false,
6274
- wasm: false
6275
- };
6276
- const nodeClientOptions = {
6277
- ...baseClientOptions,
6278
- runtimeName: getNodeRuntimeName(clientEngineType)
6259
+ edge: ["edge", "wasm", "react-native"].includes(runtimeName),
6260
+ runtimeName,
6261
+ target
6279
6262
  };
6280
- const nodeClient = new TSClient(nodeClientOptions);
6281
- const defaultClient = new TSClient({
6282
- ...nodeClientOptions
6283
- });
6284
- const edgeClient = new TSClient({
6285
- ...baseClientOptions,
6286
- runtimeName: "edge",
6287
- edge: true
6288
- });
6289
- const rnTsClient = new TSClient({
6290
- ...baseClientOptions,
6291
- runtimeName: "react-native",
6292
- edge: true
6293
- });
6294
- const fileMap = {};
6295
- fileMap["index.js"] = JS(nodeClient);
6296
- fileMap["index.d.ts"] = TS(nodeClient);
6297
- fileMap["default.js"] = JS(defaultClient);
6298
- fileMap["default.d.ts"] = TS(defaultClient);
6299
- fileMap["index-browser.js"] = BrowserJS(nodeClient);
6300
- fileMap["edge.js"] = JS(edgeClient);
6301
- fileMap["edge.d.ts"] = TS(edgeClient);
6302
- fileMap["client.js"] = JS(defaultClient);
6303
- fileMap["client.d.ts"] = TS(defaultClient);
6304
- if (generator.previewFeatures.includes("reactNative")) {
6305
- fileMap["react-native.js"] = JS(rnTsClient);
6306
- fileMap["react-native.d.ts"] = TS(rnTsClient);
6307
- }
6308
- const usesWasmRuntime = generator.previewFeatures.includes("driverAdapters");
6309
- if (usesWasmRuntime) {
6310
- const usesClientEngine = clientEngineType === import_internals10.ClientEngineType.Client;
6311
- if (usesClientEngine) {
6312
- fileMap["wasm-worker-loader.mjs"] = `export default import('./query_compiler_bg.wasm')`;
6313
- fileMap["wasm-edge-light-loader.mjs"] = `export default import('./query_compiler_bg.wasm?module')`;
6314
- } else {
6315
- fileMap["wasm-worker-loader.mjs"] = `export default import('./query_engine_bg.wasm')`;
6316
- fileMap["wasm-edge-light-loader.mjs"] = `export default import('./query_engine_bg.wasm?module')`;
6317
- }
6318
- const wasmClient = new TSClient({
6319
- ...baseClientOptions,
6320
- runtimeName: "wasm",
6321
- edge: true,
6322
- wasm: true
6323
- });
6324
- fileMap["wasm.js"] = JS(wasmClient);
6325
- fileMap["wasm.d.ts"] = TS(wasmClient);
6326
- } else {
6327
- fileMap["wasm.js"] = fileMap["index-browser.js"];
6328
- fileMap["wasm.d.ts"] = fileMap["default.d.ts"];
6329
- }
6330
- if (generator.previewFeatures.includes("deno") && !!globalThis.Deno) {
6331
- const denoEdgeClient = new TSClient({
6332
- ...baseClientOptions,
6333
- runtimeBase: `../${runtimeBase}`,
6334
- runtimeName: "edge",
6335
- deno: true,
6336
- edge: true
6337
- });
6338
- fileMap["deno/edge.js"] = JS(denoEdgeClient);
6339
- fileMap["deno/index.d.ts"] = TS(denoEdgeClient);
6340
- fileMap["deno/edge.ts"] = `
6341
- import './polyfill.js'
6342
- // @deno-types="./index.d.ts"
6343
- export * from './edge.js'`;
6344
- fileMap["deno/polyfill.js"] = "globalThis.process = { env: Deno.env.toObject() }; globalThis.global = globalThis";
6263
+ if (runtimeName === "react-native" && !generator.previewFeatures.includes("reactNative")) {
6264
+ throw new Error(`Using the "react-native" runtime requires the "reactNative" preview feature to be enabled.`);
6345
6265
  }
6266
+ const client = new TSClient(clientOptions);
6267
+ const fileMap = {};
6268
+ fileMap["index.js"] = client.toJS();
6269
+ fileMap["index.d.ts"] = client.toTS();
6270
+ const usesWasmRuntimeOnEdge = generator.previewFeatures.includes("driverAdapters");
6346
6271
  if (typedSql && typedSql.length > 0) {
6347
6272
  fileMap["sql"] = buildTypedSql({
6348
6273
  dmmf,
6349
6274
  runtimeBase: getTypedSqlRuntimeBase(runtimeBase),
6350
6275
  mainRuntimeName: getNodeRuntimeName(clientEngineType),
6351
6276
  queries: typedSql,
6352
- edgeRuntimeName: usesWasmRuntime ? "wasm" : "edge"
6277
+ edgeRuntimeName: usesWasmRuntimeOnEdge ? "wasm" : "edge"
6353
6278
  });
6354
6279
  }
6355
6280
  return {
@@ -6382,7 +6307,8 @@ async function generateClient(options) {
6382
6307
  postinstall,
6383
6308
  envPaths,
6384
6309
  copyEngine = true,
6385
- typedSql
6310
+ typedSql,
6311
+ target
6386
6312
  } = options;
6387
6313
  const clientEngineType = (0, import_internals10.getClientEngineType)(generator);
6388
6314
  const { runtimeBase, outputDir } = await getGenerationDirs(options);
@@ -6401,7 +6327,8 @@ async function generateClient(options) {
6401
6327
  postinstall,
6402
6328
  copyEngine,
6403
6329
  envPaths,
6404
- typedSql
6330
+ typedSql,
6331
+ target
6405
6332
  });
6406
6333
  const denylistsErrors = validateDmmfAgainstDenylists(prismaClientDmmf);
6407
6334
  if (denylistsErrors) {
@@ -6418,9 +6345,6 @@ To learn more about how to rename models, check out https://pris.ly/d/naming-mod
6418
6345
  }
6419
6346
  await deleteOutputDir(outputDir);
6420
6347
  await (0, import_fs_extra.ensureDir)(outputDir);
6421
- if (generator.previewFeatures.includes("deno") && !!globalThis.Deno) {
6422
- await (0, import_fs_extra.ensureDir)(import_node_path.default.join(outputDir, "deno"));
6423
- }
6424
6348
  await writeFileMap(outputDir, fileMap);
6425
6349
  const enginePath = clientEngineType === import_internals10.ClientEngineType.Library ? binaryPaths.libqueryEngine : binaryPaths.queryEngine;
6426
6350
  if (!enginePath) {
@@ -6434,13 +6358,13 @@ To learn more about how to rename models, check out https://pris.ly/d/naming-mod
6434
6358
  }
6435
6359
  for (const [binaryTarget, filePath] of Object.entries(enginePath)) {
6436
6360
  const fileName = import_node_path.default.basename(filePath);
6437
- let target;
6361
+ let target2;
6438
6362
  if (process.env.NETLIFY && !["rhel-openssl-1.0.x", "rhel-openssl-3.0.x"].includes(binaryTarget)) {
6439
- target = import_node_path.default.join("/tmp/prisma-engines", fileName);
6363
+ target2 = import_node_path.default.join("/tmp/prisma-engines", fileName);
6440
6364
  } else {
6441
- target = import_node_path.default.join(outputDir, fileName);
6365
+ target2 = import_node_path.default.join(outputDir, fileName);
6442
6366
  }
6443
- await (0, import_fetch_engine.overwriteFile)(filePath, target);
6367
+ await (0, import_fetch_engine.overwriteFile)(filePath, target2);
6444
6368
  }
6445
6369
  }
6446
6370
  const schemaTargetPath = import_node_path.default.join(outputDir, "schema.prisma");
@@ -6555,6 +6479,26 @@ async function getGenerationDirs({ runtimeBase, outputDir }) {
6555
6479
  projectRoot: userProjectRoot
6556
6480
  };
6557
6481
  }
6482
+ function getRuntimeNameForTarget(target, engineType, previewFeatures) {
6483
+ switch (target) {
6484
+ case "nodejs":
6485
+ case "deno":
6486
+ case "bun":
6487
+ return getNodeRuntimeName(engineType);
6488
+ case "workerd":
6489
+ case "edge-light":
6490
+ case "deno-deploy":
6491
+ if (previewFeatures.includes("driverAdapters")) {
6492
+ return "wasm";
6493
+ } else {
6494
+ return "edge";
6495
+ }
6496
+ case "react-native":
6497
+ return "react-native";
6498
+ default:
6499
+ (0, import_internals10.assertNever)(target, "Unknown runtime target");
6500
+ }
6501
+ }
6558
6502
  function getNodeRuntimeName(engineType) {
6559
6503
  if (engineType === import_internals10.ClientEngineType.Binary) {
6560
6504
  return "binary";
@@ -6578,7 +6522,7 @@ async function deleteOutputDir(outputDir) {
6578
6522
  if (files.length === 0) {
6579
6523
  return;
6580
6524
  }
6581
- if (!files.includes("client.d.ts")) {
6525
+ if (!files.includes("index.d.ts")) {
6582
6526
  throw new Error(
6583
6527
  `${outputDir} exists and is not empty but doesn't look like a generated Prisma Client. Please check your output path and remove the existing directory if you indeed want to generate the Prisma Client in that location.`
6584
6528
  );
@@ -6601,10 +6545,44 @@ async function deleteOutputDir(outputDir) {
6601
6545
  var import_debug = __toESM(require("@prisma/debug"));
6602
6546
  var import_engines_version = require("@prisma/engines-version");
6603
6547
  var import_internals11 = require("@prisma/internals");
6604
- var import_ts_pattern = require("ts-pattern");
6548
+ var import_ts_pattern2 = require("ts-pattern");
6605
6549
 
6606
6550
  // package.json
6607
- var version = "6.6.0-dev.95";
6551
+ var version = "6.6.0-dev.96";
6552
+
6553
+ // src/runtime-targets.ts
6554
+ var supportedRuntimes = ["nodejs", "deno", "deno-deploy", "bun", "workerd", "edge-light", "react-native"];
6555
+ function parseRuntimeTarget(target) {
6556
+ switch (target.toLowerCase()) {
6557
+ case "node":
6558
+ case "nodejs":
6559
+ return "nodejs";
6560
+ case "deno":
6561
+ return "deno";
6562
+ case "deno-deploy":
6563
+ return "deno-deploy";
6564
+ case "bun":
6565
+ return "bun";
6566
+ case "workerd":
6567
+ case "cloudflare":
6568
+ return "workerd";
6569
+ case "edge-light":
6570
+ case "vercel":
6571
+ return "edge-light";
6572
+ case "react-native":
6573
+ return "react-native";
6574
+ default:
6575
+ throw new Error(
6576
+ `Unknown target runtime: "${target}". The available options are: ${supportedRuntimes.map((runtime) => `"${runtime}"`).join(", ")}`
6577
+ );
6578
+ }
6579
+ }
6580
+ function parseRuntimeTargetFromUnknown(target) {
6581
+ if (typeof target !== "string") {
6582
+ throw new Error(`Invalid target runtime: ${JSON.stringify(target)}. Expected a string.`);
6583
+ }
6584
+ return parseRuntimeTarget(target);
6585
+ }
6608
6586
 
6609
6587
  // src/generator.ts
6610
6588
  var debug = (0, import_debug.default)("prisma:client:generator");
@@ -6626,7 +6604,7 @@ function getOutputPath(config) {
6626
6604
  var PrismaClientTsGenerator = class {
6627
6605
  name = "prisma-client-ts";
6628
6606
  getManifest(config) {
6629
- const requiresEngines = (0, import_ts_pattern.match)((0, import_internals11.getClientEngineType)(config)).with(import_internals11.ClientEngineType.Library, () => ["libqueryEngine"]).with(import_internals11.ClientEngineType.Binary, () => ["queryEngine"]).with(import_internals11.ClientEngineType.Client, () => []).exhaustive();
6607
+ const requiresEngines = (0, import_ts_pattern2.match)((0, import_internals11.getClientEngineType)(config)).with(import_internals11.ClientEngineType.Library, () => ["libqueryEngine"]).with(import_internals11.ClientEngineType.Binary, () => ["queryEngine"]).with(import_internals11.ClientEngineType.Client, () => []).exhaustive();
6630
6608
  debug("requiresEngines", requiresEngines);
6631
6609
  return Promise.resolve({
6632
6610
  defaultOutput: getOutputPath(config),
@@ -6652,7 +6630,8 @@ var PrismaClientTsGenerator = class {
6652
6630
  activeProvider: options.datasources[0]?.activeProvider,
6653
6631
  postinstall: options.postinstall,
6654
6632
  copyEngine: !options.noEngine,
6655
- typedSql: options.typedSql
6633
+ typedSql: options.typedSql,
6634
+ target: options.generator.config.runtime !== void 0 ? parseRuntimeTargetFromUnknown(options.generator.config.runtime) : "nodejs"
6656
6635
  });
6657
6636
  }
6658
6637
  };
@@ -6684,11 +6663,11 @@ function dmmfToTypes(dmmf) {
6684
6663
  browser: false,
6685
6664
  deno: false,
6686
6665
  edge: false,
6687
- wasm: false,
6688
6666
  envPaths: {
6689
6667
  rootEnvPath: null,
6690
6668
  schemaEnvPath: void 0
6691
- }
6669
+ },
6670
+ target: "nodejs"
6692
6671
  }).toTS();
6693
6672
  }
6694
6673
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -2331,17 +2331,6 @@ export type ${type.name} = (typeof ${type.name})[keyof typeof ${type.name}]
2331
2331
  }
2332
2332
  };
2333
2333
 
2334
- // src/TSClient/Generable.ts
2335
- function JS(gen) {
2336
- return gen.toJS?.() ?? "";
2337
- }
2338
- function BrowserJS(gen) {
2339
- return gen.toBrowserJS?.() ?? "";
2340
- }
2341
- function TS(gen) {
2342
- return gen.toTS();
2343
- }
2344
-
2345
2334
  // src/TSClient/Input.ts
2346
2335
  import { uniqueBy } from "@prisma/client-common";
2347
2336
  import * as ts2 from "@prisma/ts-builders";
@@ -4295,56 +4284,50 @@ config.runtimeDataModel = JSON.parse(${JSON.stringify(datamodelString)})
4295
4284
  defineDmmfProperty(exports.Prisma, config.runtimeDataModel)`;
4296
4285
  }
4297
4286
 
4298
- // src/utils/buildGetQueryCompilerWasmModule.ts
4299
- function buildQueryCompilerWasmModule(wasm, copyCompiler, runtimeName) {
4300
- if (copyCompiler && runtimeName === "client") {
4301
- return `config.compilerWasm = {
4302
- getRuntime: () => require('./query_compiler_bg.js'),
4303
- getQueryCompilerWasmModule: async () => {
4304
- const queryCompilerWasmFilePath = require('path').join(config.dirname, 'query_compiler_bg.wasm')
4305
- const queryCompilerWasmFileBytes = require('fs').readFileSync(queryCompilerWasmFilePath)
4306
-
4307
- return new WebAssembly.Module(queryCompilerWasmFileBytes)
4308
- }
4309
- }`;
4310
- }
4311
- if (copyCompiler && runtimeName === "client" && wasm === true) {
4312
- return `config.compilerWasm = {
4313
- getRuntime: () => require('./query_compiler_bg.js'),
4314
- getQueryCompilerWasmModule: async () => {
4315
- const loader = (await import('#wasm-compiler-loader')).default
4316
- const compiler = (await loader).default
4317
- return compiler
4287
+ // src/utils/buildGetWasmModule.ts
4288
+ import { capitalize as capitalize5 } from "@prisma/client-common";
4289
+ import { match } from "ts-pattern";
4290
+ function buildGetWasmModule({
4291
+ component,
4292
+ runtimeName,
4293
+ runtimeBase,
4294
+ target,
4295
+ activeProvider
4296
+ }) {
4297
+ const capitalizedComponent = capitalize5(component);
4298
+ const wasmPathBase = `${runtimeBase}/query_compiler_bg.${activeProvider}`;
4299
+ const wasmBindingsPath = `${wasmPathBase}.mjs`;
4300
+ const wasmModulePath = `${wasmPathBase}.wasm`;
4301
+ const buildNodeLoader = match(runtimeName).with("library", () => component === "engine" && !!process.env.PRISMA_CLIENT_FORCE_WASM).with("client", () => component === "compiler").otherwise(() => false);
4302
+ const buildEdgeLoader = runtimeName === "wasm" && component === "engine";
4303
+ if (buildNodeLoader) {
4304
+ return `config.${component}Wasm = {
4305
+ getRuntime: async () => await import(${JSON.stringify(wasmBindingsPath)}),
4306
+
4307
+ getQuery${capitalizedComponent}WasmModule: async () => {
4308
+ const { createRequire } = await import('node:module')
4309
+ const { readFile } = await import('node:fs/promises')
4310
+
4311
+ const require = createRequire(import.meta.url)
4312
+ const wasmModulePath = require.resolve(${JSON.stringify(wasmModulePath)})
4313
+ const wasmModuleBytes = await readFile(wasmModulePath)
4314
+
4315
+ return new globalThis.WebAssembly.Module(wasmModuleBytes)
4318
4316
  }
4319
4317
  }`;
4320
4318
  }
4321
- return `config.compilerWasm = undefined`;
4322
- }
4323
-
4324
- // src/utils/buildGetQueryEngineWasmModule.ts
4325
- function buildQueryEngineWasmModule(wasm, copyEngine, runtimeName) {
4326
- if (copyEngine && runtimeName === "library" && process.env.PRISMA_CLIENT_FORCE_WASM) {
4327
- return `config.engineWasm = {
4328
- getRuntime: () => require('./query_engine_bg.js'),
4329
- getQueryEngineWasmModule: async () => {
4330
- const queryEngineWasmFilePath = require('path').join(config.dirname, 'query_engine_bg.wasm')
4331
- const queryEngineWasmFileBytes = require('fs').readFileSync(queryEngineWasmFilePath)
4319
+ if (buildEdgeLoader) {
4320
+ const fullWasmModulePath = target === "edge-light" ? `${wasmModulePath}?module` : wasmModulePath;
4321
+ return `config.${component}Wasm = {
4322
+ getRuntime: async () => await import(${JSON.stringify(wasmBindingsPath)}),
4332
4323
 
4333
- return new WebAssembly.Module(queryEngineWasmFileBytes)
4334
- }
4335
- }`;
4336
- }
4337
- if (copyEngine && wasm === true) {
4338
- return `config.engineWasm = {
4339
- getRuntime: () => require('./query_engine_bg.js'),
4340
- getQueryEngineWasmModule: async () => {
4341
- const loader = (await import('#wasm-engine-loader')).default
4342
- const engine = (await loader).default
4343
- return engine
4324
+ getQuery${capitalizedComponent}WasmModule: async () => {
4325
+ const { default: module } = await import(${JSON.stringify(fullWasmModulePath)})
4326
+ return module
4344
4327
  }
4345
4328
  }`;
4346
4329
  }
4347
- return `config.engineWasm = undefined`;
4330
+ return `config.${component}Wasm = undefined`;
4348
4331
  }
4349
4332
 
4350
4333
  // src/utils/buildNFTAnnotations.ts
@@ -5682,7 +5665,6 @@ var TSClient = class {
5682
5665
  toJS() {
5683
5666
  const {
5684
5667
  edge,
5685
- wasm,
5686
5668
  binaryPaths,
5687
5669
  generator,
5688
5670
  outputDir,
@@ -5692,7 +5674,9 @@ var TSClient = class {
5692
5674
  datasources,
5693
5675
  deno,
5694
5676
  copyEngine = true,
5695
- envPaths
5677
+ envPaths,
5678
+ target,
5679
+ activeProvider
5696
5680
  } = this.options;
5697
5681
  const relativeEnvPaths = {
5698
5682
  rootEnvPath: envPaths.rootEnvPath && pathToPosix3(path2.relative(outputDir, envPaths.rootEnvPath)),
@@ -5743,8 +5727,8 @@ ${new Enum(
5743
5727
  const config = ${JSON.stringify(config, null, 2)}
5744
5728
  ${buildDirname(edge, relativeOutdir)}
5745
5729
  ${buildRuntimeDataModel(this.dmmf.datamodel, runtimeName)}
5746
- ${buildQueryEngineWasmModule(wasm, copyEngine, runtimeName)}
5747
- ${buildQueryCompilerWasmModule(wasm, copyEngine, runtimeName)}
5730
+ ${buildGetWasmModule({ component: "engine", runtimeBase, runtimeName, target, activeProvider })}
5731
+ ${buildGetWasmModule({ component: "compiler", runtimeBase, runtimeName, target, activeProvider })}
5748
5732
  ${buildInjectableEdgeEnv(edge, datasources)}
5749
5733
  ${buildWarnEnvConflicts(edge, runtimeBase, runtimeName)}
5750
5734
  ${buildDebugInitialization(edge)}
@@ -6248,10 +6232,12 @@ function buildClient({
6248
6232
  postinstall,
6249
6233
  copyEngine,
6250
6234
  envPaths,
6251
- typedSql
6235
+ typedSql,
6236
+ target
6252
6237
  }) {
6253
6238
  const clientEngineType = getClientEngineType2(generator);
6254
- const baseClientOptions = {
6239
+ const runtimeName = getRuntimeNameForTarget(target, clientEngineType, generator.previewFeatures);
6240
+ const clientOptions = {
6255
6241
  dmmf: getPrismaClientDMMF(dmmf),
6256
6242
  envPaths: envPaths ?? { rootEnvPath: null, schemaEnvPath: void 0 },
6257
6243
  datasources,
@@ -6268,86 +6254,25 @@ function buildClient({
6268
6254
  datamodel,
6269
6255
  browser: false,
6270
6256
  deno: false,
6271
- edge: false,
6272
- wasm: false
6257
+ edge: ["edge", "wasm", "react-native"].includes(runtimeName),
6258
+ runtimeName,
6259
+ target
6273
6260
  };
6274
- const nodeClientOptions = {
6275
- ...baseClientOptions,
6276
- runtimeName: getNodeRuntimeName(clientEngineType)
6277
- };
6278
- const nodeClient = new TSClient(nodeClientOptions);
6279
- const defaultClient = new TSClient({
6280
- ...nodeClientOptions
6281
- });
6282
- const edgeClient = new TSClient({
6283
- ...baseClientOptions,
6284
- runtimeName: "edge",
6285
- edge: true
6286
- });
6287
- const rnTsClient = new TSClient({
6288
- ...baseClientOptions,
6289
- runtimeName: "react-native",
6290
- edge: true
6291
- });
6292
- const fileMap = {};
6293
- fileMap["index.js"] = JS(nodeClient);
6294
- fileMap["index.d.ts"] = TS(nodeClient);
6295
- fileMap["default.js"] = JS(defaultClient);
6296
- fileMap["default.d.ts"] = TS(defaultClient);
6297
- fileMap["index-browser.js"] = BrowserJS(nodeClient);
6298
- fileMap["edge.js"] = JS(edgeClient);
6299
- fileMap["edge.d.ts"] = TS(edgeClient);
6300
- fileMap["client.js"] = JS(defaultClient);
6301
- fileMap["client.d.ts"] = TS(defaultClient);
6302
- if (generator.previewFeatures.includes("reactNative")) {
6303
- fileMap["react-native.js"] = JS(rnTsClient);
6304
- fileMap["react-native.d.ts"] = TS(rnTsClient);
6305
- }
6306
- const usesWasmRuntime = generator.previewFeatures.includes("driverAdapters");
6307
- if (usesWasmRuntime) {
6308
- const usesClientEngine = clientEngineType === ClientEngineType3.Client;
6309
- if (usesClientEngine) {
6310
- fileMap["wasm-worker-loader.mjs"] = `export default import('./query_compiler_bg.wasm')`;
6311
- fileMap["wasm-edge-light-loader.mjs"] = `export default import('./query_compiler_bg.wasm?module')`;
6312
- } else {
6313
- fileMap["wasm-worker-loader.mjs"] = `export default import('./query_engine_bg.wasm')`;
6314
- fileMap["wasm-edge-light-loader.mjs"] = `export default import('./query_engine_bg.wasm?module')`;
6315
- }
6316
- const wasmClient = new TSClient({
6317
- ...baseClientOptions,
6318
- runtimeName: "wasm",
6319
- edge: true,
6320
- wasm: true
6321
- });
6322
- fileMap["wasm.js"] = JS(wasmClient);
6323
- fileMap["wasm.d.ts"] = TS(wasmClient);
6324
- } else {
6325
- fileMap["wasm.js"] = fileMap["index-browser.js"];
6326
- fileMap["wasm.d.ts"] = fileMap["default.d.ts"];
6327
- }
6328
- if (generator.previewFeatures.includes("deno") && !!globalThis.Deno) {
6329
- const denoEdgeClient = new TSClient({
6330
- ...baseClientOptions,
6331
- runtimeBase: `../${runtimeBase}`,
6332
- runtimeName: "edge",
6333
- deno: true,
6334
- edge: true
6335
- });
6336
- fileMap["deno/edge.js"] = JS(denoEdgeClient);
6337
- fileMap["deno/index.d.ts"] = TS(denoEdgeClient);
6338
- fileMap["deno/edge.ts"] = `
6339
- import './polyfill.js'
6340
- // @deno-types="./index.d.ts"
6341
- export * from './edge.js'`;
6342
- fileMap["deno/polyfill.js"] = "globalThis.process = { env: Deno.env.toObject() }; globalThis.global = globalThis";
6261
+ if (runtimeName === "react-native" && !generator.previewFeatures.includes("reactNative")) {
6262
+ throw new Error(`Using the "react-native" runtime requires the "reactNative" preview feature to be enabled.`);
6343
6263
  }
6264
+ const client = new TSClient(clientOptions);
6265
+ const fileMap = {};
6266
+ fileMap["index.js"] = client.toJS();
6267
+ fileMap["index.d.ts"] = client.toTS();
6268
+ const usesWasmRuntimeOnEdge = generator.previewFeatures.includes("driverAdapters");
6344
6269
  if (typedSql && typedSql.length > 0) {
6345
6270
  fileMap["sql"] = buildTypedSql({
6346
6271
  dmmf,
6347
6272
  runtimeBase: getTypedSqlRuntimeBase(runtimeBase),
6348
6273
  mainRuntimeName: getNodeRuntimeName(clientEngineType),
6349
6274
  queries: typedSql,
6350
- edgeRuntimeName: usesWasmRuntime ? "wasm" : "edge"
6275
+ edgeRuntimeName: usesWasmRuntimeOnEdge ? "wasm" : "edge"
6351
6276
  });
6352
6277
  }
6353
6278
  return {
@@ -6380,7 +6305,8 @@ async function generateClient(options) {
6380
6305
  postinstall,
6381
6306
  envPaths,
6382
6307
  copyEngine = true,
6383
- typedSql
6308
+ typedSql,
6309
+ target
6384
6310
  } = options;
6385
6311
  const clientEngineType = getClientEngineType2(generator);
6386
6312
  const { runtimeBase, outputDir } = await getGenerationDirs(options);
@@ -6399,7 +6325,8 @@ async function generateClient(options) {
6399
6325
  postinstall,
6400
6326
  copyEngine,
6401
6327
  envPaths,
6402
- typedSql
6328
+ typedSql,
6329
+ target
6403
6330
  });
6404
6331
  const denylistsErrors = validateDmmfAgainstDenylists(prismaClientDmmf);
6405
6332
  if (denylistsErrors) {
@@ -6416,9 +6343,6 @@ To learn more about how to rename models, check out https://pris.ly/d/naming-mod
6416
6343
  }
6417
6344
  await deleteOutputDir(outputDir);
6418
6345
  await (0, import_fs_extra.ensureDir)(outputDir);
6419
- if (generator.previewFeatures.includes("deno") && !!globalThis.Deno) {
6420
- await (0, import_fs_extra.ensureDir)(path3.join(outputDir, "deno"));
6421
- }
6422
6346
  await writeFileMap(outputDir, fileMap);
6423
6347
  const enginePath = clientEngineType === ClientEngineType3.Library ? binaryPaths.libqueryEngine : binaryPaths.queryEngine;
6424
6348
  if (!enginePath) {
@@ -6432,13 +6356,13 @@ To learn more about how to rename models, check out https://pris.ly/d/naming-mod
6432
6356
  }
6433
6357
  for (const [binaryTarget, filePath] of Object.entries(enginePath)) {
6434
6358
  const fileName = path3.basename(filePath);
6435
- let target;
6359
+ let target2;
6436
6360
  if (process.env.NETLIFY && !["rhel-openssl-1.0.x", "rhel-openssl-3.0.x"].includes(binaryTarget)) {
6437
- target = path3.join("/tmp/prisma-engines", fileName);
6361
+ target2 = path3.join("/tmp/prisma-engines", fileName);
6438
6362
  } else {
6439
- target = path3.join(outputDir, fileName);
6363
+ target2 = path3.join(outputDir, fileName);
6440
6364
  }
6441
- await overwriteFile(filePath, target);
6365
+ await overwriteFile(filePath, target2);
6442
6366
  }
6443
6367
  }
6444
6368
  const schemaTargetPath = path3.join(outputDir, "schema.prisma");
@@ -6553,6 +6477,26 @@ async function getGenerationDirs({ runtimeBase, outputDir }) {
6553
6477
  projectRoot: userProjectRoot
6554
6478
  };
6555
6479
  }
6480
+ function getRuntimeNameForTarget(target, engineType, previewFeatures) {
6481
+ switch (target) {
6482
+ case "nodejs":
6483
+ case "deno":
6484
+ case "bun":
6485
+ return getNodeRuntimeName(engineType);
6486
+ case "workerd":
6487
+ case "edge-light":
6488
+ case "deno-deploy":
6489
+ if (previewFeatures.includes("driverAdapters")) {
6490
+ return "wasm";
6491
+ } else {
6492
+ return "edge";
6493
+ }
6494
+ case "react-native":
6495
+ return "react-native";
6496
+ default:
6497
+ assertNever3(target, "Unknown runtime target");
6498
+ }
6499
+ }
6556
6500
  function getNodeRuntimeName(engineType) {
6557
6501
  if (engineType === ClientEngineType3.Binary) {
6558
6502
  return "binary";
@@ -6576,7 +6520,7 @@ async function deleteOutputDir(outputDir) {
6576
6520
  if (files.length === 0) {
6577
6521
  return;
6578
6522
  }
6579
- if (!files.includes("client.d.ts")) {
6523
+ if (!files.includes("index.d.ts")) {
6580
6524
  throw new Error(
6581
6525
  `${outputDir} exists and is not empty but doesn't look like a generated Prisma Client. Please check your output path and remove the existing directory if you indeed want to generate the Prisma Client in that location.`
6582
6526
  );
@@ -6599,10 +6543,44 @@ async function deleteOutputDir(outputDir) {
6599
6543
  import Debug from "@prisma/debug";
6600
6544
  import { enginesVersion } from "@prisma/engines-version";
6601
6545
  import { ClientEngineType as ClientEngineType4, getClientEngineType as getClientEngineType3, parseEnvValue } from "@prisma/internals";
6602
- import { match } from "ts-pattern";
6546
+ import { match as match2 } from "ts-pattern";
6603
6547
 
6604
6548
  // package.json
6605
- var version = "6.6.0-dev.95";
6549
+ var version = "6.6.0-dev.96";
6550
+
6551
+ // src/runtime-targets.ts
6552
+ var supportedRuntimes = ["nodejs", "deno", "deno-deploy", "bun", "workerd", "edge-light", "react-native"];
6553
+ function parseRuntimeTarget(target) {
6554
+ switch (target.toLowerCase()) {
6555
+ case "node":
6556
+ case "nodejs":
6557
+ return "nodejs";
6558
+ case "deno":
6559
+ return "deno";
6560
+ case "deno-deploy":
6561
+ return "deno-deploy";
6562
+ case "bun":
6563
+ return "bun";
6564
+ case "workerd":
6565
+ case "cloudflare":
6566
+ return "workerd";
6567
+ case "edge-light":
6568
+ case "vercel":
6569
+ return "edge-light";
6570
+ case "react-native":
6571
+ return "react-native";
6572
+ default:
6573
+ throw new Error(
6574
+ `Unknown target runtime: "${target}". The available options are: ${supportedRuntimes.map((runtime) => `"${runtime}"`).join(", ")}`
6575
+ );
6576
+ }
6577
+ }
6578
+ function parseRuntimeTargetFromUnknown(target) {
6579
+ if (typeof target !== "string") {
6580
+ throw new Error(`Invalid target runtime: ${JSON.stringify(target)}. Expected a string.`);
6581
+ }
6582
+ return parseRuntimeTarget(target);
6583
+ }
6606
6584
 
6607
6585
  // src/generator.ts
6608
6586
  var debug = Debug("prisma:client:generator");
@@ -6624,7 +6602,7 @@ function getOutputPath(config) {
6624
6602
  var PrismaClientTsGenerator = class {
6625
6603
  name = "prisma-client-ts";
6626
6604
  getManifest(config) {
6627
- const requiresEngines = match(getClientEngineType3(config)).with(ClientEngineType4.Library, () => ["libqueryEngine"]).with(ClientEngineType4.Binary, () => ["queryEngine"]).with(ClientEngineType4.Client, () => []).exhaustive();
6605
+ const requiresEngines = match2(getClientEngineType3(config)).with(ClientEngineType4.Library, () => ["libqueryEngine"]).with(ClientEngineType4.Binary, () => ["queryEngine"]).with(ClientEngineType4.Client, () => []).exhaustive();
6628
6606
  debug("requiresEngines", requiresEngines);
6629
6607
  return Promise.resolve({
6630
6608
  defaultOutput: getOutputPath(config),
@@ -6650,7 +6628,8 @@ var PrismaClientTsGenerator = class {
6650
6628
  activeProvider: options.datasources[0]?.activeProvider,
6651
6629
  postinstall: options.postinstall,
6652
6630
  copyEngine: !options.noEngine,
6653
- typedSql: options.typedSql
6631
+ typedSql: options.typedSql,
6632
+ target: options.generator.config.runtime !== void 0 ? parseRuntimeTargetFromUnknown(options.generator.config.runtime) : "nodejs"
6654
6633
  });
6655
6634
  }
6656
6635
  };
@@ -6682,11 +6661,11 @@ function dmmfToTypes(dmmf) {
6682
6661
  browser: false,
6683
6662
  deno: false,
6684
6663
  edge: false,
6685
- wasm: false,
6686
6664
  envPaths: {
6687
6665
  rootEnvPath: null,
6688
6666
  schemaEnvPath: void 0
6689
- }
6667
+ },
6668
+ target: "nodejs"
6690
6669
  }).toTS();
6691
6670
  }
6692
6671
  export {
@@ -0,0 +1,5 @@
1
+ declare const supportedRuntimes: readonly ["nodejs", "deno", "deno-deploy", "bun", "workerd", "edge-light", "react-native"];
2
+ export type RuntimeTarget = (typeof supportedRuntimes)[number];
3
+ export declare function parseRuntimeTarget(target: string): RuntimeTarget;
4
+ export declare function parseRuntimeTargetFromUnknown(target: unknown): RuntimeTarget;
5
+ export {};
@@ -0,0 +1,11 @@
1
+ import { ActiveConnectorType } from '@prisma/generator';
2
+ import { RuntimeTarget } from '../runtime-targets';
3
+ import { RuntimeName } from '../TSClient/TSClient';
4
+ export type BuildWasmModuleOptions = {
5
+ component: 'engine' | 'compiler';
6
+ runtimeName: RuntimeName;
7
+ runtimeBase: string;
8
+ target: RuntimeTarget;
9
+ activeProvider: ActiveConnectorType;
10
+ };
11
+ export declare function buildGetWasmModule({ component, runtimeName, runtimeBase, target, activeProvider, }: BuildWasmModuleOptions): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-generator-ts",
3
- "version": "6.6.0-dev.95",
3
+ "version": "6.6.0-dev.96",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -34,14 +34,14 @@
34
34
  "pkg-up": "3.1.0",
35
35
  "pluralize": "8.0.0",
36
36
  "ts-pattern": "5.6.2",
37
- "@prisma/client-common": "6.6.0-dev.95",
38
- "@prisma/debug": "6.6.0-dev.95",
39
- "@prisma/dmmf": "6.6.0-dev.95",
40
- "@prisma/generator": "6.6.0-dev.95",
41
- "@prisma/fetch-engine": "6.6.0-dev.95",
42
- "@prisma/get-platform": "6.6.0-dev.95",
43
- "@prisma/internals": "6.6.0-dev.95",
44
- "@prisma/ts-builders": "6.6.0-dev.95"
37
+ "@prisma/debug": "6.6.0-dev.96",
38
+ "@prisma/client-common": "6.6.0-dev.96",
39
+ "@prisma/fetch-engine": "6.6.0-dev.96",
40
+ "@prisma/get-platform": "6.6.0-dev.96",
41
+ "@prisma/generator": "6.6.0-dev.96",
42
+ "@prisma/dmmf": "6.6.0-dev.96",
43
+ "@prisma/ts-builders": "6.6.0-dev.96",
44
+ "@prisma/internals": "6.6.0-dev.96"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/pluralize": "0.0.33",
@@ -55,6 +55,6 @@
55
55
  "scripts": {
56
56
  "dev": "DEV=true tsx helpers/build.ts",
57
57
  "build": "tsx helpers/build.ts",
58
- "test": "vitest run"
58
+ "test": "vitest run --testTimeout 30000"
59
59
  }
60
60
  }
@@ -1,6 +0,0 @@
1
- import { TSClientOptions } from '../TSClient/TSClient';
2
- /**
3
- * Builds the necessary glue code to load the query compiler wasm module.
4
- * @returns
5
- */
6
- export declare function buildQueryCompilerWasmModule(wasm: boolean, copyCompiler: boolean, runtimeName: TSClientOptions['runtimeName']): "config.compilerWasm = {\n getRuntime: () => require('./query_compiler_bg.js'),\n getQueryCompilerWasmModule: async () => {\n const queryCompilerWasmFilePath = require('path').join(config.dirname, 'query_compiler_bg.wasm')\n const queryCompilerWasmFileBytes = require('fs').readFileSync(queryCompilerWasmFilePath)\n\n return new WebAssembly.Module(queryCompilerWasmFileBytes)\n }\n }" | "config.compilerWasm = {\n getRuntime: () => require('./query_compiler_bg.js'),\n getQueryCompilerWasmModule: async () => {\n const loader = (await import('#wasm-compiler-loader')).default\n const compiler = (await loader).default\n return compiler\n }\n}" | "config.compilerWasm = undefined";
@@ -1,6 +0,0 @@
1
- import { TSClientOptions } from '../TSClient/TSClient';
2
- /**
3
- * Builds the necessary glue code to load the query engine wasm module.
4
- * @returns
5
- */
6
- export declare function buildQueryEngineWasmModule(wasm: boolean, copyEngine: boolean, runtimeName: TSClientOptions['runtimeName']): "config.engineWasm = {\n getRuntime: () => require('./query_engine_bg.js'),\n getQueryEngineWasmModule: async () => {\n const queryEngineWasmFilePath = require('path').join(config.dirname, 'query_engine_bg.wasm')\n const queryEngineWasmFileBytes = require('fs').readFileSync(queryEngineWasmFilePath)\n\n return new WebAssembly.Module(queryEngineWasmFileBytes)\n }\n }" | "config.engineWasm = {\n getRuntime: () => require('./query_engine_bg.js'),\n getQueryEngineWasmModule: async () => {\n const loader = (await import('#wasm-engine-loader')).default\n const engine = (await loader).default\n return engine\n }\n}" | "config.engineWasm = undefined";