(options: MergeSchemasOptions)
| 44 | * Wasm'd version of `merge_schemas`. |
| 45 | */ |
| 46 | export function mergeSchemas(options: MergeSchemasOptions): string { |
| 47 | const debugErrorType = createDebugErrorType(debug, 'mergeSchemasWasm') |
| 48 | debug(`Using mergeSchemas Wasm`) |
| 49 | |
| 50 | const mergeSchemasEither = pipe( |
| 51 | E.tryCatch( |
| 52 | () => { |
| 53 | const params = JSON.stringify({ |
| 54 | schema: options.schemas, |
| 55 | }) |
| 56 | return prismaSchemaWasm.merge_schemas(params) |
| 57 | }, |
| 58 | (e) => |
| 59 | ({ |
| 60 | type: 'wasm-error' as const, |
| 61 | reason: '(mergeSchemas wasm)', |
| 62 | error: e as Error | WasmPanic, |
| 63 | }) as const, |
| 64 | ), |
| 65 | ) |
| 66 | |
| 67 | if (E.isRight(mergeSchemasEither)) { |
| 68 | return mergeSchemasEither.right |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Check which error to throw. |
| 73 | */ |
| 74 | const error = match(mergeSchemasEither.left) |
| 75 | .with({ type: 'wasm-error' }, (e) => { |
| 76 | debugErrorType(e) |
| 77 | |
| 78 | console.error('') // empty line for better readability |
| 79 | |
| 80 | /** |
| 81 | * Capture and propagate possible Wasm panics. |
| 82 | */ |
| 83 | if (isWasmPanic(e.error)) { |
| 84 | const { message, stack } = getWasmError(e.error) |
| 85 | debug(`Error merging schemas: ${message}`) |
| 86 | debug(stack) |
| 87 | |
| 88 | const panic = new RustPanic( |
| 89 | /* message */ message, |
| 90 | /* rustStack */ stack, |
| 91 | /* request */ '@prisma/prisma-schema-wasm merge_schemas', |
| 92 | ErrorArea.FMT_CLI, |
| 93 | ) |
| 94 | return panic |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Extract the actual error by attempting to JSON-parse the error message. |
| 99 | */ |
| 100 | const errorOutput = e.error.message |
| 101 | return new MergeSchemasError(parseQueryEngineError({ errorOutput, reason: e.reason })) |
| 102 | }) |
| 103 | .exhaustive() |
no test coverage detected