import { Layout } from "./layouts" ; import { IConstructorSpec , IContract , IContractMetadata , IContractSpec , IEventParamSpec , IEventSpec , IMessageParamSpec , IMessageSpec , ITypeSpec } from "./specs" ; import { Type } from "./types" ; import { ISource } from "./specs" ; export const METADATA_VERSION = "0.1.0" ; export interface ToMetadata { toMetadata ( ) : unknown ; } /**
 * The main metadata
 */ export class ContractMetadata implements ToMetadata { public readonly metadataVersion : string = METADATA_VERSION ; constructor ( public readonly source , public readonly contract , public readonly spec , public readonly types , public readonly storage ) { } toMetadata ( ) { return { metadataVersion : this . metadataVersion , source : this . source , contract : this . contract . toMetadata ( ) , spec : this . spec . toMetadata ( ) , types : this . types . map ( ( t ) => t . toMetadata ( ) ) , storage : this . storage . toMetadata ( ) , } ; } } export class Source implements ToMetadata { constructor ( public readonly hash , public readonly language , public readonly compiler ) { } toMetadata ( ) { return { hash : this . hash , language : this . language , compiler : this . compiler , } ; } } export class Contract implements ToMetadata { private authors : Array < string > = [ ] ; private description : string | null = null ; private documentation : string | null = null ; private repository : string | null = null ; private homepage : string | null = null ; private license : string | null = null ; constructor ( private name , private version ) { } setAuthors ( authors ) { this . authors = authors ; return this ; } setDescription ( description ) { this . description = description ; return this ; } setDocumentation ( documentation ) { this . documentation = documentation ; return this ; } setRepository ( repository ) { this . repository = repository ; return this ; } setHomepage ( homepage ) { this . homepage = homepage ; return this ; } setLicense ( license ) { this . license = license ; return this ; } toMetadata ( ) { return { name : this . name , version : this . version , authors : this . authors , description : this . description , documentation : this . documentation , repository : this . repository , homepage : this . homepage , license : this . license , } ; } } export class ContractSpec implements ToMetadata { constructor ( public readonly constructors , public readonly messages , public readonly events , public readonly docs ) { } toMetadata ( ) { return { constructors : this . constructors . map ( ( c ) => c . toMetadata ( ) ) , messages : this . messages . map ( ( m ) => m . toMetadata ( ) ) , events : this . events . map ( ( e ) => e . toMetadata ( ) ) , docs : this . docs , } ; } } export class ConstructorSpec implements ToMetadata { constructor ( public readonly name , public readonly selector , public readonly args = [ ] , public readonly docs = [ ] ) { } toMetadata ( ) { return { args : this . args . map ( ( arg ) => arg . toMetadata ( ) ) , docs : this . docs , name : this . name , selector : this . selector , } ; } } export class MessageSpec implements ToMetadata { private mutates = false ; private payable = false ; constructor ( public readonly name , public readonly selector , public readonly args = [ ] , public readonly returnType , public readonly docs = [ ] ) { } setMutates ( mutates = true ) { this . mutates = mutates ; return this ; } setPayable ( payable = true ) { this . payable = payable ; return this ; } toMetadata ( ) { return { mutates : this . mutates , payable : this . payable , args : this . args . map ( ( arg ) => arg . toMetadata ( ) ) , returnType : this . returnType ?. toMetadata ( ) || null , docs : this . docs , name : this . name , selector : this . selector , } ; } } export class EventSpec implements ToMetadata { constructor ( public readonly name , public readonly args , public readonly docs ) { } toMetadata ( ) { return { name : this . name , args : this . args . map ( ( arg ) => arg . toMetadata ( ) ) , docs : this . docs , } ; } } export class EventParamSpec implements ToMetadata { constructor ( public readonly indexed , public readonly type , public readonly docs , public readonly name ) { } toMetadata ( ) { return this ; } } export class ArgumentSpec implements ToMetadata { constructor ( public readonly type , public readonly name ) { } toMetadata ( ) { return { type : this . type . toMetadata ( ) , name : this . name } ; } } export class TypeSpec implements ToMetadata { constructor ( public readonly type , public readonly displayName ) { } toMetadata ( ) { return { type : this . type , displayName : [ this . displayName ] } ; } }