chore: switch to .toml files network conf - add zod scheme parsing

This commit is contained in:
maciek
2023-03-13 10:27:40 +01:00
parent f4d83dad27
commit 9ee85296dc
2 changed files with 15 additions and 2 deletions
+11 -2
View File
@@ -14,7 +14,10 @@ import type { Environment } from '../types';
import { Networks } from '../types';
import { compileErrors } from '../utils/compile-errors';
import { envSchema } from '../utils/validate-environment';
import { configSchema } from '../utils/validate-configuration';
import {
configSchema,
tomlConfigSchema,
} from '../utils/validate-configuration';
type Client = ReturnType<typeof createClient>;
type ClientCollection = {
@@ -164,7 +167,13 @@ const fetchConfig = async (url?: string) => {
if (url.match(/github(.+)\.toml$/)) {
const content = await res.text();
const parsed = tomlParse(content);
cfg = { hosts: parsed.API.GraphQL.Hosts };
const tomlResults = tomlConfigSchema.parse(parsed);
const {
API: {
GraphQL: { Hosts: hosts },
},
} = tomlResults;
cfg = { hosts };
} else {
cfg = await res.json();
}
@@ -3,3 +3,7 @@ import z from 'zod';
export const configSchema = z.object({
hosts: z.array(z.string()),
});
export const tomlConfigSchema = z.object({
API: z.object({ GraphQL: z.object({ Hosts: z.array(z.string()) }) }),
});