MCPcopy
hub / github.com/prisma/prisma / getDMMF

Function getDMMF

packages/get-dmmf/src/index.ts:27–78  ·  view source on GitHub ↗
(options: GetDMMFOptions)

Source from the content-addressed store, hash-verified

25 * Wasm'd version of `getDMMF`.
26 */
27export function getDMMF(options: GetDMMFOptions): DMMF.Document | GetDMMFError {
28 debug(`Using getDmmf Wasm`)
29
30 const params = JSON.stringify({
31 prismaSchema: options.datamodel,
32 noColor: Boolean(process.env.NO_COLOR),
33 })
34
35 let data: string
36 try {
37 if (process.env.FORCE_PANIC_GET_DMMF) {
38 debug('Triggering a Rust panic...')
39 prismaSchemaWasm.debug_panic()
40 }
41
42 data = prismaSchemaWasm.get_dmmf(params)
43 } catch (getDMMFErr) {
44 if (isV8StringLimitError(getDMMFErr)) {
45 debug('V8 string limit hit, falling back to buffered DMMF API')
46
47 try {
48 const data = getDMMFBuffered(params)
49 debug('dmmf data retrieved via buffered API')
50 return data
51 } catch (getDMMFBufferedErr) {
52 return {
53 type: 'wasm-error',
54 reason: '(get-dmmf buffered wasm)',
55 error: getDMMFBufferedErr as Error,
56 }
57 }
58 }
59
60 return {
61 type: 'wasm-error' as const,
62 reason: '(get-dmmf wasm)',
63 error: getDMMFErr as Error,
64 }
65 }
66
67 try {
68 const document = JSON.parse(data) as DMMF.Document
69 debug('dmmf data retrieved without errors in getDmmf Wasm')
70 return document
71 } catch (err) {
72 return {
73 type: 'parse-json' as const,
74 reason: 'Unable to parse JSON',
75 error: err as Error,
76 }
77 }
78}
79
80export function getInternalDMMF(options: GetDMMFOptions): DMMF.Document | GetDMMFError {
81 const result = getDMMF(options)

Callers 6

getInternalDMMFFunction · 0.70
getTestClientFunction · 0.50
dmmf-types.test.tsFile · 0.50
dmmf-types.test.tsFile · 0.50
setupFunction · 0.50

Calls 4

debugFunction · 0.85
isV8StringLimitErrorFunction · 0.85
getDMMFBufferedFunction · 0.85
parseMethod · 0.65

Tested by 1

setupFunction · 0.40