import Ajv from 'ajv' ; import * as apiTypes from './api-types' ; const SCHEMA = { "$schema" : "http://json-schema.org/draft-07/schema#" , "definitions" : { "CreateRequestQuery" : { "type" : "object" , "properties" : { "token" : { "type" : "string" } } , "required" : [ "token" ] , "additionalProperties" : false } , "CreateRequestBody" : { "type" : "object" , "properties" : { "budget" : { "type" : "number" } } , "required" : [ "budget" ] , "additionalProperties" : false } , "AddRequestQuery" : { "type" : "object" , "properties" : { "token" : { "type" : "string" } , "spreadsheetId" : { "type" : "string" } } , "required" : [ "token" , "spreadsheetId" ] , "additionalProperties" : false } , "AddRequestBody" : { "type" : "object" , "additionalProperties" : false , "properties" : { "isoDate" : { "type" : "string" } , "currency" : { "type" : "string" } , "to" : { "type" : "string" } , "amount" : { "type" : "number" } , "url" : { "type" : "string" } , "memo" : { "type" : "string" } , "meta" : { "type" : "object" , "properties" : { "id" : { "type" : "string" } , "type" : { "type" : "string" , "enum" : [ "checking" , "checked" ] } } , "required" : [ "id" , "type" ] , "additionalProperties" : false } } , "required" : [ "amount" , "currency" , "isoDate" , "memo" , "meta" , "to" , "url" ] } , "AddResponseBody" : { "type" : "object" , "properties" : { "ok" : { "type" : "boolean" , "const" : true } } , "required" : [ "ok" ] , "additionalProperties" : false } , "GetRequestQuery" : { "type" : "object" , "properties" : { "token" : { "type" : "string" } , "spreadsheetId" : { "type" : "string" } } , "required" : [ "token" , "spreadsheetId" ] , "additionalProperties" : false } , "SpreadSheetItem" : { "type" : "object" , "properties" : { "id" : { "type" : "string" } , "date" : { "type" : "string" } , "to" : { "type" : "string" } , "amount" : { "type" : "object" , "properties" : { "number" : { "type" : "number" } , "value" : { "type" : "string" } , "raw" : { "type" : "number" } , "inputCurrency" : { "type" : "string" } , "outputCurrency" : { "type" : "string" } } , "required" : [ "number" , "value" , "raw" , "inputCurrency" , "outputCurrency" ] , "additionalProperties" : false } , "url" : { "type" : "string" } , "memo" : { "type" : "string" } , "meta" : { "type" : "object" , "properties" : { "type" : { "type" : "string" , "enum" : [ "checking" , "checked" ] } } , "required" : [ "type" ] , "additionalProperties" : false } } , "required" : [ "id" , "date" , "to" , "amount" , "url" , "memo" , "meta" ] , "additionalProperties" : false } , "SpreadSheetStats" : { "type" : "object" , "properties" : { "budget" : { "type" : "object" , "properties" : { "raw" : { "type" : "number" } , "value" : { "type" : "string" } } , "required" : [ "raw" , "value" ] , "additionalProperties" : false } , "used" : { "type" : "object" , "properties" : { "raw" : { "type" : "number" } , "value" : { "type" : "string" } } , "required" : [ "raw" , "value" ] , "additionalProperties" : false } , "balance" : { "type" : "object" , "properties" : { "raw" : { "type" : "number" } , "value" : { "type" : "string" } } , "required" : [ "raw" , "value" ] , "additionalProperties" : false } } , "required" : [ "budget" , "used" , "balance" ] , "additionalProperties" : false } , "GetResponseBody" : { "type" : "array" , "items" : { "type" : "object" , "properties" : { "year" : { "type" : "string" } , "README" : { "type" : "string" } , "stats" : { "$ref" : "#/definitions/SpreadSheetStats" } , "items" : { "type" : "array" , "items" : { "$ref" : "#/definitions/SpreadSheetItem" } } } , "required" : [ "year" , "README" , "stats" , "items" ] , "additionalProperties" : false } } } } ; const ajv = new Ajv ( { removeAdditional : true } ) . addSchema ( SCHEMA , "SCHEMA" ) ; export function validateCreateRequestQuery ( payload ) { if ( ! isCreateRequestQuery ( payload ) ) { const error = new Error ( 'invalid payload: CreateRequestQuery' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isCreateRequestQuery ( payload ) { /** Schema is defined in  SCHEMA . definitions . CreateRequestQuery * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/CreateRequestQuery" } ) ; return ajvValidate ( payload ) ; } export function validateCreateRequestBody ( payload ) { if ( ! isCreateRequestBody ( payload ) ) { const error = new Error ( 'invalid payload: CreateRequestBody' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isCreateRequestBody ( payload ) { /** Schema is defined in  SCHEMA . definitions . CreateRequestBody * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/CreateRequestBody" } ) ; return ajvValidate ( payload ) ; } export function validateAddRequestQuery ( payload ) { if ( ! isAddRequestQuery ( payload ) ) { const error = new Error ( 'invalid payload: AddRequestQuery' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isAddRequestQuery ( payload ) { /** Schema is defined in  SCHEMA . definitions . AddRequestQuery * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/AddRequestQuery" } ) ; return ajvValidate ( payload ) ; } export function validateAddRequestBody ( payload ) { if ( ! isAddRequestBody ( payload ) ) { const error = new Error ( 'invalid payload: AddRequestBody' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isAddRequestBody ( payload ) { /** Schema is defined in  SCHEMA . definitions . AddRequestBody * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/AddRequestBody" } ) ; return ajvValidate ( payload ) ; } export function validateAddResponseBody ( payload ) { if ( ! isAddResponseBody ( payload ) ) { const error = new Error ( 'invalid payload: AddResponseBody' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isAddResponseBody ( payload ) { /** Schema is defined in  SCHEMA . definitions . AddResponseBody * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/AddResponseBody" } ) ; return ajvValidate ( payload ) ; } export function validateGetRequestQuery ( payload ) { if ( ! isGetRequestQuery ( payload ) ) { const error = new Error ( 'invalid payload: GetRequestQuery' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isGetRequestQuery ( payload ) { /** Schema is defined in  SCHEMA . definitions . GetRequestQuery * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/GetRequestQuery" } ) ; return ajvValidate ( payload ) ; } export function validateSpreadSheetItem ( payload ) { if ( ! isSpreadSheetItem ( payload ) ) { const error = new Error ( 'invalid payload: SpreadSheetItem' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isSpreadSheetItem ( payload ) { /** Schema is defined in  SCHEMA . definitions . SpreadSheetItem * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/SpreadSheetItem" } ) ; return ajvValidate ( payload ) ; } export function validateSpreadSheetStats ( payload ) { if ( ! isSpreadSheetStats ( payload ) ) { const error = new Error ( 'invalid payload: SpreadSheetStats' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isSpreadSheetStats ( payload ) { /** Schema is defined in  SCHEMA . definitions . SpreadSheetStats * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/SpreadSheetStats" } ) ; return ajvValidate ( payload ) ; } export function validateGetResponseBody ( payload ) { if ( ! isGetResponseBody ( payload ) ) { const error = new Error ( 'invalid payload: GetResponseBody' ) ; error . name = "ValidationError" ; throw error ; } return payload ; } export function isGetResponseBody ( payload ) { /** Schema is defined in  SCHEMA . definitions . GetResponseBody * const ajvValidate = ajv . compile ( { "$ref" : "SCHEMA#/definitions/GetResponseBody" } ) ; return ajvValidate ( payload ) ; }