MCPcopy
hub / github.com/prisma/prisma / toBrowserJS

Method toBrowserJS

packages/client-generator-js/src/TSClient/TSClient.ts:278–331  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

276 }
277
278 public toBrowserJS(): string {
279 const code = `${commonCodeJS({
280 ...this.options,
281 runtimeName: 'index-browser',
282 browser: true,
283 })}
284/**
285 * Enums
286 */
287
288${this.dmmf.schema.enumTypes.prisma?.map((type) => new Enum(type, true).toJS()).join('\n\n')}
289${this.dmmf.schema.enumTypes.model?.map((type) => new Enum(type, false).toJS()).join('\n\n') ?? ''}
290
291${new Enum(
292 {
293 name: 'ModelName',
294 values: this.dmmf.mappings.modelOperations.map((m) => m.model),
295 },
296 true,
297).toJS()}
298
299/**
300 * This is a stub Prisma Client that will error at runtime if called.
301 */
302class PrismaClient {
303 constructor() {
304 return new Proxy(this, {
305 get(target, prop) {
306 let message
307 const runtime = getRuntime()
308 if (runtime.isEdge) {
309 message = \`PrismaClient is not configured to run in \${runtime.prettyName}. In order to run Prisma Client on edge runtime, either:
310- Use Prisma Accelerate: https://pris.ly/d/accelerate
311- Use Driver Adapters: https://pris.ly/d/driver-adapters
312\`;
313 } else {
314 message = 'PrismaClient is unable to run in this browser environment, or has been bundled for the browser (running in \`' + runtime.prettyName + '\`).'
315 }
316
317 message += \`
318If this is unexpected, please open an issue: https://pris.ly/prisma-prisma-bug-report\`
319
320 throw new Error(message)
321 }
322 })
323 }
324}
325
326exports.PrismaClient = PrismaClient
327
328Object.assign(exports, Prisma)
329`
330 return code
331 }
332}

Callers

nothing calls this directly

Calls 2

commonCodeJSFunction · 0.90
toJSMethod · 0.65

Tested by

no test coverage detected