From 43bf6293ce24e7ad9d93c5fb6b4d3c1ea54ac029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Tesa=C5=99?= Date: Mon, 4 Dec 2023 14:33:26 +0100 Subject: [PATCH] Re-order exports --- .../airnode-feed/src/validation/schema.ts | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/packages/airnode-feed/src/validation/schema.ts b/packages/airnode-feed/src/validation/schema.ts index 8fbac0ad..c61a7ea2 100644 --- a/packages/airnode-feed/src/validation/schema.ts +++ b/packages/airnode-feed/src/validation/schema.ts @@ -15,17 +15,27 @@ import { z, type SuperRefinement } from 'zod'; import packageJson from '../../package.json'; +export type Config = z.infer; +export type Address = z.infer; +export type BeaconId = z.infer; +export type TemplateId = z.infer; +export type EndpointId = z.infer; + export const parameterSchema = z.strictObject({ name: z.string(), type: z.string(), value: z.string(), }); +export type Parameter = z.infer; + export const templateSchema = z.strictObject({ endpointId: config.evmIdSchema, parameters: z.array(parameterSchema), }); +export type Template = z.infer; + export const templatesSchema = z.record(config.evmIdSchema, templateSchema).superRefine((templates, ctx) => { for (const [templateId, template] of Object.entries(templates)) { // Verify that config.templates. is valid by deriving the hash of the endpointId and parameters @@ -53,11 +63,15 @@ export const templatesSchema = z.record(config.evmIdSchema, templateSchema).supe } }); +export type Templates = z.infer; + export const endpointSchema = z.strictObject({ oisTitle: z.string(), endpointName: z.string(), }); +export type Endpoint = z.infer; + export const endpointsSchema = z.record(endpointSchema).superRefine((endpoints, ctx) => { for (const [endpointId, endpoint] of Object.entries(endpoints)) { // Verify that config.endpoints. is valid @@ -77,6 +91,8 @@ export const endpointsSchema = z.record(endpointSchema).superRefine((endpoints, } }); +export type Endpoints = z.infer; + export const baseBeaconUpdateSchema = z.strictObject({ deviationThreshold: z.number(), heartbeatInterval: z.number().int(), @@ -88,6 +104,8 @@ export const beaconUpdateSchema = z }) .merge(baseBeaconUpdateSchema); +export type BeaconUpdate = z.infer; + export const signedApiUpdateSchema = z.strictObject({ signedApiName: z.string(), templateIds: z.array(config.evmIdSchema), @@ -95,10 +113,14 @@ export const signedApiUpdateSchema = z.strictObject({ updateDelay: z.number(), }); +export type SignedApiUpdate = z.infer; + export const triggersSchema = z.strictObject({ signedApiUpdates: z.array(signedApiUpdateSchema).nonempty(), }); +export type Triggers = z.infer; + const validateTemplatesReferences: SuperRefinement<{ templates: Templates; endpoints: Endpoints }> = (config, ctx) => { for (const [templateId, template] of Object.entries(config.templates)) { const endpoint = config.endpoints[template.endpointId]; @@ -223,6 +245,8 @@ export const oisesSchema = z.array(oisSchema); export const apisCredentialsSchema = z.array(config.apiCredentialsSchema); +export type ApisCredentials = z.infer; + export const nodeSettingsSchema = z.strictObject({ nodeVersion: z.string().refine((version) => version === packageJson.version, 'Invalid node version'), airnodeWalletMnemonic: z.string().refine((mnemonic) => ethers.utils.isValidMnemonic(mnemonic), 'Invalid mnemonic'), @@ -251,38 +275,28 @@ export const configSchema = z .superRefine(validateTriggerReferences); export const encodedValueSchema = z.string().regex(/^0x[\dA-Fa-f]{64}$/); + export const signatureSchema = z.string().regex(/^0x[\dA-Fa-f]{130}$/); + export const signedDataSchema = z.strictObject({ timestamp: z.string(), encodedValue: encodedValueSchema, signature: signatureSchema, }); +export type SignedData = z.infer; + export const signedApiPayloadSchema = signedDataSchema.extend({ beaconId: config.evmIdSchema, airnode: config.evmAddressSchema, templateId: config.evmIdSchema, }); +export type SignedApiPayload = z.infer; + export const signedApiBatchPayloadSchema = z.array(signedApiPayloadSchema); -export type SignedApiPayload = z.infer; export type SignedApiBatchPayload = z.infer; -export type Config = z.infer; -export type Template = z.infer; -export type Templates = z.infer; -export type BeaconUpdate = z.infer; -export type SignedApiUpdate = z.infer; -export type Triggers = z.infer; -export type Address = z.infer; -export type BeaconId = z.infer; -export type TemplateId = z.infer; -export type EndpointId = z.infer; -export type SignedData = z.infer; -export type Endpoint = z.infer; -export type Endpoints = z.infer; -export type ApisCredentials = z.infer; -export type Parameter = z.infer; export const secretsSchema = z.record(z.string());