diff --git a/.changeset/light-singers-tap.md b/.changeset/light-singers-tap.md new file mode 100644 index 0000000000..7e263dc78b --- /dev/null +++ b/.changeset/light-singers-tap.md @@ -0,0 +1,5 @@ +--- +'@moralisweb3/common-aptos-utils': patch +--- + +The `AptosAddress` class normalizes an address to full length. By this is easier to compare two addresses. diff --git a/.changeset/strong-suits-watch.md b/.changeset/strong-suits-watch.md new file mode 100644 index 0000000000..868df35fd7 --- /dev/null +++ b/.changeset/strong-suits-watch.md @@ -0,0 +1,5 @@ +--- +'@moralisweb3/aptos-api': minor +--- + +Released the SDK for the Aptos API. diff --git a/packages/apiGenerator/README.md b/packages/apiGenerator/README.md new file mode 100644 index 0000000000..0a9b23a76f --- /dev/null +++ b/packages/apiGenerator/README.md @@ -0,0 +1,24 @@ +# API Generator + +This package provides a generator that can be used to generate a strong typed client based on a OpenAPI specification. + +Supported versions of the OpenAPI specification: +* 3.0.x + +Supported languages: +* TypeScript + +## How to Run? + +You need to call the generator by `ts-node` and provide the path to the folder with the configuration file. The configuration file is called `generator.config.json`. + +``` +ts-node src/index.ts ../../common/aptosUtils +``` + +## Architecture + +The generator is split into two parts: + +* The OpenAPI reader - it's responsible for reading the OpenAPI specification and creating normalized data structures that can be used by the generator. That data structure is called a contract. This architecture allows us to support multiple versions of the OpenAPI specification. Additionally, the data structure of the contract is designed for easy generating the object-oriented structure. +* The generator - it's responsible for generating the code based on the contract data structure. diff --git a/packages/apiGenerator/jest.config.js b/packages/apiGenerator/jest.config.js new file mode 100644 index 0000000000..67ac7a2396 --- /dev/null +++ b/packages/apiGenerator/jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + preset: 'ts-jest/presets/default', + testMatch: ['**/?(*.)+(spec|test).ts?(x)'], + transform: { + '^.+\\.(ts|js)x?$': 'ts-jest', + }, + transformIgnorePatterns: ['^.+\\.js$'], +}; diff --git a/packages/apiGenerator/package.json b/packages/apiGenerator/package.json new file mode 100644 index 0000000000..f0c349459e --- /dev/null +++ b/packages/apiGenerator/package.json @@ -0,0 +1,18 @@ +{ + "name": "@moralisweb3/api-generator", + "private": true, + "scripts": { + "gen:aptos": "ts-node src/index.ts ../../common/aptosUtils", + "gen:playground": "ts-node src/index.ts ../playground", + "test": "jest", + "test:watch": "jest --watch" + }, + "devDependencies": { + "@types/jest": "^29.2.6", + "axios": "^1.2.2", + "jest": "29.3.1", + "openapi-types": "^12.1.0", + "ts-node": "^10.9.1", + "typescript": "^4.9.4" + } +} diff --git a/packages/apiGenerator/playground/.gitignore b/packages/apiGenerator/playground/.gitignore new file mode 100644 index 0000000000..9ab870da89 --- /dev/null +++ b/packages/apiGenerator/playground/.gitignore @@ -0,0 +1 @@ +generated/ diff --git a/packages/apiGenerator/playground/generator.config.json b/packages/apiGenerator/playground/generator.config.json new file mode 100644 index 0000000000..2cbbed1e81 --- /dev/null +++ b/packages/apiGenerator/playground/generator.config.json @@ -0,0 +1,22 @@ +{ + "url": "https://deep-index.moralis.io/api-docs-2.1/v2.1/swagger.json", + "generator": { + "outputDir": "generated", + "classNamePrefix": "Ply", + "mappings": { + "types": [], + "refs": [], + "complexTypeProperties": [], + "operationParameters": [] + }, + "typeDeterminants": [] + }, + "openApiReader": { + "v3": { + "operations": { + "groupRef": "#/x-tag-sdk", + "isEnabledRef": "#/x-tag-sdk" + } + } + } +} diff --git a/packages/apiGenerator/src/configuration/Configuration.ts b/packages/apiGenerator/src/configuration/Configuration.ts new file mode 100644 index 0000000000..7243c2ec00 --- /dev/null +++ b/packages/apiGenerator/src/configuration/Configuration.ts @@ -0,0 +1,8 @@ +import { OpenApiReaderConfiguration } from 'src/reader/OpenApiReaderConfiguration'; +import { GeneratorConfiguration } from '../generator/GeneratorConfiguration'; + +export interface Configuration { + url: string; + generator: GeneratorConfiguration; + openApiReader: OpenApiReaderConfiguration; +} diff --git a/packages/apiGenerator/src/configuration/ConfigurationReader.ts b/packages/apiGenerator/src/configuration/ConfigurationReader.ts new file mode 100644 index 0000000000..5c14de8685 --- /dev/null +++ b/packages/apiGenerator/src/configuration/ConfigurationReader.ts @@ -0,0 +1,14 @@ +import path from 'path'; +import fs from 'fs'; +import { Configuration } from './Configuration'; + +export class ConfigurationReader { + public static read(projectPath: string): Configuration { + const jsonPath = path.join(projectPath, 'generator.config.json'); + if (!fs.existsSync(jsonPath)) { + throw new Error(`Cannot open ${jsonPath} file`); + } + const jsonRaw = fs.readFileSync(jsonPath, 'utf-8'); + return JSON.parse(jsonRaw) as Configuration; + } +} diff --git a/packages/apiGenerator/src/generator/Generator.ts b/packages/apiGenerator/src/generator/Generator.ts new file mode 100644 index 0000000000..317e70497b --- /dev/null +++ b/packages/apiGenerator/src/generator/Generator.ts @@ -0,0 +1,109 @@ +import { IndexFileGenerator } from './fileGenerators/IndexFileGenerator'; +import { OperationFileGenerator } from './fileGenerators/OperationFileGenerator'; +import { SimpleTypeFileGenerator } from './fileGenerators/SimpleTypeFileGenerator'; +import { ComplexTypeFileGenerator } from './fileGenerators/ComplexTypeFileGenerator'; +import { GeneratorWriter } from './GeneratorWriter'; +import { + ComplexTypeInfo, + OpenApiContract, + OperationInfo, + SimpleTypeInfo, + UnionTypeInfo, +} from '../reader/OpenApiContract'; +import { TypeResolver } from './fileGenerators/resolvers/TypeResolver'; +import { AbstractClientFileGenerator } from './fileGenerators/AbstractClientFileGenerator'; +import { MappingResolver } from './fileGenerators/resolvers/MappingResolver'; +import { UnionTypeFileGenerator } from './fileGenerators/UnionTypeFileGenerator'; +import { GeneratorConfiguration } from './GeneratorConfiguration'; +import { TypeDeterminantResolver } from './fileGenerators/resolvers/TypeDeterminantResolver'; +import { TypeInfoResolver } from './fileGenerators/resolvers/TypeInfoResolver'; + +export class Generator { + public static create( + contract: OpenApiContract, + configuration: GeneratorConfiguration, + projectPath: string, + ): Generator { + const mappingResolver = new MappingResolver(configuration.mappings); + const typeInfoResolver = new TypeInfoResolver(contract); + const typeResolver = new TypeResolver(configuration.classNamePrefix, mappingResolver, typeInfoResolver); + const typeDeterminantResolver = new TypeDeterminantResolver(configuration.typeDeterminants); + const generatorWriter = new GeneratorWriter(projectPath, configuration.outputDir); + return new Generator(contract, typeResolver, typeDeterminantResolver, typeInfoResolver, generatorWriter); + } + + private readonly typesIndexGenerator = new IndexFileGenerator(); + private readonly operationsIndexGenerator = new IndexFileGenerator(); + + private constructor( + private readonly contract: OpenApiContract, + private readonly typeResolver: TypeResolver, + private readonly typeDeterminantResolver: TypeDeterminantResolver, + private readonly typeInfoResolver: TypeInfoResolver, + private readonly writer: GeneratorWriter, + ) {} + + public generate() { + this.writer.prepare(); + + for (const operation of this.contract.operations) { + this.generateOperation(operation); + } + for (const simpleType of this.contract.simpleTypes) { + this.generateSimpleType(simpleType); + } + for (const complexType of this.contract.complexTypes) { + this.generateComplexType(complexType); + } + for (const unionType of this.contract.unionTypes) { + this.generateUnionType(unionType); + } + + const abstractClientFileGenerator = new AbstractClientFileGenerator(this.contract.operations, this.typeResolver); + this.writer.writeAbstractClient(abstractClientFileGenerator.generate()); + + this.writer.writeTypesIndex(this.typesIndexGenerator.generate()); + this.writer.writeOperationsIndex(this.operationsIndexGenerator.generate()); + } + + private generateOperation(info: OperationInfo) { + const generator = new OperationFileGenerator(info, this.typeResolver); + const result = generator.generate(); + + this.writer.writeOperation(result.className, result.output); + + this.operationsIndexGenerator.add(result.className); + } + + private generateSimpleType(info: SimpleTypeInfo) { + const generator = new SimpleTypeFileGenerator(info, this.typeResolver); + const result = generator.generate(); + + this.writer.writeType(result.className, result.output); + + this.typesIndexGenerator.add(result.className); + } + + private generateComplexType(info: ComplexTypeInfo) { + const generator = new ComplexTypeFileGenerator( + info, + this.typeResolver, + this.typeDeterminantResolver, + this.typeInfoResolver, + ); + const result = generator.generate(); + + this.writer.writeType(result.className, result.output); + + this.typesIndexGenerator.add(result.className); + } + + private generateUnionType(info: UnionTypeInfo) { + const generator = new UnionTypeFileGenerator(info, this.typeResolver); + const result = generator.generate(); + + this.writer.writeType(result.className, result.output); + + this.typesIndexGenerator.add(result.className); + } +} diff --git a/packages/apiGenerator/src/generator/GeneratorConfiguration.ts b/packages/apiGenerator/src/generator/GeneratorConfiguration.ts new file mode 100644 index 0000000000..a2b05786df --- /dev/null +++ b/packages/apiGenerator/src/generator/GeneratorConfiguration.ts @@ -0,0 +1,40 @@ +export interface GeneratorConfiguration { + outputDir: string; + classNamePrefix: string; + mappings: Mappings; + typeDeterminants: TypeDeterminant[]; +} + +export interface Mappings { + types: TypeMapping[]; + refs: RefMapping[]; + complexTypeProperties: ComplexTypePropertyMapping[]; + operationParameters: OperationParameterMapping[]; +} + +export interface MappingTarget { + className?: string; + import?: string; +} + +export interface TypeMapping extends MappingTarget { + typeName: string; +} + +export interface RefMapping extends MappingTarget { + $ref: string; +} + +export interface ComplexTypePropertyMapping extends MappingTarget { + names: string[]; +} + +export interface OperationParameterMapping extends MappingTarget { + names: string[]; +} + +export interface TypeDeterminant { + typeName: string; + isInputCode: string; + isJSONCode: string; +} diff --git a/packages/apiGenerator/src/generator/GeneratorWriter.ts b/packages/apiGenerator/src/generator/GeneratorWriter.ts new file mode 100644 index 0000000000..ca07ddf311 --- /dev/null +++ b/packages/apiGenerator/src/generator/GeneratorWriter.ts @@ -0,0 +1,57 @@ +import path from 'path'; +import fs from 'fs'; +import { Output } from './output/Output'; + +export class GeneratorWriter { + private readonly outputPath: string; + private readonly typesPath: string; + private readonly operationsPath: string; + private readonly clientPath: string; + + public constructor(projectPath: string, outputDir: string) { + this.outputPath = path.join(projectPath, outputDir); + this.typesPath = path.join(this.outputPath, 'types'); + this.operationsPath = path.join(this.outputPath, 'operations'); + this.clientPath = path.join(this.outputPath, 'client'); + } + + private prepareDir(path: string) { + fs.mkdirSync(path, { + recursive: true, + }); + fs.readdirSync(path).forEach((fileName) => { + fs.rmSync(`${path}/${fileName}`); + }); + } + + public prepare() { + this.prepareDir(this.typesPath); + this.prepareDir(this.operationsPath); + this.prepareDir(this.clientPath); + } + + public writeOperation(className: string, output: Output) { + this.writeFile(this.operationsPath, className + '.ts', output); + } + + public writeOperationsIndex(output: Output) { + this.writeFile(this.operationsPath, 'index.ts', output); + } + + public writeType(className: string, output: Output) { + this.writeFile(this.typesPath, className + '.ts', output); + } + + public writeTypesIndex(output: Output) { + this.writeFile(this.typesPath, 'index.ts', output); + } + + public writeAbstractClient(output: Output) { + this.writeFile(this.clientPath, 'abstractClient.ts', output); + } + + private writeFile(basePath: string, fileName: string, output: Output) { + const finalPath = path.join(basePath, fileName); + fs.writeFileSync(finalPath, output.toString(), 'utf-8'); + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/AbstractClientFileGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/AbstractClientFileGenerator.ts new file mode 100644 index 0000000000..12b3f9d343 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/AbstractClientFileGenerator.ts @@ -0,0 +1,136 @@ +import { OperationInfo } from '../../reader/OpenApiContract'; +import { NameFormatter } from './codeGenerators/NameFormatter'; +import { TypeName } from '../../reader/utils/TypeName'; +import { TypeResolver } from './resolvers/TypeResolver'; +import { TypeCodesGenerator } from './codeGenerators/TypeCodesGenerator'; +import { TypeScriptOutput } from '../output/TypeScriptOutput'; +import { Output } from '../output/Output'; + +export class AbstractClientFileGenerator { + public constructor(private readonly operations: OperationInfo[], private readonly typeResolver: TypeResolver) {} + + public generate(): Output { + const output = new TypeScriptOutput(); + + const groupNames = [...new Set(this.operations.map((o) => o.groupName))]; + groupNames.sort(); + + const operations = this.operations.map((operation) => { + const className = NameFormatter.getClassName(operation.operationId) + 'Operation'; + + const resolvedResponseType = operation.response ? this.typeResolver.resolve(operation.response.descriptor) : null; + const responseTypeCodes = resolvedResponseType + ? TypeCodesGenerator.generate(resolvedResponseType, true) + : TypeCodesGenerator.generateNull(); + + const resolvedBodyType = operation.body ? this.typeResolver.resolve(operation.body.descriptor) : null; + const bodyTypeCodes = + resolvedBodyType && operation.body + ? TypeCodesGenerator.generate(resolvedBodyType, operation.body.isRequired) + : null; + + const parameterName = NameFormatter.getParameterName( + NameFormatter.getClassName(TypeName.from(operation.operationId)), + ); + + return { + groupName: operation.groupName, + className, + responseTypeCodes, + bodyTypeCodes, + parameterName, + }; + }); + + const groups = groupNames.map((name) => { + const safeName = NameFormatter.getParameterName(name); + const groupOperations = operations.filter((o) => o.groupName === name); + return { + safeName: safeName, + operations: groupOperations, + }; + }); + + // view: + + for (const operation of operations) { + output.addImport( + [operation.className, `${operation.className}Request`, `${operation.className}RequestJSON`], + `../operations/${operation.className}`, + ); + if (operation.responseTypeCodes.referenceType) { + output.addImport( + [ + operation.responseTypeCodes.referenceType.valueClassName, + operation.responseTypeCodes.referenceType.jsonClassName, + ], + operation.responseTypeCodes.referenceType.importPath, + ); + } + if (operation.bodyTypeCodes?.referenceType) { + output.addImport( + [ + operation.bodyTypeCodes.referenceType.valueClassName, + operation.bodyTypeCodes.referenceType.inputClassName, + operation.bodyTypeCodes.referenceType.jsonClassName, + ], + operation.bodyTypeCodes.referenceType.importPath, + ); + } + } + output.commitImports(); + + output.write(0, `export interface OperationV3 {`); + output.write(1, `operationId: string;`); + output.write(1, `groupName: string;`); + output.write(1, `httpMethod: string;`); + output.write(1, `routePattern: string;`); + output.write(1, `parameterNames: string[];`); + output.write(1, `hasResponse: boolean;`); + output.write(1, `hasBody: boolean;`); + output.write(1, `serializeRequest?: (request: Request) => RequestJSON;`); + output.write(1, `parseResponse?: (json: ResponseJSON) => Response;`); + output.write(1, `serializeBody?: (body: Body) => BodyJSON;`); + output.write(0, `}`); + output.newLine(); + + output.write(0, `export abstract class AbstractClient {`); + + output.write(1, `protected abstract createEndpoint(`); + output.write(2, `operation: OperationV3`); + output.write(1, `): (request: Request) => Promise;`); + + output.write( + 1, + 'protected abstract createEndpointWithBody(', + ); + output.write(2, `operation: OperationV3`); + output.write(1, `): (request: Request, body: Body) => Promise;`); + + output.newLine(); + + for (const group of groups) { + output.write(1, `public readonly ${group.safeName} = {`); + for (const operation of group.operations) { + const factoryMethodName = operation.bodyTypeCodes ? 'createEndpointWithBody' : 'createEndpoint'; + output.write(2, `${operation.parameterName}: this.${factoryMethodName}<`); + output.write(3, `${operation.className}Request`); + output.write(3, `, ${operation.className}RequestJSON`); + output.write(3, `, ${operation.responseTypeCodes.valueTypeCode}`); + output.write(3, `, ${operation.responseTypeCodes.jsonTypeCode}`); + if (operation.bodyTypeCodes) { + output.write( + 3, + `, ${operation.bodyTypeCodes.inputOrValueTypeCode}${operation.bodyTypeCodes.undefinedSuffix}`, + ); + output.write(3, `, ${operation.bodyTypeCodes.jsonTypeCode}${operation.bodyTypeCodes.undefinedSuffix}`); + } + output.write(2, `>(${operation.className}),`); + } + output.write(1, '};'); + } + + output.write(0, '}'); + return output; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/ComplexTypeFileGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/ComplexTypeFileGenerator.ts new file mode 100644 index 0000000000..1e72a81531 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/ComplexTypeFileGenerator.ts @@ -0,0 +1,198 @@ +import { ComplexTypeInfo } from 'src/reader/OpenApiContract'; +import { Output } from '../output/Output'; +import { ValueMappingCodeGenerator } from './codeGenerators/ValueMappingCodeGenerator'; +import { TypeCodesGenerator } from './codeGenerators/TypeCodesGenerator'; +import { TypeScriptOutput } from '../output/TypeScriptOutput'; +import { PropertyNameCodeGenerator } from './codeGenerators/PropertyNameCodeGenerator'; +import { TypeDeterminantResolver } from './resolvers/TypeDeterminantResolver'; +import { TypeInfoResolver } from './resolvers/TypeInfoResolver'; +import { TypeResolver } from './resolvers/TypeResolver'; + +export interface TypeClassGeneratorResult { + className: string; + output: Output; +} + +export class ComplexTypeFileGenerator { + public constructor( + private readonly info: ComplexTypeInfo, + private readonly typeResolver: TypeResolver, + private readonly typeDeterminantResolver: TypeDeterminantResolver, + private readonly typeInfoResolver: TypeInfoResolver, + ) {} + + public generate(): TypeClassGeneratorResult { + if (this.info.descriptor.isArray) { + throw new Error(`Array complex type is not supported yet (${this.info.descriptor.ref})`); + } + + const resolvedType = this.typeResolver.resolveWithNoMapping(this.info.descriptor); + const typeCodes = TypeCodesGenerator.generate(resolvedType, true); + if (!typeCodes.referenceType) { + throw new Error('Invalid descriptor type'); + } + + const output = new TypeScriptOutput(); + + const properties = this.info.properties.map((property) => { + const resolvedPropertyType = this.typeResolver.resolveForComplexTypeProperty(property.descriptor, property.name); + const propertyNameCodes = PropertyNameCodeGenerator.generate(property.name); + return { + property, + propertyNameCodes, + typeCodes: TypeCodesGenerator.generate(resolvedPropertyType, property.isRequired), + json2TypeCode: ValueMappingCodeGenerator.generateJSON2TypeCode( + resolvedPropertyType, + `json${propertyNameCodes.accessCode}`, + property.isRequired, + ), + type2jsonCode: ValueMappingCodeGenerator.generateType2JSONCode( + resolvedPropertyType, + `this${propertyNameCodes.camelCasedAccessCode}`, + property.isRequired, + ), + input2typeCode: ValueMappingCodeGenerator.generateInput2TypeCode( + resolvedPropertyType, + `input${propertyNameCodes.camelCasedAccessCode}`, + property.isRequired, + ), + }; + }); + + const customTypeDeterminant = this.typeDeterminantResolver.tryResolve(this.info.descriptor.typeName); + const requiredInputFieldNames = properties + .filter((property) => property.property.isRequired) + .map((property) => property.propertyNameCodes.camelCasedNameCode); + const requiredJSONFieldNames = properties + .filter((property) => property.property.isRequired) + .map((property) => property.propertyNameCodes.nameCode); + + const isUsedByUnions = this.typeInfoResolver.isUsedByUnions(this.info.descriptor); + + // view: + + for (const p of properties) { + if (!p.typeCodes.referenceType) { + continue; + } + if (p.typeCodes.referenceType.factoryClassName === typeCodes.referenceType.factoryClassName) { + // Skips import to self type + continue; + } + output.addImport( + [ + p.typeCodes.referenceType.factoryClassName, + p.typeCodes.referenceType.valueClassName, + p.typeCodes.referenceType.inputClassName, + p.typeCodes.referenceType.jsonClassName, + ], + p.typeCodes.referenceType.importPath, + ); + } + output.commitImports(); + + output.write(0, `// $ref: ${this.info.descriptor.ref.toString()}`); + output.write(0, `// type: ${this.info.descriptor.typeName.toString()}`); + output.write(0, `// properties:`); + for (const p of properties) { + output.write(0, `// - ${p.property.name} ($ref: ${p.property.descriptor.ref})`); + } + output.newLine(); + + output.write(0, `export interface ${typeCodes.referenceType.jsonClassName} {`); + for (const p of properties) { + output.write(1, `readonly ${p.propertyNameCodes.nameCode}${p.typeCodes.colon} ${p.typeCodes.jsonTypeCode};`); + } + output.write(0, '}'); + output.newLine(); + + output.write(0, `export interface ${typeCodes.referenceType.inputClassName} {`); + for (const p of properties) { + output.write( + 1, + `readonly ${p.propertyNameCodes.camelCasedNameCode}${p.typeCodes.colon} ${p.typeCodes.inputOrValueTypeCode};`, + ); + } + output.write(0, '}'); + output.newLine(); + + output.write(0, `export class ${typeCodes.referenceType.factoryClassName} {`); + + output.write( + 1, + `public static create(input: ${typeCodes.inputOrValueTypeCode}): ${typeCodes.referenceType.factoryClassName} {`, + ); + output.write(2, `if (input instanceof ${typeCodes.referenceType.factoryClassName}) {`); + output.write(3, `return input;`); + output.write(2, `}`); + output.write(2, `return new ${typeCodes.referenceType.factoryClassName}(input);`); + output.write(1, '}'); + output.newLine(); + + output.write( + 1, + `public static fromJSON(json: ${typeCodes.referenceType.jsonClassName}): ${typeCodes.referenceType.factoryClassName} {`, + ); + output.write(2, `const input: ${typeCodes.referenceType.inputClassName} = {`); + for (const p of properties) { + output.write(3, `${p.propertyNameCodes.camelCasedNameCode}: ${p.json2TypeCode},`); + } + output.write(2, `};`); + output.write(2, `return ${typeCodes.referenceType.factoryClassName}.create(input);`); + output.write(1, `}`); + output.newLine(); + + if (isUsedByUnions) { + output.write(1, `public static isInput(input: any): input is ${typeCodes.referenceType.inputClassName} {`); + if (customTypeDeterminant) { + output.write(2, `return ${customTypeDeterminant.isInputCode};`); + } else { + output.write( + 2, + `return ${JSON.stringify(requiredInputFieldNames)}.every((name) => input[name] !== undefined);`, + ); + } + output.write(1, `}`); + output.newLine(); + + output.write(1, `public static isJSON(json: any): json is ${typeCodes.referenceType.jsonClassName} {`); + if (customTypeDeterminant) { + output.write(2, `return ${customTypeDeterminant.isJSONCode};`); + } else { + output.write(2, `return ${JSON.stringify(requiredJSONFieldNames)}.every((name) => json[name] !== undefined);`); + } + output.write(1, `}`); + output.newLine(); + } + + for (const p of properties) { + output.writeComment(1, null, { + description: p.property.description, + }); + output.write( + 1, + `public readonly ${p.propertyNameCodes.camelCasedNameCode}${p.typeCodes.colon} ${p.typeCodes.valueTypeCode};`, + ); + } + output.newLine(); + + output.write(1, `private constructor(input: ${typeCodes.referenceType.inputClassName}) {`); + for (const p of properties) { + output.write(2, `this${p.propertyNameCodes.camelCasedAccessCode} = ${p.input2typeCode};`); + } + output.write(1, '}'); + output.newLine(); + + output.write(1, `public toJSON(): ${typeCodes.referenceType.jsonClassName} {`); + output.write(2, 'return {'); + for (const p of properties) { + output.write(3, `${p.propertyNameCodes.nameCode}: ${p.type2jsonCode},`); + } + output.write(2, '}'); + output.write(1, '}'); + + output.write(0, `}`); + + return { output, className: typeCodes.referenceType.factoryClassName as string }; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/IndexFileGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/IndexFileGenerator.ts new file mode 100644 index 0000000000..6d4a449928 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/IndexFileGenerator.ts @@ -0,0 +1,20 @@ +import { MemoryOutput } from '../output/MemoryOutput'; +import { Output } from '../output/Output'; + +export class IndexFileGenerator { + public readonly fileNames: string[] = []; + + public add(fileName: string) { + this.fileNames.push(fileName); + } + + public generate(): Output { + const output = new MemoryOutput(); + + for (const fileName of this.fileNames) { + output.write(0, `export * from './${fileName}';`); + } + + return output; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/OperationFileGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/OperationFileGenerator.ts new file mode 100644 index 0000000000..7355ad5c46 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/OperationFileGenerator.ts @@ -0,0 +1,185 @@ +import { OperationInfo } from '../../reader/OpenApiContract'; +import { NameFormatter } from './codeGenerators/NameFormatter'; +import { Output } from '../output/Output'; +import { ValueMappingCodeGenerator } from './codeGenerators/ValueMappingCodeGenerator'; +import { TypeCodesGenerator } from './codeGenerators/TypeCodesGenerator'; +import { TypeResolver } from './resolvers/TypeResolver'; +import { TypeScriptOutput } from '../output/TypeScriptOutput'; + +export interface OperationFileGeneratorResult { + className: string; + output: Output; +} + +export class OperationFileGenerator { + public constructor(private readonly info: OperationInfo, private readonly typeResolver: TypeResolver) {} + + public generate(): OperationFileGeneratorResult { + const resolvedResponseType = this.info.response ? this.typeResolver.resolve(this.info.response.descriptor) : null; + const responseTypeCodes = resolvedResponseType ? TypeCodesGenerator.generate(resolvedResponseType, true) : null; + + const resolvedBodyType = this.info.body ? this.typeResolver.resolve(this.info.body.descriptor) : null; + const bodyTypeCodes = + resolvedBodyType && this.info.body + ? TypeCodesGenerator.generate(resolvedBodyType, this.info.body.isRequired) + : null; + + const className = NameFormatter.getClassName(this.info.operationId) + 'Operation'; + const output = new TypeScriptOutput(); + + const parameters = this.info.parameters.map((parameter) => { + const camelCasedName = NameFormatter.getParameterName(parameter.name); + const resolvedParamType = this.typeResolver.resolveForOperationParameter(parameter.descriptor, parameter.name); + const types = TypeCodesGenerator.generate(resolvedParamType, parameter.isRequired); + return { + camelCasedName, + types, + parameter, + input2TypeCode: ValueMappingCodeGenerator.generateInput2TypeCode( + resolvedParamType, + `request.${camelCasedName}`, + parameter.isRequired, + ), + type2JSONCode: ValueMappingCodeGenerator.generateType2JSONCode( + resolvedParamType, + camelCasedName, + parameter.isRequired, + ), + }; + }); + + const parameterNames = parameters.map((p) => p.parameter.name); + + // view: + + parameters.forEach((parameter) => { + if (parameter.types.referenceType) { + output.addImport( + [ + parameter.types.referenceType.factoryClassName, + parameter.types.referenceType.valueClassName, + parameter.types.referenceType.inputClassName, + parameter.types.referenceType.jsonClassName, + ], + parameter.types.referenceType.importPath, + ); + } + }); + if (responseTypeCodes?.referenceType) { + output.addImport( + [ + responseTypeCodes.referenceType.factoryClassName, + responseTypeCodes.referenceType.valueClassName, + responseTypeCodes.referenceType.jsonClassName, + ], + responseTypeCodes.referenceType.importPath, + ); + } + if (bodyTypeCodes?.referenceType) { + output.addImport( + [ + bodyTypeCodes.referenceType.factoryClassName, + bodyTypeCodes.referenceType.valueClassName, + bodyTypeCodes.referenceType.inputClassName, + bodyTypeCodes.referenceType.jsonClassName, + ], + bodyTypeCodes.referenceType.importPath, + ); + } + output.commitImports(); + + output.write(0, '// request parameters:'); + for (const p of parameters) { + output.write(0, `// - ${p.parameter.name} ($ref: ${p.parameter.descriptor.ref})`); + } + output.newLine(); + + output.write(0, `export interface ${className}Request {`); + for (const p of parameters) { + output.writeComment(1, null, { + description: p.parameter.description, + }); + output.write(1, `readonly ${p.camelCasedName}${p.types.colon} ${p.types.inputOrValueTypeCode};`); + } + output.write(0, '}'); + output.newLine(); + + output.write(0, `export interface ${className}RequestJSON {`); + for (const p of parameters) { + output.write(1, `readonly ${p.parameter.name}${p.types.colon} ${p.types.jsonTypeCode};`); + } + output.write(0, '}'); + output.newLine(); + + if (this.info.description) { + output.writeComment(0, null, { + description: this.info.description, + }); + } + + output.write(0, `export const ${className} = {`); + output.write(1, `operationId: ${JSON.stringify(this.info.operationId)},`); + output.write(1, `groupName: ${JSON.stringify(this.info.groupName)},`); + output.write(1, `httpMethod: ${JSON.stringify(this.info.httpMethod)},`); + output.write(1, `routePattern: ${JSON.stringify(this.info.routePattern)},`); + output.write(1, `parameterNames: ${JSON.stringify(parameterNames)},`); + output.write(1, `hasResponse: ${JSON.stringify(!!this.info.response)},`); + output.write(1, `hasBody: ${JSON.stringify(!!this.info.body)},`); + output.newLine(); + + if (resolvedResponseType && responseTypeCodes && this.info.response) { + const responseJSON2TypeCode = ValueMappingCodeGenerator.generateJSON2TypeCode(resolvedResponseType, 'json', true); + + output.write(1, `parseResponse(json: ${responseTypeCodes.jsonTypeCode}): ${responseTypeCodes.valueTypeCode} {`); + output.write(2, `return ${responseJSON2TypeCode};`); + output.write(1, '},'); + output.newLine(); + } + + output.write(1, `serializeRequest(request: ${className}Request): ${className}RequestJSON {`); + for (const p of parameters) { + output.write(2, `const ${p.camelCasedName} = ${p.input2TypeCode};`); + } + + output.write(2, 'return {'); + for (const p of parameters) { + output.write(3, `${p.parameter.name}: ${p.type2JSONCode},`); + } + output.write(2, '};'); + output.write(1, '},'); + output.newLine(); + + if (resolvedBodyType && bodyTypeCodes && this.info.body) { + const bodyInput2TypeCode = ValueMappingCodeGenerator.generateInput2TypeCode( + resolvedBodyType, + 'body', + this.info.body.isRequired, + ); + const bodyType2JSONCode = ValueMappingCodeGenerator.generateType2JSONCode( + resolvedBodyType, + `value`, + this.info.body.isRequired, + ); + + output.write( + 1, + `serializeBody(body: ${bodyTypeCodes.inputOrValueTypeCode}${bodyTypeCodes.undefinedSuffix}): ${bodyTypeCodes.jsonTypeCode}${bodyTypeCodes.undefinedSuffix} {`, + ); + if (!this.info.body.isRequired) { + output.write(1, 'if (!body) {'); + output.write(2, 'return undefined;'); + output.write(1, '}'); + } + output.write(2, `const value = ${bodyInput2TypeCode};`); + output.write(2, `return ${bodyType2JSONCode};`); + output.write(1, '},'); + } + + output.write(0, '}'); + + return { + output, + className, + }; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/SimpleTypeFileGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/SimpleTypeFileGenerator.ts new file mode 100644 index 0000000000..e6ec051a5c --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/SimpleTypeFileGenerator.ts @@ -0,0 +1,63 @@ +import { SimpleTypeInfo } from 'src/reader/OpenApiContract'; +import { Output } from '../output/Output'; +import { TypeCodesGenerator } from './codeGenerators/TypeCodesGenerator'; +import { NativeTypeNormalizer } from './codeGenerators/NativeTypeNormalizer'; +import { TypeResolver } from './resolvers/TypeResolver'; +import { TypeScriptOutput } from '../output/TypeScriptOutput'; + +export interface SimpleTypeFileGeneratorResult { + className: string; + output: Output; +} + +export class SimpleTypeFileGenerator { + public constructor(private readonly info: SimpleTypeInfo, private readonly typeResolver: TypeResolver) {} + + public generate(): SimpleTypeFileGeneratorResult { + const resolvedType = this.typeResolver.resolveWithNoMapping(this.info.descriptor); + const { referenceType: referenceTypeCodes, inputOrValueTypeCode: inputOrValueTypeCode } = + TypeCodesGenerator.generate(resolvedType, true); + if (!referenceTypeCodes) { + throw new Error('Complex type is only supported'); + } + + const normalizedNativeType = NativeTypeNormalizer.normalize(this.info.nativeType); + let typeCode: string; + if (this.info.enum) { + typeCode = this.info.enum.map((value) => JSON.stringify(value)).join(' | '); + } else { + typeCode = TypeCodesGenerator.getTypeCode(normalizedNativeType, this.info.descriptor.isArray); + } + + // view: + + const output = new TypeScriptOutput(); + + output.write(0, `// $ref: ${this.info.descriptor.ref.toString()}`); + output.write(0, `// typeName: ${this.info.descriptor.typeName.toString()}`); + output.newLine(); + + output.write(0, `export type ${referenceTypeCodes.jsonClassName} = ${typeCode};`); + output.write(0, `export type ${referenceTypeCodes.inputClassName} = ${typeCode};`); + output.write(0, `export type ${referenceTypeCodes.valueClassName} = ${typeCode};`); + output.newLine(); + + output.write(0, `export abstract class ${referenceTypeCodes.factoryClassName} {`); + + output.write(1, `public static create(input: ${inputOrValueTypeCode}): ${referenceTypeCodes.valueClassName} {`); + output.write(2, `return input;`); + output.write(1, `}`); + output.newLine(); + + output.write( + 1, + `public static fromJSON(json: ${referenceTypeCodes.jsonClassName}): ${referenceTypeCodes.valueClassName} {`, + ); + output.write(2, `return json;`); + output.write(1, `}`); + + output.write(0, `}`); + + return { output, className: referenceTypeCodes.factoryClassName as string }; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/UnionTypeFileGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/UnionTypeFileGenerator.ts new file mode 100644 index 0000000000..09d69a2a0d --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/UnionTypeFileGenerator.ts @@ -0,0 +1,112 @@ +import { UnionTypeInfo } from '../../reader/OpenApiContract'; +import { Output } from '../output/Output'; +import { TypeCodesGenerator } from './codeGenerators/TypeCodesGenerator'; +import { TypeResolver } from './resolvers/TypeResolver'; +import { TypeScriptOutput } from '../output/TypeScriptOutput'; + +export interface UnionTypeFileGeneratorResult { + className: string; + output: Output; +} + +export class UnionTypeFileGenerator { + public constructor(private readonly info: UnionTypeInfo, private readonly typeResolver: TypeResolver) {} + + public generate(): UnionTypeFileGeneratorResult { + const resolvedType = this.typeResolver.resolveWithNoMapping(this.info.descriptor); + const { referenceType: typeCodes, inputOrValueTypeCode: inputUnionTypeCode } = TypeCodesGenerator.generate( + resolvedType, + true, + ); + if (!typeCodes) { + throw new Error('Reference type is only supported'); + } + + const unionTypes = this.info.unionDescriptors.map((descriptor) => { + const unionResolvedType = this.typeResolver.resolveWithNoMapping(descriptor); + return { + typeCodes: TypeCodesGenerator.generate(unionResolvedType, true), + }; + }); + + const unionJsonTypeCode = unionTypes.map((unionType) => unionType.typeCodes.jsonTypeCode).join(' | '); + const unionInputTypeCode = unionTypes.map((unionType) => unionType.typeCodes.inputTypeCode).join(' | '); + const unionValueTypeCode = unionTypes.map((unionType) => unionType.typeCodes.valueTypeCode).join(' | '); + const hasAnySimpleType = unionTypes.some((unionType) => !unionType.typeCodes.referenceType); + + // view: + + const output = new TypeScriptOutput(); + + for (const unionType of unionTypes) { + if (unionType.typeCodes.referenceType) { + output.addImport( + [ + unionType.typeCodes.referenceType.factoryClassName, + unionType.typeCodes.referenceType.valueClassName, + unionType.typeCodes.referenceType.jsonClassName, + unionType.typeCodes.referenceType.inputClassName, + ], + unionType.typeCodes.referenceType.importPath, + ); + } + } + output.commitImports(); + + output.write(0, `// $ref: ${this.info.descriptor.ref.toString()}`); + output.write(0, `// typeName: ${this.info.descriptor.typeName.toString()}`); + output.write(0, `// unionType: ${this.info.unionType}`); + output.newLine(); + + output.write(0, `export type ${typeCodes.jsonClassName} = ${unionJsonTypeCode};`); + output.write(0, `export type ${typeCodes.inputClassName} = ${unionInputTypeCode};`); + output.write(0, `export type ${typeCodes.valueClassName} = ${unionValueTypeCode};`); + output.newLine(); + + output.write(0, `export abstract class ${typeCodes.factoryClassName} {`); + + output.write(1, `public static create(input: ${typeCodes.inputClassName}): ${typeCodes.valueClassName} {`); + for (const unionType of unionTypes) { + if (!unionType.typeCodes.referenceType) { + continue; + } + output.write(2, `if (${unionType.typeCodes.referenceType.factoryClassName}.isInput(input)) {`); + output.write(3, `return ${unionType.typeCodes.referenceType.factoryClassName}.create(input);`); + output.write(2, '}'); + } + + if (hasAnySimpleType) { + output.write(2, `return new ${typeCodes.factoryClassName}(input);`); + } else { + output.write(2, `throw new Error('Cannot resolve union for input');`); + } + output.write(1, `}`); + output.newLine(); + + output.write(1, `public static fromJSON(json: ${typeCodes.jsonClassName}): ${typeCodes.valueClassName} {`); + for (const unionType of unionTypes) { + if (!unionType.typeCodes.referenceType) { + continue; + } + output.write(2, `if (${unionType.typeCodes.referenceType.factoryClassName}.isJSON(json)) {`); + output.write(3, `return ${unionType.typeCodes.referenceType.factoryClassName}.fromJSON(json);`); + output.write(2, '}'); + } + + if (hasAnySimpleType) { + output.write(2, `return new ${typeCodes.factoryClassName}(json);`); + } else { + output.write(2, `const keys = Object.keys(json).join(', ');`); + output.write(2, `const type = (json as any).type;`); + output.write( + 2, + `throw new Error(\`Cannot resolve union for ${typeCodes.factoryClassName} (keys: \${keys}, type: \${type})\`);`, + ); + } + output.write(1, `}`); + + output.write(0, `}`); + + return { output, className: typeCodes.factoryClassName as string }; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NameFormatter.test.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NameFormatter.test.ts new file mode 100644 index 0000000000..b48180ce92 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NameFormatter.test.ts @@ -0,0 +1,23 @@ +import { NameFormatter } from './NameFormatter'; + +describe('NameFormatter', () => { + describe('getClassName', () => { + it('returns expected name', () => { + expect(NameFormatter.getClassName('test')).toBe('Test'); + expect(NameFormatter.getClassName('one_two_three')).toBe('OneTwoThree'); + expect(NameFormatter.getClassName('_one_')).toBe('One'); + expect(NameFormatter.getClassName('lorem ipsum')).toBe('LoremIpsum'); + expect(NameFormatter.getClassName('t1')).toBe('T1'); + expect(NameFormatter.getClassName('Some$Value')).toBe('SomeValue'); + }); + }); + + describe('getParameterName', () => { + it('returns expected name', () => { + expect(NameFormatter.getParameterName('test')).toBe('test'); + expect(NameFormatter.getParameterName('lorem_ipsum')).toBe('loremIpsum'); + expect(NameFormatter.getParameterName('someStrangeValue')).toBe('someStrangeValue'); + expect(NameFormatter.getParameterName('foo$bar')).toBe('fooBar'); + }); + }); +}); diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NameFormatter.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NameFormatter.ts new file mode 100644 index 0000000000..0856dd70b5 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NameFormatter.ts @@ -0,0 +1,41 @@ +import { TypeName } from '../../../reader/utils/TypeName'; + +export class NameFormatter { + public static getClassName(className: TypeName | string): string { + if (typeof className === 'string') { + className = TypeName.from(className); + } + return className.parts + .map((part) => { + part = normalize(part); + part = toCamelCase(part); + part = capitalizeFirst(part); + return part; + }) + .join(''); + } + + public static getParameterName(name: string): string { + name = normalize(name); + name = toCamelCase(name); + return lowercaseFirst(name); + } +} + +function toCamelCase(value: string): string { + return value.replace(/([-_][a-z])/gi, (found) => { + return found.toUpperCase().replace('-', '').replace('_', ''); + }); +} + +function normalize(value: string): string { + return value.replace(/\W+/g, '_').replace(/^_|_$/g, ''); +} + +function capitalizeFirst(value: string): string { + return value.substring(0, 1).toUpperCase() + value.substring(1); +} + +function lowercaseFirst(value: string): string { + return value.substring(0, 1).toLowerCase() + value.substring(1); +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NativeTypeNormalizer.test.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NativeTypeNormalizer.test.ts new file mode 100644 index 0000000000..94b25fbd81 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NativeTypeNormalizer.test.ts @@ -0,0 +1,15 @@ +import { NativeTypeNormalizer } from './NativeTypeNormalizer'; + +describe('NativeTypeNormalizer', () => { + it('normalizes integer to number', () => { + expect(NativeTypeNormalizer.normalize('integer')).toBe('number'); + }); + + it('normalizes string to string', () => { + expect(NativeTypeNormalizer.normalize('string')).toBe('string'); + }); + + it('throw an error when array type is passed', () => { + expect(() => NativeTypeNormalizer.normalize('array')).toThrowError('Invalid native type: array'); + }); +}); diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NativeTypeNormalizer.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NativeTypeNormalizer.ts new file mode 100644 index 0000000000..a36fc80982 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/NativeTypeNormalizer.ts @@ -0,0 +1,17 @@ +export class NativeTypeNormalizer { + public static normalize(nativeType: string): string { + switch (nativeType) { + case 'integer': + return 'number'; + case 'array': + throw new Error(`Invalid native type: ${nativeType}`); + case 'string': + case 'boolean': + case 'number': + case 'object': + case 'null': + return nativeType; + } + throw new Error(`Not supported native type: ${nativeType}`); + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/PropertyNameCodeGenerator.test.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/PropertyNameCodeGenerator.test.ts new file mode 100644 index 0000000000..7111555bf1 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/PropertyNameCodeGenerator.test.ts @@ -0,0 +1,19 @@ +import { PropertyNameCodeGenerator } from './PropertyNameCodeGenerator'; + +describe('PropertyNameCodeGenerator', () => { + it('generates for plain name', () => { + const codes = PropertyNameCodeGenerator.generate('foo_bar'); + expect(codes.accessCode).toBe('.foo_bar'); + expect(codes.nameCode).toBe('foo_bar'); + expect(codes.camelCasedAccessCode).toBe('.fooBar'); + expect(codes.camelCasedNameCode).toBe('fooBar'); + }); + + it('generates for "+" name', () => { + const codes = PropertyNameCodeGenerator.generate('+'); + expect(codes.accessCode).toBe("['+']"); + expect(codes.nameCode).toBe("'+'"); + expect(codes.camelCasedAccessCode).toBe("['+']"); + expect(codes.camelCasedNameCode).toBe("'+'"); + }); +}); diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/PropertyNameCodeGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/PropertyNameCodeGenerator.ts new file mode 100644 index 0000000000..0701ec3cf8 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/PropertyNameCodeGenerator.ts @@ -0,0 +1,28 @@ +import { NameFormatter } from './NameFormatter'; + +export interface PropertyNameCodes { + nameCode: string; + accessCode: string; + camelCasedNameCode: string; + camelCasedAccessCode: string; +} + +export class PropertyNameCodeGenerator { + public static generate(name: string): PropertyNameCodes { + const isSafe = isNameSafe(name); + const nameCode = isSafe ? name : `'${name}'`; + const camelCasedNameCode = isSafe ? NameFormatter.getParameterName(name) : `'${name}'`; + const accessCode = isSafe ? `.${nameCode}` : `[${nameCode}]`; + const camelCasedAccessCode = isSafe ? `.${camelCasedNameCode}` : `[${camelCasedNameCode}]`; + return { + nameCode, + accessCode, + camelCasedNameCode, + camelCasedAccessCode, + }; + } +} + +function isNameSafe(name: string): boolean { + return /^[a-zA-Z_][a-zA-Z_0-9]*$/.test(name); +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/TypeCodesGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/TypeCodesGenerator.ts new file mode 100644 index 0000000000..0f69763ba4 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/TypeCodesGenerator.ts @@ -0,0 +1,89 @@ +import { NativeTypeNormalizer } from './NativeTypeNormalizer'; +import { ResolvedType } from '../resolvers/TypeResolver'; + +export interface TypeCodes { + colon: string; + + valueTypeCode: string; + inputTypeCode: string; + jsonTypeCode: string; + inputOrValueTypeCode: string; + + undefinedSuffix: string; + referenceType: ReferenceTypeCodes | null; +} + +export interface ReferenceTypeCodes { + factoryClassName: string; + valueClassName: string; + inputClassName: string; + jsonClassName: string; + importPath: string; +} + +export class TypeCodesGenerator { + public static getTypeCode(type: string, isArray: boolean): string { + return isArray ? `${type}[]` : type; + } + + public static generate(resolvedType: ResolvedType, isRequired: boolean): TypeCodes { + const colon = isRequired ? ':' : '?:'; + const undefinedSuffix = isRequired ? '' : ' | undefined'; + + if (resolvedType.referenceType) { + const { className, isSimpleType, isUnionType } = resolvedType.referenceType; + const valueClassName = isSimpleType || isUnionType ? `${className}Value` : className; + const jsonClassName = className + 'JSON'; + const inputClassName = className + 'Input'; + const valueTypeCode = TypeCodesGenerator.getTypeCode(valueClassName, resolvedType.isArray); + const inputTypeCode = TypeCodesGenerator.getTypeCode(inputClassName, resolvedType.isArray); + + return { + colon, + + valueTypeCode, + inputTypeCode, + jsonTypeCode: TypeCodesGenerator.getTypeCode(jsonClassName, resolvedType.isArray), + inputOrValueTypeCode: `${inputTypeCode} | ${valueTypeCode}`, + + undefinedSuffix, + referenceType: { + factoryClassName: className, + valueClassName, + inputClassName, + jsonClassName, + importPath: resolvedType.referenceType.importPath, + }, + }; + } + + if (resolvedType.nativeType) { + const normalizedNativeType = NativeTypeNormalizer.normalize(resolvedType.nativeType); + const typeCode = TypeCodesGenerator.getTypeCode(normalizedNativeType, resolvedType.isArray); + + return { + colon, + valueTypeCode: typeCode, + inputTypeCode: typeCode, + jsonTypeCode: typeCode, + inputOrValueTypeCode: typeCode, + undefinedSuffix, + referenceType: null, + }; + } + + throw new Error('Unknown descriptor type'); + } + + public static generateNull(): TypeCodes { + return { + colon: ':', + valueTypeCode: 'null', + inputTypeCode: 'null', + inputOrValueTypeCode: 'null', + jsonTypeCode: 'null', + undefinedSuffix: '', + referenceType: null, + }; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/ValueMappingCodeGenerator.ts b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/ValueMappingCodeGenerator.ts new file mode 100644 index 0000000000..6071d3a45f --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/codeGenerators/ValueMappingCodeGenerator.ts @@ -0,0 +1,48 @@ +import { ResolvedType } from '../resolvers/TypeResolver'; + +export class ValueMappingCodeGenerator { + public static generateJSON2TypeCode(resolvedType: ResolvedType, valueCode: string, isRequired: boolean): string { + if (resolvedType.referenceType) { + let code: string; + if (resolvedType.isArray) { + code = `${valueCode}.map((item) => ${resolvedType.referenceType.className}.fromJSON(item))`; + } else { + code = `${resolvedType.referenceType.className}.fromJSON(${valueCode})`; + } + return isRequired ? code : `${valueCode} ? ${code} : undefined`; + } + + return valueCode; + } + + public static generateType2JSONCode(resolvedType: ResolvedType, valueCode: string, isRequired: boolean): string { + if (resolvedType.referenceType) { + let code: string; + if (resolvedType.referenceType.isSimpleType) { + code = valueCode; + } else if (resolvedType.isArray) { + code = `${valueCode}.map((item) => item.toJSON())`; + } else { + code = `${valueCode}.toJSON()`; + } + return isRequired ? code : `${valueCode} ? ${code} : undefined`; + } + + return valueCode; + } + + public static generateInput2TypeCode(resolvedType: ResolvedType, valueCode: string, isRequired: boolean): string { + if (resolvedType.referenceType) { + const { className } = resolvedType.referenceType; + let code: string; + if (resolvedType.isArray) { + code = `${valueCode}.map((item) => ${className}.create(item))`; + } else { + code = `${className}.create(${valueCode})`; + } + return isRequired ? code : `${valueCode} ? ${code} : undefined`; + } + + return valueCode; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/resolvers/MappingResolver.ts b/packages/apiGenerator/src/generator/fileGenerators/resolvers/MappingResolver.ts new file mode 100644 index 0000000000..7164435be0 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/resolvers/MappingResolver.ts @@ -0,0 +1,27 @@ +import { + ComplexTypePropertyMapping, + Mappings, + OperationParameterMapping, + RefMapping, + TypeMapping, +} from '../../GeneratorConfiguration'; + +export class MappingResolver { + public constructor(private readonly mappings: Mappings) {} + + public tryResolveByTypeName(typeName: string): TypeMapping | undefined { + return this.mappings.types.find((m) => m.typeName === typeName); + } + + public tryResolveBy$ref($ref: string): RefMapping | undefined { + return this.mappings.refs.find((r) => r.$ref === $ref); + } + + public tryResolveByOperationParameterName(name: string): OperationParameterMapping | undefined { + return this.mappings.operationParameters.find((p) => p.names.includes(name)); + } + + public tryResolveByComplexTypePropertyName(name: string): ComplexTypePropertyMapping | undefined { + return this.mappings.complexTypeProperties.find((p) => p.names.includes(name)); + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeDeterminantResolver.ts b/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeDeterminantResolver.ts new file mode 100644 index 0000000000..20eaa2e799 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeDeterminantResolver.ts @@ -0,0 +1,12 @@ +import { TypeName } from '../../../reader/utils/TypeName'; +import { TypeDeterminant } from '../../GeneratorConfiguration'; + +export class TypeDeterminantResolver { + public constructor(private readonly typeDeterminants: TypeDeterminant[]) {} + + public tryResolve(typeName: TypeName): TypeDeterminant | null { + const typeNameString = typeName.toString(); + const condition = this.typeDeterminants.find((c) => c.typeName === typeNameString); + return condition ?? null; + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeInfoResolver.ts b/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeInfoResolver.ts new file mode 100644 index 0000000000..a685fc2ca7 --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeInfoResolver.ts @@ -0,0 +1,26 @@ +import { ReferenceTypePointer } from '../../../reader/TypeDescriptor'; +import { OpenApiContract } from '../../../reader/OpenApiContract'; + +export class TypeInfoResolver { + public constructor(private readonly contract: OpenApiContract) {} + + public isUsedByUnions(pointer: ReferenceTypePointer): boolean { + const $ref = pointer.ref.toString(); + for (const unionType of this.contract.unionTypes) { + if (unionType.unionDescriptors.some((descriptor) => descriptor.ref.toString() === $ref)) { + return true; + } + } + return false; + } + + public isSimpleType(pointer: ReferenceTypePointer): boolean { + const $ref = pointer.ref.toString(); + return this.contract.simpleTypes.some((type) => type.descriptor.ref.toString() === $ref); + } + + public isUnionType(pointer: ReferenceTypePointer): boolean { + const $ref = pointer.ref.toString(); + return this.contract.unionTypes.some((type) => type.descriptor.ref.toString() === $ref); + } +} diff --git a/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeResolver.ts b/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeResolver.ts new file mode 100644 index 0000000000..6148d4d88b --- /dev/null +++ b/packages/apiGenerator/src/generator/fileGenerators/resolvers/TypeResolver.ts @@ -0,0 +1,106 @@ +import { NameFormatter } from '../codeGenerators/NameFormatter'; +import { isReferenceTypeDescriptor, isNativeTypeDescriptor, TypeDescriptor } from '../../../reader/TypeDescriptor'; +import { MappingTarget } from '../../GeneratorConfiguration'; +import { TypeName } from 'src/reader/utils/TypeName'; +import { MappingResolver } from './MappingResolver'; +import { TypeInfoResolver } from './TypeInfoResolver'; + +export interface ResolvedType { + isArray: boolean; + nativeType?: string; + referenceType?: ReferenceResolvedType; +} + +export interface ReferenceResolvedType { + className: string; + isSimpleType: boolean; + isUnionType: boolean; + importPath: string; +} + +const BASE_PATH = '../'; + +export class TypeResolver { + public constructor( + private readonly classNamePrefix: string, + private readonly mappingResolver: MappingResolver, + private readonly typeInfoResolver: TypeInfoResolver, + ) {} + + public resolveWithNoMapping(descriptor: TypeDescriptor): ResolvedType { + if (isReferenceTypeDescriptor(descriptor)) { + const className = this.createClassName(descriptor.typeName); + return { + isArray: descriptor.isArray, + referenceType: { + className, + isSimpleType: this.typeInfoResolver.isSimpleType(descriptor), + isUnionType: this.typeInfoResolver.isUnionType(descriptor), + importPath: `${BASE_PATH}types/${className}`, + }, + }; + } + if (isNativeTypeDescriptor(descriptor)) { + return { + isArray: descriptor.isArray, + nativeType: descriptor.nativeType, + }; + } + throw new Error('Unsupported descriptor type'); + } + + public resolveForOperationParameter(descriptor: TypeDescriptor, parameterName: string): ResolvedType { + const target = this.mappingResolver.tryResolveByOperationParameterName(parameterName); + if (target) { + return this.resolveTarget(descriptor, target); + } + return this.resolve(descriptor); + } + + public resolveForComplexTypeProperty(descriptor: TypeDescriptor, propertyName: string): ResolvedType { + const target = this.mappingResolver.tryResolveByComplexTypePropertyName(propertyName); + if (target) { + return this.resolveTarget(descriptor, target); + } + return this.resolve(descriptor); + } + + public resolve(descriptor: TypeDescriptor): ResolvedType { + let target: MappingTarget | undefined = undefined; + + if (isReferenceTypeDescriptor(descriptor)) { + target = this.mappingResolver.tryResolveByTypeName(descriptor.typeName.toString()); + } + if (!target) { + target = this.mappingResolver.tryResolveBy$ref(descriptor.ref.toString()); + } + + if (target) { + return this.resolveTarget(descriptor, target); + } + return this.resolveWithNoMapping(descriptor); + } + + // + + private createClassName(className: TypeName): string { + return NameFormatter.getClassName(className.addPrefix(this.classNamePrefix)); + } + + private resolveTarget(descriptor: TypeDescriptor, target: MappingTarget): ResolvedType { + if (!target.className) { + throw new Error('Not supported mapping target'); + } + + const importPath = target.import ? target.import : `${BASE_PATH}customTypes/${target.className}`; + return { + isArray: descriptor.isArray, + referenceType: { + className: target.className, + isSimpleType: false, + isUnionType: false, + importPath, + }, + }; + } +} diff --git a/packages/apiGenerator/src/generator/output/MemoryOutput.test.ts b/packages/apiGenerator/src/generator/output/MemoryOutput.test.ts new file mode 100644 index 0000000000..4f4f2416de --- /dev/null +++ b/packages/apiGenerator/src/generator/output/MemoryOutput.test.ts @@ -0,0 +1,11 @@ +import { MemoryOutput } from './MemoryOutput'; + +describe('MemoryOutput', () => { + it('creates output', () => { + const output = new MemoryOutput(); + output.write(0, 'A'); + output.write(1, 'B'); + output.newLine(); + expect(output.toString()).toBe('A\r\n B\r\n\r\n'); + }); +}); diff --git a/packages/apiGenerator/src/generator/output/MemoryOutput.ts b/packages/apiGenerator/src/generator/output/MemoryOutput.ts new file mode 100644 index 0000000000..2e41b7a7ce --- /dev/null +++ b/packages/apiGenerator/src/generator/output/MemoryOutput.ts @@ -0,0 +1,34 @@ +import { Output } from './Output'; + +export const TAB = ' '; +export const EOL = '\r\n'; + +export class MemoryOutput implements Output { + public static createTabs(tabs: number): string { + let result = ''; + for (let i = 0; i < tabs; i++) { + result += TAB; + } + return result; + } + + private readonly lines: { tabs: number; content: string }[] = []; + + public newLine() { + this.lines.push({ tabs: 0, content: '' }); + } + + public write(tabs: number, content: string) { + this.lines.push({ tabs, content }); + } + + public toString(): string { + let output = ''; + for (const line of this.lines) { + output += MemoryOutput.createTabs(line.tabs); + output += line.content; + output += EOL; + } + return output; + } +} diff --git a/packages/apiGenerator/src/generator/output/Output.ts b/packages/apiGenerator/src/generator/output/Output.ts new file mode 100644 index 0000000000..9d7208b729 --- /dev/null +++ b/packages/apiGenerator/src/generator/output/Output.ts @@ -0,0 +1,5 @@ +export interface Output { + newLine(): void; + write(tabs: number, content: string): void; + toString(): string; +} diff --git a/packages/apiGenerator/src/generator/output/TypeScriptOutput.test.ts b/packages/apiGenerator/src/generator/output/TypeScriptOutput.test.ts new file mode 100644 index 0000000000..81789c0b61 --- /dev/null +++ b/packages/apiGenerator/src/generator/output/TypeScriptOutput.test.ts @@ -0,0 +1,17 @@ +import { TypeScriptOutput } from './TypeScriptOutput'; + +describe('TypeScriptOutput', () => { + it('creates multiline comments correctly', () => { + const output = new TypeScriptOutput(); + output.writeComment(1, 'tiny\r\nexample', { + test: 'foo\r\nbar', + }); + const lines = output.toString().split(/\r\n/g); + expect(lines[0]).toBe(' /**'); + expect(lines[1]).toBe(' * tiny'); + expect(lines[2]).toBe(' * example'); + expect(lines[3]).toBe(' * @test foo'); + expect(lines[4]).toBe(' * bar'); + expect(lines[5]).toBe(' */'); + }); +}); diff --git a/packages/apiGenerator/src/generator/output/TypeScriptOutput.ts b/packages/apiGenerator/src/generator/output/TypeScriptOutput.ts new file mode 100644 index 0000000000..fb2c397cad --- /dev/null +++ b/packages/apiGenerator/src/generator/output/TypeScriptOutput.ts @@ -0,0 +1,66 @@ +import { EOL, MemoryOutput } from './MemoryOutput'; +import { Output } from './Output'; + +export class TypeScriptOutput implements Output { + private readonly output = new MemoryOutput(); + private readonly imports = new Map>(); + + public addImport(types: string[], path: string) { + let items = this.imports.get(path); + if (items) { + for (const type of types) { + items.add(type); + } + } else { + this.imports.set(path, new Set(types)); + } + } + + public commitImports() { + let count = 0; + for (const path of this.imports.keys()) { + const types = [...(this.imports.get(path) as Set)]; + this.output.write(0, `import { ${types.join(', ')} } from '${path}';`); + count++; + } + if (count > 0) { + this.output.newLine(); + } + } + + public writeComment(tabs: number, comment: string | null, props: { [key: string]: string | undefined }) { + const notEmptyPropKeys = Object.keys(props).filter((name) => props[name]); + if (notEmptyPropKeys.length < 1) { + return; + } + + this.write(tabs, '/**'); + if (comment) { + this.write(tabs, ' * ' + wrapComment(tabs, comment)); + } + for (const key of notEmptyPropKeys) { + this.write(tabs, ` * @${key} ${wrapComment(tabs, props[key] as string)}`); + } + this.write(tabs, ' */'); + } + + public newLine() { + this.output.newLine(); + } + + public write(tabs: number, content: string) { + this.output.write(tabs, content); + } + + public toString(): string { + return this.output.toString(); + } +} + +function wrapComment(tabs: number, value: string): string { + return value + .split(/\r|\n/) + .filter((line) => !!line) + .map((line, index) => (index === 0 ? line : `${MemoryOutput.createTabs(tabs)} * ${line}`)) + .join(EOL); +} diff --git a/packages/apiGenerator/src/index.ts b/packages/apiGenerator/src/index.ts new file mode 100644 index 0000000000..bd89ef70f7 --- /dev/null +++ b/packages/apiGenerator/src/index.ts @@ -0,0 +1,24 @@ +import { Generator } from './generator/Generator'; +import { ConfigurationReader } from './configuration/ConfigurationReader'; +import { OpenApiDownloader } from './reader/OpenApiDownloader'; +import { OpenApiReader } from './reader/OpenApiReader'; +import path from 'path'; + +async function run(projectPath: string) { + if (!projectPath) { + throw new Error('Invalid usage'); + } + projectPath = path.join(__dirname, projectPath); + + const configuration = ConfigurationReader.read(projectPath); + console.log(`📔 Swagger: ${configuration.url}`); + + const document = await OpenApiDownloader.download(configuration.url); + const readerResult = OpenApiReader.create(document, configuration.openApiReader).read(); + const generator = Generator.create(readerResult, configuration.generator, projectPath); + generator.generate(); + + console.log('✅ Done'); +} + +run(process.argv[2]); diff --git a/packages/apiGenerator/src/reader/OpenApiContract.ts b/packages/apiGenerator/src/reader/OpenApiContract.ts new file mode 100644 index 0000000000..dea389596b --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiContract.ts @@ -0,0 +1,59 @@ +import { ReferenceTypeDescriptor, TypeDescriptor, UnionType } from './TypeDescriptor'; + +export interface OpenApiContract { + operations: OperationInfo[]; + complexTypes: ComplexTypeInfo[]; + simpleTypes: SimpleTypeInfo[]; + unionTypes: UnionTypeInfo[]; +} + +export interface ComplexTypeInfo { + descriptor: ReferenceTypeDescriptor; + properties: PropertyInfo[]; +} + +export interface PropertyInfo { + name: string; + description?: string; + isRequired: boolean; + descriptor: TypeDescriptor; +} + +export interface SimpleTypeInfo { + descriptor: ReferenceTypeDescriptor; + nativeType: string; // 'string', 'number', 'object'... + enum?: string[]; +} + +export interface UnionTypeInfo { + descriptor: ReferenceTypeDescriptor; + unionType: UnionType; + unionDescriptors: TypeDescriptor[]; +} + +export interface OperationInfo { + operationId: string; + groupName: string; + httpMethod: string; + routePattern: string; + description?: string; + response: OperationResponseInfo | null; + body: OperationBodyInfo | null; + parameters: ParameterInfo[]; +} + +export interface OperationResponseInfo { + descriptor: TypeDescriptor; +} + +export interface OperationBodyInfo { + descriptor: TypeDescriptor; + isRequired: boolean; +} + +export interface ParameterInfo { + name: string; + isRequired: boolean; + descriptor: TypeDescriptor; + description?: string; +} diff --git a/packages/apiGenerator/src/reader/OpenApiDownloader.ts b/packages/apiGenerator/src/reader/OpenApiDownloader.ts new file mode 100644 index 0000000000..8c1c019c6a --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiDownloader.ts @@ -0,0 +1,15 @@ +import { OpenAPI } from 'openapi-types'; +import axios from 'axios'; +import fs from 'fs'; + +export class OpenApiDownloader { + public static async download(url: string): Promise { + if (url.startsWith('https://') || url.startsWith('http://')) { + const response = await axios.get(url); + return response.data as OpenAPI.Document; + } + + const content = fs.readFileSync(url, 'utf8'); + return JSON.parse(content) as OpenAPI.Document; + } +} diff --git a/packages/apiGenerator/src/reader/OpenApiReader.arrayOfEnum.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.arrayOfEnum.test.ts new file mode 100644 index 0000000000..f39f3d121a --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.arrayOfEnum.test.ts @@ -0,0 +1,176 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { ReferenceTypeDescriptor, isReferenceTypeDescriptor, NativeTypeDescriptor } from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('array of enum', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/streams/aptos': { + get: { + operationId: 'GetAllStreams', + responses: { + '200': { + description: '', + content: { + 'application/json': { + schema: { + properties: { + total: { + type: 'number', + format: 'double', + }, + result: { + items: { + $ref: '#/components/schemas/AptosStreamType', + }, + type: 'array', + }, + }, + required: ['total', 'result'], + type: 'object', + }, + }, + }, + }, + }, + parameters: [ + { + in: 'query', + name: 'limit', + required: true, + schema: { + format: 'double', + type: 'number', + }, + }, + { + in: 'query', + name: 'cursor', + required: false, + schema: { + type: 'string', + }, + }, + ], + }, + }, + }, + components: { + schemas: { + AptosStreamType: { + properties: { + network: { + $ref: '#/components/schemas/AptosNetwork', + }, + events: { + items: { + type: 'string', + }, + type: 'array', + }, + }, + required: ['network', 'events'], + type: 'object', + }, + AptosNetwork: { + items: { + type: 'string', + enum: ['mainnet', 'testnet', 'devnet'], + }, + type: 'array', + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + expect(operation.operationId).toBe('GetAllStreams'); + expect(operation.httpMethod).toBe('get'); + expect(operation.routePattern).toBe('/streams/aptos'); + expect(operation.body).toBeNull(); + + expect(isReferenceTypeDescriptor(operation.response!.descriptor)).toBe(true); + const responseD = operation.response!.descriptor as ReferenceTypeDescriptor; + expect(responseD.typeName.toString()).toBe('GetAllStreams'); + expect(responseD.ref.toString()).toBe( + '#/paths/~1streams~1aptos/get/responses/200/content/application~1json/schema', + ); + expect(responseD.isArray).toBe(false); + + // complex types + + const complexType1 = result.complexTypes[0]; + const complexType1D = complexType1.descriptor; + { + expect(complexType1D.ref.toString()).toBe( + '#/paths/~1streams~1aptos/get/responses/200/content/application~1json/schema', + ); + expect(complexType1D.typeName.toString()).toBe('GetAllStreams'); + expect(complexType1D.isArray).toBe(false); + + const totalProp = complexType1.properties.find((p) => p.name === 'total')!; + const totalPropD = totalProp.descriptor as NativeTypeDescriptor; + expect(totalPropD.nativeType).toBe('number'); + expect(totalPropD.isArray).toBe(false); + + const resultProp = complexType1.properties.find((p) => p.name === 'result')!; + const resultPropD = resultProp.descriptor as ReferenceTypeDescriptor; + expect(resultPropD.typeName.toString()).toBe('AptosStreamType'); + expect(resultPropD.ref.toString()).toBe('#/components/schemas/AptosStreamType'); + expect(resultPropD.isArray).toBe(true); + } + + const complexType2 = result.complexTypes[1]; + const complexType2D = complexType2.descriptor; + { + expect(complexType2D.typeName.toString()).toBe('AptosStreamType'); + expect(complexType2D.ref.toString()).toBe('#/components/schemas/AptosStreamType'); + expect(complexType2D.isArray).toBe(false); + + const eventsProp = complexType2.properties.find((p) => p.name === 'events')!; + const eventsPropD = eventsProp.descriptor as NativeTypeDescriptor; + expect(eventsPropD.nativeType).toBe('string'); + expect(eventsPropD.isArray).toBe(true); + + const networkProp = complexType2.properties.find((p) => p.name === 'network')!; + const networkPropD = networkProp.descriptor as ReferenceTypeDescriptor; + expect(networkPropD.typeName.toString()).toBe('AptosNetwork_Item'); + expect(networkPropD.ref.toString()).toBe('#/components/schemas/AptosNetwork/items'); + expect(networkPropD.isArray).toBe(true); + } + + expect(result.complexTypes[3]).toBeUndefined(); + + // simple types + + const simpleType1 = result.simpleTypes[0]; + const simpleType1D = simpleType1.descriptor as ReferenceTypeDescriptor; + { + expect(simpleType1D.typeName.toString()).toBe('AptosNetwork_Item'); + expect(simpleType1D.ref.toString()).toBe('#/components/schemas/AptosNetwork/items'); + expect(simpleType1D.isArray).toBe(false); + + expect(simpleType1.nativeType).toBe('string'); + expect(simpleType1.enum).toContain('mainnet'); + expect(simpleType1.enum).toContain('testnet'); + expect(simpleType1.enum).toContain('devnet'); + } + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.arrayOfOneOf.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.arrayOfOneOf.test.ts new file mode 100644 index 0000000000..6c4345ac3c --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.arrayOfOneOf.test.ts @@ -0,0 +1,137 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { isReferenceTypeDescriptor, ReferenceTypeDescriptor, UnionType } from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('response with array of oneOf', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/transactions': { + get: { + operationId: 'getTransactions', + responses: { + '200': { + description: '', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + oneOf: [ + { + $ref: '#/components/schemas/PendingTransaction', + }, + { + $ref: '#/components/schemas/UserTransaction', + }, + { + $ref: '#/components/schemas/GenesisTransaction', + }, + ], + }, + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + PendingTransaction: { + type: 'object', + properties: { + hash: { + type: 'string', + }, + sender: { + type: 'string', + }, + }, + required: ['hash', 'sender'], + }, + UserTransaction: { + type: 'object', + properties: { + type: { + type: 'string', + }, + hash: { + type: 'string', + }, + success: { + type: 'boolean', + }, + }, + required: ['type', 'hash', 'success'], + }, + GenesisTransaction: { + type: 'object', + properties: { + type: { + type: 'string', + }, + state_change_hash: { + type: 'string', + }, + }, + required: ['type', 'state_change_hash'], + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + + const responseD = operation.response!.descriptor as ReferenceTypeDescriptor; + expect(responseD.isArray).toBe(true); + expect(responseD.typeName.toString()).toBe('getTransactions_Item'); + expect(responseD.ref.toString()).toBe( + '#/paths/~1transactions/get/responses/200/content/application~1json/schema/items', + ); + + const unionType1 = result.unionTypes[0]; + const unionType1D = unionType1.descriptor; + { + expect(unionType1.unionType).toBe(UnionType.oneOf); + expect(unionType1D.isArray).toBe(false); + expect(unionType1D.typeName.toString()).toBe('getTransactions_Item'); + expect(unionType1D.ref.toString()).toBe( + '#/paths/~1transactions/get/responses/200/content/application~1json/schema/items', + ); + + expect(unionType1.unionDescriptors.length).toBe(3); + + const unionDescriptor1 = unionType1.unionDescriptors[0]; + expect(isReferenceTypeDescriptor(unionDescriptor1)).toBe(true); + expect(unionDescriptor1.ref.toString()).toBe('#/components/schemas/PendingTransaction'); + + const unionDescriptor2 = unionType1.unionDescriptors[1]; + expect(isReferenceTypeDescriptor(unionDescriptor2)).toBe(true); + expect(unionDescriptor2.ref.toString()).toBe('#/components/schemas/UserTransaction'); + + const unionDescriptor3 = unionType1.unionDescriptors[2]; + expect(isReferenceTypeDescriptor(unionDescriptor3)).toBe(true); + expect(unionDescriptor3.ref.toString()).toBe('#/components/schemas/GenesisTransaction'); + } + + expect(result.complexTypes.length).toBe(3); + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.arrayRefResponse.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.arrayRefResponse.test.ts new file mode 100644 index 0000000000..6087b5b354 --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.arrayRefResponse.test.ts @@ -0,0 +1,110 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { ReferenceTypeDescriptor, isReferenceTypeDescriptor } from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('array ref response', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/wallets/balances': { + get: { + operationId: 'getNativeBalancesForAddresses', + parameters: [], + responses: { + '200': { + description: '', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/nativeBalances', + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + nativeBalances: { + type: 'array', + items: { + type: 'object', + required: ['wallet_balances'], + properties: { + wallet_balances: { + type: 'array', + items: { + type: 'object', + required: ['address'], + properties: { + address: { + type: 'string', + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + + expect(isReferenceTypeDescriptor(operation.response!.descriptor)).toBe(true); + const responseD = operation.response!.descriptor as ReferenceTypeDescriptor; + expect(responseD.typeName.toString()).toBe('nativeBalances_Item'); + expect(responseD.ref.toString()).toBe('#/components/schemas/nativeBalances/items'); + expect(responseD.isArray).toBe(true); + + const complexType1 = result.complexTypes[0]; + const complexType1D = complexType1.descriptor; + { + expect(complexType1D.typeName.toString()).toBe('nativeBalances_Item'); + expect(complexType1D.ref.toString()).toBe('#/components/schemas/nativeBalances/items'); + expect(complexType1D.isArray).toBe(false); + + const balancesProp = complexType1.properties.find((p) => p.name === 'wallet_balances')!; + expect(balancesProp).toBeDefined(); + expect(isReferenceTypeDescriptor(balancesProp.descriptor)).toBe(true); + const balancesPropD = balancesProp.descriptor as ReferenceTypeDescriptor; + expect(balancesPropD.typeName.toString()).toBe('nativeBalances_Item_wallet_balances_Item'); + expect(balancesPropD.ref.toString()).toBe( + '#/components/schemas/nativeBalances/items/properties/wallet_balances/items', + ); + expect(balancesPropD.isArray).toBe(true); + } + + const complexType2 = result.complexTypes[1]; + const complexType2D = complexType2.descriptor; + { + expect(complexType2D.typeName.toString()).toBe('nativeBalances_Item_wallet_balances_Item'); + expect(complexType2D.ref.toString()).toBe( + '#/components/schemas/nativeBalances/items/properties/wallet_balances/items', + ); + expect(complexType2D.isArray).toBe(false); + + const addressProp = complexType2.properties.find((p) => p.name === 'address'); + expect(addressProp).toBeDefined(); + } + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.noResponse.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.noResponse.test.ts new file mode 100644 index 0000000000..88681c8dfb --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.noResponse.test.ts @@ -0,0 +1,68 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { NativeTypeDescriptor } from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('no response', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/nft/{address}/sync': { + put: { + operationId: 'syncNFTContract', + parameters: [ + { + in: 'path', + name: 'address', + required: true, + schema: { + type: 'string', + }, + }, + ], + responses: { + '201': { + description: 'Contract address was triggered for index.', + }, + }, + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + + expect(operation.operationId).toBe('syncNFTContract'); + expect(operation.httpMethod).toBe('put'); + expect(operation.routePattern).toBe('/nft/{address}/sync'); + expect(operation.response).toBeNull(); + expect(operation.body).toBeNull(); + + const parameter1 = operation.parameters[0]; + const parameter1D = parameter1.descriptor as NativeTypeDescriptor; + { + expect(parameter1.name).toBe('address'); + expect(parameter1.isRequired).toBe(true); + expect(parameter1D.isArray).toBe(false); + expect(parameter1D.nativeType).toBe('string'); + } + + expect(result.complexTypes.length).toBe(0); + expect(result.simpleTypes.length).toBe(0); + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.simpleOneOf.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.simpleOneOf.test.ts new file mode 100644 index 0000000000..07145c3719 --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.simpleOneOf.test.ts @@ -0,0 +1,108 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { ReferenceTypeDescriptor, NativeTypeDescriptor, UnionType } from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('response with simple oneOf', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/transaction/{transaction_hash}': { + get: { + operationId: 'getTransaction', + responses: { + '200': { + description: '', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/blockTransaction', + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + blockTransaction: { + required: ['to_address'], + properties: { + to_address: { + oneOf: [ + { + type: 'string', + }, + { + type: 'null', + }, + ], + description: 'The to address', + }, + }, + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + + const responseD = operation.response!.descriptor as ReferenceTypeDescriptor; + expect(responseD.isArray).toBe(false); + expect(responseD.typeName.toString()).toBe('blockTransaction'); + expect(responseD.ref.toString()).toBe('#/components/schemas/blockTransaction'); + + const complexType1 = result.complexTypes[0]; + const complexType1D = complexType1.descriptor; + { + expect(complexType1D.isArray).toBe(false); + expect(complexType1D.typeName.toString()).toBe('blockTransaction'); + expect(complexType1D.ref.toString()).toBe('#/components/schemas/blockTransaction'); + + const toAddressProp = complexType1.properties[0]; + const toAddressPropD = toAddressProp.descriptor as ReferenceTypeDescriptor; + { + expect(toAddressPropD.isArray).toBe(false); + expect(toAddressPropD.ref.toString()).toBe('#/components/schemas/blockTransaction/properties/to_address'); + expect(toAddressPropD.typeName.toString()).toBe('blockTransaction_to_address'); + } + } + + const unionType1 = result.unionTypes[0]; + const unionType1D = unionType1.descriptor; + { + expect(unionType1.unionType).toBe(UnionType.oneOf); + expect(unionType1D.isArray).toBe(false); + expect(unionType1D.isArray).toBe(false); + expect(unionType1D.ref.toString()).toBe('#/components/schemas/blockTransaction/properties/to_address'); + expect(unionType1D.typeName.toString()).toBe('blockTransaction_to_address'); + + const union1D = unionType1.unionDescriptors[0] as NativeTypeDescriptor; + expect(union1D.isArray).toBe(false); + expect(union1D.ref.toString()).toBe('#/components/schemas/blockTransaction/properties/to_address/oneOf/0'); + expect(union1D.nativeType).toBe('string'); + + const union2D = unionType1.unionDescriptors[1] as NativeTypeDescriptor; + expect(union2D.isArray).toBe(false); + expect(union2D.ref.toString()).toBe('#/components/schemas/blockTransaction/properties/to_address/oneOf/1'); + expect(union2D.nativeType).toBe('null'); + } + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.simpleStringResponse.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.simpleStringResponse.test.ts new file mode 100644 index 0000000000..3340933b6c --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.simpleStringResponse.test.ts @@ -0,0 +1,136 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { + ReferenceTypeDescriptor, + isReferenceTypeDescriptor, + isNativeTypeDescriptor, + NativeTypeDescriptor, +} from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('simple string response', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/{address}/function': { + post: { + operationId: 'runContractFunction', + requestBody: { + required: true, + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/RunContractDto', + }, + }, + }, + }, + parameters: [], + responses: { + '200': { + description: '', + content: { + 'application/json': { + schema: { + type: 'string', + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + RunContractDto: { + required: ['abi'], + properties: { + abi: { + type: 'array', + items: { + type: 'object', + }, + description: 'The contract ABI', + example: [], + }, + params: { + type: 'object', + description: 'The params for the given function', + example: {}, + }, + }, + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + + expect(isNativeTypeDescriptor(operation.response!.descriptor)).toBe(true); + const responseD = operation.response!.descriptor as NativeTypeDescriptor; + expect(responseD.isArray).toBe(false); + expect(responseD.nativeType).toBe('string'); + + expect(operation.operationId).toBe('runContractFunction'); + + const complexType1 = result.complexTypes[0]; + const complexType1D = complexType1.descriptor; + { + expect(complexType1D.typeName.toString()).toBe('RunContractDto'); + expect(complexType1D.ref.toString()).toBe('#/components/schemas/RunContractDto'); + expect(complexType1D.isArray).toBe(false); + + const abiProp = complexType1.properties[0]; + expect(abiProp.name).toBe('abi'); + expect(abiProp.isRequired).toBe(true); + expect(isReferenceTypeDescriptor(abiProp.descriptor)).toBe(true); + const abiPropD = abiProp.descriptor as ReferenceTypeDescriptor; + expect(abiPropD.isArray).toBe(true); + expect(abiPropD.ref.toString()).toBe('#/components/schemas/RunContractDto/properties/abi/items'); + expect(abiPropD.typeName.toString()).toBe('RunContractDto_abi_Item'); + + const paramsProp = complexType1.properties[1]; + expect(paramsProp.name).toBe('params'); + expect(paramsProp.isRequired).toBe(false); + expect(isReferenceTypeDescriptor(paramsProp.descriptor)).toBe(true); + const paramsPropD = paramsProp.descriptor as ReferenceTypeDescriptor; + expect(paramsPropD.isArray).toBe(false); + expect(paramsPropD.ref.toString()).toBe('#/components/schemas/RunContractDto/properties/params'); + expect(paramsPropD.typeName.toString()).toBe('RunContractDto_params'); + } + + const simpleType1 = result.simpleTypes[0]; + const simpleType1D = simpleType1.descriptor; + { + expect(simpleType1.nativeType).toBe('object'); + expect(simpleType1D.isArray).toBe(false); + expect(simpleType1D.typeName.toString()).toBe('RunContractDto_abi_Item'); + expect(simpleType1D.ref.toString()).toBe('#/components/schemas/RunContractDto/properties/abi/items'); + } + + const simpleType2 = result.simpleTypes[1]; + const simpleType2D = simpleType2.descriptor; + { + expect(simpleType2.nativeType).toBe('object'); + expect(simpleType2D.isArray).toBe(false); + expect(simpleType2D.typeName.toString()).toBe('RunContractDto_params'); + expect(simpleType2D.ref.toString()).toBe('#/components/schemas/RunContractDto/properties/params'); + } + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.singleAllOf.test.ts b/packages/apiGenerator/src/reader/OpenApiReader.singleAllOf.test.ts new file mode 100644 index 0000000000..3e0ccae499 --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.singleAllOf.test.ts @@ -0,0 +1,106 @@ +import { OpenApiReader } from './OpenApiReader'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { ReferenceTypeDescriptor, isReferenceTypeDescriptor } from './TypeDescriptor'; + +describe('OpenApiReader', () => { + it('response with single allOf', () => { + const configuration: OpenApiReaderConfiguration = { + v3: { + operations: { + groupRef: '#/operationId', + isEnabledRef: '#/operationId', + }, + }, + }; + const result = OpenApiReader.create( + { + openapi: '3.0.0', + info: { + title: 'test', + version: '1', + }, + paths: { + '/accounts/{address}/modules': { + get: { + operationId: 'getAccountModules', + parameters: [], + responses: { + '200': { + description: '', + content: { + 'application/json': { + schema: { + type: 'array', + items: { + $ref: '#/components/schemas/GetAccountModuleResponse', + }, + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + GetAccountModuleResponse: { + type: 'object', + properties: { + abi: { + description: 'A Move module', + allOf: [ + { + $ref: '#/components/schemas/MoveModuleAbi', + }, + ], + }, + }, + required: ['bytecode'], + }, + MoveModuleAbi: { + type: 'object', + properties: { + address: { + type: 'string', + }, + }, + required: ['address'], + }, + }, + }, + }, + configuration, + ).read(); + + const operation = result.operations[0]; + + expect(isReferenceTypeDescriptor(operation.response!.descriptor)).toBe(true); + const responseD = operation.response!.descriptor as ReferenceTypeDescriptor; + expect(responseD.isArray).toBe(true); + expect(responseD.typeName.toString()).toBe('GetAccountModuleResponse'); + expect(responseD.ref.toString()).toBe('#/components/schemas/GetAccountModuleResponse'); + + const complexType1 = result.complexTypes[0]; + const complexType1D = complexType1.descriptor; + { + expect(complexType1D.isArray).toBe(false); + expect(complexType1D.typeName.toString()).toBe('GetAccountModuleResponse'); + expect(complexType1D.ref.toString()).toBe('#/components/schemas/GetAccountModuleResponse'); + + const abiProp = complexType1.properties.find((p) => p.name === 'abi')!; + const abiPropD = abiProp.descriptor as ReferenceTypeDescriptor; + expect(abiPropD.isArray).toBe(false); + expect(abiPropD.typeName.toString()).toBe('MoveModuleAbi'); + expect(abiPropD.ref.toString()).toBe('#/components/schemas/MoveModuleAbi'); + } + + const complexType2 = result.complexTypes[1]; + const complexType2D = complexType2.descriptor; + { + expect(complexType2D.isArray).toBe(false); + expect(complexType2D.typeName.toString()).toBe('MoveModuleAbi'); + expect(complexType2D.ref.toString()).toBe('#/components/schemas/MoveModuleAbi'); + } + }); +}); diff --git a/packages/apiGenerator/src/reader/OpenApiReader.ts b/packages/apiGenerator/src/reader/OpenApiReader.ts new file mode 100644 index 0000000000..f28744c9ac --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReader.ts @@ -0,0 +1,30 @@ +import { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'; +import { OpenApiReaderConfiguration } from './OpenApiReaderConfiguration'; +import { OpenApiContract } from './OpenApiContract'; +import { OpenApiV3Reader } from './v3/OpenApiV3Reader'; + +export class OpenApiReader { + public static create(document: OpenAPI.Document, configuration: OpenApiReaderConfiguration): OpenApiReader { + let version = (document as OpenAPIV3.Document | OpenAPIV3_1.Document).openapi as string | undefined; + if (!version) { + version = 'unknown'; + } + + if (version.startsWith('3.0.')) { + const reader = OpenApiV3Reader.create(document as OpenAPIV3.Document, configuration.v3); + return new OpenApiReader(reader); + } + + throw new Error(`Unsupported OpenApi version: ${version}`); + } + + private constructor(private readonly reader: OpenApiVersionReader) {} + + public read(): OpenApiContract { + return this.reader.read(); + } +} + +export interface OpenApiVersionReader { + read(): OpenApiContract; +} diff --git a/packages/apiGenerator/src/reader/OpenApiReaderConfiguration.ts b/packages/apiGenerator/src/reader/OpenApiReaderConfiguration.ts new file mode 100644 index 0000000000..bf775de00d --- /dev/null +++ b/packages/apiGenerator/src/reader/OpenApiReaderConfiguration.ts @@ -0,0 +1,5 @@ +import { OpenApiV3ReaderConfiguration } from './v3/OpenApiV3ReaderConfiguration'; + +export interface OpenApiReaderConfiguration { + v3: OpenApiV3ReaderConfiguration; +} diff --git a/packages/apiGenerator/src/reader/TypeDescriptor.ts b/packages/apiGenerator/src/reader/TypeDescriptor.ts new file mode 100644 index 0000000000..fa2fe8144c --- /dev/null +++ b/packages/apiGenerator/src/reader/TypeDescriptor.ts @@ -0,0 +1,42 @@ +import { TypeName } from './utils/TypeName'; +import { JsonRef } from './utils/JsonRef'; + +export interface TypeDescriptor { + ref: JsonRef; + isArray: boolean; +} + +export interface ReferenceTypePointer { + ref: JsonRef; + typeName: TypeName; +} + +export class ReferenceTypeDescriptor implements TypeDescriptor, ReferenceTypePointer { + public constructor( + public readonly isArray: boolean, + public readonly ref: JsonRef, + public readonly typeName: TypeName, + ) {} +} + +export class NativeTypeDescriptor implements TypeDescriptor { + public constructor( + public readonly isArray: boolean, + public readonly ref: JsonRef, + public readonly nativeType: string, + ) {} +} + +export enum UnionType { + anyOf = 'anyOf', + allOf = 'allOf', + oneOf = 'oneOf', +} + +export function isReferenceTypeDescriptor(descriptor: TypeDescriptor): descriptor is ReferenceTypeDescriptor { + return Boolean((descriptor as ReferenceTypeDescriptor).typeName); +} + +export function isNativeTypeDescriptor(descriptor: TypeDescriptor): descriptor is NativeTypeDescriptor { + return Boolean((descriptor as NativeTypeDescriptor).nativeType); +} diff --git a/packages/apiGenerator/src/reader/utils/JsonRef.test.ts b/packages/apiGenerator/src/reader/utils/JsonRef.test.ts new file mode 100644 index 0000000000..793a5aeb81 --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/JsonRef.test.ts @@ -0,0 +1,32 @@ +import { JsonRef } from './JsonRef'; + +describe('JsonRef', () => { + it('serializes correctly', () => { + expect(JsonRef.from(['a', 'b', 'c']).toString()).toBe('#/a/b/c'); + }); + + it('parses correctly', () => { + const ref = JsonRef.parse('#/a/b/c'); + expect(ref.parts.length).toBe(3); + expect(ref.parts[0]).toBe('a'); + expect(ref.parts[1]).toBe('b'); + expect(ref.parts[2]).toBe('c'); + }); + + it('extends correctly', () => { + const ref = JsonRef.parse('#/a'); + expect(ref.extend(['b', 'c']).toString()).toBe('#/a/b/c'); + }); + + it('reads a child from object', () => { + const obj = { + A: { + B: { + C: 10, + }, + }, + }; + + expect(JsonRef.parse('#/A/B/C').find(obj)).toBe(10); + }); +}); diff --git a/packages/apiGenerator/src/reader/utils/JsonRef.ts b/packages/apiGenerator/src/reader/utils/JsonRef.ts new file mode 100644 index 0000000000..c771531de1 --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/JsonRef.ts @@ -0,0 +1,53 @@ +export class JsonRef { + public static parse(ref: string): JsonRef { + if (!ref) { + throw new Error('Ref is empty or null'); + } + if (!ref.startsWith('#/')) { + throw new Error('Not supported ref'); + } + return new JsonRef(ref.split('/').map(decode).slice(1)); + } + + public static from(parts: string[]): JsonRef { + return new JsonRef(parts); + } + + private constructor(public readonly parts: string[]) {} + + public toString() { + return '#/' + this.parts.map(encode).join('/'); + } + + public extend(newParts: string[]): JsonRef { + return new JsonRef(this.parts.concat(newParts)); + } + + public find(data: any): T { + const found = this.tryFind(data); + if (found === undefined) { + throw new Error(`Cannot find node by ref: ${this.toString()}`); + } + return found; + } + + public tryFind(data: any): T | undefined { + let current = data; + for (let index = 0; index < this.parts.length; index++) { + const part = this.parts[index]; + current = current[part]; + if (!current) { + return undefined; + } + } + return current as T; + } +} + +function encode(value: string): string { + return value.replace(/~/g, '~0').replace(/\//g, '~1'); +} + +function decode(value: string): string { + return value.replace(/~1/g, '/').replace(/~0/g, '~'); +} diff --git a/packages/apiGenerator/src/reader/utils/TypeName.test.ts b/packages/apiGenerator/src/reader/utils/TypeName.test.ts new file mode 100644 index 0000000000..47e491db33 --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/TypeName.test.ts @@ -0,0 +1,8 @@ +import { TypeName } from './TypeName'; + +describe('TypeName', () => { + it('serializes correctly', () => { + const name = TypeName.from('3').add('4').addPrefix('2').addPrefix('1'); + expect(name.toString()).toBe('1_2_3_4'); + }); +}); diff --git a/packages/apiGenerator/src/reader/utils/TypeName.ts b/packages/apiGenerator/src/reader/utils/TypeName.ts new file mode 100644 index 0000000000..e5ae2d4d8e --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/TypeName.ts @@ -0,0 +1,19 @@ +export class TypeName { + public static from(part: string) { + return new TypeName([part]); + } + + private constructor(public readonly parts: string[]) {} + + public addPrefix(part: string): TypeName { + return new TypeName([part].concat(this.parts)); + } + + public add(part: string): TypeName { + return new TypeName(this.parts.concat(part)); + } + + public toString(): string { + return this.parts.join('_'); + } +} diff --git a/packages/apiGenerator/src/reader/utils/TypesQueue.ts b/packages/apiGenerator/src/reader/utils/TypesQueue.ts new file mode 100644 index 0000000000..43d31c44ec --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/TypesQueue.ts @@ -0,0 +1,23 @@ +import { ReferenceTypePointer } from '../TypeDescriptor'; + +export class TypesQueue { + private readonly queue: { [key: string]: { done: boolean; pointer: ReferenceTypePointer } } = {}; + + public push(pointer: ReferenceTypePointer) { + const $ref = pointer.ref.toString(); + const current = this.queue[$ref]; + if (!current) { + this.queue[$ref] = { done: false, pointer }; + } + } + + public pop(): ReferenceTypePointer | null { + const nextKey = Object.keys(this.queue).find(($ref) => !this.queue[$ref].done); + if (!nextKey) { + return null; + } + const next = this.queue[nextKey]; + next.done = true; + return next.pointer; + } +} diff --git a/packages/apiGenerator/src/reader/utils/UniquenessChecker.test.ts b/packages/apiGenerator/src/reader/utils/UniquenessChecker.test.ts new file mode 100644 index 0000000000..525057b995 --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/UniquenessChecker.test.ts @@ -0,0 +1,18 @@ +import { UniquenessChecker } from './UniquenessChecker'; + +describe('UniquenessChecker', () => { + it('does not throw an error when values are unique', () => { + const errorFactory = () => 'Invalid error'; + const checker = new UniquenessChecker(); + checker.check('ALFA', errorFactory); + checker.check('BETA', errorFactory); + checker.check('GAMMA', errorFactory); + }); + + it('throws an error when values are duplicated', () => { + const errorFactory = () => 'DUPLICATE!'; + const checker = new UniquenessChecker(); + checker.check('ALFA', errorFactory); + expect(() => checker.check('ALFA', errorFactory)).toThrowError('DUPLICATE!'); + }); +}); diff --git a/packages/apiGenerator/src/reader/utils/UniquenessChecker.ts b/packages/apiGenerator/src/reader/utils/UniquenessChecker.ts new file mode 100644 index 0000000000..bb117de0fd --- /dev/null +++ b/packages/apiGenerator/src/reader/utils/UniquenessChecker.ts @@ -0,0 +1,10 @@ +export class UniquenessChecker { + private readonly values: string[] = []; + + public check(value: string, error: () => string) { + if (this.values.includes(value)) { + throw new Error(error()); + } + this.values.push(value); + } +} diff --git a/packages/apiGenerator/src/reader/v3/OpenApiV3Reader.ts b/packages/apiGenerator/src/reader/v3/OpenApiV3Reader.ts new file mode 100644 index 0000000000..1956977c0d --- /dev/null +++ b/packages/apiGenerator/src/reader/v3/OpenApiV3Reader.ts @@ -0,0 +1,36 @@ +import { OpenAPIV3 } from 'openapi-types'; +import { OpenApiVersionReader } from '../OpenApiReader'; +import { OpenApiContract } from '../OpenApiContract'; +import { TypesQueue } from '../utils/TypesQueue'; +import { OpenApiV3ReaderConfiguration } from './OpenApiV3ReaderConfiguration'; +import { OperationsV3Reader } from './OperationsV3Reader'; +import { TypeDescriptorV3Reader } from './TypeDescriptorV3Reader'; +import { TypesV3Reader } from './TypesV3Reader'; + +export class OpenApiV3Reader implements OpenApiVersionReader { + public static create(document: OpenAPIV3.Document, configuration: OpenApiV3ReaderConfiguration) { + return new OpenApiV3Reader(document, configuration); + } + + private constructor( + private readonly document: OpenAPIV3.Document, + private readonly configuration: OpenApiV3ReaderConfiguration, + ) {} + + public read(): OpenApiContract { + const queue = new TypesQueue(); + const typeDescriptorReader = new TypeDescriptorV3Reader(this.document); + const operationsReader = new OperationsV3Reader(this.document, typeDescriptorReader, queue, this.configuration); + const typesReader = new TypesV3Reader(this.document, typeDescriptorReader, queue); + + operationsReader.read(); + typesReader.read(); + + return { + operations: operationsReader.operations, + complexTypes: typesReader.complexTypes, + simpleTypes: typesReader.simpleTypes, + unionTypes: typesReader.unionTypes, + }; + } +} diff --git a/packages/apiGenerator/src/reader/v3/OpenApiV3ReaderConfiguration.ts b/packages/apiGenerator/src/reader/v3/OpenApiV3ReaderConfiguration.ts new file mode 100644 index 0000000000..e421505ede --- /dev/null +++ b/packages/apiGenerator/src/reader/v3/OpenApiV3ReaderConfiguration.ts @@ -0,0 +1,15 @@ +export interface OpenApiV3ReaderConfiguration { + operations: { + groupRef: string; + isEnabledRef: string; + virtualParameters?: VirtualParameter[]; + }; +} + +export interface VirtualParameter { + operationId?: string; + name: string; + isRequired: boolean; + nativeType: string; + description?: string; +} diff --git a/packages/apiGenerator/src/reader/v3/OperationsV3Reader.ts b/packages/apiGenerator/src/reader/v3/OperationsV3Reader.ts new file mode 100644 index 0000000000..295715f9c8 --- /dev/null +++ b/packages/apiGenerator/src/reader/v3/OperationsV3Reader.ts @@ -0,0 +1,214 @@ +import { OpenAPIV3 } from 'openapi-types'; +import { JsonRef } from '../utils/JsonRef'; +import { isReferenceTypeDescriptor, NativeTypeDescriptor } from '../TypeDescriptor'; +import { UniquenessChecker } from '../utils/UniquenessChecker'; +import { OperationBodyInfo, OperationInfo, OperationResponseInfo, ParameterInfo } from '../OpenApiContract'; +import { TypeDescriptorV3Reader } from './TypeDescriptorV3Reader'; +import { TypesQueue } from '../utils/TypesQueue'; +import { TypeName } from '../utils/TypeName'; +import { OpenApiV3ReaderConfiguration } from './OpenApiV3ReaderConfiguration'; + +const SUCCESS_RESPONSE_CODES = ['200', '201', '202', '203', '204', '205']; +const BODY_TYPE_NAME_SUFFIX = 'Body'; + +export class OperationsV3Reader { + public readonly operations: OperationInfo[] = []; + + public constructor( + private readonly document: OpenAPIV3.Document, + private readonly typeDescriptorReader: TypeDescriptorV3Reader, + private readonly queue: TypesQueue, + private readonly configuration: OpenApiV3ReaderConfiguration, + ) {} + + public read() { + if (!this.document.paths) { + return; + } + + const operationIdUniquenessChecker = new UniquenessChecker(); + const groupRef = JsonRef.parse(this.configuration.operations.groupRef); + const isEnabledRef = JsonRef.parse(this.configuration.operations.isEnabledRef); + + for (const routePattern of Object.keys(this.document.paths)) { + const pathGroup = this.document.paths[routePattern]; + if (!pathGroup) { + continue; + } + + const operationHttpMethods = Object.keys(pathGroup) as OpenAPIV3.HttpMethods[]; + for (const httpMethod of operationHttpMethods) { + const path = pathGroup[httpMethod]!; + if (!path.operationId) { + console.warn(`[no-operation-id] Path ${routePattern} does not have operationId`); + continue; + } + + operationIdUniquenessChecker.check(path.operationId, () => `Operation id ${path.operationId} is duplicated`); + + const responseCode = SUCCESS_RESPONSE_CODES.find((code) => path.responses[code]); + if (!responseCode) { + const supportedCodes = Object.keys(path.responses).join(', '); + console.warn( + `[no-success-response] Path ${routePattern} does not have any success response (found: ${supportedCodes})`, + ); + continue; + } + + const isEnabled = isEnabledRef.tryFind(path); + if (!isEnabled) { + continue; + } + + const operationRef = JsonRef.from(['paths', routePattern, httpMethod]); + + const responseBody = path.responses[responseCode] as OpenAPIV3.ResponseObject; + const response = this.readResponse(operationRef, path.operationId, responseCode, responseBody); + + const parameters = this.readParameters(operationRef, path.operationId, path.parameters); + const body = this.readBody(operationRef, path.operationId, path.requestBody); + + const groupName = groupRef.find(path); + + this.operations.push({ + operationId: path.operationId, + groupName, + description: path.description, + httpMethod, + routePattern, + response, + body, + parameters, + }); + } + } + } + + private readParameters( + operationRef: JsonRef, + operationId: string, + parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[], + ) { + const result: ParameterInfo[] = []; + if (!parameters) { + return result; + } + + const parameterNameUniquenessChecker = new UniquenessChecker(); + for (let index = 0; index < parameters.length; index++) { + const $refOrParameter = parameters[index]; + if (($refOrParameter as OpenAPIV3.ReferenceObject).$ref) { + throw new Error('Not supported $ref parameters'); + } + + const parameter = $refOrParameter as OpenAPIV3.ParameterObject; + const schema = parameter.schema; + if (!schema) { + throw new Error('Parameter does not have schema'); + } + + parameterNameUniquenessChecker.check( + parameter.name, + () => `Parameter name ${parameter.name} is duplicated (${operationRef.toString()})`, + ); + + const ref = operationRef.extend(['parameters', String(index), 'schema']); + const defaultTypeName = TypeName.from(operationId).add(parameter.name); + const descriptor = this.typeDescriptorReader.read(schema, ref, defaultTypeName); + if (isReferenceTypeDescriptor(descriptor)) { + this.queue.push(descriptor); + } + + result.push({ + name: parameter.name, + isRequired: parameter.required || false, + descriptor: descriptor, + description: parameter.description, + }); + } + + if (this.configuration.operations.virtualParameters) { + for (const virtualParameter of this.configuration.operations.virtualParameters) { + if (virtualParameter.operationId && virtualParameter.operationId !== operationId) { + continue; + } + + parameterNameUniquenessChecker.check( + virtualParameter.name, + () => `Virtual parameter name ${virtualParameter.name} is duplicated (${operationRef.toString()})`, + ); + + const virtualDescriptor: NativeTypeDescriptor = { + ref: JsonRef.from(['virtualParameter', virtualParameter.name]), + isArray: false, + nativeType: virtualParameter.nativeType, + }; + result.push({ + name: virtualParameter.name, + isRequired: virtualParameter.isRequired, + descriptor: virtualDescriptor, + description: virtualParameter.description, + }); + } + } + return result; + } + + private readResponse( + operationRef: JsonRef, + operationId: string, + responseCode: string, + response: OpenAPIV3.ResponseObject, + ): OperationResponseInfo | null { + const json = response.content ? response.content['application/json'] : null; + const $refOrSchema = json ? json.schema : null; + if (!$refOrSchema) { + console.warn(`[no-response] Operation ${operationId} does not have a response`); + return null; + } + + const defaultTypeName = TypeName.from(operationId); + const ref = operationRef.extend(['responses', responseCode, 'content', 'application/json', 'schema']); + + const descriptor = this.typeDescriptorReader.read($refOrSchema, ref, defaultTypeName); + if (isReferenceTypeDescriptor(descriptor)) { + this.queue.push(descriptor); + } + + return { + descriptor, + }; + } + + private readBody( + operationRef: JsonRef, + operationId: string, + $refOrBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject, + ): OperationBodyInfo | null { + if (!$refOrBody) { + return null; + } + if (($refOrBody as OpenAPIV3.ReferenceObject).$ref) { + throw new Error('Not supported $ref request body'); + } + + const body = $refOrBody as OpenAPIV3.RequestBodyObject; + const bodyJson = body.content['application/json']; + const $refOrSchema = bodyJson ? bodyJson.schema : null; + if (!$refOrSchema) { + return null; + } + + const ref = operationRef.extend(['requestBody', 'content', 'application/json', 'schema']); + const defaultTypeName = TypeName.from(operationId).add(BODY_TYPE_NAME_SUFFIX); + const descriptor = this.typeDescriptorReader.read($refOrSchema, ref, defaultTypeName); + if (isReferenceTypeDescriptor(descriptor)) { + this.queue.push(descriptor); + } + + return { + descriptor, + isRequired: body.required || false, + }; + } +} diff --git a/packages/apiGenerator/src/reader/v3/TypeDescriptorV3Reader.ts b/packages/apiGenerator/src/reader/v3/TypeDescriptorV3Reader.ts new file mode 100644 index 0000000000..267c5b87d2 --- /dev/null +++ b/packages/apiGenerator/src/reader/v3/TypeDescriptorV3Reader.ts @@ -0,0 +1,94 @@ +import { OpenAPIV3 } from 'openapi-types'; +import { JsonRef } from '../utils/JsonRef'; +import { ReferenceTypeDescriptor, NativeTypeDescriptor, TypeDescriptor } from '../TypeDescriptor'; +import { TypeName } from '../utils/TypeName'; +import { UnionV3Reader } from './UnionV3Reader'; + +const ITEM_TYPE_NAME_SUFFIX = 'Item'; +const COMPONENT_SCHEMA_$REF_PREFIX = '#/components/schemas/'; + +export class TypeDescriptorV3Reader { + public constructor(private readonly document: OpenAPIV3.Document) {} + + public read( + $refOrSchema: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, + parentRef: JsonRef, + defaultTypeName: TypeName, + ): TypeDescriptor { + const $ref = ($refOrSchema as OpenAPIV3.ReferenceObject).$ref; + if ($ref) { + const ref = JsonRef.parse($ref); + let typeName = readTypeNameFromRef($ref); + + const targetSchema = ref.find(this.document); + if (targetSchema.type === 'array') { + const itemTypeName = typeName.add(ITEM_TYPE_NAME_SUFFIX); + return new ReferenceTypeDescriptor(true, ref.extend(['items']), itemTypeName); + } + + return new ReferenceTypeDescriptor(false, ref, typeName); + } + + const schema = $refOrSchema as OpenAPIV3.SchemaObject; + if (schema.type === 'array') { + const items$ref = (schema.items as OpenAPIV3.ReferenceObject).$ref; + if (items$ref) { + const itemsRef = JsonRef.parse(items$ref); + const typeName = readTypeNameFromRef(items$ref); + return new ReferenceTypeDescriptor(true, itemsRef, typeName); + } + + const itemsSchema = schema.items as OpenAPIV3.SchemaObject; + if (itemsSchema.type === 'object') { + const itemTypeName = defaultTypeName.add(ITEM_TYPE_NAME_SUFFIX); + return new ReferenceTypeDescriptor(true, parentRef.extend(['items']), itemTypeName); + } + if (itemsSchema.type === 'array') { + const itemTypeName = defaultTypeName.add(ITEM_TYPE_NAME_SUFFIX); + return new ReferenceTypeDescriptor(true, parentRef.extend(['items']), itemTypeName); + } + + const itemsUnion = UnionV3Reader.tryRead(itemsSchema); + if (itemsUnion) { + const itemTypeName = defaultTypeName.add(ITEM_TYPE_NAME_SUFFIX); + return new ReferenceTypeDescriptor(true, parentRef.extend(['items']), itemTypeName); + } + + if (!itemsSchema.type) { + itemsSchema.type = 'string'; + console.warn(`[no-schema-type] Items schema has empty type, set string as default (${parentRef})`); + } + return new NativeTypeDescriptor(true, parentRef, itemsSchema.type); + } + + if (schema.type === 'object') { + return new ReferenceTypeDescriptor(false, parentRef, defaultTypeName); + } + + const union = UnionV3Reader.tryRead(schema); + if (union) { + if (union.$refsOrSchemas.length === 1) { + // We reduce single union to single type. + const itemRef = parentRef.extend([union.unionType, '0']); + return this.read(union.$refsOrSchemas[0], itemRef, defaultTypeName); + } + return new ReferenceTypeDescriptor(false, parentRef, defaultTypeName); + } + + if (!schema.type) { + schema.type = 'string'; + console.warn( + `[no-schema-type] Schema has empty type, set string as default (${parentRef}) [${Object.keys(schema)}]`, + ); + } + return new NativeTypeDescriptor(false, parentRef, schema.type); + } +} + +function readTypeNameFromRef($ref: string): TypeName { + if ($ref.startsWith(COMPONENT_SCHEMA_$REF_PREFIX)) { + const name = $ref.substring(COMPONENT_SCHEMA_$REF_PREFIX.length); + return TypeName.from(name); + } + throw new Error(`Not supported $ref: ${$ref}`); +} diff --git a/packages/apiGenerator/src/reader/v3/TypesV3Reader.ts b/packages/apiGenerator/src/reader/v3/TypesV3Reader.ts new file mode 100644 index 0000000000..c13b517943 --- /dev/null +++ b/packages/apiGenerator/src/reader/v3/TypesV3Reader.ts @@ -0,0 +1,129 @@ +import { OpenAPIV3 } from 'openapi-types'; +import { ComplexTypeInfo, PropertyInfo, SimpleTypeInfo, UnionTypeInfo } from '../OpenApiContract'; +import { isReferenceTypeDescriptor, ReferenceTypeDescriptor, ReferenceTypePointer } from '../TypeDescriptor'; +import { UniquenessChecker } from '../utils/UniquenessChecker'; +import { TypesQueue } from '../utils/TypesQueue'; +import { TypeDescriptorV3Reader } from './TypeDescriptorV3Reader'; +import { UnionInfo, UnionV3Reader } from './UnionV3Reader'; + +export class TypesV3Reader { + public readonly complexTypes: ComplexTypeInfo[] = []; + public readonly simpleTypes: SimpleTypeInfo[] = []; + public readonly unionTypes: UnionTypeInfo[] = []; + private readonly typeNameUniquenessChecker = new UniquenessChecker(); + + public constructor( + private readonly document: OpenAPIV3.Document, + private readonly typeDescriptorReader: TypeDescriptorV3Reader, + private readonly queue: TypesQueue, + ) {} + + public read() { + let pointer: ReferenceTypePointer | null = null; + do { + pointer = this.queue.pop(); + if (pointer) { + this.readPointer(pointer); + } + } while (pointer); + } + + private readPointer(pointer: ReferenceTypePointer) { + const scheme = pointer.ref.find(this.document); + + if (scheme.type && scheme.type === 'array') { + throw new Error(`Array complex type is not supported yet (${pointer.ref})`); + } + + const typeName = pointer.typeName.toString(); + this.typeNameUniquenessChecker.check(typeName, () => `Type name ${typeName} is duplicated`); + + const union = UnionV3Reader.tryRead(scheme); + if (union) { + this.readUnionType(pointer, union); + } else { + this.readComplexType(scheme, pointer); + } + } + + private readUnionType(pointer: ReferenceTypePointer, union: UnionInfo) { + const unionDescriptors = union.$refsOrSchemas.map(($ros, index) => { + const itemRef = pointer.ref.extend([union.unionType, String(index)]); + const itemDefaultName = pointer.typeName.add(String(index)); + const descriptor = this.typeDescriptorReader.read($ros, itemRef, itemDefaultName); + if (isReferenceTypeDescriptor(descriptor)) { + this.queue.push(descriptor); + } + return descriptor; + }); + + this.unionTypes.push({ + descriptor: { + isArray: false, + ref: pointer.ref, + typeName: pointer.typeName, + }, + unionType: union.unionType, + unionDescriptors, + }); + } + + private readComplexType(scheme: OpenAPIV3.SchemaObject, pointer: ReferenceTypePointer) { + const descriptor: ReferenceTypeDescriptor = { + isArray: false, + typeName: pointer.typeName, + ref: pointer.ref, + }; + + const propertyKeys = scheme.properties ? Object.keys(scheme.properties) : []; + if (!scheme.properties || propertyKeys.length < 1) { + if (scheme.anyOf || scheme.allOf || scheme.anyOf) { + throw new Error(`anyOf, allOf and anyOf is not supported (${pointer.ref})`); + } + + let simpleType = scheme.type; + if (!simpleType) { + simpleType = 'object'; + console.warn(`[no-schema-type] Not defined schema type for complex type (${pointer.ref.toString()})`); + } + + this.simpleTypes.push({ + descriptor, + nativeType: simpleType, + enum: scheme.enum as string[] | undefined, + }); + return; + } + + const propertyNameUniquenessChecker = new UniquenessChecker(); + const properties: PropertyInfo[] = []; + for (const name of propertyKeys) { + const ref = pointer.ref.extend(['properties', name]); + + propertyNameUniquenessChecker.check(name, () => `Parameter name ${name} is duplicated (${ref.toString()})`); + + const isRequired = scheme.required?.includes(name) || false; + const refOrSchema = scheme.properties[name]; + + const defaultTypeName = pointer.typeName.add(name); + const descriptor = this.typeDescriptorReader.read(refOrSchema, ref, defaultTypeName); + if (isReferenceTypeDescriptor(descriptor)) { + this.queue.push(descriptor); + } + + const description = (refOrSchema as OpenAPIV3.SchemaObject).description; + + properties.push({ + name, + isRequired, + descriptor, + description, + }); + } + + this.complexTypes.push({ + descriptor, + properties, + }); + } +} diff --git a/packages/apiGenerator/src/reader/v3/UnionV3Reader.ts b/packages/apiGenerator/src/reader/v3/UnionV3Reader.ts new file mode 100644 index 0000000000..66b559b803 --- /dev/null +++ b/packages/apiGenerator/src/reader/v3/UnionV3Reader.ts @@ -0,0 +1,31 @@ +import { OpenAPIV3 } from 'openapi-types'; +import { UnionType } from '../TypeDescriptor'; + +export interface UnionInfo { + $refsOrSchemas: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[]; + unionType: UnionType; +} + +export class UnionV3Reader { + public static tryRead(schema: OpenAPIV3.NonArraySchemaObject): UnionInfo | null { + if (schema.allOf) { + return { + $refsOrSchemas: schema.allOf, + unionType: UnionType.allOf, + }; + } + if (schema.anyOf) { + return { + $refsOrSchemas: schema.anyOf, + unionType: UnionType.anyOf, + }; + } + if (schema.oneOf) { + return { + $refsOrSchemas: schema.oneOf, + unionType: UnionType.oneOf, + }; + } + return null; + } +} diff --git a/packages/apiGenerator/tsconfig.json b/packages/apiGenerator/tsconfig.json new file mode 100644 index 0000000000..4469c6d7ff --- /dev/null +++ b/packages/apiGenerator/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "strict": true, + "module": "commonjs", + "outDir": "build", + "baseUrl": ".", + "rootDir": "src", + "declaration": true, + "declarationDir": "build", + "sourceMap": true, + "target": "es2017", + "esModuleInterop": true, + "useUnknownInCatchVariables": false, + "skipLibCheck": true + }, + "include": ["src"] +} diff --git a/packages/apiUtils/src/resolvers2/index.ts b/packages/apiUtils/src/resolvers2/index.ts index 342c42f147..335f0a30c0 100644 --- a/packages/apiUtils/src/resolvers2/index.ts +++ b/packages/apiUtils/src/resolvers2/index.ts @@ -1,3 +1,4 @@ +export * from './getSdkDetailsHeaders'; export * from './OperationResolver'; export * from './NullableOperationResolver'; export * from './PaginatedOperationResolver'; diff --git a/packages/aptosApi/.eslintrc.js b/packages/aptosApi/.eslintrc.js new file mode 100644 index 0000000000..92cea72b04 --- /dev/null +++ b/packages/aptosApi/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + extends: ['@moralisweb3'], + plugins: ['jest'], + ignorePatterns: ['**/lib/**/*', '**/*.test.ts', '**/dist/**/*', '**/build/**/*', '**/generated/**/*'], +}; diff --git a/packages/aptosApi/README.md b/packages/aptosApi/README.md new file mode 100644 index 0000000000..cd4d01cbd4 --- /dev/null +++ b/packages/aptosApi/README.md @@ -0,0 +1,3 @@ +# @moralisweb3/apt-api + +This package contains API client for Aptos API. diff --git a/packages/aptosApi/integration/mocks/config.ts b/packages/aptosApi/integration/mocks/config.ts new file mode 100644 index 0000000000..52ff8927be --- /dev/null +++ b/packages/aptosApi/integration/mocks/config.ts @@ -0,0 +1,2 @@ +export const MOCK_API_KEY = 'test-api-key'; +export const APTOS_API_ROOT = 'https://aptos-mainnet.aws-prod-api-1.moralis.io'; diff --git a/packages/aptosApi/integration/mocks/endpoints/accounts.getAccount.ts b/packages/aptosApi/integration/mocks/endpoints/accounts.getAccount.ts new file mode 100644 index 0000000000..2d19ffaace --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/accounts.getAccount.ts @@ -0,0 +1,23 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetAccount = MockScenarios.create( + { + method: 'get', + name: 'mockGetAccount', + url: `/accounts/:address`, + getParams: ({ req }) => ({ + address: req.params.address, + }), + }, + [ + { + condition: { + address: '0x7abf3bc917c75e13b2225417aa1b008a4c1b1a6b487739ad0a39ef847b9c2f8e', + }, + response: { + sequence_number: '0', + authentication_key: '0x7abf3bc917c75e13b2225417aa1b008a4c1b1a6b487739ad0a39ef847b9c2f8e', + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/accounts.getAccountModule.ts b/packages/aptosApi/integration/mocks/endpoints/accounts.getAccountModule.ts new file mode 100644 index 0000000000..2680b877a6 --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/accounts.getAccountModule.ts @@ -0,0 +1,53 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetAccountModule = MockScenarios.create( + { + method: 'get', + name: 'mockGetAccountModule', + url: `/accounts/:address/resource/:module_name`, + getParams: ({ req }) => ({ + address: req.params.address, + moduleName: req.params.module_name, + }), + }, + [ + { + condition: { + address: '0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1', + moduleName: 'module_name_todo', + }, + response: { + bytecode: '0xbytecode_todo', + abi: { + address: '0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1', + name: 'string', + friends: ['0x1::aptos_coin'], + exposed_functions: [ + { + name: 'string', + visibility: 'private', + is_entry: true, + generic_type_params: [{ constraints: ['todo_x1'] }], + params: ['string'], + return: ['string'], + }, + ], + structs: [ + { + name: 'string', + is_native: true, + abilities: ['string'], + generic_type_params: [{ constraints: ['todo_x1'] }], + fields: [ + { + name: 'string', + type: 'string', + }, + ], + }, + ], + }, + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/blocks.getBlockByHeight.ts b/packages/aptosApi/integration/mocks/endpoints/blocks.getBlockByHeight.ts new file mode 100644 index 0000000000..9e5f2acddc --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/blocks.getBlockByHeight.ts @@ -0,0 +1,559 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetBlockByHeight = MockScenarios.create( + { + method: 'get', + name: 'mockGetBlockByHeight', + url: `/blocks/{block_height}`, + getParams: ({ req }) => ({ + blockHeight: req.params.block_height, + withTransactions: req.url.searchParams.get('with_transactions'), + }), + }, + [ + { + condition: { + blockHeight: '499540', + withTransactions: true, + }, + response: { + block_height: '499540', + block_hash: '0x5a5f8cd83acd6248c90108e5f21fc60b9efca44890aac91d66da02c03913ac9b', + block_timestamp: '1665858020377412', + first_version: '999999', + last_version: '1000000', + transactions: [ + { + version: '999999', + hash: '0xa64930fb0e18d93bd9183d262457cf0d7c27b52ca01d02fb8d736812b9e7454d', + state_change_hash: '0xfac8fd76f793c857e4d1055e34b5d0a3896a01bfdade7c910f6a35cd93012802', + event_root_hash: '0xf8ea6589995ae4479b04f4c5683d18991e86c7c8de86d317279591a8f5792cfa', + state_checkpoint_hash: null, + gas_used: '0', + success: true, + vm_status: 'Executed successfully', + accumulator_root_hash: '0xdfa2cd5d5455cee92a4727913a8ad2f7691ec9c53f54d36e275897ea413976de', + changes: [ + { + address: '0x1', + state_key_hash: '0x5ddf404c60e96e9485beafcabb95609fed8e38e941a725cae4dcec8296fb32d7', + data: { + type: '0x1::block::BlockResource', + data: { + epoch_interval: '7200000000', + height: '499540', + new_block_events: { + counter: '499541', + guid: { + id: { + addr: '0x1', + creation_num: '3', + }, + }, + }, + update_epoch_interval_events: { + counter: '0', + guid: { + id: { + addr: '0x1', + creation_num: '4', + }, + }, + }, + }, + }, + type: 'write_resource', + }, + { + address: '0x1', + state_key_hash: '0x8048c954221814b04533a9f0a9946c3a8d472ac62df5accb9f47c097e256e8b6', + data: { + type: '0x1::stake::ValidatorPerformance', + data: { + validators: [ + { + failed_proposals: '0', + successful_proposals: '11', + }, + { + failed_proposals: '0', + successful_proposals: '19', + }, + { + failed_proposals: '0', + successful_proposals: '18', + }, + { + failed_proposals: '0', + successful_proposals: '8', + }, + { + failed_proposals: '0', + successful_proposals: '8', + }, + { + failed_proposals: '0', + successful_proposals: '40', + }, + { + failed_proposals: '0', + successful_proposals: '24', + }, + { + failed_proposals: '0', + successful_proposals: '8', + }, + { + failed_proposals: '0', + successful_proposals: '16', + }, + { + failed_proposals: '0', + successful_proposals: '25', + }, + { + failed_proposals: '0', + successful_proposals: '31', + }, + { + failed_proposals: '0', + successful_proposals: '50', + }, + { + failed_proposals: '0', + successful_proposals: '37', + }, + { + failed_proposals: '0', + successful_proposals: '44', + }, + { + failed_proposals: '0', + successful_proposals: '102', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '9', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '10', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '186', + }, + { + failed_proposals: '0', + successful_proposals: '183', + }, + { + failed_proposals: '0', + successful_proposals: '173', + }, + { + failed_proposals: '0', + successful_proposals: '179', + }, + { + failed_proposals: '0', + successful_proposals: '203', + }, + { + failed_proposals: '0', + successful_proposals: '164', + }, + { + failed_proposals: '0', + successful_proposals: '183', + }, + { + failed_proposals: '0', + successful_proposals: '197', + }, + { + failed_proposals: '0', + successful_proposals: '165', + }, + { + failed_proposals: '0', + successful_proposals: '170', + }, + { + failed_proposals: '0', + successful_proposals: '124', + }, + { + failed_proposals: '0', + successful_proposals: '13', + }, + { + failed_proposals: '0', + successful_proposals: '6', + }, + { + failed_proposals: '0', + successful_proposals: '13', + }, + { + failed_proposals: '0', + successful_proposals: '6', + }, + { + failed_proposals: '0', + successful_proposals: '11', + }, + { + failed_proposals: '0', + successful_proposals: '13', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '14', + }, + { + failed_proposals: '0', + successful_proposals: '9', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '205', + }, + { + failed_proposals: '0', + successful_proposals: '9', + }, + { + failed_proposals: '0', + successful_proposals: '173', + }, + { + failed_proposals: '0', + successful_proposals: '13', + }, + { + failed_proposals: '0', + successful_proposals: '11', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '163', + }, + { + failed_proposals: '0', + successful_proposals: '208', + }, + { + failed_proposals: '0', + successful_proposals: '10', + }, + { + failed_proposals: '0', + successful_proposals: '8', + }, + { + failed_proposals: '0', + successful_proposals: '46', + }, + { + failed_proposals: '0', + successful_proposals: '6', + }, + { + failed_proposals: '0', + successful_proposals: '130', + }, + { + failed_proposals: '0', + successful_proposals: '19', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '8', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '174', + }, + { + failed_proposals: '0', + successful_proposals: '181', + }, + { + failed_proposals: '0', + successful_proposals: '127', + }, + { + failed_proposals: '0', + successful_proposals: '164', + }, + { + failed_proposals: '0', + successful_proposals: '8', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '32', + }, + { + failed_proposals: '0', + successful_proposals: '6', + }, + { + failed_proposals: '0', + successful_proposals: '11', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '6', + }, + { + failed_proposals: '0', + successful_proposals: '69', + }, + { + failed_proposals: '0', + successful_proposals: '29', + }, + { + failed_proposals: '0', + successful_proposals: '29', + }, + { + failed_proposals: '0', + successful_proposals: '26', + }, + { + failed_proposals: '0', + successful_proposals: '12', + }, + { + failed_proposals: '0', + successful_proposals: '180', + }, + { + failed_proposals: '0', + successful_proposals: '175', + }, + { + failed_proposals: '0', + successful_proposals: '10', + }, + { + failed_proposals: '0', + successful_proposals: '186', + }, + { + failed_proposals: '0', + successful_proposals: '12', + }, + { + failed_proposals: '0', + successful_proposals: '6', + }, + { + failed_proposals: '0', + successful_proposals: '190', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '172', + }, + { + failed_proposals: '0', + successful_proposals: '57', + }, + { + failed_proposals: '0', + successful_proposals: '48', + }, + { + failed_proposals: '0', + successful_proposals: '183', + }, + { + failed_proposals: '0', + successful_proposals: '155', + }, + { + failed_proposals: '0', + successful_proposals: '153', + }, + { + failed_proposals: '0', + successful_proposals: '7', + }, + { + failed_proposals: '0', + successful_proposals: '5', + }, + { + failed_proposals: '0', + successful_proposals: '165', + }, + { + failed_proposals: '0', + successful_proposals: '173', + }, + { + failed_proposals: '0', + successful_proposals: '181', + }, + { + failed_proposals: '0', + successful_proposals: '131', + }, + { + failed_proposals: '0', + successful_proposals: '137', + }, + { + failed_proposals: '0', + successful_proposals: '22', + }, + { + failed_proposals: '0', + successful_proposals: '146', + }, + { + failed_proposals: '0', + successful_proposals: '10', + }, + ], + }, + }, + type: 'write_resource', + }, + { + address: '0x1', + state_key_hash: '0x7b1615bf012d3c94223f3f76287ee2f7bdf31d364071128b256aeff0841b626d', + data: { + type: '0x1::timestamp::CurrentTimeMicroseconds', + data: { + microseconds: '1665858020377412', + }, + }, + type: 'write_resource', + }, + ], + id: '0x5a5f8cd83acd6248c90108e5f21fc60b9efca44890aac91d66da02c03913ac9b', + epoch: '36', + round: '6952', + events: [ + { + guid: { + creation_number: '3', + account_address: '0x1', + }, + sequence_number: '499540', + type: '0x1::block::NewBlockEvent', + data: { + epoch: '36', + failed_proposer_indices: [], + hash: '0x5a5f8cd83acd6248c90108e5f21fc60b9efca44890aac91d66da02c03913ac9b', + height: '499540', + previous_block_votes_bitvec: '0xfdff091380163cc775ff6a93e0', + proposer: '0xc29a231581f243ddcbf97de8b93c8aabb466dd6912ce5ba12579ff2f13cb8da5', + round: '6952', + time_microseconds: '1665858020377412', + }, + }, + ], + previous_block_votes_bitvec: [253, 255, 9, 19, 128, 22, 60, 199, 117, 255, 106, 147, 224], + proposer: '0xc29a231581f243ddcbf97de8b93c8aabb466dd6912ce5ba12579ff2f13cb8da5', + failed_proposer_indices: [], + timestamp: '1665858020377412', + type: 'block_metadata_transaction', + }, + { + version: '1000000', + hash: '0x01dd79a7ed3b885cbb2ad05fbe410963b8a8d92dadace11851233e76b533158b', + state_change_hash: '0xafb6e14fe47d850fd0a7395bcfb997ffacf4715e0f895cc162c218e4a7564bc6', + event_root_hash: '0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000', + state_checkpoint_hash: '0x2e2476f44b95e361bde7236b0d72d66de862d4f3caca142cf33df34332370e15', + gas_used: '0', + success: true, + vm_status: 'Executed successfully', + accumulator_root_hash: '0xd9cfc4fb3f9f7f0be494ba0e0cc4ceadb6cd61da1865e82881250ca6749ac474', + changes: [], + timestamp: '1665858020377412', + type: 'state_checkpoint_transaction', + }, + ], + __headers: { + date: 'Fri, 10 Mar 2023 08:49:46 GMT', + 'content-type': 'application/json', + 'content-length': '8372', + connection: 'close', + 'x-aptos-chain-id': '1', + 'x-aptos-ledger-version': '99731525', + 'x-aptos-ledger-oldest-version': '0', + 'x-aptos-ledger-timestampusec': '1678438185336840', + 'x-aptos-epoch': '1786', + 'x-aptos-block-height': '38227763', + 'x-aptos-oldest-block-height': '0', + }, + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/coins.getCoinInfoByCoinTypeHashes.ts b/packages/aptosApi/integration/mocks/endpoints/coins.getCoinInfoByCoinTypeHashes.ts new file mode 100644 index 0000000000..127828d124 --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/coins.getCoinInfoByCoinTypeHashes.ts @@ -0,0 +1,34 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetCoinInfoByCoinTypeHashes = MockScenarios.create( + { + method: 'get', + name: 'mockGetCoinInfoByCoinTypeHashes', + url: `/coins`, + getParams: ({ req }) => ({ + coinTypeHashes: req.url.searchParams.get('coin_type_hashes[]'), + }), + }, + [ + { + condition: { + coinTypeHashes: '069476fd0e9663039084fcd721540374c2313c9f0dffe81130970774a22855c3', + }, + response: [ + { + coin_type: + '0x5a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948::lp_coin::LP<0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::UsdtCoin, 0x1::aptos_coin::AptosCoin, 0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated>', + coin_type_hash: '069476fd0e9663039084fcd721540374c2313c9f0dffe81130970774a22855c3', + creator_address: '0x5a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948', + decimals: 6, + name: 'LiquidLP-USDT-APT-U', + supply_aggregator_table_handle: null, + supply_aggregator_table_key: null, + symbol: 'USDT-APT', + transaction_created_timestamp: '2023-02-07T08:54:55.000Z', + transaction_version_created: '83401661', + }, + ], + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/coins.getLatestCoins.ts b/packages/aptosApi/integration/mocks/endpoints/coins.getLatestCoins.ts new file mode 100644 index 0000000000..e96e1f7f88 --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/coins.getLatestCoins.ts @@ -0,0 +1,51 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetLatestCoins = MockScenarios.create( + { + method: 'get', + name: 'mockGetLatestCoins', + url: `/coins/latest`, + getParams: ({ req }) => ({ + limit: req.url.searchParams.get('limit'), + }), + }, + [ + { + condition: { + limit: '2', + }, + response: { + cursor: 'cursor!', + hasNextPage: true, + result: [ + { + coin_type: + '0x5a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948::lp_coin::LP<0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::UsdtCoin, 0x1::aptos_coin::AptosCoin, 0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated>', + coin_type_hash: '069476fd0e9663039084fcd721540374c2313c9f0dffe81130970774a22855c3', + name: 'LiquidLP-USDT-APT-U', + creator_address: '0x5a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948', + decimals: 6, + supply_aggregator_table_handle: null, + supply_aggregator_table_key: null, + symbol: 'USDT-APT', + transaction_created_timestamp: '2023-02-07T08:54:55.000Z', + transaction_version_created: '83401661', + }, + { + coin_type: + '0xd1c6deb6d98cd356a160c901909a282f1478c547d5ae3154a5f54ff0c25f49c3::vault::IbToken<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT>', + coin_type_hash: 'ed9bd9c81d49a0ed7f5c6b5ecf597bb23cd54c7dd0b67c3ccba2b3f0804b8bb0', + name: 'IblzUSDT', + creator_address: '0xd1c6deb6d98cd356a160c901909a282f1478c547d5ae3154a5f54ff0c25f49c3', + decimals: 6, + supply_aggregator_table_handle: null, + supply_aggregator_table_key: null, + symbol: 'IblzUSDT', + transaction_created_timestamp: '2023-02-07T08:12:00.000Z', + transaction_version_created: '83386839', + }, + ], + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/coins.getTopHoldersByCoin.ts b/packages/aptosApi/integration/mocks/endpoints/coins.getTopHoldersByCoin.ts new file mode 100644 index 0000000000..0a32b8cd3b --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/coins.getTopHoldersByCoin.ts @@ -0,0 +1,42 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetTopHoldersByCoin = MockScenarios.create( + { + method: 'get', + name: 'mockGetTopHoldersByCoin', + url: `/coins/owners/:coin_type_hash/top-holders`, + getParams: ({ req }) => ({ + coinTypeHash: req.params.coin_type_hash, + limit: req.url.searchParams.get('limit'), + }), + }, + [ + { + condition: { + coinTypeHash: '91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6', + limit: '2', + }, + response: { + hasNextPage: false, + result: [ + { + amount: '5203986610945473', + coin_type_hash: '91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6', + owner_address: '0xc739507214d0e1bf9795485299d709e00024e92f7c0d055a4c2c39717882bdfd', + coin_type: '0x1::aptos_coin::AptosCoin', + last_transaction_timestamp: '2023-02-02T18:55:40.000Z', + last_transaction_version: '81068073', + }, + { + amount: '1679493633445700', + coin_type_hash: '91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6', + owner_address: '0xaaa9c5fb3b4855e1569321041febcc1146b44af3f08893d4ce41846cc7e25645', + coin_type: '0x1::aptos_coin::AptosCoin', + last_transaction_timestamp: '2023-02-02T22:26:31.000Z', + last_transaction_version: '81147167', + }, + ], + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/collections.getNFTCollections.ts b/packages/aptosApi/integration/mocks/endpoints/collections.getNFTCollections.ts new file mode 100644 index 0000000000..e3aab0fe5b --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/collections.getNFTCollections.ts @@ -0,0 +1,40 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetNFTCollections = MockScenarios.create( + { + method: 'get', + name: 'mockGetNFTCollections', + url: `/collections`, + getParams: ({ req }) => ({ + limit: req.url.searchParams.get('limit'), + }), + }, + [ + { + condition: { + limit: '1', + }, + response: { + cursor: 'c.u.r.s.o.r', + result: [ + { + collection_data_id_hash: 'f5220e2d492bfce726c26086e7ba6948a4604fa22af736df1705d49937fe0114', + collection_name: 'Lorem ipsum', + creator_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + description: 'Sit dolor', + description_mutable: false, + last_transaction_timestamp: '2022-10-20T19:54:07.000Z', + last_transaction_version: '6369344', + maximum: '9007199254740991', + maximum_mutable: false, + metadata_uri: '', + supply: '0', + table_handle: '0x691434926a0e9c9b0265bc86de879316f794f705e35786622b9ef73aee4258c0', + uri_mutable: false, + }, + ], + hasNextPage: true, + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/nfts.getNFTOwnersByCollection.ts b/packages/aptosApi/integration/mocks/endpoints/nfts.getNFTOwnersByCollection.ts new file mode 100644 index 0000000000..ebf53b78ab --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/nfts.getNFTOwnersByCollection.ts @@ -0,0 +1,41 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetNFTOwnersByCollection = MockScenarios.create( + { + method: 'get', + name: 'mockGetNFTOwnersByCollection', + url: `/nfts/collections/:collectionDataIdHash/owners`, + getParams: ({ req }) => ({ + collectionDataIdHash: req.params.collectionDataIdHash, + limit: req.url.searchParams.get('limit'), + }), + }, + [ + { + condition: { + collectionDataIdHash: 'bd1e7fef8fd8d3ff8351eb564541f43cdaeaff93bbefd4ed402af66e9d70bedc', + limit: '2', + }, + response: { + cursor: null, + hasNextPage: false, + result: [ + { + amount: '100000000', + collection_data_id_hash: 'bd1e7fef8fd8d3ff8351eb564541f43cdaeaff93bbefd4ed402af66e9d70bedc', + collection_name: 'collName552', + creator_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + last_transaction_timestamp: '2022-10-20T08:51:16.000Z', + last_transaction_version: '5563252', + name: 'popitys', + owner_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + property_version: '0', + table_type: '0x3::token::TokenStore', + token_data_id_hash: '301304744b268b2a4ed57333cd8715a84d0f503543ba981d20e6df81d0f46a8b', + token_properties: {}, + }, + ], + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/nfts.getNFTsByCreators.ts b/packages/aptosApi/integration/mocks/endpoints/nfts.getNFTsByCreators.ts new file mode 100644 index 0000000000..72f2e96c99 --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/nfts.getNFTsByCreators.ts @@ -0,0 +1,73 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetNFTsByCreators = MockScenarios.create( + { + method: 'get', + name: 'mockGetNFTsByCreators', + url: `/nfts/creators`, + getParams: ({ req }) => ({ + creatorAddresses: req.url.searchParams.get('creator_addresses[]'), + limit: req.url.searchParams.get('limit'), + }), + }, + [ + { + condition: { + creatorAddresses: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + limit: '2', + }, + response: { + cursor: 'c.u.r.s.o.r', + hasNextPage: true, + result: [ + { + collection_data_id_hash: 'bd1e7fef8fd8d3ff8351eb564541f43cdaeaff93bbefd4ed402af66e9d70bedc', + collection_name: 'collName552', + creator_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + default_properties: {}, + description: 'brawlstars', + description_mutable: false, + largest_property_version: '0', + last_transaction_timestamp: '2022-10-20T08:51:16.000Z', + last_transaction_version: '5563252', + maximum: '9007199254740991', + maximum_mutable: false, + metadata_uri: 'https://i.postimg.cc/C1CdcRcL/B8-AE2-EBE-7-B60-46-C4-A96-E-958-D9159-D15-A.jpg', + name: 'popitys', + payee_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + properties_mutable: false, + royalty_mutable: false, + royalty_points_denominator: '0', + royalty_points_numerator: '0', + supply: '1', + token_data_id_hash: '301304744b268b2a4ed57333cd8715a84d0f503543ba981d20e6df81d0f46a8b', + uri_mutable: false, + }, + { + collection_data_id_hash: '4e41e0f1b888051ac98acf6879eeabdca2c74778a883366f60a04e62cd27a1b1', + collection_name: 'collName23', + creator_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + default_properties: {}, + description: 'girl', + description_mutable: false, + largest_property_version: '0', + last_transaction_timestamp: '2022-10-20T19:16:58.000Z', + last_transaction_version: '6347950', + maximum: '9007199254740991', + maximum_mutable: false, + metadata_uri: 'https://i.postimg.cc/FHnsybnZ/1528473855169978071.jpg', + name: 'mem', + payee_address: '0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0', + properties_mutable: false, + royalty_mutable: false, + royalty_points_denominator: '0', + royalty_points_numerator: '0', + supply: '1', + token_data_id_hash: '4a923c9ab0da0a69f6ac8aac5f16c35226c9ea776648f84c923dbe4f6a03ca75', + uri_mutable: false, + }, + ], + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/transactions.estimateGasPrice.ts b/packages/aptosApi/integration/mocks/endpoints/transactions.estimateGasPrice.ts new file mode 100644 index 0000000000..531d610d3e --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/transactions.estimateGasPrice.ts @@ -0,0 +1,20 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockEstimateGasPrice = MockScenarios.create( + { + method: 'get', + name: 'mockEstimateGasPrice', + url: `/transactions/estimate_gas_price`, + getParams: () => ({}), + }, + [ + { + condition: {}, + response: { + deprioritized_gas_estimate: 100, + gas_estimate: 133, + prioritized_gas_estimate: 150, + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/endpoints/wallets.getCoinBalancesByWallets.ts b/packages/aptosApi/integration/mocks/endpoints/wallets.getCoinBalancesByWallets.ts new file mode 100644 index 0000000000..0de46e4263 --- /dev/null +++ b/packages/aptosApi/integration/mocks/endpoints/wallets.getCoinBalancesByWallets.ts @@ -0,0 +1,43 @@ +import { MockScenarios } from '@moralisweb3/test-utils'; + +export const mockGetCoinBalancesByWallets = MockScenarios.create( + { + method: 'get', + name: 'mockGetCoinBalancesByWallets', + url: `/wallets/coins`, + getParams: ({ req }) => ({ + limit: req.url.searchParams.get('limit'), + ownerAddresses: req.url.searchParams.get('owner_addresses[]'), + }), + }, + [ + { + condition: { + limit: '10', + ownerAddresses: '0xbc4bd90ad3ff96a2172307622764ee5950790ae85f2db147f4cb8ce72dd9d13f', + }, + response: { + hasNextPage: false, + result: [ + { + amount: '9080143', + coin_type_hash: '91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6', + owner_address: '0xbc4bd90ad3ff96a2172307622764ee5950790ae85f2db147f4cb8ce72dd9d13f', + coin_type: '0x1::aptos_coin::AptosCoin', + last_transaction_timestamp: '2023-02-06T11:41:06.000Z', + last_transaction_version: '82945819', + }, + { + amount: '97914848', + coin_type_hash: 'fa4a1de6fcaea5d87155218712be91c3c2c02cd261cb12a5aeadad05b4708edd', + owner_address: '0xbc4bd90ad3ff96a2172307622764ee5950790ae85f2db147f4cb8ce72dd9d13f', + coin_type: + '0x84d7aeef42d38a5ffc3ccef853e1b82e4958659d16a7de736a29c55fbbeb0114::staked_aptos_coin::StakedAptosCoin', + last_transaction_timestamp: '2023-02-06T11:41:06.000Z', + last_transaction_version: '82945819', + }, + ], + }, + }, + ], +); diff --git a/packages/aptosApi/integration/mocks/mockServer.ts b/packages/aptosApi/integration/mocks/mockServer.ts new file mode 100644 index 0000000000..318dd5ef2c --- /dev/null +++ b/packages/aptosApi/integration/mocks/mockServer.ts @@ -0,0 +1,29 @@ +import { MOCK_API_KEY, APTOS_API_ROOT } from './config'; +import { MockServer } from '@moralisweb3/test-utils'; +import { mockGetAccount } from './endpoints/accounts.getAccount'; +import { mockGetCoinBalancesByWallets } from './endpoints/wallets.getCoinBalancesByWallets'; +import { mockGetTopHoldersByCoin } from './endpoints/coins.getTopHoldersByCoin'; +import { mockGetNFTCollections } from './endpoints/collections.getNFTCollections'; +import { mockGetAccountModule } from './endpoints/accounts.getAccountModule'; +import { mockGetLatestCoins } from './endpoints/coins.getLatestCoins'; +import { mockEstimateGasPrice } from './endpoints/transactions.estimateGasPrice'; +import { mockGetNFTsByCreators } from './endpoints/nfts.getNFTsByCreators'; +import { mockGetNFTOwnersByCollection } from './endpoints/nfts.getNFTOwnersByCollection'; +import { mockGetCoinInfoByCoinTypeHashes } from './endpoints/coins.getCoinInfoByCoinTypeHashes'; +import { mockGetBlockByHeight } from './endpoints/blocks.getBlockByHeight'; + +const handlers = [ + mockGetAccount, + mockGetAccountModule, + mockGetBlockByHeight, + mockGetTopHoldersByCoin, + mockGetNFTCollections, + mockGetCoinInfoByCoinTypeHashes, + mockGetCoinBalancesByWallets, + mockGetLatestCoins, + mockGetNFTOwnersByCollection, + mockGetNFTsByCreators, + mockEstimateGasPrice, +]; + +export const mockServer = MockServer.create({ apiKey: MOCK_API_KEY, apiRoot: APTOS_API_ROOT }, handlers).start(); diff --git a/packages/aptosApi/integration/setup.ts b/packages/aptosApi/integration/setup.ts new file mode 100644 index 0000000000..7728ba5075 --- /dev/null +++ b/packages/aptosApi/integration/setup.ts @@ -0,0 +1,28 @@ +import { ApiUtils } from '@moralisweb3/api-utils'; +import { Core } from '@moralisweb3/common-core'; +import { AptosApi } from '../src/AptosApi'; +import { MOCK_API_KEY } from './mocks/config'; +import { mockServer } from './mocks/mockServer'; + +export function setupAptosApi(): AptosApi { + const core = Core.create(); + const apiUtils = ApiUtils.create(core); + const aptosApi = AptosApi.create(core); + core.registerModule(apiUtils); + + // DO NOT SET `CoreProvider.setDefault(core)` here! + + core.start({ + apiKey: MOCK_API_KEY, + }); + + mockServer.listen({ + onUnhandledRequest: 'warn', + }); + + return aptosApi; +} + +export function cleanAptosApi() { + mockServer.close(); +} diff --git a/packages/aptosApi/integration/tests/accounts.getAccount.test.ts b/packages/aptosApi/integration/tests/accounts.getAccount.test.ts new file mode 100644 index 0000000000..8d224fd2f0 --- /dev/null +++ b/packages/aptosApi/integration/tests/accounts.getAccount.test.ts @@ -0,0 +1,23 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getAccount', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns an info', async () => { + const response = await aptosApi.accounts.getAccount({ + address: '0x7abf3bc917c75e13b2225417aa1b008a4c1b1a6b487739ad0a39ef847b9c2f8e', + }); + + expect(response.sequenceNumber).toBe('0'); + expect(response.authenticationKey).toBe('0x7abf3bc917c75e13b2225417aa1b008a4c1b1a6b487739ad0a39ef847b9c2f8e'); + }); +}); diff --git a/packages/aptosApi/integration/tests/accounts.getAccountModule.test.ts b/packages/aptosApi/integration/tests/accounts.getAccountModule.test.ts new file mode 100644 index 0000000000..39c6f23bdb --- /dev/null +++ b/packages/aptosApi/integration/tests/accounts.getAccountModule.test.ts @@ -0,0 +1,33 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getAccountModule', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns an info', async () => { + const response = await aptosApi.accounts.getAccountModule({ + address: '0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1', + moduleName: 'module_name_todo', + }); + + expect(response.bytecode).toBe('0xbytecode_todo'); + expect(response.abi.address.address).toBe('0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1'); + expect(response.abi.name).toBe('string'); + expect(response.abi.friends).toContain('0x1::aptos_coin'); + const exposedFunction = response.abi.exposedFunctions[0]; + expect(exposedFunction.name).toBe('string'); + expect(exposedFunction.visibility).toBe('private'); + expect(exposedFunction.isEntry).toBe(true); + expect(exposedFunction.genericTypeParams[0].constraints).toContain('todo_x1'); + expect(exposedFunction.params).toContain('string'); + expect(exposedFunction.return).toContain('string'); + }); +}); diff --git a/packages/aptosApi/integration/tests/blocks.getBlockByHeight.test.ts b/packages/aptosApi/integration/tests/blocks.getBlockByHeight.test.ts new file mode 100644 index 0000000000..9d40a9be92 --- /dev/null +++ b/packages/aptosApi/integration/tests/blocks.getBlockByHeight.test.ts @@ -0,0 +1,68 @@ +import { AptosBlockMetadataTransaction, AptosWriteResourceChange } from '@moralisweb3/common-aptos-utils'; +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getBlockByHeight', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns an info', async () => { + const response = await aptosApi.blocks.getBlockByHeight({ + blockHeight: 499540, + withTransactions: true, + }); + + expect(response.blockHeight).toBe('499540'); + expect(response.blockHash).toBe('0x5a5f8cd83acd6248c90108e5f21fc60b9efca44890aac91d66da02c03913ac9b'); + expect(response.blockTimestamp).toBe('1665858020377412'); + expect(response.firstVersion).toBe('999999'); + expect(response.lastVersion).toBe('1000000'); + + expect(response.transactions).toHaveLength(2); + + const tx1 = response.transactions![0] as AptosBlockMetadataTransaction; + + expect(AptosBlockMetadataTransaction.isInput(tx1)).toBe(true); + expect(tx1.hash).toBe('0xa64930fb0e18d93bd9183d262457cf0d7c27b52ca01d02fb8d736812b9e7454d'); + expect(tx1.type).toBe('block_metadata_transaction'); + expect(tx1.proposer.address).toBe('0xc29a231581f243ddcbf97de8b93c8aabb466dd6912ce5ba12579ff2f13cb8da5'); + expect(tx1.timestamp).toBe('1665858020377412'); + expect(tx1.epoch).toBe('36'); + expect(tx1.round).toBe('6952'); + expect(tx1.id).toBe('0x5a5f8cd83acd6248c90108e5f21fc60b9efca44890aac91d66da02c03913ac9b'); + expect(tx1.changes).toHaveLength(3); + expect(tx1.events).toHaveLength(1); + + const event = tx1.events[0]; + expect(event.guid.accountAddress.address).toBe( + '0x0000000000000000000000000000000000000000000000000000000000000001', + ); + expect(event.guid.creationNumber).toBe('3'); + expect(event.sequenceNumber).toBe('499540'); + expect(event.type).toBe('0x1::block::NewBlockEvent'); + expect(event.data).toBeDefined(); + + const change1 = tx1.changes[0] as AptosWriteResourceChange; + expect(AptosWriteResourceChange.isInput(change1)).toBe(true); + expect(change1.address.address).toBe('0x0000000000000000000000000000000000000000000000000000000000000001'); + expect(change1.stateKeyHash).toBe('0x5ddf404c60e96e9485beafcabb95609fed8e38e941a725cae4dcec8296fb32d7'); + expect(change1.type).toBe('write_resource'); + expect(change1.address.address).toBe('0x0000000000000000000000000000000000000000000000000000000000000001'); + expect(change1.stateKeyHash).toBe('0x5ddf404c60e96e9485beafcabb95609fed8e38e941a725cae4dcec8296fb32d7'); + expect(change1.data.type).toBe('0x1::block::BlockResource'); + expect(change1.data.data).toBeDefined(); + + const change2 = tx1.changes[1]; + expect(AptosWriteResourceChange.isInput(change2)).toBe(true); + + const change3 = tx1.changes[2]; + expect(AptosWriteResourceChange.isInput(change3)).toBe(true); + }); +}); diff --git a/packages/aptosApi/integration/tests/coins.getCoinInfoByCoinTypeHashes.test.ts b/packages/aptosApi/integration/tests/coins.getCoinInfoByCoinTypeHashes.test.ts new file mode 100644 index 0000000000..4032c49501 --- /dev/null +++ b/packages/aptosApi/integration/tests/coins.getCoinInfoByCoinTypeHashes.test.ts @@ -0,0 +1,34 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getLatestCoins', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns latest coins', async () => { + const response = await aptosApi.coins.getCoinInfoByCoinTypeHashes({ + coinTypeHashes: ['069476fd0e9663039084fcd721540374c2313c9f0dffe81130970774a22855c3'], + }); + + const item1 = response[0]; + expect(item1.coinType).toBe( + '0x5a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948::lp_coin::LP<0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::UsdtCoin, 0x1::aptos_coin::AptosCoin, 0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated>', + ); + expect(item1.coinTypeHash).toBe('069476fd0e9663039084fcd721540374c2313c9f0dffe81130970774a22855c3'); + expect(item1.creatorAddress.address).toBe('0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948'); + expect(item1.decimals).toBe(6); + expect(item1.name).toBe('LiquidLP-USDT-APT-U'); + expect(item1.supplyAggregatorTableHandle).toBeNull(); + expect(item1.supplyAggregatorTableKey).toBeNull(); + expect(item1.symbol).toBe('USDT-APT'); + expect(item1.transactionCreatedTimestamp).toBe('2023-02-07T08:54:55.000Z'); + expect(item1.transactionVersionCreated).toBe('83401661'); + }); +}); diff --git a/packages/aptosApi/integration/tests/coins.getLatestCoins.test.ts b/packages/aptosApi/integration/tests/coins.getLatestCoins.test.ts new file mode 100644 index 0000000000..9dcd21f7a7 --- /dev/null +++ b/packages/aptosApi/integration/tests/coins.getLatestCoins.test.ts @@ -0,0 +1,38 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getLatestCoins', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns latest coins', async () => { + const response = await aptosApi.coins.getLatestCoins({ + limit: 2, + }); + + expect(response.hasNextPage).toBe(true); + expect(response.cursor).toBeDefined(); + expect(response.result.length).toBe(2); + + const item1 = response.result[0]; + expect(item1.coinType).toBe( + '0x5a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948::lp_coin::LP<0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::UsdtCoin, 0x1::aptos_coin::AptosCoin, 0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated>', + ); + expect(item1.coinTypeHash).toBe('069476fd0e9663039084fcd721540374c2313c9f0dffe81130970774a22855c3'); + expect(item1.name).toBe('LiquidLP-USDT-APT-U'); + expect(item1.creatorAddress.address).toBe('0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948'); + expect(item1.decimals).toBe(6); + expect(item1.supplyAggregatorTableHandle).toBeNull(); + expect(item1.supplyAggregatorTableKey).toBeNull(); + expect(item1.symbol).toBe('USDT-APT'); + expect(item1.transactionCreatedTimestamp).toBe('2023-02-07T08:54:55.000Z'); + expect(item1.transactionVersionCreated).toBe('83401661'); + }); +}); diff --git a/packages/aptosApi/integration/tests/coins.getTopHoldersByCoin.test.ts b/packages/aptosApi/integration/tests/coins.getTopHoldersByCoin.test.ts new file mode 100644 index 0000000000..6b1e5d0c0f --- /dev/null +++ b/packages/aptosApi/integration/tests/coins.getTopHoldersByCoin.test.ts @@ -0,0 +1,33 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getTopHoldersByCoin', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns top holders', async () => { + const response = await aptosApi.coins.getTopHoldersByCoin({ + coinTypeHash: '91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6', + limit: 2, + }); + + expect(response.hasNextPage).toBe(false); + expect(response.cursor).not.toBeDefined(); + expect(response.result.length).toBe(2); + + const item1 = response.result[0]; + expect(item1.amount.aptos).toBe('52039866.10945473'); + expect(item1.coinTypeHash).toBe('91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6'); + expect(item1.ownerAddress.address).toBe('0xc739507214d0e1bf9795485299d709e00024e92f7c0d055a4c2c39717882bdfd'); + expect(item1.coinType).toBe('0x1::aptos_coin::AptosCoin'); + expect(item1.lastTransactionTimestamp).toBe('2023-02-02T18:55:40.000Z'); + expect(item1.lastTransactionVersion).toBe('81068073'); + }); +}); diff --git a/packages/aptosApi/integration/tests/collections.getNFTCollections.test.ts b/packages/aptosApi/integration/tests/collections.getNFTCollections.test.ts new file mode 100644 index 0000000000..ddb92245da --- /dev/null +++ b/packages/aptosApi/integration/tests/collections.getNFTCollections.test.ts @@ -0,0 +1,39 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getNFTCollections', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns collections', async () => { + const response = await aptosApi.collections.getNFTCollections({ + limit: 1, + }); + + expect(response.cursor).toBeDefined(); + expect(response.hasNextPage).toBe(true); + expect(response.result.length).toBe(1); + + const item1 = response.result[0]; + expect(item1.collectionDataIdHash).toBe('f5220e2d492bfce726c26086e7ba6948a4604fa22af736df1705d49937fe0114'); + expect(item1.collectionName).toBe('Lorem ipsum'); + expect(item1.creatorAddress.address).toBe('0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0'); + expect(item1.description).toBe('Sit dolor'); + expect(item1.descriptionMutable).toBe(false); + expect(item1.lastTransactionTimestamp).toBe('2022-10-20T19:54:07.000Z'); + expect(item1.lastTransactionVersion).toBe('6369344'); + expect(item1.maximum).toBe('9007199254740991'); + expect(item1.maximumMutable).toBe(false); + expect(item1.metadataUri).toBe(''); + expect(item1.supply).toBe('0'); + expect(item1.tableHandle).toBe('0x691434926a0e9c9b0265bc86de879316f794f705e35786622b9ef73aee4258c0'); + expect(item1.uriMutable).toBe(false); + }); +}); diff --git a/packages/aptosApi/integration/tests/nfts.getNFTOwnersByCollection.test.ts b/packages/aptosApi/integration/tests/nfts.getNFTOwnersByCollection.test.ts new file mode 100644 index 0000000000..28b3956ce8 --- /dev/null +++ b/packages/aptosApi/integration/tests/nfts.getNFTOwnersByCollection.test.ts @@ -0,0 +1,39 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getNFTOwnersByCollection', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns nft owners', async () => { + const response = await aptosApi.nfts.getNFTOwnersByCollection({ + collectionDataIdHash: 'bd1e7fef8fd8d3ff8351eb564541f43cdaeaff93bbefd4ed402af66e9d70bedc', + limit: 2, + }); + + expect(response.cursor).toBeNull(); + expect(response.hasNextPage).toBe(false); + expect(response.result.length).toBe(1); + + const item1 = response.result[0]; + expect(item1.amount.octas).toBe('100000000'); + expect(item1.collectionDataIdHash).toBe('bd1e7fef8fd8d3ff8351eb564541f43cdaeaff93bbefd4ed402af66e9d70bedc'); + expect(item1.collectionName).toBe('collName552'); + expect(item1.creatorAddress.address).toBe('0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0'); + expect(item1.lastTransactionTimestamp).toBe('2022-10-20T08:51:16.000Z'); + expect(item1.lastTransactionVersion).toBe('5563252'); + expect(item1.name).toBe('popitys'); + expect(item1.ownerAddress.address).toBe('0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0'); + expect(item1.propertyVersion).toBe('0'); + expect(item1.tableType).toBe('0x3::token::TokenStore'); + expect(item1.tokenDataIdHash).toBe('301304744b268b2a4ed57333cd8715a84d0f503543ba981d20e6df81d0f46a8b'); + expect(item1.tokenProperties).toMatchObject({}); + }); +}); diff --git a/packages/aptosApi/integration/tests/nfts.getNFTsByCreators.test.ts b/packages/aptosApi/integration/tests/nfts.getNFTsByCreators.test.ts new file mode 100644 index 0000000000..2298e0fd36 --- /dev/null +++ b/packages/aptosApi/integration/tests/nfts.getNFTsByCreators.test.ts @@ -0,0 +1,48 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; +import { AptosAddress } from '@moralisweb3/common-aptos-utils'; + +describe('getNFTsByCreators', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns nfts', async () => { + const response = await aptosApi.nfts.getNFTsByCreators({ + creatorAddresses: [AptosAddress.create('0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0')], + limit: 2, + }); + + expect(response.cursor).toBeDefined(); + expect(response.hasNextPage).toBe(true); + expect(response.result.length).toBe(2); + + const item1 = response.result[0]; + expect(item1.collectionDataIdHash).toBe('bd1e7fef8fd8d3ff8351eb564541f43cdaeaff93bbefd4ed402af66e9d70bedc'); + expect(item1.collectionName).toBe('collName552'); + expect(item1.creatorAddress.address).toBe('0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0'); + expect(item1.description).toBe('brawlstars'); + expect(item1.descriptionMutable).toBe(false); + expect(item1.largestPropertyVersion).toBe('0'); + expect(item1.lastTransactionTimestamp).toBe('2022-10-20T08:51:16.000Z'); + expect(item1.lastTransactionVersion).toBe('5563252'); + expect(item1.maximum).toBe('9007199254740991'); + expect(item1.maximumMutable).toBe(false); + expect(item1.metadataUri).toBe('https://i.postimg.cc/C1CdcRcL/B8-AE2-EBE-7-B60-46-C4-A96-E-958-D9159-D15-A.jpg'); + expect(item1.name).toBe('popitys'); + expect(item1.payeeAddress.address).toBe('0xe9fa81b90a846ab2737e88592a4e207e3f503bfac7e5774a4a4bc93b439258f0'); + expect(item1.propertiesMutable).toBe(false); + expect(item1.royaltyMutable).toBe(false); + expect(item1.royaltyPointsDenominator).toBe('0'); + expect(item1.royaltyPointsNumerator).toBe('0'); + expect(item1.supply).toBe('1'); + expect(item1.tokenDataIdHash).toBe('301304744b268b2a4ed57333cd8715a84d0f503543ba981d20e6df81d0f46a8b'); + expect(item1.uriMutable).toBe(false); + }); +}); diff --git a/packages/aptosApi/integration/tests/transactions.estimateGasPrice.test.ts b/packages/aptosApi/integration/tests/transactions.estimateGasPrice.test.ts new file mode 100644 index 0000000000..6772716403 --- /dev/null +++ b/packages/aptosApi/integration/tests/transactions.estimateGasPrice.test.ts @@ -0,0 +1,22 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('estimateGasPrice', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns gas price', async () => { + const response = await aptosApi.transactions.estimateGasPrice({}); + + expect(response.deprioritizedGasEstimate).toBe(100); + expect(response.gasEstimate).toBe(133); + expect(response.prioritizedGasEstimate).toBe(150); + }); +}); diff --git a/packages/aptosApi/integration/tests/wallets.getCoinBalancesByWallets.test.ts b/packages/aptosApi/integration/tests/wallets.getCoinBalancesByWallets.test.ts new file mode 100644 index 0000000000..536c6a2ab6 --- /dev/null +++ b/packages/aptosApi/integration/tests/wallets.getCoinBalancesByWallets.test.ts @@ -0,0 +1,33 @@ +import { AptosApi } from '../../src/AptosApi'; +import { cleanAptosApi, setupAptosApi } from '../setup'; + +describe('getCoinBalancesByWallets', () => { + let aptosApi: AptosApi; + + beforeAll(() => { + aptosApi = setupAptosApi(); + }); + + afterAll(() => { + cleanAptosApi(); + }); + + it('returns balances', async () => { + const response = await aptosApi.wallets.getCoinBalancesByWallets({ + ownerAddresses: ['0xbc4bd90ad3ff96a2172307622764ee5950790ae85f2db147f4cb8ce72dd9d13f'], + limit: 10, + }); + + expect(response.hasNextPage).toBe(false); + expect(response.cursor).not.toBeDefined(); + expect(response.result.length).toBe(2); + + const item1 = response.result[0]; + expect(item1.amount.aptos).toBe('0.09080143'); + expect(item1.coinTypeHash).toBe('91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6'); + expect(item1.ownerAddress.address).toBe('0xbc4bd90ad3ff96a2172307622764ee5950790ae85f2db147f4cb8ce72dd9d13f'); + expect(item1.coinType).toBe('0x1::aptos_coin::AptosCoin'); + expect(item1.lastTransactionTimestamp).toBe('2023-02-06T11:41:06.000Z'); + expect(item1.lastTransactionVersion).toBe('82945819'); + }); +}); diff --git a/packages/aptosApi/jest.config.cjs b/packages/aptosApi/jest.config.cjs new file mode 100644 index 0000000000..1c13fbaa33 --- /dev/null +++ b/packages/aptosApi/jest.config.cjs @@ -0,0 +1,4 @@ +/* eslint-disable global-require */ +module.exports = { + ...require('../../jest.config'), +}; diff --git a/packages/aptosApi/package.json b/packages/aptosApi/package.json new file mode 100644 index 0000000000..c096fcda22 --- /dev/null +++ b/packages/aptosApi/package.json @@ -0,0 +1,50 @@ +{ + "name": "@moralisweb3/aptos-api", + "author": "Moralis", + "version": "2.14.3", + "license": "MIT", + "type": "module", + "main": "./lib/esm/index.js", + "types": "./lib/index.d.ts", + "typings": "./lib/index.d.ts", + "exports": { + ".": { + "types": { + "default": "./lib/index.d.ts" + }, + "default": { + "require": "./lib/cjs/index.cjs", + "default": "./lib/esm/index.js" + } + } + }, + "files": [ + "lib/*" + ], + "scripts": { + "test": "jest --runInBand --detectOpenHandles --forceExit --ci", + "test:coverage": "yarn run test --coverage --coverageReporters json-summary", + "test:watch": "yarn run test --watch", + "lint": "eslint . --ext .js,.ts,.tsx,jsx", + "clean": "rm -rf lib && rm -rf ./node_modules/.cache/nx", + "build": "rollup -c", + "dev": "tsc --watch" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-node-resolve": "^15.0.1", + "jest": "29.3.1", + "openapi-typescript": "^5.2.0", + "rollup": "^3.10.1", + "rollup-plugin-cleaner": "^1.0.0", + "rollup-plugin-dts": "^5.2.0", + "rollup-plugin-node-polyfills": "^0.2.1", + "rollup-plugin-typescript2": "^0.34.1", + "typescript": "^4.9.3" + }, + "dependencies": { + "@moralisweb3/api-utils": "^2.14.3", + "@moralisweb3/common-aptos-utils": "^2.14.3", + "@moralisweb3/common-core": "^2.14.3" + } +} diff --git a/packages/aptosApi/rollup.config.mjs b/packages/aptosApi/rollup.config.mjs new file mode 100644 index 0000000000..cb62d22af8 --- /dev/null +++ b/packages/aptosApi/rollup.config.mjs @@ -0,0 +1,46 @@ +import typescript from 'rollup-plugin-typescript2'; +import cleaner from 'rollup-plugin-cleaner'; +import dts from 'rollup-plugin-dts'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import fs from 'fs'; + +const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); +const external = Object.keys(packageJson.dependencies); + +export default [ + { + input: './src/index.ts', + plugins: [ + cleaner({ + targets: ['./lib'], + }), + typescript({ + useTsconfigDeclarationDir: true, + }), + nodeResolve(), + ], + cache: false, + external, + output: [ + { + file: './lib/cjs/index.cjs', + format: 'cjs', + exports: 'named', + }, + { + file: './lib/esm/index.js', + format: 'esm', + }, + ], + }, + { + input: './build/index.d.ts', + output: [ + { + file: './lib/index.d.ts', + format: 'es', + }, + ], + plugins: [dts()], + }, +]; diff --git a/packages/aptosApi/src/AptosApi.ts b/packages/aptosApi/src/AptosApi.ts new file mode 100644 index 0000000000..34656f9b00 --- /dev/null +++ b/packages/aptosApi/src/AptosApi.ts @@ -0,0 +1,60 @@ +import { Core, CoreProvider, RequestController } from '@moralisweb3/common-core'; +import { AbstractClient, AptosNetworkResolver, OperationV3, AptosNetworkInput } from '@moralisweb3/common-aptos-utils'; +import { OperationV3Resolver, OperationV3UrlBaseResolver } from './OperationV3Resolver'; + +const MAINNET_BASE_URL = 'https://aptos-mainnet.aws-prod-api-1.moralis.io'; +const TESTNET_BASE_URL = 'https://aptos-testnet.aws-prod-api-1.moralis.io'; + +export class AptosApi extends AbstractClient { + public static readonly moduleName = 'aptApi'; + + public static create(core?: Core): AptosApi { + if (!core) { + core = CoreProvider.getDefault(); + } + const requestController = RequestController.create(core); + const baseUrlResolver = new AptosApiBaseUrlResolver(core); + const operationResolver = new OperationV3Resolver(baseUrlResolver, core.config, requestController); + return new AptosApi(operationResolver); + } + + private constructor(private readonly operationResolver: OperationV3Resolver) { + super(); + } + + protected createEndpoint( + operation: OperationV3, + ): (r: Request) => Promise { + return (request: Request) => { + return this.operationResolver.resolve(request, null, operation); + }; + } + + protected createEndpointWithBody( + operation: OperationV3, + ): (r: Request, b: Body) => Promise { + return (request: Request, body: Body) => { + return this.operationResolver.resolve(request, body, operation); + }; + } +} + +class AptosApiBaseUrlResolver implements OperationV3UrlBaseResolver { + public constructor(private readonly core: Core) {} + + public resolve(request: unknown): string { + const { network } = request as { network: AptosNetworkInput | undefined }; + if (network) { + const finalNetwork = AptosNetworkResolver.resolve(network, this.core); + switch (finalNetwork) { + case 'mainnet': + return MAINNET_BASE_URL; + case 'testnet': + return TESTNET_BASE_URL; + default: + throw new Error('Not supported network'); + } + } + return MAINNET_BASE_URL; + } +} diff --git a/packages/aptosApi/src/OperationV3Resolver.ts b/packages/aptosApi/src/OperationV3Resolver.ts new file mode 100644 index 0000000000..0be3d52124 --- /dev/null +++ b/packages/aptosApi/src/OperationV3Resolver.ts @@ -0,0 +1,78 @@ +import { ApiUtilsConfig, getSdkDetailsHeaders } from '@moralisweb3/api-utils'; +import { ApiErrorCode, Config, CoreConfig, MoralisApiError, RequestController } from '@moralisweb3/common-core'; +import { OperationV3 } from '@moralisweb3/common-aptos-utils'; + +export interface OperationV3UrlBaseResolver { + resolve(request: unknown): string; +} + +export class OperationV3Resolver { + public constructor( + private readonly baseUrlResolver: OperationV3UrlBaseResolver, + private readonly config: Config, + private readonly requestController: RequestController, + ) {} + + public async resolve( + request: Request, + body: Body | null, + operation: OperationV3, + ): Promise { + const urlParamNames = operation.parameterNames.filter((name) => operation.routePattern.includes(`{${name}}`)); + const requestJSON: Record = operation.serializeRequest + ? (operation.serializeRequest(request) as Record) + : {}; + + const url = urlParamNames.reduce((current, name) => { + const value = requestJSON[name]; + current = current.replace(`{${name}}`, String(value)); + return current; + }, operation.routePattern); + + const searchParams = operation.parameterNames + .filter((name) => !urlParamNames.includes(name)) + .reduce((current, name) => { + current[name] = requestJSON[name]; + return current; + }, {} as Record); + + const bodyJSON = body && operation.serializeBody ? operation.serializeBody(body) : undefined; + + const responseJSON = await this.requestController.request({ + url, + params: searchParams, + baseURL: this.baseUrlResolver.resolve(request), + method: operation.httpMethod, + data: bodyJSON, + headers: this.prepareHeaders(), + }); + + if (!responseJSON || !operation.parseResponse) { + if (operation.hasResponse) { + throw new Error('Expected response, but API has returned empty response'); + } + return null as Response; + } + return operation.parseResponse(responseJSON); + } + + public prepareHeaders(): Record { + const apiKey = this.config.get(ApiUtilsConfig.apiKey); + const product = this.config.get(CoreConfig.product); + + if (!apiKey) { + throw new MoralisApiError({ + code: ApiErrorCode.API_KEY_NOT_SET, + message: 'apiKey is not set', + }); + } + + const headers = getSdkDetailsHeaders(); + headers['x-api-key'] = `${apiKey}`; + headers['Authorization'] = `Bearer ${apiKey}`; + if (product) { + headers['x-moralis-product'] = product; + } + return headers; + } +} diff --git a/packages/aptosApi/src/index.ts b/packages/aptosApi/src/index.ts new file mode 100644 index 0000000000..79d40459fe --- /dev/null +++ b/packages/aptosApi/src/index.ts @@ -0,0 +1,5 @@ +import { AptosApi } from './AptosApi'; + +export * from './AptosApi'; + +export default { AptosApi }; diff --git a/packages/aptosApi/tsconfig.json b/packages/aptosApi/tsconfig.json new file mode 100644 index 0000000000..8e8521e8b0 --- /dev/null +++ b/packages/aptosApi/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.package.json", + "compilerOptions": { + "outDir": "./build", + "declarationDir": "./build", + "rootDir": "./src" + }, + "include": ["src/**/*"] +} diff --git a/packages/auth/src/methods/requestMessage.ts b/packages/auth/src/methods/requestMessage.ts index f7ea8ebf58..fcb9cf3b3f 100644 --- a/packages/auth/src/methods/requestMessage.ts +++ b/packages/auth/src/methods/requestMessage.ts @@ -9,7 +9,7 @@ import { requestChallengeEvmOperation, requestChallengeAptosOperation, } from '@moralisweb3/common-auth-utils'; -import { AptosAddress, AptosAddressish, AptosNetwork, AptosNetworkish } from '@moralisweb3/common-aptos-utils'; +import { AptosAddress, AptosAddressInput, AptosNetwork, AptosNetworkInput } from '@moralisweb3/common-aptos-utils'; // Imported from Swagger and adjusted for better types for Evm // TODO: generalize and extend generated types @@ -53,8 +53,8 @@ export interface RequestMessageSolOptions { export interface RequestMessageAptosOptions { networkType: 'aptos'; domain: string; - chain: AptosNetworkish; - address: AptosAddressish; + chain: AptosNetworkInput; + address: AptosAddressInput; publicKey: string; statement?: string; uri: string; diff --git a/packages/common/aptosUtils/generator.config.json b/packages/common/aptosUtils/generator.config.json new file mode 100644 index 0000000000..d1fb51fc12 --- /dev/null +++ b/packages/common/aptosUtils/generator.config.json @@ -0,0 +1,133 @@ +{ + "url": "https://mainnet-aptos-api.moralis.io/aptos-api/swagger-json", + "generator": { + "outputDir": "src/generated", + "classNamePrefix": "Aptos", + "mappings": { + "types": [], + "refs": [], + "complexTypeProperties": [ + { + "names": [ + "creator_address", + "owner_address", + "address", + "sender", + "payee_address", + "from_address", + "to_address", + "proposer", + "account_address" + ], + "className": "AptosAddress", + "import": "../../dataTypes" + }, + { + "names": ["amount", "coin_amount", "token_amount"], + "className": "AptosNative", + "import": "../../dataTypes" + } + ], + "operationParameters": [ + { + "names": ["network"], + "className": "AptosNetwork", + "import": "../../dataTypes" + }, + { + "names": ["owner_addresses", "creator_addresses", "creator_address", "wallet_addresses"], + "className": "AptosAddress", + "import": "../../dataTypes" + }, + { + "names": ["min_amount"], + "className": "AptosNative", + "import": "../../dataTypes" + } + ] + }, + "typeDeterminants": [ + { + "typeName": "BlockMetadataTransaction", + "isInputCode": "input.type === 'block_metadata_transaction'", + "isJSONCode": "json.type === 'block_metadata_transaction'" + }, + { + "typeName": "UserTransaction", + "isInputCode": "input.type === 'user_transaction'", + "isJSONCode": "json.type === 'user_transaction'" + }, + { + "typeName": "GenesisTransaction", + "isInputCode": "input.type === 'genesis_transaction'", + "isJSONCode": "json.type === 'genesis_transaction'" + }, + { + "typeName": "PendingTransaction", + "isInputCode": "input.type === 'pending_transaction'", + "isJSONCode": "json.type === 'pending_transaction'" + }, + { + "typeName": "StateCheckpointTransaction", + "isInputCode": "input.type === 'state_checkpoint_transaction'", + "isJSONCode": "json.type === 'state_checkpoint_transaction'" + }, + { + "typeName": "DeleteModuleChange", + "isInputCode": "input.type === 'delete_module'", + "isJSONCode": "json.type === 'delete_module'" + }, + { + "typeName": "DeleteResourceChange", + "isInputCode": "input.type === 'delete_resource'", + "isJSONCode": "json.type === 'delete_resource'" + }, + { + "typeName": "DeleteTableItemChange", + "isInputCode": "input.type === 'delete_table_item'", + "isJSONCode": "json.type === 'delete_table_item'" + }, + { + "typeName": "WriteOrUpdateModuleChange", + "isInputCode": "input.type === 'write_module'", + "isJSONCode": "json.type === 'write_module'" + }, + { + "typeName": "WriteResourceChange", + "isInputCode": "input.type === 'write_resource'", + "isJSONCode": "json.type === 'write_resource'" + }, + { + "typeName": "WriteTableChangeSetChange", + "isInputCode": "input.type === 'write_table_item'", + "isJSONCode": "json.type === 'write_table_item'" + }, + { + "typeName": "ScriptWriteSet", + "isInputCode": "input.type === 'script_write_set'", + "isJSONCode": "json.type === 'script_write_set'" + }, + { + "typeName": "DirectWriteSet", + "isInputCode": "input.type === 'direct_write_set'", + "isJSONCode": "json.type === 'direct_write_set'" + } + ] + }, + "openApiReader": { + "v3": { + "operations": { + "groupRef": "#/x-tag-sdk", + "isEnabledRef": "#/x-tag-sdk", + "virtualParameters": [ + { + "name": "network", + "isRequired": false, + "nativeType": "string", + "description": "The network of query. Defaults to mainnet." + } + ] + } + } + } +} diff --git a/packages/common/aptosUtils/src/AptosNetworkResolver.ts b/packages/common/aptosUtils/src/AptosNetworkResolver.ts index b0c510ec6e..1a982a06c8 100644 --- a/packages/common/aptosUtils/src/AptosNetworkResolver.ts +++ b/packages/common/aptosUtils/src/AptosNetworkResolver.ts @@ -1,9 +1,9 @@ import Core from '@moralisweb3/common-core'; import { CommonAptosUtilsConfig } from './config/CommonAptosUtilsConfig'; -import { AptosNetwork, AptosNetworkish, AptosNetworkName } from './dataTypes'; +import { AptosNetwork, AptosNetworkInput, AptosNetworkName } from './dataTypes'; export class AptosNetworkResolver { - public static resolve(network: AptosNetworkish | undefined, core: Core): AptosNetworkName { + public static resolve(network: AptosNetworkInput | undefined, core: Core): AptosNetworkName { if (!network) { network = core.config.get(CommonAptosUtilsConfig.defaultAptosNetwork); } diff --git a/packages/common/aptosUtils/src/config/CommonAptosUtilsConfig.ts b/packages/common/aptosUtils/src/config/CommonAptosUtilsConfig.ts index 24b0a195c6..ded35f427e 100644 --- a/packages/common/aptosUtils/src/config/CommonAptosUtilsConfig.ts +++ b/packages/common/aptosUtils/src/config/CommonAptosUtilsConfig.ts @@ -1,9 +1,9 @@ import { ConfigKey } from '@moralisweb3/common-core'; -import { AptosNetworkish } from '../dataTypes'; +import { AptosNetworkInput } from '../dataTypes'; export const CommonAptosUtilsConfig = { defaultAptosNetwork: { name: 'defaultAptosNetwork', defaultValue: 'mainnet', - } as ConfigKey, + } as ConfigKey, }; diff --git a/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.test.ts b/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.test.ts index f95e95b2ca..706ed2536c 100644 --- a/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.test.ts +++ b/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.test.ts @@ -1,67 +1,60 @@ import { AptosAddress } from './AptosAddress'; describe('AptosAddress', () => { - const ADDRESS = '0xeeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b'; // account - - const validAddresses = [ - ADDRESS, - '0x19aadeca9388e009d136245b9a67423f3eee242b03142849eb4f81a4a409e59c', - '0000357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b', // no 0x - '0x357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b', // shorter, completes leading 0s - '0x0000357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b', - ]; - - const invalidAddresses = [ - 'invalid', - '0x19aadeca9388e009d136245b9a67423f3eee242b03142849eb4f81a4a409e59c19aadeca9388e009d136245b9a67423f3eee242b03142849eb4f81a4a409e59c', // super long - ]; + describe('equals()', () => { + it('returns true for comparison the same address but with trimmed leading 0s', () => { + const a = AptosAddress.create('0000357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b'); + const b = AptosAddress.create('0x0000357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b'); + const c = AptosAddress.create('0x357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b'); + + expect(a.equals(b)).toBe(true); + expect(b.equals(c)).toBe(true); + }); - for (const address of validAddresses) { - it(`creates an instance for ${address}`, () => { - const aptos = AptosAddress.create(address); + it('returns false for different addresses', () => { + const a = AptosAddress.create('0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90'); + const b = AptosAddress.create('0x1d8727df513fa2a8785d0834e40b34223daff1affc079574082baadb74b66ee4'); - expect(aptos.address).toEqual(address); - expect(aptos.toJSON()).toEqual(address); - expect(aptos.toString()).toEqual(address); - expect(aptos.format()).toEqual(address); + expect(a.equals(b)).toBe(false); }); - } - for (const address of invalidAddresses) { - it('create() throws an error when a passed address is invalid', () => { - expect(() => AptosAddress.create(address)).toThrowError(`[C0005] Invalid address provided: ${address}`); + it('static equals() method return proper value', () => { + expect(AptosAddress.equals('0x1', '0x1')).toBe(true); + expect(AptosAddress.equals('0x1', '0x0000000000000000000000000000000000000000000000000000000000000001')).toBe( + true, + ); + expect(AptosAddress.equals('0x1', '0x2')).toBe(false); + expect(AptosAddress.equals('0x1', '0x00002')).toBe(false); }); - } - - it('create() does not create a new instance when AptosAddress passed', () => { - const address1 = AptosAddress.create(ADDRESS); - const address2 = AptosAddress.create(address1); - - expect(address1 === address2).toBe(true); }); - it('equals() returns correct value', () => { - const a = AptosAddress.create(ADDRESS); - const b = AptosAddress.create(ADDRESS); - const c = '0x0000357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b'; - - expect(a.equals(b)).toBe(true); - expect(b.equals(a)).toBe(true); - expect(a.equals(c)).toBe(false); - expect(b.equals(c)).toBe(false); - }); + describe('normalization', () => { + it('returns normalized address', () => { + expect(AptosAddress.create('0x1').address).toBe( + '0x0000000000000000000000000000000000000000000000000000000000000001', + ); + expect(AptosAddress.create('1').address).toBe( + '0x0000000000000000000000000000000000000000000000000000000000000001', + ); + }); - it('should check equality of 2 addresses of the same value via a static method', () => { - const addressA = AptosAddress.create(ADDRESS); - const addressB = AptosAddress.create(ADDRESS); + it('util methods returns proper value', () => { + const foo = AptosAddress.create('0x1'); - expect(AptosAddress.equals(addressA, addressB)).toBeTruthy(); + expect(foo.address).toBe('0x0000000000000000000000000000000000000000000000000000000000000001'); + expect(foo.format()).toBe('0x0000000000000000000000000000000000000000000000000000000000000001'); + expect(foo.toJSON()).toBe('0x0000000000000000000000000000000000000000000000000000000000000001'); + }); }); - it('should check inequality of 2 addresses of different value', () => { - const addressA = AptosAddress.create(ADDRESS); - const addressB = AptosAddress.create(validAddresses[1]); - - expect(addressA.equals(addressB)).toBeFalsy(); + describe('errors', () => { + it('throws an error when address is invalid', () => { + expect(() => AptosAddress.create('invalid')).toThrowError('[C0005] Invalid address provided'); + expect(() => + AptosAddress.create( + '0x19aadeca9388e009d136245b9a67423f3eee242b03142849eb4f81a4a409e59c19aadeca9388e009d136245b9a67423f3eee242b03142849eb4f81a4a409e59c', + ), + ).toThrowError('[C0005] Invalid address provided'); + }); }); }); diff --git a/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.ts b/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.ts index 1a9702b191..823123634a 100644 --- a/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.ts +++ b/packages/common/aptosUtils/src/dataTypes/AptosAddress/AptosAddress.ts @@ -5,10 +5,12 @@ import { AccountAddress } from '../../utils/AccountAddress'; * Valid input for a new AptosAddress instance. * This can be an existing AptosAddress or a valid address string. * - * @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" - * @example AptosAddress.create("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM") + * @example "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90" + * @example AptosAddress.create("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90") */ -export type AptosAddressish = AptosAddress | string; +export type AptosAddressInput = AptosAddress | string; + +export type AptosAddressJSON = string; /** * A representation of an address on the Aptos network. @@ -21,21 +23,25 @@ export class AptosAddress implements MoralisData { /** * Create a new instance of AptosAddress from any valid address input. * - * @example `const address = AptosAddress.create("0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c")` + * @example `const address = AptosAddress.create("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90")` * @throws an error when a passed address is invalid. */ - public static create(address: AptosAddressish): AptosAddress { - return address instanceof AptosAddress ? address : new AptosAddress(AptosAddress.parse(address)); + public static create(address: AptosAddressInput): AptosAddress { + if (address instanceof AptosAddress) { + return address; + } + return new AptosAddress(AptosAddress.parse(address)); + } + + public static fromJSON(json: AptosAddressJSON): AptosAddress { + return AptosAddress.create(json); } private static parse(address: string): string { try { if (!AccountAddress.isValid(address)) { - // Throw and catch locally to resolve the same way if it is invalid and if it cannot be parsed - throw new Error(); + throw new Error('Address is invalid'); } - - return address; } catch (e) { throw new CoreError({ code: CoreErrorCode.INVALID_ARGUMENT, @@ -43,6 +49,11 @@ export class AptosAddress implements MoralisData { cause: e, }); } + + if (address.startsWith('0x')) { + address = address.substring(2); + } + return '0x' + address.padStart(64, '0'); } public constructor(public readonly address: string) {} @@ -50,7 +61,7 @@ export class AptosAddress implements MoralisData { /** * Formats the address to hex format. * Currently returns a string representing the address. - * @example address.format(); // "0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c" + * @example address.format(); // "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90" */ public format(): MoralisDataFormatted { // TODO: add `format` argument @@ -59,24 +70,24 @@ export class AptosAddress implements MoralisData { /** * Check the equality between two Aptos addresses - * @example `AptosAddress.equals("0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c", "0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c")` + * @example `AptosAddress.equals("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90", "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90")` */ - static equals(addressA: AptosAddressish, addressB: AptosAddressish) { + static equals(addressA: AptosAddressInput, addressB: AptosAddressInput) { return AptosAddress.create(addressA).equals(addressB); } /** * Checks the equality of the current address with another Aptos address. - * @example `address.equals("0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c")` - * @example `address.equals(AptosAddress.create("0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c"))` + * @example `address.equals("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90")` + * @example `address.equals(AptosAddress.create("0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90"))` */ - public equals(address: AptosAddressish): boolean { + public equals(address: AptosAddressInput): boolean { return this.address === AptosAddress.create(address).address; } /** * @returns a string representing the address. - * @example address.toString(); // "0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c" + * @example address.toString(); // "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90" */ public toString(): string { return this.address; @@ -84,9 +95,9 @@ export class AptosAddress implements MoralisData { /** * @returns a string representing the address. - * @example address.toJSON(); // "0xcd30fbbda98b2aed026772c13e5ed90a7f056b589ef9e78cd96415e1af12451c" + * @example address.toJSON(); // "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90" */ - public toJSON(): string { + public toJSON(): AptosAddressJSON { return this.address; } } diff --git a/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.test.ts b/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.test.ts index ef8d367f5c..161425dbd2 100644 --- a/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.test.ts +++ b/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.test.ts @@ -1,9 +1,9 @@ import { BigNumber } from '@moralisweb3/common-core'; -import { AptosNative, AptosNativeish, AptosNativeUnit } from './AptosNative'; +import { AptosNative, AptosNativeInput, AptosNativeUnit } from './AptosNative'; describe('AptosNative', () => { function testUnit( - value: AptosNativeish, + value: AptosNativeInput, unit: AptosNativeUnit | undefined, expectedAptos: string, expectedOctas: string, diff --git a/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.ts b/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.ts index e347d038d0..cd4febb653 100644 --- a/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.ts +++ b/packages/common/aptosUtils/src/dataTypes/AptosNative/AptosNative.ts @@ -16,7 +16,9 @@ export type AptosNativeUnit = 'aptos' | 'octas' | number; * Valid input for a new AptosNative instance. * This can be an existing {@link AptosNative} or a valid {@link @moralisweb3/common-core!BigNumberish} type */ -export type AptosNativeish = AptosNative | BigNumberish; +export type AptosNativeInput = AptosNative | BigNumberish; + +export type AptosNativeJSON = string; const unitToDecimals: Record = { aptos: 8, @@ -30,7 +32,7 @@ const unitToDecimals: Record = { */ export class AptosNative implements MoralisData { /** - * Create a new instance of AptosNative from any valid {@link AptosNativeish} value. + * Create a new instance of AptosNative from any valid {@link AptosNativeInput} value. * @param value - the value to create the AptosNative from * @param unit - the unit of the value (optional), defaults to `aptos` * @returns a new instance of AptosNative @@ -40,13 +42,17 @@ export class AptosNative implements MoralisData { * const native = AptosNative.create(2); *``` */ - public static create(value: AptosNativeish, unit?: AptosNativeUnit): AptosNative { + public static create(value: AptosNativeInput, unit?: AptosNativeUnit): AptosNative { if (value instanceof AptosNative) { return value; } return new AptosNative(AptosNative.parse(value, unit)); } + public static fromJSON(json: AptosNativeJSON): AptosNative { + return AptosNative.create(json, 'octas'); + } + private static parse(value: BigNumberish, unit: AptosNativeUnit = 'aptos'): BigNumber { let decimal: number; if (typeof unit === 'number') { @@ -74,7 +80,7 @@ export class AptosNative implements MoralisData { * AptosNative.equals(AptosNative.create(1), AptosNative.create(1)); // true * ``` */ - public static equals(valueA: AptosNativeish, valueB: AptosNativeish): boolean { + public static equals(valueA: AptosNativeInput, valueB: AptosNativeInput): boolean { const aptosNativeA = AptosNative.create(valueA); const aptosNativeB = AptosNative.create(valueB); @@ -110,7 +116,7 @@ export class AptosNative implements MoralisData { * @returns the value of the AptosNative as a string * @example `native.toJSON()` */ - public toJSON(): string { + public toJSON(): AptosNativeJSON { return this.octas; } diff --git a/packages/common/aptosUtils/src/dataTypes/AptosNetwork/AptosNetwork.ts b/packages/common/aptosUtils/src/dataTypes/AptosNetwork/AptosNetwork.ts index 1db2ccd919..b0574ad906 100644 --- a/packages/common/aptosUtils/src/dataTypes/AptosNetwork/AptosNetwork.ts +++ b/packages/common/aptosUtils/src/dataTypes/AptosNetwork/AptosNetwork.ts @@ -20,7 +20,7 @@ export type AptosNetworkName = typeof aptosNetworkNames[number]; * @example "mainnet" * @example "devnet" */ -export type AptosNetworkNameish = AptosNetworkName | string; +export type AptosNetworkJSON = AptosNetworkName | string; /** * Valid input for a new AptosNetwork instance. @@ -30,7 +30,7 @@ export type AptosNetworkNameish = AptosNetworkName | string; * @example "devnet" * @example AptosNetwork.create("mainnet") */ -export type AptosNetworkish = AptosNetwork | AptosNetworkNameish; +export type AptosNetworkInput = AptosNetwork | AptosNetworkJSON; /** * A representation of a Aptos network. @@ -70,11 +70,11 @@ export class AptosNetwork implements MoralisData { * @example `const network = AptosNetwork.create("mainnet")` * @throws an error when a passed network is invalid. */ - public static create(network: AptosNetworkish): AptosNetwork { + public static create(network: AptosNetworkInput): AptosNetwork { return network instanceof AptosNetwork ? network : new AptosNetwork(AptosNetwork.parse(network)); } - private static parse(network: AptosNetworkNameish): AptosNetworkName { + private static parse(network: AptosNetworkJSON): AptosNetworkName { if (typeof network !== 'string') { throw new CoreError({ code: CoreErrorCode.INVALID_ARGUMENT, @@ -111,7 +111,7 @@ export class AptosNetwork implements MoralisData { * @example `network.equals("mainnet")` * @example `network.equals(AptosNetwork.create("mainnet"))` */ - public equals(network: AptosNetworkish): boolean { + public equals(network: AptosNetworkInput): boolean { return this.network === AptosNetwork.create(network).network; } diff --git a/packages/common/aptosUtils/src/generated/client/abstractClient.ts b/packages/common/aptosUtils/src/generated/client/abstractClient.ts new file mode 100644 index 0000000000..ceebc7babb --- /dev/null +++ b/packages/common/aptosUtils/src/generated/client/abstractClient.ts @@ -0,0 +1,401 @@ +import { GetNFTsByIdsOperation, GetNFTsByIdsOperationRequest, GetNFTsByIdsOperationRequestJSON } from '../operations/GetNFTsByIdsOperation'; +import { AptosNFTTokenResponse, AptosNFTTokenResponseJSON } from '../types/AptosNFTTokenResponse'; +import { GetNFTsByCollectionOperation, GetNFTsByCollectionOperationRequest, GetNFTsByCollectionOperationRequestJSON } from '../operations/GetNFTsByCollectionOperation'; +import { AptosNFTTokensByCollectionResponse, AptosNFTTokensByCollectionResponseJSON } from '../types/AptosNFTTokensByCollectionResponse'; +import { GetNFTsByCreatorsOperation, GetNFTsByCreatorsOperationRequest, GetNFTsByCreatorsOperationRequestJSON } from '../operations/GetNFTsByCreatorsOperation'; +import { AptosNFTTokensByCreatorsResponse, AptosNFTTokensByCreatorsResponseJSON } from '../types/AptosNFTTokensByCreatorsResponse'; +import { GetNFTCollectionsOperation, GetNFTCollectionsOperationRequest, GetNFTCollectionsOperationRequestJSON } from '../operations/GetNFTCollectionsOperation'; +import { AptosNFTCollectionsByNameRangeResponse, AptosNFTCollectionsByNameRangeResponseJSON } from '../types/AptosNFTCollectionsByNameRangeResponse'; +import { GetNFTCollectionsByIdsOperation, GetNFTCollectionsByIdsOperationRequest, GetNFTCollectionsByIdsOperationRequestJSON } from '../operations/GetNFTCollectionsByIdsOperation'; +import { AptosNFTCollectionItemResponse, AptosNFTCollectionItemResponseJSON } from '../types/AptosNFTCollectionItemResponse'; +import { GetNFTCollectionsByCreatorOperation, GetNFTCollectionsByCreatorOperationRequest, GetNFTCollectionsByCreatorOperationRequestJSON } from '../operations/GetNFTCollectionsByCreatorOperation'; +import { AptosNFTCollectionsByCreatorResponse, AptosNFTCollectionsByCreatorResponseJSON } from '../types/AptosNFTCollectionsByCreatorResponse'; +import { GetNFTOwnersByTokensOperation, GetNFTOwnersByTokensOperationRequest, GetNFTOwnersByTokensOperationRequestJSON } from '../operations/GetNFTOwnersByTokensOperation'; +import { AptosNFTOwnersByTokensResponse, AptosNFTOwnersByTokensResponseJSON } from '../types/AptosNFTOwnersByTokensResponse'; +import { GetNFTOwnersByCollectionOperation, GetNFTOwnersByCollectionOperationRequest, GetNFTOwnersByCollectionOperationRequestJSON } from '../operations/GetNFTOwnersByCollectionOperation'; +import { AptosNFTOwnersByCollectionResponse, AptosNFTOwnersByCollectionResponseJSON } from '../types/AptosNFTOwnersByCollectionResponse'; +import { GetNFTOwnersOfCollectionOperation, GetNFTOwnersOfCollectionOperationRequest, GetNFTOwnersOfCollectionOperationRequestJSON } from '../operations/GetNFTOwnersOfCollectionOperation'; +import { AptosNFTOwnersOfCollectionResponse, AptosNFTOwnersOfCollectionResponseJSON } from '../types/AptosNFTOwnersOfCollectionResponse'; +import { GetNFTTransfersByIdsOperation, GetNFTTransfersByIdsOperationRequest, GetNFTTransfersByIdsOperationRequestJSON } from '../operations/GetNFTTransfersByIdsOperation'; +import { AptosNFTTransfersByTokensResponse, AptosNFTTransfersByTokensResponseJSON } from '../types/AptosNFTTransfersByTokensResponse'; +import { GetNFTTransfersByCollectionOperation, GetNFTTransfersByCollectionOperationRequest, GetNFTTransfersByCollectionOperationRequestJSON } from '../operations/GetNFTTransfersByCollectionOperation'; +import { AptosGetNFTTransfersByCollectionResponse, AptosGetNFTTransfersByCollectionResponseJSON } from '../types/AptosGetNFTTransfersByCollectionResponse'; +import { GetNFTTransfersByCreatorsOperation, GetNFTTransfersByCreatorsOperationRequest, GetNFTTransfersByCreatorsOperationRequestJSON } from '../operations/GetNFTTransfersByCreatorsOperation'; +import { AptosGetNFTTransfersByCreatorsResponse, AptosGetNFTTransfersByCreatorsResponseJSON } from '../types/AptosGetNFTTransfersByCreatorsResponse'; +import { GetNFTTransfersByWalletsOperation, GetNFTTransfersByWalletsOperationRequest, GetNFTTransfersByWalletsOperationRequestJSON } from '../operations/GetNFTTransfersByWalletsOperation'; +import { AptosNFTTransfersByWalletsResponse, AptosNFTTransfersByWalletsResponseJSON } from '../types/AptosNFTTransfersByWalletsResponse'; +import { GetCoinInfoByCoinTypeHashesOperation, GetCoinInfoByCoinTypeHashesOperationRequest, GetCoinInfoByCoinTypeHashesOperationRequestJSON } from '../operations/GetCoinInfoByCoinTypeHashesOperation'; +import { AptosCoinInfoDto, AptosCoinInfoDtoJSON } from '../types/AptosCoinInfoDto'; +import { GetLatestCoinsOperation, GetLatestCoinsOperationRequest, GetLatestCoinsOperationRequestJSON } from '../operations/GetLatestCoinsOperation'; +import { AptosGetLatestCoinsResponse, AptosGetLatestCoinsResponseJSON } from '../types/AptosGetLatestCoinsResponse'; +import { GetCoinsByNameRangeOperation, GetCoinsByNameRangeOperationRequest, GetCoinsByNameRangeOperationRequestJSON } from '../operations/GetCoinsByNameRangeOperation'; +import { AptosGetCoinsByNameRangeResponse, AptosGetCoinsByNameRangeResponseJSON } from '../types/AptosGetCoinsByNameRangeResponse'; +import { GetCoinsBySymbolRangeOperation, GetCoinsBySymbolRangeOperationRequest, GetCoinsBySymbolRangeOperationRequestJSON } from '../operations/GetCoinsBySymbolRangeOperation'; +import { AptosGetCoinsBySymbolRangeResponse, AptosGetCoinsBySymbolRangeResponseJSON } from '../types/AptosGetCoinsBySymbolRangeResponse'; +import { GetCoinsByCreatorsOperation, GetCoinsByCreatorsOperationRequest, GetCoinsByCreatorsOperationRequestJSON } from '../operations/GetCoinsByCreatorsOperation'; +import { AptosGetCoinsByCreatorsResponse, AptosGetCoinsByCreatorsResponseJSON } from '../types/AptosGetCoinsByCreatorsResponse'; +import { GetCoinTransfersByOwnerAddressesOperation, GetCoinTransfersByOwnerAddressesOperationRequest, GetCoinTransfersByOwnerAddressesOperationRequestJSON } from '../operations/GetCoinTransfersByOwnerAddressesOperation'; +import { AptosGetCoinTransfersByOwnerAddressesResponse, AptosGetCoinTransfersByOwnerAddressesResponseJSON } from '../types/AptosGetCoinTransfersByOwnerAddressesResponse'; +import { GetCoinTransfersByBlockHeightsOperation, GetCoinTransfersByBlockHeightsOperationRequest, GetCoinTransfersByBlockHeightsOperationRequestJSON } from '../operations/GetCoinTransfersByBlockHeightsOperation'; +import { AptosGetCoinTransfersByBlockHeightsResponse, AptosGetCoinTransfersByBlockHeightsResponseJSON } from '../types/AptosGetCoinTransfersByBlockHeightsResponse'; +import { GetCoinTransfersByCoinTypeOperation, GetCoinTransfersByCoinTypeOperationRequest, GetCoinTransfersByCoinTypeOperationRequestJSON } from '../operations/GetCoinTransfersByCoinTypeOperation'; +import { AptosGetCoinTransfersByCoinTypeResponse, AptosGetCoinTransfersByCoinTypeResponseJSON } from '../types/AptosGetCoinTransfersByCoinTypeResponse'; +import { GetTopHoldersByCoinOperation, GetTopHoldersByCoinOperationRequest, GetTopHoldersByCoinOperationRequestJSON } from '../operations/GetTopHoldersByCoinOperation'; +import { AptosGetTopHoldersByCoinResponse, AptosGetTopHoldersByCoinResponseJSON } from '../types/AptosGetTopHoldersByCoinResponse'; +import { GetCoinBalancesByWalletsOperation, GetCoinBalancesByWalletsOperationRequest, GetCoinBalancesByWalletsOperationRequestJSON } from '../operations/GetCoinBalancesByWalletsOperation'; +import { AptosGetCoinBalancesByWalletsResponse, AptosGetCoinBalancesByWalletsResponseJSON } from '../types/AptosGetCoinBalancesByWalletsResponse'; +import { GetHistoricalCoinBalancesByWalletsOperation, GetHistoricalCoinBalancesByWalletsOperationRequest, GetHistoricalCoinBalancesByWalletsOperationRequestJSON } from '../operations/GetHistoricalCoinBalancesByWalletsOperation'; +import { AptosGetHistoricalCoinBalancesByWalletsResponse, AptosGetHistoricalCoinBalancesByWalletsResponseJSON } from '../types/AptosGetHistoricalCoinBalancesByWalletsResponse'; +import { GetCoinTransfersByWalletAddressesOperation, GetCoinTransfersByWalletAddressesOperationRequest, GetCoinTransfersByWalletAddressesOperationRequestJSON } from '../operations/GetCoinTransfersByWalletAddressesOperation'; +import { GetNFTByOwnersOperation, GetNFTByOwnersOperationRequest, GetNFTByOwnersOperationRequestJSON } from '../operations/GetNFTByOwnersOperation'; +import { AptosNFTsByOwnersResponse, AptosNFTsByOwnersResponseJSON } from '../types/AptosNFTsByOwnersResponse'; +import { GetWalletsNFTTransfersOperation, GetWalletsNFTTransfersOperationRequest, GetWalletsNFTTransfersOperationRequestJSON } from '../operations/GetWalletsNFTTransfersOperation'; +import { GetAccountOperation, GetAccountOperationRequest, GetAccountOperationRequestJSON } from '../operations/GetAccountOperation'; +import { AptosGetAccountResponse, AptosGetAccountResponseJSON } from '../types/AptosGetAccountResponse'; +import { GetAccountResourcesOperation, GetAccountResourcesOperationRequest, GetAccountResourcesOperationRequestJSON } from '../operations/GetAccountResourcesOperation'; +import { AptosGetAccountResourceResponse, AptosGetAccountResourceResponseJSON } from '../types/AptosGetAccountResourceResponse'; +import { GetAccountModulesOperation, GetAccountModulesOperationRequest, GetAccountModulesOperationRequestJSON } from '../operations/GetAccountModulesOperation'; +import { AptosGetAccountModuleResponse, AptosGetAccountModuleResponseJSON } from '../types/AptosGetAccountModuleResponse'; +import { GetAccountResourceOperation, GetAccountResourceOperationRequest, GetAccountResourceOperationRequestJSON } from '../operations/GetAccountResourceOperation'; +import { GetAccountModuleOperation, GetAccountModuleOperationRequest, GetAccountModuleOperationRequestJSON } from '../operations/GetAccountModuleOperation'; +import { GetEventsByCreationNumberOperation, GetEventsByCreationNumberOperationRequest, GetEventsByCreationNumberOperationRequestJSON } from '../operations/GetEventsByCreationNumberOperation'; +import { AptosGetEventsByCreationNumberResponse, AptosGetEventsByCreationNumberResponseJSON } from '../types/AptosGetEventsByCreationNumberResponse'; +import { GetEventsByEventHandleOperation, GetEventsByEventHandleOperationRequest, GetEventsByEventHandleOperationRequestJSON } from '../operations/GetEventsByEventHandleOperation'; +import { AptosGetEventsByEventHandleResponse, AptosGetEventsByEventHandleResponseJSON } from '../types/AptosGetEventsByEventHandleResponse'; +import { GetTransactionsOperation, GetTransactionsOperationRequest, GetTransactionsOperationRequestJSON } from '../operations/GetTransactionsOperation'; +import { AptosGetTransactionsItemValue, AptosGetTransactionsItemJSON } from '../types/AptosGetTransactionsItem'; +import { SubmitTransactionOperation, SubmitTransactionOperationRequest, SubmitTransactionOperationRequestJSON } from '../operations/SubmitTransactionOperation'; +import { AptosPendingTransaction, AptosPendingTransactionJSON } from '../types/AptosPendingTransaction'; +import { AptosSubmitTransactionRequest, AptosSubmitTransactionRequestInput, AptosSubmitTransactionRequestJSON } from '../types/AptosSubmitTransactionRequest'; +import { GetTransactionByHashOperation, GetTransactionByHashOperationRequest, GetTransactionByHashOperationRequestJSON } from '../operations/GetTransactionByHashOperation'; +import { AptosGetTransactionByHashValue, AptosGetTransactionByHashJSON } from '../types/AptosGetTransactionByHash'; +import { GetTransactionByVersionOperation, GetTransactionByVersionOperationRequest, GetTransactionByVersionOperationRequestJSON } from '../operations/GetTransactionByVersionOperation'; +import { AptosGetTransactionByVersionValue, AptosGetTransactionByVersionJSON } from '../types/AptosGetTransactionByVersion'; +import { GetAccountTransactionsOperation, GetAccountTransactionsOperationRequest, GetAccountTransactionsOperationRequestJSON } from '../operations/GetAccountTransactionsOperation'; +import { AptosGetAccountTransactionsItemValue, AptosGetAccountTransactionsItemJSON } from '../types/AptosGetAccountTransactionsItem'; +import { SubmitBatchTransactionsOperation, SubmitBatchTransactionsOperationRequest, SubmitBatchTransactionsOperationRequestJSON } from '../operations/SubmitBatchTransactionsOperation'; +import { AptosSubmitBatchTransactionResult, AptosSubmitBatchTransactionResultJSON } from '../types/AptosSubmitBatchTransactionResult'; +import { SimulateTransactionOperation, SimulateTransactionOperationRequest, SimulateTransactionOperationRequestJSON } from '../operations/SimulateTransactionOperation'; +import { AptosSimulateTransactionValue, AptosSimulateTransactionJSON } from '../types/AptosSimulateTransaction'; +import { EncodeSubmissionOperation, EncodeSubmissionOperationRequest, EncodeSubmissionOperationRequestJSON } from '../operations/EncodeSubmissionOperation'; +import { AptosEncodeSubmissionRequest, AptosEncodeSubmissionRequestInput, AptosEncodeSubmissionRequestJSON } from '../types/AptosEncodeSubmissionRequest'; +import { EstimateGasPriceOperation, EstimateGasPriceOperationRequest, EstimateGasPriceOperationRequestJSON } from '../operations/EstimateGasPriceOperation'; +import { AptosEstimateGasPriceResult, AptosEstimateGasPriceResultJSON } from '../types/AptosEstimateGasPriceResult'; +import { GetBlockByHeightOperation, GetBlockByHeightOperationRequest, GetBlockByHeightOperationRequestJSON } from '../operations/GetBlockByHeightOperation'; +import { AptosBlock, AptosBlockJSON } from '../types/AptosBlock'; +import { GetBlockByVersionOperation, GetBlockByVersionOperationRequest, GetBlockByVersionOperationRequestJSON } from '../operations/GetBlockByVersionOperation'; + +export interface OperationV3 { + operationId: string; + groupName: string; + httpMethod: string; + routePattern: string; + parameterNames: string[]; + hasResponse: boolean; + hasBody: boolean; + serializeRequest?: (request: Request) => RequestJSON; + parseResponse?: (json: ResponseJSON) => Response; + serializeBody?: (body: Body) => BodyJSON; +} + +export abstract class AbstractClient { + protected abstract createEndpoint( + operation: OperationV3 + ): (request: Request) => Promise; + protected abstract createEndpointWithBody( + operation: OperationV3 + ): (request: Request, body: Body) => Promise; + + public readonly accounts = { + getAccount: this.createEndpoint< + GetAccountOperationRequest + , GetAccountOperationRequestJSON + , AptosGetAccountResponse + , AptosGetAccountResponseJSON + >(GetAccountOperation), + getAccountResources: this.createEndpoint< + GetAccountResourcesOperationRequest + , GetAccountResourcesOperationRequestJSON + , AptosGetAccountResourceResponse[] + , AptosGetAccountResourceResponseJSON[] + >(GetAccountResourcesOperation), + getAccountModules: this.createEndpoint< + GetAccountModulesOperationRequest + , GetAccountModulesOperationRequestJSON + , AptosGetAccountModuleResponse[] + , AptosGetAccountModuleResponseJSON[] + >(GetAccountModulesOperation), + getAccountResource: this.createEndpoint< + GetAccountResourceOperationRequest + , GetAccountResourceOperationRequestJSON + , AptosGetAccountResourceResponse + , AptosGetAccountResourceResponseJSON + >(GetAccountResourceOperation), + getAccountModule: this.createEndpoint< + GetAccountModuleOperationRequest + , GetAccountModuleOperationRequestJSON + , AptosGetAccountModuleResponse + , AptosGetAccountModuleResponseJSON + >(GetAccountModuleOperation), + getEventsByCreationNumber: this.createEndpoint< + GetEventsByCreationNumberOperationRequest + , GetEventsByCreationNumberOperationRequestJSON + , AptosGetEventsByCreationNumberResponse[] + , AptosGetEventsByCreationNumberResponseJSON[] + >(GetEventsByCreationNumberOperation), + getEventsByEventHandle: this.createEndpoint< + GetEventsByEventHandleOperationRequest + , GetEventsByEventHandleOperationRequestJSON + , AptosGetEventsByEventHandleResponse[] + , AptosGetEventsByEventHandleResponseJSON[] + >(GetEventsByEventHandleOperation), + }; + public readonly blocks = { + getBlockByHeight: this.createEndpoint< + GetBlockByHeightOperationRequest + , GetBlockByHeightOperationRequestJSON + , AptosBlock + , AptosBlockJSON + >(GetBlockByHeightOperation), + getBlockByVersion: this.createEndpoint< + GetBlockByVersionOperationRequest + , GetBlockByVersionOperationRequestJSON + , AptosBlock + , AptosBlockJSON + >(GetBlockByVersionOperation), + }; + public readonly coins = { + getCoinInfoByCoinTypeHashes: this.createEndpoint< + GetCoinInfoByCoinTypeHashesOperationRequest + , GetCoinInfoByCoinTypeHashesOperationRequestJSON + , AptosCoinInfoDto[] + , AptosCoinInfoDtoJSON[] + >(GetCoinInfoByCoinTypeHashesOperation), + getLatestCoins: this.createEndpoint< + GetLatestCoinsOperationRequest + , GetLatestCoinsOperationRequestJSON + , AptosGetLatestCoinsResponse + , AptosGetLatestCoinsResponseJSON + >(GetLatestCoinsOperation), + getCoinsByNameRange: this.createEndpoint< + GetCoinsByNameRangeOperationRequest + , GetCoinsByNameRangeOperationRequestJSON + , AptosGetCoinsByNameRangeResponse + , AptosGetCoinsByNameRangeResponseJSON + >(GetCoinsByNameRangeOperation), + getCoinsBySymbolRange: this.createEndpoint< + GetCoinsBySymbolRangeOperationRequest + , GetCoinsBySymbolRangeOperationRequestJSON + , AptosGetCoinsBySymbolRangeResponse + , AptosGetCoinsBySymbolRangeResponseJSON + >(GetCoinsBySymbolRangeOperation), + getCoinsByCreators: this.createEndpoint< + GetCoinsByCreatorsOperationRequest + , GetCoinsByCreatorsOperationRequestJSON + , AptosGetCoinsByCreatorsResponse + , AptosGetCoinsByCreatorsResponseJSON + >(GetCoinsByCreatorsOperation), + getCoinTransfersByOwnerAddresses: this.createEndpoint< + GetCoinTransfersByOwnerAddressesOperationRequest + , GetCoinTransfersByOwnerAddressesOperationRequestJSON + , AptosGetCoinTransfersByOwnerAddressesResponse + , AptosGetCoinTransfersByOwnerAddressesResponseJSON + >(GetCoinTransfersByOwnerAddressesOperation), + getCoinTransfersByBlockHeights: this.createEndpoint< + GetCoinTransfersByBlockHeightsOperationRequest + , GetCoinTransfersByBlockHeightsOperationRequestJSON + , AptosGetCoinTransfersByBlockHeightsResponse + , AptosGetCoinTransfersByBlockHeightsResponseJSON + >(GetCoinTransfersByBlockHeightsOperation), + getCoinTransfersByCoinType: this.createEndpoint< + GetCoinTransfersByCoinTypeOperationRequest + , GetCoinTransfersByCoinTypeOperationRequestJSON + , AptosGetCoinTransfersByCoinTypeResponse + , AptosGetCoinTransfersByCoinTypeResponseJSON + >(GetCoinTransfersByCoinTypeOperation), + getTopHoldersByCoin: this.createEndpoint< + GetTopHoldersByCoinOperationRequest + , GetTopHoldersByCoinOperationRequestJSON + , AptosGetTopHoldersByCoinResponse + , AptosGetTopHoldersByCoinResponseJSON + >(GetTopHoldersByCoinOperation), + }; + public readonly collections = { + getNFTCollections: this.createEndpoint< + GetNFTCollectionsOperationRequest + , GetNFTCollectionsOperationRequestJSON + , AptosNFTCollectionsByNameRangeResponse + , AptosNFTCollectionsByNameRangeResponseJSON + >(GetNFTCollectionsOperation), + getNFTCollectionsByIds: this.createEndpoint< + GetNFTCollectionsByIdsOperationRequest + , GetNFTCollectionsByIdsOperationRequestJSON + , AptosNFTCollectionItemResponse[] + , AptosNFTCollectionItemResponseJSON[] + >(GetNFTCollectionsByIdsOperation), + getNFTCollectionsByCreator: this.createEndpoint< + GetNFTCollectionsByCreatorOperationRequest + , GetNFTCollectionsByCreatorOperationRequestJSON + , AptosNFTCollectionsByCreatorResponse + , AptosNFTCollectionsByCreatorResponseJSON + >(GetNFTCollectionsByCreatorOperation), + }; + public readonly nfts = { + getNFTsByIds: this.createEndpoint< + GetNFTsByIdsOperationRequest + , GetNFTsByIdsOperationRequestJSON + , AptosNFTTokenResponse[] + , AptosNFTTokenResponseJSON[] + >(GetNFTsByIdsOperation), + getNFTsByCollection: this.createEndpoint< + GetNFTsByCollectionOperationRequest + , GetNFTsByCollectionOperationRequestJSON + , AptosNFTTokensByCollectionResponse + , AptosNFTTokensByCollectionResponseJSON + >(GetNFTsByCollectionOperation), + getNFTsByCreators: this.createEndpoint< + GetNFTsByCreatorsOperationRequest + , GetNFTsByCreatorsOperationRequestJSON + , AptosNFTTokensByCreatorsResponse + , AptosNFTTokensByCreatorsResponseJSON + >(GetNFTsByCreatorsOperation), + getNFTOwnersByTokens: this.createEndpoint< + GetNFTOwnersByTokensOperationRequest + , GetNFTOwnersByTokensOperationRequestJSON + , AptosNFTOwnersByTokensResponse + , AptosNFTOwnersByTokensResponseJSON + >(GetNFTOwnersByTokensOperation), + getNFTOwnersByCollection: this.createEndpoint< + GetNFTOwnersByCollectionOperationRequest + , GetNFTOwnersByCollectionOperationRequestJSON + , AptosNFTOwnersByCollectionResponse + , AptosNFTOwnersByCollectionResponseJSON + >(GetNFTOwnersByCollectionOperation), + getNFTOwnersOfCollection: this.createEndpoint< + GetNFTOwnersOfCollectionOperationRequest + , GetNFTOwnersOfCollectionOperationRequestJSON + , AptosNFTOwnersOfCollectionResponse + , AptosNFTOwnersOfCollectionResponseJSON + >(GetNFTOwnersOfCollectionOperation), + getNFTTransfersByIds: this.createEndpoint< + GetNFTTransfersByIdsOperationRequest + , GetNFTTransfersByIdsOperationRequestJSON + , AptosNFTTransfersByTokensResponse[] + , AptosNFTTransfersByTokensResponseJSON[] + >(GetNFTTransfersByIdsOperation), + getNFTTransfersByCollection: this.createEndpoint< + GetNFTTransfersByCollectionOperationRequest + , GetNFTTransfersByCollectionOperationRequestJSON + , AptosGetNFTTransfersByCollectionResponse + , AptosGetNFTTransfersByCollectionResponseJSON + >(GetNFTTransfersByCollectionOperation), + getNFTTransfersByCreators: this.createEndpoint< + GetNFTTransfersByCreatorsOperationRequest + , GetNFTTransfersByCreatorsOperationRequestJSON + , AptosGetNFTTransfersByCreatorsResponse + , AptosGetNFTTransfersByCreatorsResponseJSON + >(GetNFTTransfersByCreatorsOperation), + getNFTTransfersByWallets: this.createEndpoint< + GetNFTTransfersByWalletsOperationRequest + , GetNFTTransfersByWalletsOperationRequestJSON + , AptosNFTTransfersByWalletsResponse + , AptosNFTTransfersByWalletsResponseJSON + >(GetNFTTransfersByWalletsOperation), + }; + public readonly transactions = { + getTransactions: this.createEndpoint< + GetTransactionsOperationRequest + , GetTransactionsOperationRequestJSON + , AptosGetTransactionsItemValue[] + , AptosGetTransactionsItemJSON[] + >(GetTransactionsOperation), + submitTransaction: this.createEndpointWithBody< + SubmitTransactionOperationRequest + , SubmitTransactionOperationRequestJSON + , AptosPendingTransaction + , AptosPendingTransactionJSON + , AptosSubmitTransactionRequestInput | AptosSubmitTransactionRequest + , AptosSubmitTransactionRequestJSON + >(SubmitTransactionOperation), + getTransactionByHash: this.createEndpoint< + GetTransactionByHashOperationRequest + , GetTransactionByHashOperationRequestJSON + , AptosGetTransactionByHashValue + , AptosGetTransactionByHashJSON + >(GetTransactionByHashOperation), + getTransactionByVersion: this.createEndpoint< + GetTransactionByVersionOperationRequest + , GetTransactionByVersionOperationRequestJSON + , AptosGetTransactionByVersionValue + , AptosGetTransactionByVersionJSON + >(GetTransactionByVersionOperation), + getAccountTransactions: this.createEndpoint< + GetAccountTransactionsOperationRequest + , GetAccountTransactionsOperationRequestJSON + , AptosGetAccountTransactionsItemValue[] + , AptosGetAccountTransactionsItemJSON[] + >(GetAccountTransactionsOperation), + submitBatchTransactions: this.createEndpointWithBody< + SubmitBatchTransactionsOperationRequest + , SubmitBatchTransactionsOperationRequestJSON + , AptosSubmitBatchTransactionResult + , AptosSubmitBatchTransactionResultJSON + , AptosSubmitTransactionRequestInput[] | AptosSubmitTransactionRequest[] + , AptosSubmitTransactionRequestJSON[] + >(SubmitBatchTransactionsOperation), + simulateTransaction: this.createEndpointWithBody< + SimulateTransactionOperationRequest + , SimulateTransactionOperationRequestJSON + , AptosSimulateTransactionValue + , AptosSimulateTransactionJSON + , AptosSubmitTransactionRequestInput | AptosSubmitTransactionRequest + , AptosSubmitTransactionRequestJSON + >(SimulateTransactionOperation), + encodeSubmission: this.createEndpointWithBody< + EncodeSubmissionOperationRequest + , EncodeSubmissionOperationRequestJSON + , string + , string + , AptosEncodeSubmissionRequestInput | AptosEncodeSubmissionRequest + , AptosEncodeSubmissionRequestJSON + >(EncodeSubmissionOperation), + estimateGasPrice: this.createEndpoint< + EstimateGasPriceOperationRequest + , EstimateGasPriceOperationRequestJSON + , AptosEstimateGasPriceResult + , AptosEstimateGasPriceResultJSON + >(EstimateGasPriceOperation), + }; + public readonly wallets = { + getCoinBalancesByWallets: this.createEndpoint< + GetCoinBalancesByWalletsOperationRequest + , GetCoinBalancesByWalletsOperationRequestJSON + , AptosGetCoinBalancesByWalletsResponse + , AptosGetCoinBalancesByWalletsResponseJSON + >(GetCoinBalancesByWalletsOperation), + getHistoricalCoinBalancesByWallets: this.createEndpoint< + GetHistoricalCoinBalancesByWalletsOperationRequest + , GetHistoricalCoinBalancesByWalletsOperationRequestJSON + , AptosGetHistoricalCoinBalancesByWalletsResponse + , AptosGetHistoricalCoinBalancesByWalletsResponseJSON + >(GetHistoricalCoinBalancesByWalletsOperation), + getCoinTransfersByWalletAddresses: this.createEndpoint< + GetCoinTransfersByWalletAddressesOperationRequest + , GetCoinTransfersByWalletAddressesOperationRequestJSON + , AptosGetCoinTransfersByOwnerAddressesResponse + , AptosGetCoinTransfersByOwnerAddressesResponseJSON + >(GetCoinTransfersByWalletAddressesOperation), + getNFTByOwners: this.createEndpoint< + GetNFTByOwnersOperationRequest + , GetNFTByOwnersOperationRequestJSON + , AptosNFTsByOwnersResponse + , AptosNFTsByOwnersResponseJSON + >(GetNFTByOwnersOperation), + getWalletsNFTTransfers: this.createEndpoint< + GetWalletsNFTTransfersOperationRequest + , GetWalletsNFTTransfersOperationRequestJSON + , AptosNFTTransfersByWalletsResponse + , AptosNFTTransfersByWalletsResponseJSON + >(GetWalletsNFTTransfersOperation), + }; +} diff --git a/packages/common/aptosUtils/src/generated/index.ts b/packages/common/aptosUtils/src/generated/index.ts new file mode 100644 index 0000000000..1c17c91a7f --- /dev/null +++ b/packages/common/aptosUtils/src/generated/index.ts @@ -0,0 +1,3 @@ +export * from './client/abstractClient'; +export * from './operations'; +export * from './types'; diff --git a/packages/common/aptosUtils/src/generated/operations/EncodeSubmissionOperation.ts b/packages/common/aptosUtils/src/generated/operations/EncodeSubmissionOperation.ts new file mode 100644 index 0000000000..9e617aa012 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/EncodeSubmissionOperation.ts @@ -0,0 +1,42 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosEncodeSubmissionRequest, AptosEncodeSubmissionRequestInput, AptosEncodeSubmissionRequestJSON } from '../types/AptosEncodeSubmissionRequest'; + +// request parameters: +// - network ($ref: #/virtualParameter/network) + +export interface EncodeSubmissionOperationRequest { + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface EncodeSubmissionOperationRequestJSON { + readonly network?: AptosNetworkJSON; +} + +export const EncodeSubmissionOperation = { + operationId: "encodeSubmission", + groupName: "transactions", + httpMethod: "post", + routePattern: "/transactions/encode_submission", + parameterNames: ["network"], + hasResponse: true, + hasBody: true, + + parseResponse(json: string): string { + return json; + }, + + serializeRequest(request: EncodeSubmissionOperationRequest): EncodeSubmissionOperationRequestJSON { + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + network: network ? network.toJSON() : undefined, + }; + }, + + serializeBody(body: AptosEncodeSubmissionRequestInput | AptosEncodeSubmissionRequest): AptosEncodeSubmissionRequestJSON { + const value = AptosEncodeSubmissionRequest.create(body); + return value.toJSON(); + }, +} diff --git a/packages/common/aptosUtils/src/generated/operations/EstimateGasPriceOperation.ts b/packages/common/aptosUtils/src/generated/operations/EstimateGasPriceOperation.ts new file mode 100644 index 0000000000..18d85af850 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/EstimateGasPriceOperation.ts @@ -0,0 +1,38 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosEstimateGasPriceResult, AptosEstimateGasPriceResultJSON } from '../types/AptosEstimateGasPriceResult'; + +// request parameters: +// - network ($ref: #/virtualParameter/network) + +export interface EstimateGasPriceOperationRequest { + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface EstimateGasPriceOperationRequestJSON { + readonly network?: AptosNetworkJSON; +} + +export const EstimateGasPriceOperation = { + operationId: "estimateGasPrice", + groupName: "transactions", + httpMethod: "get", + routePattern: "/transactions/estimate_gas_price", + parameterNames: ["network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosEstimateGasPriceResultJSON): AptosEstimateGasPriceResult { + return AptosEstimateGasPriceResult.fromJSON(json); + }, + + serializeRequest(request: EstimateGasPriceOperationRequest): EstimateGasPriceOperationRequestJSON { + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetAccountModuleOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetAccountModuleOperation.ts new file mode 100644 index 0000000000..612b32dc5c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetAccountModuleOperation.ts @@ -0,0 +1,63 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetAccountModuleResponse, AptosGetAccountModuleResponseJSON } from '../types/AptosGetAccountModuleResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1resource~1{module_name}/get/parameters/0/schema) +// - module_name ($ref: #/paths/~1accounts~1{address}~1resource~1{module_name}/get/parameters/1/schema) +// - ledger_version ($ref: #/paths/~1accounts~1{address}~1resource~1{module_name}/get/parameters/2/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetAccountModuleOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Name of module to retrieve + */ + readonly moduleName: string; + /** + * @description Ledger version to get state of account. + * If not provided, it will be the latest version + */ + readonly ledgerVersion?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetAccountModuleOperationRequestJSON { + readonly address: string; + readonly module_name: string; + readonly ledger_version?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetAccountModuleOperation = { + operationId: "getAccountModule", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}/resource/{module_name}", + parameterNames: ["address","module_name","ledger_version","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetAccountModuleResponseJSON): AptosGetAccountModuleResponse { + return AptosGetAccountModuleResponse.fromJSON(json); + }, + + serializeRequest(request: GetAccountModuleOperationRequest): GetAccountModuleOperationRequestJSON { + const address = request.address; + const moduleName = request.moduleName; + const ledgerVersion = request.ledgerVersion; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + module_name: moduleName, + ledger_version: ledgerVersion, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetAccountModulesOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetAccountModulesOperation.ts new file mode 100644 index 0000000000..aea8b242d4 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetAccountModulesOperation.ts @@ -0,0 +1,73 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetAccountModuleResponse, AptosGetAccountModuleResponseJSON } from '../types/AptosGetAccountModuleResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1modules/get/parameters/0/schema) +// - ledger_version ($ref: #/paths/~1accounts~1{address}~1modules/get/parameters/1/schema) +// - limit ($ref: #/paths/~1accounts~1{address}~1modules/get/parameters/2/schema) +// - start ($ref: #/paths/~1accounts~1{address}~1modules/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetAccountModulesOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Ledger version to get state of account. + * If not provided, it will be the latest version + */ + readonly ledgerVersion?: string; + /** + * @description Max number of account resources to retrieve. + * If not provided, defaults to default page size. + */ + readonly limit?: number; + /** + * @description Cursor specifying where to start for pagination + * This cursor cannot be derived manually client-side. Instead, you must call this endpoint once without this query parameter specified, and then use the cursor returned in the X-Aptos-Cursor header in the response. + */ + readonly start?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetAccountModulesOperationRequestJSON { + readonly address: string; + readonly ledger_version?: string; + readonly limit?: number; + readonly start?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetAccountModulesOperation = { + operationId: "getAccountModules", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}/modules", + parameterNames: ["address","ledger_version","limit","start","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetAccountModuleResponseJSON[]): AptosGetAccountModuleResponse[] { + return json.map((item) => AptosGetAccountModuleResponse.fromJSON(item)); + }, + + serializeRequest(request: GetAccountModulesOperationRequest): GetAccountModulesOperationRequestJSON { + const address = request.address; + const ledgerVersion = request.ledgerVersion; + const limit = request.limit; + const start = request.start; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + ledger_version: ledgerVersion, + limit: limit, + start: start, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetAccountOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetAccountOperation.ts new file mode 100644 index 0000000000..2e35a7821a --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetAccountOperation.ts @@ -0,0 +1,55 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetAccountResponse, AptosGetAccountResponseJSON } from '../types/AptosGetAccountResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}/get/parameters/0/schema) +// - ledger_version ($ref: #/paths/~1accounts~1{address}/get/parameters/1/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetAccountOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Ledger version to get state of account. + * If not provided, it will be the latest version + */ + readonly ledgerVersion?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetAccountOperationRequestJSON { + readonly address: string; + readonly ledger_version?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetAccountOperation = { + operationId: "getAccount", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}", + parameterNames: ["address","ledger_version","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetAccountResponseJSON): AptosGetAccountResponse { + return AptosGetAccountResponse.fromJSON(json); + }, + + serializeRequest(request: GetAccountOperationRequest): GetAccountOperationRequestJSON { + const address = request.address; + const ledgerVersion = request.ledgerVersion; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + ledger_version: ledgerVersion, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetAccountResourceOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetAccountResourceOperation.ts new file mode 100644 index 0000000000..8663778bfd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetAccountResourceOperation.ts @@ -0,0 +1,63 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetAccountResourceResponse, AptosGetAccountResourceResponseJSON } from '../types/AptosGetAccountResourceResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1resource~1{resource_type}/get/parameters/0/schema) +// - resource_type ($ref: #/paths/~1accounts~1{address}~1resource~1{resource_type}/get/parameters/1/schema) +// - ledger_version ($ref: #/paths/~1accounts~1{address}~1resource~1{resource_type}/get/parameters/2/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetAccountResourceOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Name of struct to retrieve e.g. 0x1::account::Account + */ + readonly resourceType: string; + /** + * @description Ledger version to get state of account. + * If not provided, it will be the latest version + */ + readonly ledgerVersion?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetAccountResourceOperationRequestJSON { + readonly address: string; + readonly resource_type: string; + readonly ledger_version?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetAccountResourceOperation = { + operationId: "getAccountResource", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}/resource/{resource_type}", + parameterNames: ["address","resource_type","ledger_version","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetAccountResourceResponseJSON): AptosGetAccountResourceResponse { + return AptosGetAccountResourceResponse.fromJSON(json); + }, + + serializeRequest(request: GetAccountResourceOperationRequest): GetAccountResourceOperationRequestJSON { + const address = request.address; + const resourceType = request.resourceType; + const ledgerVersion = request.ledgerVersion; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + resource_type: resourceType, + ledger_version: ledgerVersion, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetAccountResourcesOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetAccountResourcesOperation.ts new file mode 100644 index 0000000000..1cea28e94e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetAccountResourcesOperation.ts @@ -0,0 +1,73 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetAccountResourceResponse, AptosGetAccountResourceResponseJSON } from '../types/AptosGetAccountResourceResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1resources/get/parameters/0/schema) +// - ledger_version ($ref: #/paths/~1accounts~1{address}~1resources/get/parameters/1/schema) +// - limit ($ref: #/paths/~1accounts~1{address}~1resources/get/parameters/2/schema) +// - start ($ref: #/paths/~1accounts~1{address}~1resources/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetAccountResourcesOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Ledger version to get state of account. + * If not provided, it will be the latest version + */ + readonly ledgerVersion?: string; + /** + * @description Max number of account resources to retrieve. + * If not provided, defaults to default page size. + */ + readonly limit?: number; + /** + * @description Cursor specifying where to start for pagination + * This cursor cannot be derived manually client-side. Instead, you must call this endpoint once without this query parameter specified, and then use the cursor returned in the X-Aptos-Cursor header in the response. + */ + readonly start?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetAccountResourcesOperationRequestJSON { + readonly address: string; + readonly ledger_version?: string; + readonly limit?: number; + readonly start?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetAccountResourcesOperation = { + operationId: "getAccountResources", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}/resources", + parameterNames: ["address","ledger_version","limit","start","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetAccountResourceResponseJSON[]): AptosGetAccountResourceResponse[] { + return json.map((item) => AptosGetAccountResourceResponse.fromJSON(item)); + }, + + serializeRequest(request: GetAccountResourcesOperationRequest): GetAccountResourcesOperationRequestJSON { + const address = request.address; + const ledgerVersion = request.ledgerVersion; + const limit = request.limit; + const start = request.start; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + ledger_version: ledgerVersion, + limit: limit, + start: start, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetAccountTransactionsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetAccountTransactionsOperation.ts new file mode 100644 index 0000000000..24796d05fd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetAccountTransactionsOperation.ts @@ -0,0 +1,64 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetAccountTransactionsItem, AptosGetAccountTransactionsItemValue, AptosGetAccountTransactionsItemJSON } from '../types/AptosGetAccountTransactionsItem'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1transactions/get/parameters/0/schema) +// - limit ($ref: #/paths/~1accounts~1{address}~1transactions/get/parameters/1/schema) +// - start ($ref: #/paths/~1accounts~1{address}~1transactions/get/parameters/2/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetAccountTransactionsOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Max number of transactions to retrieve. + * If not provided, defaults to default page size + */ + readonly limit?: number; + /** + * @description Account sequence number to start list of transactions. + * If not provided, defaults to showing the latest transactions + */ + readonly start?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetAccountTransactionsOperationRequestJSON { + readonly address: string; + readonly limit?: number; + readonly start?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetAccountTransactionsOperation = { + operationId: "getAccountTransactions", + groupName: "transactions", + httpMethod: "get", + routePattern: "/accounts/{address}/transactions", + parameterNames: ["address","limit","start","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetAccountTransactionsItemJSON[]): AptosGetAccountTransactionsItemValue[] { + return json.map((item) => AptosGetAccountTransactionsItem.fromJSON(item)); + }, + + serializeRequest(request: GetAccountTransactionsOperationRequest): GetAccountTransactionsOperationRequestJSON { + const address = request.address; + const limit = request.limit; + const start = request.start; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + limit: limit, + start: start, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetBlockByHeightOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetBlockByHeightOperation.ts new file mode 100644 index 0000000000..0c7db9955d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetBlockByHeightOperation.ts @@ -0,0 +1,54 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosBlock, AptosBlockJSON } from '../types/AptosBlock'; + +// request parameters: +// - block_height ($ref: #/paths/~1blocks~1{block_height}/get/parameters/0/schema) +// - with_transactions ($ref: #/paths/~1blocks~1{block_height}/get/parameters/1/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetBlockByHeightOperationRequest { + /** + * @description Block height to lookup. Starts at 0 + */ + readonly blockHeight: number; + /** + * @description If set to true, include all transactions in the block + */ + readonly withTransactions?: boolean; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetBlockByHeightOperationRequestJSON { + readonly block_height: number; + readonly with_transactions?: boolean; + readonly network?: AptosNetworkJSON; +} + +export const GetBlockByHeightOperation = { + operationId: "getBlockByHeight", + groupName: "blocks", + httpMethod: "get", + routePattern: "/blocks/{block_height}", + parameterNames: ["block_height","with_transactions","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosBlockJSON): AptosBlock { + return AptosBlock.fromJSON(json); + }, + + serializeRequest(request: GetBlockByHeightOperationRequest): GetBlockByHeightOperationRequestJSON { + const blockHeight = request.blockHeight; + const withTransactions = request.withTransactions; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + block_height: blockHeight, + with_transactions: withTransactions, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetBlockByVersionOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetBlockByVersionOperation.ts new file mode 100644 index 0000000000..d82fb0e062 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetBlockByVersionOperation.ts @@ -0,0 +1,54 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosBlock, AptosBlockJSON } from '../types/AptosBlock'; + +// request parameters: +// - version ($ref: #/paths/~1blocks~1by_version~1{version}/get/parameters/0/schema) +// - with_transactions ($ref: #/paths/~1blocks~1by_version~1{version}/get/parameters/1/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetBlockByVersionOperationRequest { + /** + * @description Ledger version to lookup block information for. + */ + readonly version: number; + /** + * @description If set to true, include all transactions in the block + */ + readonly withTransactions?: boolean; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetBlockByVersionOperationRequestJSON { + readonly version: number; + readonly with_transactions?: boolean; + readonly network?: AptosNetworkJSON; +} + +export const GetBlockByVersionOperation = { + operationId: "getBlockByVersion", + groupName: "blocks", + httpMethod: "get", + routePattern: "/blocks/by_version/{version}", + parameterNames: ["version","with_transactions","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosBlockJSON): AptosBlock { + return AptosBlock.fromJSON(json); + }, + + serializeRequest(request: GetBlockByVersionOperationRequest): GetBlockByVersionOperationRequestJSON { + const version = request.version; + const withTransactions = request.withTransactions; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + version: version, + with_transactions: withTransactions, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinBalancesByWalletsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinBalancesByWalletsOperation.ts new file mode 100644 index 0000000000..2c4b1a10ef --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinBalancesByWalletsOperation.ts @@ -0,0 +1,86 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinBalancesByWalletsResponse, AptosGetCoinBalancesByWalletsResponseJSON } from '../types/AptosGetCoinBalancesByWalletsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1wallets~1coins/get/parameters/0/schema) +// - offset ($ref: #/paths/~1wallets~1coins/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1wallets~1coins/get/parameters/2/schema) +// - owner_addresses ($ref: #/paths/~1wallets~1coins/get/parameters/3/schema) +// - coin_type_hash_blacklist ($ref: #/paths/~1wallets~1coins/get/parameters/4/schema) +// - coin_type_hash_whitelist ($ref: #/paths/~1wallets~1coins/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinBalancesByWalletsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the owners to get coin balances for + */ + readonly ownerAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The coin type hashes of the coins to whitelist + */ + readonly coinTypeHashBlacklist?: string[]; + /** + * @description The coin type hashes of the coins to whitelist + */ + readonly coinTypeHashWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinBalancesByWalletsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly owner_addresses: AptosAddressJSON[]; + readonly coin_type_hash_blacklist?: string[]; + readonly coin_type_hash_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinBalancesByWalletsOperation = { + operationId: "getCoinBalancesByWallets", + groupName: "wallets", + httpMethod: "get", + routePattern: "/wallets/coins", + parameterNames: ["limit","offset","cursor","owner_addresses","coin_type_hash_blacklist","coin_type_hash_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinBalancesByWalletsResponseJSON): AptosGetCoinBalancesByWalletsResponse { + return AptosGetCoinBalancesByWalletsResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinBalancesByWalletsOperationRequest): GetCoinBalancesByWalletsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const ownerAddresses = request.ownerAddresses.map((item) => AptosAddress.create(item)); + const coinTypeHashBlacklist = request.coinTypeHashBlacklist; + const coinTypeHashWhitelist = request.coinTypeHashWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + owner_addresses: ownerAddresses.map((item) => item.toJSON()), + coin_type_hash_blacklist: coinTypeHashBlacklist, + coin_type_hash_whitelist: coinTypeHashWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinInfoByCoinTypeHashesOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinInfoByCoinTypeHashesOperation.ts new file mode 100644 index 0000000000..c4e109fb35 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinInfoByCoinTypeHashesOperation.ts @@ -0,0 +1,46 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosCoinInfoDto, AptosCoinInfoDtoJSON } from '../types/AptosCoinInfoDto'; + +// request parameters: +// - coin_type_hashes ($ref: #/paths/~1coins/get/parameters/0/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinInfoByCoinTypeHashesOperationRequest { + /** + * @description The coin type hashes to fetch info about + */ + readonly coinTypeHashes: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinInfoByCoinTypeHashesOperationRequestJSON { + readonly coin_type_hashes: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinInfoByCoinTypeHashesOperation = { + operationId: "getCoinInfoByCoinTypeHashes", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins", + parameterNames: ["coin_type_hashes","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosCoinInfoDtoJSON[]): AptosCoinInfoDto[] { + return json.map((item) => AptosCoinInfoDto.fromJSON(item)); + }, + + serializeRequest(request: GetCoinInfoByCoinTypeHashesOperationRequest): GetCoinInfoByCoinTypeHashesOperationRequestJSON { + const coinTypeHashes = request.coinTypeHashes; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + coin_type_hashes: coinTypeHashes, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByBlockHeightsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByBlockHeightsOperation.ts new file mode 100644 index 0000000000..9e54cf7501 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByBlockHeightsOperation.ts @@ -0,0 +1,70 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinTransfersByBlockHeightsResponse, AptosGetCoinTransfersByBlockHeightsResponseJSON } from '../types/AptosGetCoinTransfersByBlockHeightsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1coins~1transfers~1blocks/get/parameters/0/schema) +// - offset ($ref: #/paths/~1coins~1transfers~1blocks/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1coins~1transfers~1blocks/get/parameters/2/schema) +// - block_heights ($ref: #/paths/~1coins~1transfers~1blocks/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinTransfersByBlockHeightsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The coin types to fetch info about + */ + readonly blockHeights: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinTransfersByBlockHeightsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly block_heights: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinTransfersByBlockHeightsOperation = { + operationId: "getCoinTransfersByBlockHeights", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/transfers/blocks", + parameterNames: ["limit","offset","cursor","block_heights","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinTransfersByBlockHeightsResponseJSON): AptosGetCoinTransfersByBlockHeightsResponse { + return AptosGetCoinTransfersByBlockHeightsResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinTransfersByBlockHeightsOperationRequest): GetCoinTransfersByBlockHeightsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const blockHeights = request.blockHeights; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + block_heights: blockHeights, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByCoinTypeOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByCoinTypeOperation.ts new file mode 100644 index 0000000000..5f17c3934b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByCoinTypeOperation.ts @@ -0,0 +1,86 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinTransfersByCoinTypeResponse, AptosGetCoinTransfersByCoinTypeResponseJSON } from '../types/AptosGetCoinTransfersByCoinTypeResponse'; + +// request parameters: +// - coin_type ($ref: #/paths/~1coins~1transfers~1{coin_type}/get/parameters/0/schema) +// - limit ($ref: #/paths/~1coins~1transfers~1{coin_type}/get/parameters/1/schema) +// - offset ($ref: #/paths/~1coins~1transfers~1{coin_type}/get/parameters/2/schema) +// - cursor ($ref: #/paths/~1coins~1transfers~1{coin_type}/get/parameters/3/schema) +// - from_date ($ref: #/paths/~1coins~1transfers~1{coin_type}/get/parameters/4/schema) +// - to_date ($ref: #/paths/~1coins~1transfers~1{coin_type}/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinTransfersByCoinTypeOperationRequest { + /** + * @description The coin type to fetch info about + */ + readonly coinType: string; + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The date from which to fetch coin transfers + */ + readonly fromDate?: string; + /** + * @description The date to which to fetch coin transfers + */ + readonly toDate?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinTransfersByCoinTypeOperationRequestJSON { + readonly coin_type: string; + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly from_date?: string; + readonly to_date?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinTransfersByCoinTypeOperation = { + operationId: "getCoinTransfersByCoinType", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/transfers/{coin_type}", + parameterNames: ["coin_type","limit","offset","cursor","from_date","to_date","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinTransfersByCoinTypeResponseJSON): AptosGetCoinTransfersByCoinTypeResponse { + return AptosGetCoinTransfersByCoinTypeResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinTransfersByCoinTypeOperationRequest): GetCoinTransfersByCoinTypeOperationRequestJSON { + const coinType = request.coinType; + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const fromDate = request.fromDate; + const toDate = request.toDate; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + coin_type: coinType, + limit: limit, + offset: offset, + cursor: cursor, + from_date: fromDate, + to_date: toDate, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByOwnerAddressesOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByOwnerAddressesOperation.ts new file mode 100644 index 0000000000..5d61f206d0 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByOwnerAddressesOperation.ts @@ -0,0 +1,102 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinTransfersByOwnerAddressesResponse, AptosGetCoinTransfersByOwnerAddressesResponseJSON } from '../types/AptosGetCoinTransfersByOwnerAddressesResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/0/schema) +// - offset ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/2/schema) +// - owner_addresses ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/3/schema) +// - from_date ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/4/schema) +// - to_date ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/5/schema) +// - coin_type_blacklist ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/6/schema) +// - coin_type_whitelist ($ref: #/paths/~1coins~1transfers~1wallets/get/parameters/7/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinTransfersByOwnerAddressesOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the owners to get tokens for + */ + readonly ownerAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The date from which to fetch coin transfers + */ + readonly fromDate?: string; + /** + * @description The date to which to fetch coin transfers + */ + readonly toDate?: string; + /** + * @description The coin types of the coins to whitelist + */ + readonly coinTypeBlacklist?: string[]; + /** + * @description The coin types of the coins to whitelist + */ + readonly coinTypeWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinTransfersByOwnerAddressesOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly owner_addresses: AptosAddressJSON[]; + readonly from_date?: string; + readonly to_date?: string; + readonly coin_type_blacklist?: string[]; + readonly coin_type_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinTransfersByOwnerAddressesOperation = { + operationId: "getCoinTransfersByOwnerAddresses", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/transfers/wallets", + parameterNames: ["limit","offset","cursor","owner_addresses","from_date","to_date","coin_type_blacklist","coin_type_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinTransfersByOwnerAddressesResponseJSON): AptosGetCoinTransfersByOwnerAddressesResponse { + return AptosGetCoinTransfersByOwnerAddressesResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinTransfersByOwnerAddressesOperationRequest): GetCoinTransfersByOwnerAddressesOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const ownerAddresses = request.ownerAddresses.map((item) => AptosAddress.create(item)); + const fromDate = request.fromDate; + const toDate = request.toDate; + const coinTypeBlacklist = request.coinTypeBlacklist; + const coinTypeWhitelist = request.coinTypeWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + owner_addresses: ownerAddresses.map((item) => item.toJSON()), + from_date: fromDate, + to_date: toDate, + coin_type_blacklist: coinTypeBlacklist, + coin_type_whitelist: coinTypeWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByWalletAddressesOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByWalletAddressesOperation.ts new file mode 100644 index 0000000000..d5f38509aa --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinTransfersByWalletAddressesOperation.ts @@ -0,0 +1,102 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinTransfersByOwnerAddressesResponse, AptosGetCoinTransfersByOwnerAddressesResponseJSON } from '../types/AptosGetCoinTransfersByOwnerAddressesResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/0/schema) +// - offset ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/2/schema) +// - owner_addresses ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/3/schema) +// - from_date ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/4/schema) +// - to_date ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/5/schema) +// - coin_type_blacklist ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/6/schema) +// - coin_type_whitelist ($ref: #/paths/~1wallets~1coins~1transfers/get/parameters/7/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinTransfersByWalletAddressesOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the owners to get tokens for + */ + readonly ownerAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The date from which to fetch coin transfers + */ + readonly fromDate?: string; + /** + * @description The date to which to fetch coin transfers + */ + readonly toDate?: string; + /** + * @description The coin types of the coins to whitelist + */ + readonly coinTypeBlacklist?: string[]; + /** + * @description The coin types of the coins to whitelist + */ + readonly coinTypeWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinTransfersByWalletAddressesOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly owner_addresses: AptosAddressJSON[]; + readonly from_date?: string; + readonly to_date?: string; + readonly coin_type_blacklist?: string[]; + readonly coin_type_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinTransfersByWalletAddressesOperation = { + operationId: "getCoinTransfersByWalletAddresses", + groupName: "wallets", + httpMethod: "get", + routePattern: "/wallets/coins/transfers", + parameterNames: ["limit","offset","cursor","owner_addresses","from_date","to_date","coin_type_blacklist","coin_type_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinTransfersByOwnerAddressesResponseJSON): AptosGetCoinTransfersByOwnerAddressesResponse { + return AptosGetCoinTransfersByOwnerAddressesResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinTransfersByWalletAddressesOperationRequest): GetCoinTransfersByWalletAddressesOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const ownerAddresses = request.ownerAddresses.map((item) => AptosAddress.create(item)); + const fromDate = request.fromDate; + const toDate = request.toDate; + const coinTypeBlacklist = request.coinTypeBlacklist; + const coinTypeWhitelist = request.coinTypeWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + owner_addresses: ownerAddresses.map((item) => item.toJSON()), + from_date: fromDate, + to_date: toDate, + coin_type_blacklist: coinTypeBlacklist, + coin_type_whitelist: coinTypeWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinsByCreatorsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinsByCreatorsOperation.ts new file mode 100644 index 0000000000..ec2d20e7ba --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinsByCreatorsOperation.ts @@ -0,0 +1,70 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinsByCreatorsResponse, AptosGetCoinsByCreatorsResponseJSON } from '../types/AptosGetCoinsByCreatorsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1coins~1creators/get/parameters/0/schema) +// - offset ($ref: #/paths/~1coins~1creators/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1coins~1creators/get/parameters/2/schema) +// - creator_addresses ($ref: #/paths/~1coins~1creators/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinsByCreatorsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the creators + */ + readonly creatorAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinsByCreatorsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly creator_addresses: AptosAddressJSON[]; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinsByCreatorsOperation = { + operationId: "getCoinsByCreators", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/creators", + parameterNames: ["limit","offset","cursor","creator_addresses","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinsByCreatorsResponseJSON): AptosGetCoinsByCreatorsResponse { + return AptosGetCoinsByCreatorsResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinsByCreatorsOperationRequest): GetCoinsByCreatorsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const creatorAddresses = request.creatorAddresses.map((item) => AptosAddress.create(item)); + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + creator_addresses: creatorAddresses.map((item) => item.toJSON()), + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinsByNameRangeOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinsByNameRangeOperation.ts new file mode 100644 index 0000000000..5580b1fa73 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinsByNameRangeOperation.ts @@ -0,0 +1,78 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinsByNameRangeResponse, AptosGetCoinsByNameRangeResponseJSON } from '../types/AptosGetCoinsByNameRangeResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1coins~1names/get/parameters/0/schema) +// - offset ($ref: #/paths/~1coins~1names/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1coins~1names/get/parameters/2/schema) +// - from_name ($ref: #/paths/~1coins~1names/get/parameters/3/schema) +// - to_name ($ref: #/paths/~1coins~1names/get/parameters/4/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinsByNameRangeOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The name of the coin to start from (inclusive and case sensitive) + */ + readonly fromName?: string; + /** + * @description The name of the coin to end at (inclusive and case sensitive) + */ + readonly toName?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinsByNameRangeOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly from_name?: string; + readonly to_name?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinsByNameRangeOperation = { + operationId: "getCoinsByNameRange", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/names", + parameterNames: ["limit","offset","cursor","from_name","to_name","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinsByNameRangeResponseJSON): AptosGetCoinsByNameRangeResponse { + return AptosGetCoinsByNameRangeResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinsByNameRangeOperationRequest): GetCoinsByNameRangeOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const fromName = request.fromName; + const toName = request.toName; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + from_name: fromName, + to_name: toName, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetCoinsBySymbolRangeOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetCoinsBySymbolRangeOperation.ts new file mode 100644 index 0000000000..63da5b1f92 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetCoinsBySymbolRangeOperation.ts @@ -0,0 +1,78 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetCoinsBySymbolRangeResponse, AptosGetCoinsBySymbolRangeResponseJSON } from '../types/AptosGetCoinsBySymbolRangeResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1coins~1symbols/get/parameters/0/schema) +// - offset ($ref: #/paths/~1coins~1symbols/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1coins~1symbols/get/parameters/2/schema) +// - from_symbol ($ref: #/paths/~1coins~1symbols/get/parameters/3/schema) +// - to_symbol ($ref: #/paths/~1coins~1symbols/get/parameters/4/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetCoinsBySymbolRangeOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The name of the coin to start from (inclusive and case sensitive) + */ + readonly fromSymbol?: string; + /** + * @description The name of the coin to end at (inclusive and case sensitive) + */ + readonly toSymbol?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetCoinsBySymbolRangeOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly from_symbol?: string; + readonly to_symbol?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetCoinsBySymbolRangeOperation = { + operationId: "getCoinsBySymbolRange", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/symbols", + parameterNames: ["limit","offset","cursor","from_symbol","to_symbol","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetCoinsBySymbolRangeResponseJSON): AptosGetCoinsBySymbolRangeResponse { + return AptosGetCoinsBySymbolRangeResponse.fromJSON(json); + }, + + serializeRequest(request: GetCoinsBySymbolRangeOperationRequest): GetCoinsBySymbolRangeOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const fromSymbol = request.fromSymbol; + const toSymbol = request.toSymbol; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + from_symbol: fromSymbol, + to_symbol: toSymbol, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetEventsByCreationNumberOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetEventsByCreationNumberOperation.ts new file mode 100644 index 0000000000..ef4b3ffac0 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetEventsByCreationNumberOperation.ts @@ -0,0 +1,72 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetEventsByCreationNumberResponse, AptosGetEventsByCreationNumberResponseJSON } from '../types/AptosGetEventsByCreationNumberResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1events~1{creation_number}/get/parameters/0/schema) +// - creation_number ($ref: #/paths/~1accounts~1{address}~1events~1{creation_number}/get/parameters/1/schema) +// - limit ($ref: #/paths/~1accounts~1{address}~1events~1{creation_number}/get/parameters/2/schema) +// - start ($ref: #/paths/~1accounts~1{address}~1events~1{creation_number}/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetEventsByCreationNumberOperationRequest { + /** + * @description Address of account with or without a 0x prefix + */ + readonly address: string; + /** + * @description Creation number corresponding to the event stream originating from the given account. + */ + readonly creationNumber: string; + /** + * @description Max number of account resources to retrieve. + * If not provided, defaults to default page size. + */ + readonly limit?: number; + /** + * @description Starting sequence number of events. + * If unspecified, by default will retrieve the most recent events + */ + readonly start?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetEventsByCreationNumberOperationRequestJSON { + readonly address: string; + readonly creation_number: string; + readonly limit?: number; + readonly start?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetEventsByCreationNumberOperation = { + operationId: "getEventsByCreationNumber", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}/events/{creation_number}", + parameterNames: ["address","creation_number","limit","start","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetEventsByCreationNumberResponseJSON[]): AptosGetEventsByCreationNumberResponse[] { + return json.map((item) => AptosGetEventsByCreationNumberResponse.fromJSON(item)); + }, + + serializeRequest(request: GetEventsByCreationNumberOperationRequest): GetEventsByCreationNumberOperationRequestJSON { + const address = request.address; + const creationNumber = request.creationNumber; + const limit = request.limit; + const start = request.start; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + creation_number: creationNumber, + limit: limit, + start: start, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetEventsByEventHandleOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetEventsByEventHandleOperation.ts new file mode 100644 index 0000000000..9ef9977bb1 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetEventsByEventHandleOperation.ts @@ -0,0 +1,80 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetEventsByEventHandleResponse, AptosGetEventsByEventHandleResponseJSON } from '../types/AptosGetEventsByEventHandleResponse'; + +// request parameters: +// - address ($ref: #/paths/~1accounts~1{address}~1events~1{event_handle}~1{field_name}/get/parameters/0/schema) +// - event_handle ($ref: #/paths/~1accounts~1{address}~1events~1{event_handle}~1{field_name}/get/parameters/1/schema) +// - field_name ($ref: #/paths/~1accounts~1{address}~1events~1{event_handle}~1{field_name}/get/parameters/2/schema) +// - limit ($ref: #/paths/~1accounts~1{address}~1events~1{event_handle}~1{field_name}/get/parameters/3/schema) +// - start ($ref: #/paths/~1accounts~1{address}~1events~1{event_handle}~1{field_name}/get/parameters/4/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetEventsByEventHandleOperationRequest { + /** + * @description Hex-encoded 32 byte Aptos account, with or without a 0x prefix, for which events are queried. This refers to the account that events were emitted to, not the account hosting the move module that emits that event type. + */ + readonly address: string; + /** + * @description Name of struct to lookup event handle. + */ + readonly eventHandle: string; + /** + * @description Name of field to lookup event handle. + */ + readonly fieldName: string; + /** + * @description Max number of account resources to retrieve. + * If not provided, defaults to default page size. + */ + readonly limit?: number; + /** + * @description Starting sequence number of events. + * If unspecified, by default will retrieve the most recent events + */ + readonly start?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetEventsByEventHandleOperationRequestJSON { + readonly address: string; + readonly event_handle: string; + readonly field_name: string; + readonly limit?: number; + readonly start?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetEventsByEventHandleOperation = { + operationId: "getEventsByEventHandle", + groupName: "accounts", + httpMethod: "get", + routePattern: "/accounts/{address}/events/{event_handle}/{field_name}", + parameterNames: ["address","event_handle","field_name","limit","start","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetEventsByEventHandleResponseJSON[]): AptosGetEventsByEventHandleResponse[] { + return json.map((item) => AptosGetEventsByEventHandleResponse.fromJSON(item)); + }, + + serializeRequest(request: GetEventsByEventHandleOperationRequest): GetEventsByEventHandleOperationRequestJSON { + const address = request.address; + const eventHandle = request.eventHandle; + const fieldName = request.fieldName; + const limit = request.limit; + const start = request.start; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + address: address, + event_handle: eventHandle, + field_name: fieldName, + limit: limit, + start: start, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetHistoricalCoinBalancesByWalletsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetHistoricalCoinBalancesByWalletsOperation.ts new file mode 100644 index 0000000000..d8464a016a --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetHistoricalCoinBalancesByWalletsOperation.ts @@ -0,0 +1,86 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetHistoricalCoinBalancesByWalletsResponse, AptosGetHistoricalCoinBalancesByWalletsResponseJSON } from '../types/AptosGetHistoricalCoinBalancesByWalletsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1wallets~1coins~1history/get/parameters/0/schema) +// - offset ($ref: #/paths/~1wallets~1coins~1history/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1wallets~1coins~1history/get/parameters/2/schema) +// - owner_addresses ($ref: #/paths/~1wallets~1coins~1history/get/parameters/3/schema) +// - coin_type_hash_blacklist ($ref: #/paths/~1wallets~1coins~1history/get/parameters/4/schema) +// - coin_type_hash_whitelist ($ref: #/paths/~1wallets~1coins~1history/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetHistoricalCoinBalancesByWalletsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the owner addresses to get historical balances for + */ + readonly ownerAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The coin type hash of the coins to whitelist + */ + readonly coinTypeHashBlacklist?: string[]; + /** + * @description The coin type hash of the coins to whitelist + */ + readonly coinTypeHashWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetHistoricalCoinBalancesByWalletsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly owner_addresses: AptosAddressJSON[]; + readonly coin_type_hash_blacklist?: string[]; + readonly coin_type_hash_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetHistoricalCoinBalancesByWalletsOperation = { + operationId: "getHistoricalCoinBalancesByWallets", + groupName: "wallets", + httpMethod: "get", + routePattern: "/wallets/coins/history", + parameterNames: ["limit","offset","cursor","owner_addresses","coin_type_hash_blacklist","coin_type_hash_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetHistoricalCoinBalancesByWalletsResponseJSON): AptosGetHistoricalCoinBalancesByWalletsResponse { + return AptosGetHistoricalCoinBalancesByWalletsResponse.fromJSON(json); + }, + + serializeRequest(request: GetHistoricalCoinBalancesByWalletsOperationRequest): GetHistoricalCoinBalancesByWalletsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const ownerAddresses = request.ownerAddresses.map((item) => AptosAddress.create(item)); + const coinTypeHashBlacklist = request.coinTypeHashBlacklist; + const coinTypeHashWhitelist = request.coinTypeHashWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + owner_addresses: ownerAddresses.map((item) => item.toJSON()), + coin_type_hash_blacklist: coinTypeHashBlacklist, + coin_type_hash_whitelist: coinTypeHashWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetLatestCoinsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetLatestCoinsOperation.ts new file mode 100644 index 0000000000..9266721280 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetLatestCoinsOperation.ts @@ -0,0 +1,62 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetLatestCoinsResponse, AptosGetLatestCoinsResponseJSON } from '../types/AptosGetLatestCoinsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1coins~1latest/get/parameters/0/schema) +// - offset ($ref: #/paths/~1coins~1latest/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1coins~1latest/get/parameters/2/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetLatestCoinsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetLatestCoinsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetLatestCoinsOperation = { + operationId: "getLatestCoins", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/latest", + parameterNames: ["limit","offset","cursor","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetLatestCoinsResponseJSON): AptosGetLatestCoinsResponse { + return AptosGetLatestCoinsResponse.fromJSON(json); + }, + + serializeRequest(request: GetLatestCoinsOperationRequest): GetLatestCoinsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTByOwnersOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTByOwnersOperation.ts new file mode 100644 index 0000000000..bfb6733603 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTByOwnersOperation.ts @@ -0,0 +1,86 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTsByOwnersResponse, AptosNFTsByOwnersResponseJSON } from '../types/AptosNFTsByOwnersResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1wallets~1nfts/get/parameters/0/schema) +// - offset ($ref: #/paths/~1wallets~1nfts/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1wallets~1nfts/get/parameters/2/schema) +// - owner_addresses ($ref: #/paths/~1wallets~1nfts/get/parameters/3/schema) +// - collection_blacklist ($ref: #/paths/~1wallets~1nfts/get/parameters/4/schema) +// - collection_whitelist ($ref: #/paths/~1wallets~1nfts/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTByOwnersOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the owners to get tokens for + */ + readonly ownerAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The collection data id hashes of the collections to whitelist + */ + readonly collectionBlacklist?: string[]; + /** + * @description The collection data id hashes of the collections to whitelist + */ + readonly collectionWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTByOwnersOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly owner_addresses: AptosAddressJSON[]; + readonly collection_blacklist?: string[]; + readonly collection_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTByOwnersOperation = { + operationId: "getNFTByOwners", + groupName: "wallets", + httpMethod: "get", + routePattern: "/wallets/nfts", + parameterNames: ["limit","offset","cursor","owner_addresses","collection_blacklist","collection_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTsByOwnersResponseJSON): AptosNFTsByOwnersResponse { + return AptosNFTsByOwnersResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTByOwnersOperationRequest): GetNFTByOwnersOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const ownerAddresses = request.ownerAddresses.map((item) => AptosAddress.create(item)); + const collectionBlacklist = request.collectionBlacklist; + const collectionWhitelist = request.collectionWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + owner_addresses: ownerAddresses.map((item) => item.toJSON()), + collection_blacklist: collectionBlacklist, + collection_whitelist: collectionWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsByCreatorOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsByCreatorOperation.ts new file mode 100644 index 0000000000..f03553ec7a --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsByCreatorOperation.ts @@ -0,0 +1,70 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTCollectionsByCreatorResponse, AptosNFTCollectionsByCreatorResponseJSON } from '../types/AptosNFTCollectionsByCreatorResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1collections~1creators/get/parameters/0/schema) +// - offset ($ref: #/paths/~1collections~1creators/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1collections~1creators/get/parameters/2/schema) +// - creator_address ($ref: #/paths/~1collections~1creators/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTCollectionsByCreatorOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The address of the creator + */ + readonly creatorAddress: AptosAddressInput | AptosAddress; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTCollectionsByCreatorOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly creator_address: AptosAddressJSON; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTCollectionsByCreatorOperation = { + operationId: "getNFTCollectionsByCreator", + groupName: "collections", + httpMethod: "get", + routePattern: "/collections/creators", + parameterNames: ["limit","offset","cursor","creator_address","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTCollectionsByCreatorResponseJSON): AptosNFTCollectionsByCreatorResponse { + return AptosNFTCollectionsByCreatorResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTCollectionsByCreatorOperationRequest): GetNFTCollectionsByCreatorOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const creatorAddress = AptosAddress.create(request.creatorAddress); + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + creator_address: creatorAddress.toJSON(), + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsByIdsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsByIdsOperation.ts new file mode 100644 index 0000000000..6b58a76e52 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsByIdsOperation.ts @@ -0,0 +1,46 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTCollectionItemResponse, AptosNFTCollectionItemResponseJSON } from '../types/AptosNFTCollectionItemResponse'; + +// request parameters: +// - ids ($ref: #/paths/~1collections~1ids/get/parameters/0/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTCollectionsByIdsOperationRequest { + /** + * @description The identifiers of the collections to get + */ + readonly ids: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTCollectionsByIdsOperationRequestJSON { + readonly ids: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTCollectionsByIdsOperation = { + operationId: "getNFTCollectionsByIds", + groupName: "collections", + httpMethod: "get", + routePattern: "/collections/ids", + parameterNames: ["ids","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTCollectionItemResponseJSON[]): AptosNFTCollectionItemResponse[] { + return json.map((item) => AptosNFTCollectionItemResponse.fromJSON(item)); + }, + + serializeRequest(request: GetNFTCollectionsByIdsOperationRequest): GetNFTCollectionsByIdsOperationRequestJSON { + const ids = request.ids; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + ids: ids, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsOperation.ts new file mode 100644 index 0000000000..74438bb215 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTCollectionsOperation.ts @@ -0,0 +1,78 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTCollectionsByNameRangeResponse, AptosNFTCollectionsByNameRangeResponseJSON } from '../types/AptosNFTCollectionsByNameRangeResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1collections/get/parameters/0/schema) +// - offset ($ref: #/paths/~1collections/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1collections/get/parameters/2/schema) +// - fromName ($ref: #/paths/~1collections/get/parameters/3/schema) +// - toName ($ref: #/paths/~1collections/get/parameters/4/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTCollectionsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The name of the collection to start from (inclusive and case sensitive) + */ + readonly fromName?: string; + /** + * @description The name of the collection to end at (inclusive and case sensitive) + */ + readonly toName?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTCollectionsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly fromName?: string; + readonly toName?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTCollectionsOperation = { + operationId: "getNFTCollections", + groupName: "collections", + httpMethod: "get", + routePattern: "/collections", + parameterNames: ["limit","offset","cursor","fromName","toName","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTCollectionsByNameRangeResponseJSON): AptosNFTCollectionsByNameRangeResponse { + return AptosNFTCollectionsByNameRangeResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTCollectionsOperationRequest): GetNFTCollectionsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const fromName = request.fromName; + const toName = request.toName; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + fromName: fromName, + toName: toName, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersByCollectionOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersByCollectionOperation.ts new file mode 100644 index 0000000000..20e5920f48 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersByCollectionOperation.ts @@ -0,0 +1,86 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTOwnersByCollectionResponse, AptosNFTOwnersByCollectionResponseJSON } from '../types/AptosNFTOwnersByCollectionResponse'; + +// request parameters: +// - collection_data_id_hash ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners/get/parameters/0/schema) +// - limit ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners/get/parameters/1/schema) +// - offset ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners/get/parameters/2/schema) +// - cursor ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners/get/parameters/3/schema) +// - wallet_blacklist ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners/get/parameters/4/schema) +// - wallet_whitelist ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTOwnersByCollectionOperationRequest { + /** + * @description The id of the token + */ + readonly collectionDataIdHash: string; + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the wallets to blacklist + */ + readonly walletBlacklist?: string[]; + /** + * @description The addresses of the wallets to whitelist + */ + readonly walletWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTOwnersByCollectionOperationRequestJSON { + readonly collection_data_id_hash: string; + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly wallet_blacklist?: string[]; + readonly wallet_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTOwnersByCollectionOperation = { + operationId: "getNFTOwnersByCollection", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/collections/{collection_data_id_hash}/owners", + parameterNames: ["collection_data_id_hash","limit","offset","cursor","wallet_blacklist","wallet_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTOwnersByCollectionResponseJSON): AptosNFTOwnersByCollectionResponse { + return AptosNFTOwnersByCollectionResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTOwnersByCollectionOperationRequest): GetNFTOwnersByCollectionOperationRequestJSON { + const collectionDataIdHash = request.collectionDataIdHash; + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const walletBlacklist = request.walletBlacklist; + const walletWhitelist = request.walletWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + collection_data_id_hash: collectionDataIdHash, + limit: limit, + offset: offset, + cursor: cursor, + wallet_blacklist: walletBlacklist, + wallet_whitelist: walletWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersByTokensOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersByTokensOperation.ts new file mode 100644 index 0000000000..6b975e852e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersByTokensOperation.ts @@ -0,0 +1,70 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTOwnersByTokensResponse, AptosNFTOwnersByTokensResponseJSON } from '../types/AptosNFTOwnersByTokensResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1nfts~1owners/get/parameters/0/schema) +// - offset ($ref: #/paths/~1nfts~1owners/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1nfts~1owners/get/parameters/2/schema) +// - token_ids ($ref: #/paths/~1nfts~1owners/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTOwnersByTokensOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The identifiers of the tokens to get owners for + */ + readonly tokenIds: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTOwnersByTokensOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly token_ids: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTOwnersByTokensOperation = { + operationId: "getNFTOwnersByTokens", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/owners", + parameterNames: ["limit","offset","cursor","token_ids","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTOwnersByTokensResponseJSON): AptosNFTOwnersByTokensResponse { + return AptosNFTOwnersByTokensResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTOwnersByTokensOperationRequest): GetNFTOwnersByTokensOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const tokenIds = request.tokenIds; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + token_ids: tokenIds, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersOfCollectionOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersOfCollectionOperation.ts new file mode 100644 index 0000000000..7afdf712f1 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTOwnersOfCollectionOperation.ts @@ -0,0 +1,70 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTOwnersOfCollectionResponse, AptosNFTOwnersOfCollectionResponseJSON } from '../types/AptosNFTOwnersOfCollectionResponse'; + +// request parameters: +// - collection_data_id_hash ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners~1list/get/parameters/0/schema) +// - limit ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners~1list/get/parameters/1/schema) +// - offset ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners~1list/get/parameters/2/schema) +// - cursor ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1owners~1list/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTOwnersOfCollectionOperationRequest { + /** + * @description The id of the token + */ + readonly collectionDataIdHash: string; + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTOwnersOfCollectionOperationRequestJSON { + readonly collection_data_id_hash: string; + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTOwnersOfCollectionOperation = { + operationId: "getNFTOwnersOfCollection", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/collections/{collection_data_id_hash}/owners/list", + parameterNames: ["collection_data_id_hash","limit","offset","cursor","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTOwnersOfCollectionResponseJSON): AptosNFTOwnersOfCollectionResponse { + return AptosNFTOwnersOfCollectionResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTOwnersOfCollectionOperationRequest): GetNFTOwnersOfCollectionOperationRequestJSON { + const collectionDataIdHash = request.collectionDataIdHash; + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + collection_data_id_hash: collectionDataIdHash, + limit: limit, + offset: offset, + cursor: cursor, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByCollectionOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByCollectionOperation.ts new file mode 100644 index 0000000000..ae539fd977 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByCollectionOperation.ts @@ -0,0 +1,86 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetNFTTransfersByCollectionResponse, AptosGetNFTTransfersByCollectionResponseJSON } from '../types/AptosGetNFTTransfersByCollectionResponse'; + +// request parameters: +// - collection_data_id_hash ($ref: #/paths/~1nfts~1transfers~1collections~1{collection_data_id_hash}/get/parameters/0/schema) +// - limit ($ref: #/paths/~1nfts~1transfers~1collections~1{collection_data_id_hash}/get/parameters/1/schema) +// - offset ($ref: #/paths/~1nfts~1transfers~1collections~1{collection_data_id_hash}/get/parameters/2/schema) +// - cursor ($ref: #/paths/~1nfts~1transfers~1collections~1{collection_data_id_hash}/get/parameters/3/schema) +// - wallet_whitelist ($ref: #/paths/~1nfts~1transfers~1collections~1{collection_data_id_hash}/get/parameters/4/schema) +// - wallet_blacklist ($ref: #/paths/~1nfts~1transfers~1collections~1{collection_data_id_hash}/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTTransfersByCollectionOperationRequest { + /** + * @description The collection data id hash of the token + */ + readonly collectionDataIdHash: string; + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the wallets to whitelist + */ + readonly walletWhitelist?: string[]; + /** + * @description The addresses of the wallets to blacklist + */ + readonly walletBlacklist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTTransfersByCollectionOperationRequestJSON { + readonly collection_data_id_hash: string; + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly wallet_whitelist?: string[]; + readonly wallet_blacklist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTTransfersByCollectionOperation = { + operationId: "getNFTTransfersByCollection", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/transfers/collections/{collection_data_id_hash}", + parameterNames: ["collection_data_id_hash","limit","offset","cursor","wallet_whitelist","wallet_blacklist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetNFTTransfersByCollectionResponseJSON): AptosGetNFTTransfersByCollectionResponse { + return AptosGetNFTTransfersByCollectionResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTTransfersByCollectionOperationRequest): GetNFTTransfersByCollectionOperationRequestJSON { + const collectionDataIdHash = request.collectionDataIdHash; + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const walletWhitelist = request.walletWhitelist; + const walletBlacklist = request.walletBlacklist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + collection_data_id_hash: collectionDataIdHash, + limit: limit, + offset: offset, + cursor: cursor, + wallet_whitelist: walletWhitelist, + wallet_blacklist: walletBlacklist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByCreatorsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByCreatorsOperation.ts new file mode 100644 index 0000000000..310142994e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByCreatorsOperation.ts @@ -0,0 +1,86 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetNFTTransfersByCreatorsResponse, AptosGetNFTTransfersByCreatorsResponseJSON } from '../types/AptosGetNFTTransfersByCreatorsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1nfts~1transfers~1creators/get/parameters/0/schema) +// - offset ($ref: #/paths/~1nfts~1transfers~1creators/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1nfts~1transfers~1creators/get/parameters/2/schema) +// - creator_addresses ($ref: #/paths/~1nfts~1transfers~1creators/get/parameters/3/schema) +// - collection_blacklist ($ref: #/paths/~1nfts~1transfers~1creators/get/parameters/4/schema) +// - collection_whitelist ($ref: #/paths/~1nfts~1transfers~1creators/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTTransfersByCreatorsOperationRequest { + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the creators + */ + readonly creatorAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The ids of the collections to whitelist + */ + readonly collectionBlacklist?: string[]; + /** + * @description The ids of the collections to whitelist + */ + readonly collectionWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTTransfersByCreatorsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly creator_addresses: AptosAddressJSON[]; + readonly collection_blacklist?: string[]; + readonly collection_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTTransfersByCreatorsOperation = { + operationId: "getNFTTransfersByCreators", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/transfers/creators", + parameterNames: ["limit","offset","cursor","creator_addresses","collection_blacklist","collection_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetNFTTransfersByCreatorsResponseJSON): AptosGetNFTTransfersByCreatorsResponse { + return AptosGetNFTTransfersByCreatorsResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTTransfersByCreatorsOperationRequest): GetNFTTransfersByCreatorsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const creatorAddresses = request.creatorAddresses.map((item) => AptosAddress.create(item)); + const collectionBlacklist = request.collectionBlacklist; + const collectionWhitelist = request.collectionWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + creator_addresses: creatorAddresses.map((item) => item.toJSON()), + collection_blacklist: collectionBlacklist, + collection_whitelist: collectionWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByIdsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByIdsOperation.ts new file mode 100644 index 0000000000..df01af5acc --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByIdsOperation.ts @@ -0,0 +1,86 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTTransfersByTokensResponse, AptosNFTTransfersByTokensResponseJSON } from '../types/AptosNFTTransfersByTokensResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1nfts~1transfers/get/parameters/0/schema) +// - offset ($ref: #/paths/~1nfts~1transfers/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1nfts~1transfers/get/parameters/2/schema) +// - wallet_blacklist ($ref: #/paths/~1nfts~1transfers/get/parameters/3/schema) +// - wallet_whitelist ($ref: #/paths/~1nfts~1transfers/get/parameters/4/schema) +// - token_ids ($ref: #/paths/~1nfts~1transfers/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTTransfersByIdsOperationRequest { + /** + * @description The number of tokens to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the wallets to blacklist + */ + readonly walletBlacklist?: string[]; + /** + * @description The addresses of the wallets to whitelist + */ + readonly walletWhitelist?: string[]; + /** + * @description The identifiers of the tokens to get + */ + readonly tokenIds: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTTransfersByIdsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly wallet_blacklist?: string[]; + readonly wallet_whitelist?: string[]; + readonly token_ids: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTTransfersByIdsOperation = { + operationId: "getNFTTransfersByIds", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/transfers", + parameterNames: ["limit","offset","cursor","wallet_blacklist","wallet_whitelist","token_ids","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTTransfersByTokensResponseJSON[]): AptosNFTTransfersByTokensResponse[] { + return json.map((item) => AptosNFTTransfersByTokensResponse.fromJSON(item)); + }, + + serializeRequest(request: GetNFTTransfersByIdsOperationRequest): GetNFTTransfersByIdsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const walletBlacklist = request.walletBlacklist; + const walletWhitelist = request.walletWhitelist; + const tokenIds = request.tokenIds; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + wallet_blacklist: walletBlacklist, + wallet_whitelist: walletWhitelist, + token_ids: tokenIds, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByWalletsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByWalletsOperation.ts new file mode 100644 index 0000000000..9ba97dd8fe --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTTransfersByWalletsOperation.ts @@ -0,0 +1,86 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTTransfersByWalletsResponse, AptosNFTTransfersByWalletsResponseJSON } from '../types/AptosNFTTransfersByWalletsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1nfts~1transfers~1wallets/get/parameters/0/schema) +// - offset ($ref: #/paths/~1nfts~1transfers~1wallets/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1nfts~1transfers~1wallets/get/parameters/2/schema) +// - wallet_addresses ($ref: #/paths/~1nfts~1transfers~1wallets/get/parameters/3/schema) +// - collection_blacklist ($ref: #/paths/~1nfts~1transfers~1wallets/get/parameters/4/schema) +// - collection_whitelist ($ref: #/paths/~1nfts~1transfers~1wallets/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTTransfersByWalletsOperationRequest { + /** + * @description The number of tokens to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the wallets to get transfers for + */ + readonly walletAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The ids of the collections to whitelist + */ + readonly collectionBlacklist?: string[]; + /** + * @description The ids of the collections to whitelist + */ + readonly collectionWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTTransfersByWalletsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly wallet_addresses: AptosAddressJSON[]; + readonly collection_blacklist?: string[]; + readonly collection_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTTransfersByWalletsOperation = { + operationId: "getNFTTransfersByWallets", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/transfers/wallets", + parameterNames: ["limit","offset","cursor","wallet_addresses","collection_blacklist","collection_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTTransfersByWalletsResponseJSON): AptosNFTTransfersByWalletsResponse { + return AptosNFTTransfersByWalletsResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTTransfersByWalletsOperationRequest): GetNFTTransfersByWalletsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const walletAddresses = request.walletAddresses.map((item) => AptosAddress.create(item)); + const collectionBlacklist = request.collectionBlacklist; + const collectionWhitelist = request.collectionWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + wallet_addresses: walletAddresses.map((item) => item.toJSON()), + collection_blacklist: collectionBlacklist, + collection_whitelist: collectionWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTsByCollectionOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTsByCollectionOperation.ts new file mode 100644 index 0000000000..9b47e9fdb5 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTsByCollectionOperation.ts @@ -0,0 +1,70 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTTokensByCollectionResponse, AptosNFTTokensByCollectionResponseJSON } from '../types/AptosNFTTokensByCollectionResponse'; + +// request parameters: +// - collection_data_id_hash ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1tokens/get/parameters/0/schema) +// - limit ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1tokens/get/parameters/1/schema) +// - offset ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1tokens/get/parameters/2/schema) +// - cursor ($ref: #/paths/~1nfts~1collections~1{collection_data_id_hash}~1tokens/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTsByCollectionOperationRequest { + /** + * @description The collection data id hash of the collection + */ + readonly collectionDataIdHash: string; + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTsByCollectionOperationRequestJSON { + readonly collection_data_id_hash: string; + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTsByCollectionOperation = { + operationId: "getNFTsByCollection", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/collections/{collection_data_id_hash}/tokens", + parameterNames: ["collection_data_id_hash","limit","offset","cursor","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTTokensByCollectionResponseJSON): AptosNFTTokensByCollectionResponse { + return AptosNFTTokensByCollectionResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTsByCollectionOperationRequest): GetNFTsByCollectionOperationRequestJSON { + const collectionDataIdHash = request.collectionDataIdHash; + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + collection_data_id_hash: collectionDataIdHash, + limit: limit, + offset: offset, + cursor: cursor, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTsByCreatorsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTsByCreatorsOperation.ts new file mode 100644 index 0000000000..a83ab7ccf5 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTsByCreatorsOperation.ts @@ -0,0 +1,70 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTTokensByCreatorsResponse, AptosNFTTokensByCreatorsResponseJSON } from '../types/AptosNFTTokensByCreatorsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1nfts~1creators/get/parameters/0/schema) +// - offset ($ref: #/paths/~1nfts~1creators/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1nfts~1creators/get/parameters/2/schema) +// - creator_addresses ($ref: #/paths/~1nfts~1creators/get/parameters/3/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTsByCreatorsOperationRequest { + /** + * @description The number of tokens to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the creators + */ + readonly creatorAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTsByCreatorsOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly creator_addresses: AptosAddressJSON[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTsByCreatorsOperation = { + operationId: "getNFTsByCreators", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts/creators", + parameterNames: ["limit","offset","cursor","creator_addresses","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTTokensByCreatorsResponseJSON): AptosNFTTokensByCreatorsResponse { + return AptosNFTTokensByCreatorsResponse.fromJSON(json); + }, + + serializeRequest(request: GetNFTsByCreatorsOperationRequest): GetNFTsByCreatorsOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const creatorAddresses = request.creatorAddresses.map((item) => AptosAddress.create(item)); + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + creator_addresses: creatorAddresses.map((item) => item.toJSON()), + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetNFTsByIdsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetNFTsByIdsOperation.ts new file mode 100644 index 0000000000..4a8de877a2 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetNFTsByIdsOperation.ts @@ -0,0 +1,46 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTTokenResponse, AptosNFTTokenResponseJSON } from '../types/AptosNFTTokenResponse'; + +// request parameters: +// - token_ids ($ref: #/paths/~1nfts/get/parameters/0/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetNFTsByIdsOperationRequest { + /** + * @description The identifiers of the tokens to get + */ + readonly tokenIds: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetNFTsByIdsOperationRequestJSON { + readonly token_ids: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetNFTsByIdsOperation = { + operationId: "getNFTsByIds", + groupName: "nfts", + httpMethod: "get", + routePattern: "/nfts", + parameterNames: ["token_ids","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTTokenResponseJSON[]): AptosNFTTokenResponse[] { + return json.map((item) => AptosNFTTokenResponse.fromJSON(item)); + }, + + serializeRequest(request: GetNFTsByIdsOperationRequest): GetNFTsByIdsOperationRequestJSON { + const tokenIds = request.tokenIds; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + token_ids: tokenIds, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetTopHoldersByCoinOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetTopHoldersByCoinOperation.ts new file mode 100644 index 0000000000..e618f5a514 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetTopHoldersByCoinOperation.ts @@ -0,0 +1,102 @@ +import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetTopHoldersByCoinResponse, AptosGetTopHoldersByCoinResponseJSON } from '../types/AptosGetTopHoldersByCoinResponse'; + +// request parameters: +// - coin_type_hash ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/0/schema) +// - limit ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/1/schema) +// - offset ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/2/schema) +// - cursor ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/3/schema) +// - min_amount ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/4/schema) +// - min_version ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/5/schema) +// - wallet_blacklist ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/6/schema) +// - wallet_whitelist ($ref: #/paths/~1coins~1owners~1{coin_type_hash}~1top-holders/get/parameters/7/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetTopHoldersByCoinOperationRequest { + /** + * @description The coin type hash to fetch info about + */ + readonly coinTypeHash: string; + /** + * @description The number of results to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The minimum amount of coins required for a wallet to be included in the results + */ + readonly minAmount?: AptosNativeInput | AptosNative; + /** + * @description The minimum version on when the balance was last updated + */ + readonly minVersion?: number; + /** + * @description The addresses of the wallets to blacklist + */ + readonly walletBlacklist?: string[]; + /** + * @description The addresses of the wallets to whitelist + */ + readonly walletWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetTopHoldersByCoinOperationRequestJSON { + readonly coin_type_hash: string; + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly min_amount?: AptosNativeJSON; + readonly min_version?: number; + readonly wallet_blacklist?: string[]; + readonly wallet_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetTopHoldersByCoinOperation = { + operationId: "getTopHoldersByCoin", + groupName: "coins", + httpMethod: "get", + routePattern: "/coins/owners/{coin_type_hash}/top-holders", + parameterNames: ["coin_type_hash","limit","offset","cursor","min_amount","min_version","wallet_blacklist","wallet_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetTopHoldersByCoinResponseJSON): AptosGetTopHoldersByCoinResponse { + return AptosGetTopHoldersByCoinResponse.fromJSON(json); + }, + + serializeRequest(request: GetTopHoldersByCoinOperationRequest): GetTopHoldersByCoinOperationRequestJSON { + const coinTypeHash = request.coinTypeHash; + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const minAmount = request.minAmount ? AptosNative.create(request.minAmount) : undefined; + const minVersion = request.minVersion; + const walletBlacklist = request.walletBlacklist; + const walletWhitelist = request.walletWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + coin_type_hash: coinTypeHash, + limit: limit, + offset: offset, + cursor: cursor, + min_amount: minAmount ? minAmount.toJSON() : undefined, + min_version: minVersion, + wallet_blacklist: walletBlacklist, + wallet_whitelist: walletWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetTransactionByHashOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetTransactionByHashOperation.ts new file mode 100644 index 0000000000..88dcb471d4 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetTransactionByHashOperation.ts @@ -0,0 +1,46 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetTransactionByHash, AptosGetTransactionByHashValue, AptosGetTransactionByHashJSON } from '../types/AptosGetTransactionByHash'; + +// request parameters: +// - txn_hash ($ref: #/paths/~1transactions~1by_hash~1{txn_hash}/get/parameters/0/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetTransactionByHashOperationRequest { + /** + * @description Hash of transaction to retrieve + */ + readonly txnHash: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetTransactionByHashOperationRequestJSON { + readonly txn_hash: string; + readonly network?: AptosNetworkJSON; +} + +export const GetTransactionByHashOperation = { + operationId: "getTransactionByHash", + groupName: "transactions", + httpMethod: "get", + routePattern: "/transactions/by_hash/{txn_hash}", + parameterNames: ["txn_hash","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetTransactionByHashJSON): AptosGetTransactionByHashValue { + return AptosGetTransactionByHash.fromJSON(json); + }, + + serializeRequest(request: GetTransactionByHashOperationRequest): GetTransactionByHashOperationRequestJSON { + const txnHash = request.txnHash; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + txn_hash: txnHash, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetTransactionByVersionOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetTransactionByVersionOperation.ts new file mode 100644 index 0000000000..740d310fd9 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetTransactionByVersionOperation.ts @@ -0,0 +1,46 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetTransactionByVersion, AptosGetTransactionByVersionValue, AptosGetTransactionByVersionJSON } from '../types/AptosGetTransactionByVersion'; + +// request parameters: +// - txn_version ($ref: #/paths/~1transactions~1by_version~1{txn_version}/get/parameters/0/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetTransactionByVersionOperationRequest { + /** + * @description Version of transaction to retrieve + */ + readonly txnVersion: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetTransactionByVersionOperationRequestJSON { + readonly txn_version: string; + readonly network?: AptosNetworkJSON; +} + +export const GetTransactionByVersionOperation = { + operationId: "getTransactionByVersion", + groupName: "transactions", + httpMethod: "get", + routePattern: "/transactions/by_version/{txn_version}", + parameterNames: ["txn_version","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetTransactionByVersionJSON): AptosGetTransactionByVersionValue { + return AptosGetTransactionByVersion.fromJSON(json); + }, + + serializeRequest(request: GetTransactionByVersionOperationRequest): GetTransactionByVersionOperationRequestJSON { + const txnVersion = request.txnVersion; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + txn_version: txnVersion, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetTransactionsOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetTransactionsOperation.ts new file mode 100644 index 0000000000..745c9d87fc --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetTransactionsOperation.ts @@ -0,0 +1,56 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosGetTransactionsItem, AptosGetTransactionsItemValue, AptosGetTransactionsItemJSON } from '../types/AptosGetTransactionsItem'; + +// request parameters: +// - limit ($ref: #/paths/~1transactions/get/parameters/0/schema) +// - start ($ref: #/paths/~1transactions/get/parameters/1/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetTransactionsOperationRequest { + /** + * @description Max number of transactions to retrieve. + * If not provided, defaults to default page size + */ + readonly limit?: number; + /** + * @description Account sequence number to start list of transactions. + * If not provided, defaults to showing the latest transactions + */ + readonly start?: string; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetTransactionsOperationRequestJSON { + readonly limit?: number; + readonly start?: string; + readonly network?: AptosNetworkJSON; +} + +export const GetTransactionsOperation = { + operationId: "getTransactions", + groupName: "transactions", + httpMethod: "get", + routePattern: "/transactions", + parameterNames: ["limit","start","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosGetTransactionsItemJSON[]): AptosGetTransactionsItemValue[] { + return json.map((item) => AptosGetTransactionsItem.fromJSON(item)); + }, + + serializeRequest(request: GetTransactionsOperationRequest): GetTransactionsOperationRequestJSON { + const limit = request.limit; + const start = request.start; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + start: start, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/GetWalletsNFTTransfersOperation.ts b/packages/common/aptosUtils/src/generated/operations/GetWalletsNFTTransfersOperation.ts new file mode 100644 index 0000000000..a6b230cf4e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/GetWalletsNFTTransfersOperation.ts @@ -0,0 +1,86 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON, AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosNFTTransfersByWalletsResponse, AptosNFTTransfersByWalletsResponseJSON } from '../types/AptosNFTTransfersByWalletsResponse'; + +// request parameters: +// - limit ($ref: #/paths/~1wallets~1nfts~1transfers/get/parameters/0/schema) +// - offset ($ref: #/paths/~1wallets~1nfts~1transfers/get/parameters/1/schema) +// - cursor ($ref: #/paths/~1wallets~1nfts~1transfers/get/parameters/2/schema) +// - wallet_addresses ($ref: #/paths/~1wallets~1nfts~1transfers/get/parameters/3/schema) +// - collection_blacklist ($ref: #/paths/~1wallets~1nfts~1transfers/get/parameters/4/schema) +// - collection_whitelist ($ref: #/paths/~1wallets~1nfts~1transfers/get/parameters/5/schema) +// - network ($ref: #/virtualParameter/network) + +export interface GetWalletsNFTTransfersOperationRequest { + /** + * @description The number of tokens to return + */ + readonly limit: number; + /** + * @description The number of results to skip + */ + readonly offset?: number; + /** + * @description The cursor to use for getting the next page + */ + readonly cursor?: string; + /** + * @description The addresses of the wallets to get transfers for + */ + readonly walletAddresses: AptosAddressInput[] | AptosAddress[]; + /** + * @description The ids of the collections to whitelist + */ + readonly collectionBlacklist?: string[]; + /** + * @description The ids of the collections to whitelist + */ + readonly collectionWhitelist?: string[]; + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface GetWalletsNFTTransfersOperationRequestJSON { + readonly limit: number; + readonly offset?: number; + readonly cursor?: string; + readonly wallet_addresses: AptosAddressJSON[]; + readonly collection_blacklist?: string[]; + readonly collection_whitelist?: string[]; + readonly network?: AptosNetworkJSON; +} + +export const GetWalletsNFTTransfersOperation = { + operationId: "getWalletsNFTTransfers", + groupName: "wallets", + httpMethod: "get", + routePattern: "/wallets/nfts/transfers", + parameterNames: ["limit","offset","cursor","wallet_addresses","collection_blacklist","collection_whitelist","network"], + hasResponse: true, + hasBody: false, + + parseResponse(json: AptosNFTTransfersByWalletsResponseJSON): AptosNFTTransfersByWalletsResponse { + return AptosNFTTransfersByWalletsResponse.fromJSON(json); + }, + + serializeRequest(request: GetWalletsNFTTransfersOperationRequest): GetWalletsNFTTransfersOperationRequestJSON { + const limit = request.limit; + const offset = request.offset; + const cursor = request.cursor; + const walletAddresses = request.walletAddresses.map((item) => AptosAddress.create(item)); + const collectionBlacklist = request.collectionBlacklist; + const collectionWhitelist = request.collectionWhitelist; + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + limit: limit, + offset: offset, + cursor: cursor, + wallet_addresses: walletAddresses.map((item) => item.toJSON()), + collection_blacklist: collectionBlacklist, + collection_whitelist: collectionWhitelist, + network: network ? network.toJSON() : undefined, + }; + }, + +} diff --git a/packages/common/aptosUtils/src/generated/operations/SimulateTransactionOperation.ts b/packages/common/aptosUtils/src/generated/operations/SimulateTransactionOperation.ts new file mode 100644 index 0000000000..268179a747 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/SimulateTransactionOperation.ts @@ -0,0 +1,43 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosSimulateTransaction, AptosSimulateTransactionValue, AptosSimulateTransactionJSON } from '../types/AptosSimulateTransaction'; +import { AptosSubmitTransactionRequest, AptosSubmitTransactionRequestInput, AptosSubmitTransactionRequestJSON } from '../types/AptosSubmitTransactionRequest'; + +// request parameters: +// - network ($ref: #/virtualParameter/network) + +export interface SimulateTransactionOperationRequest { + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface SimulateTransactionOperationRequestJSON { + readonly network?: AptosNetworkJSON; +} + +export const SimulateTransactionOperation = { + operationId: "simulateTransaction", + groupName: "transactions", + httpMethod: "post", + routePattern: "/transactions/simulate", + parameterNames: ["network"], + hasResponse: true, + hasBody: true, + + parseResponse(json: AptosSimulateTransactionJSON): AptosSimulateTransactionValue { + return AptosSimulateTransaction.fromJSON(json); + }, + + serializeRequest(request: SimulateTransactionOperationRequest): SimulateTransactionOperationRequestJSON { + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + network: network ? network.toJSON() : undefined, + }; + }, + + serializeBody(body: AptosSubmitTransactionRequestInput | AptosSubmitTransactionRequest): AptosSubmitTransactionRequestJSON { + const value = AptosSubmitTransactionRequest.create(body); + return value.toJSON(); + }, +} diff --git a/packages/common/aptosUtils/src/generated/operations/SubmitBatchTransactionsOperation.ts b/packages/common/aptosUtils/src/generated/operations/SubmitBatchTransactionsOperation.ts new file mode 100644 index 0000000000..08f06aa37c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/SubmitBatchTransactionsOperation.ts @@ -0,0 +1,43 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosSubmitBatchTransactionResult, AptosSubmitBatchTransactionResultJSON } from '../types/AptosSubmitBatchTransactionResult'; +import { AptosSubmitTransactionRequest, AptosSubmitTransactionRequestInput, AptosSubmitTransactionRequestJSON } from '../types/AptosSubmitTransactionRequest'; + +// request parameters: +// - network ($ref: #/virtualParameter/network) + +export interface SubmitBatchTransactionsOperationRequest { + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface SubmitBatchTransactionsOperationRequestJSON { + readonly network?: AptosNetworkJSON; +} + +export const SubmitBatchTransactionsOperation = { + operationId: "submitBatchTransactions", + groupName: "transactions", + httpMethod: "post", + routePattern: "/transactions/batch", + parameterNames: ["network"], + hasResponse: true, + hasBody: true, + + parseResponse(json: AptosSubmitBatchTransactionResultJSON): AptosSubmitBatchTransactionResult { + return AptosSubmitBatchTransactionResult.fromJSON(json); + }, + + serializeRequest(request: SubmitBatchTransactionsOperationRequest): SubmitBatchTransactionsOperationRequestJSON { + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + network: network ? network.toJSON() : undefined, + }; + }, + + serializeBody(body: AptosSubmitTransactionRequestInput[] | AptosSubmitTransactionRequest[]): AptosSubmitTransactionRequestJSON[] { + const value = body.map((item) => AptosSubmitTransactionRequest.create(item)); + return value.map((item) => item.toJSON()); + }, +} diff --git a/packages/common/aptosUtils/src/generated/operations/SubmitTransactionOperation.ts b/packages/common/aptosUtils/src/generated/operations/SubmitTransactionOperation.ts new file mode 100644 index 0000000000..a453a2ecc8 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/SubmitTransactionOperation.ts @@ -0,0 +1,43 @@ +import { AptosNetwork, AptosNetworkInput, AptosNetworkJSON } from '../../dataTypes'; +import { AptosPendingTransaction, AptosPendingTransactionJSON } from '../types/AptosPendingTransaction'; +import { AptosSubmitTransactionRequest, AptosSubmitTransactionRequestInput, AptosSubmitTransactionRequestJSON } from '../types/AptosSubmitTransactionRequest'; + +// request parameters: +// - network ($ref: #/virtualParameter/network) + +export interface SubmitTransactionOperationRequest { + /** + * @description The network of query. Defaults to mainnet. + */ + readonly network?: AptosNetworkInput | AptosNetwork; +} + +export interface SubmitTransactionOperationRequestJSON { + readonly network?: AptosNetworkJSON; +} + +export const SubmitTransactionOperation = { + operationId: "submitTransaction", + groupName: "transactions", + httpMethod: "post", + routePattern: "/transactions", + parameterNames: ["network"], + hasResponse: true, + hasBody: true, + + parseResponse(json: AptosPendingTransactionJSON): AptosPendingTransaction { + return AptosPendingTransaction.fromJSON(json); + }, + + serializeRequest(request: SubmitTransactionOperationRequest): SubmitTransactionOperationRequestJSON { + const network = request.network ? AptosNetwork.create(request.network) : undefined; + return { + network: network ? network.toJSON() : undefined, + }; + }, + + serializeBody(body: AptosSubmitTransactionRequestInput | AptosSubmitTransactionRequest): AptosSubmitTransactionRequestJSON { + const value = AptosSubmitTransactionRequest.create(body); + return value.toJSON(); + }, +} diff --git a/packages/common/aptosUtils/src/generated/operations/index.ts b/packages/common/aptosUtils/src/generated/operations/index.ts new file mode 100644 index 0000000000..97c329c54d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/operations/index.ts @@ -0,0 +1,45 @@ +export * from './GetNFTsByIdsOperation'; +export * from './GetNFTsByCollectionOperation'; +export * from './GetNFTsByCreatorsOperation'; +export * from './GetNFTCollectionsOperation'; +export * from './GetNFTCollectionsByIdsOperation'; +export * from './GetNFTCollectionsByCreatorOperation'; +export * from './GetNFTOwnersByTokensOperation'; +export * from './GetNFTOwnersByCollectionOperation'; +export * from './GetNFTOwnersOfCollectionOperation'; +export * from './GetNFTTransfersByIdsOperation'; +export * from './GetNFTTransfersByCollectionOperation'; +export * from './GetNFTTransfersByCreatorsOperation'; +export * from './GetNFTTransfersByWalletsOperation'; +export * from './GetCoinInfoByCoinTypeHashesOperation'; +export * from './GetLatestCoinsOperation'; +export * from './GetCoinsByNameRangeOperation'; +export * from './GetCoinsBySymbolRangeOperation'; +export * from './GetCoinsByCreatorsOperation'; +export * from './GetCoinTransfersByOwnerAddressesOperation'; +export * from './GetCoinTransfersByBlockHeightsOperation'; +export * from './GetCoinTransfersByCoinTypeOperation'; +export * from './GetTopHoldersByCoinOperation'; +export * from './GetCoinBalancesByWalletsOperation'; +export * from './GetHistoricalCoinBalancesByWalletsOperation'; +export * from './GetCoinTransfersByWalletAddressesOperation'; +export * from './GetNFTByOwnersOperation'; +export * from './GetWalletsNFTTransfersOperation'; +export * from './GetAccountOperation'; +export * from './GetAccountResourcesOperation'; +export * from './GetAccountModulesOperation'; +export * from './GetAccountResourceOperation'; +export * from './GetAccountModuleOperation'; +export * from './GetEventsByCreationNumberOperation'; +export * from './GetEventsByEventHandleOperation'; +export * from './GetTransactionsOperation'; +export * from './SubmitTransactionOperation'; +export * from './GetTransactionByHashOperation'; +export * from './GetTransactionByVersionOperation'; +export * from './GetAccountTransactionsOperation'; +export * from './SubmitBatchTransactionsOperation'; +export * from './SimulateTransactionOperation'; +export * from './EncodeSubmissionOperation'; +export * from './EstimateGasPriceOperation'; +export * from './GetBlockByHeightOperation'; +export * from './GetBlockByVersionOperation'; diff --git a/packages/common/aptosUtils/src/generated/types/AptosBlock.ts b/packages/common/aptosUtils/src/generated/types/AptosBlock.ts new file mode 100644 index 0000000000..21b198eb9c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosBlock.ts @@ -0,0 +1,92 @@ +import { AptosBlockTransactionsItem, AptosBlockTransactionsItemValue, AptosBlockTransactionsItemInput, AptosBlockTransactionsItemJSON } from '../types/AptosBlockTransactionsItem'; + +// $ref: #/components/schemas/Block +// type: Block +// properties: +// - block_height ($ref: #/components/schemas/Block/properties/block_height) +// - block_hash ($ref: #/components/schemas/Block/properties/block_hash) +// - block_timestamp ($ref: #/components/schemas/Block/properties/block_timestamp) +// - first_version ($ref: #/components/schemas/Block/properties/first_version) +// - last_version ($ref: #/components/schemas/Block/properties/last_version) +// - transactions ($ref: #/components/schemas/Block/properties/transactions/items) + +export interface AptosBlockJSON { + readonly block_height: string; + readonly block_hash: string; + readonly block_timestamp: string; + readonly first_version: string; + readonly last_version: string; + readonly transactions?: AptosBlockTransactionsItemJSON[]; +} + +export interface AptosBlockInput { + readonly blockHeight: string; + readonly blockHash: string; + readonly blockTimestamp: string; + readonly firstVersion: string; + readonly lastVersion: string; + readonly transactions?: AptosBlockTransactionsItemInput[] | AptosBlockTransactionsItemValue[]; +} + +export class AptosBlock { + public static create(input: AptosBlockInput | AptosBlock): AptosBlock { + if (input instanceof AptosBlock) { + return input; + } + return new AptosBlock(input); + } + + public static fromJSON(json: AptosBlockJSON): AptosBlock { + const input: AptosBlockInput = { + blockHeight: json.block_height, + blockHash: json.block_hash, + blockTimestamp: json.block_timestamp, + firstVersion: json.first_version, + lastVersion: json.last_version, + transactions: json.transactions ? json.transactions.map((item) => AptosBlockTransactionsItem.fromJSON(item)) : undefined, + }; + return AptosBlock.create(input); + } + + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly blockHeight: string; + public readonly blockHash: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly blockTimestamp: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly firstVersion: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly lastVersion: string; + /** + * @description List of transactions + */ + public readonly transactions?: AptosBlockTransactionsItemValue[]; + + private constructor(input: AptosBlockInput) { + this.blockHeight = input.blockHeight; + this.blockHash = input.blockHash; + this.blockTimestamp = input.blockTimestamp; + this.firstVersion = input.firstVersion; + this.lastVersion = input.lastVersion; + this.transactions = input.transactions ? input.transactions.map((item) => AptosBlockTransactionsItem.create(item)) : undefined; + } + + public toJSON(): AptosBlockJSON { + return { + block_height: this.blockHeight, + block_hash: this.blockHash, + block_timestamp: this.blockTimestamp, + first_version: this.firstVersion, + last_version: this.lastVersion, + transactions: this.transactions ? this.transactions.map((item) => item.toJSON()) : undefined, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosBlockMetadataTransaction.ts b/packages/common/aptosUtils/src/generated/types/AptosBlockMetadataTransaction.ts new file mode 100644 index 0000000000..dc81568b82 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosBlockMetadataTransaction.ts @@ -0,0 +1,211 @@ +import { AptosBlockMetadataTransactionChangesItem, AptosBlockMetadataTransactionChangesItemValue, AptosBlockMetadataTransactionChangesItemInput, AptosBlockMetadataTransactionChangesItemJSON } from '../types/AptosBlockMetadataTransactionChangesItem'; +import { AptosTransactionEvent, AptosTransactionEventInput, AptosTransactionEventJSON } from '../types/AptosTransactionEvent'; +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/BlockMetadataTransaction +// type: BlockMetadataTransaction +// properties: +// - type ($ref: #/components/schemas/BlockMetadataTransaction/properties/type) +// - version ($ref: #/components/schemas/BlockMetadataTransaction/properties/version) +// - hash ($ref: #/components/schemas/BlockMetadataTransaction/properties/hash) +// - state_change_hash ($ref: #/components/schemas/BlockMetadataTransaction/properties/state_change_hash) +// - event_root_hash ($ref: #/components/schemas/BlockMetadataTransaction/properties/event_root_hash) +// - state_checkpoint_hash ($ref: #/components/schemas/BlockMetadataTransaction/properties/state_checkpoint_hash) +// - gas_used ($ref: #/components/schemas/BlockMetadataTransaction/properties/gas_used) +// - success ($ref: #/components/schemas/BlockMetadataTransaction/properties/success) +// - vm_status ($ref: #/components/schemas/BlockMetadataTransaction/properties/vm_status) +// - accumulator_root_hash ($ref: #/components/schemas/BlockMetadataTransaction/properties/accumulator_root_hash) +// - changes ($ref: #/components/schemas/BlockMetadataTransaction/properties/changes/items) +// - id ($ref: #/components/schemas/BlockMetadataTransaction/properties/id) +// - epoch ($ref: #/components/schemas/BlockMetadataTransaction/properties/epoch) +// - round ($ref: #/components/schemas/BlockMetadataTransaction/properties/round) +// - events ($ref: #/components/schemas/TransactionEvent) +// - previous_block_votes_bitvec ($ref: #/components/schemas/BlockMetadataTransaction/properties/previous_block_votes_bitvec) +// - proposer ($ref: #/components/schemas/BlockMetadataTransaction/properties/proposer) +// - failed_proposer_indices ($ref: #/components/schemas/BlockMetadataTransaction/properties/failed_proposer_indices) +// - timestamp ($ref: #/components/schemas/BlockMetadataTransaction/properties/timestamp) + +export interface AptosBlockMetadataTransactionJSON { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly state_change_hash: string; + readonly event_root_hash: string; + readonly state_checkpoint_hash: string; + readonly gas_used: string; + readonly success: boolean; + readonly vm_status: string; + readonly accumulator_root_hash: string; + readonly changes: AptosBlockMetadataTransactionChangesItemJSON[]; + readonly id: string; + readonly epoch: string; + readonly round: string; + readonly events: AptosTransactionEventJSON[]; + readonly previous_block_votes_bitvec: string[]; + readonly proposer: AptosAddressJSON; + readonly failed_proposer_indices: string[]; + readonly timestamp: string; +} + +export interface AptosBlockMetadataTransactionInput { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly stateChangeHash: string; + readonly eventRootHash: string; + readonly stateCheckpointHash: string; + readonly gasUsed: string; + readonly success: boolean; + readonly vmStatus: string; + readonly accumulatorRootHash: string; + readonly changes: AptosBlockMetadataTransactionChangesItemInput[] | AptosBlockMetadataTransactionChangesItemValue[]; + readonly id: string; + readonly epoch: string; + readonly round: string; + readonly events: AptosTransactionEventInput[] | AptosTransactionEvent[]; + readonly previousBlockVotesBitvec: string[]; + readonly proposer: AptosAddressInput | AptosAddress; + readonly failedProposerIndices: string[]; + readonly timestamp: string; +} + +export class AptosBlockMetadataTransaction { + public static create(input: AptosBlockMetadataTransactionInput | AptosBlockMetadataTransaction): AptosBlockMetadataTransaction { + if (input instanceof AptosBlockMetadataTransaction) { + return input; + } + return new AptosBlockMetadataTransaction(input); + } + + public static fromJSON(json: AptosBlockMetadataTransactionJSON): AptosBlockMetadataTransaction { + const input: AptosBlockMetadataTransactionInput = { + type: json.type, + version: json.version, + hash: json.hash, + stateChangeHash: json.state_change_hash, + eventRootHash: json.event_root_hash, + stateCheckpointHash: json.state_checkpoint_hash, + gasUsed: json.gas_used, + success: json.success, + vmStatus: json.vm_status, + accumulatorRootHash: json.accumulator_root_hash, + changes: json.changes.map((item) => AptosBlockMetadataTransactionChangesItem.fromJSON(item)), + id: json.id, + epoch: json.epoch, + round: json.round, + events: json.events.map((item) => AptosTransactionEvent.fromJSON(item)), + previousBlockVotesBitvec: json.previous_block_votes_bitvec, + proposer: AptosAddress.fromJSON(json.proposer), + failedProposerIndices: json.failed_proposer_indices, + timestamp: json.timestamp, + }; + return AptosBlockMetadataTransaction.create(input); + } + + public static isInput(input: any): input is AptosBlockMetadataTransactionInput { + return input.type === 'block_metadata_transaction'; + } + + public static isJSON(json: any): json is AptosBlockMetadataTransactionJSON { + return json.type === 'block_metadata_transaction'; + } + + public readonly type: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly version: string; + public readonly hash: string; + public readonly stateChangeHash: string; + public readonly eventRootHash: string; + public readonly stateCheckpointHash: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUsed: string; + /** + * @description Whether the transaction was successful + */ + public readonly success: boolean; + /** + * @description The VM status of the transaction, can tell useful information in a failure + */ + public readonly vmStatus: string; + public readonly accumulatorRootHash: string; + public readonly changes: AptosBlockMetadataTransactionChangesItemValue[]; + public readonly id: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly epoch: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly round: string; + /** + * @description he events emitted at the block creation + */ + public readonly events: AptosTransactionEvent[]; + /** + * @description Previous block votes + */ + public readonly previousBlockVotesBitvec: string[]; + /** + * @description A hex encoded 32 byte Aptos account address.S + */ + public readonly proposer: AptosAddress; + /** + * @description The indices of the proposers who failed to propose + */ + public readonly failedProposerIndices: string[]; + /** + * @description A string containing a 64-bit unsigned integer + */ + public readonly timestamp: string; + + private constructor(input: AptosBlockMetadataTransactionInput) { + this.type = input.type; + this.version = input.version; + this.hash = input.hash; + this.stateChangeHash = input.stateChangeHash; + this.eventRootHash = input.eventRootHash; + this.stateCheckpointHash = input.stateCheckpointHash; + this.gasUsed = input.gasUsed; + this.success = input.success; + this.vmStatus = input.vmStatus; + this.accumulatorRootHash = input.accumulatorRootHash; + this.changes = input.changes.map((item) => AptosBlockMetadataTransactionChangesItem.create(item)); + this.id = input.id; + this.epoch = input.epoch; + this.round = input.round; + this.events = input.events.map((item) => AptosTransactionEvent.create(item)); + this.previousBlockVotesBitvec = input.previousBlockVotesBitvec; + this.proposer = AptosAddress.create(input.proposer); + this.failedProposerIndices = input.failedProposerIndices; + this.timestamp = input.timestamp; + } + + public toJSON(): AptosBlockMetadataTransactionJSON { + return { + type: this.type, + version: this.version, + hash: this.hash, + state_change_hash: this.stateChangeHash, + event_root_hash: this.eventRootHash, + state_checkpoint_hash: this.stateCheckpointHash, + gas_used: this.gasUsed, + success: this.success, + vm_status: this.vmStatus, + accumulator_root_hash: this.accumulatorRootHash, + changes: this.changes.map((item) => item.toJSON()), + id: this.id, + epoch: this.epoch, + round: this.round, + events: this.events.map((item) => item.toJSON()), + previous_block_votes_bitvec: this.previousBlockVotesBitvec, + proposer: this.proposer.toJSON(), + failed_proposer_indices: this.failedProposerIndices, + timestamp: this.timestamp, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosBlockMetadataTransactionChangesItem.ts b/packages/common/aptosUtils/src/generated/types/AptosBlockMetadataTransactionChangesItem.ts new file mode 100644 index 0000000000..faec3ce75c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosBlockMetadataTransactionChangesItem.ts @@ -0,0 +1,62 @@ +import { AptosDeleteModuleChange, AptosDeleteModuleChangeJSON, AptosDeleteModuleChangeInput } from '../types/AptosDeleteModuleChange'; +import { AptosDeleteResourceChange, AptosDeleteResourceChangeJSON, AptosDeleteResourceChangeInput } from '../types/AptosDeleteResourceChange'; +import { AptosDeleteTableItemChange, AptosDeleteTableItemChangeJSON, AptosDeleteTableItemChangeInput } from '../types/AptosDeleteTableItemChange'; +import { AptosWriteOrUpdateModuleChange, AptosWriteOrUpdateModuleChangeJSON, AptosWriteOrUpdateModuleChangeInput } from '../types/AptosWriteOrUpdateModuleChange'; +import { AptosWriteResourceChange, AptosWriteResourceChangeJSON, AptosWriteResourceChangeInput } from '../types/AptosWriteResourceChange'; +import { AptosWriteTableChangeSetChange, AptosWriteTableChangeSetChangeJSON, AptosWriteTableChangeSetChangeInput } from '../types/AptosWriteTableChangeSetChange'; + +// $ref: #/components/schemas/BlockMetadataTransaction/properties/changes/items +// typeName: BlockMetadataTransaction_changes_Item +// unionType: anyOf + +export type AptosBlockMetadataTransactionChangesItemJSON = AptosDeleteModuleChangeJSON | AptosDeleteResourceChangeJSON | AptosDeleteTableItemChangeJSON | AptosWriteOrUpdateModuleChangeJSON | AptosWriteResourceChangeJSON | AptosWriteTableChangeSetChangeJSON; +export type AptosBlockMetadataTransactionChangesItemInput = AptosDeleteModuleChangeInput | AptosDeleteResourceChangeInput | AptosDeleteTableItemChangeInput | AptosWriteOrUpdateModuleChangeInput | AptosWriteResourceChangeInput | AptosWriteTableChangeSetChangeInput; +export type AptosBlockMetadataTransactionChangesItemValue = AptosDeleteModuleChange | AptosDeleteResourceChange | AptosDeleteTableItemChange | AptosWriteOrUpdateModuleChange | AptosWriteResourceChange | AptosWriteTableChangeSetChange; + +export abstract class AptosBlockMetadataTransactionChangesItem { + public static create(input: AptosBlockMetadataTransactionChangesItemInput): AptosBlockMetadataTransactionChangesItemValue { + if (AptosDeleteModuleChange.isInput(input)) { + return AptosDeleteModuleChange.create(input); + } + if (AptosDeleteResourceChange.isInput(input)) { + return AptosDeleteResourceChange.create(input); + } + if (AptosDeleteTableItemChange.isInput(input)) { + return AptosDeleteTableItemChange.create(input); + } + if (AptosWriteOrUpdateModuleChange.isInput(input)) { + return AptosWriteOrUpdateModuleChange.create(input); + } + if (AptosWriteResourceChange.isInput(input)) { + return AptosWriteResourceChange.create(input); + } + if (AptosWriteTableChangeSetChange.isInput(input)) { + return AptosWriteTableChangeSetChange.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosBlockMetadataTransactionChangesItemJSON): AptosBlockMetadataTransactionChangesItemValue { + if (AptosDeleteModuleChange.isJSON(json)) { + return AptosDeleteModuleChange.fromJSON(json); + } + if (AptosDeleteResourceChange.isJSON(json)) { + return AptosDeleteResourceChange.fromJSON(json); + } + if (AptosDeleteTableItemChange.isJSON(json)) { + return AptosDeleteTableItemChange.fromJSON(json); + } + if (AptosWriteOrUpdateModuleChange.isJSON(json)) { + return AptosWriteOrUpdateModuleChange.fromJSON(json); + } + if (AptosWriteResourceChange.isJSON(json)) { + return AptosWriteResourceChange.fromJSON(json); + } + if (AptosWriteTableChangeSetChange.isJSON(json)) { + return AptosWriteTableChangeSetChange.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosBlockMetadataTransactionChangesItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosBlockTransactionsItem.ts b/packages/common/aptosUtils/src/generated/types/AptosBlockTransactionsItem.ts new file mode 100644 index 0000000000..a53af47fb7 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosBlockTransactionsItem.ts @@ -0,0 +1,55 @@ +import { AptosPendingTransaction, AptosPendingTransactionJSON, AptosPendingTransactionInput } from '../types/AptosPendingTransaction'; +import { AptosUserTransaction, AptosUserTransactionJSON, AptosUserTransactionInput } from '../types/AptosUserTransaction'; +import { AptosGenesisTransaction, AptosGenesisTransactionJSON, AptosGenesisTransactionInput } from '../types/AptosGenesisTransaction'; +import { AptosBlockMetadataTransaction, AptosBlockMetadataTransactionJSON, AptosBlockMetadataTransactionInput } from '../types/AptosBlockMetadataTransaction'; +import { AptosStateCheckpointTransaction, AptosStateCheckpointTransactionJSON, AptosStateCheckpointTransactionInput } from '../types/AptosStateCheckpointTransaction'; + +// $ref: #/components/schemas/Block/properties/transactions/items +// typeName: Block_transactions_Item +// unionType: anyOf + +export type AptosBlockTransactionsItemJSON = AptosPendingTransactionJSON | AptosUserTransactionJSON | AptosGenesisTransactionJSON | AptosBlockMetadataTransactionJSON | AptosStateCheckpointTransactionJSON; +export type AptosBlockTransactionsItemInput = AptosPendingTransactionInput | AptosUserTransactionInput | AptosGenesisTransactionInput | AptosBlockMetadataTransactionInput | AptosStateCheckpointTransactionInput; +export type AptosBlockTransactionsItemValue = AptosPendingTransaction | AptosUserTransaction | AptosGenesisTransaction | AptosBlockMetadataTransaction | AptosStateCheckpointTransaction; + +export abstract class AptosBlockTransactionsItem { + public static create(input: AptosBlockTransactionsItemInput): AptosBlockTransactionsItemValue { + if (AptosPendingTransaction.isInput(input)) { + return AptosPendingTransaction.create(input); + } + if (AptosUserTransaction.isInput(input)) { + return AptosUserTransaction.create(input); + } + if (AptosGenesisTransaction.isInput(input)) { + return AptosGenesisTransaction.create(input); + } + if (AptosBlockMetadataTransaction.isInput(input)) { + return AptosBlockMetadataTransaction.create(input); + } + if (AptosStateCheckpointTransaction.isInput(input)) { + return AptosStateCheckpointTransaction.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosBlockTransactionsItemJSON): AptosBlockTransactionsItemValue { + if (AptosPendingTransaction.isJSON(json)) { + return AptosPendingTransaction.fromJSON(json); + } + if (AptosUserTransaction.isJSON(json)) { + return AptosUserTransaction.fromJSON(json); + } + if (AptosGenesisTransaction.isJSON(json)) { + return AptosGenesisTransaction.fromJSON(json); + } + if (AptosBlockMetadataTransaction.isJSON(json)) { + return AptosBlockMetadataTransaction.fromJSON(json); + } + if (AptosStateCheckpointTransaction.isJSON(json)) { + return AptosStateCheckpointTransaction.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosBlockTransactionsItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosCoinInfoDto.ts b/packages/common/aptosUtils/src/generated/types/AptosCoinInfoDto.ts new file mode 100644 index 0000000000..fde5f3b6dc --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosCoinInfoDto.ts @@ -0,0 +1,135 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/CoinInfoDto +// type: CoinInfoDto +// properties: +// - coin_type ($ref: #/components/schemas/CoinInfoDto/properties/coin_type) +// - coin_type_hash ($ref: #/components/schemas/CoinInfoDto/properties/coin_type_hash) +// - creator_address ($ref: #/components/schemas/CoinInfoDto/properties/creator_address) +// - decimals ($ref: #/components/schemas/CoinInfoDto/properties/decimals) +// - name ($ref: #/components/schemas/CoinInfoDto/properties/name) +// - supply_aggregator_table_handle ($ref: #/components/schemas/CoinInfoDto/properties/supply_aggregator_table_handle) +// - supply_aggregator_table_key ($ref: #/components/schemas/CoinInfoDto/properties/supply_aggregator_table_key) +// - symbol ($ref: #/components/schemas/CoinInfoDto/properties/symbol) +// - transaction_created_timestamp ($ref: #/components/schemas/CoinInfoDto/properties/transaction_created_timestamp) +// - transaction_version_created ($ref: #/components/schemas/CoinInfoDto/properties/transaction_version_created) + +export interface AptosCoinInfoDtoJSON { + readonly coin_type: string; + readonly coin_type_hash: string; + readonly creator_address: AptosAddressJSON; + readonly decimals: number; + readonly name: string; + readonly supply_aggregator_table_handle: string; + readonly supply_aggregator_table_key: string; + readonly symbol: string; + readonly transaction_created_timestamp: string; + readonly transaction_version_created: string; +} + +export interface AptosCoinInfoDtoInput { + readonly coinType: string; + readonly coinTypeHash: string; + readonly creatorAddress: AptosAddressInput | AptosAddress; + readonly decimals: number; + readonly name: string; + readonly supplyAggregatorTableHandle: string; + readonly supplyAggregatorTableKey: string; + readonly symbol: string; + readonly transactionCreatedTimestamp: string; + readonly transactionVersionCreated: string; +} + +export class AptosCoinInfoDto { + public static create(input: AptosCoinInfoDtoInput | AptosCoinInfoDto): AptosCoinInfoDto { + if (input instanceof AptosCoinInfoDto) { + return input; + } + return new AptosCoinInfoDto(input); + } + + public static fromJSON(json: AptosCoinInfoDtoJSON): AptosCoinInfoDto { + const input: AptosCoinInfoDtoInput = { + coinType: json.coin_type, + coinTypeHash: json.coin_type_hash, + creatorAddress: AptosAddress.fromJSON(json.creator_address), + decimals: json.decimals, + name: json.name, + supplyAggregatorTableHandle: json.supply_aggregator_table_handle, + supplyAggregatorTableKey: json.supply_aggregator_table_key, + symbol: json.symbol, + transactionCreatedTimestamp: json.transaction_created_timestamp, + transactionVersionCreated: json.transaction_version_created, + }; + return AptosCoinInfoDto.create(input); + } + + /** + * @description The definition of the coin structure (identifier) + */ + public readonly coinType: string; + /** + * @description The hash of the coin_type (identifier) and a known fixed length + */ + public readonly coinTypeHash: string; + /** + * @description The address of the creator of the coin + */ + public readonly creatorAddress: AptosAddress; + /** + * @description The number of decimals of the coin + */ + public readonly decimals: number; + /** + * @description The name of the Coin + */ + public readonly name: string; + /** + * @description The data structure of the token + */ + public readonly supplyAggregatorTableHandle: string; + /** + * @description The data structure of the token + */ + public readonly supplyAggregatorTableKey: string; + /** + * @description The symbol of the coin + */ + public readonly symbol: string; + /** + * @description The timestamp of the transaction of when the coin was created + */ + public readonly transactionCreatedTimestamp: string; + /** + * @description The version of the transaction where the coin was created + */ + public readonly transactionVersionCreated: string; + + private constructor(input: AptosCoinInfoDtoInput) { + this.coinType = input.coinType; + this.coinTypeHash = input.coinTypeHash; + this.creatorAddress = AptosAddress.create(input.creatorAddress); + this.decimals = input.decimals; + this.name = input.name; + this.supplyAggregatorTableHandle = input.supplyAggregatorTableHandle; + this.supplyAggregatorTableKey = input.supplyAggregatorTableKey; + this.symbol = input.symbol; + this.transactionCreatedTimestamp = input.transactionCreatedTimestamp; + this.transactionVersionCreated = input.transactionVersionCreated; + } + + public toJSON(): AptosCoinInfoDtoJSON { + return { + coin_type: this.coinType, + coin_type_hash: this.coinTypeHash, + creator_address: this.creatorAddress.toJSON(), + decimals: this.decimals, + name: this.name, + supply_aggregator_table_handle: this.supplyAggregatorTableHandle, + supply_aggregator_table_key: this.supplyAggregatorTableKey, + symbol: this.symbol, + transaction_created_timestamp: this.transactionCreatedTimestamp, + transaction_version_created: this.transactionVersionCreated, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosCoinTransferDto.ts b/packages/common/aptosUtils/src/generated/types/AptosCoinTransferDto.ts new file mode 100644 index 0000000000..1c14e3562b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosCoinTransferDto.ts @@ -0,0 +1,165 @@ +import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/CoinTransferDto +// type: CoinTransferDto +// properties: +// - activity_type ($ref: #/components/schemas/CoinTransferDto/properties/activity_type) +// - amount ($ref: #/components/schemas/CoinTransferDto/properties/amount) +// - block_height ($ref: #/components/schemas/CoinTransferDto/properties/block_height) +// - coin_type ($ref: #/components/schemas/CoinTransferDto/properties/coin_type) +// - entry_function_id_str ($ref: #/components/schemas/CoinTransferDto/properties/entry_function_id_str) +// - event_account_address ($ref: #/components/schemas/CoinTransferDto/properties/event_account_address) +// - event_creation_number ($ref: #/components/schemas/CoinTransferDto/properties/event_creation_number) +// - event_sequence_number ($ref: #/components/schemas/CoinTransferDto/properties/event_sequence_number) +// - is_gas_fee ($ref: #/components/schemas/CoinTransferDto/properties/is_gas_fee) +// - is_transaction_success ($ref: #/components/schemas/CoinTransferDto/properties/is_transaction_success) +// - owner_address ($ref: #/components/schemas/CoinTransferDto/properties/owner_address) +// - transaction_timestamp ($ref: #/components/schemas/CoinTransferDto/properties/transaction_timestamp) +// - transaction_version ($ref: #/components/schemas/CoinTransferDto/properties/transaction_version) + +export interface AptosCoinTransferDtoJSON { + readonly activity_type: string; + readonly amount: AptosNativeJSON; + readonly block_height: string; + readonly coin_type: string; + readonly entry_function_id_str: string; + readonly event_account_address: string; + readonly event_creation_number: string; + readonly event_sequence_number: string; + readonly is_gas_fee: boolean; + readonly is_transaction_success: boolean; + readonly owner_address: AptosAddressJSON; + readonly transaction_timestamp: string; + readonly transaction_version: string; +} + +export interface AptosCoinTransferDtoInput { + readonly activityType: string; + readonly amount: AptosNativeInput | AptosNative; + readonly blockHeight: string; + readonly coinType: string; + readonly entryFunctionIdStr: string; + readonly eventAccountAddress: string; + readonly eventCreationNumber: string; + readonly eventSequenceNumber: string; + readonly isGasFee: boolean; + readonly isTransactionSuccess: boolean; + readonly ownerAddress: AptosAddressInput | AptosAddress; + readonly transactionTimestamp: string; + readonly transactionVersion: string; +} + +export class AptosCoinTransferDto { + public static create(input: AptosCoinTransferDtoInput | AptosCoinTransferDto): AptosCoinTransferDto { + if (input instanceof AptosCoinTransferDto) { + return input; + } + return new AptosCoinTransferDto(input); + } + + public static fromJSON(json: AptosCoinTransferDtoJSON): AptosCoinTransferDto { + const input: AptosCoinTransferDtoInput = { + activityType: json.activity_type, + amount: AptosNative.fromJSON(json.amount), + blockHeight: json.block_height, + coinType: json.coin_type, + entryFunctionIdStr: json.entry_function_id_str, + eventAccountAddress: json.event_account_address, + eventCreationNumber: json.event_creation_number, + eventSequenceNumber: json.event_sequence_number, + isGasFee: json.is_gas_fee, + isTransactionSuccess: json.is_transaction_success, + ownerAddress: AptosAddress.fromJSON(json.owner_address), + transactionTimestamp: json.transaction_timestamp, + transactionVersion: json.transaction_version, + }; + return AptosCoinTransferDto.create(input); + } + + /** + * @description The definition of the coin activity + */ + public readonly activityType: string; + /** + * @description The amount being transfered + */ + public readonly amount: AptosNative; + /** + * @description The blockheight that the transfer was included in + */ + public readonly blockHeight: string; + /** + * @description The definition of the coin structure (identifier) + */ + public readonly coinType: string; + /** + * @description The function that was called to transfer the coin + */ + public readonly entryFunctionIdStr: string; + /** + * @description The address of the event account + */ + public readonly eventAccountAddress: string; + /** + * @description The event creation number + */ + public readonly eventCreationNumber: string; + /** + * @description The sequence number of the event + */ + public readonly eventSequenceNumber: string; + /** + * @description If the transfer was a gas fee or not + */ + public readonly isGasFee: boolean; + /** + * @description If the transfer was successful or not + */ + public readonly isTransactionSuccess: boolean; + /** + * @description The address of the owner of the coin + */ + public readonly ownerAddress: AptosAddress; + /** + * @description The timestamp of the transaction of when the coin was transfered + */ + public readonly transactionTimestamp: string; + /** + * @description The version of the transaction where the coin was transfered + */ + public readonly transactionVersion: string; + + private constructor(input: AptosCoinTransferDtoInput) { + this.activityType = input.activityType; + this.amount = AptosNative.create(input.amount); + this.blockHeight = input.blockHeight; + this.coinType = input.coinType; + this.entryFunctionIdStr = input.entryFunctionIdStr; + this.eventAccountAddress = input.eventAccountAddress; + this.eventCreationNumber = input.eventCreationNumber; + this.eventSequenceNumber = input.eventSequenceNumber; + this.isGasFee = input.isGasFee; + this.isTransactionSuccess = input.isTransactionSuccess; + this.ownerAddress = AptosAddress.create(input.ownerAddress); + this.transactionTimestamp = input.transactionTimestamp; + this.transactionVersion = input.transactionVersion; + } + + public toJSON(): AptosCoinTransferDtoJSON { + return { + activity_type: this.activityType, + amount: this.amount.toJSON(), + block_height: this.blockHeight, + coin_type: this.coinType, + entry_function_id_str: this.entryFunctionIdStr, + event_account_address: this.eventAccountAddress, + event_creation_number: this.eventCreationNumber, + event_sequence_number: this.eventSequenceNumber, + is_gas_fee: this.isGasFee, + is_transaction_success: this.isTransactionSuccess, + owner_address: this.ownerAddress.toJSON(), + transaction_timestamp: this.transactionTimestamp, + transaction_version: this.transactionVersion, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosCurrentCoinBalanceDto.ts b/packages/common/aptosUtils/src/generated/types/AptosCurrentCoinBalanceDto.ts new file mode 100644 index 0000000000..5bce0bd277 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosCurrentCoinBalanceDto.ts @@ -0,0 +1,95 @@ +import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/CurrentCoinBalanceDto +// type: CurrentCoinBalanceDto +// properties: +// - amount ($ref: #/components/schemas/CurrentCoinBalanceDto/properties/amount) +// - coin_type ($ref: #/components/schemas/CurrentCoinBalanceDto/properties/coin_type) +// - coin_type_hash ($ref: #/components/schemas/CurrentCoinBalanceDto/properties/coin_type_hash) +// - last_transaction_timestamp ($ref: #/components/schemas/CurrentCoinBalanceDto/properties/last_transaction_timestamp) +// - last_transaction_version ($ref: #/components/schemas/CurrentCoinBalanceDto/properties/last_transaction_version) +// - owner_address ($ref: #/components/schemas/CurrentCoinBalanceDto/properties/owner_address) + +export interface AptosCurrentCoinBalanceDtoJSON { + readonly amount: AptosNativeJSON; + readonly coin_type: string; + readonly coin_type_hash: string; + readonly last_transaction_timestamp: string; + readonly last_transaction_version: string; + readonly owner_address: AptosAddressJSON; +} + +export interface AptosCurrentCoinBalanceDtoInput { + readonly amount: AptosNativeInput | AptosNative; + readonly coinType: string; + readonly coinTypeHash: string; + readonly lastTransactionTimestamp: string; + readonly lastTransactionVersion: string; + readonly ownerAddress: AptosAddressInput | AptosAddress; +} + +export class AptosCurrentCoinBalanceDto { + public static create(input: AptosCurrentCoinBalanceDtoInput | AptosCurrentCoinBalanceDto): AptosCurrentCoinBalanceDto { + if (input instanceof AptosCurrentCoinBalanceDto) { + return input; + } + return new AptosCurrentCoinBalanceDto(input); + } + + public static fromJSON(json: AptosCurrentCoinBalanceDtoJSON): AptosCurrentCoinBalanceDto { + const input: AptosCurrentCoinBalanceDtoInput = { + amount: AptosNative.fromJSON(json.amount), + coinType: json.coin_type, + coinTypeHash: json.coin_type_hash, + lastTransactionTimestamp: json.last_transaction_timestamp, + lastTransactionVersion: json.last_transaction_version, + ownerAddress: AptosAddress.fromJSON(json.owner_address), + }; + return AptosCurrentCoinBalanceDto.create(input); + } + + /** + * @description The amount being transfered + */ + public readonly amount: AptosNative; + /** + * @description The definition of the coin structure (identifier) + */ + public readonly coinType: string; + /** + * @description The hash of the coin_type (identifier) and a known fixed length + */ + public readonly coinTypeHash: string; + /** + * @description The timestamp of the last update to the balance + */ + public readonly lastTransactionTimestamp: string; + /** + * @description The version of the transaction where the balance was last s + */ + public readonly lastTransactionVersion: string; + /** + * @description The address of the owner of the coin + */ + public readonly ownerAddress: AptosAddress; + + private constructor(input: AptosCurrentCoinBalanceDtoInput) { + this.amount = AptosNative.create(input.amount); + this.coinType = input.coinType; + this.coinTypeHash = input.coinTypeHash; + this.lastTransactionTimestamp = input.lastTransactionTimestamp; + this.lastTransactionVersion = input.lastTransactionVersion; + this.ownerAddress = AptosAddress.create(input.ownerAddress); + } + + public toJSON(): AptosCurrentCoinBalanceDtoJSON { + return { + amount: this.amount.toJSON(), + coin_type: this.coinType, + coin_type_hash: this.coinTypeHash, + last_transaction_timestamp: this.lastTransactionTimestamp, + last_transaction_version: this.lastTransactionVersion, + owner_address: this.ownerAddress.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDecodedTableData.ts b/packages/common/aptosUtils/src/generated/types/AptosDecodedTableData.ts new file mode 100644 index 0000000000..75d24e9669 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDecodedTableData.ts @@ -0,0 +1,73 @@ +// $ref: #/components/schemas/DecodedTableData +// type: DecodedTableData +// properties: +// - key ($ref: #/components/schemas/DecodedTableData/properties/key) +// - key_type ($ref: #/components/schemas/DecodedTableData/properties/key_type) +// - value ($ref: #/components/schemas/DecodedTableData/properties/value) +// - value_type ($ref: #/components/schemas/DecodedTableData/properties/value_type) + +export interface AptosDecodedTableDataJSON { + readonly key: string; + readonly key_type: string; + readonly value: string; + readonly value_type: string; +} + +export interface AptosDecodedTableDataInput { + readonly key: string; + readonly keyType: string; + readonly value: string; + readonly valueType: string; +} + +export class AptosDecodedTableData { + public static create(input: AptosDecodedTableDataInput | AptosDecodedTableData): AptosDecodedTableData { + if (input instanceof AptosDecodedTableData) { + return input; + } + return new AptosDecodedTableData(input); + } + + public static fromJSON(json: AptosDecodedTableDataJSON): AptosDecodedTableData { + const input: AptosDecodedTableDataInput = { + key: json.key, + keyType: json.key_type, + value: json.value, + valueType: json.value_type, + }; + return AptosDecodedTableData.create(input); + } + + /** + * @description Key of table in JSON + */ + public readonly key: string; + /** + * @description Type of key + */ + public readonly keyType: string; + /** + * @description Value of table in JSON + */ + public readonly value: string; + /** + * @description Type of value + */ + public readonly valueType: string; + + private constructor(input: AptosDecodedTableDataInput) { + this.key = input.key; + this.keyType = input.keyType; + this.value = input.value; + this.valueType = input.valueType; + } + + public toJSON(): AptosDecodedTableDataJSON { + return { + key: this.key, + key_type: this.keyType, + value: this.value, + value_type: this.valueType, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteModuleChange.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteModuleChange.ts new file mode 100644 index 0000000000..84cbd1bc8b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteModuleChange.ts @@ -0,0 +1,81 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosDeleteModuleChangeModule, AptosDeleteModuleChangeModuleValue, AptosDeleteModuleChangeModuleInput, AptosDeleteModuleChangeModuleJSON } from '../types/AptosDeleteModuleChangeModule'; + +// $ref: #/components/schemas/DeleteModuleChange +// type: DeleteModuleChange +// properties: +// - type ($ref: #/components/schemas/DeleteModuleChange/properties/type) +// - address ($ref: #/components/schemas/DeleteModuleChange/properties/address) +// - state_key_hash ($ref: #/components/schemas/DeleteModuleChange/properties/state_key_hash) +// - module ($ref: #/components/schemas/DeleteModuleChange/properties/module) + +export interface AptosDeleteModuleChangeJSON { + readonly type: string; + readonly address: AptosAddressJSON; + readonly state_key_hash: string; + readonly module: AptosDeleteModuleChangeModuleJSON; +} + +export interface AptosDeleteModuleChangeInput { + readonly type: string; + readonly address: AptosAddressInput | AptosAddress; + readonly stateKeyHash: string; + readonly module: AptosDeleteModuleChangeModuleInput | AptosDeleteModuleChangeModuleValue; +} + +export class AptosDeleteModuleChange { + public static create(input: AptosDeleteModuleChangeInput | AptosDeleteModuleChange): AptosDeleteModuleChange { + if (input instanceof AptosDeleteModuleChange) { + return input; + } + return new AptosDeleteModuleChange(input); + } + + public static fromJSON(json: AptosDeleteModuleChangeJSON): AptosDeleteModuleChange { + const input: AptosDeleteModuleChangeInput = { + type: json.type, + address: AptosAddress.fromJSON(json.address), + stateKeyHash: json.state_key_hash, + module: AptosDeleteModuleChangeModule.fromJSON(json.module), + }; + return AptosDeleteModuleChange.create(input); + } + + public static isInput(input: any): input is AptosDeleteModuleChangeInput { + return input.type === 'delete_module'; + } + + public static isJSON(json: any): json is AptosDeleteModuleChangeJSON { + return json.type === 'delete_module'; + } + + public readonly type: string; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly address: AptosAddress; + /** + * @description State key hash + */ + public readonly stateKeyHash: string; + /** + * @description Move module id is a string representation of Move module + */ + public readonly module: AptosDeleteModuleChangeModuleValue; + + private constructor(input: AptosDeleteModuleChangeInput) { + this.type = input.type; + this.address = AptosAddress.create(input.address); + this.stateKeyHash = input.stateKeyHash; + this.module = AptosDeleteModuleChangeModule.create(input.module); + } + + public toJSON(): AptosDeleteModuleChangeJSON { + return { + type: this.type, + address: this.address.toJSON(), + state_key_hash: this.stateKeyHash, + module: this.module, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteModuleChangeModule.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteModuleChangeModule.ts new file mode 100644 index 0000000000..8cd9f177ee --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteModuleChangeModule.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/DeleteModuleChange/properties/module +// typeName: DeleteModuleChange_module + +export type AptosDeleteModuleChangeModuleJSON = object; +export type AptosDeleteModuleChangeModuleInput = object; +export type AptosDeleteModuleChangeModuleValue = object; + +export abstract class AptosDeleteModuleChangeModule { + public static create(input: AptosDeleteModuleChangeModuleInput | AptosDeleteModuleChangeModuleValue): AptosDeleteModuleChangeModuleValue { + return input; + } + + public static fromJSON(json: AptosDeleteModuleChangeModuleJSON): AptosDeleteModuleChangeModuleValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteResourceChange.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteResourceChange.ts new file mode 100644 index 0000000000..5c4b9ce4b8 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteResourceChange.ts @@ -0,0 +1,81 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosDeleteResourceChangeResource, AptosDeleteResourceChangeResourceValue, AptosDeleteResourceChangeResourceInput, AptosDeleteResourceChangeResourceJSON } from '../types/AptosDeleteResourceChangeResource'; + +// $ref: #/components/schemas/DeleteResourceChange +// type: DeleteResourceChange +// properties: +// - type ($ref: #/components/schemas/DeleteResourceChange/properties/type) +// - address ($ref: #/components/schemas/DeleteResourceChange/properties/address) +// - state_key_hash ($ref: #/components/schemas/DeleteResourceChange/properties/state_key_hash) +// - resource ($ref: #/components/schemas/DeleteResourceChange/properties/resource) + +export interface AptosDeleteResourceChangeJSON { + readonly type: string; + readonly address: AptosAddressJSON; + readonly state_key_hash: string; + readonly resource: AptosDeleteResourceChangeResourceJSON; +} + +export interface AptosDeleteResourceChangeInput { + readonly type: string; + readonly address: AptosAddressInput | AptosAddress; + readonly stateKeyHash: string; + readonly resource: AptosDeleteResourceChangeResourceInput | AptosDeleteResourceChangeResourceValue; +} + +export class AptosDeleteResourceChange { + public static create(input: AptosDeleteResourceChangeInput | AptosDeleteResourceChange): AptosDeleteResourceChange { + if (input instanceof AptosDeleteResourceChange) { + return input; + } + return new AptosDeleteResourceChange(input); + } + + public static fromJSON(json: AptosDeleteResourceChangeJSON): AptosDeleteResourceChange { + const input: AptosDeleteResourceChangeInput = { + type: json.type, + address: AptosAddress.fromJSON(json.address), + stateKeyHash: json.state_key_hash, + resource: AptosDeleteResourceChangeResource.fromJSON(json.resource), + }; + return AptosDeleteResourceChange.create(input); + } + + public static isInput(input: any): input is AptosDeleteResourceChangeInput { + return input.type === 'delete_resource'; + } + + public static isJSON(json: any): json is AptosDeleteResourceChangeJSON { + return json.type === 'delete_resource'; + } + + public readonly type: string; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly address: AptosAddress; + /** + * @description State key hash + */ + public readonly stateKeyHash: string; + /** + * @description String representation of a MoveStructTag (on-chain Move struct type). + */ + public readonly resource: AptosDeleteResourceChangeResourceValue; + + private constructor(input: AptosDeleteResourceChangeInput) { + this.type = input.type; + this.address = AptosAddress.create(input.address); + this.stateKeyHash = input.stateKeyHash; + this.resource = AptosDeleteResourceChangeResource.create(input.resource); + } + + public toJSON(): AptosDeleteResourceChangeJSON { + return { + type: this.type, + address: this.address.toJSON(), + state_key_hash: this.stateKeyHash, + resource: this.resource, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteResourceChangeResource.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteResourceChangeResource.ts new file mode 100644 index 0000000000..3cd42eb438 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteResourceChangeResource.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/DeleteResourceChange/properties/resource +// typeName: DeleteResourceChange_resource + +export type AptosDeleteResourceChangeResourceJSON = object; +export type AptosDeleteResourceChangeResourceInput = object; +export type AptosDeleteResourceChangeResourceValue = object; + +export abstract class AptosDeleteResourceChangeResource { + public static create(input: AptosDeleteResourceChangeResourceInput | AptosDeleteResourceChangeResourceValue): AptosDeleteResourceChangeResourceValue { + return input; + } + + public static fromJSON(json: AptosDeleteResourceChangeResourceJSON): AptosDeleteResourceChangeResourceValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChange.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChange.ts new file mode 100644 index 0000000000..6e93fe88ad --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChange.ts @@ -0,0 +1,92 @@ +import { AptosDeleteTableItemChangeHandle, AptosDeleteTableItemChangeHandleValue, AptosDeleteTableItemChangeHandleInput, AptosDeleteTableItemChangeHandleJSON } from '../types/AptosDeleteTableItemChangeHandle'; +import { AptosDeleteTableItemChangeKey, AptosDeleteTableItemChangeKeyValue, AptosDeleteTableItemChangeKeyInput, AptosDeleteTableItemChangeKeyJSON } from '../types/AptosDeleteTableItemChangeKey'; +import { AptosDeletedTableData, AptosDeletedTableDataInput, AptosDeletedTableDataJSON } from '../types/AptosDeletedTableData'; + +// $ref: #/components/schemas/DeleteTableItemChange +// type: DeleteTableItemChange +// properties: +// - type ($ref: #/components/schemas/DeleteTableItemChange/properties/type) +// - state_key_hash ($ref: #/components/schemas/DeleteTableItemChange/properties/state_key_hash) +// - handle ($ref: #/components/schemas/DeleteTableItemChange/properties/handle) +// - key ($ref: #/components/schemas/DeleteTableItemChange/properties/key) +// - data ($ref: #/components/schemas/DeletedTableData) + +export interface AptosDeleteTableItemChangeJSON { + readonly type: string; + readonly state_key_hash: string; + readonly handle: AptosDeleteTableItemChangeHandleJSON; + readonly key: AptosDeleteTableItemChangeKeyJSON; + readonly data: AptosDeletedTableDataJSON; +} + +export interface AptosDeleteTableItemChangeInput { + readonly type: string; + readonly stateKeyHash: string; + readonly handle: AptosDeleteTableItemChangeHandleInput | AptosDeleteTableItemChangeHandleValue; + readonly key: AptosDeleteTableItemChangeKeyInput | AptosDeleteTableItemChangeKeyValue; + readonly data: AptosDeletedTableDataInput | AptosDeletedTableData; +} + +export class AptosDeleteTableItemChange { + public static create(input: AptosDeleteTableItemChangeInput | AptosDeleteTableItemChange): AptosDeleteTableItemChange { + if (input instanceof AptosDeleteTableItemChange) { + return input; + } + return new AptosDeleteTableItemChange(input); + } + + public static fromJSON(json: AptosDeleteTableItemChangeJSON): AptosDeleteTableItemChange { + const input: AptosDeleteTableItemChangeInput = { + type: json.type, + stateKeyHash: json.state_key_hash, + handle: AptosDeleteTableItemChangeHandle.fromJSON(json.handle), + key: AptosDeleteTableItemChangeKey.fromJSON(json.key), + data: AptosDeletedTableData.fromJSON(json.data), + }; + return AptosDeleteTableItemChange.create(input); + } + + public static isInput(input: any): input is AptosDeleteTableItemChangeInput { + return input.type === 'delete_table_item'; + } + + public static isJSON(json: any): json is AptosDeleteTableItemChangeJSON { + return json.type === 'delete_table_item'; + } + + public readonly type: string; + /** + * @description State key hash + */ + public readonly stateKeyHash: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly handle: AptosDeleteTableItemChangeHandleValue; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly key: AptosDeleteTableItemChangeKeyValue; + /** + * @description Deleted table data + */ + public readonly data: AptosDeletedTableData; + + private constructor(input: AptosDeleteTableItemChangeInput) { + this.type = input.type; + this.stateKeyHash = input.stateKeyHash; + this.handle = AptosDeleteTableItemChangeHandle.create(input.handle); + this.key = AptosDeleteTableItemChangeKey.create(input.key); + this.data = AptosDeletedTableData.create(input.data); + } + + public toJSON(): AptosDeleteTableItemChangeJSON { + return { + type: this.type, + state_key_hash: this.stateKeyHash, + handle: this.handle, + key: this.key, + data: this.data.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChangeHandle.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChangeHandle.ts new file mode 100644 index 0000000000..b6ac66a2f8 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChangeHandle.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/DeleteTableItemChange/properties/handle +// typeName: DeleteTableItemChange_handle + +export type AptosDeleteTableItemChangeHandleJSON = object; +export type AptosDeleteTableItemChangeHandleInput = object; +export type AptosDeleteTableItemChangeHandleValue = object; + +export abstract class AptosDeleteTableItemChangeHandle { + public static create(input: AptosDeleteTableItemChangeHandleInput | AptosDeleteTableItemChangeHandleValue): AptosDeleteTableItemChangeHandleValue { + return input; + } + + public static fromJSON(json: AptosDeleteTableItemChangeHandleJSON): AptosDeleteTableItemChangeHandleValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChangeKey.ts b/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChangeKey.ts new file mode 100644 index 0000000000..40e3efbf3b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeleteTableItemChangeKey.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/DeleteTableItemChange/properties/key +// typeName: DeleteTableItemChange_key + +export type AptosDeleteTableItemChangeKeyJSON = object; +export type AptosDeleteTableItemChangeKeyInput = object; +export type AptosDeleteTableItemChangeKeyValue = object; + +export abstract class AptosDeleteTableItemChangeKey { + public static create(input: AptosDeleteTableItemChangeKeyInput | AptosDeleteTableItemChangeKeyValue): AptosDeleteTableItemChangeKeyValue { + return input; + } + + public static fromJSON(json: AptosDeleteTableItemChangeKeyJSON): AptosDeleteTableItemChangeKeyValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDeletedTableData.ts b/packages/common/aptosUtils/src/generated/types/AptosDeletedTableData.ts new file mode 100644 index 0000000000..6277e8c79f --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDeletedTableData.ts @@ -0,0 +1,53 @@ +// $ref: #/components/schemas/DeletedTableData +// type: DeletedTableData +// properties: +// - key ($ref: #/components/schemas/DeletedTableData/properties/key) +// - key_type ($ref: #/components/schemas/DeletedTableData/properties/key_type) + +export interface AptosDeletedTableDataJSON { + readonly key: string; + readonly key_type: string; +} + +export interface AptosDeletedTableDataInput { + readonly key: string; + readonly keyType: string; +} + +export class AptosDeletedTableData { + public static create(input: AptosDeletedTableDataInput | AptosDeletedTableData): AptosDeletedTableData { + if (input instanceof AptosDeletedTableData) { + return input; + } + return new AptosDeletedTableData(input); + } + + public static fromJSON(json: AptosDeletedTableDataJSON): AptosDeletedTableData { + const input: AptosDeletedTableDataInput = { + key: json.key, + keyType: json.key_type, + }; + return AptosDeletedTableData.create(input); + } + + /** + * @description Deleted key + */ + public readonly key: string; + /** + * @description Deleted key type + */ + public readonly keyType: string; + + private constructor(input: AptosDeletedTableDataInput) { + this.key = input.key; + this.keyType = input.keyType; + } + + public toJSON(): AptosDeletedTableDataJSON { + return { + key: this.key, + key_type: this.keyType, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosDirectWriteSet.ts b/packages/common/aptosUtils/src/generated/types/AptosDirectWriteSet.ts new file mode 100644 index 0000000000..eeb4f7d0ce --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosDirectWriteSet.ts @@ -0,0 +1,67 @@ +import { AptosTransactionEvent, AptosTransactionEventInput, AptosTransactionEventJSON } from '../types/AptosTransactionEvent'; + +// $ref: #/components/schemas/DirectWriteSet +// type: DirectWriteSet +// properties: +// - type ($ref: #/components/schemas/DirectWriteSet/properties/type) +// - changes ($ref: #/components/schemas/DirectWriteSet/properties/changes) +// - events ($ref: #/components/schemas/TransactionEvent) + +export interface AptosDirectWriteSetJSON { + readonly type: string; + readonly changes: string[]; + readonly events: AptosTransactionEventJSON[]; +} + +export interface AptosDirectWriteSetInput { + readonly type: string; + readonly changes: string[]; + readonly events: AptosTransactionEventInput[] | AptosTransactionEvent[]; +} + +export class AptosDirectWriteSet { + public static create(input: AptosDirectWriteSetInput | AptosDirectWriteSet): AptosDirectWriteSet { + if (input instanceof AptosDirectWriteSet) { + return input; + } + return new AptosDirectWriteSet(input); + } + + public static fromJSON(json: AptosDirectWriteSetJSON): AptosDirectWriteSet { + const input: AptosDirectWriteSetInput = { + type: json.type, + changes: json.changes, + events: json.events.map((item) => AptosTransactionEvent.fromJSON(item)), + }; + return AptosDirectWriteSet.create(input); + } + + public static isInput(input: any): input is AptosDirectWriteSetInput { + return input.type === 'direct_write_set'; + } + + public static isJSON(json: any): json is AptosDirectWriteSetJSON { + return json.type === 'direct_write_set'; + } + + public readonly type: string; + public readonly changes: string[]; + /** + * @description Events emitted during genesis + */ + public readonly events: AptosTransactionEvent[]; + + private constructor(input: AptosDirectWriteSetInput) { + this.type = input.type; + this.changes = input.changes; + this.events = input.events.map((item) => AptosTransactionEvent.create(item)); + } + + public toJSON(): AptosDirectWriteSetJSON { + return { + type: this.type, + changes: this.changes, + events: this.events.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosEd25519SignatureRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosEd25519SignatureRequest.ts new file mode 100644 index 0000000000..7e2694a536 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosEd25519SignatureRequest.ts @@ -0,0 +1,68 @@ +// $ref: #/components/schemas/Ed25519SignatureRequest +// type: Ed25519SignatureRequest +// properties: +// - type ($ref: #/components/schemas/Ed25519SignatureRequest/properties/type) +// - signature ($ref: #/components/schemas/Ed25519SignatureRequest/properties/signature) +// - public_key ($ref: #/components/schemas/Ed25519SignatureRequest/properties/public_key) + +export interface AptosEd25519SignatureRequestJSON { + readonly type: string; + readonly signature: string; + readonly public_key: string; +} + +export interface AptosEd25519SignatureRequestInput { + readonly type: string; + readonly signature: string; + readonly publicKey: string; +} + +export class AptosEd25519SignatureRequest { + public static create(input: AptosEd25519SignatureRequestInput | AptosEd25519SignatureRequest): AptosEd25519SignatureRequest { + if (input instanceof AptosEd25519SignatureRequest) { + return input; + } + return new AptosEd25519SignatureRequest(input); + } + + public static fromJSON(json: AptosEd25519SignatureRequestJSON): AptosEd25519SignatureRequest { + const input: AptosEd25519SignatureRequestInput = { + type: json.type, + signature: json.signature, + publicKey: json.public_key, + }; + return AptosEd25519SignatureRequest.create(input); + } + + public static isInput(input: any): input is AptosEd25519SignatureRequestInput { + return ["type","signature","publicKey"].every((name) => input[name] !== undefined); + } + + public static isJSON(json: any): json is AptosEd25519SignatureRequestJSON { + return ["type","signature","public_key"].every((name) => json[name] !== undefined); + } + + public readonly type: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte + */ + public readonly signature: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly publicKey: string; + + private constructor(input: AptosEd25519SignatureRequestInput) { + this.type = input.type; + this.signature = input.signature; + this.publicKey = input.publicKey; + } + + public toJSON(): AptosEd25519SignatureRequestJSON { + return { + type: this.type, + signature: this.signature, + public_key: this.publicKey, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosEncodeSubmissionRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosEncodeSubmissionRequest.ts new file mode 100644 index 0000000000..4302b349aa --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosEncodeSubmissionRequest.ts @@ -0,0 +1,106 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosEncodeSubmissionRequestPayload, AptosEncodeSubmissionRequestPayloadValue, AptosEncodeSubmissionRequestPayloadInput, AptosEncodeSubmissionRequestPayloadJSON } from '../types/AptosEncodeSubmissionRequestPayload'; + +// $ref: #/components/schemas/EncodeSubmissionRequest +// type: EncodeSubmissionRequest +// properties: +// - sender ($ref: #/components/schemas/EncodeSubmissionRequest/properties/sender) +// - sequence_number ($ref: #/components/schemas/EncodeSubmissionRequest/properties/sequence_number) +// - max_gas_amount ($ref: #/components/schemas/EncodeSubmissionRequest/properties/max_gas_amount) +// - gas_unit_price ($ref: #/components/schemas/EncodeSubmissionRequest/properties/gas_unit_price) +// - expiration_timestamp_secs ($ref: #/components/schemas/EncodeSubmissionRequest/properties/expiration_timestamp_secs) +// - payload ($ref: #/components/schemas/EncodeSubmissionRequest/properties/payload) +// - secondary_signers ($ref: #/components/schemas/EncodeSubmissionRequest/properties/secondary_signers) + +export interface AptosEncodeSubmissionRequestJSON { + readonly sender: AptosAddressJSON; + readonly sequence_number: string; + readonly max_gas_amount: string; + readonly gas_unit_price: string; + readonly expiration_timestamp_secs: string; + readonly payload: AptosEncodeSubmissionRequestPayloadJSON; + readonly secondary_signers: string[]; +} + +export interface AptosEncodeSubmissionRequestInput { + readonly sender: AptosAddressInput | AptosAddress; + readonly sequenceNumber: string; + readonly maxGasAmount: string; + readonly gasUnitPrice: string; + readonly expirationTimestampSecs: string; + readonly payload: AptosEncodeSubmissionRequestPayloadInput | AptosEncodeSubmissionRequestPayloadValue; + readonly secondarySigners: string[]; +} + +export class AptosEncodeSubmissionRequest { + public static create(input: AptosEncodeSubmissionRequestInput | AptosEncodeSubmissionRequest): AptosEncodeSubmissionRequest { + if (input instanceof AptosEncodeSubmissionRequest) { + return input; + } + return new AptosEncodeSubmissionRequest(input); + } + + public static fromJSON(json: AptosEncodeSubmissionRequestJSON): AptosEncodeSubmissionRequest { + const input: AptosEncodeSubmissionRequestInput = { + sender: AptosAddress.fromJSON(json.sender), + sequenceNumber: json.sequence_number, + maxGasAmount: json.max_gas_amount, + gasUnitPrice: json.gas_unit_price, + expirationTimestampSecs: json.expiration_timestamp_secs, + payload: AptosEncodeSubmissionRequestPayload.fromJSON(json.payload), + secondarySigners: json.secondary_signers, + }; + return AptosEncodeSubmissionRequest.create(input); + } + + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly sender: AptosAddress; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly sequenceNumber: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly maxGasAmount: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUnitPrice: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly expirationTimestampSecs: string; + /** + * @description An enum of the possible transaction payloads + */ + public readonly payload: AptosEncodeSubmissionRequestPayloadValue; + /** + * @description Secondary signer accounts of the request for Multi-agent + */ + public readonly secondarySigners: string[]; + + private constructor(input: AptosEncodeSubmissionRequestInput) { + this.sender = AptosAddress.create(input.sender); + this.sequenceNumber = input.sequenceNumber; + this.maxGasAmount = input.maxGasAmount; + this.gasUnitPrice = input.gasUnitPrice; + this.expirationTimestampSecs = input.expirationTimestampSecs; + this.payload = AptosEncodeSubmissionRequestPayload.create(input.payload); + this.secondarySigners = input.secondarySigners; + } + + public toJSON(): AptosEncodeSubmissionRequestJSON { + return { + sender: this.sender.toJSON(), + sequence_number: this.sequenceNumber, + max_gas_amount: this.maxGasAmount, + gas_unit_price: this.gasUnitPrice, + expiration_timestamp_secs: this.expirationTimestampSecs, + payload: this.payload.toJSON(), + secondary_signers: this.secondarySigners, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosEncodeSubmissionRequestPayload.ts b/packages/common/aptosUtils/src/generated/types/AptosEncodeSubmissionRequestPayload.ts new file mode 100644 index 0000000000..7aa2e0c29a --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosEncodeSubmissionRequestPayload.ts @@ -0,0 +1,41 @@ +import { AptosEntryFunctionPayloadRequest, AptosEntryFunctionPayloadRequestJSON, AptosEntryFunctionPayloadRequestInput } from '../types/AptosEntryFunctionPayloadRequest'; +import { AptosScriptPayloadRequest, AptosScriptPayloadRequestJSON, AptosScriptPayloadRequestInput } from '../types/AptosScriptPayloadRequest'; +import { AptosModuleBundlePayloadRequest, AptosModuleBundlePayloadRequestJSON, AptosModuleBundlePayloadRequestInput } from '../types/AptosModuleBundlePayloadRequest'; + +// $ref: #/components/schemas/EncodeSubmissionRequest/properties/payload +// typeName: EncodeSubmissionRequest_payload +// unionType: oneOf + +export type AptosEncodeSubmissionRequestPayloadJSON = AptosEntryFunctionPayloadRequestJSON | AptosScriptPayloadRequestJSON | AptosModuleBundlePayloadRequestJSON; +export type AptosEncodeSubmissionRequestPayloadInput = AptosEntryFunctionPayloadRequestInput | AptosScriptPayloadRequestInput | AptosModuleBundlePayloadRequestInput; +export type AptosEncodeSubmissionRequestPayloadValue = AptosEntryFunctionPayloadRequest | AptosScriptPayloadRequest | AptosModuleBundlePayloadRequest; + +export abstract class AptosEncodeSubmissionRequestPayload { + public static create(input: AptosEncodeSubmissionRequestPayloadInput): AptosEncodeSubmissionRequestPayloadValue { + if (AptosEntryFunctionPayloadRequest.isInput(input)) { + return AptosEntryFunctionPayloadRequest.create(input); + } + if (AptosScriptPayloadRequest.isInput(input)) { + return AptosScriptPayloadRequest.create(input); + } + if (AptosModuleBundlePayloadRequest.isInput(input)) { + return AptosModuleBundlePayloadRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosEncodeSubmissionRequestPayloadJSON): AptosEncodeSubmissionRequestPayloadValue { + if (AptosEntryFunctionPayloadRequest.isJSON(json)) { + return AptosEntryFunctionPayloadRequest.fromJSON(json); + } + if (AptosScriptPayloadRequest.isJSON(json)) { + return AptosScriptPayloadRequest.fromJSON(json); + } + if (AptosModuleBundlePayloadRequest.isJSON(json)) { + return AptosModuleBundlePayloadRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosEncodeSubmissionRequestPayload (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosEntryFunctionPayloadRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosEntryFunctionPayloadRequest.ts new file mode 100644 index 0000000000..84f22676b9 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosEntryFunctionPayloadRequest.ts @@ -0,0 +1,78 @@ +// $ref: #/components/schemas/EntryFunctionPayloadRequest +// type: EntryFunctionPayloadRequest +// properties: +// - type ($ref: #/components/schemas/EntryFunctionPayloadRequest/properties/type) +// - function ($ref: #/components/schemas/EntryFunctionPayloadRequest/properties/function) +// - type_arguments ($ref: #/components/schemas/EntryFunctionPayloadRequest/properties/type_arguments) +// - arguments ($ref: #/components/schemas/EntryFunctionPayloadRequest/properties/arguments) + +export interface AptosEntryFunctionPayloadRequestJSON { + readonly type: string; + readonly function: string; + readonly type_arguments: string[]; + readonly arguments: string[]; +} + +export interface AptosEntryFunctionPayloadRequestInput { + readonly type: string; + readonly function: string; + readonly typeArguments: string[]; + readonly arguments: string[]; +} + +export class AptosEntryFunctionPayloadRequest { + public static create(input: AptosEntryFunctionPayloadRequestInput | AptosEntryFunctionPayloadRequest): AptosEntryFunctionPayloadRequest { + if (input instanceof AptosEntryFunctionPayloadRequest) { + return input; + } + return new AptosEntryFunctionPayloadRequest(input); + } + + public static fromJSON(json: AptosEntryFunctionPayloadRequestJSON): AptosEntryFunctionPayloadRequest { + const input: AptosEntryFunctionPayloadRequestInput = { + type: json.type, + function: json.function, + typeArguments: json.type_arguments, + arguments: json.arguments, + }; + return AptosEntryFunctionPayloadRequest.create(input); + } + + public static isInput(input: any): input is AptosEntryFunctionPayloadRequestInput { + return ["type","function","typeArguments","arguments"].every((name) => input[name] !== undefined); + } + + public static isJSON(json: any): json is AptosEntryFunctionPayloadRequestJSON { + return ["type","function","type_arguments","arguments"].every((name) => json[name] !== undefined); + } + + public readonly type: string; + /** + * @description Entry function id is string representation of a entry function defined on-chain. + */ + public readonly function: string; + /** + * @description Type arguments of the function + */ + public readonly typeArguments: string[]; + /** + * @description Arguments of the function + */ + public readonly arguments: string[]; + + private constructor(input: AptosEntryFunctionPayloadRequestInput) { + this.type = input.type; + this.function = input.function; + this.typeArguments = input.typeArguments; + this.arguments = input.arguments; + } + + public toJSON(): AptosEntryFunctionPayloadRequestJSON { + return { + type: this.type, + function: this.function, + type_arguments: this.typeArguments, + arguments: this.arguments, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosEstimateGasPriceResult.ts b/packages/common/aptosUtils/src/generated/types/AptosEstimateGasPriceResult.ts new file mode 100644 index 0000000000..ff2e196f5c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosEstimateGasPriceResult.ts @@ -0,0 +1,63 @@ +// $ref: #/components/schemas/EstimateGasPriceResult +// type: EstimateGasPriceResult +// properties: +// - deprioritized_gas_estimate ($ref: #/components/schemas/EstimateGasPriceResult/properties/deprioritized_gas_estimate) +// - gas_estimate ($ref: #/components/schemas/EstimateGasPriceResult/properties/gas_estimate) +// - prioritized_gas_estimate ($ref: #/components/schemas/EstimateGasPriceResult/properties/prioritized_gas_estimate) + +export interface AptosEstimateGasPriceResultJSON { + readonly deprioritized_gas_estimate: number; + readonly gas_estimate: number; + readonly prioritized_gas_estimate: number; +} + +export interface AptosEstimateGasPriceResultInput { + readonly deprioritizedGasEstimate: number; + readonly gasEstimate: number; + readonly prioritizedGasEstimate: number; +} + +export class AptosEstimateGasPriceResult { + public static create(input: AptosEstimateGasPriceResultInput | AptosEstimateGasPriceResult): AptosEstimateGasPriceResult { + if (input instanceof AptosEstimateGasPriceResult) { + return input; + } + return new AptosEstimateGasPriceResult(input); + } + + public static fromJSON(json: AptosEstimateGasPriceResultJSON): AptosEstimateGasPriceResult { + const input: AptosEstimateGasPriceResultInput = { + deprioritizedGasEstimate: json.deprioritized_gas_estimate, + gasEstimate: json.gas_estimate, + prioritizedGasEstimate: json.prioritized_gas_estimate, + }; + return AptosEstimateGasPriceResult.create(input); + } + + /** + * @description The deprioritized estimate for the gas unit price + */ + public readonly deprioritizedGasEstimate: number; + /** + * @description The current estimate for the gas unit price + */ + public readonly gasEstimate: number; + /** + * @description The prioritized estimate for the gas unit price + */ + public readonly prioritizedGasEstimate: number; + + private constructor(input: AptosEstimateGasPriceResultInput) { + this.deprioritizedGasEstimate = input.deprioritizedGasEstimate; + this.gasEstimate = input.gasEstimate; + this.prioritizedGasEstimate = input.prioritizedGasEstimate; + } + + public toJSON(): AptosEstimateGasPriceResultJSON { + return { + deprioritized_gas_estimate: this.deprioritizedGasEstimate, + gas_estimate: this.gasEstimate, + prioritized_gas_estimate: this.prioritizedGasEstimate, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGenericTypeParam.ts b/packages/common/aptosUtils/src/generated/types/AptosGenericTypeParam.ts new file mode 100644 index 0000000000..7f3f970bdd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGenericTypeParam.ts @@ -0,0 +1,43 @@ +// $ref: #/components/schemas/GenericTypeParam +// type: GenericTypeParam +// properties: +// - constraints ($ref: #/components/schemas/GenericTypeParam/properties/constraints) + +export interface AptosGenericTypeParamJSON { + readonly constraints: string[]; +} + +export interface AptosGenericTypeParamInput { + readonly constraints: string[]; +} + +export class AptosGenericTypeParam { + public static create(input: AptosGenericTypeParamInput | AptosGenericTypeParam): AptosGenericTypeParam { + if (input instanceof AptosGenericTypeParam) { + return input; + } + return new AptosGenericTypeParam(input); + } + + public static fromJSON(json: AptosGenericTypeParamJSON): AptosGenericTypeParam { + const input: AptosGenericTypeParamInput = { + constraints: json.constraints, + }; + return AptosGenericTypeParam.create(input); + } + + /** + * @description Move abilities tied to the generic type param and associated with the function that uses it + */ + public readonly constraints: string[]; + + private constructor(input: AptosGenericTypeParamInput) { + this.constraints = input.constraints; + } + + public toJSON(): AptosGenericTypeParamJSON { + return { + constraints: this.constraints, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGenesisTransaction.ts b/packages/common/aptosUtils/src/generated/types/AptosGenesisTransaction.ts new file mode 100644 index 0000000000..606a6682b1 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGenesisTransaction.ts @@ -0,0 +1,154 @@ +import { AptosGenesisTransactionChangesItem, AptosGenesisTransactionChangesItemValue, AptosGenesisTransactionChangesItemInput, AptosGenesisTransactionChangesItemJSON } from '../types/AptosGenesisTransactionChangesItem'; +import { AptosWriteSetPayload, AptosWriteSetPayloadInput, AptosWriteSetPayloadJSON } from '../types/AptosWriteSetPayload'; +import { AptosTransactionEvent, AptosTransactionEventInput, AptosTransactionEventJSON } from '../types/AptosTransactionEvent'; + +// $ref: #/components/schemas/GenesisTransaction +// type: GenesisTransaction +// properties: +// - type ($ref: #/components/schemas/GenesisTransaction/properties/type) +// - version ($ref: #/components/schemas/GenesisTransaction/properties/version) +// - hash ($ref: #/components/schemas/GenesisTransaction/properties/hash) +// - state_change_hash ($ref: #/components/schemas/GenesisTransaction/properties/state_change_hash) +// - event_root_hash ($ref: #/components/schemas/GenesisTransaction/properties/event_root_hash) +// - state_checkpoint_hash ($ref: #/components/schemas/GenesisTransaction/properties/state_checkpoint_hash) +// - gas_used ($ref: #/components/schemas/GenesisTransaction/properties/gas_used) +// - success ($ref: #/components/schemas/GenesisTransaction/properties/success) +// - vm_status ($ref: #/components/schemas/GenesisTransaction/properties/vm_status) +// - accumulator_root_hash ($ref: #/components/schemas/GenesisTransaction/properties/accumulator_root_hash) +// - changes ($ref: #/components/schemas/GenesisTransaction/properties/changes/items) +// - payload ($ref: #/components/schemas/WriteSetPayload) +// - events ($ref: #/components/schemas/TransactionEvent) + +export interface AptosGenesisTransactionJSON { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly state_change_hash: string; + readonly event_root_hash: string; + readonly state_checkpoint_hash: string; + readonly gas_used: string; + readonly success: boolean; + readonly vm_status: string; + readonly accumulator_root_hash: string; + readonly changes: AptosGenesisTransactionChangesItemJSON[]; + readonly payload: AptosWriteSetPayloadJSON; + readonly events: AptosTransactionEventJSON[]; +} + +export interface AptosGenesisTransactionInput { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly stateChangeHash: string; + readonly eventRootHash: string; + readonly stateCheckpointHash: string; + readonly gasUsed: string; + readonly success: boolean; + readonly vmStatus: string; + readonly accumulatorRootHash: string; + readonly changes: AptosGenesisTransactionChangesItemInput[] | AptosGenesisTransactionChangesItemValue[]; + readonly payload: AptosWriteSetPayloadInput | AptosWriteSetPayload; + readonly events: AptosTransactionEventInput[] | AptosTransactionEvent[]; +} + +export class AptosGenesisTransaction { + public static create(input: AptosGenesisTransactionInput | AptosGenesisTransaction): AptosGenesisTransaction { + if (input instanceof AptosGenesisTransaction) { + return input; + } + return new AptosGenesisTransaction(input); + } + + public static fromJSON(json: AptosGenesisTransactionJSON): AptosGenesisTransaction { + const input: AptosGenesisTransactionInput = { + type: json.type, + version: json.version, + hash: json.hash, + stateChangeHash: json.state_change_hash, + eventRootHash: json.event_root_hash, + stateCheckpointHash: json.state_checkpoint_hash, + gasUsed: json.gas_used, + success: json.success, + vmStatus: json.vm_status, + accumulatorRootHash: json.accumulator_root_hash, + changes: json.changes.map((item) => AptosGenesisTransactionChangesItem.fromJSON(item)), + payload: AptosWriteSetPayload.fromJSON(json.payload), + events: json.events.map((item) => AptosTransactionEvent.fromJSON(item)), + }; + return AptosGenesisTransaction.create(input); + } + + public static isInput(input: any): input is AptosGenesisTransactionInput { + return input.type === 'genesis_transaction'; + } + + public static isJSON(json: any): json is AptosGenesisTransactionJSON { + return json.type === 'genesis_transaction'; + } + + public readonly type: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly version: string; + public readonly hash: string; + public readonly stateChangeHash: string; + public readonly eventRootHash: string; + public readonly stateCheckpointHash: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUsed: string; + /** + * @description Whether the transaction was successful + */ + public readonly success: boolean; + /** + * @description The VM status of the transaction, can tell useful information in a failure + */ + public readonly vmStatus: string; + public readonly accumulatorRootHash: string; + public readonly changes: AptosGenesisTransactionChangesItemValue[]; + /** + * @description A writeset payload, used only for genesis + */ + public readonly payload: AptosWriteSetPayload; + /** + * @description Events generated by the transaction + */ + public readonly events: AptosTransactionEvent[]; + + private constructor(input: AptosGenesisTransactionInput) { + this.type = input.type; + this.version = input.version; + this.hash = input.hash; + this.stateChangeHash = input.stateChangeHash; + this.eventRootHash = input.eventRootHash; + this.stateCheckpointHash = input.stateCheckpointHash; + this.gasUsed = input.gasUsed; + this.success = input.success; + this.vmStatus = input.vmStatus; + this.accumulatorRootHash = input.accumulatorRootHash; + this.changes = input.changes.map((item) => AptosGenesisTransactionChangesItem.create(item)); + this.payload = AptosWriteSetPayload.create(input.payload); + this.events = input.events.map((item) => AptosTransactionEvent.create(item)); + } + + public toJSON(): AptosGenesisTransactionJSON { + return { + type: this.type, + version: this.version, + hash: this.hash, + state_change_hash: this.stateChangeHash, + event_root_hash: this.eventRootHash, + state_checkpoint_hash: this.stateCheckpointHash, + gas_used: this.gasUsed, + success: this.success, + vm_status: this.vmStatus, + accumulator_root_hash: this.accumulatorRootHash, + changes: this.changes.map((item) => item.toJSON()), + payload: this.payload.toJSON(), + events: this.events.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGenesisTransactionChangesItem.ts b/packages/common/aptosUtils/src/generated/types/AptosGenesisTransactionChangesItem.ts new file mode 100644 index 0000000000..2b145c4364 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGenesisTransactionChangesItem.ts @@ -0,0 +1,62 @@ +import { AptosDeleteModuleChange, AptosDeleteModuleChangeJSON, AptosDeleteModuleChangeInput } from '../types/AptosDeleteModuleChange'; +import { AptosDeleteResourceChange, AptosDeleteResourceChangeJSON, AptosDeleteResourceChangeInput } from '../types/AptosDeleteResourceChange'; +import { AptosDeleteTableItemChange, AptosDeleteTableItemChangeJSON, AptosDeleteTableItemChangeInput } from '../types/AptosDeleteTableItemChange'; +import { AptosWriteOrUpdateModuleChange, AptosWriteOrUpdateModuleChangeJSON, AptosWriteOrUpdateModuleChangeInput } from '../types/AptosWriteOrUpdateModuleChange'; +import { AptosWriteResourceChange, AptosWriteResourceChangeJSON, AptosWriteResourceChangeInput } from '../types/AptosWriteResourceChange'; +import { AptosWriteTableChangeSetChange, AptosWriteTableChangeSetChangeJSON, AptosWriteTableChangeSetChangeInput } from '../types/AptosWriteTableChangeSetChange'; + +// $ref: #/components/schemas/GenesisTransaction/properties/changes/items +// typeName: GenesisTransaction_changes_Item +// unionType: anyOf + +export type AptosGenesisTransactionChangesItemJSON = AptosDeleteModuleChangeJSON | AptosDeleteResourceChangeJSON | AptosDeleteTableItemChangeJSON | AptosWriteOrUpdateModuleChangeJSON | AptosWriteResourceChangeJSON | AptosWriteTableChangeSetChangeJSON; +export type AptosGenesisTransactionChangesItemInput = AptosDeleteModuleChangeInput | AptosDeleteResourceChangeInput | AptosDeleteTableItemChangeInput | AptosWriteOrUpdateModuleChangeInput | AptosWriteResourceChangeInput | AptosWriteTableChangeSetChangeInput; +export type AptosGenesisTransactionChangesItemValue = AptosDeleteModuleChange | AptosDeleteResourceChange | AptosDeleteTableItemChange | AptosWriteOrUpdateModuleChange | AptosWriteResourceChange | AptosWriteTableChangeSetChange; + +export abstract class AptosGenesisTransactionChangesItem { + public static create(input: AptosGenesisTransactionChangesItemInput): AptosGenesisTransactionChangesItemValue { + if (AptosDeleteModuleChange.isInput(input)) { + return AptosDeleteModuleChange.create(input); + } + if (AptosDeleteResourceChange.isInput(input)) { + return AptosDeleteResourceChange.create(input); + } + if (AptosDeleteTableItemChange.isInput(input)) { + return AptosDeleteTableItemChange.create(input); + } + if (AptosWriteOrUpdateModuleChange.isInput(input)) { + return AptosWriteOrUpdateModuleChange.create(input); + } + if (AptosWriteResourceChange.isInput(input)) { + return AptosWriteResourceChange.create(input); + } + if (AptosWriteTableChangeSetChange.isInput(input)) { + return AptosWriteTableChangeSetChange.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosGenesisTransactionChangesItemJSON): AptosGenesisTransactionChangesItemValue { + if (AptosDeleteModuleChange.isJSON(json)) { + return AptosDeleteModuleChange.fromJSON(json); + } + if (AptosDeleteResourceChange.isJSON(json)) { + return AptosDeleteResourceChange.fromJSON(json); + } + if (AptosDeleteTableItemChange.isJSON(json)) { + return AptosDeleteTableItemChange.fromJSON(json); + } + if (AptosWriteOrUpdateModuleChange.isJSON(json)) { + return AptosWriteOrUpdateModuleChange.fromJSON(json); + } + if (AptosWriteResourceChange.isJSON(json)) { + return AptosWriteResourceChange.fromJSON(json); + } + if (AptosWriteTableChangeSetChange.isJSON(json)) { + return AptosWriteTableChangeSetChange.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosGenesisTransactionChangesItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetAccountModuleResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetAccountModuleResponse.ts new file mode 100644 index 0000000000..3338fb8980 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetAccountModuleResponse.ts @@ -0,0 +1,55 @@ +import { AptosMoveModuleAbi, AptosMoveModuleAbiInput, AptosMoveModuleAbiJSON } from '../types/AptosMoveModuleAbi'; + +// $ref: #/components/schemas/GetAccountModuleResponse +// type: GetAccountModuleResponse +// properties: +// - bytecode ($ref: #/components/schemas/GetAccountModuleResponse/properties/bytecode) +// - abi ($ref: #/components/schemas/MoveModuleAbi) + +export interface AptosGetAccountModuleResponseJSON { + readonly bytecode: string; + readonly abi: AptosMoveModuleAbiJSON; +} + +export interface AptosGetAccountModuleResponseInput { + readonly bytecode: string; + readonly abi: AptosMoveModuleAbiInput | AptosMoveModuleAbi; +} + +export class AptosGetAccountModuleResponse { + public static create(input: AptosGetAccountModuleResponseInput | AptosGetAccountModuleResponse): AptosGetAccountModuleResponse { + if (input instanceof AptosGetAccountModuleResponse) { + return input; + } + return new AptosGetAccountModuleResponse(input); + } + + public static fromJSON(json: AptosGetAccountModuleResponseJSON): AptosGetAccountModuleResponse { + const input: AptosGetAccountModuleResponseInput = { + bytecode: json.bytecode, + abi: AptosMoveModuleAbi.fromJSON(json.abi), + }; + return AptosGetAccountModuleResponse.create(input); + } + + /** + * @description 0x88fbd33f54e1126269769780feb24480428179f552e2313fbe571b72e62a1ca1 + */ + public readonly bytecode: string; + /** + * @description A Move module + */ + public readonly abi: AptosMoveModuleAbi; + + private constructor(input: AptosGetAccountModuleResponseInput) { + this.bytecode = input.bytecode; + this.abi = AptosMoveModuleAbi.create(input.abi); + } + + public toJSON(): AptosGetAccountModuleResponseJSON { + return { + bytecode: this.bytecode, + abi: this.abi.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetAccountResourceResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetAccountResourceResponse.ts new file mode 100644 index 0000000000..e6535391e6 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetAccountResourceResponse.ts @@ -0,0 +1,55 @@ +import { AptosGetAccountResourceResponseData, AptosGetAccountResourceResponseDataValue, AptosGetAccountResourceResponseDataInput, AptosGetAccountResourceResponseDataJSON } from '../types/AptosGetAccountResourceResponseData'; + +// $ref: #/components/schemas/GetAccountResourceResponse +// type: GetAccountResourceResponse +// properties: +// - type ($ref: #/components/schemas/GetAccountResourceResponse/properties/type) +// - data ($ref: #/components/schemas/GetAccountResourceResponse/properties/data) + +export interface AptosGetAccountResourceResponseJSON { + readonly type: string; + readonly data: AptosGetAccountResourceResponseDataJSON; +} + +export interface AptosGetAccountResourceResponseInput { + readonly type: string; + readonly data: AptosGetAccountResourceResponseDataInput | AptosGetAccountResourceResponseDataValue; +} + +export class AptosGetAccountResourceResponse { + public static create(input: AptosGetAccountResourceResponseInput | AptosGetAccountResourceResponse): AptosGetAccountResourceResponse { + if (input instanceof AptosGetAccountResourceResponse) { + return input; + } + return new AptosGetAccountResourceResponse(input); + } + + public static fromJSON(json: AptosGetAccountResourceResponseJSON): AptosGetAccountResourceResponse { + const input: AptosGetAccountResourceResponseInput = { + type: json.type, + data: AptosGetAccountResourceResponseData.fromJSON(json.data), + }; + return AptosGetAccountResourceResponse.create(input); + } + + /** + * @description String representation of a MoveStructTag (on-chain Move struct type). This exists so you can specify MoveStructTags as path / query parameters + */ + public readonly type: string; + /** + * @description This is a JSON representation of some data within an account resource. More specifically, it is a map of strings to arbitrary JSON values / objects, where the keys are top level fields within the given resource. + */ + public readonly data: AptosGetAccountResourceResponseDataValue; + + private constructor(input: AptosGetAccountResourceResponseInput) { + this.type = input.type; + this.data = AptosGetAccountResourceResponseData.create(input.data); + } + + public toJSON(): AptosGetAccountResourceResponseJSON { + return { + type: this.type, + data: this.data, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetAccountResourceResponseData.ts b/packages/common/aptosUtils/src/generated/types/AptosGetAccountResourceResponseData.ts new file mode 100644 index 0000000000..eb24c933cb --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetAccountResourceResponseData.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/GetAccountResourceResponse/properties/data +// typeName: GetAccountResourceResponse_data + +export type AptosGetAccountResourceResponseDataJSON = object; +export type AptosGetAccountResourceResponseDataInput = object; +export type AptosGetAccountResourceResponseDataValue = object; + +export abstract class AptosGetAccountResourceResponseData { + public static create(input: AptosGetAccountResourceResponseDataInput | AptosGetAccountResourceResponseDataValue): AptosGetAccountResourceResponseDataValue { + return input; + } + + public static fromJSON(json: AptosGetAccountResourceResponseDataJSON): AptosGetAccountResourceResponseDataValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetAccountResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetAccountResponse.ts new file mode 100644 index 0000000000..179ddae35d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetAccountResponse.ts @@ -0,0 +1,55 @@ +// $ref: #/components/schemas/GetAccountResponse +// type: GetAccountResponse +// properties: +// - sequence_number ($ref: #/components/schemas/GetAccountResponse/properties/sequence_number) +// - authentication_key ($ref: #/components/schemas/GetAccountResponse/properties/authentication_key) + +export interface AptosGetAccountResponseJSON { + readonly sequence_number: string; + readonly authentication_key: string; +} + +export interface AptosGetAccountResponseInput { + readonly sequenceNumber: string; + readonly authenticationKey: string; +} + +export class AptosGetAccountResponse { + public static create(input: AptosGetAccountResponseInput | AptosGetAccountResponse): AptosGetAccountResponse { + if (input instanceof AptosGetAccountResponse) { + return input; + } + return new AptosGetAccountResponse(input); + } + + public static fromJSON(json: AptosGetAccountResponseJSON): AptosGetAccountResponse { + const input: AptosGetAccountResponseInput = { + sequenceNumber: json.sequence_number, + authenticationKey: json.authentication_key, + }; + return AptosGetAccountResponse.create(input); + } + + /** + * @description A string containing a 64-bit unsigned integer. + * We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. + */ + public readonly sequenceNumber: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + * Unlike the Address type, HexEncodedBytes will not trim any zeros. + */ + public readonly authenticationKey: string; + + private constructor(input: AptosGetAccountResponseInput) { + this.sequenceNumber = input.sequenceNumber; + this.authenticationKey = input.authenticationKey; + } + + public toJSON(): AptosGetAccountResponseJSON { + return { + sequence_number: this.sequenceNumber, + authentication_key: this.authenticationKey, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetAccountTransactionsItem.ts b/packages/common/aptosUtils/src/generated/types/AptosGetAccountTransactionsItem.ts new file mode 100644 index 0000000000..ac41993ba2 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetAccountTransactionsItem.ts @@ -0,0 +1,55 @@ +import { AptosPendingTransaction, AptosPendingTransactionJSON, AptosPendingTransactionInput } from '../types/AptosPendingTransaction'; +import { AptosUserTransaction, AptosUserTransactionJSON, AptosUserTransactionInput } from '../types/AptosUserTransaction'; +import { AptosGenesisTransaction, AptosGenesisTransactionJSON, AptosGenesisTransactionInput } from '../types/AptosGenesisTransaction'; +import { AptosBlockMetadataTransaction, AptosBlockMetadataTransactionJSON, AptosBlockMetadataTransactionInput } from '../types/AptosBlockMetadataTransaction'; +import { AptosStateCheckpointTransaction, AptosStateCheckpointTransactionJSON, AptosStateCheckpointTransactionInput } from '../types/AptosStateCheckpointTransaction'; + +// $ref: #/paths/~1accounts~1{address}~1transactions/get/responses/200/content/application~1json/schema/items +// typeName: getAccountTransactions_Item +// unionType: oneOf + +export type AptosGetAccountTransactionsItemJSON = AptosPendingTransactionJSON | AptosUserTransactionJSON | AptosGenesisTransactionJSON | AptosBlockMetadataTransactionJSON | AptosStateCheckpointTransactionJSON; +export type AptosGetAccountTransactionsItemInput = AptosPendingTransactionInput | AptosUserTransactionInput | AptosGenesisTransactionInput | AptosBlockMetadataTransactionInput | AptosStateCheckpointTransactionInput; +export type AptosGetAccountTransactionsItemValue = AptosPendingTransaction | AptosUserTransaction | AptosGenesisTransaction | AptosBlockMetadataTransaction | AptosStateCheckpointTransaction; + +export abstract class AptosGetAccountTransactionsItem { + public static create(input: AptosGetAccountTransactionsItemInput): AptosGetAccountTransactionsItemValue { + if (AptosPendingTransaction.isInput(input)) { + return AptosPendingTransaction.create(input); + } + if (AptosUserTransaction.isInput(input)) { + return AptosUserTransaction.create(input); + } + if (AptosGenesisTransaction.isInput(input)) { + return AptosGenesisTransaction.create(input); + } + if (AptosBlockMetadataTransaction.isInput(input)) { + return AptosBlockMetadataTransaction.create(input); + } + if (AptosStateCheckpointTransaction.isInput(input)) { + return AptosStateCheckpointTransaction.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosGetAccountTransactionsItemJSON): AptosGetAccountTransactionsItemValue { + if (AptosPendingTransaction.isJSON(json)) { + return AptosPendingTransaction.fromJSON(json); + } + if (AptosUserTransaction.isJSON(json)) { + return AptosUserTransaction.fromJSON(json); + } + if (AptosGenesisTransaction.isJSON(json)) { + return AptosGenesisTransaction.fromJSON(json); + } + if (AptosBlockMetadataTransaction.isJSON(json)) { + return AptosBlockMetadataTransaction.fromJSON(json); + } + if (AptosStateCheckpointTransaction.isJSON(json)) { + return AptosStateCheckpointTransaction.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosGetAccountTransactionsItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinBalancesByWalletsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinBalancesByWalletsResponse.ts new file mode 100644 index 0000000000..bbd2ca6f57 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinBalancesByWalletsResponse.ts @@ -0,0 +1,65 @@ +import { AptosCurrentCoinBalanceDto, AptosCurrentCoinBalanceDtoInput, AptosCurrentCoinBalanceDtoJSON } from '../types/AptosCurrentCoinBalanceDto'; + +// $ref: #/components/schemas/GetCoinBalancesByWalletsResponse +// type: GetCoinBalancesByWalletsResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinBalancesByWalletsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinBalancesByWalletsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CurrentCoinBalanceDto) + +export interface AptosGetCoinBalancesByWalletsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCurrentCoinBalanceDtoJSON[]; +} + +export interface AptosGetCoinBalancesByWalletsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCurrentCoinBalanceDtoInput[] | AptosCurrentCoinBalanceDto[]; +} + +export class AptosGetCoinBalancesByWalletsResponse { + public static create(input: AptosGetCoinBalancesByWalletsResponseInput | AptosGetCoinBalancesByWalletsResponse): AptosGetCoinBalancesByWalletsResponse { + if (input instanceof AptosGetCoinBalancesByWalletsResponse) { + return input; + } + return new AptosGetCoinBalancesByWalletsResponse(input); + } + + public static fromJSON(json: AptosGetCoinBalancesByWalletsResponseJSON): AptosGetCoinBalancesByWalletsResponse { + const input: AptosGetCoinBalancesByWalletsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCurrentCoinBalanceDto.fromJSON(item)), + }; + return AptosGetCoinBalancesByWalletsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins balances for the provided wallets + */ + public readonly result: AptosCurrentCoinBalanceDto[]; + + private constructor(input: AptosGetCoinBalancesByWalletsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCurrentCoinBalanceDto.create(item)); + } + + public toJSON(): AptosGetCoinBalancesByWalletsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByBlockHeightsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByBlockHeightsResponse.ts new file mode 100644 index 0000000000..0ab16d53cc --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByBlockHeightsResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinTransferDto, AptosCoinTransferDtoInput, AptosCoinTransferDtoJSON } from '../types/AptosCoinTransferDto'; + +// $ref: #/components/schemas/GetCoinTransfersByBlockHeightsResponse +// type: GetCoinTransfersByBlockHeightsResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinTransfersByBlockHeightsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinTransfersByBlockHeightsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinTransferDto) + +export interface AptosGetCoinTransfersByBlockHeightsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinTransferDtoJSON[]; +} + +export interface AptosGetCoinTransfersByBlockHeightsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinTransferDtoInput[] | AptosCoinTransferDto[]; +} + +export class AptosGetCoinTransfersByBlockHeightsResponse { + public static create(input: AptosGetCoinTransfersByBlockHeightsResponseInput | AptosGetCoinTransfersByBlockHeightsResponse): AptosGetCoinTransfersByBlockHeightsResponse { + if (input instanceof AptosGetCoinTransfersByBlockHeightsResponse) { + return input; + } + return new AptosGetCoinTransfersByBlockHeightsResponse(input); + } + + public static fromJSON(json: AptosGetCoinTransfersByBlockHeightsResponseJSON): AptosGetCoinTransfersByBlockHeightsResponse { + const input: AptosGetCoinTransfersByBlockHeightsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinTransferDto.fromJSON(item)), + }; + return AptosGetCoinTransfersByBlockHeightsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins transfers for the provided block heights + */ + public readonly result: AptosCoinTransferDto[]; + + private constructor(input: AptosGetCoinTransfersByBlockHeightsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinTransferDto.create(item)); + } + + public toJSON(): AptosGetCoinTransfersByBlockHeightsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByCoinTypeResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByCoinTypeResponse.ts new file mode 100644 index 0000000000..09868b12bd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByCoinTypeResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinTransferDto, AptosCoinTransferDtoInput, AptosCoinTransferDtoJSON } from '../types/AptosCoinTransferDto'; + +// $ref: #/components/schemas/GetCoinTransfersByCoinTypeResponse +// type: GetCoinTransfersByCoinTypeResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinTransfersByCoinTypeResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinTransfersByCoinTypeResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinTransferDto) + +export interface AptosGetCoinTransfersByCoinTypeResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinTransferDtoJSON[]; +} + +export interface AptosGetCoinTransfersByCoinTypeResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinTransferDtoInput[] | AptosCoinTransferDto[]; +} + +export class AptosGetCoinTransfersByCoinTypeResponse { + public static create(input: AptosGetCoinTransfersByCoinTypeResponseInput | AptosGetCoinTransfersByCoinTypeResponse): AptosGetCoinTransfersByCoinTypeResponse { + if (input instanceof AptosGetCoinTransfersByCoinTypeResponse) { + return input; + } + return new AptosGetCoinTransfersByCoinTypeResponse(input); + } + + public static fromJSON(json: AptosGetCoinTransfersByCoinTypeResponseJSON): AptosGetCoinTransfersByCoinTypeResponse { + const input: AptosGetCoinTransfersByCoinTypeResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinTransferDto.fromJSON(item)), + }; + return AptosGetCoinTransfersByCoinTypeResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins transfers for the provided coin type + */ + public readonly result: AptosCoinTransferDto[]; + + private constructor(input: AptosGetCoinTransfersByCoinTypeResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinTransferDto.create(item)); + } + + public toJSON(): AptosGetCoinTransfersByCoinTypeResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByOwnerAddressesResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByOwnerAddressesResponse.ts new file mode 100644 index 0000000000..f41ebd8e81 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinTransfersByOwnerAddressesResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinTransferDto, AptosCoinTransferDtoInput, AptosCoinTransferDtoJSON } from '../types/AptosCoinTransferDto'; + +// $ref: #/components/schemas/GetCoinTransfersByOwnerAddressesResponse +// type: GetCoinTransfersByOwnerAddressesResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinTransfersByOwnerAddressesResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinTransfersByOwnerAddressesResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinTransferDto) + +export interface AptosGetCoinTransfersByOwnerAddressesResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinTransferDtoJSON[]; +} + +export interface AptosGetCoinTransfersByOwnerAddressesResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinTransferDtoInput[] | AptosCoinTransferDto[]; +} + +export class AptosGetCoinTransfersByOwnerAddressesResponse { + public static create(input: AptosGetCoinTransfersByOwnerAddressesResponseInput | AptosGetCoinTransfersByOwnerAddressesResponse): AptosGetCoinTransfersByOwnerAddressesResponse { + if (input instanceof AptosGetCoinTransfersByOwnerAddressesResponse) { + return input; + } + return new AptosGetCoinTransfersByOwnerAddressesResponse(input); + } + + public static fromJSON(json: AptosGetCoinTransfersByOwnerAddressesResponseJSON): AptosGetCoinTransfersByOwnerAddressesResponse { + const input: AptosGetCoinTransfersByOwnerAddressesResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinTransferDto.fromJSON(item)), + }; + return AptosGetCoinTransfersByOwnerAddressesResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins transfers for the provided owner addresses + */ + public readonly result: AptosCoinTransferDto[]; + + private constructor(input: AptosGetCoinTransfersByOwnerAddressesResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinTransferDto.create(item)); + } + + public toJSON(): AptosGetCoinTransfersByOwnerAddressesResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinsByCreatorsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinsByCreatorsResponse.ts new file mode 100644 index 0000000000..73ca90315e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinsByCreatorsResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinInfoDto, AptosCoinInfoDtoInput, AptosCoinInfoDtoJSON } from '../types/AptosCoinInfoDto'; + +// $ref: #/components/schemas/GetCoinsByCreatorsResponse +// type: GetCoinsByCreatorsResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinsByCreatorsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinsByCreatorsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinInfoDto) + +export interface AptosGetCoinsByCreatorsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoJSON[]; +} + +export interface AptosGetCoinsByCreatorsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoInput[] | AptosCoinInfoDto[]; +} + +export class AptosGetCoinsByCreatorsResponse { + public static create(input: AptosGetCoinsByCreatorsResponseInput | AptosGetCoinsByCreatorsResponse): AptosGetCoinsByCreatorsResponse { + if (input instanceof AptosGetCoinsByCreatorsResponse) { + return input; + } + return new AptosGetCoinsByCreatorsResponse(input); + } + + public static fromJSON(json: AptosGetCoinsByCreatorsResponseJSON): AptosGetCoinsByCreatorsResponse { + const input: AptosGetCoinsByCreatorsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinInfoDto.fromJSON(item)), + }; + return AptosGetCoinsByCreatorsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins created by the given creators + */ + public readonly result: AptosCoinInfoDto[]; + + private constructor(input: AptosGetCoinsByCreatorsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinInfoDto.create(item)); + } + + public toJSON(): AptosGetCoinsByCreatorsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinsByNameRangeResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinsByNameRangeResponse.ts new file mode 100644 index 0000000000..d72773c4a1 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinsByNameRangeResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinInfoDto, AptosCoinInfoDtoInput, AptosCoinInfoDtoJSON } from '../types/AptosCoinInfoDto'; + +// $ref: #/components/schemas/GetCoinsByNameRangeResponse +// type: GetCoinsByNameRangeResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinsByNameRangeResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinsByNameRangeResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinInfoDto) + +export interface AptosGetCoinsByNameRangeResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoJSON[]; +} + +export interface AptosGetCoinsByNameRangeResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoInput[] | AptosCoinInfoDto[]; +} + +export class AptosGetCoinsByNameRangeResponse { + public static create(input: AptosGetCoinsByNameRangeResponseInput | AptosGetCoinsByNameRangeResponse): AptosGetCoinsByNameRangeResponse { + if (input instanceof AptosGetCoinsByNameRangeResponse) { + return input; + } + return new AptosGetCoinsByNameRangeResponse(input); + } + + public static fromJSON(json: AptosGetCoinsByNameRangeResponseJSON): AptosGetCoinsByNameRangeResponse { + const input: AptosGetCoinsByNameRangeResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinInfoDto.fromJSON(item)), + }; + return AptosGetCoinsByNameRangeResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins matching the query + */ + public readonly result: AptosCoinInfoDto[]; + + private constructor(input: AptosGetCoinsByNameRangeResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinInfoDto.create(item)); + } + + public toJSON(): AptosGetCoinsByNameRangeResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetCoinsBySymbolRangeResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetCoinsBySymbolRangeResponse.ts new file mode 100644 index 0000000000..34f4b2ff6b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetCoinsBySymbolRangeResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinInfoDto, AptosCoinInfoDtoInput, AptosCoinInfoDtoJSON } from '../types/AptosCoinInfoDto'; + +// $ref: #/components/schemas/GetCoinsBySymbolRangeResponse +// type: GetCoinsBySymbolRangeResponse +// properties: +// - cursor ($ref: #/components/schemas/GetCoinsBySymbolRangeResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetCoinsBySymbolRangeResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinInfoDto) + +export interface AptosGetCoinsBySymbolRangeResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoJSON[]; +} + +export interface AptosGetCoinsBySymbolRangeResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoInput[] | AptosCoinInfoDto[]; +} + +export class AptosGetCoinsBySymbolRangeResponse { + public static create(input: AptosGetCoinsBySymbolRangeResponseInput | AptosGetCoinsBySymbolRangeResponse): AptosGetCoinsBySymbolRangeResponse { + if (input instanceof AptosGetCoinsBySymbolRangeResponse) { + return input; + } + return new AptosGetCoinsBySymbolRangeResponse(input); + } + + public static fromJSON(json: AptosGetCoinsBySymbolRangeResponseJSON): AptosGetCoinsBySymbolRangeResponse { + const input: AptosGetCoinsBySymbolRangeResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinInfoDto.fromJSON(item)), + }; + return AptosGetCoinsBySymbolRangeResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins matching the query + */ + public readonly result: AptosCoinInfoDto[]; + + private constructor(input: AptosGetCoinsBySymbolRangeResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinInfoDto.create(item)); + } + + public toJSON(): AptosGetCoinsBySymbolRangeResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetEventsByCreationNumberResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByCreationNumberResponse.ts new file mode 100644 index 0000000000..79bd885dcb --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByCreationNumberResponse.ts @@ -0,0 +1,85 @@ +import { AptosTransactionEventGuid, AptosTransactionEventGuidInput, AptosTransactionEventGuidJSON } from '../types/AptosTransactionEventGuid'; +import { AptosGetEventsByCreationNumberResponseData, AptosGetEventsByCreationNumberResponseDataValue, AptosGetEventsByCreationNumberResponseDataInput, AptosGetEventsByCreationNumberResponseDataJSON } from '../types/AptosGetEventsByCreationNumberResponseData'; + +// $ref: #/components/schemas/GetEventsByCreationNumberResponse +// type: GetEventsByCreationNumberResponse +// properties: +// - version ($ref: #/components/schemas/GetEventsByCreationNumberResponse/properties/version) +// - guid ($ref: #/components/schemas/TransactionEventGuid) +// - sequence_number ($ref: #/components/schemas/GetEventsByCreationNumberResponse/properties/sequence_number) +// - type ($ref: #/components/schemas/GetEventsByCreationNumberResponse/properties/type) +// - data ($ref: #/components/schemas/GetEventsByCreationNumberResponse/properties/data) + +export interface AptosGetEventsByCreationNumberResponseJSON { + readonly version: string; + readonly guid: AptosTransactionEventGuidJSON; + readonly sequence_number: string; + readonly type: string; + readonly data: AptosGetEventsByCreationNumberResponseDataJSON; +} + +export interface AptosGetEventsByCreationNumberResponseInput { + readonly version: string; + readonly guid: AptosTransactionEventGuidInput | AptosTransactionEventGuid; + readonly sequenceNumber: string; + readonly type: string; + readonly data: AptosGetEventsByCreationNumberResponseDataInput | AptosGetEventsByCreationNumberResponseDataValue; +} + +export class AptosGetEventsByCreationNumberResponse { + public static create(input: AptosGetEventsByCreationNumberResponseInput | AptosGetEventsByCreationNumberResponse): AptosGetEventsByCreationNumberResponse { + if (input instanceof AptosGetEventsByCreationNumberResponse) { + return input; + } + return new AptosGetEventsByCreationNumberResponse(input); + } + + public static fromJSON(json: AptosGetEventsByCreationNumberResponseJSON): AptosGetEventsByCreationNumberResponse { + const input: AptosGetEventsByCreationNumberResponseInput = { + version: json.version, + guid: AptosTransactionEventGuid.fromJSON(json.guid), + sequenceNumber: json.sequence_number, + type: json.type, + data: AptosGetEventsByCreationNumberResponseData.fromJSON(json.data), + }; + return AptosGetEventsByCreationNumberResponse.create(input); + } + + /** + * @description A string containing a 64-bit unsigned integer. + * We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. + */ + public readonly version: string; + public readonly guid: AptosTransactionEventGuid; + /** + * @description A string containing a 64-bit unsigned integer. + * We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. + */ + public readonly sequenceNumber: string; + /** + * @description String representation of an on-chain Move type tag that is exposed in transaction payload. + */ + public readonly type: string; + /** + * @description The JSON representation of the event + */ + public readonly data: AptosGetEventsByCreationNumberResponseDataValue; + + private constructor(input: AptosGetEventsByCreationNumberResponseInput) { + this.version = input.version; + this.guid = AptosTransactionEventGuid.create(input.guid); + this.sequenceNumber = input.sequenceNumber; + this.type = input.type; + this.data = AptosGetEventsByCreationNumberResponseData.create(input.data); + } + + public toJSON(): AptosGetEventsByCreationNumberResponseJSON { + return { + version: this.version, + guid: this.guid.toJSON(), + sequence_number: this.sequenceNumber, + type: this.type, + data: this.data, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetEventsByCreationNumberResponseData.ts b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByCreationNumberResponseData.ts new file mode 100644 index 0000000000..c6e5bff039 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByCreationNumberResponseData.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/GetEventsByCreationNumberResponse/properties/data +// typeName: GetEventsByCreationNumberResponse_data + +export type AptosGetEventsByCreationNumberResponseDataJSON = object; +export type AptosGetEventsByCreationNumberResponseDataInput = object; +export type AptosGetEventsByCreationNumberResponseDataValue = object; + +export abstract class AptosGetEventsByCreationNumberResponseData { + public static create(input: AptosGetEventsByCreationNumberResponseDataInput | AptosGetEventsByCreationNumberResponseDataValue): AptosGetEventsByCreationNumberResponseDataValue { + return input; + } + + public static fromJSON(json: AptosGetEventsByCreationNumberResponseDataJSON): AptosGetEventsByCreationNumberResponseDataValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetEventsByEventHandleResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByEventHandleResponse.ts new file mode 100644 index 0000000000..f239a44e16 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByEventHandleResponse.ts @@ -0,0 +1,85 @@ +import { AptosTransactionEventGuid, AptosTransactionEventGuidInput, AptosTransactionEventGuidJSON } from '../types/AptosTransactionEventGuid'; +import { AptosGetEventsByEventHandleResponseData, AptosGetEventsByEventHandleResponseDataValue, AptosGetEventsByEventHandleResponseDataInput, AptosGetEventsByEventHandleResponseDataJSON } from '../types/AptosGetEventsByEventHandleResponseData'; + +// $ref: #/components/schemas/GetEventsByEventHandleResponse +// type: GetEventsByEventHandleResponse +// properties: +// - version ($ref: #/components/schemas/GetEventsByEventHandleResponse/properties/version) +// - guid ($ref: #/components/schemas/TransactionEventGuid) +// - sequence_number ($ref: #/components/schemas/GetEventsByEventHandleResponse/properties/sequence_number) +// - type ($ref: #/components/schemas/GetEventsByEventHandleResponse/properties/type) +// - data ($ref: #/components/schemas/GetEventsByEventHandleResponse/properties/data) + +export interface AptosGetEventsByEventHandleResponseJSON { + readonly version: string; + readonly guid: AptosTransactionEventGuidJSON; + readonly sequence_number: string; + readonly type: string; + readonly data: AptosGetEventsByEventHandleResponseDataJSON; +} + +export interface AptosGetEventsByEventHandleResponseInput { + readonly version: string; + readonly guid: AptosTransactionEventGuidInput | AptosTransactionEventGuid; + readonly sequenceNumber: string; + readonly type: string; + readonly data: AptosGetEventsByEventHandleResponseDataInput | AptosGetEventsByEventHandleResponseDataValue; +} + +export class AptosGetEventsByEventHandleResponse { + public static create(input: AptosGetEventsByEventHandleResponseInput | AptosGetEventsByEventHandleResponse): AptosGetEventsByEventHandleResponse { + if (input instanceof AptosGetEventsByEventHandleResponse) { + return input; + } + return new AptosGetEventsByEventHandleResponse(input); + } + + public static fromJSON(json: AptosGetEventsByEventHandleResponseJSON): AptosGetEventsByEventHandleResponse { + const input: AptosGetEventsByEventHandleResponseInput = { + version: json.version, + guid: AptosTransactionEventGuid.fromJSON(json.guid), + sequenceNumber: json.sequence_number, + type: json.type, + data: AptosGetEventsByEventHandleResponseData.fromJSON(json.data), + }; + return AptosGetEventsByEventHandleResponse.create(input); + } + + /** + * @description A string containing a 64-bit unsigned integer. + * We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. + */ + public readonly version: string; + public readonly guid: AptosTransactionEventGuid; + /** + * @description A string containing a 64-bit unsigned integer. + * We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. + */ + public readonly sequenceNumber: string; + /** + * @description String representation of an on-chain Move type tag that is exposed in transaction payload. + */ + public readonly type: string; + /** + * @description The JSON representation of the event + */ + public readonly data: AptosGetEventsByEventHandleResponseDataValue; + + private constructor(input: AptosGetEventsByEventHandleResponseInput) { + this.version = input.version; + this.guid = AptosTransactionEventGuid.create(input.guid); + this.sequenceNumber = input.sequenceNumber; + this.type = input.type; + this.data = AptosGetEventsByEventHandleResponseData.create(input.data); + } + + public toJSON(): AptosGetEventsByEventHandleResponseJSON { + return { + version: this.version, + guid: this.guid.toJSON(), + sequence_number: this.sequenceNumber, + type: this.type, + data: this.data, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetEventsByEventHandleResponseData.ts b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByEventHandleResponseData.ts new file mode 100644 index 0000000000..926d7a4e5b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetEventsByEventHandleResponseData.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/GetEventsByEventHandleResponse/properties/data +// typeName: GetEventsByEventHandleResponse_data + +export type AptosGetEventsByEventHandleResponseDataJSON = object; +export type AptosGetEventsByEventHandleResponseDataInput = object; +export type AptosGetEventsByEventHandleResponseDataValue = object; + +export abstract class AptosGetEventsByEventHandleResponseData { + public static create(input: AptosGetEventsByEventHandleResponseDataInput | AptosGetEventsByEventHandleResponseDataValue): AptosGetEventsByEventHandleResponseDataValue { + return input; + } + + public static fromJSON(json: AptosGetEventsByEventHandleResponseDataJSON): AptosGetEventsByEventHandleResponseDataValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetHistoricalCoinBalancesByWalletsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetHistoricalCoinBalancesByWalletsResponse.ts new file mode 100644 index 0000000000..8096f014d6 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetHistoricalCoinBalancesByWalletsResponse.ts @@ -0,0 +1,65 @@ +import { AptosHistoricalCoinBalanceDto, AptosHistoricalCoinBalanceDtoInput, AptosHistoricalCoinBalanceDtoJSON } from '../types/AptosHistoricalCoinBalanceDto'; + +// $ref: #/components/schemas/GetHistoricalCoinBalancesByWalletsResponse +// type: GetHistoricalCoinBalancesByWalletsResponse +// properties: +// - cursor ($ref: #/components/schemas/GetHistoricalCoinBalancesByWalletsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetHistoricalCoinBalancesByWalletsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/HistoricalCoinBalanceDto) + +export interface AptosGetHistoricalCoinBalancesByWalletsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosHistoricalCoinBalanceDtoJSON[]; +} + +export interface AptosGetHistoricalCoinBalancesByWalletsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosHistoricalCoinBalanceDtoInput[] | AptosHistoricalCoinBalanceDto[]; +} + +export class AptosGetHistoricalCoinBalancesByWalletsResponse { + public static create(input: AptosGetHistoricalCoinBalancesByWalletsResponseInput | AptosGetHistoricalCoinBalancesByWalletsResponse): AptosGetHistoricalCoinBalancesByWalletsResponse { + if (input instanceof AptosGetHistoricalCoinBalancesByWalletsResponse) { + return input; + } + return new AptosGetHistoricalCoinBalancesByWalletsResponse(input); + } + + public static fromJSON(json: AptosGetHistoricalCoinBalancesByWalletsResponseJSON): AptosGetHistoricalCoinBalancesByWalletsResponse { + const input: AptosGetHistoricalCoinBalancesByWalletsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosHistoricalCoinBalanceDto.fromJSON(item)), + }; + return AptosGetHistoricalCoinBalancesByWalletsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins balances for the provided wallets + */ + public readonly result: AptosHistoricalCoinBalanceDto[]; + + private constructor(input: AptosGetHistoricalCoinBalancesByWalletsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosHistoricalCoinBalanceDto.create(item)); + } + + public toJSON(): AptosGetHistoricalCoinBalancesByWalletsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetLatestCoinsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetLatestCoinsResponse.ts new file mode 100644 index 0000000000..c037076520 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetLatestCoinsResponse.ts @@ -0,0 +1,65 @@ +import { AptosCoinInfoDto, AptosCoinInfoDtoInput, AptosCoinInfoDtoJSON } from '../types/AptosCoinInfoDto'; + +// $ref: #/components/schemas/GetLatestCoinsResponse +// type: GetLatestCoinsResponse +// properties: +// - cursor ($ref: #/components/schemas/GetLatestCoinsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetLatestCoinsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CoinInfoDto) + +export interface AptosGetLatestCoinsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoJSON[]; +} + +export interface AptosGetLatestCoinsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCoinInfoDtoInput[] | AptosCoinInfoDto[]; +} + +export class AptosGetLatestCoinsResponse { + public static create(input: AptosGetLatestCoinsResponseInput | AptosGetLatestCoinsResponse): AptosGetLatestCoinsResponse { + if (input instanceof AptosGetLatestCoinsResponse) { + return input; + } + return new AptosGetLatestCoinsResponse(input); + } + + public static fromJSON(json: AptosGetLatestCoinsResponseJSON): AptosGetLatestCoinsResponse { + const input: AptosGetLatestCoinsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCoinInfoDto.fromJSON(item)), + }; + return AptosGetLatestCoinsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The coins matching the query + */ + public readonly result: AptosCoinInfoDto[]; + + private constructor(input: AptosGetLatestCoinsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCoinInfoDto.create(item)); + } + + public toJSON(): AptosGetLatestCoinsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetNFTTransfersByCollectionResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetNFTTransfersByCollectionResponse.ts new file mode 100644 index 0000000000..e0ec59559e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetNFTTransfersByCollectionResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTTransferResponse, AptosNFTTransferResponseInput, AptosNFTTransferResponseJSON } from '../types/AptosNFTTransferResponse'; + +// $ref: #/components/schemas/GetNFTTransfersByCollectionResponse +// type: GetNFTTransfersByCollectionResponse +// properties: +// - cursor ($ref: #/components/schemas/GetNFTTransfersByCollectionResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetNFTTransfersByCollectionResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTTransferResponse) + +export interface AptosGetNFTTransfersByCollectionResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseJSON[]; +} + +export interface AptosGetNFTTransfersByCollectionResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseInput[] | AptosNFTTransferResponse[]; +} + +export class AptosGetNFTTransfersByCollectionResponse { + public static create(input: AptosGetNFTTransfersByCollectionResponseInput | AptosGetNFTTransfersByCollectionResponse): AptosGetNFTTransfersByCollectionResponse { + if (input instanceof AptosGetNFTTransfersByCollectionResponse) { + return input; + } + return new AptosGetNFTTransfersByCollectionResponse(input); + } + + public static fromJSON(json: AptosGetNFTTransfersByCollectionResponseJSON): AptosGetNFTTransfersByCollectionResponse { + const input: AptosGetNFTTransfersByCollectionResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTTransferResponse.fromJSON(item)), + }; + return AptosGetNFTTransfersByCollectionResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creators + */ + public readonly result: AptosNFTTransferResponse[]; + + private constructor(input: AptosGetNFTTransfersByCollectionResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTTransferResponse.create(item)); + } + + public toJSON(): AptosGetNFTTransfersByCollectionResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetNFTTransfersByCreatorsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetNFTTransfersByCreatorsResponse.ts new file mode 100644 index 0000000000..7f1315d79f --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetNFTTransfersByCreatorsResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTTransferResponse, AptosNFTTransferResponseInput, AptosNFTTransferResponseJSON } from '../types/AptosNFTTransferResponse'; + +// $ref: #/components/schemas/GetNFTTransfersByCreatorsResponse +// type: GetNFTTransfersByCreatorsResponse +// properties: +// - cursor ($ref: #/components/schemas/GetNFTTransfersByCreatorsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetNFTTransfersByCreatorsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTTransferResponse) + +export interface AptosGetNFTTransfersByCreatorsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseJSON[]; +} + +export interface AptosGetNFTTransfersByCreatorsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseInput[] | AptosNFTTransferResponse[]; +} + +export class AptosGetNFTTransfersByCreatorsResponse { + public static create(input: AptosGetNFTTransfersByCreatorsResponseInput | AptosGetNFTTransfersByCreatorsResponse): AptosGetNFTTransfersByCreatorsResponse { + if (input instanceof AptosGetNFTTransfersByCreatorsResponse) { + return input; + } + return new AptosGetNFTTransfersByCreatorsResponse(input); + } + + public static fromJSON(json: AptosGetNFTTransfersByCreatorsResponseJSON): AptosGetNFTTransfersByCreatorsResponse { + const input: AptosGetNFTTransfersByCreatorsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTTransferResponse.fromJSON(item)), + }; + return AptosGetNFTTransfersByCreatorsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creators + */ + public readonly result: AptosNFTTransferResponse[]; + + private constructor(input: AptosGetNFTTransfersByCreatorsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTTransferResponse.create(item)); + } + + public toJSON(): AptosGetNFTTransfersByCreatorsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetTopHoldersByCoinResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosGetTopHoldersByCoinResponse.ts new file mode 100644 index 0000000000..dc5c39e195 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetTopHoldersByCoinResponse.ts @@ -0,0 +1,65 @@ +import { AptosCurrentCoinBalanceDto, AptosCurrentCoinBalanceDtoInput, AptosCurrentCoinBalanceDtoJSON } from '../types/AptosCurrentCoinBalanceDto'; + +// $ref: #/components/schemas/GetTopHoldersByCoinResponse +// type: GetTopHoldersByCoinResponse +// properties: +// - cursor ($ref: #/components/schemas/GetTopHoldersByCoinResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/GetTopHoldersByCoinResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/CurrentCoinBalanceDto) + +export interface AptosGetTopHoldersByCoinResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCurrentCoinBalanceDtoJSON[]; +} + +export interface AptosGetTopHoldersByCoinResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosCurrentCoinBalanceDtoInput[] | AptosCurrentCoinBalanceDto[]; +} + +export class AptosGetTopHoldersByCoinResponse { + public static create(input: AptosGetTopHoldersByCoinResponseInput | AptosGetTopHoldersByCoinResponse): AptosGetTopHoldersByCoinResponse { + if (input instanceof AptosGetTopHoldersByCoinResponse) { + return input; + } + return new AptosGetTopHoldersByCoinResponse(input); + } + + public static fromJSON(json: AptosGetTopHoldersByCoinResponseJSON): AptosGetTopHoldersByCoinResponse { + const input: AptosGetTopHoldersByCoinResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosCurrentCoinBalanceDto.fromJSON(item)), + }; + return AptosGetTopHoldersByCoinResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The top holders of the given coin + */ + public readonly result: AptosCurrentCoinBalanceDto[]; + + private constructor(input: AptosGetTopHoldersByCoinResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosCurrentCoinBalanceDto.create(item)); + } + + public toJSON(): AptosGetTopHoldersByCoinResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetTransactionByHash.ts b/packages/common/aptosUtils/src/generated/types/AptosGetTransactionByHash.ts new file mode 100644 index 0000000000..f38dc960df --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetTransactionByHash.ts @@ -0,0 +1,55 @@ +import { AptosPendingTransaction, AptosPendingTransactionJSON, AptosPendingTransactionInput } from '../types/AptosPendingTransaction'; +import { AptosUserTransaction, AptosUserTransactionJSON, AptosUserTransactionInput } from '../types/AptosUserTransaction'; +import { AptosGenesisTransaction, AptosGenesisTransactionJSON, AptosGenesisTransactionInput } from '../types/AptosGenesisTransaction'; +import { AptosBlockMetadataTransaction, AptosBlockMetadataTransactionJSON, AptosBlockMetadataTransactionInput } from '../types/AptosBlockMetadataTransaction'; +import { AptosStateCheckpointTransaction, AptosStateCheckpointTransactionJSON, AptosStateCheckpointTransactionInput } from '../types/AptosStateCheckpointTransaction'; + +// $ref: #/paths/~1transactions~1by_hash~1{txn_hash}/get/responses/200/content/application~1json/schema +// typeName: getTransactionByHash +// unionType: oneOf + +export type AptosGetTransactionByHashJSON = AptosPendingTransactionJSON | AptosUserTransactionJSON | AptosGenesisTransactionJSON | AptosBlockMetadataTransactionJSON | AptosStateCheckpointTransactionJSON; +export type AptosGetTransactionByHashInput = AptosPendingTransactionInput | AptosUserTransactionInput | AptosGenesisTransactionInput | AptosBlockMetadataTransactionInput | AptosStateCheckpointTransactionInput; +export type AptosGetTransactionByHashValue = AptosPendingTransaction | AptosUserTransaction | AptosGenesisTransaction | AptosBlockMetadataTransaction | AptosStateCheckpointTransaction; + +export abstract class AptosGetTransactionByHash { + public static create(input: AptosGetTransactionByHashInput): AptosGetTransactionByHashValue { + if (AptosPendingTransaction.isInput(input)) { + return AptosPendingTransaction.create(input); + } + if (AptosUserTransaction.isInput(input)) { + return AptosUserTransaction.create(input); + } + if (AptosGenesisTransaction.isInput(input)) { + return AptosGenesisTransaction.create(input); + } + if (AptosBlockMetadataTransaction.isInput(input)) { + return AptosBlockMetadataTransaction.create(input); + } + if (AptosStateCheckpointTransaction.isInput(input)) { + return AptosStateCheckpointTransaction.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosGetTransactionByHashJSON): AptosGetTransactionByHashValue { + if (AptosPendingTransaction.isJSON(json)) { + return AptosPendingTransaction.fromJSON(json); + } + if (AptosUserTransaction.isJSON(json)) { + return AptosUserTransaction.fromJSON(json); + } + if (AptosGenesisTransaction.isJSON(json)) { + return AptosGenesisTransaction.fromJSON(json); + } + if (AptosBlockMetadataTransaction.isJSON(json)) { + return AptosBlockMetadataTransaction.fromJSON(json); + } + if (AptosStateCheckpointTransaction.isJSON(json)) { + return AptosStateCheckpointTransaction.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosGetTransactionByHash (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetTransactionByVersion.ts b/packages/common/aptosUtils/src/generated/types/AptosGetTransactionByVersion.ts new file mode 100644 index 0000000000..f4edb21af1 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetTransactionByVersion.ts @@ -0,0 +1,55 @@ +import { AptosPendingTransaction, AptosPendingTransactionJSON, AptosPendingTransactionInput } from '../types/AptosPendingTransaction'; +import { AptosUserTransaction, AptosUserTransactionJSON, AptosUserTransactionInput } from '../types/AptosUserTransaction'; +import { AptosGenesisTransaction, AptosGenesisTransactionJSON, AptosGenesisTransactionInput } from '../types/AptosGenesisTransaction'; +import { AptosBlockMetadataTransaction, AptosBlockMetadataTransactionJSON, AptosBlockMetadataTransactionInput } from '../types/AptosBlockMetadataTransaction'; +import { AptosStateCheckpointTransaction, AptosStateCheckpointTransactionJSON, AptosStateCheckpointTransactionInput } from '../types/AptosStateCheckpointTransaction'; + +// $ref: #/paths/~1transactions~1by_version~1{txn_version}/get/responses/200/content/application~1json/schema +// typeName: getTransactionByVersion +// unionType: oneOf + +export type AptosGetTransactionByVersionJSON = AptosPendingTransactionJSON | AptosUserTransactionJSON | AptosGenesisTransactionJSON | AptosBlockMetadataTransactionJSON | AptosStateCheckpointTransactionJSON; +export type AptosGetTransactionByVersionInput = AptosPendingTransactionInput | AptosUserTransactionInput | AptosGenesisTransactionInput | AptosBlockMetadataTransactionInput | AptosStateCheckpointTransactionInput; +export type AptosGetTransactionByVersionValue = AptosPendingTransaction | AptosUserTransaction | AptosGenesisTransaction | AptosBlockMetadataTransaction | AptosStateCheckpointTransaction; + +export abstract class AptosGetTransactionByVersion { + public static create(input: AptosGetTransactionByVersionInput): AptosGetTransactionByVersionValue { + if (AptosPendingTransaction.isInput(input)) { + return AptosPendingTransaction.create(input); + } + if (AptosUserTransaction.isInput(input)) { + return AptosUserTransaction.create(input); + } + if (AptosGenesisTransaction.isInput(input)) { + return AptosGenesisTransaction.create(input); + } + if (AptosBlockMetadataTransaction.isInput(input)) { + return AptosBlockMetadataTransaction.create(input); + } + if (AptosStateCheckpointTransaction.isInput(input)) { + return AptosStateCheckpointTransaction.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosGetTransactionByVersionJSON): AptosGetTransactionByVersionValue { + if (AptosPendingTransaction.isJSON(json)) { + return AptosPendingTransaction.fromJSON(json); + } + if (AptosUserTransaction.isJSON(json)) { + return AptosUserTransaction.fromJSON(json); + } + if (AptosGenesisTransaction.isJSON(json)) { + return AptosGenesisTransaction.fromJSON(json); + } + if (AptosBlockMetadataTransaction.isJSON(json)) { + return AptosBlockMetadataTransaction.fromJSON(json); + } + if (AptosStateCheckpointTransaction.isJSON(json)) { + return AptosStateCheckpointTransaction.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosGetTransactionByVersion (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosGetTransactionsItem.ts b/packages/common/aptosUtils/src/generated/types/AptosGetTransactionsItem.ts new file mode 100644 index 0000000000..09c480a164 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosGetTransactionsItem.ts @@ -0,0 +1,55 @@ +import { AptosPendingTransaction, AptosPendingTransactionJSON, AptosPendingTransactionInput } from '../types/AptosPendingTransaction'; +import { AptosUserTransaction, AptosUserTransactionJSON, AptosUserTransactionInput } from '../types/AptosUserTransaction'; +import { AptosGenesisTransaction, AptosGenesisTransactionJSON, AptosGenesisTransactionInput } from '../types/AptosGenesisTransaction'; +import { AptosBlockMetadataTransaction, AptosBlockMetadataTransactionJSON, AptosBlockMetadataTransactionInput } from '../types/AptosBlockMetadataTransaction'; +import { AptosStateCheckpointTransaction, AptosStateCheckpointTransactionJSON, AptosStateCheckpointTransactionInput } from '../types/AptosStateCheckpointTransaction'; + +// $ref: #/paths/~1transactions/get/responses/200/content/application~1json/schema/items +// typeName: getTransactions_Item +// unionType: anyOf + +export type AptosGetTransactionsItemJSON = AptosPendingTransactionJSON | AptosUserTransactionJSON | AptosGenesisTransactionJSON | AptosBlockMetadataTransactionJSON | AptosStateCheckpointTransactionJSON; +export type AptosGetTransactionsItemInput = AptosPendingTransactionInput | AptosUserTransactionInput | AptosGenesisTransactionInput | AptosBlockMetadataTransactionInput | AptosStateCheckpointTransactionInput; +export type AptosGetTransactionsItemValue = AptosPendingTransaction | AptosUserTransaction | AptosGenesisTransaction | AptosBlockMetadataTransaction | AptosStateCheckpointTransaction; + +export abstract class AptosGetTransactionsItem { + public static create(input: AptosGetTransactionsItemInput): AptosGetTransactionsItemValue { + if (AptosPendingTransaction.isInput(input)) { + return AptosPendingTransaction.create(input); + } + if (AptosUserTransaction.isInput(input)) { + return AptosUserTransaction.create(input); + } + if (AptosGenesisTransaction.isInput(input)) { + return AptosGenesisTransaction.create(input); + } + if (AptosBlockMetadataTransaction.isInput(input)) { + return AptosBlockMetadataTransaction.create(input); + } + if (AptosStateCheckpointTransaction.isInput(input)) { + return AptosStateCheckpointTransaction.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosGetTransactionsItemJSON): AptosGetTransactionsItemValue { + if (AptosPendingTransaction.isJSON(json)) { + return AptosPendingTransaction.fromJSON(json); + } + if (AptosUserTransaction.isJSON(json)) { + return AptosUserTransaction.fromJSON(json); + } + if (AptosGenesisTransaction.isJSON(json)) { + return AptosGenesisTransaction.fromJSON(json); + } + if (AptosBlockMetadataTransaction.isJSON(json)) { + return AptosBlockMetadataTransaction.fromJSON(json); + } + if (AptosStateCheckpointTransaction.isJSON(json)) { + return AptosStateCheckpointTransaction.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosGetTransactionsItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosHistoricalCoinBalanceDto.ts b/packages/common/aptosUtils/src/generated/types/AptosHistoricalCoinBalanceDto.ts new file mode 100644 index 0000000000..d530d267b6 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosHistoricalCoinBalanceDto.ts @@ -0,0 +1,95 @@ +import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/HistoricalCoinBalanceDto +// type: HistoricalCoinBalanceDto +// properties: +// - amount ($ref: #/components/schemas/HistoricalCoinBalanceDto/properties/amount) +// - coin_type ($ref: #/components/schemas/HistoricalCoinBalanceDto/properties/coin_type) +// - coin_type_hash ($ref: #/components/schemas/HistoricalCoinBalanceDto/properties/coin_type_hash) +// - transaction_timestamp ($ref: #/components/schemas/HistoricalCoinBalanceDto/properties/transaction_timestamp) +// - transaction_version ($ref: #/components/schemas/HistoricalCoinBalanceDto/properties/transaction_version) +// - owner_address ($ref: #/components/schemas/HistoricalCoinBalanceDto/properties/owner_address) + +export interface AptosHistoricalCoinBalanceDtoJSON { + readonly amount: AptosNativeJSON; + readonly coin_type: string; + readonly coin_type_hash: string; + readonly transaction_timestamp: string; + readonly transaction_version: string; + readonly owner_address: AptosAddressJSON; +} + +export interface AptosHistoricalCoinBalanceDtoInput { + readonly amount: AptosNativeInput | AptosNative; + readonly coinType: string; + readonly coinTypeHash: string; + readonly transactionTimestamp: string; + readonly transactionVersion: string; + readonly ownerAddress: AptosAddressInput | AptosAddress; +} + +export class AptosHistoricalCoinBalanceDto { + public static create(input: AptosHistoricalCoinBalanceDtoInput | AptosHistoricalCoinBalanceDto): AptosHistoricalCoinBalanceDto { + if (input instanceof AptosHistoricalCoinBalanceDto) { + return input; + } + return new AptosHistoricalCoinBalanceDto(input); + } + + public static fromJSON(json: AptosHistoricalCoinBalanceDtoJSON): AptosHistoricalCoinBalanceDto { + const input: AptosHistoricalCoinBalanceDtoInput = { + amount: AptosNative.fromJSON(json.amount), + coinType: json.coin_type, + coinTypeHash: json.coin_type_hash, + transactionTimestamp: json.transaction_timestamp, + transactionVersion: json.transaction_version, + ownerAddress: AptosAddress.fromJSON(json.owner_address), + }; + return AptosHistoricalCoinBalanceDto.create(input); + } + + /** + * @description The amount being transfered + */ + public readonly amount: AptosNative; + /** + * @description The definition of the coin structure (identifier) + */ + public readonly coinType: string; + /** + * @description The hash of the coin_type (identifier) and a known fixed length + */ + public readonly coinTypeHash: string; + /** + * @description The timestamp of the updated balance + */ + public readonly transactionTimestamp: string; + /** + * @description The version of the transaction where the balacne was updated + */ + public readonly transactionVersion: string; + /** + * @description The address of the owner of the coin + */ + public readonly ownerAddress: AptosAddress; + + private constructor(input: AptosHistoricalCoinBalanceDtoInput) { + this.amount = AptosNative.create(input.amount); + this.coinType = input.coinType; + this.coinTypeHash = input.coinTypeHash; + this.transactionTimestamp = input.transactionTimestamp; + this.transactionVersion = input.transactionVersion; + this.ownerAddress = AptosAddress.create(input.ownerAddress); + } + + public toJSON(): AptosHistoricalCoinBalanceDtoJSON { + return { + amount: this.amount.toJSON(), + coin_type: this.coinType, + coin_type_hash: this.coinTypeHash, + transaction_timestamp: this.transactionTimestamp, + transaction_version: this.transactionVersion, + owner_address: this.ownerAddress.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosModuleBundlePayloadRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosModuleBundlePayloadRequest.ts new file mode 100644 index 0000000000..2cbf87c856 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosModuleBundlePayloadRequest.ts @@ -0,0 +1,55 @@ +// $ref: #/components/schemas/ModuleBundlePayloadRequest +// type: ModuleBundlePayloadRequest +// properties: +// - type ($ref: #/components/schemas/ModuleBundlePayloadRequest/properties/type) +// - modules ($ref: #/components/schemas/ModuleBundlePayloadRequest/properties/modules) + +export interface AptosModuleBundlePayloadRequestJSON { + readonly type: string; + readonly modules: string[]; +} + +export interface AptosModuleBundlePayloadRequestInput { + readonly type: string; + readonly modules: string[]; +} + +export class AptosModuleBundlePayloadRequest { + public static create(input: AptosModuleBundlePayloadRequestInput | AptosModuleBundlePayloadRequest): AptosModuleBundlePayloadRequest { + if (input instanceof AptosModuleBundlePayloadRequest) { + return input; + } + return new AptosModuleBundlePayloadRequest(input); + } + + public static fromJSON(json: AptosModuleBundlePayloadRequestJSON): AptosModuleBundlePayloadRequest { + const input: AptosModuleBundlePayloadRequestInput = { + type: json.type, + modules: json.modules, + }; + return AptosModuleBundlePayloadRequest.create(input); + } + + public static isInput(input: any): input is AptosModuleBundlePayloadRequestInput { + return ["type","modules"].every((name) => input[name] !== undefined); + } + + public static isJSON(json: any): json is AptosModuleBundlePayloadRequestJSON { + return ["type","modules"].every((name) => json[name] !== undefined); + } + + public readonly type: string; + public readonly modules: string[]; + + private constructor(input: AptosModuleBundlePayloadRequestInput) { + this.type = input.type; + this.modules = input.modules; + } + + public toJSON(): AptosModuleBundlePayloadRequestJSON { + return { + type: this.type, + modules: this.modules, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosModuleExposedFunction.ts b/packages/common/aptosUtils/src/generated/types/AptosModuleExposedFunction.ts new file mode 100644 index 0000000000..629ca06c5e --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosModuleExposedFunction.ts @@ -0,0 +1,95 @@ +import { AptosGenericTypeParam, AptosGenericTypeParamInput, AptosGenericTypeParamJSON } from '../types/AptosGenericTypeParam'; + +// $ref: #/components/schemas/ModuleExposedFunction +// type: ModuleExposedFunction +// properties: +// - name ($ref: #/components/schemas/ModuleExposedFunction/properties/name) +// - visibility ($ref: #/components/schemas/ModuleExposedFunction/properties/visibility) +// - is_entry ($ref: #/components/schemas/ModuleExposedFunction/properties/is_entry) +// - generic_type_params ($ref: #/components/schemas/GenericTypeParam) +// - params ($ref: #/components/schemas/ModuleExposedFunction/properties/params) +// - return ($ref: #/components/schemas/ModuleExposedFunction/properties/return) + +export interface AptosModuleExposedFunctionJSON { + readonly name: string; + readonly visibility: string; + readonly is_entry: boolean; + readonly generic_type_params: AptosGenericTypeParamJSON[]; + readonly params: string[]; + readonly return: string[]; +} + +export interface AptosModuleExposedFunctionInput { + readonly name: string; + readonly visibility: string; + readonly isEntry: boolean; + readonly genericTypeParams: AptosGenericTypeParamInput[] | AptosGenericTypeParam[]; + readonly params: string[]; + readonly return: string[]; +} + +export class AptosModuleExposedFunction { + public static create(input: AptosModuleExposedFunctionInput | AptosModuleExposedFunction): AptosModuleExposedFunction { + if (input instanceof AptosModuleExposedFunction) { + return input; + } + return new AptosModuleExposedFunction(input); + } + + public static fromJSON(json: AptosModuleExposedFunctionJSON): AptosModuleExposedFunction { + const input: AptosModuleExposedFunctionInput = { + name: json.name, + visibility: json.visibility, + isEntry: json.is_entry, + genericTypeParams: json.generic_type_params.map((item) => AptosGenericTypeParam.fromJSON(item)), + params: json.params, + return: json.return, + }; + return AptosModuleExposedFunction.create(input); + } + + /** + * @description Name of the function + */ + public readonly name: string; + /** + * @description Move function visibility + */ + public readonly visibility: string; + /** + * @description Whether the function can be called as an entry function directly in a transaction + */ + public readonly isEntry: boolean; + /** + * @description Generic type params associated with the Move function + */ + public readonly genericTypeParams: AptosGenericTypeParam[]; + /** + * @description Parameters associated with the move function + */ + public readonly params: string[]; + /** + * @description Return type of the function + */ + public readonly return: string[]; + + private constructor(input: AptosModuleExposedFunctionInput) { + this.name = input.name; + this.visibility = input.visibility; + this.isEntry = input.isEntry; + this.genericTypeParams = input.genericTypeParams.map((item) => AptosGenericTypeParam.create(item)); + this.params = input.params; + this.return = input.return; + } + + public toJSON(): AptosModuleExposedFunctionJSON { + return { + name: this.name, + visibility: this.visibility, + is_entry: this.isEntry, + generic_type_params: this.genericTypeParams.map((item) => item.toJSON()), + params: this.params, + return: this.return, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosModuleStruct.ts b/packages/common/aptosUtils/src/generated/types/AptosModuleStruct.ts new file mode 100644 index 0000000000..5197eb2075 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosModuleStruct.ts @@ -0,0 +1,86 @@ +import { AptosGenericTypeParam, AptosGenericTypeParamInput, AptosGenericTypeParamJSON } from '../types/AptosGenericTypeParam'; +import { AptosModuleStructField, AptosModuleStructFieldInput, AptosModuleStructFieldJSON } from '../types/AptosModuleStructField'; + +// $ref: #/components/schemas/ModuleStruct +// type: ModuleStruct +// properties: +// - name ($ref: #/components/schemas/ModuleStruct/properties/name) +// - is_native ($ref: #/components/schemas/ModuleStruct/properties/is_native) +// - abilities ($ref: #/components/schemas/ModuleStruct/properties/abilities) +// - generic_type_params ($ref: #/components/schemas/GenericTypeParam) +// - fields ($ref: #/components/schemas/ModuleStructField) + +export interface AptosModuleStructJSON { + readonly name: string; + readonly is_native: boolean; + readonly abilities: string[]; + readonly generic_type_params: AptosGenericTypeParamJSON[]; + readonly fields: AptosModuleStructFieldJSON[]; +} + +export interface AptosModuleStructInput { + readonly name: string; + readonly isNative: boolean; + readonly abilities: string[]; + readonly genericTypeParams: AptosGenericTypeParamInput[] | AptosGenericTypeParam[]; + readonly fields: AptosModuleStructFieldInput[] | AptosModuleStructField[]; +} + +export class AptosModuleStruct { + public static create(input: AptosModuleStructInput | AptosModuleStruct): AptosModuleStruct { + if (input instanceof AptosModuleStruct) { + return input; + } + return new AptosModuleStruct(input); + } + + public static fromJSON(json: AptosModuleStructJSON): AptosModuleStruct { + const input: AptosModuleStructInput = { + name: json.name, + isNative: json.is_native, + abilities: json.abilities, + genericTypeParams: json.generic_type_params.map((item) => AptosGenericTypeParam.fromJSON(item)), + fields: json.fields.map((item) => AptosModuleStructField.fromJSON(item)), + }; + return AptosModuleStruct.create(input); + } + + /** + * @description Name of the struct + */ + public readonly name: string; + /** + * @description Whether the struct is a native struct of Move + */ + public readonly isNative: boolean; + /** + * @description Abilities associated with the struct + */ + public readonly abilities: string[]; + /** + * @description Generic types associated with the struct + */ + public readonly genericTypeParams: AptosGenericTypeParam[]; + /** + * @description Fields associated with the struct + */ + public readonly fields: AptosModuleStructField[]; + + private constructor(input: AptosModuleStructInput) { + this.name = input.name; + this.isNative = input.isNative; + this.abilities = input.abilities; + this.genericTypeParams = input.genericTypeParams.map((item) => AptosGenericTypeParam.create(item)); + this.fields = input.fields.map((item) => AptosModuleStructField.create(item)); + } + + public toJSON(): AptosModuleStructJSON { + return { + name: this.name, + is_native: this.isNative, + abilities: this.abilities, + generic_type_params: this.genericTypeParams.map((item) => item.toJSON()), + fields: this.fields.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosModuleStructField.ts b/packages/common/aptosUtils/src/generated/types/AptosModuleStructField.ts new file mode 100644 index 0000000000..37d81a9520 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosModuleStructField.ts @@ -0,0 +1,53 @@ +// $ref: #/components/schemas/ModuleStructField +// type: ModuleStructField +// properties: +// - name ($ref: #/components/schemas/ModuleStructField/properties/name) +// - type ($ref: #/components/schemas/ModuleStructField/properties/type) + +export interface AptosModuleStructFieldJSON { + readonly name: string; + readonly type: string; +} + +export interface AptosModuleStructFieldInput { + readonly name: string; + readonly type: string; +} + +export class AptosModuleStructField { + public static create(input: AptosModuleStructFieldInput | AptosModuleStructField): AptosModuleStructField { + if (input instanceof AptosModuleStructField) { + return input; + } + return new AptosModuleStructField(input); + } + + public static fromJSON(json: AptosModuleStructFieldJSON): AptosModuleStructField { + const input: AptosModuleStructFieldInput = { + name: json.name, + type: json.type, + }; + return AptosModuleStructField.create(input); + } + + /** + * @description Name of the field + */ + public readonly name: string; + /** + * @description String representation of an on-chain Move type tag that is exposed in transaction payload. + */ + public readonly type: string; + + private constructor(input: AptosModuleStructFieldInput) { + this.name = input.name; + this.type = input.type; + } + + public toJSON(): AptosModuleStructFieldJSON { + return { + name: this.name, + type: this.type, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosMoveModuleAbi.ts b/packages/common/aptosUtils/src/generated/types/AptosMoveModuleAbi.ts new file mode 100644 index 0000000000..11867f641d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosMoveModuleAbi.ts @@ -0,0 +1,84 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosModuleExposedFunction, AptosModuleExposedFunctionInput, AptosModuleExposedFunctionJSON } from '../types/AptosModuleExposedFunction'; +import { AptosModuleStruct, AptosModuleStructInput, AptosModuleStructJSON } from '../types/AptosModuleStruct'; + +// $ref: #/components/schemas/MoveModuleAbi +// type: MoveModuleAbi +// properties: +// - address ($ref: #/components/schemas/MoveModuleAbi/properties/address) +// - name ($ref: #/components/schemas/MoveModuleAbi/properties/name) +// - friends ($ref: #/components/schemas/MoveModuleAbi/properties/friends) +// - exposed_functions ($ref: #/components/schemas/ModuleExposedFunction) +// - structs ($ref: #/components/schemas/ModuleStruct) + +export interface AptosMoveModuleAbiJSON { + readonly address: AptosAddressJSON; + readonly name: string; + readonly friends: string[]; + readonly exposed_functions: AptosModuleExposedFunctionJSON[]; + readonly structs: AptosModuleStructJSON[]; +} + +export interface AptosMoveModuleAbiInput { + readonly address: AptosAddressInput | AptosAddress; + readonly name: string; + readonly friends: string[]; + readonly exposedFunctions: AptosModuleExposedFunctionInput[] | AptosModuleExposedFunction[]; + readonly structs: AptosModuleStructInput[] | AptosModuleStruct[]; +} + +export class AptosMoveModuleAbi { + public static create(input: AptosMoveModuleAbiInput | AptosMoveModuleAbi): AptosMoveModuleAbi { + if (input instanceof AptosMoveModuleAbi) { + return input; + } + return new AptosMoveModuleAbi(input); + } + + public static fromJSON(json: AptosMoveModuleAbiJSON): AptosMoveModuleAbi { + const input: AptosMoveModuleAbiInput = { + address: AptosAddress.fromJSON(json.address), + name: json.name, + friends: json.friends, + exposedFunctions: json.exposed_functions.map((item) => AptosModuleExposedFunction.fromJSON(item)), + structs: json.structs.map((item) => AptosModuleStruct.fromJSON(item)), + }; + return AptosMoveModuleAbi.create(input); + } + + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly address: AptosAddress; + public readonly name: string; + /** + * @description Friends of the module + */ + public readonly friends: string[]; + /** + * @description Public functions of the module + */ + public readonly exposedFunctions: AptosModuleExposedFunction[]; + /** + * @description Structs of the module + */ + public readonly structs: AptosModuleStruct[]; + + private constructor(input: AptosMoveModuleAbiInput) { + this.address = AptosAddress.create(input.address); + this.name = input.name; + this.friends = input.friends; + this.exposedFunctions = input.exposedFunctions.map((item) => AptosModuleExposedFunction.create(item)); + this.structs = input.structs.map((item) => AptosModuleStruct.create(item)); + } + + public toJSON(): AptosMoveModuleAbiJSON { + return { + address: this.address.toJSON(), + name: this.name, + friends: this.friends, + exposed_functions: this.exposedFunctions.map((item) => item.toJSON()), + structs: this.structs.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequest.ts new file mode 100644 index 0000000000..2b5d409b8d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequest.ts @@ -0,0 +1,75 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosMultiAgentSignatureRequestSecondarySigners, AptosMultiAgentSignatureRequestSecondarySignersValue, AptosMultiAgentSignatureRequestSecondarySignersInput, AptosMultiAgentSignatureRequestSecondarySignersJSON } from '../types/AptosMultiAgentSignatureRequestSecondarySigners'; + +// $ref: #/components/schemas/MultiAgentSignatureRequest +// type: MultiAgentSignatureRequest +// properties: +// - type ($ref: #/components/schemas/MultiAgentSignatureRequest/properties/type) +// - sender ($ref: #/components/schemas/MultiAgentSignatureRequest/properties/sender) +// - secondary_signer_addresses ($ref: #/components/schemas/MultiAgentSignatureRequest/properties/secondary_signer_addresses) +// - secondary_signers ($ref: #/components/schemas/MultiAgentSignatureRequest/properties/secondary_signers) + +export interface AptosMultiAgentSignatureRequestJSON { + readonly type: string; + readonly sender: AptosAddressJSON; + readonly secondary_signer_addresses: string[]; + readonly secondary_signers: AptosMultiAgentSignatureRequestSecondarySignersJSON; +} + +export interface AptosMultiAgentSignatureRequestInput { + readonly type: string; + readonly sender: AptosAddressInput | AptosAddress; + readonly secondarySignerAddresses: string[]; + readonly secondarySigners: AptosMultiAgentSignatureRequestSecondarySignersInput | AptosMultiAgentSignatureRequestSecondarySignersValue; +} + +export class AptosMultiAgentSignatureRequest { + public static create(input: AptosMultiAgentSignatureRequestInput | AptosMultiAgentSignatureRequest): AptosMultiAgentSignatureRequest { + if (input instanceof AptosMultiAgentSignatureRequest) { + return input; + } + return new AptosMultiAgentSignatureRequest(input); + } + + public static fromJSON(json: AptosMultiAgentSignatureRequestJSON): AptosMultiAgentSignatureRequest { + const input: AptosMultiAgentSignatureRequestInput = { + type: json.type, + sender: AptosAddress.fromJSON(json.sender), + secondarySignerAddresses: json.secondary_signer_addresses, + secondarySigners: AptosMultiAgentSignatureRequestSecondarySigners.fromJSON(json.secondary_signers), + }; + return AptosMultiAgentSignatureRequest.create(input); + } + + public static isInput(input: any): input is AptosMultiAgentSignatureRequestInput { + return ["type","sender","secondarySignerAddresses","secondarySigners"].every((name) => input[name] !== undefined); + } + + public static isJSON(json: any): json is AptosMultiAgentSignatureRequestJSON { + return ["type","sender","secondary_signer_addresses","secondary_signers"].every((name) => json[name] !== undefined); + } + + public readonly type: string; + public readonly sender: AptosAddress; + /** + * @description The other involved parties addresses + */ + public readonly secondarySignerAddresses: string[]; + public readonly secondarySigners: AptosMultiAgentSignatureRequestSecondarySignersValue; + + private constructor(input: AptosMultiAgentSignatureRequestInput) { + this.type = input.type; + this.sender = AptosAddress.create(input.sender); + this.secondarySignerAddresses = input.secondarySignerAddresses; + this.secondarySigners = AptosMultiAgentSignatureRequestSecondarySigners.create(input.secondarySigners); + } + + public toJSON(): AptosMultiAgentSignatureRequestJSON { + return { + type: this.type, + sender: this.sender.toJSON(), + secondary_signer_addresses: this.secondarySignerAddresses, + secondary_signers: this.secondarySigners.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequestSecondarySigners.ts b/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequestSecondarySigners.ts new file mode 100644 index 0000000000..4cf703b157 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequestSecondarySigners.ts @@ -0,0 +1,34 @@ +import { AptosEd25519SignatureRequest, AptosEd25519SignatureRequestJSON, AptosEd25519SignatureRequestInput } from '../types/AptosEd25519SignatureRequest'; +import { AptosMultiEd25519SignatureRequest, AptosMultiEd25519SignatureRequestJSON, AptosMultiEd25519SignatureRequestInput } from '../types/AptosMultiEd25519SignatureRequest'; + +// $ref: #/components/schemas/MultiAgentSignatureRequest/properties/secondary_signers +// typeName: MultiAgentSignatureRequest_secondary_signers +// unionType: oneOf + +export type AptosMultiAgentSignatureRequestSecondarySignersJSON = AptosEd25519SignatureRequestJSON | AptosMultiEd25519SignatureRequestJSON; +export type AptosMultiAgentSignatureRequestSecondarySignersInput = AptosEd25519SignatureRequestInput | AptosMultiEd25519SignatureRequestInput; +export type AptosMultiAgentSignatureRequestSecondarySignersValue = AptosEd25519SignatureRequest | AptosMultiEd25519SignatureRequest; + +export abstract class AptosMultiAgentSignatureRequestSecondarySigners { + public static create(input: AptosMultiAgentSignatureRequestSecondarySignersInput): AptosMultiAgentSignatureRequestSecondarySignersValue { + if (AptosEd25519SignatureRequest.isInput(input)) { + return AptosEd25519SignatureRequest.create(input); + } + if (AptosMultiEd25519SignatureRequest.isInput(input)) { + return AptosMultiEd25519SignatureRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosMultiAgentSignatureRequestSecondarySignersJSON): AptosMultiAgentSignatureRequestSecondarySignersValue { + if (AptosEd25519SignatureRequest.isJSON(json)) { + return AptosEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiEd25519SignatureRequest.isJSON(json)) { + return AptosMultiEd25519SignatureRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosMultiAgentSignatureRequestSecondarySigners (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequestSender.ts b/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequestSender.ts new file mode 100644 index 0000000000..6fe19e51d8 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosMultiAgentSignatureRequestSender.ts @@ -0,0 +1,34 @@ +import { AptosEd25519SignatureRequest, AptosEd25519SignatureRequestJSON, AptosEd25519SignatureRequestInput } from '../types/AptosEd25519SignatureRequest'; +import { AptosMultiEd25519SignatureRequest, AptosMultiEd25519SignatureRequestJSON, AptosMultiEd25519SignatureRequestInput } from '../types/AptosMultiEd25519SignatureRequest'; + +// $ref: #/components/schemas/MultiAgentSignatureRequest/properties/sender +// typeName: MultiAgentSignatureRequest_sender +// unionType: oneOf + +export type AptosMultiAgentSignatureRequestSenderJSON = AptosEd25519SignatureRequestJSON | AptosMultiEd25519SignatureRequestJSON; +export type AptosMultiAgentSignatureRequestSenderInput = AptosEd25519SignatureRequestInput | AptosMultiEd25519SignatureRequestInput; +export type AptosMultiAgentSignatureRequestSenderValue = AptosEd25519SignatureRequest | AptosMultiEd25519SignatureRequest; + +export abstract class AptosMultiAgentSignatureRequestSender { + public static create(input: AptosMultiAgentSignatureRequestSenderInput): AptosMultiAgentSignatureRequestSenderValue { + if (AptosEd25519SignatureRequest.isInput(input)) { + return AptosEd25519SignatureRequest.create(input); + } + if (AptosMultiEd25519SignatureRequest.isInput(input)) { + return AptosMultiEd25519SignatureRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosMultiAgentSignatureRequestSenderJSON): AptosMultiAgentSignatureRequestSenderValue { + if (AptosEd25519SignatureRequest.isJSON(json)) { + return AptosEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiEd25519SignatureRequest.isJSON(json)) { + return AptosMultiEd25519SignatureRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosMultiAgentSignatureRequestSender (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosMultiEd25519SignatureRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosMultiEd25519SignatureRequest.ts new file mode 100644 index 0000000000..9ba9b2c43d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosMultiEd25519SignatureRequest.ts @@ -0,0 +1,88 @@ +// $ref: #/components/schemas/MultiEd25519SignatureRequest +// type: MultiEd25519SignatureRequest +// properties: +// - type ($ref: #/components/schemas/MultiEd25519SignatureRequest/properties/type) +// - public_keys ($ref: #/components/schemas/MultiEd25519SignatureRequest/properties/public_keys) +// - signatures ($ref: #/components/schemas/MultiEd25519SignatureRequest/properties/signatures) +// - threshold ($ref: #/components/schemas/MultiEd25519SignatureRequest/properties/threshold) +// - bitmap ($ref: #/components/schemas/MultiEd25519SignatureRequest/properties/bitmap) + +export interface AptosMultiEd25519SignatureRequestJSON { + readonly type: string; + readonly public_keys: string[]; + readonly signatures: string[]; + readonly threshold: number; + readonly bitmap: string; +} + +export interface AptosMultiEd25519SignatureRequestInput { + readonly type: string; + readonly publicKeys: string[]; + readonly signatures: string[]; + readonly threshold: number; + readonly bitmap: string; +} + +export class AptosMultiEd25519SignatureRequest { + public static create(input: AptosMultiEd25519SignatureRequestInput | AptosMultiEd25519SignatureRequest): AptosMultiEd25519SignatureRequest { + if (input instanceof AptosMultiEd25519SignatureRequest) { + return input; + } + return new AptosMultiEd25519SignatureRequest(input); + } + + public static fromJSON(json: AptosMultiEd25519SignatureRequestJSON): AptosMultiEd25519SignatureRequest { + const input: AptosMultiEd25519SignatureRequestInput = { + type: json.type, + publicKeys: json.public_keys, + signatures: json.signatures, + threshold: json.threshold, + bitmap: json.bitmap, + }; + return AptosMultiEd25519SignatureRequest.create(input); + } + + public static isInput(input: any): input is AptosMultiEd25519SignatureRequestInput { + return ["type","publicKeys","signatures","threshold","bitmap"].every((name) => input[name] !== undefined); + } + + public static isJSON(json: any): json is AptosMultiEd25519SignatureRequestJSON { + return ["type","public_keys","signatures","threshold","bitmap"].every((name) => json[name] !== undefined); + } + + public readonly type: string; + /** + * @description The public keys for the Ed25519 signature + */ + public readonly publicKeys: string[]; + /** + * @description Signature associated with the public keys in the same order + */ + public readonly signatures: string[]; + /** + * @description The number of signatures required for a successful transaction + */ + public readonly threshold: number; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly bitmap: string; + + private constructor(input: AptosMultiEd25519SignatureRequestInput) { + this.type = input.type; + this.publicKeys = input.publicKeys; + this.signatures = input.signatures; + this.threshold = input.threshold; + this.bitmap = input.bitmap; + } + + public toJSON(): AptosMultiEd25519SignatureRequestJSON { + return { + type: this.type, + public_keys: this.publicKeys, + signatures: this.signatures, + threshold: this.threshold, + bitmap: this.bitmap, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionItemResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionItemResponse.ts new file mode 100644 index 0000000000..01b91f1678 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionItemResponse.ts @@ -0,0 +1,165 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/NFTCollectionItemResponse +// type: NFTCollectionItemResponse +// properties: +// - collection_data_id_hash ($ref: #/components/schemas/NFTCollectionItemResponse/properties/collection_data_id_hash) +// - collection_name ($ref: #/components/schemas/NFTCollectionItemResponse/properties/collection_name) +// - creator_address ($ref: #/components/schemas/NFTCollectionItemResponse/properties/creator_address) +// - description ($ref: #/components/schemas/NFTCollectionItemResponse/properties/description) +// - description_mutable ($ref: #/components/schemas/NFTCollectionItemResponse/properties/description_mutable) +// - last_transaction_timestamp ($ref: #/components/schemas/NFTCollectionItemResponse/properties/last_transaction_timestamp) +// - last_transaction_version ($ref: #/components/schemas/NFTCollectionItemResponse/properties/last_transaction_version) +// - maximum ($ref: #/components/schemas/NFTCollectionItemResponse/properties/maximum) +// - maximum_mutable ($ref: #/components/schemas/NFTCollectionItemResponse/properties/maximum_mutable) +// - metadata_uri ($ref: #/components/schemas/NFTCollectionItemResponse/properties/metadata_uri) +// - supply ($ref: #/components/schemas/NFTCollectionItemResponse/properties/supply) +// - table_handle ($ref: #/components/schemas/NFTCollectionItemResponse/properties/table_handle) +// - uri_mutable ($ref: #/components/schemas/NFTCollectionItemResponse/properties/uri_mutable) + +export interface AptosNFTCollectionItemResponseJSON { + readonly collection_data_id_hash: string; + readonly collection_name: string; + readonly creator_address: AptosAddressJSON; + readonly description: string; + readonly description_mutable: boolean; + readonly last_transaction_timestamp: string; + readonly last_transaction_version: string; + readonly maximum: string; + readonly maximum_mutable: boolean; + readonly metadata_uri: string; + readonly supply: string; + readonly table_handle: string; + readonly uri_mutable: boolean; +} + +export interface AptosNFTCollectionItemResponseInput { + readonly collectionDataIdHash: string; + readonly collectionName: string; + readonly creatorAddress: AptosAddressInput | AptosAddress; + readonly description: string; + readonly descriptionMutable: boolean; + readonly lastTransactionTimestamp: string; + readonly lastTransactionVersion: string; + readonly maximum: string; + readonly maximumMutable: boolean; + readonly metadataUri: string; + readonly supply: string; + readonly tableHandle: string; + readonly uriMutable: boolean; +} + +export class AptosNFTCollectionItemResponse { + public static create(input: AptosNFTCollectionItemResponseInput | AptosNFTCollectionItemResponse): AptosNFTCollectionItemResponse { + if (input instanceof AptosNFTCollectionItemResponse) { + return input; + } + return new AptosNFTCollectionItemResponse(input); + } + + public static fromJSON(json: AptosNFTCollectionItemResponseJSON): AptosNFTCollectionItemResponse { + const input: AptosNFTCollectionItemResponseInput = { + collectionDataIdHash: json.collection_data_id_hash, + collectionName: json.collection_name, + creatorAddress: AptosAddress.fromJSON(json.creator_address), + description: json.description, + descriptionMutable: json.description_mutable, + lastTransactionTimestamp: json.last_transaction_timestamp, + lastTransactionVersion: json.last_transaction_version, + maximum: json.maximum, + maximumMutable: json.maximum_mutable, + metadataUri: json.metadata_uri, + supply: json.supply, + tableHandle: json.table_handle, + uriMutable: json.uri_mutable, + }; + return AptosNFTCollectionItemResponse.create(input); + } + + /** + * @description The identifier of the collection + */ + public readonly collectionDataIdHash: string; + /** + * @description The name of the collection + */ + public readonly collectionName: string; + /** + * @description The address of the creator of the collection + */ + public readonly creatorAddress: AptosAddress; + /** + * @description The description of the collection + */ + public readonly description: string; + /** + * @description Whether the description can be changed + */ + public readonly descriptionMutable: boolean; + /** + * @description The timestamp of the last transaction + */ + public readonly lastTransactionTimestamp: string; + /** + * @description The version of the last transaction + */ + public readonly lastTransactionVersion: string; + /** + * @description The maximum number of tokens that can be minted + */ + public readonly maximum: string; + /** + * @description Whether the maximum number of tokens can be changed + */ + public readonly maximumMutable: boolean; + /** + * @description The URI of the image of the collection + */ + public readonly metadataUri: string; + /** + * @description The number of tokens minted + */ + public readonly supply: string; + /** + * @description The address of the table that stores the tokens + */ + public readonly tableHandle: string; + /** + * @description Whether the URI of the image can be changed + */ + public readonly uriMutable: boolean; + + private constructor(input: AptosNFTCollectionItemResponseInput) { + this.collectionDataIdHash = input.collectionDataIdHash; + this.collectionName = input.collectionName; + this.creatorAddress = AptosAddress.create(input.creatorAddress); + this.description = input.description; + this.descriptionMutable = input.descriptionMutable; + this.lastTransactionTimestamp = input.lastTransactionTimestamp; + this.lastTransactionVersion = input.lastTransactionVersion; + this.maximum = input.maximum; + this.maximumMutable = input.maximumMutable; + this.metadataUri = input.metadataUri; + this.supply = input.supply; + this.tableHandle = input.tableHandle; + this.uriMutable = input.uriMutable; + } + + public toJSON(): AptosNFTCollectionItemResponseJSON { + return { + collection_data_id_hash: this.collectionDataIdHash, + collection_name: this.collectionName, + creator_address: this.creatorAddress.toJSON(), + description: this.description, + description_mutable: this.descriptionMutable, + last_transaction_timestamp: this.lastTransactionTimestamp, + last_transaction_version: this.lastTransactionVersion, + maximum: this.maximum, + maximum_mutable: this.maximumMutable, + metadata_uri: this.metadataUri, + supply: this.supply, + table_handle: this.tableHandle, + uri_mutable: this.uriMutable, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionsByCreatorResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionsByCreatorResponse.ts new file mode 100644 index 0000000000..f44f2ee5f0 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionsByCreatorResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTCollectionItemResponse, AptosNFTCollectionItemResponseInput, AptosNFTCollectionItemResponseJSON } from '../types/AptosNFTCollectionItemResponse'; + +// $ref: #/components/schemas/NFTCollectionsByCreatorResponse +// type: NFTCollectionsByCreatorResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTCollectionsByCreatorResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTCollectionsByCreatorResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTCollectionItemResponse) + +export interface AptosNFTCollectionsByCreatorResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTCollectionItemResponseJSON[]; +} + +export interface AptosNFTCollectionsByCreatorResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTCollectionItemResponseInput[] | AptosNFTCollectionItemResponse[]; +} + +export class AptosNFTCollectionsByCreatorResponse { + public static create(input: AptosNFTCollectionsByCreatorResponseInput | AptosNFTCollectionsByCreatorResponse): AptosNFTCollectionsByCreatorResponse { + if (input instanceof AptosNFTCollectionsByCreatorResponse) { + return input; + } + return new AptosNFTCollectionsByCreatorResponse(input); + } + + public static fromJSON(json: AptosNFTCollectionsByCreatorResponseJSON): AptosNFTCollectionsByCreatorResponse { + const input: AptosNFTCollectionsByCreatorResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTCollectionItemResponse.fromJSON(item)), + }; + return AptosNFTCollectionsByCreatorResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creator + */ + public readonly result: AptosNFTCollectionItemResponse[]; + + private constructor(input: AptosNFTCollectionsByCreatorResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTCollectionItemResponse.create(item)); + } + + public toJSON(): AptosNFTCollectionsByCreatorResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionsByNameRangeResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionsByNameRangeResponse.ts new file mode 100644 index 0000000000..b456108765 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTCollectionsByNameRangeResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTCollectionItemResponse, AptosNFTCollectionItemResponseInput, AptosNFTCollectionItemResponseJSON } from '../types/AptosNFTCollectionItemResponse'; + +// $ref: #/components/schemas/NFTCollectionsByNameRangeResponse +// type: NFTCollectionsByNameRangeResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTCollectionsByNameRangeResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTCollectionsByNameRangeResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTCollectionItemResponse) + +export interface AptosNFTCollectionsByNameRangeResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTCollectionItemResponseJSON[]; +} + +export interface AptosNFTCollectionsByNameRangeResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTCollectionItemResponseInput[] | AptosNFTCollectionItemResponse[]; +} + +export class AptosNFTCollectionsByNameRangeResponse { + public static create(input: AptosNFTCollectionsByNameRangeResponseInput | AptosNFTCollectionsByNameRangeResponse): AptosNFTCollectionsByNameRangeResponse { + if (input instanceof AptosNFTCollectionsByNameRangeResponse) { + return input; + } + return new AptosNFTCollectionsByNameRangeResponse(input); + } + + public static fromJSON(json: AptosNFTCollectionsByNameRangeResponseJSON): AptosNFTCollectionsByNameRangeResponse { + const input: AptosNFTCollectionsByNameRangeResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTCollectionItemResponse.fromJSON(item)), + }; + return AptosNFTCollectionsByNameRangeResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creator + */ + public readonly result: AptosNFTCollectionItemResponse[]; + + private constructor(input: AptosNFTCollectionsByNameRangeResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTCollectionItemResponse.create(item)); + } + + public toJSON(): AptosNFTCollectionsByNameRangeResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTOwnerResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnerResponse.ts new file mode 100644 index 0000000000..fd3dd0b3c5 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnerResponse.ts @@ -0,0 +1,156 @@ +import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosNFTOwnerResponseTokenProperties, AptosNFTOwnerResponseTokenPropertiesValue, AptosNFTOwnerResponseTokenPropertiesInput, AptosNFTOwnerResponseTokenPropertiesJSON } from '../types/AptosNFTOwnerResponseTokenProperties'; + +// $ref: #/components/schemas/NFTOwnerResponse +// type: NFTOwnerResponse +// properties: +// - amount ($ref: #/components/schemas/NFTOwnerResponse/properties/amount) +// - collection_data_id_hash ($ref: #/components/schemas/NFTOwnerResponse/properties/collection_data_id_hash) +// - collection_name ($ref: #/components/schemas/NFTOwnerResponse/properties/collection_name) +// - creator_address ($ref: #/components/schemas/NFTOwnerResponse/properties/creator_address) +// - last_transaction_timestamp ($ref: #/components/schemas/NFTOwnerResponse/properties/last_transaction_timestamp) +// - last_transaction_version ($ref: #/components/schemas/NFTOwnerResponse/properties/last_transaction_version) +// - name ($ref: #/components/schemas/NFTOwnerResponse/properties/name) +// - owner_address ($ref: #/components/schemas/NFTOwnerResponse/properties/owner_address) +// - property_version ($ref: #/components/schemas/NFTOwnerResponse/properties/property_version) +// - table_type ($ref: #/components/schemas/NFTOwnerResponse/properties/table_type) +// - token_data_id_hash ($ref: #/components/schemas/NFTOwnerResponse/properties/token_data_id_hash) +// - token_properties ($ref: #/components/schemas/NFTOwnerResponse/properties/token_properties) + +export interface AptosNFTOwnerResponseJSON { + readonly amount: AptosNativeJSON; + readonly collection_data_id_hash: string; + readonly collection_name: string; + readonly creator_address: AptosAddressJSON; + readonly last_transaction_timestamp: string; + readonly last_transaction_version: string; + readonly name: string; + readonly owner_address: AptosAddressJSON; + readonly property_version: string; + readonly table_type: string; + readonly token_data_id_hash: string; + readonly token_properties: AptosNFTOwnerResponseTokenPropertiesJSON; +} + +export interface AptosNFTOwnerResponseInput { + readonly amount: AptosNativeInput | AptosNative; + readonly collectionDataIdHash: string; + readonly collectionName: string; + readonly creatorAddress: AptosAddressInput | AptosAddress; + readonly lastTransactionTimestamp: string; + readonly lastTransactionVersion: string; + readonly name: string; + readonly ownerAddress: AptosAddressInput | AptosAddress; + readonly propertyVersion: string; + readonly tableType: string; + readonly tokenDataIdHash: string; + readonly tokenProperties: AptosNFTOwnerResponseTokenPropertiesInput | AptosNFTOwnerResponseTokenPropertiesValue; +} + +export class AptosNFTOwnerResponse { + public static create(input: AptosNFTOwnerResponseInput | AptosNFTOwnerResponse): AptosNFTOwnerResponse { + if (input instanceof AptosNFTOwnerResponse) { + return input; + } + return new AptosNFTOwnerResponse(input); + } + + public static fromJSON(json: AptosNFTOwnerResponseJSON): AptosNFTOwnerResponse { + const input: AptosNFTOwnerResponseInput = { + amount: AptosNative.fromJSON(json.amount), + collectionDataIdHash: json.collection_data_id_hash, + collectionName: json.collection_name, + creatorAddress: AptosAddress.fromJSON(json.creator_address), + lastTransactionTimestamp: json.last_transaction_timestamp, + lastTransactionVersion: json.last_transaction_version, + name: json.name, + ownerAddress: AptosAddress.fromJSON(json.owner_address), + propertyVersion: json.property_version, + tableType: json.table_type, + tokenDataIdHash: json.token_data_id_hash, + tokenProperties: AptosNFTOwnerResponseTokenProperties.fromJSON(json.token_properties), + }; + return AptosNFTOwnerResponse.create(input); + } + + /** + * @description The number of tokens that belonging to the owner + */ + public readonly amount: AptosNative; + /** + * @description The identifier of the collection + */ + public readonly collectionDataIdHash: string; + /** + * @description The name of the collection + */ + public readonly collectionName: string; + /** + * @description The address of the creator of the collection + */ + public readonly creatorAddress: AptosAddress; + /** + * @description The timestamp of the last transaction + */ + public readonly lastTransactionTimestamp: string; + /** + * @description The version of the last transaction + */ + public readonly lastTransactionVersion: string; + /** + * @description The name of the token + */ + public readonly name: string; + /** + * @description The address of the owner of the token + */ + public readonly ownerAddress: AptosAddress; + /** + * @description The property version of the token + */ + public readonly propertyVersion: string; + /** + * @description The data structure of the token + */ + public readonly tableType: string; + /** + * @description The identifier of the token + */ + public readonly tokenDataIdHash: string; + /** + * @description The properties of the token + */ + public readonly tokenProperties: AptosNFTOwnerResponseTokenPropertiesValue; + + private constructor(input: AptosNFTOwnerResponseInput) { + this.amount = AptosNative.create(input.amount); + this.collectionDataIdHash = input.collectionDataIdHash; + this.collectionName = input.collectionName; + this.creatorAddress = AptosAddress.create(input.creatorAddress); + this.lastTransactionTimestamp = input.lastTransactionTimestamp; + this.lastTransactionVersion = input.lastTransactionVersion; + this.name = input.name; + this.ownerAddress = AptosAddress.create(input.ownerAddress); + this.propertyVersion = input.propertyVersion; + this.tableType = input.tableType; + this.tokenDataIdHash = input.tokenDataIdHash; + this.tokenProperties = AptosNFTOwnerResponseTokenProperties.create(input.tokenProperties); + } + + public toJSON(): AptosNFTOwnerResponseJSON { + return { + amount: this.amount.toJSON(), + collection_data_id_hash: this.collectionDataIdHash, + collection_name: this.collectionName, + creator_address: this.creatorAddress.toJSON(), + last_transaction_timestamp: this.lastTransactionTimestamp, + last_transaction_version: this.lastTransactionVersion, + name: this.name, + owner_address: this.ownerAddress.toJSON(), + property_version: this.propertyVersion, + table_type: this.tableType, + token_data_id_hash: this.tokenDataIdHash, + token_properties: this.tokenProperties, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTOwnerResponseTokenProperties.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnerResponseTokenProperties.ts new file mode 100644 index 0000000000..8f1b8a7c2b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnerResponseTokenProperties.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/NFTOwnerResponse/properties/token_properties +// typeName: NFTOwnerResponse_token_properties + +export type AptosNFTOwnerResponseTokenPropertiesJSON = object; +export type AptosNFTOwnerResponseTokenPropertiesInput = object; +export type AptosNFTOwnerResponseTokenPropertiesValue = object; + +export abstract class AptosNFTOwnerResponseTokenProperties { + public static create(input: AptosNFTOwnerResponseTokenPropertiesInput | AptosNFTOwnerResponseTokenPropertiesValue): AptosNFTOwnerResponseTokenPropertiesValue { + return input; + } + + public static fromJSON(json: AptosNFTOwnerResponseTokenPropertiesJSON): AptosNFTOwnerResponseTokenPropertiesValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersByCollectionResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersByCollectionResponse.ts new file mode 100644 index 0000000000..dc91946fa4 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersByCollectionResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTOwnerResponse, AptosNFTOwnerResponseInput, AptosNFTOwnerResponseJSON } from '../types/AptosNFTOwnerResponse'; + +// $ref: #/components/schemas/NFTOwnersByCollectionResponse +// type: NFTOwnersByCollectionResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTOwnersByCollectionResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTOwnersByCollectionResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTOwnerResponse) + +export interface AptosNFTOwnersByCollectionResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTOwnerResponseJSON[]; +} + +export interface AptosNFTOwnersByCollectionResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTOwnerResponseInput[] | AptosNFTOwnerResponse[]; +} + +export class AptosNFTOwnersByCollectionResponse { + public static create(input: AptosNFTOwnersByCollectionResponseInput | AptosNFTOwnersByCollectionResponse): AptosNFTOwnersByCollectionResponse { + if (input instanceof AptosNFTOwnersByCollectionResponse) { + return input; + } + return new AptosNFTOwnersByCollectionResponse(input); + } + + public static fromJSON(json: AptosNFTOwnersByCollectionResponseJSON): AptosNFTOwnersByCollectionResponse { + const input: AptosNFTOwnersByCollectionResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTOwnerResponse.fromJSON(item)), + }; + return AptosNFTOwnersByCollectionResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The owners for the given collection + */ + public readonly result: AptosNFTOwnerResponse[]; + + private constructor(input: AptosNFTOwnersByCollectionResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTOwnerResponse.create(item)); + } + + public toJSON(): AptosNFTOwnersByCollectionResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersByTokensResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersByTokensResponse.ts new file mode 100644 index 0000000000..48e392f625 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersByTokensResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTOwnerResponse, AptosNFTOwnerResponseInput, AptosNFTOwnerResponseJSON } from '../types/AptosNFTOwnerResponse'; + +// $ref: #/components/schemas/NFTOwnersByTokensResponse +// type: NFTOwnersByTokensResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTOwnersByTokensResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTOwnersByTokensResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTOwnerResponse) + +export interface AptosNFTOwnersByTokensResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTOwnerResponseJSON[]; +} + +export interface AptosNFTOwnersByTokensResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTOwnerResponseInput[] | AptosNFTOwnerResponse[]; +} + +export class AptosNFTOwnersByTokensResponse { + public static create(input: AptosNFTOwnersByTokensResponseInput | AptosNFTOwnersByTokensResponse): AptosNFTOwnersByTokensResponse { + if (input instanceof AptosNFTOwnersByTokensResponse) { + return input; + } + return new AptosNFTOwnersByTokensResponse(input); + } + + public static fromJSON(json: AptosNFTOwnersByTokensResponseJSON): AptosNFTOwnersByTokensResponse { + const input: AptosNFTOwnersByTokensResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTOwnerResponse.fromJSON(item)), + }; + return AptosNFTOwnersByTokensResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The owners for the given tokens + */ + public readonly result: AptosNFTOwnerResponse[]; + + private constructor(input: AptosNFTOwnersByTokensResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTOwnerResponse.create(item)); + } + + public toJSON(): AptosNFTOwnersByTokensResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersOfCollectionResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersOfCollectionResponse.ts new file mode 100644 index 0000000000..d4a6a06168 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTOwnersOfCollectionResponse.ts @@ -0,0 +1,63 @@ +// $ref: #/components/schemas/NFTOwnersOfCollectionResponse +// type: NFTOwnersOfCollectionResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTOwnersOfCollectionResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTOwnersOfCollectionResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTOwnersOfCollectionResponse/properties/result) + +export interface AptosNFTOwnersOfCollectionResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: string[]; +} + +export interface AptosNFTOwnersOfCollectionResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: string[]; +} + +export class AptosNFTOwnersOfCollectionResponse { + public static create(input: AptosNFTOwnersOfCollectionResponseInput | AptosNFTOwnersOfCollectionResponse): AptosNFTOwnersOfCollectionResponse { + if (input instanceof AptosNFTOwnersOfCollectionResponse) { + return input; + } + return new AptosNFTOwnersOfCollectionResponse(input); + } + + public static fromJSON(json: AptosNFTOwnersOfCollectionResponseJSON): AptosNFTOwnersOfCollectionResponse { + const input: AptosNFTOwnersOfCollectionResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result, + }; + return AptosNFTOwnersOfCollectionResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The owner addresses for the given collection + */ + public readonly result: string[]; + + private constructor(input: AptosNFTOwnersOfCollectionResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result; + } + + public toJSON(): AptosNFTOwnersOfCollectionResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTokenResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTokenResponse.ts new file mode 100644 index 0000000000..a10d4cc06c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTokenResponse.ts @@ -0,0 +1,246 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosNFTTokenResponseDefaultProperties, AptosNFTTokenResponseDefaultPropertiesValue, AptosNFTTokenResponseDefaultPropertiesInput, AptosNFTTokenResponseDefaultPropertiesJSON } from '../types/AptosNFTTokenResponseDefaultProperties'; + +// $ref: #/components/schemas/NFTTokenResponse +// type: NFTTokenResponse +// properties: +// - collection_data_id_hash ($ref: #/components/schemas/NFTTokenResponse/properties/collection_data_id_hash) +// - collection_name ($ref: #/components/schemas/NFTTokenResponse/properties/collection_name) +// - creator_address ($ref: #/components/schemas/NFTTokenResponse/properties/creator_address) +// - default_properties ($ref: #/components/schemas/NFTTokenResponse/properties/default_properties) +// - description ($ref: #/components/schemas/NFTTokenResponse/properties/description) +// - description_mutable ($ref: #/components/schemas/NFTTokenResponse/properties/description_mutable) +// - largest_property_version ($ref: #/components/schemas/NFTTokenResponse/properties/largest_property_version) +// - last_transaction_timestamp ($ref: #/components/schemas/NFTTokenResponse/properties/last_transaction_timestamp) +// - last_transaction_version ($ref: #/components/schemas/NFTTokenResponse/properties/last_transaction_version) +// - maximum ($ref: #/components/schemas/NFTTokenResponse/properties/maximum) +// - maximum_mutable ($ref: #/components/schemas/NFTTokenResponse/properties/maximum_mutable) +// - metadata_uri ($ref: #/components/schemas/NFTTokenResponse/properties/metadata_uri) +// - name ($ref: #/components/schemas/NFTTokenResponse/properties/name) +// - payee_address ($ref: #/components/schemas/NFTTokenResponse/properties/payee_address) +// - properties_mutable ($ref: #/components/schemas/NFTTokenResponse/properties/properties_mutable) +// - royalty_mutable ($ref: #/components/schemas/NFTTokenResponse/properties/royalty_mutable) +// - royalty_points_denominator ($ref: #/components/schemas/NFTTokenResponse/properties/royalty_points_denominator) +// - royalty_points_numerator ($ref: #/components/schemas/NFTTokenResponse/properties/royalty_points_numerator) +// - supply ($ref: #/components/schemas/NFTTokenResponse/properties/supply) +// - token_data_id_hash ($ref: #/components/schemas/NFTTokenResponse/properties/token_data_id_hash) +// - uri_mutable ($ref: #/components/schemas/NFTTokenResponse/properties/uri_mutable) + +export interface AptosNFTTokenResponseJSON { + readonly collection_data_id_hash: string; + readonly collection_name: string; + readonly creator_address: AptosAddressJSON; + readonly default_properties: AptosNFTTokenResponseDefaultPropertiesJSON; + readonly description: string; + readonly description_mutable: boolean; + readonly largest_property_version: string; + readonly last_transaction_timestamp: string; + readonly last_transaction_version: string; + readonly maximum: string; + readonly maximum_mutable: boolean; + readonly metadata_uri: string; + readonly name: string; + readonly payee_address: AptosAddressJSON; + readonly properties_mutable: boolean; + readonly royalty_mutable: boolean; + readonly royalty_points_denominator: string; + readonly royalty_points_numerator: string; + readonly supply: string; + readonly token_data_id_hash: string; + readonly uri_mutable: boolean; +} + +export interface AptosNFTTokenResponseInput { + readonly collectionDataIdHash: string; + readonly collectionName: string; + readonly creatorAddress: AptosAddressInput | AptosAddress; + readonly defaultProperties: AptosNFTTokenResponseDefaultPropertiesInput | AptosNFTTokenResponseDefaultPropertiesValue; + readonly description: string; + readonly descriptionMutable: boolean; + readonly largestPropertyVersion: string; + readonly lastTransactionTimestamp: string; + readonly lastTransactionVersion: string; + readonly maximum: string; + readonly maximumMutable: boolean; + readonly metadataUri: string; + readonly name: string; + readonly payeeAddress: AptosAddressInput | AptosAddress; + readonly propertiesMutable: boolean; + readonly royaltyMutable: boolean; + readonly royaltyPointsDenominator: string; + readonly royaltyPointsNumerator: string; + readonly supply: string; + readonly tokenDataIdHash: string; + readonly uriMutable: boolean; +} + +export class AptosNFTTokenResponse { + public static create(input: AptosNFTTokenResponseInput | AptosNFTTokenResponse): AptosNFTTokenResponse { + if (input instanceof AptosNFTTokenResponse) { + return input; + } + return new AptosNFTTokenResponse(input); + } + + public static fromJSON(json: AptosNFTTokenResponseJSON): AptosNFTTokenResponse { + const input: AptosNFTTokenResponseInput = { + collectionDataIdHash: json.collection_data_id_hash, + collectionName: json.collection_name, + creatorAddress: AptosAddress.fromJSON(json.creator_address), + defaultProperties: AptosNFTTokenResponseDefaultProperties.fromJSON(json.default_properties), + description: json.description, + descriptionMutable: json.description_mutable, + largestPropertyVersion: json.largest_property_version, + lastTransactionTimestamp: json.last_transaction_timestamp, + lastTransactionVersion: json.last_transaction_version, + maximum: json.maximum, + maximumMutable: json.maximum_mutable, + metadataUri: json.metadata_uri, + name: json.name, + payeeAddress: AptosAddress.fromJSON(json.payee_address), + propertiesMutable: json.properties_mutable, + royaltyMutable: json.royalty_mutable, + royaltyPointsDenominator: json.royalty_points_denominator, + royaltyPointsNumerator: json.royalty_points_numerator, + supply: json.supply, + tokenDataIdHash: json.token_data_id_hash, + uriMutable: json.uri_mutable, + }; + return AptosNFTTokenResponse.create(input); + } + + /** + * @description The identifier of the collection + */ + public readonly collectionDataIdHash: string; + /** + * @description The name of the collection + */ + public readonly collectionName: string; + /** + * @description The address of the creator of the collection + */ + public readonly creatorAddress: AptosAddress; + /** + * @description The default properties of the token + */ + public readonly defaultProperties: AptosNFTTokenResponseDefaultPropertiesValue; + /** + * @description The description of the collection + */ + public readonly description: string; + /** + * @description Whether the description can be changed + */ + public readonly descriptionMutable: boolean; + /** + * @description largest_property_version + */ + public readonly largestPropertyVersion: string; + /** + * @description The timestamp of the last transaction + */ + public readonly lastTransactionTimestamp: string; + /** + * @description The version of the last transaction + */ + public readonly lastTransactionVersion: string; + /** + * @description The maximum number of tokens that can be minted + */ + public readonly maximum: string; + /** + * @description Whether the maximum number of tokens can be changed + */ + public readonly maximumMutable: boolean; + /** + * @description The URI of the image of the token + */ + public readonly metadataUri: string; + /** + * @description The name of the token + */ + public readonly name: string; + /** + * @description The address that last payed for the token + */ + public readonly payeeAddress: AptosAddress; + /** + * @description Whether the properties of the token can be changed + */ + public readonly propertiesMutable: boolean; + /** + * @description Whether the royalty of the token can be changed + */ + public readonly royaltyMutable: boolean; + /** + * @description The denominator for royalty points + */ + public readonly royaltyPointsDenominator: string; + /** + * @description The numerator for royalty points + */ + public readonly royaltyPointsNumerator: string; + /** + * @description The number of tokens minted + */ + public readonly supply: string; + /** + * @description The identifier of the token + */ + public readonly tokenDataIdHash: string; + /** + * @description Whether the URI of the image can be changed + */ + public readonly uriMutable: boolean; + + private constructor(input: AptosNFTTokenResponseInput) { + this.collectionDataIdHash = input.collectionDataIdHash; + this.collectionName = input.collectionName; + this.creatorAddress = AptosAddress.create(input.creatorAddress); + this.defaultProperties = AptosNFTTokenResponseDefaultProperties.create(input.defaultProperties); + this.description = input.description; + this.descriptionMutable = input.descriptionMutable; + this.largestPropertyVersion = input.largestPropertyVersion; + this.lastTransactionTimestamp = input.lastTransactionTimestamp; + this.lastTransactionVersion = input.lastTransactionVersion; + this.maximum = input.maximum; + this.maximumMutable = input.maximumMutable; + this.metadataUri = input.metadataUri; + this.name = input.name; + this.payeeAddress = AptosAddress.create(input.payeeAddress); + this.propertiesMutable = input.propertiesMutable; + this.royaltyMutable = input.royaltyMutable; + this.royaltyPointsDenominator = input.royaltyPointsDenominator; + this.royaltyPointsNumerator = input.royaltyPointsNumerator; + this.supply = input.supply; + this.tokenDataIdHash = input.tokenDataIdHash; + this.uriMutable = input.uriMutable; + } + + public toJSON(): AptosNFTTokenResponseJSON { + return { + collection_data_id_hash: this.collectionDataIdHash, + collection_name: this.collectionName, + creator_address: this.creatorAddress.toJSON(), + default_properties: this.defaultProperties, + description: this.description, + description_mutable: this.descriptionMutable, + largest_property_version: this.largestPropertyVersion, + last_transaction_timestamp: this.lastTransactionTimestamp, + last_transaction_version: this.lastTransactionVersion, + maximum: this.maximum, + maximum_mutable: this.maximumMutable, + metadata_uri: this.metadataUri, + name: this.name, + payee_address: this.payeeAddress.toJSON(), + properties_mutable: this.propertiesMutable, + royalty_mutable: this.royaltyMutable, + royalty_points_denominator: this.royaltyPointsDenominator, + royalty_points_numerator: this.royaltyPointsNumerator, + supply: this.supply, + token_data_id_hash: this.tokenDataIdHash, + uri_mutable: this.uriMutable, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTokenResponseDefaultProperties.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTokenResponseDefaultProperties.ts new file mode 100644 index 0000000000..f9ae7e0ebd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTokenResponseDefaultProperties.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/NFTTokenResponse/properties/default_properties +// typeName: NFTTokenResponse_default_properties + +export type AptosNFTTokenResponseDefaultPropertiesJSON = object; +export type AptosNFTTokenResponseDefaultPropertiesInput = object; +export type AptosNFTTokenResponseDefaultPropertiesValue = object; + +export abstract class AptosNFTTokenResponseDefaultProperties { + public static create(input: AptosNFTTokenResponseDefaultPropertiesInput | AptosNFTTokenResponseDefaultPropertiesValue): AptosNFTTokenResponseDefaultPropertiesValue { + return input; + } + + public static fromJSON(json: AptosNFTTokenResponseDefaultPropertiesJSON): AptosNFTTokenResponseDefaultPropertiesValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTokensByCollectionResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTokensByCollectionResponse.ts new file mode 100644 index 0000000000..dca12c48ae --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTokensByCollectionResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTTokenResponse, AptosNFTTokenResponseInput, AptosNFTTokenResponseJSON } from '../types/AptosNFTTokenResponse'; + +// $ref: #/components/schemas/NFTTokensByCollectionResponse +// type: NFTTokensByCollectionResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTTokensByCollectionResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTTokensByCollectionResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTTokenResponse) + +export interface AptosNFTTokensByCollectionResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTokenResponseJSON[]; +} + +export interface AptosNFTTokensByCollectionResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTokenResponseInput[] | AptosNFTTokenResponse[]; +} + +export class AptosNFTTokensByCollectionResponse { + public static create(input: AptosNFTTokensByCollectionResponseInput | AptosNFTTokensByCollectionResponse): AptosNFTTokensByCollectionResponse { + if (input instanceof AptosNFTTokensByCollectionResponse) { + return input; + } + return new AptosNFTTokensByCollectionResponse(input); + } + + public static fromJSON(json: AptosNFTTokensByCollectionResponseJSON): AptosNFTTokensByCollectionResponse { + const input: AptosNFTTokensByCollectionResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTTokenResponse.fromJSON(item)), + }; + return AptosNFTTokensByCollectionResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The tokens for the given collection + */ + public readonly result: AptosNFTTokenResponse[]; + + private constructor(input: AptosNFTTokensByCollectionResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTTokenResponse.create(item)); + } + + public toJSON(): AptosNFTTokensByCollectionResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTokensByCreatorsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTokensByCreatorsResponse.ts new file mode 100644 index 0000000000..3457eeed89 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTokensByCreatorsResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTTokenResponse, AptosNFTTokenResponseInput, AptosNFTTokenResponseJSON } from '../types/AptosNFTTokenResponse'; + +// $ref: #/components/schemas/NFTTokensByCreatorsResponse +// type: NFTTokensByCreatorsResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTTokensByCreatorsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTTokensByCreatorsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTTokenResponse) + +export interface AptosNFTTokensByCreatorsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTokenResponseJSON[]; +} + +export interface AptosNFTTokensByCreatorsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTokenResponseInput[] | AptosNFTTokenResponse[]; +} + +export class AptosNFTTokensByCreatorsResponse { + public static create(input: AptosNFTTokensByCreatorsResponseInput | AptosNFTTokensByCreatorsResponse): AptosNFTTokensByCreatorsResponse { + if (input instanceof AptosNFTTokensByCreatorsResponse) { + return input; + } + return new AptosNFTTokensByCreatorsResponse(input); + } + + public static fromJSON(json: AptosNFTTokensByCreatorsResponseJSON): AptosNFTTokensByCreatorsResponse { + const input: AptosNFTTokensByCreatorsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTTokenResponse.fromJSON(item)), + }; + return AptosNFTTokensByCreatorsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creators + */ + public readonly result: AptosNFTTokenResponse[]; + + private constructor(input: AptosNFTTokensByCreatorsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTTokenResponse.create(item)); + } + + public toJSON(): AptosNFTTokensByCreatorsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTransferResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTransferResponse.ts new file mode 100644 index 0000000000..a0811f8b70 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTransferResponse.ts @@ -0,0 +1,205 @@ +import { AptosNative, AptosNativeInput, AptosNativeJSON, AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/NFTTransferResponse +// type: NFTTransferResponse +// properties: +// - coin_amount ($ref: #/components/schemas/NFTTransferResponse/properties/coin_amount) +// - coin_type ($ref: #/components/schemas/NFTTransferResponse/properties/coin_type) +// - collection_data_id_hash ($ref: #/components/schemas/NFTTransferResponse/properties/collection_data_id_hash) +// - collection_name ($ref: #/components/schemas/NFTTransferResponse/properties/collection_name) +// - creator_address ($ref: #/components/schemas/NFTTransferResponse/properties/creator_address) +// - event_account_address ($ref: #/components/schemas/NFTTransferResponse/properties/event_account_address) +// - event_creation_number ($ref: #/components/schemas/NFTTransferResponse/properties/event_creation_number) +// - event_sequence_number ($ref: #/components/schemas/NFTTransferResponse/properties/event_sequence_number) +// - from_address ($ref: #/components/schemas/NFTTransferResponse/properties/from_address) +// - name ($ref: #/components/schemas/NFTTransferResponse/properties/name) +// - property_version ($ref: #/components/schemas/NFTTransferResponse/properties/property_version) +// - to_address ($ref: #/components/schemas/NFTTransferResponse/properties/to_address) +// - token_amount ($ref: #/components/schemas/NFTTransferResponse/properties/token_amount) +// - token_data_id_hash ($ref: #/components/schemas/NFTTransferResponse/properties/token_data_id_hash) +// - transaction_timestamp ($ref: #/components/schemas/NFTTransferResponse/properties/transaction_timestamp) +// - transaction_version ($ref: #/components/schemas/NFTTransferResponse/properties/transaction_version) +// - transfer_type ($ref: #/components/schemas/NFTTransferResponse/properties/transfer_type) + +export interface AptosNFTTransferResponseJSON { + readonly coin_amount: AptosNativeJSON; + readonly coin_type: string; + readonly collection_data_id_hash: string; + readonly collection_name: string; + readonly creator_address: AptosAddressJSON; + readonly event_account_address: string; + readonly event_creation_number: string; + readonly event_sequence_number: string; + readonly from_address: AptosAddressJSON; + readonly name: string; + readonly property_version: string; + readonly to_address: AptosAddressJSON; + readonly token_amount: AptosNativeJSON; + readonly token_data_id_hash: string; + readonly transaction_timestamp: string; + readonly transaction_version: string; + readonly transfer_type: string; +} + +export interface AptosNFTTransferResponseInput { + readonly coinAmount: AptosNativeInput | AptosNative; + readonly coinType: string; + readonly collectionDataIdHash: string; + readonly collectionName: string; + readonly creatorAddress: AptosAddressInput | AptosAddress; + readonly eventAccountAddress: string; + readonly eventCreationNumber: string; + readonly eventSequenceNumber: string; + readonly fromAddress: AptosAddressInput | AptosAddress; + readonly name: string; + readonly propertyVersion: string; + readonly toAddress: AptosAddressInput | AptosAddress; + readonly tokenAmount: AptosNativeInput | AptosNative; + readonly tokenDataIdHash: string; + readonly transactionTimestamp: string; + readonly transactionVersion: string; + readonly transferType: string; +} + +export class AptosNFTTransferResponse { + public static create(input: AptosNFTTransferResponseInput | AptosNFTTransferResponse): AptosNFTTransferResponse { + if (input instanceof AptosNFTTransferResponse) { + return input; + } + return new AptosNFTTransferResponse(input); + } + + public static fromJSON(json: AptosNFTTransferResponseJSON): AptosNFTTransferResponse { + const input: AptosNFTTransferResponseInput = { + coinAmount: AptosNative.fromJSON(json.coin_amount), + coinType: json.coin_type, + collectionDataIdHash: json.collection_data_id_hash, + collectionName: json.collection_name, + creatorAddress: AptosAddress.fromJSON(json.creator_address), + eventAccountAddress: json.event_account_address, + eventCreationNumber: json.event_creation_number, + eventSequenceNumber: json.event_sequence_number, + fromAddress: AptosAddress.fromJSON(json.from_address), + name: json.name, + propertyVersion: json.property_version, + toAddress: AptosAddress.fromJSON(json.to_address), + tokenAmount: AptosNative.fromJSON(json.token_amount), + tokenDataIdHash: json.token_data_id_hash, + transactionTimestamp: json.transaction_timestamp, + transactionVersion: json.transaction_version, + transferType: json.transfer_type, + }; + return AptosNFTTransferResponse.create(input); + } + + /** + * @description The number of tokens transferred + */ + public readonly coinAmount: AptosNative; + /** + * @description The type of tokens transferred + */ + public readonly coinType: string; + /** + * @description The identifier of the collection + */ + public readonly collectionDataIdHash: string; + /** + * @description The name of the collection + */ + public readonly collectionName: string; + /** + * @description The address of the creator of the collection + */ + public readonly creatorAddress: AptosAddress; + /** + * @description The account address of the transfer + */ + public readonly eventAccountAddress: string; + /** + * @description The creation number of the event + */ + public readonly eventCreationNumber: string; + /** + * @description The sequence number of the event + */ + public readonly eventSequenceNumber: string; + /** + * @description The address sending the transfer + */ + public readonly fromAddress: AptosAddress; + /** + * @description The name of the token + */ + public readonly name: string; + /** + * @description The property version of the token + */ + public readonly propertyVersion: string; + /** + * @description The address recieving the transfer + */ + public readonly toAddress: AptosAddress; + /** + * @description The number of tokens transferred + */ + public readonly tokenAmount: AptosNative; + /** + * @description The identifier of the token + */ + public readonly tokenDataIdHash: string; + /** + * @description The timestamp of the transfer + */ + public readonly transactionTimestamp: string; + /** + * @description The version of the transaction that the transfer is a part of + */ + public readonly transactionVersion: string; + /** + * @description The type of transfer + */ + public readonly transferType: string; + + private constructor(input: AptosNFTTransferResponseInput) { + this.coinAmount = AptosNative.create(input.coinAmount); + this.coinType = input.coinType; + this.collectionDataIdHash = input.collectionDataIdHash; + this.collectionName = input.collectionName; + this.creatorAddress = AptosAddress.create(input.creatorAddress); + this.eventAccountAddress = input.eventAccountAddress; + this.eventCreationNumber = input.eventCreationNumber; + this.eventSequenceNumber = input.eventSequenceNumber; + this.fromAddress = AptosAddress.create(input.fromAddress); + this.name = input.name; + this.propertyVersion = input.propertyVersion; + this.toAddress = AptosAddress.create(input.toAddress); + this.tokenAmount = AptosNative.create(input.tokenAmount); + this.tokenDataIdHash = input.tokenDataIdHash; + this.transactionTimestamp = input.transactionTimestamp; + this.transactionVersion = input.transactionVersion; + this.transferType = input.transferType; + } + + public toJSON(): AptosNFTTransferResponseJSON { + return { + coin_amount: this.coinAmount.toJSON(), + coin_type: this.coinType, + collection_data_id_hash: this.collectionDataIdHash, + collection_name: this.collectionName, + creator_address: this.creatorAddress.toJSON(), + event_account_address: this.eventAccountAddress, + event_creation_number: this.eventCreationNumber, + event_sequence_number: this.eventSequenceNumber, + from_address: this.fromAddress.toJSON(), + name: this.name, + property_version: this.propertyVersion, + to_address: this.toAddress.toJSON(), + token_amount: this.tokenAmount.toJSON(), + token_data_id_hash: this.tokenDataIdHash, + transaction_timestamp: this.transactionTimestamp, + transaction_version: this.transactionVersion, + transfer_type: this.transferType, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTransfersByTokensResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTransfersByTokensResponse.ts new file mode 100644 index 0000000000..f477c2de78 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTransfersByTokensResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTTransferResponse, AptosNFTTransferResponseInput, AptosNFTTransferResponseJSON } from '../types/AptosNFTTransferResponse'; + +// $ref: #/components/schemas/NFTTransfersByTokensResponse +// type: NFTTransfersByTokensResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTTransfersByTokensResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTTransfersByTokensResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTTransferResponse) + +export interface AptosNFTTransfersByTokensResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseJSON[]; +} + +export interface AptosNFTTransfersByTokensResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseInput[] | AptosNFTTransferResponse[]; +} + +export class AptosNFTTransfersByTokensResponse { + public static create(input: AptosNFTTransfersByTokensResponseInput | AptosNFTTransfersByTokensResponse): AptosNFTTransfersByTokensResponse { + if (input instanceof AptosNFTTransfersByTokensResponse) { + return input; + } + return new AptosNFTTransfersByTokensResponse(input); + } + + public static fromJSON(json: AptosNFTTransfersByTokensResponseJSON): AptosNFTTransfersByTokensResponse { + const input: AptosNFTTransfersByTokensResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTTransferResponse.fromJSON(item)), + }; + return AptosNFTTransfersByTokensResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creators + */ + public readonly result: AptosNFTTransferResponse[]; + + private constructor(input: AptosNFTTransfersByTokensResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTTransferResponse.create(item)); + } + + public toJSON(): AptosNFTTransfersByTokensResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTTransfersByWalletsResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTTransfersByWalletsResponse.ts new file mode 100644 index 0000000000..6e653964c4 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTTransfersByWalletsResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTTransferResponse, AptosNFTTransferResponseInput, AptosNFTTransferResponseJSON } from '../types/AptosNFTTransferResponse'; + +// $ref: #/components/schemas/NFTTransfersByWalletsResponse +// type: NFTTransfersByWalletsResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTTransfersByWalletsResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTTransfersByWalletsResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTTransferResponse) + +export interface AptosNFTTransfersByWalletsResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseJSON[]; +} + +export interface AptosNFTTransfersByWalletsResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTTransferResponseInput[] | AptosNFTTransferResponse[]; +} + +export class AptosNFTTransfersByWalletsResponse { + public static create(input: AptosNFTTransfersByWalletsResponseInput | AptosNFTTransfersByWalletsResponse): AptosNFTTransfersByWalletsResponse { + if (input instanceof AptosNFTTransfersByWalletsResponse) { + return input; + } + return new AptosNFTTransfersByWalletsResponse(input); + } + + public static fromJSON(json: AptosNFTTransfersByWalletsResponseJSON): AptosNFTTransfersByWalletsResponse { + const input: AptosNFTTransfersByWalletsResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTTransferResponse.fromJSON(item)), + }; + return AptosNFTTransfersByWalletsResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The collections for the given creators + */ + public readonly result: AptosNFTTransferResponse[]; + + private constructor(input: AptosNFTTransfersByWalletsResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTTransferResponse.create(item)); + } + + public toJSON(): AptosNFTTransfersByWalletsResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosNFTsByOwnersResponse.ts b/packages/common/aptosUtils/src/generated/types/AptosNFTsByOwnersResponse.ts new file mode 100644 index 0000000000..d7d0551dae --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosNFTsByOwnersResponse.ts @@ -0,0 +1,65 @@ +import { AptosNFTOwnerResponse, AptosNFTOwnerResponseInput, AptosNFTOwnerResponseJSON } from '../types/AptosNFTOwnerResponse'; + +// $ref: #/components/schemas/NFTsByOwnersResponse +// type: NFTsByOwnersResponse +// properties: +// - cursor ($ref: #/components/schemas/NFTsByOwnersResponse/properties/cursor) +// - hasNextPage ($ref: #/components/schemas/NFTsByOwnersResponse/properties/hasNextPage) +// - result ($ref: #/components/schemas/NFTOwnerResponse) + +export interface AptosNFTsByOwnersResponseJSON { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTOwnerResponseJSON[]; +} + +export interface AptosNFTsByOwnersResponseInput { + readonly cursor: string; + readonly hasNextPage: boolean; + readonly result: AptosNFTOwnerResponseInput[] | AptosNFTOwnerResponse[]; +} + +export class AptosNFTsByOwnersResponse { + public static create(input: AptosNFTsByOwnersResponseInput | AptosNFTsByOwnersResponse): AptosNFTsByOwnersResponse { + if (input instanceof AptosNFTsByOwnersResponse) { + return input; + } + return new AptosNFTsByOwnersResponse(input); + } + + public static fromJSON(json: AptosNFTsByOwnersResponseJSON): AptosNFTsByOwnersResponse { + const input: AptosNFTsByOwnersResponseInput = { + cursor: json.cursor, + hasNextPage: json.hasNextPage, + result: json.result.map((item) => AptosNFTOwnerResponse.fromJSON(item)), + }; + return AptosNFTsByOwnersResponse.create(input); + } + + /** + * @description The cursor to use for the next page of results. (Cursor is null on last page) + */ + public readonly cursor: string; + /** + * @description Indicates if there is a next page of results + */ + public readonly hasNextPage: boolean; + /** + * @description The tokens for the given owners + */ + public readonly result: AptosNFTOwnerResponse[]; + + private constructor(input: AptosNFTsByOwnersResponseInput) { + this.cursor = input.cursor; + this.hasNextPage = input.hasNextPage; + this.result = input.result.map((item) => AptosNFTOwnerResponse.create(item)); + } + + public toJSON(): AptosNFTsByOwnersResponseJSON { + return { + cursor: this.cursor, + hasNextPage: this.hasNextPage, + result: this.result.map((item) => item.toJSON()), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosPendingTransaction.ts b/packages/common/aptosUtils/src/generated/types/AptosPendingTransaction.ts new file mode 100644 index 0000000000..11dd1fe319 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosPendingTransaction.ts @@ -0,0 +1,116 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosPendingTransactionPayload, AptosPendingTransactionPayloadValue, AptosPendingTransactionPayloadInput, AptosPendingTransactionPayloadJSON } from '../types/AptosPendingTransactionPayload'; +import { AptosPendingTransactionSignature, AptosPendingTransactionSignatureValue, AptosPendingTransactionSignatureInput, AptosPendingTransactionSignatureJSON } from '../types/AptosPendingTransactionSignature'; + +// $ref: #/components/schemas/PendingTransaction +// type: PendingTransaction +// properties: +// - hash ($ref: #/components/schemas/PendingTransaction/properties/hash) +// - sender ($ref: #/components/schemas/PendingTransaction/properties/sender) +// - sequence_number ($ref: #/components/schemas/PendingTransaction/properties/sequence_number) +// - max_gas_amount ($ref: #/components/schemas/PendingTransaction/properties/max_gas_amount) +// - gas_unit_price ($ref: #/components/schemas/PendingTransaction/properties/gas_unit_price) +// - expiration_timestamp_secs ($ref: #/components/schemas/PendingTransaction/properties/expiration_timestamp_secs) +// - payload ($ref: #/components/schemas/PendingTransaction/properties/payload) +// - signature ($ref: #/components/schemas/PendingTransaction/properties/signature) + +export interface AptosPendingTransactionJSON { + readonly hash: string; + readonly sender: AptosAddressJSON; + readonly sequence_number: string; + readonly max_gas_amount: string; + readonly gas_unit_price: string; + readonly expiration_timestamp_secs: string; + readonly payload: AptosPendingTransactionPayloadJSON; + readonly signature: AptosPendingTransactionSignatureJSON; +} + +export interface AptosPendingTransactionInput { + readonly hash: string; + readonly sender: AptosAddressInput | AptosAddress; + readonly sequenceNumber: string; + readonly maxGasAmount: string; + readonly gasUnitPrice: string; + readonly expirationTimestampSecs: string; + readonly payload: AptosPendingTransactionPayloadInput | AptosPendingTransactionPayloadValue; + readonly signature: AptosPendingTransactionSignatureInput | AptosPendingTransactionSignatureValue; +} + +export class AptosPendingTransaction { + public static create(input: AptosPendingTransactionInput | AptosPendingTransaction): AptosPendingTransaction { + if (input instanceof AptosPendingTransaction) { + return input; + } + return new AptosPendingTransaction(input); + } + + public static fromJSON(json: AptosPendingTransactionJSON): AptosPendingTransaction { + const input: AptosPendingTransactionInput = { + hash: json.hash, + sender: AptosAddress.fromJSON(json.sender), + sequenceNumber: json.sequence_number, + maxGasAmount: json.max_gas_amount, + gasUnitPrice: json.gas_unit_price, + expirationTimestampSecs: json.expiration_timestamp_secs, + payload: AptosPendingTransactionPayload.fromJSON(json.payload), + signature: AptosPendingTransactionSignature.fromJSON(json.signature), + }; + return AptosPendingTransaction.create(input); + } + + public static isInput(input: any): input is AptosPendingTransactionInput { + return input.type === 'pending_transaction'; + } + + public static isJSON(json: any): json is AptosPendingTransactionJSON { + return json.type === 'pending_transaction'; + } + + public readonly hash: string; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly sender: AptosAddress; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly sequenceNumber: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly maxGasAmount: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUnitPrice: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly expirationTimestampSecs: string; + public readonly payload: AptosPendingTransactionPayloadValue; + public readonly signature: AptosPendingTransactionSignatureValue; + + private constructor(input: AptosPendingTransactionInput) { + this.hash = input.hash; + this.sender = AptosAddress.create(input.sender); + this.sequenceNumber = input.sequenceNumber; + this.maxGasAmount = input.maxGasAmount; + this.gasUnitPrice = input.gasUnitPrice; + this.expirationTimestampSecs = input.expirationTimestampSecs; + this.payload = AptosPendingTransactionPayload.create(input.payload); + this.signature = AptosPendingTransactionSignature.create(input.signature); + } + + public toJSON(): AptosPendingTransactionJSON { + return { + hash: this.hash, + sender: this.sender.toJSON(), + sequence_number: this.sequenceNumber, + max_gas_amount: this.maxGasAmount, + gas_unit_price: this.gasUnitPrice, + expiration_timestamp_secs: this.expirationTimestampSecs, + payload: this.payload.toJSON(), + signature: this.signature.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosPendingTransactionPayload.ts b/packages/common/aptosUtils/src/generated/types/AptosPendingTransactionPayload.ts new file mode 100644 index 0000000000..5484952270 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosPendingTransactionPayload.ts @@ -0,0 +1,41 @@ +import { AptosEntryFunctionPayloadRequest, AptosEntryFunctionPayloadRequestJSON, AptosEntryFunctionPayloadRequestInput } from '../types/AptosEntryFunctionPayloadRequest'; +import { AptosScriptPayloadRequest, AptosScriptPayloadRequestJSON, AptosScriptPayloadRequestInput } from '../types/AptosScriptPayloadRequest'; +import { AptosModuleBundlePayloadRequest, AptosModuleBundlePayloadRequestJSON, AptosModuleBundlePayloadRequestInput } from '../types/AptosModuleBundlePayloadRequest'; + +// $ref: #/components/schemas/PendingTransaction/properties/payload +// typeName: PendingTransaction_payload +// unionType: oneOf + +export type AptosPendingTransactionPayloadJSON = AptosEntryFunctionPayloadRequestJSON | AptosScriptPayloadRequestJSON | AptosModuleBundlePayloadRequestJSON; +export type AptosPendingTransactionPayloadInput = AptosEntryFunctionPayloadRequestInput | AptosScriptPayloadRequestInput | AptosModuleBundlePayloadRequestInput; +export type AptosPendingTransactionPayloadValue = AptosEntryFunctionPayloadRequest | AptosScriptPayloadRequest | AptosModuleBundlePayloadRequest; + +export abstract class AptosPendingTransactionPayload { + public static create(input: AptosPendingTransactionPayloadInput): AptosPendingTransactionPayloadValue { + if (AptosEntryFunctionPayloadRequest.isInput(input)) { + return AptosEntryFunctionPayloadRequest.create(input); + } + if (AptosScriptPayloadRequest.isInput(input)) { + return AptosScriptPayloadRequest.create(input); + } + if (AptosModuleBundlePayloadRequest.isInput(input)) { + return AptosModuleBundlePayloadRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosPendingTransactionPayloadJSON): AptosPendingTransactionPayloadValue { + if (AptosEntryFunctionPayloadRequest.isJSON(json)) { + return AptosEntryFunctionPayloadRequest.fromJSON(json); + } + if (AptosScriptPayloadRequest.isJSON(json)) { + return AptosScriptPayloadRequest.fromJSON(json); + } + if (AptosModuleBundlePayloadRequest.isJSON(json)) { + return AptosModuleBundlePayloadRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosPendingTransactionPayload (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosPendingTransactionSignature.ts b/packages/common/aptosUtils/src/generated/types/AptosPendingTransactionSignature.ts new file mode 100644 index 0000000000..1d3557d1d8 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosPendingTransactionSignature.ts @@ -0,0 +1,41 @@ +import { AptosEd25519SignatureRequest, AptosEd25519SignatureRequestJSON, AptosEd25519SignatureRequestInput } from '../types/AptosEd25519SignatureRequest'; +import { AptosMultiEd25519SignatureRequest, AptosMultiEd25519SignatureRequestJSON, AptosMultiEd25519SignatureRequestInput } from '../types/AptosMultiEd25519SignatureRequest'; +import { AptosMultiAgentSignatureRequest, AptosMultiAgentSignatureRequestJSON, AptosMultiAgentSignatureRequestInput } from '../types/AptosMultiAgentSignatureRequest'; + +// $ref: #/components/schemas/PendingTransaction/properties/signature +// typeName: PendingTransaction_signature +// unionType: oneOf + +export type AptosPendingTransactionSignatureJSON = AptosEd25519SignatureRequestJSON | AptosMultiEd25519SignatureRequestJSON | AptosMultiAgentSignatureRequestJSON; +export type AptosPendingTransactionSignatureInput = AptosEd25519SignatureRequestInput | AptosMultiEd25519SignatureRequestInput | AptosMultiAgentSignatureRequestInput; +export type AptosPendingTransactionSignatureValue = AptosEd25519SignatureRequest | AptosMultiEd25519SignatureRequest | AptosMultiAgentSignatureRequest; + +export abstract class AptosPendingTransactionSignature { + public static create(input: AptosPendingTransactionSignatureInput): AptosPendingTransactionSignatureValue { + if (AptosEd25519SignatureRequest.isInput(input)) { + return AptosEd25519SignatureRequest.create(input); + } + if (AptosMultiEd25519SignatureRequest.isInput(input)) { + return AptosMultiEd25519SignatureRequest.create(input); + } + if (AptosMultiAgentSignatureRequest.isInput(input)) { + return AptosMultiAgentSignatureRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosPendingTransactionSignatureJSON): AptosPendingTransactionSignatureValue { + if (AptosEd25519SignatureRequest.isJSON(json)) { + return AptosEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiEd25519SignatureRequest.isJSON(json)) { + return AptosMultiEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiAgentSignatureRequest.isJSON(json)) { + return AptosMultiAgentSignatureRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosPendingTransactionSignature (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosScriptPayloadRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosScriptPayloadRequest.ts new file mode 100644 index 0000000000..ae7b9145c9 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosScriptPayloadRequest.ts @@ -0,0 +1,83 @@ +import { AptosScriptPayloadRequestCode, AptosScriptPayloadRequestCodeValue, AptosScriptPayloadRequestCodeInput, AptosScriptPayloadRequestCodeJSON } from '../types/AptosScriptPayloadRequestCode'; + +// $ref: #/components/schemas/ScriptPayloadRequest +// type: ScriptPayloadRequest +// properties: +// - type ($ref: #/components/schemas/ScriptPayloadRequest/properties/type) +// - code ($ref: #/components/schemas/ScriptPayloadRequest/properties/code) +// - type_arguments ($ref: #/components/schemas/ScriptPayloadRequest/properties/type_arguments) +// - arguments ($ref: #/components/schemas/ScriptPayloadRequest/properties/arguments) + +export interface AptosScriptPayloadRequestJSON { + readonly type: string; + readonly code: AptosScriptPayloadRequestCodeJSON; + readonly type_arguments: string[]; + readonly arguments: string[]; +} + +export interface AptosScriptPayloadRequestInput { + readonly type: string; + readonly code: AptosScriptPayloadRequestCodeInput | AptosScriptPayloadRequestCodeValue; + readonly typeArguments: string[]; + readonly arguments: string[]; +} + +export class AptosScriptPayloadRequest { + public static create(input: AptosScriptPayloadRequestInput | AptosScriptPayloadRequest): AptosScriptPayloadRequest { + if (input instanceof AptosScriptPayloadRequest) { + return input; + } + return new AptosScriptPayloadRequest(input); + } + + public static fromJSON(json: AptosScriptPayloadRequestJSON): AptosScriptPayloadRequest { + const input: AptosScriptPayloadRequestInput = { + type: json.type, + code: AptosScriptPayloadRequestCode.fromJSON(json.code), + typeArguments: json.type_arguments, + arguments: json.arguments, + }; + return AptosScriptPayloadRequest.create(input); + } + + public static isInput(input: any): input is AptosScriptPayloadRequestInput { + return ["type","code","typeArguments","arguments"].every((name) => input[name] !== undefined); + } + + public static isJSON(json: any): json is AptosScriptPayloadRequestJSON { + return ["type","code","type_arguments","arguments"].every((name) => json[name] !== undefined); + } + + /** + * @description Type of payload + */ + public readonly type: string; + /** + * @description Move script bytecode + */ + public readonly code: AptosScriptPayloadRequestCodeValue; + /** + * @description Type arguments of the function + */ + public readonly typeArguments: string[]; + /** + * @description Arguments of the function + */ + public readonly arguments: string[]; + + private constructor(input: AptosScriptPayloadRequestInput) { + this.type = input.type; + this.code = AptosScriptPayloadRequestCode.create(input.code); + this.typeArguments = input.typeArguments; + this.arguments = input.arguments; + } + + public toJSON(): AptosScriptPayloadRequestJSON { + return { + type: this.type, + code: this.code, + type_arguments: this.typeArguments, + arguments: this.arguments, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosScriptPayloadRequestCode.ts b/packages/common/aptosUtils/src/generated/types/AptosScriptPayloadRequestCode.ts new file mode 100644 index 0000000000..0011102efc --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosScriptPayloadRequestCode.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/ScriptPayloadRequest/properties/code +// typeName: ScriptPayloadRequest_code + +export type AptosScriptPayloadRequestCodeJSON = object; +export type AptosScriptPayloadRequestCodeInput = object; +export type AptosScriptPayloadRequestCodeValue = object; + +export abstract class AptosScriptPayloadRequestCode { + public static create(input: AptosScriptPayloadRequestCodeInput | AptosScriptPayloadRequestCodeValue): AptosScriptPayloadRequestCodeValue { + return input; + } + + public static fromJSON(json: AptosScriptPayloadRequestCodeJSON): AptosScriptPayloadRequestCodeValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosScriptWriteSet.ts b/packages/common/aptosUtils/src/generated/types/AptosScriptWriteSet.ts new file mode 100644 index 0000000000..c47a674675 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosScriptWriteSet.ts @@ -0,0 +1,70 @@ +import { AptosScriptPayloadRequest, AptosScriptPayloadRequestInput, AptosScriptPayloadRequestJSON } from '../types/AptosScriptPayloadRequest'; + +// $ref: #/components/schemas/ScriptWriteSet +// type: ScriptWriteSet +// properties: +// - type ($ref: #/components/schemas/ScriptWriteSet/properties/type) +// - execute_as ($ref: #/components/schemas/ScriptWriteSet/properties/execute_as) +// - script ($ref: #/components/schemas/ScriptPayloadRequest) + +export interface AptosScriptWriteSetJSON { + readonly type: string; + readonly execute_as: string; + readonly script: AptosScriptPayloadRequestJSON; +} + +export interface AptosScriptWriteSetInput { + readonly type: string; + readonly executeAs: string; + readonly script: AptosScriptPayloadRequestInput | AptosScriptPayloadRequest; +} + +export class AptosScriptWriteSet { + public static create(input: AptosScriptWriteSetInput | AptosScriptWriteSet): AptosScriptWriteSet { + if (input instanceof AptosScriptWriteSet) { + return input; + } + return new AptosScriptWriteSet(input); + } + + public static fromJSON(json: AptosScriptWriteSetJSON): AptosScriptWriteSet { + const input: AptosScriptWriteSetInput = { + type: json.type, + executeAs: json.execute_as, + script: AptosScriptPayloadRequest.fromJSON(json.script), + }; + return AptosScriptWriteSet.create(input); + } + + public static isInput(input: any): input is AptosScriptWriteSetInput { + return input.type === 'script_write_set'; + } + + public static isJSON(json: any): json is AptosScriptWriteSetJSON { + return json.type === 'script_write_set'; + } + + public readonly type: string; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly executeAs: string; + /** + * @description Payload which runs a script that can run multiple functions + */ + public readonly script: AptosScriptPayloadRequest; + + private constructor(input: AptosScriptWriteSetInput) { + this.type = input.type; + this.executeAs = input.executeAs; + this.script = AptosScriptPayloadRequest.create(input.script); + } + + public toJSON(): AptosScriptWriteSetJSON { + return { + type: this.type, + execute_as: this.executeAs, + script: this.script.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosSimulateTransaction.ts b/packages/common/aptosUtils/src/generated/types/AptosSimulateTransaction.ts new file mode 100644 index 0000000000..0048989828 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosSimulateTransaction.ts @@ -0,0 +1,55 @@ +import { AptosPendingTransaction, AptosPendingTransactionJSON, AptosPendingTransactionInput } from '../types/AptosPendingTransaction'; +import { AptosUserTransaction, AptosUserTransactionJSON, AptosUserTransactionInput } from '../types/AptosUserTransaction'; +import { AptosGenesisTransaction, AptosGenesisTransactionJSON, AptosGenesisTransactionInput } from '../types/AptosGenesisTransaction'; +import { AptosBlockMetadataTransaction, AptosBlockMetadataTransactionJSON, AptosBlockMetadataTransactionInput } from '../types/AptosBlockMetadataTransaction'; +import { AptosStateCheckpointTransaction, AptosStateCheckpointTransactionJSON, AptosStateCheckpointTransactionInput } from '../types/AptosStateCheckpointTransaction'; + +// $ref: #/paths/~1transactions~1simulate/post/responses/200/content/application~1json/schema +// typeName: simulateTransaction +// unionType: oneOf + +export type AptosSimulateTransactionJSON = AptosPendingTransactionJSON | AptosUserTransactionJSON | AptosGenesisTransactionJSON | AptosBlockMetadataTransactionJSON | AptosStateCheckpointTransactionJSON; +export type AptosSimulateTransactionInput = AptosPendingTransactionInput | AptosUserTransactionInput | AptosGenesisTransactionInput | AptosBlockMetadataTransactionInput | AptosStateCheckpointTransactionInput; +export type AptosSimulateTransactionValue = AptosPendingTransaction | AptosUserTransaction | AptosGenesisTransaction | AptosBlockMetadataTransaction | AptosStateCheckpointTransaction; + +export abstract class AptosSimulateTransaction { + public static create(input: AptosSimulateTransactionInput): AptosSimulateTransactionValue { + if (AptosPendingTransaction.isInput(input)) { + return AptosPendingTransaction.create(input); + } + if (AptosUserTransaction.isInput(input)) { + return AptosUserTransaction.create(input); + } + if (AptosGenesisTransaction.isInput(input)) { + return AptosGenesisTransaction.create(input); + } + if (AptosBlockMetadataTransaction.isInput(input)) { + return AptosBlockMetadataTransaction.create(input); + } + if (AptosStateCheckpointTransaction.isInput(input)) { + return AptosStateCheckpointTransaction.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosSimulateTransactionJSON): AptosSimulateTransactionValue { + if (AptosPendingTransaction.isJSON(json)) { + return AptosPendingTransaction.fromJSON(json); + } + if (AptosUserTransaction.isJSON(json)) { + return AptosUserTransaction.fromJSON(json); + } + if (AptosGenesisTransaction.isJSON(json)) { + return AptosGenesisTransaction.fromJSON(json); + } + if (AptosBlockMetadataTransaction.isJSON(json)) { + return AptosBlockMetadataTransaction.fromJSON(json); + } + if (AptosStateCheckpointTransaction.isJSON(json)) { + return AptosStateCheckpointTransaction.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosSimulateTransaction (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosStateCheckpointTransaction.ts b/packages/common/aptosUtils/src/generated/types/AptosStateCheckpointTransaction.ts new file mode 100644 index 0000000000..8aeb8a72bd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosStateCheckpointTransaction.ts @@ -0,0 +1,142 @@ +import { AptosStateCheckpointTransactionChangesItem, AptosStateCheckpointTransactionChangesItemValue, AptosStateCheckpointTransactionChangesItemInput, AptosStateCheckpointTransactionChangesItemJSON } from '../types/AptosStateCheckpointTransactionChangesItem'; + +// $ref: #/components/schemas/StateCheckpointTransaction +// type: StateCheckpointTransaction +// properties: +// - type ($ref: #/components/schemas/StateCheckpointTransaction/properties/type) +// - version ($ref: #/components/schemas/StateCheckpointTransaction/properties/version) +// - hash ($ref: #/components/schemas/StateCheckpointTransaction/properties/hash) +// - state_change_hash ($ref: #/components/schemas/StateCheckpointTransaction/properties/state_change_hash) +// - event_root_hash ($ref: #/components/schemas/StateCheckpointTransaction/properties/event_root_hash) +// - state_checkpoint_hash ($ref: #/components/schemas/StateCheckpointTransaction/properties/state_checkpoint_hash) +// - gas_used ($ref: #/components/schemas/StateCheckpointTransaction/properties/gas_used) +// - success ($ref: #/components/schemas/StateCheckpointTransaction/properties/success) +// - vm_status ($ref: #/components/schemas/StateCheckpointTransaction/properties/vm_status) +// - accumulator_root_hash ($ref: #/components/schemas/StateCheckpointTransaction/properties/accumulator_root_hash) +// - changes ($ref: #/components/schemas/StateCheckpointTransaction/properties/changes/items) +// - timestamp ($ref: #/components/schemas/StateCheckpointTransaction/properties/timestamp) + +export interface AptosStateCheckpointTransactionJSON { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly state_change_hash: string; + readonly event_root_hash: string; + readonly state_checkpoint_hash: string; + readonly gas_used: string; + readonly success: boolean; + readonly vm_status: string; + readonly accumulator_root_hash: string; + readonly changes: AptosStateCheckpointTransactionChangesItemJSON[]; + readonly timestamp: string; +} + +export interface AptosStateCheckpointTransactionInput { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly stateChangeHash: string; + readonly eventRootHash: string; + readonly stateCheckpointHash: string; + readonly gasUsed: string; + readonly success: boolean; + readonly vmStatus: string; + readonly accumulatorRootHash: string; + readonly changes: AptosStateCheckpointTransactionChangesItemInput[] | AptosStateCheckpointTransactionChangesItemValue[]; + readonly timestamp: string; +} + +export class AptosStateCheckpointTransaction { + public static create(input: AptosStateCheckpointTransactionInput | AptosStateCheckpointTransaction): AptosStateCheckpointTransaction { + if (input instanceof AptosStateCheckpointTransaction) { + return input; + } + return new AptosStateCheckpointTransaction(input); + } + + public static fromJSON(json: AptosStateCheckpointTransactionJSON): AptosStateCheckpointTransaction { + const input: AptosStateCheckpointTransactionInput = { + type: json.type, + version: json.version, + hash: json.hash, + stateChangeHash: json.state_change_hash, + eventRootHash: json.event_root_hash, + stateCheckpointHash: json.state_checkpoint_hash, + gasUsed: json.gas_used, + success: json.success, + vmStatus: json.vm_status, + accumulatorRootHash: json.accumulator_root_hash, + changes: json.changes.map((item) => AptosStateCheckpointTransactionChangesItem.fromJSON(item)), + timestamp: json.timestamp, + }; + return AptosStateCheckpointTransaction.create(input); + } + + public static isInput(input: any): input is AptosStateCheckpointTransactionInput { + return input.type === 'state_checkpoint_transaction'; + } + + public static isJSON(json: any): json is AptosStateCheckpointTransactionJSON { + return json.type === 'state_checkpoint_transaction'; + } + + public readonly type: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly version: string; + public readonly hash: string; + public readonly stateChangeHash: string; + public readonly eventRootHash: string; + public readonly stateCheckpointHash: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUsed: string; + /** + * @description Whether the transaction was successful + */ + public readonly success: boolean; + /** + * @description The VM status of the transaction, can tell useful information in a failure + */ + public readonly vmStatus: string; + public readonly accumulatorRootHash: string; + public readonly changes: AptosStateCheckpointTransactionChangesItemValue[]; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly timestamp: string; + + private constructor(input: AptosStateCheckpointTransactionInput) { + this.type = input.type; + this.version = input.version; + this.hash = input.hash; + this.stateChangeHash = input.stateChangeHash; + this.eventRootHash = input.eventRootHash; + this.stateCheckpointHash = input.stateCheckpointHash; + this.gasUsed = input.gasUsed; + this.success = input.success; + this.vmStatus = input.vmStatus; + this.accumulatorRootHash = input.accumulatorRootHash; + this.changes = input.changes.map((item) => AptosStateCheckpointTransactionChangesItem.create(item)); + this.timestamp = input.timestamp; + } + + public toJSON(): AptosStateCheckpointTransactionJSON { + return { + type: this.type, + version: this.version, + hash: this.hash, + state_change_hash: this.stateChangeHash, + event_root_hash: this.eventRootHash, + state_checkpoint_hash: this.stateCheckpointHash, + gas_used: this.gasUsed, + success: this.success, + vm_status: this.vmStatus, + accumulator_root_hash: this.accumulatorRootHash, + changes: this.changes.map((item) => item.toJSON()), + timestamp: this.timestamp, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosStateCheckpointTransactionChangesItem.ts b/packages/common/aptosUtils/src/generated/types/AptosStateCheckpointTransactionChangesItem.ts new file mode 100644 index 0000000000..f43684e18f --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosStateCheckpointTransactionChangesItem.ts @@ -0,0 +1,62 @@ +import { AptosDeleteModuleChange, AptosDeleteModuleChangeJSON, AptosDeleteModuleChangeInput } from '../types/AptosDeleteModuleChange'; +import { AptosDeleteResourceChange, AptosDeleteResourceChangeJSON, AptosDeleteResourceChangeInput } from '../types/AptosDeleteResourceChange'; +import { AptosDeleteTableItemChange, AptosDeleteTableItemChangeJSON, AptosDeleteTableItemChangeInput } from '../types/AptosDeleteTableItemChange'; +import { AptosWriteOrUpdateModuleChange, AptosWriteOrUpdateModuleChangeJSON, AptosWriteOrUpdateModuleChangeInput } from '../types/AptosWriteOrUpdateModuleChange'; +import { AptosWriteResourceChange, AptosWriteResourceChangeJSON, AptosWriteResourceChangeInput } from '../types/AptosWriteResourceChange'; +import { AptosWriteTableChangeSetChange, AptosWriteTableChangeSetChangeJSON, AptosWriteTableChangeSetChangeInput } from '../types/AptosWriteTableChangeSetChange'; + +// $ref: #/components/schemas/StateCheckpointTransaction/properties/changes/items +// typeName: StateCheckpointTransaction_changes_Item +// unionType: anyOf + +export type AptosStateCheckpointTransactionChangesItemJSON = AptosDeleteModuleChangeJSON | AptosDeleteResourceChangeJSON | AptosDeleteTableItemChangeJSON | AptosWriteOrUpdateModuleChangeJSON | AptosWriteResourceChangeJSON | AptosWriteTableChangeSetChangeJSON; +export type AptosStateCheckpointTransactionChangesItemInput = AptosDeleteModuleChangeInput | AptosDeleteResourceChangeInput | AptosDeleteTableItemChangeInput | AptosWriteOrUpdateModuleChangeInput | AptosWriteResourceChangeInput | AptosWriteTableChangeSetChangeInput; +export type AptosStateCheckpointTransactionChangesItemValue = AptosDeleteModuleChange | AptosDeleteResourceChange | AptosDeleteTableItemChange | AptosWriteOrUpdateModuleChange | AptosWriteResourceChange | AptosWriteTableChangeSetChange; + +export abstract class AptosStateCheckpointTransactionChangesItem { + public static create(input: AptosStateCheckpointTransactionChangesItemInput): AptosStateCheckpointTransactionChangesItemValue { + if (AptosDeleteModuleChange.isInput(input)) { + return AptosDeleteModuleChange.create(input); + } + if (AptosDeleteResourceChange.isInput(input)) { + return AptosDeleteResourceChange.create(input); + } + if (AptosDeleteTableItemChange.isInput(input)) { + return AptosDeleteTableItemChange.create(input); + } + if (AptosWriteOrUpdateModuleChange.isInput(input)) { + return AptosWriteOrUpdateModuleChange.create(input); + } + if (AptosWriteResourceChange.isInput(input)) { + return AptosWriteResourceChange.create(input); + } + if (AptosWriteTableChangeSetChange.isInput(input)) { + return AptosWriteTableChangeSetChange.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosStateCheckpointTransactionChangesItemJSON): AptosStateCheckpointTransactionChangesItemValue { + if (AptosDeleteModuleChange.isJSON(json)) { + return AptosDeleteModuleChange.fromJSON(json); + } + if (AptosDeleteResourceChange.isJSON(json)) { + return AptosDeleteResourceChange.fromJSON(json); + } + if (AptosDeleteTableItemChange.isJSON(json)) { + return AptosDeleteTableItemChange.fromJSON(json); + } + if (AptosWriteOrUpdateModuleChange.isJSON(json)) { + return AptosWriteOrUpdateModuleChange.fromJSON(json); + } + if (AptosWriteResourceChange.isJSON(json)) { + return AptosWriteResourceChange.fromJSON(json); + } + if (AptosWriteTableChangeSetChange.isJSON(json)) { + return AptosWriteTableChangeSetChange.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosStateCheckpointTransactionChangesItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosSubmitBatchTransactionResult.ts b/packages/common/aptosUtils/src/generated/types/AptosSubmitBatchTransactionResult.ts new file mode 100644 index 0000000000..be7af83505 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosSubmitBatchTransactionResult.ts @@ -0,0 +1,43 @@ +// $ref: #/components/schemas/SubmitBatchTransactionResult +// type: SubmitBatchTransactionResult +// properties: +// - transaction_failures ($ref: #/components/schemas/SubmitBatchTransactionResult/properties/transaction_failures) + +export interface AptosSubmitBatchTransactionResultJSON { + readonly transaction_failures: string[]; +} + +export interface AptosSubmitBatchTransactionResultInput { + readonly transactionFailures: string[]; +} + +export class AptosSubmitBatchTransactionResult { + public static create(input: AptosSubmitBatchTransactionResultInput | AptosSubmitBatchTransactionResult): AptosSubmitBatchTransactionResult { + if (input instanceof AptosSubmitBatchTransactionResult) { + return input; + } + return new AptosSubmitBatchTransactionResult(input); + } + + public static fromJSON(json: AptosSubmitBatchTransactionResultJSON): AptosSubmitBatchTransactionResult { + const input: AptosSubmitBatchTransactionResultInput = { + transactionFailures: json.transaction_failures, + }; + return AptosSubmitBatchTransactionResult.create(input); + } + + /** + * @description Summary of the failed transactions + */ + public readonly transactionFailures: string[]; + + private constructor(input: AptosSubmitBatchTransactionResultInput) { + this.transactionFailures = input.transactionFailures; + } + + public toJSON(): AptosSubmitBatchTransactionResultJSON { + return { + transaction_failures: this.transactionFailures, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequest.ts b/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequest.ts new file mode 100644 index 0000000000..76ffc820d3 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequest.ts @@ -0,0 +1,104 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosSubmitTransactionRequestPayload, AptosSubmitTransactionRequestPayloadValue, AptosSubmitTransactionRequestPayloadInput, AptosSubmitTransactionRequestPayloadJSON } from '../types/AptosSubmitTransactionRequestPayload'; +import { AptosSubmitTransactionRequestSignature, AptosSubmitTransactionRequestSignatureValue, AptosSubmitTransactionRequestSignatureInput, AptosSubmitTransactionRequestSignatureJSON } from '../types/AptosSubmitTransactionRequestSignature'; + +// $ref: #/components/schemas/SubmitTransactionRequest +// type: SubmitTransactionRequest +// properties: +// - sender ($ref: #/components/schemas/SubmitTransactionRequest/properties/sender) +// - sequence_number ($ref: #/components/schemas/SubmitTransactionRequest/properties/sequence_number) +// - max_gas_amount ($ref: #/components/schemas/SubmitTransactionRequest/properties/max_gas_amount) +// - gas_unit_price ($ref: #/components/schemas/SubmitTransactionRequest/properties/gas_unit_price) +// - expiration_timestamp_secs ($ref: #/components/schemas/SubmitTransactionRequest/properties/expiration_timestamp_secs) +// - payload ($ref: #/components/schemas/SubmitTransactionRequest/properties/payload) +// - signature ($ref: #/components/schemas/SubmitTransactionRequest/properties/signature) + +export interface AptosSubmitTransactionRequestJSON { + readonly sender: AptosAddressJSON; + readonly sequence_number: string; + readonly max_gas_amount: string; + readonly gas_unit_price: string; + readonly expiration_timestamp_secs: string; + readonly payload: AptosSubmitTransactionRequestPayloadJSON; + readonly signature: AptosSubmitTransactionRequestSignatureJSON; +} + +export interface AptosSubmitTransactionRequestInput { + readonly sender: AptosAddressInput | AptosAddress; + readonly sequenceNumber: string; + readonly maxGasAmount: string; + readonly gasUnitPrice: string; + readonly expirationTimestampSecs: string; + readonly payload: AptosSubmitTransactionRequestPayloadInput | AptosSubmitTransactionRequestPayloadValue; + readonly signature: AptosSubmitTransactionRequestSignatureInput | AptosSubmitTransactionRequestSignatureValue; +} + +export class AptosSubmitTransactionRequest { + public static create(input: AptosSubmitTransactionRequestInput | AptosSubmitTransactionRequest): AptosSubmitTransactionRequest { + if (input instanceof AptosSubmitTransactionRequest) { + return input; + } + return new AptosSubmitTransactionRequest(input); + } + + public static fromJSON(json: AptosSubmitTransactionRequestJSON): AptosSubmitTransactionRequest { + const input: AptosSubmitTransactionRequestInput = { + sender: AptosAddress.fromJSON(json.sender), + sequenceNumber: json.sequence_number, + maxGasAmount: json.max_gas_amount, + gasUnitPrice: json.gas_unit_price, + expirationTimestampSecs: json.expiration_timestamp_secs, + payload: AptosSubmitTransactionRequestPayload.fromJSON(json.payload), + signature: AptosSubmitTransactionRequestSignature.fromJSON(json.signature), + }; + return AptosSubmitTransactionRequest.create(input); + } + + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly sender: AptosAddress; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly sequenceNumber: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly maxGasAmount: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUnitPrice: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly expirationTimestampSecs: string; + /** + * @description An enum of the possible transaction payloads + */ + public readonly payload: AptosSubmitTransactionRequestPayloadValue; + public readonly signature: AptosSubmitTransactionRequestSignatureValue; + + private constructor(input: AptosSubmitTransactionRequestInput) { + this.sender = AptosAddress.create(input.sender); + this.sequenceNumber = input.sequenceNumber; + this.maxGasAmount = input.maxGasAmount; + this.gasUnitPrice = input.gasUnitPrice; + this.expirationTimestampSecs = input.expirationTimestampSecs; + this.payload = AptosSubmitTransactionRequestPayload.create(input.payload); + this.signature = AptosSubmitTransactionRequestSignature.create(input.signature); + } + + public toJSON(): AptosSubmitTransactionRequestJSON { + return { + sender: this.sender.toJSON(), + sequence_number: this.sequenceNumber, + max_gas_amount: this.maxGasAmount, + gas_unit_price: this.gasUnitPrice, + expiration_timestamp_secs: this.expirationTimestampSecs, + payload: this.payload.toJSON(), + signature: this.signature.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequestPayload.ts b/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequestPayload.ts new file mode 100644 index 0000000000..b4d733c899 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequestPayload.ts @@ -0,0 +1,41 @@ +import { AptosEntryFunctionPayloadRequest, AptosEntryFunctionPayloadRequestJSON, AptosEntryFunctionPayloadRequestInput } from '../types/AptosEntryFunctionPayloadRequest'; +import { AptosScriptPayloadRequest, AptosScriptPayloadRequestJSON, AptosScriptPayloadRequestInput } from '../types/AptosScriptPayloadRequest'; +import { AptosModuleBundlePayloadRequest, AptosModuleBundlePayloadRequestJSON, AptosModuleBundlePayloadRequestInput } from '../types/AptosModuleBundlePayloadRequest'; + +// $ref: #/components/schemas/SubmitTransactionRequest/properties/payload +// typeName: SubmitTransactionRequest_payload +// unionType: oneOf + +export type AptosSubmitTransactionRequestPayloadJSON = AptosEntryFunctionPayloadRequestJSON | AptosScriptPayloadRequestJSON | AptosModuleBundlePayloadRequestJSON; +export type AptosSubmitTransactionRequestPayloadInput = AptosEntryFunctionPayloadRequestInput | AptosScriptPayloadRequestInput | AptosModuleBundlePayloadRequestInput; +export type AptosSubmitTransactionRequestPayloadValue = AptosEntryFunctionPayloadRequest | AptosScriptPayloadRequest | AptosModuleBundlePayloadRequest; + +export abstract class AptosSubmitTransactionRequestPayload { + public static create(input: AptosSubmitTransactionRequestPayloadInput): AptosSubmitTransactionRequestPayloadValue { + if (AptosEntryFunctionPayloadRequest.isInput(input)) { + return AptosEntryFunctionPayloadRequest.create(input); + } + if (AptosScriptPayloadRequest.isInput(input)) { + return AptosScriptPayloadRequest.create(input); + } + if (AptosModuleBundlePayloadRequest.isInput(input)) { + return AptosModuleBundlePayloadRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosSubmitTransactionRequestPayloadJSON): AptosSubmitTransactionRequestPayloadValue { + if (AptosEntryFunctionPayloadRequest.isJSON(json)) { + return AptosEntryFunctionPayloadRequest.fromJSON(json); + } + if (AptosScriptPayloadRequest.isJSON(json)) { + return AptosScriptPayloadRequest.fromJSON(json); + } + if (AptosModuleBundlePayloadRequest.isJSON(json)) { + return AptosModuleBundlePayloadRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosSubmitTransactionRequestPayload (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequestSignature.ts b/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequestSignature.ts new file mode 100644 index 0000000000..84701e5b96 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosSubmitTransactionRequestSignature.ts @@ -0,0 +1,41 @@ +import { AptosEd25519SignatureRequest, AptosEd25519SignatureRequestJSON, AptosEd25519SignatureRequestInput } from '../types/AptosEd25519SignatureRequest'; +import { AptosMultiEd25519SignatureRequest, AptosMultiEd25519SignatureRequestJSON, AptosMultiEd25519SignatureRequestInput } from '../types/AptosMultiEd25519SignatureRequest'; +import { AptosMultiAgentSignatureRequest, AptosMultiAgentSignatureRequestJSON, AptosMultiAgentSignatureRequestInput } from '../types/AptosMultiAgentSignatureRequest'; + +// $ref: #/components/schemas/SubmitTransactionRequest/properties/signature +// typeName: SubmitTransactionRequest_signature +// unionType: oneOf + +export type AptosSubmitTransactionRequestSignatureJSON = AptosEd25519SignatureRequestJSON | AptosMultiEd25519SignatureRequestJSON | AptosMultiAgentSignatureRequestJSON; +export type AptosSubmitTransactionRequestSignatureInput = AptosEd25519SignatureRequestInput | AptosMultiEd25519SignatureRequestInput | AptosMultiAgentSignatureRequestInput; +export type AptosSubmitTransactionRequestSignatureValue = AptosEd25519SignatureRequest | AptosMultiEd25519SignatureRequest | AptosMultiAgentSignatureRequest; + +export abstract class AptosSubmitTransactionRequestSignature { + public static create(input: AptosSubmitTransactionRequestSignatureInput): AptosSubmitTransactionRequestSignatureValue { + if (AptosEd25519SignatureRequest.isInput(input)) { + return AptosEd25519SignatureRequest.create(input); + } + if (AptosMultiEd25519SignatureRequest.isInput(input)) { + return AptosMultiEd25519SignatureRequest.create(input); + } + if (AptosMultiAgentSignatureRequest.isInput(input)) { + return AptosMultiAgentSignatureRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosSubmitTransactionRequestSignatureJSON): AptosSubmitTransactionRequestSignatureValue { + if (AptosEd25519SignatureRequest.isJSON(json)) { + return AptosEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiEd25519SignatureRequest.isJSON(json)) { + return AptosMultiEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiAgentSignatureRequest.isJSON(json)) { + return AptosMultiAgentSignatureRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosSubmitTransactionRequestSignature (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosTransactionEvent.ts b/packages/common/aptosUtils/src/generated/types/AptosTransactionEvent.ts new file mode 100644 index 0000000000..526bd524eb --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosTransactionEvent.ts @@ -0,0 +1,73 @@ +import { AptosTransactionEventGuid, AptosTransactionEventGuidInput, AptosTransactionEventGuidJSON } from '../types/AptosTransactionEventGuid'; +import { AptosTransactionEventData, AptosTransactionEventDataValue, AptosTransactionEventDataInput, AptosTransactionEventDataJSON } from '../types/AptosTransactionEventData'; + +// $ref: #/components/schemas/TransactionEvent +// type: TransactionEvent +// properties: +// - guid ($ref: #/components/schemas/TransactionEventGuid) +// - sequence_number ($ref: #/components/schemas/TransactionEvent/properties/sequence_number) +// - type ($ref: #/components/schemas/TransactionEvent/properties/type) +// - data ($ref: #/components/schemas/TransactionEvent/properties/data) + +export interface AptosTransactionEventJSON { + readonly guid: AptosTransactionEventGuidJSON; + readonly sequence_number: string; + readonly type: string; + readonly data: AptosTransactionEventDataJSON; +} + +export interface AptosTransactionEventInput { + readonly guid: AptosTransactionEventGuidInput | AptosTransactionEventGuid; + readonly sequenceNumber: string; + readonly type: string; + readonly data: AptosTransactionEventDataInput | AptosTransactionEventDataValue; +} + +export class AptosTransactionEvent { + public static create(input: AptosTransactionEventInput | AptosTransactionEvent): AptosTransactionEvent { + if (input instanceof AptosTransactionEvent) { + return input; + } + return new AptosTransactionEvent(input); + } + + public static fromJSON(json: AptosTransactionEventJSON): AptosTransactionEvent { + const input: AptosTransactionEventInput = { + guid: AptosTransactionEventGuid.fromJSON(json.guid), + sequenceNumber: json.sequence_number, + type: json.type, + data: AptosTransactionEventData.fromJSON(json.data), + }; + return AptosTransactionEvent.create(input); + } + + public readonly guid: AptosTransactionEventGuid; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly sequenceNumber: string; + /** + * @description String representation of an on-chain Move type tag that is exposed in transaction payload. + */ + public readonly type: string; + /** + * @description The JSON representation of the event + */ + public readonly data: AptosTransactionEventDataValue; + + private constructor(input: AptosTransactionEventInput) { + this.guid = AptosTransactionEventGuid.create(input.guid); + this.sequenceNumber = input.sequenceNumber; + this.type = input.type; + this.data = AptosTransactionEventData.create(input.data); + } + + public toJSON(): AptosTransactionEventJSON { + return { + guid: this.guid.toJSON(), + sequence_number: this.sequenceNumber, + type: this.type, + data: this.data, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosTransactionEventData.ts b/packages/common/aptosUtils/src/generated/types/AptosTransactionEventData.ts new file mode 100644 index 0000000000..160209d33b --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosTransactionEventData.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/TransactionEvent/properties/data +// typeName: TransactionEvent_data + +export type AptosTransactionEventDataJSON = object; +export type AptosTransactionEventDataInput = object; +export type AptosTransactionEventDataValue = object; + +export abstract class AptosTransactionEventData { + public static create(input: AptosTransactionEventDataInput | AptosTransactionEventDataValue): AptosTransactionEventDataValue { + return input; + } + + public static fromJSON(json: AptosTransactionEventDataJSON): AptosTransactionEventDataValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosTransactionEventGuid.ts b/packages/common/aptosUtils/src/generated/types/AptosTransactionEventGuid.ts new file mode 100644 index 0000000000..765557c143 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosTransactionEventGuid.ts @@ -0,0 +1,57 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; + +// $ref: #/components/schemas/TransactionEventGuid +// type: TransactionEventGuid +// properties: +// - creation_number ($ref: #/components/schemas/TransactionEventGuid/properties/creation_number) +// - account_address ($ref: #/components/schemas/TransactionEventGuid/properties/account_address) + +export interface AptosTransactionEventGuidJSON { + readonly creation_number: string; + readonly account_address: AptosAddressJSON; +} + +export interface AptosTransactionEventGuidInput { + readonly creationNumber: string; + readonly accountAddress: AptosAddressInput | AptosAddress; +} + +export class AptosTransactionEventGuid { + public static create(input: AptosTransactionEventGuidInput | AptosTransactionEventGuid): AptosTransactionEventGuid { + if (input instanceof AptosTransactionEventGuid) { + return input; + } + return new AptosTransactionEventGuid(input); + } + + public static fromJSON(json: AptosTransactionEventGuidJSON): AptosTransactionEventGuid { + const input: AptosTransactionEventGuidInput = { + creationNumber: json.creation_number, + accountAddress: AptosAddress.fromJSON(json.account_address), + }; + return AptosTransactionEventGuid.create(input); + } + + /** + * @description A string containing a 64-bit unsigned integer. + * We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. + */ + public readonly creationNumber: string; + /** + * @description A hex encoded 32 byte Aptos account address. + * This is represented in a string as a 64 character hex string, sometimes shortened by stripping leading 0s, and adding a 0x. + */ + public readonly accountAddress: AptosAddress; + + private constructor(input: AptosTransactionEventGuidInput) { + this.creationNumber = input.creationNumber; + this.accountAddress = AptosAddress.create(input.accountAddress); + } + + public toJSON(): AptosTransactionEventGuidJSON { + return { + creation_number: this.creationNumber, + account_address: this.accountAddress.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosUserTransaction.ts b/packages/common/aptosUtils/src/generated/types/AptosUserTransaction.ts new file mode 100644 index 0000000000..317fc169fd --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosUserTransaction.ts @@ -0,0 +1,223 @@ +import { AptosUserTransactionChangesItem, AptosUserTransactionChangesItemValue, AptosUserTransactionChangesItemInput, AptosUserTransactionChangesItemJSON } from '../types/AptosUserTransactionChangesItem'; +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosUserTransactionPayload, AptosUserTransactionPayloadValue, AptosUserTransactionPayloadInput, AptosUserTransactionPayloadJSON } from '../types/AptosUserTransactionPayload'; +import { AptosUserTransactionSignature, AptosUserTransactionSignatureValue, AptosUserTransactionSignatureInput, AptosUserTransactionSignatureJSON } from '../types/AptosUserTransactionSignature'; +import { AptosTransactionEvent, AptosTransactionEventInput, AptosTransactionEventJSON } from '../types/AptosTransactionEvent'; + +// $ref: #/components/schemas/UserTransaction +// type: UserTransaction +// properties: +// - type ($ref: #/components/schemas/UserTransaction/properties/type) +// - version ($ref: #/components/schemas/UserTransaction/properties/version) +// - hash ($ref: #/components/schemas/UserTransaction/properties/hash) +// - state_change_hash ($ref: #/components/schemas/UserTransaction/properties/state_change_hash) +// - event_root_hash ($ref: #/components/schemas/UserTransaction/properties/event_root_hash) +// - state_checkpoint_hash ($ref: #/components/schemas/UserTransaction/properties/state_checkpoint_hash) +// - gas_used ($ref: #/components/schemas/UserTransaction/properties/gas_used) +// - success ($ref: #/components/schemas/UserTransaction/properties/success) +// - vm_status ($ref: #/components/schemas/UserTransaction/properties/vm_status) +// - accumulator_root_hash ($ref: #/components/schemas/UserTransaction/properties/accumulator_root_hash) +// - changes ($ref: #/components/schemas/UserTransaction/properties/changes/items) +// - sender ($ref: #/components/schemas/UserTransaction/properties/sender) +// - sequence_number ($ref: #/components/schemas/UserTransaction/properties/sequence_number) +// - max_gas_amount ($ref: #/components/schemas/UserTransaction/properties/max_gas_amount) +// - gas_unit_price ($ref: #/components/schemas/UserTransaction/properties/gas_unit_price) +// - expiration_timestamp_secs ($ref: #/components/schemas/UserTransaction/properties/expiration_timestamp_secs) +// - payload ($ref: #/components/schemas/UserTransaction/properties/payload) +// - signature ($ref: #/components/schemas/UserTransaction/properties/signature) +// - events ($ref: #/components/schemas/TransactionEvent) +// - timestamp ($ref: #/components/schemas/UserTransaction/properties/timestamp) + +export interface AptosUserTransactionJSON { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly state_change_hash: string; + readonly event_root_hash: string; + readonly state_checkpoint_hash: string; + readonly gas_used: string; + readonly success: boolean; + readonly vm_status: string; + readonly accumulator_root_hash: string; + readonly changes: AptosUserTransactionChangesItemJSON[]; + readonly sender: AptosAddressJSON; + readonly sequence_number: string; + readonly max_gas_amount: string; + readonly gas_unit_price: string; + readonly expiration_timestamp_secs: string; + readonly payload: AptosUserTransactionPayloadJSON; + readonly signature: AptosUserTransactionSignatureJSON; + readonly events: AptosTransactionEventJSON[]; + readonly timestamp: string; +} + +export interface AptosUserTransactionInput { + readonly type: string; + readonly version: string; + readonly hash: string; + readonly stateChangeHash: string; + readonly eventRootHash: string; + readonly stateCheckpointHash: string; + readonly gasUsed: string; + readonly success: boolean; + readonly vmStatus: string; + readonly accumulatorRootHash: string; + readonly changes: AptosUserTransactionChangesItemInput[] | AptosUserTransactionChangesItemValue[]; + readonly sender: AptosAddressInput | AptosAddress; + readonly sequenceNumber: string; + readonly maxGasAmount: string; + readonly gasUnitPrice: string; + readonly expirationTimestampSecs: string; + readonly payload: AptosUserTransactionPayloadInput | AptosUserTransactionPayloadValue; + readonly signature: AptosUserTransactionSignatureInput | AptosUserTransactionSignatureValue; + readonly events: AptosTransactionEventInput[] | AptosTransactionEvent[]; + readonly timestamp: string; +} + +export class AptosUserTransaction { + public static create(input: AptosUserTransactionInput | AptosUserTransaction): AptosUserTransaction { + if (input instanceof AptosUserTransaction) { + return input; + } + return new AptosUserTransaction(input); + } + + public static fromJSON(json: AptosUserTransactionJSON): AptosUserTransaction { + const input: AptosUserTransactionInput = { + type: json.type, + version: json.version, + hash: json.hash, + stateChangeHash: json.state_change_hash, + eventRootHash: json.event_root_hash, + stateCheckpointHash: json.state_checkpoint_hash, + gasUsed: json.gas_used, + success: json.success, + vmStatus: json.vm_status, + accumulatorRootHash: json.accumulator_root_hash, + changes: json.changes.map((item) => AptosUserTransactionChangesItem.fromJSON(item)), + sender: AptosAddress.fromJSON(json.sender), + sequenceNumber: json.sequence_number, + maxGasAmount: json.max_gas_amount, + gasUnitPrice: json.gas_unit_price, + expirationTimestampSecs: json.expiration_timestamp_secs, + payload: AptosUserTransactionPayload.fromJSON(json.payload), + signature: AptosUserTransactionSignature.fromJSON(json.signature), + events: json.events.map((item) => AptosTransactionEvent.fromJSON(item)), + timestamp: json.timestamp, + }; + return AptosUserTransaction.create(input); + } + + public static isInput(input: any): input is AptosUserTransactionInput { + return input.type === 'user_transaction'; + } + + public static isJSON(json: any): json is AptosUserTransactionJSON { + return json.type === 'user_transaction'; + } + + /** + * @description user_transaction + */ + public readonly type: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly version: string; + public readonly hash: string; + public readonly stateChangeHash: string; + public readonly eventRootHash: string; + public readonly stateCheckpointHash: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUsed: string; + /** + * @description Whether the transaction was successful + */ + public readonly success: boolean; + /** + * @description The VM status of the transaction, can tell useful information in a failure + */ + public readonly vmStatus: string; + public readonly accumulatorRootHash: string; + public readonly changes: AptosUserTransactionChangesItemValue[]; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly sender: AptosAddress; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly sequenceNumber: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly maxGasAmount: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly gasUnitPrice: string; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly expirationTimestampSecs: string; + public readonly payload: AptosUserTransactionPayloadValue; + public readonly signature: AptosUserTransactionSignatureValue; + /** + * @description Events generated by the transaction + */ + public readonly events: AptosTransactionEvent[]; + /** + * @description A string containing a 64-bit unsigned integer. + */ + public readonly timestamp: string; + + private constructor(input: AptosUserTransactionInput) { + this.type = input.type; + this.version = input.version; + this.hash = input.hash; + this.stateChangeHash = input.stateChangeHash; + this.eventRootHash = input.eventRootHash; + this.stateCheckpointHash = input.stateCheckpointHash; + this.gasUsed = input.gasUsed; + this.success = input.success; + this.vmStatus = input.vmStatus; + this.accumulatorRootHash = input.accumulatorRootHash; + this.changes = input.changes.map((item) => AptosUserTransactionChangesItem.create(item)); + this.sender = AptosAddress.create(input.sender); + this.sequenceNumber = input.sequenceNumber; + this.maxGasAmount = input.maxGasAmount; + this.gasUnitPrice = input.gasUnitPrice; + this.expirationTimestampSecs = input.expirationTimestampSecs; + this.payload = AptosUserTransactionPayload.create(input.payload); + this.signature = AptosUserTransactionSignature.create(input.signature); + this.events = input.events.map((item) => AptosTransactionEvent.create(item)); + this.timestamp = input.timestamp; + } + + public toJSON(): AptosUserTransactionJSON { + return { + type: this.type, + version: this.version, + hash: this.hash, + state_change_hash: this.stateChangeHash, + event_root_hash: this.eventRootHash, + state_checkpoint_hash: this.stateCheckpointHash, + gas_used: this.gasUsed, + success: this.success, + vm_status: this.vmStatus, + accumulator_root_hash: this.accumulatorRootHash, + changes: this.changes.map((item) => item.toJSON()), + sender: this.sender.toJSON(), + sequence_number: this.sequenceNumber, + max_gas_amount: this.maxGasAmount, + gas_unit_price: this.gasUnitPrice, + expiration_timestamp_secs: this.expirationTimestampSecs, + payload: this.payload.toJSON(), + signature: this.signature.toJSON(), + events: this.events.map((item) => item.toJSON()), + timestamp: this.timestamp, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosUserTransactionChangesItem.ts b/packages/common/aptosUtils/src/generated/types/AptosUserTransactionChangesItem.ts new file mode 100644 index 0000000000..6186005d5d --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosUserTransactionChangesItem.ts @@ -0,0 +1,62 @@ +import { AptosDeleteModuleChange, AptosDeleteModuleChangeJSON, AptosDeleteModuleChangeInput } from '../types/AptosDeleteModuleChange'; +import { AptosDeleteResourceChange, AptosDeleteResourceChangeJSON, AptosDeleteResourceChangeInput } from '../types/AptosDeleteResourceChange'; +import { AptosDeleteTableItemChange, AptosDeleteTableItemChangeJSON, AptosDeleteTableItemChangeInput } from '../types/AptosDeleteTableItemChange'; +import { AptosWriteOrUpdateModuleChange, AptosWriteOrUpdateModuleChangeJSON, AptosWriteOrUpdateModuleChangeInput } from '../types/AptosWriteOrUpdateModuleChange'; +import { AptosWriteResourceChange, AptosWriteResourceChangeJSON, AptosWriteResourceChangeInput } from '../types/AptosWriteResourceChange'; +import { AptosWriteTableChangeSetChange, AptosWriteTableChangeSetChangeJSON, AptosWriteTableChangeSetChangeInput } from '../types/AptosWriteTableChangeSetChange'; + +// $ref: #/components/schemas/UserTransaction/properties/changes/items +// typeName: UserTransaction_changes_Item +// unionType: anyOf + +export type AptosUserTransactionChangesItemJSON = AptosDeleteModuleChangeJSON | AptosDeleteResourceChangeJSON | AptosDeleteTableItemChangeJSON | AptosWriteOrUpdateModuleChangeJSON | AptosWriteResourceChangeJSON | AptosWriteTableChangeSetChangeJSON; +export type AptosUserTransactionChangesItemInput = AptosDeleteModuleChangeInput | AptosDeleteResourceChangeInput | AptosDeleteTableItemChangeInput | AptosWriteOrUpdateModuleChangeInput | AptosWriteResourceChangeInput | AptosWriteTableChangeSetChangeInput; +export type AptosUserTransactionChangesItemValue = AptosDeleteModuleChange | AptosDeleteResourceChange | AptosDeleteTableItemChange | AptosWriteOrUpdateModuleChange | AptosWriteResourceChange | AptosWriteTableChangeSetChange; + +export abstract class AptosUserTransactionChangesItem { + public static create(input: AptosUserTransactionChangesItemInput): AptosUserTransactionChangesItemValue { + if (AptosDeleteModuleChange.isInput(input)) { + return AptosDeleteModuleChange.create(input); + } + if (AptosDeleteResourceChange.isInput(input)) { + return AptosDeleteResourceChange.create(input); + } + if (AptosDeleteTableItemChange.isInput(input)) { + return AptosDeleteTableItemChange.create(input); + } + if (AptosWriteOrUpdateModuleChange.isInput(input)) { + return AptosWriteOrUpdateModuleChange.create(input); + } + if (AptosWriteResourceChange.isInput(input)) { + return AptosWriteResourceChange.create(input); + } + if (AptosWriteTableChangeSetChange.isInput(input)) { + return AptosWriteTableChangeSetChange.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosUserTransactionChangesItemJSON): AptosUserTransactionChangesItemValue { + if (AptosDeleteModuleChange.isJSON(json)) { + return AptosDeleteModuleChange.fromJSON(json); + } + if (AptosDeleteResourceChange.isJSON(json)) { + return AptosDeleteResourceChange.fromJSON(json); + } + if (AptosDeleteTableItemChange.isJSON(json)) { + return AptosDeleteTableItemChange.fromJSON(json); + } + if (AptosWriteOrUpdateModuleChange.isJSON(json)) { + return AptosWriteOrUpdateModuleChange.fromJSON(json); + } + if (AptosWriteResourceChange.isJSON(json)) { + return AptosWriteResourceChange.fromJSON(json); + } + if (AptosWriteTableChangeSetChange.isJSON(json)) { + return AptosWriteTableChangeSetChange.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosUserTransactionChangesItem (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosUserTransactionPayload.ts b/packages/common/aptosUtils/src/generated/types/AptosUserTransactionPayload.ts new file mode 100644 index 0000000000..bf9e31c647 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosUserTransactionPayload.ts @@ -0,0 +1,41 @@ +import { AptosEntryFunctionPayloadRequest, AptosEntryFunctionPayloadRequestJSON, AptosEntryFunctionPayloadRequestInput } from '../types/AptosEntryFunctionPayloadRequest'; +import { AptosScriptPayloadRequest, AptosScriptPayloadRequestJSON, AptosScriptPayloadRequestInput } from '../types/AptosScriptPayloadRequest'; +import { AptosModuleBundlePayloadRequest, AptosModuleBundlePayloadRequestJSON, AptosModuleBundlePayloadRequestInput } from '../types/AptosModuleBundlePayloadRequest'; + +// $ref: #/components/schemas/UserTransaction/properties/payload +// typeName: UserTransaction_payload +// unionType: oneOf + +export type AptosUserTransactionPayloadJSON = AptosEntryFunctionPayloadRequestJSON | AptosScriptPayloadRequestJSON | AptosModuleBundlePayloadRequestJSON; +export type AptosUserTransactionPayloadInput = AptosEntryFunctionPayloadRequestInput | AptosScriptPayloadRequestInput | AptosModuleBundlePayloadRequestInput; +export type AptosUserTransactionPayloadValue = AptosEntryFunctionPayloadRequest | AptosScriptPayloadRequest | AptosModuleBundlePayloadRequest; + +export abstract class AptosUserTransactionPayload { + public static create(input: AptosUserTransactionPayloadInput): AptosUserTransactionPayloadValue { + if (AptosEntryFunctionPayloadRequest.isInput(input)) { + return AptosEntryFunctionPayloadRequest.create(input); + } + if (AptosScriptPayloadRequest.isInput(input)) { + return AptosScriptPayloadRequest.create(input); + } + if (AptosModuleBundlePayloadRequest.isInput(input)) { + return AptosModuleBundlePayloadRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosUserTransactionPayloadJSON): AptosUserTransactionPayloadValue { + if (AptosEntryFunctionPayloadRequest.isJSON(json)) { + return AptosEntryFunctionPayloadRequest.fromJSON(json); + } + if (AptosScriptPayloadRequest.isJSON(json)) { + return AptosScriptPayloadRequest.fromJSON(json); + } + if (AptosModuleBundlePayloadRequest.isJSON(json)) { + return AptosModuleBundlePayloadRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosUserTransactionPayload (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosUserTransactionSignature.ts b/packages/common/aptosUtils/src/generated/types/AptosUserTransactionSignature.ts new file mode 100644 index 0000000000..e4136bbb0c --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosUserTransactionSignature.ts @@ -0,0 +1,41 @@ +import { AptosEd25519SignatureRequest, AptosEd25519SignatureRequestJSON, AptosEd25519SignatureRequestInput } from '../types/AptosEd25519SignatureRequest'; +import { AptosMultiEd25519SignatureRequest, AptosMultiEd25519SignatureRequestJSON, AptosMultiEd25519SignatureRequestInput } from '../types/AptosMultiEd25519SignatureRequest'; +import { AptosMultiAgentSignatureRequest, AptosMultiAgentSignatureRequestJSON, AptosMultiAgentSignatureRequestInput } from '../types/AptosMultiAgentSignatureRequest'; + +// $ref: #/components/schemas/UserTransaction/properties/signature +// typeName: UserTransaction_signature +// unionType: oneOf + +export type AptosUserTransactionSignatureJSON = AptosEd25519SignatureRequestJSON | AptosMultiEd25519SignatureRequestJSON | AptosMultiAgentSignatureRequestJSON; +export type AptosUserTransactionSignatureInput = AptosEd25519SignatureRequestInput | AptosMultiEd25519SignatureRequestInput | AptosMultiAgentSignatureRequestInput; +export type AptosUserTransactionSignatureValue = AptosEd25519SignatureRequest | AptosMultiEd25519SignatureRequest | AptosMultiAgentSignatureRequest; + +export abstract class AptosUserTransactionSignature { + public static create(input: AptosUserTransactionSignatureInput): AptosUserTransactionSignatureValue { + if (AptosEd25519SignatureRequest.isInput(input)) { + return AptosEd25519SignatureRequest.create(input); + } + if (AptosMultiEd25519SignatureRequest.isInput(input)) { + return AptosMultiEd25519SignatureRequest.create(input); + } + if (AptosMultiAgentSignatureRequest.isInput(input)) { + return AptosMultiAgentSignatureRequest.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosUserTransactionSignatureJSON): AptosUserTransactionSignatureValue { + if (AptosEd25519SignatureRequest.isJSON(json)) { + return AptosEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiEd25519SignatureRequest.isJSON(json)) { + return AptosMultiEd25519SignatureRequest.fromJSON(json); + } + if (AptosMultiAgentSignatureRequest.isJSON(json)) { + return AptosMultiAgentSignatureRequest.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosUserTransactionSignature (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteModuleData.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteModuleData.ts new file mode 100644 index 0000000000..b3b5fca642 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteModuleData.ts @@ -0,0 +1,52 @@ +import { AptosMoveModuleAbi, AptosMoveModuleAbiInput, AptosMoveModuleAbiJSON } from '../types/AptosMoveModuleAbi'; + +// $ref: #/components/schemas/WriteModuleData +// type: WriteModuleData +// properties: +// - bytecode ($ref: #/components/schemas/WriteModuleData/properties/bytecode) +// - abi ($ref: #/components/schemas/MoveModuleAbi) + +export interface AptosWriteModuleDataJSON { + readonly bytecode: string; + readonly abi: AptosMoveModuleAbiJSON; +} + +export interface AptosWriteModuleDataInput { + readonly bytecode: string; + readonly abi: AptosMoveModuleAbiInput | AptosMoveModuleAbi; +} + +export class AptosWriteModuleData { + public static create(input: AptosWriteModuleDataInput | AptosWriteModuleData): AptosWriteModuleData { + if (input instanceof AptosWriteModuleData) { + return input; + } + return new AptosWriteModuleData(input); + } + + public static fromJSON(json: AptosWriteModuleDataJSON): AptosWriteModuleData { + const input: AptosWriteModuleDataInput = { + bytecode: json.bytecode, + abi: AptosMoveModuleAbi.fromJSON(json.abi), + }; + return AptosWriteModuleData.create(input); + } + + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly bytecode: string; + public readonly abi: AptosMoveModuleAbi; + + private constructor(input: AptosWriteModuleDataInput) { + this.bytecode = input.bytecode; + this.abi = AptosMoveModuleAbi.create(input.abi); + } + + public toJSON(): AptosWriteModuleDataJSON { + return { + bytecode: this.bytecode, + abi: this.abi.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteOrUpdateModuleChange.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteOrUpdateModuleChange.ts new file mode 100644 index 0000000000..bcd50d7395 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteOrUpdateModuleChange.ts @@ -0,0 +1,78 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosWriteModuleData, AptosWriteModuleDataInput, AptosWriteModuleDataJSON } from '../types/AptosWriteModuleData'; + +// $ref: #/components/schemas/WriteOrUpdateModuleChange +// type: WriteOrUpdateModuleChange +// properties: +// - type ($ref: #/components/schemas/WriteOrUpdateModuleChange/properties/type) +// - address ($ref: #/components/schemas/WriteOrUpdateModuleChange/properties/address) +// - state_key_hash ($ref: #/components/schemas/WriteOrUpdateModuleChange/properties/state_key_hash) +// - data ($ref: #/components/schemas/WriteModuleData) + +export interface AptosWriteOrUpdateModuleChangeJSON { + readonly type: string; + readonly address: AptosAddressJSON; + readonly state_key_hash: string; + readonly data: AptosWriteModuleDataJSON; +} + +export interface AptosWriteOrUpdateModuleChangeInput { + readonly type: string; + readonly address: AptosAddressInput | AptosAddress; + readonly stateKeyHash: string; + readonly data: AptosWriteModuleDataInput | AptosWriteModuleData; +} + +export class AptosWriteOrUpdateModuleChange { + public static create(input: AptosWriteOrUpdateModuleChangeInput | AptosWriteOrUpdateModuleChange): AptosWriteOrUpdateModuleChange { + if (input instanceof AptosWriteOrUpdateModuleChange) { + return input; + } + return new AptosWriteOrUpdateModuleChange(input); + } + + public static fromJSON(json: AptosWriteOrUpdateModuleChangeJSON): AptosWriteOrUpdateModuleChange { + const input: AptosWriteOrUpdateModuleChangeInput = { + type: json.type, + address: AptosAddress.fromJSON(json.address), + stateKeyHash: json.state_key_hash, + data: AptosWriteModuleData.fromJSON(json.data), + }; + return AptosWriteOrUpdateModuleChange.create(input); + } + + public static isInput(input: any): input is AptosWriteOrUpdateModuleChangeInput { + return input.type === 'write_module'; + } + + public static isJSON(json: any): json is AptosWriteOrUpdateModuleChangeJSON { + return json.type === 'write_module'; + } + + public readonly type: string; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly address: AptosAddress; + /** + * @description State key hash + */ + public readonly stateKeyHash: string; + public readonly data: AptosWriteModuleData; + + private constructor(input: AptosWriteOrUpdateModuleChangeInput) { + this.type = input.type; + this.address = AptosAddress.create(input.address); + this.stateKeyHash = input.stateKeyHash; + this.data = AptosWriteModuleData.create(input.data); + } + + public toJSON(): AptosWriteOrUpdateModuleChangeJSON { + return { + type: this.type, + address: this.address.toJSON(), + state_key_hash: this.stateKeyHash, + data: this.data.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteResourceChange.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteResourceChange.ts new file mode 100644 index 0000000000..9c6cd46da3 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteResourceChange.ts @@ -0,0 +1,78 @@ +import { AptosAddress, AptosAddressInput, AptosAddressJSON } from '../../dataTypes'; +import { AptosWriteResourceData, AptosWriteResourceDataInput, AptosWriteResourceDataJSON } from '../types/AptosWriteResourceData'; + +// $ref: #/components/schemas/WriteResourceChange +// type: WriteResourceChange +// properties: +// - type ($ref: #/components/schemas/WriteResourceChange/properties/type) +// - address ($ref: #/components/schemas/WriteResourceChange/properties/address) +// - state_key_hash ($ref: #/components/schemas/WriteResourceChange/properties/state_key_hash) +// - data ($ref: #/components/schemas/WriteResourceData) + +export interface AptosWriteResourceChangeJSON { + readonly type: string; + readonly address: AptosAddressJSON; + readonly state_key_hash: string; + readonly data: AptosWriteResourceDataJSON; +} + +export interface AptosWriteResourceChangeInput { + readonly type: string; + readonly address: AptosAddressInput | AptosAddress; + readonly stateKeyHash: string; + readonly data: AptosWriteResourceDataInput | AptosWriteResourceData; +} + +export class AptosWriteResourceChange { + public static create(input: AptosWriteResourceChangeInput | AptosWriteResourceChange): AptosWriteResourceChange { + if (input instanceof AptosWriteResourceChange) { + return input; + } + return new AptosWriteResourceChange(input); + } + + public static fromJSON(json: AptosWriteResourceChangeJSON): AptosWriteResourceChange { + const input: AptosWriteResourceChangeInput = { + type: json.type, + address: AptosAddress.fromJSON(json.address), + stateKeyHash: json.state_key_hash, + data: AptosWriteResourceData.fromJSON(json.data), + }; + return AptosWriteResourceChange.create(input); + } + + public static isInput(input: any): input is AptosWriteResourceChangeInput { + return input.type === 'write_resource'; + } + + public static isJSON(json: any): json is AptosWriteResourceChangeJSON { + return json.type === 'write_resource'; + } + + public readonly type: string; + /** + * @description A hex encoded 32 byte Aptos account address. + */ + public readonly address: AptosAddress; + /** + * @description State key hash + */ + public readonly stateKeyHash: string; + public readonly data: AptosWriteResourceData; + + private constructor(input: AptosWriteResourceChangeInput) { + this.type = input.type; + this.address = AptosAddress.create(input.address); + this.stateKeyHash = input.stateKeyHash; + this.data = AptosWriteResourceData.create(input.data); + } + + public toJSON(): AptosWriteResourceChangeJSON { + return { + type: this.type, + address: this.address.toJSON(), + state_key_hash: this.stateKeyHash, + data: this.data.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteResourceData.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteResourceData.ts new file mode 100644 index 0000000000..a779c8d2be --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteResourceData.ts @@ -0,0 +1,55 @@ +import { AptosWriteResourceDataData, AptosWriteResourceDataDataValue, AptosWriteResourceDataDataInput, AptosWriteResourceDataDataJSON } from '../types/AptosWriteResourceDataData'; + +// $ref: #/components/schemas/WriteResourceData +// type: WriteResourceData +// properties: +// - type ($ref: #/components/schemas/WriteResourceData/properties/type) +// - data ($ref: #/components/schemas/WriteResourceData/properties/data) + +export interface AptosWriteResourceDataJSON { + readonly type: string; + readonly data: AptosWriteResourceDataDataJSON; +} + +export interface AptosWriteResourceDataInput { + readonly type: string; + readonly data: AptosWriteResourceDataDataInput | AptosWriteResourceDataDataValue; +} + +export class AptosWriteResourceData { + public static create(input: AptosWriteResourceDataInput | AptosWriteResourceData): AptosWriteResourceData { + if (input instanceof AptosWriteResourceData) { + return input; + } + return new AptosWriteResourceData(input); + } + + public static fromJSON(json: AptosWriteResourceDataJSON): AptosWriteResourceData { + const input: AptosWriteResourceDataInput = { + type: json.type, + data: AptosWriteResourceDataData.fromJSON(json.data), + }; + return AptosWriteResourceData.create(input); + } + + /** + * @description String representation of a MoveStructTag (on-chain Move struct type). + */ + public readonly type: string; + /** + * @description This is a JSON representation of some data within an account resource. More specifically, it is a map of strings to arbitrary JSON values / objects, where the keys are top level fields within the given resource. + */ + public readonly data: AptosWriteResourceDataDataValue; + + private constructor(input: AptosWriteResourceDataInput) { + this.type = input.type; + this.data = AptosWriteResourceDataData.create(input.data); + } + + public toJSON(): AptosWriteResourceDataJSON { + return { + type: this.type, + data: this.data, + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteResourceDataData.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteResourceDataData.ts new file mode 100644 index 0000000000..4cee564d08 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteResourceDataData.ts @@ -0,0 +1,16 @@ +// $ref: #/components/schemas/WriteResourceData/properties/data +// typeName: WriteResourceData_data + +export type AptosWriteResourceDataDataJSON = object; +export type AptosWriteResourceDataDataInput = object; +export type AptosWriteResourceDataDataValue = object; + +export abstract class AptosWriteResourceDataData { + public static create(input: AptosWriteResourceDataDataInput | AptosWriteResourceDataDataValue): AptosWriteResourceDataDataValue { + return input; + } + + public static fromJSON(json: AptosWriteResourceDataDataJSON): AptosWriteResourceDataDataValue { + return json; + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteSetPayload.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteSetPayload.ts new file mode 100644 index 0000000000..ffaccf74fa --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteSetPayload.ts @@ -0,0 +1,52 @@ +import { AptosWriteSetPayloadWriteSet, AptosWriteSetPayloadWriteSetValue, AptosWriteSetPayloadWriteSetInput, AptosWriteSetPayloadWriteSetJSON } from '../types/AptosWriteSetPayloadWriteSet'; + +// $ref: #/components/schemas/WriteSetPayload +// type: WriteSetPayload +// properties: +// - type ($ref: #/components/schemas/WriteSetPayload/properties/type) +// - write_set ($ref: #/components/schemas/WriteSetPayload/properties/write_set) + +export interface AptosWriteSetPayloadJSON { + readonly type: string; + readonly write_set: AptosWriteSetPayloadWriteSetJSON; +} + +export interface AptosWriteSetPayloadInput { + readonly type: string; + readonly writeSet: AptosWriteSetPayloadWriteSetInput | AptosWriteSetPayloadWriteSetValue; +} + +export class AptosWriteSetPayload { + public static create(input: AptosWriteSetPayloadInput | AptosWriteSetPayload): AptosWriteSetPayload { + if (input instanceof AptosWriteSetPayload) { + return input; + } + return new AptosWriteSetPayload(input); + } + + public static fromJSON(json: AptosWriteSetPayloadJSON): AptosWriteSetPayload { + const input: AptosWriteSetPayloadInput = { + type: json.type, + writeSet: AptosWriteSetPayloadWriteSet.fromJSON(json.write_set), + }; + return AptosWriteSetPayload.create(input); + } + + public readonly type: string; + /** + * @description The associated writeset with a payload + */ + public readonly writeSet: AptosWriteSetPayloadWriteSetValue; + + private constructor(input: AptosWriteSetPayloadInput) { + this.type = input.type; + this.writeSet = AptosWriteSetPayloadWriteSet.create(input.writeSet); + } + + public toJSON(): AptosWriteSetPayloadJSON { + return { + type: this.type, + write_set: this.writeSet.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteSetPayloadWriteSet.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteSetPayloadWriteSet.ts new file mode 100644 index 0000000000..d47c50dcc5 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteSetPayloadWriteSet.ts @@ -0,0 +1,34 @@ +import { AptosScriptWriteSet, AptosScriptWriteSetJSON, AptosScriptWriteSetInput } from '../types/AptosScriptWriteSet'; +import { AptosDirectWriteSet, AptosDirectWriteSetJSON, AptosDirectWriteSetInput } from '../types/AptosDirectWriteSet'; + +// $ref: #/components/schemas/WriteSetPayload/properties/write_set +// typeName: WriteSetPayload_write_set +// unionType: oneOf + +export type AptosWriteSetPayloadWriteSetJSON = AptosScriptWriteSetJSON | AptosDirectWriteSetJSON; +export type AptosWriteSetPayloadWriteSetInput = AptosScriptWriteSetInput | AptosDirectWriteSetInput; +export type AptosWriteSetPayloadWriteSetValue = AptosScriptWriteSet | AptosDirectWriteSet; + +export abstract class AptosWriteSetPayloadWriteSet { + public static create(input: AptosWriteSetPayloadWriteSetInput): AptosWriteSetPayloadWriteSetValue { + if (AptosScriptWriteSet.isInput(input)) { + return AptosScriptWriteSet.create(input); + } + if (AptosDirectWriteSet.isInput(input)) { + return AptosDirectWriteSet.create(input); + } + throw new Error('Cannot resolve union for input'); + } + + public static fromJSON(json: AptosWriteSetPayloadWriteSetJSON): AptosWriteSetPayloadWriteSetValue { + if (AptosScriptWriteSet.isJSON(json)) { + return AptosScriptWriteSet.fromJSON(json); + } + if (AptosDirectWriteSet.isJSON(json)) { + return AptosDirectWriteSet.fromJSON(json); + } + const keys = Object.keys(json).join(', '); + const type = (json as any).type; + throw new Error(`Cannot resolve union for AptosWriteSetPayloadWriteSet (keys: ${keys}, type: ${type})`); + } +} diff --git a/packages/common/aptosUtils/src/generated/types/AptosWriteTableChangeSetChange.ts b/packages/common/aptosUtils/src/generated/types/AptosWriteTableChangeSetChange.ts new file mode 100644 index 0000000000..4fcb3f36b5 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/AptosWriteTableChangeSetChange.ts @@ -0,0 +1,97 @@ +import { AptosDecodedTableData, AptosDecodedTableDataInput, AptosDecodedTableDataJSON } from '../types/AptosDecodedTableData'; + +// $ref: #/components/schemas/WriteTableChangeSetChange +// type: WriteTableChangeSetChange +// properties: +// - type ($ref: #/components/schemas/WriteTableChangeSetChange/properties/type) +// - state_key_hash ($ref: #/components/schemas/WriteTableChangeSetChange/properties/state_key_hash) +// - handle ($ref: #/components/schemas/WriteTableChangeSetChange/properties/handle) +// - key ($ref: #/components/schemas/WriteTableChangeSetChange/properties/key) +// - value ($ref: #/components/schemas/WriteTableChangeSetChange/properties/value) +// - data ($ref: #/components/schemas/DecodedTableData) + +export interface AptosWriteTableChangeSetChangeJSON { + readonly type: string; + readonly state_key_hash: string; + readonly handle: string; + readonly key: string; + readonly value: string; + readonly data: AptosDecodedTableDataJSON; +} + +export interface AptosWriteTableChangeSetChangeInput { + readonly type: string; + readonly stateKeyHash: string; + readonly handle: string; + readonly key: string; + readonly value: string; + readonly data: AptosDecodedTableDataInput | AptosDecodedTableData; +} + +export class AptosWriteTableChangeSetChange { + public static create(input: AptosWriteTableChangeSetChangeInput | AptosWriteTableChangeSetChange): AptosWriteTableChangeSetChange { + if (input instanceof AptosWriteTableChangeSetChange) { + return input; + } + return new AptosWriteTableChangeSetChange(input); + } + + public static fromJSON(json: AptosWriteTableChangeSetChangeJSON): AptosWriteTableChangeSetChange { + const input: AptosWriteTableChangeSetChangeInput = { + type: json.type, + stateKeyHash: json.state_key_hash, + handle: json.handle, + key: json.key, + value: json.value, + data: AptosDecodedTableData.fromJSON(json.data), + }; + return AptosWriteTableChangeSetChange.create(input); + } + + public static isInput(input: any): input is AptosWriteTableChangeSetChangeInput { + return input.type === 'write_table_item'; + } + + public static isJSON(json: any): json is AptosWriteTableChangeSetChangeJSON { + return json.type === 'write_table_item'; + } + + public readonly type: string; + /** + * @description State key hash + */ + public readonly stateKeyHash: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly handle: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly key: string; + /** + * @description All bytes (Vec) data is represented as hex-encoded string prefixed with 0x and fulfilled with two hex digits per byte. + */ + public readonly value: string; + public readonly data: AptosDecodedTableData; + + private constructor(input: AptosWriteTableChangeSetChangeInput) { + this.type = input.type; + this.stateKeyHash = input.stateKeyHash; + this.handle = input.handle; + this.key = input.key; + this.value = input.value; + this.data = AptosDecodedTableData.create(input.data); + } + + public toJSON(): AptosWriteTableChangeSetChangeJSON { + return { + type: this.type, + state_key_hash: this.stateKeyHash, + handle: this.handle, + key: this.key, + value: this.value, + data: this.data.toJSON(), + } + } +} diff --git a/packages/common/aptosUtils/src/generated/types/index.ts b/packages/common/aptosUtils/src/generated/types/index.ts new file mode 100644 index 0000000000..a8d1910455 --- /dev/null +++ b/packages/common/aptosUtils/src/generated/types/index.ts @@ -0,0 +1,103 @@ +export * from './AptosNFTTokenResponseDefaultProperties'; +export * from './AptosGetAccountResourceResponseData'; +export * from './AptosGetEventsByCreationNumberResponseData'; +export * from './AptosGetEventsByEventHandleResponseData'; +export * from './AptosNFTOwnerResponseTokenProperties'; +export * from './AptosTransactionEventData'; +export * from './AptosScriptPayloadRequestCode'; +export * from './AptosDeleteModuleChangeModule'; +export * from './AptosDeleteResourceChangeResource'; +export * from './AptosDeleteTableItemChangeHandle'; +export * from './AptosDeleteTableItemChangeKey'; +export * from './AptosWriteResourceDataData'; +export * from './AptosNFTTokenResponse'; +export * from './AptosNFTTokensByCollectionResponse'; +export * from './AptosNFTTokensByCreatorsResponse'; +export * from './AptosNFTCollectionsByNameRangeResponse'; +export * from './AptosNFTCollectionItemResponse'; +export * from './AptosNFTCollectionsByCreatorResponse'; +export * from './AptosNFTOwnersByTokensResponse'; +export * from './AptosNFTOwnersByCollectionResponse'; +export * from './AptosNFTOwnersOfCollectionResponse'; +export * from './AptosNFTTransfersByTokensResponse'; +export * from './AptosGetNFTTransfersByCollectionResponse'; +export * from './AptosGetNFTTransfersByCreatorsResponse'; +export * from './AptosNFTTransfersByWalletsResponse'; +export * from './AptosCoinInfoDto'; +export * from './AptosGetLatestCoinsResponse'; +export * from './AptosGetCoinsByNameRangeResponse'; +export * from './AptosGetCoinsBySymbolRangeResponse'; +export * from './AptosGetCoinsByCreatorsResponse'; +export * from './AptosGetCoinTransfersByOwnerAddressesResponse'; +export * from './AptosGetCoinTransfersByBlockHeightsResponse'; +export * from './AptosGetCoinTransfersByCoinTypeResponse'; +export * from './AptosGetTopHoldersByCoinResponse'; +export * from './AptosGetCoinBalancesByWalletsResponse'; +export * from './AptosGetHistoricalCoinBalancesByWalletsResponse'; +export * from './AptosNFTsByOwnersResponse'; +export * from './AptosGetAccountResponse'; +export * from './AptosGetAccountResourceResponse'; +export * from './AptosGetAccountModuleResponse'; +export * from './AptosGetEventsByCreationNumberResponse'; +export * from './AptosGetEventsByEventHandleResponse'; +export * from './AptosPendingTransaction'; +export * from './AptosSubmitTransactionRequest'; +export * from './AptosSubmitBatchTransactionResult'; +export * from './AptosEncodeSubmissionRequest'; +export * from './AptosEstimateGasPriceResult'; +export * from './AptosBlock'; +export * from './AptosNFTOwnerResponse'; +export * from './AptosNFTTransferResponse'; +export * from './AptosCoinTransferDto'; +export * from './AptosCurrentCoinBalanceDto'; +export * from './AptosHistoricalCoinBalanceDto'; +export * from './AptosMoveModuleAbi'; +export * from './AptosTransactionEventGuid'; +export * from './AptosUserTransaction'; +export * from './AptosGenesisTransaction'; +export * from './AptosBlockMetadataTransaction'; +export * from './AptosStateCheckpointTransaction'; +export * from './AptosModuleExposedFunction'; +export * from './AptosModuleStruct'; +export * from './AptosTransactionEvent'; +export * from './AptosWriteSetPayload'; +export * from './AptosEntryFunctionPayloadRequest'; +export * from './AptosScriptPayloadRequest'; +export * from './AptosModuleBundlePayloadRequest'; +export * from './AptosEd25519SignatureRequest'; +export * from './AptosMultiEd25519SignatureRequest'; +export * from './AptosMultiAgentSignatureRequest'; +export * from './AptosGenericTypeParam'; +export * from './AptosModuleStructField'; +export * from './AptosDeleteModuleChange'; +export * from './AptosDeleteResourceChange'; +export * from './AptosDeleteTableItemChange'; +export * from './AptosWriteOrUpdateModuleChange'; +export * from './AptosWriteResourceChange'; +export * from './AptosWriteTableChangeSetChange'; +export * from './AptosDeletedTableData'; +export * from './AptosWriteModuleData'; +export * from './AptosWriteResourceData'; +export * from './AptosDecodedTableData'; +export * from './AptosScriptWriteSet'; +export * from './AptosDirectWriteSet'; +export * from './AptosGetTransactionsItem'; +export * from './AptosGetTransactionByHash'; +export * from './AptosGetTransactionByVersion'; +export * from './AptosGetAccountTransactionsItem'; +export * from './AptosSimulateTransaction'; +export * from './AptosPendingTransactionPayload'; +export * from './AptosPendingTransactionSignature'; +export * from './AptosSubmitTransactionRequestPayload'; +export * from './AptosSubmitTransactionRequestSignature'; +export * from './AptosEncodeSubmissionRequestPayload'; +export * from './AptosBlockTransactionsItem'; +export * from './AptosUserTransactionChangesItem'; +export * from './AptosUserTransactionPayload'; +export * from './AptosUserTransactionSignature'; +export * from './AptosGenesisTransactionChangesItem'; +export * from './AptosBlockMetadataTransactionChangesItem'; +export * from './AptosStateCheckpointTransactionChangesItem'; +export * from './AptosWriteSetPayloadWriteSet'; +export * from './AptosMultiAgentSignatureRequestSender'; +export * from './AptosMultiAgentSignatureRequestSecondarySigners'; diff --git a/packages/common/aptosUtils/src/index.ts b/packages/common/aptosUtils/src/index.ts index 1041ed96ce..5efefe62f4 100644 --- a/packages/common/aptosUtils/src/index.ts +++ b/packages/common/aptosUtils/src/index.ts @@ -2,3 +2,4 @@ export * from './config'; export * from './dataTypes'; export * from './AptosNetworkResolver'; export * from './CommonAptosUtils'; +export * from './generated'; diff --git a/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.test.ts b/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.test.ts index a362c90c4c..3a57f3eec7 100644 --- a/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.test.ts +++ b/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.test.ts @@ -30,7 +30,7 @@ describe('aptosRequestChallengeOperation', () => { const serializedRequest = requestChallengeAptosOperation.serializeRequest(request, core); - expect(serializedRequest.address).toBe(address); + expect(serializedRequest.address).toBe('0x000000000000000000000000fB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'); expect(serializedRequest.chainId).toBe(chain); expect(serializedRequest.domain).toBe(request.domain); expect(serializedRequest.statement).toBe(request.statement); @@ -42,7 +42,9 @@ describe('aptosRequestChallengeOperation', () => { const deserializedRequest = requestChallengeAptosOperation.deserializeRequest(serializedRequest, core); - expect((deserializedRequest.address as AptosAddress).toString()).toBe(address); + expect((deserializedRequest.address as AptosAddress).toString()).toBe( + '0x000000000000000000000000fB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', + ); expect((deserializedRequest.chainId as AptosNetwork).toString()).toBe(chain); expect(deserializedRequest.domain).toBe(request.domain); expect(deserializedRequest.statement).toBe(request.statement); diff --git a/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.ts b/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.ts index 988a164ba3..51fb6e3142 100644 --- a/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.ts +++ b/packages/common/authUtils/src/operations/aptos/requestChallengeAptosOperation.ts @@ -1,6 +1,6 @@ -import { AptosNetwork, AptosNetworkish, AptosNetworkResolver } from '@moralisweb3/common-aptos-utils'; +import { AptosNetwork, AptosNetworkInput, AptosNetworkResolver } from '@moralisweb3/common-aptos-utils'; import { Core, Camelize, Operation, DateInput, ResponseAdapter } from '@moralisweb3/common-core'; -import { AptosAddress, AptosAddressish } from '@moralisweb3/common-aptos-utils'; +import { AptosAddress, AptosAddressInput } from '@moralisweb3/common-aptos-utils'; import { operations } from '../openapi'; type OperationId = 'requestChallengeAptos'; @@ -14,8 +14,8 @@ type SuccessResponse = operations[OperationId]['responses']['201']['content']['a export interface RequestChallengeAptosRequest extends Camelize> { - address: AptosAddressish; - chainId: AptosNetworkish; + address: AptosAddressInput; + chainId: AptosNetworkInput; expirationTime?: DateInput; notBefore?: DateInput; } diff --git a/packages/common/streamsUtils/src/dataTypes/AptosStream/types.ts b/packages/common/streamsUtils/src/dataTypes/AptosStream/types.ts index 119f1299a4..2aea8d2dc5 100644 --- a/packages/common/streamsUtils/src/dataTypes/AptosStream/types.ts +++ b/packages/common/streamsUtils/src/dataTypes/AptosStream/types.ts @@ -1,4 +1,4 @@ -import { AptosNetwork, AptosNetworkish } from '@moralisweb3/common-aptos-utils'; +import { AptosNetwork, AptosNetworkInput } from '@moralisweb3/common-aptos-utils'; export type StreamStatus = 'active' | 'paused' | 'error' | 'terminated'; @@ -11,7 +11,7 @@ export interface AptosStreamInput { includeEvents: boolean; includePayload: boolean; isErrorSince: string | null; - network: AptosNetworkish[]; + network: AptosNetworkInput[]; status: StreamStatus; statusMessage: string; events: string[]; diff --git a/packages/common/streamsUtils/src/operations/aptosStreams/addAddressAptosOperation.ts b/packages/common/streamsUtils/src/operations/aptosStreams/addAddressAptosOperation.ts index c179326ba7..729a4b13b5 100644 --- a/packages/common/streamsUtils/src/operations/aptosStreams/addAddressAptosOperation.ts +++ b/packages/common/streamsUtils/src/operations/aptosStreams/addAddressAptosOperation.ts @@ -1,5 +1,5 @@ import { Camelize, Operation, ResponseAdapter, toCamelCase } from '@moralisweb3/common-core'; -import { AptosAddress, AptosAddressish } from '@moralisweb3/common-aptos-utils'; +import { AptosAddress, AptosAddressInput } from '@moralisweb3/common-aptos-utils'; import { operations } from '../openapi'; type OperationId = 'aptosStreamsAddAddresses'; @@ -13,7 +13,7 @@ type SuccessResponse = operations[OperationId]['responses']['200']['content']['a // Exports export interface AddAddressAptosRequest extends Camelize> { - address: AptosAddressish | AptosAddressish[]; + address: AptosAddressInput | AptosAddressInput[]; } export type AddAddressAptosJSONRequest = ReturnType; diff --git a/packages/common/streamsUtils/src/operations/aptosStreams/createStreamAptosOperation.ts b/packages/common/streamsUtils/src/operations/aptosStreams/createStreamAptosOperation.ts index bcda45a49d..a1c68dbcda 100644 --- a/packages/common/streamsUtils/src/operations/aptosStreams/createStreamAptosOperation.ts +++ b/packages/common/streamsUtils/src/operations/aptosStreams/createStreamAptosOperation.ts @@ -1,5 +1,5 @@ import { Camelize, Operation, ResponseAdapter } from '@moralisweb3/common-core'; -import { AptosNetwork, AptosNetworkish } from '@moralisweb3/common-aptos-utils'; +import { AptosNetwork, AptosNetworkInput } from '@moralisweb3/common-aptos-utils'; import { AptosStream } from '../../dataTypes'; import { operations } from '../openapi'; @@ -13,7 +13,7 @@ type SuccessResponse = operations[OperationId]['responses']['200']['content']['a // Exports export interface CreateStreamAptosRequest extends Camelize> { - network: AptosNetworkish[]; + network: AptosNetworkInput[]; } export type CreateStreamAptosJSONRequest = ReturnType; diff --git a/packages/common/streamsUtils/src/operations/aptosStreams/deleteAddressAptosOperation.ts b/packages/common/streamsUtils/src/operations/aptosStreams/deleteAddressAptosOperation.ts index cbd9702bba..d05c14b5a0 100644 --- a/packages/common/streamsUtils/src/operations/aptosStreams/deleteAddressAptosOperation.ts +++ b/packages/common/streamsUtils/src/operations/aptosStreams/deleteAddressAptosOperation.ts @@ -1,5 +1,5 @@ import { Camelize, Operation, ResponseAdapter } from '@moralisweb3/common-core'; -import { AptosAddress, AptosAddressish } from '@moralisweb3/common-aptos-utils'; +import { AptosAddress, AptosAddressInput } from '@moralisweb3/common-aptos-utils'; import { operations } from '../openapi'; type OperationId = 'aptosStreamsDeleteAddresses'; @@ -13,7 +13,7 @@ type SuccessResponse = operations[OperationId]['responses']['200']['content']['a // Exports export interface DeleteAddressAptosRequest extends Camelize> { - address: AptosAddressish | AptosAddressish[]; + address: AptosAddressInput | AptosAddressInput[]; } export type DeleteAddressAptosJSONRequest = ReturnType; diff --git a/packages/common/streamsUtils/src/operations/aptosStreams/updateStreamAptosOperation.ts b/packages/common/streamsUtils/src/operations/aptosStreams/updateStreamAptosOperation.ts index 169e96502d..e1973f0dc7 100644 --- a/packages/common/streamsUtils/src/operations/aptosStreams/updateStreamAptosOperation.ts +++ b/packages/common/streamsUtils/src/operations/aptosStreams/updateStreamAptosOperation.ts @@ -1,5 +1,5 @@ import { Camelize, Operation, ResponseAdapter } from '@moralisweb3/common-core'; -import { AptosNetwork, AptosNetworkish } from '@moralisweb3/common-aptos-utils'; +import { AptosNetwork, AptosNetworkInput } from '@moralisweb3/common-aptos-utils'; import { AptosStream } from '../../dataTypes'; import { operations } from '../openapi'; @@ -14,7 +14,7 @@ type SuccessResponse = operations[OperationId]['responses']['200']['content']['a // Exports export interface UpdateStreamAptosRequest extends Camelize> { - network: AptosNetworkish[]; + network: AptosNetworkInput[]; } export type UpdateStreamAptosJSONRequest = ReturnType; diff --git a/packages/moralis/package.json b/packages/moralis/package.json index c1667efce9..cce6eaca5f 100644 --- a/packages/moralis/package.json +++ b/packages/moralis/package.json @@ -158,6 +158,7 @@ }, "dependencies": { "@moralisweb3/api-utils": "^2.14.3", + "@moralisweb3/aptos-api": "^2.14.3", "@moralisweb3/auth": "^2.14.3", "@moralisweb3/common-auth-utils": "^2.14.3", "@moralisweb3/common-core": "^2.14.3", diff --git a/packages/moralis/src/index.ts b/packages/moralis/src/index.ts index bf78fa51fe..16f4507a91 100644 --- a/packages/moralis/src/index.ts +++ b/packages/moralis/src/index.ts @@ -3,6 +3,7 @@ import { ApiUtils } from '@moralisweb3/api-utils'; import { Auth } from '@moralisweb3/auth'; import { CommonEvmUtils } from '@moralisweb3/common-evm-utils'; import { EvmApi } from '@moralisweb3/evm-api'; +import { AptosApi } from '@moralisweb3/aptos-api'; import { CommonSolUtils } from '@moralisweb3/common-sol-utils'; import { SolApi } from '@moralisweb3/sol-api'; import { Core, CoreProvider } from '@moralisweb3/common-core'; @@ -23,6 +24,7 @@ const auth = Auth.create(core); const streams = Streams.create(core); const evmApi = EvmApi.create(core); const solApi = SolApi.create(core); +const aptosApi = AptosApi.create(core); // Register all Moralis modules to Core core.registerModules([commonEvmUtils, commonSolUtils, auth, apiUtils, evmApi, solApi, streams]); @@ -36,6 +38,7 @@ const Moralis = { Streams: streams, EvmApi: evmApi, SolApi: solApi, + AptosApi: aptosApi, EvmUtils: commonEvmUtils, SolUtils: commonSolUtils, diff --git a/yarn.lock b/yarn.lock index 65f2879fce..3b55d8ccc2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7430,6 +7430,19 @@ __metadata: languageName: node linkType: hard +"@moralisweb3/api-generator@workspace:packages/apiGenerator": + version: 0.0.0-use.local + resolution: "@moralisweb3/api-generator@workspace:packages/apiGenerator" + dependencies: + "@types/jest": ^29.2.6 + axios: ^1.2.2 + jest: 29.3.1 + openapi-types: ^12.1.0 + ts-node: ^10.9.1 + typescript: ^4.9.4 + languageName: unknown + linkType: soft + "@moralisweb3/api-utils@^2.14.3, @moralisweb3/api-utils@workspace:packages/apiUtils": version: 0.0.0-use.local resolution: "@moralisweb3/api-utils@workspace:packages/apiUtils" @@ -7448,6 +7461,26 @@ __metadata: languageName: unknown linkType: soft +"@moralisweb3/aptos-api@^2.14.3, @moralisweb3/aptos-api@workspace:packages/aptosApi": + version: 0.0.0-use.local + resolution: "@moralisweb3/aptos-api@workspace:packages/aptosApi" + dependencies: + "@moralisweb3/api-utils": ^2.14.3 + "@moralisweb3/common-aptos-utils": ^2.14.3 + "@moralisweb3/common-core": ^2.14.3 + "@rollup/plugin-commonjs": ^24.0.1 + "@rollup/plugin-node-resolve": ^15.0.1 + jest: 29.3.1 + openapi-typescript: ^5.2.0 + rollup: ^3.10.1 + rollup-plugin-cleaner: ^1.0.0 + rollup-plugin-dts: ^5.2.0 + rollup-plugin-node-polyfills: ^0.2.1 + rollup-plugin-typescript2: ^0.34.1 + typescript: ^4.9.3 + languageName: unknown + linkType: soft + "@moralisweb3/auth@^2.14.3, @moralisweb3/auth@workspace:packages/auth": version: 0.0.0-use.local resolution: "@moralisweb3/auth@workspace:packages/auth" @@ -10165,7 +10198,7 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:*, @types/jest@npm:^29.2.5": +"@types/jest@npm:*, @types/jest@npm:^29.2.5, @types/jest@npm:^29.2.6": version: 29.4.0 resolution: "@types/jest@npm:29.4.0" dependencies: @@ -12696,6 +12729,17 @@ __metadata: languageName: node linkType: hard +"axios@npm:^1.2.2": + version: 1.3.4 + resolution: "axios@npm:1.3.4" + dependencies: + follow-redirects: ^1.15.0 + form-data: ^4.0.0 + proxy-from-env: ^1.1.0 + checksum: 7440edefcf8498bc3cdf39de00443e8101f249972c83b739c6e880d9d669fea9486372dbe8739e88b3bf8bb1ad15f6106693f206f078f4516fe8fd47b1c3093c + languageName: node + linkType: hard + "axobject-query@npm:^3.1.1": version: 3.1.1 resolution: "axobject-query@npm:3.1.1" @@ -25612,6 +25656,7 @@ __metadata: resolution: "moralis@workspace:packages/moralis" dependencies: "@moralisweb3/api-utils": ^2.14.3 + "@moralisweb3/aptos-api": ^2.14.3 "@moralisweb3/auth": ^2.14.3 "@moralisweb3/common-auth-utils": ^2.14.3 "@moralisweb3/common-core": ^2.14.3 @@ -26786,7 +26831,7 @@ __metadata: languageName: node linkType: hard -"openapi-types@npm:^12.0.0": +"openapi-types@npm:^12.0.0, openapi-types@npm:^12.1.0": version: 12.1.0 resolution: "openapi-types@npm:12.1.0" checksum: d8f3e2bae519aa6bcf2012f4a5592b7283fe928c06f3bdc182776ce637c7ed8d5f9f342724f68c95c9572aefe21ed5e89b18a0295a703da61af5f97bd2aea9a7