(
schemaFile: string,
opts: { returnServices?: boolean; mergeImports?: boolean } = {},
)
| 57 | opts: { returnServices: true; mergeImports?: boolean }, |
| 58 | ): Promise<{ model: Model; services: ZModelServices }>; |
| 59 | export async function loadSchemaDocument( |
| 60 | schemaFile: string, |
| 61 | opts: { returnServices?: boolean; mergeImports?: boolean } = {}, |
| 62 | ) { |
| 63 | const returnServices = opts.returnServices ?? false; |
| 64 | const mergeImports = opts.mergeImports ?? true; |
| 65 | |
| 66 | const loadResult = await loadDocument(schemaFile, [], mergeImports); |
| 67 | if (!loadResult.success) { |
| 68 | loadResult.errors.forEach((err) => { |
| 69 | console.error(colors.red(err)); |
| 70 | }); |
| 71 | throw new CliError('Schema contains errors. See above for details.'); |
| 72 | } |
| 73 | loadResult.warnings.forEach((warn) => { |
| 74 | console.warn(colors.yellow(warn)); |
| 75 | }); |
| 76 | |
| 77 | if (returnServices) return { model: loadResult.model, services: loadResult.services }; |
| 78 | |
| 79 | return loadResult.model; |
| 80 | } |
| 81 | |
| 82 | export function handleSubProcessError(err: unknown) { |
| 83 | if (err instanceof Error && 'status' in err && typeof err.status === 'number') { |
no test coverage detected