(options: ValidateOptions)
| 44 | * Wasm'd version of `validate`. |
| 45 | */ |
| 46 | export function validate(options: ValidateOptions): void { |
| 47 | const debugErrorType = createDebugErrorType(debug, 'validateWasm') |
| 48 | debug(`Using validate Wasm`) |
| 49 | |
| 50 | const validateEither = pipe( |
| 51 | E.tryCatch( |
| 52 | () => { |
| 53 | /** |
| 54 | * Note: `validate` was introduced as a substitute of `getDMMF` to validate schemas the |
| 55 | * same way `getDMMF` did, but without the expensive DMMF document computation, so we |
| 56 | * keep using `FORCE_PANIC_GET_DMMF` to avoid breaking changes in env vars. |
| 57 | */ |
| 58 | if (process.env.FORCE_PANIC_GET_DMMF) { |
| 59 | debug('Triggering a Rust panic...') |
| 60 | prismaSchemaWasm.debug_panic() |
| 61 | } |
| 62 | |
| 63 | const params = JSON.stringify({ |
| 64 | prismaSchema: options.schemas, |
| 65 | noColor: Boolean(process.env.NO_COLOR), |
| 66 | }) |
| 67 | prismaSchemaWasm.validate(params) |
| 68 | }, |
| 69 | (e) => |
| 70 | ({ |
| 71 | type: 'wasm-error' as const, |
| 72 | reason: '(validate wasm)', |
| 73 | error: e as Error | WasmPanic, |
| 74 | }) as const, |
| 75 | ), |
| 76 | ) |
| 77 | |
| 78 | if (E.isRight(validateEither)) { |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Check which error to throw. |
| 84 | */ |
| 85 | const error = match(validateEither.left) |
| 86 | .with({ type: 'wasm-error' }, (e) => { |
| 87 | debugErrorType(e) |
| 88 | |
| 89 | console.error('') // empty line for better readability |
| 90 | |
| 91 | /** |
| 92 | * Capture and propagate possible Wasm panics. |
| 93 | */ |
| 94 | if (isWasmPanic(e.error)) { |
| 95 | const { message, stack } = getWasmError(e.error) |
| 96 | debug(`Error validating schema: ${message}`) |
| 97 | debug(stack) |
| 98 | |
| 99 | const panic = new RustPanic( |
| 100 | /* message */ message, |
| 101 | /* rustStack */ stack, |
| 102 | /* request */ '@prisma/prisma-schema-wasm validate', |
| 103 | ErrorArea.FMT_CLI, |
no test coverage detected