(options: GetConfigOptions)
| 69 | * Wasm'd version of `getConfig`. |
| 70 | */ |
| 71 | export async function getConfig(options: GetConfigOptions): Promise<ConfigMetaFormat> { |
| 72 | const debugErrorType = createDebugErrorType(debug, 'getConfigWasm') |
| 73 | debug(`Using getConfig Wasm`) |
| 74 | |
| 75 | const configEither = pipe( |
| 76 | E.tryCatch( |
| 77 | () => { |
| 78 | if (process.env.FORCE_PANIC_GET_CONFIG) { |
| 79 | debug('Triggering a Rust panic...') |
| 80 | prismaSchemaWasm.debug_panic() |
| 81 | } |
| 82 | |
| 83 | const params = JSON.stringify({ prismaSchema: options.datamodel }) |
| 84 | |
| 85 | return prismaSchemaWasm.get_config(params) |
| 86 | }, |
| 87 | (e) => ({ |
| 88 | type: 'wasm-error' as const, |
| 89 | reason: '(get-config wasm)', |
| 90 | error: e as Error | WasmPanic, |
| 91 | }), |
| 92 | ), |
| 93 | E.map((result) => ({ result })), |
| 94 | E.chainW(({ result }) => |
| 95 | // NOTE: this should never fail, as we expect returned values to be valid JSON-serializable strings |
| 96 | E.tryCatch( |
| 97 | () => JSON.parse(result) as GetConfigResponse, |
| 98 | (e) => ({ |
| 99 | type: 'parse-json' as const, |
| 100 | reason: 'Unable to parse JSON', |
| 101 | error: e as Error, |
| 102 | }), |
| 103 | ), |
| 104 | ), |
| 105 | E.chainW((response) => { |
| 106 | if (response.errors.length > 0) { |
| 107 | return E.left({ |
| 108 | type: 'validation-error' as const, |
| 109 | reason: '(get-config wasm)', |
| 110 | error: response.errors, |
| 111 | }) |
| 112 | } |
| 113 | return E.right(response.config) |
| 114 | }), |
| 115 | ) |
| 116 | |
| 117 | if (E.isRight(configEither)) { |
| 118 | debug('config data retrieved without errors in getConfig Wasm') |
| 119 | const { right: data } = configEither |
| 120 | |
| 121 | for (const generator of data.generators) { |
| 122 | await resolveBinaryTargets(generator) |
| 123 | } |
| 124 | |
| 125 | return Promise.resolve(data) |
| 126 | } |
| 127 | |
| 128 | /** |
no test coverage detected