import * as t from "io-ts" import { Schema, Instance } from "@underlay/apg" import apg from "@underlay/apg-codec-apg" export type Schemas = Record export type Instances = Record export type Paths = Record export type Codec = t.Type //https://github.com/sindresorhus/type-fest/ export type JsonObject = { [Key in string]: JsonValue } export interface JsonArray extends Array {} export type JsonValue = | string | number | boolean | null | JsonObject | JsonArray export interface Block< State extends JsonObject, Inputs extends Schemas, Outputs extends Schemas > { name: string state: t.Type inputs: { [i in keyof Inputs]: Codec } outputs: { [o in keyof Outputs]: Codec } initialValue: State validate: Validate backgroundColor?: string } export const schema: Codec = new t.Type< Schema.Schema, Schema.Schema, Schema.Schema >("schema", apg.is, t.success, t.identity) export type Validate< State extends JsonObject, Inputs extends Schemas, Outputs extends Schemas > = ( state: State, inputs: { [input in keyof Inputs]: { schema: Inputs[input] } } ) => Promise<{ [output in keyof Outputs]: { schema: Outputs[output] } }>