Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: mimic JsonAbi interface from abi-coder in abi-typegen #2743

Merged
merged 13 commits into from
Jul 11, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/strange-buses-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-typegen": patch
---

chore: mimic `JsonAbi` interface from `abi-coder` in `abi-typegen`
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/Abi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getTypegenForcProject,
} from '../../test/fixtures/forc-projects/index';
import { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum';
import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType';
import type { JsonAbiType } from '../types/interfaces/JsonAbi';
import * as parseConfigurablesMod from '../utils/parseConfigurables';
import * as parseFunctionsMod from '../utils/parseFunctions';
import * as parseTypesMod from '../utils/parseTypes';
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('Abi.ts', () => {
}

function getRawTypeFor(params: { type: string }) {
const rawAbiType: IRawAbiTypeRoot = {
const rawAbiType: JsonAbiType = {
typeId: 1,
type: params.type,
components: null,
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/abi/Abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { normalizeString } from '@fuel-ts/utils';
import type { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum';
import type { IConfigurable } from '../types/interfaces/IConfigurable';
import type { IFunction } from '../types/interfaces/IFunction';
import type { IRawAbi } from '../types/interfaces/IRawAbi';
import type { IType } from '../types/interfaces/IType';
import type { JsonAbi } from '../types/interfaces/JsonAbi';
import { parseConfigurables } from '../utils/parseConfigurables';
import { parseFunctions } from '../utils/parseFunctions';
import { parseTypes } from '../utils/parseTypes';
Expand All @@ -22,7 +22,7 @@ export class Abi {

public commonTypesInUse: string[] = [];

public rawContents: IRawAbi;
public rawContents: JsonAbi;
public hexlifiedBinContents?: string;
public storageSlotsContents?: string;

Expand All @@ -33,7 +33,7 @@ export class Abi {
constructor(params: {
filepath: string;
programType: ProgramTypeEnum;
rawContents: IRawAbi;
rawContents: JsonAbi;
hexlifiedBinContents?: string;
storageSlotsContents?: string;
outputDir: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType';
import type { IType } from '../../types/interfaces/IType';
import type { JsonAbiType } from '../../types/interfaces/JsonAbi';
import * as findTypeMod from '../../utils/findType';

import { Configurable } from './Configurable';
Expand All @@ -13,7 +13,7 @@ import { Configurable } from './Configurable';
*/
describe('Configurable.ts', () => {
function mockAllDeps() {
const rawAbiType: IRawAbiTypeRoot = {
const rawAbiType: JsonAbiType = {
typeId: 1,
type: 'mockType',
components: null,
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/abi/configurable/Configurable.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { IConfigurable } from '../../types/interfaces/IConfigurable';
import type { IRawAbiConfigurable } from '../../types/interfaces/IRawAbiConfigurable';
import type { IType } from '../../types/interfaces/IType';
import type { JsonAbiConfigurable } from '../../types/interfaces/JsonAbi';
import { findType } from '../../utils/findType';

export class Configurable implements IConfigurable {
public name: string;
public type: IType;
public rawAbiConfigurable: IRawAbiConfigurable;
public rawAbiConfigurable: JsonAbiConfigurable;

constructor(params: { types: IType[]; rawAbiConfigurable: IRawAbiConfigurable }) {
constructor(params: { types: IType[]; rawAbiConfigurable: JsonAbiConfigurable }) {
const { types, rawAbiConfigurable } = params;

this.name = rawAbiConfigurable.name;
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/abi/functions/Function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IFunction, IRawAbiFunction, IFunctionAttributes } from '../../index';
import type { IFunction, JsonAbiFunction, IFunctionAttributes } from '../../index';
import { TargetEnum } from '../../types/enums/TargetEnum';
import type { IType } from '../../types/interfaces/IType';
import { findType } from '../../utils/findType';
Expand All @@ -8,10 +8,10 @@ import { EmptyType } from '../types/EmptyType';
export class Function implements IFunction {
public name: string;
public types: IType[];
public rawAbiFunction: IRawAbiFunction;
public rawAbiFunction: JsonAbiFunction;
public attributes: IFunctionAttributes;

constructor(params: { types: IType[]; rawAbiFunction: IRawAbiFunction }) {
constructor(params: { types: IType[]; rawAbiFunction: JsonAbiFunction }) {
this.rawAbiFunction = params.rawAbiFunction;
this.types = params.types;
this.name = params.rawAbiFunction.name;
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/abi/types/AType.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType';
import type { ITypeAttributes } from '../../types/interfaces/IType';
import type { JsonAbiType } from '../../types/interfaces/JsonAbi';

export class AType {
public rawAbiType: IRawAbiTypeRoot;
public rawAbiType: JsonAbiType;
public attributes: ITypeAttributes;
public requiredFuelsMembersImports: string[];

constructor(params: { rawAbiType: IRawAbiTypeRoot }) {
constructor(params: { rawAbiType: JsonAbiType }) {
this.rawAbiType = params.rawAbiType;
this.attributes = {
inputLabel: 'unknown',
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/abi/types/ArrayType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects';
import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType';
import type { JsonAbiType } from '../../types/interfaces/JsonAbi';
import { findType } from '../../utils/findType';
import { makeType } from '../../utils/makeType';
import * as parseTypeArgumentsMod from '../../utils/parseTypeArguments';
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('ArrayType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.STRUCT_WITH_ARRAY);

const rawTypes = project.abiContents.types;
const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

// validating `struct B`, with simple tuples on property `x`
const b = findType({ types, typeId: 0 }) as ArrayType;
Expand All @@ -50,7 +50,7 @@ describe('ArrayType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.ARRAY_WITH_GENERICS);

const rawTypes = project.abiContents.types;
const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

const a = findType({ types, typeId: 1 }) as ArrayType;

Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/EmptyType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRawAbiTypeRoot } from '../..';
import type { JsonAbiType } from '../..';
import type { IType } from '../../types/interfaces/IType';

import { AType } from './AType';
Expand All @@ -10,7 +10,7 @@ export class EmptyType extends AType implements IType {

static MATCH_REGEX: RegExp = /^\(\)$/m;

constructor(params: { rawAbiType: IRawAbiTypeRoot }) {
constructor(params: { rawAbiType: JsonAbiType }) {
super(params);
this.attributes = {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/EnumType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import { TargetEnum } from '../../types/enums/TargetEnum';
import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType';
import type { JsonAbiType } from '../../types/interfaces/JsonAbi';
import { findType } from '../../utils/findType';
import { makeType } from '../../utils/makeType';

Expand All @@ -23,7 +23,7 @@ describe('EnumType.ts', () => {
abiContents: { types: rawTypes },
} = getTypegenForcProject(project);

const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

return { types };
}
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-typegen/src/abi/types/EnumType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRawAbiTypeComponent } from '../../index';
import type { JsonAbiArgument } from '../../index';
import type { TargetEnum } from '../../types/enums/TargetEnum';
import type { IType } from '../../types/interfaces/IType';
import { extractStructName } from '../../utils/extractStructName';
Expand Down Expand Up @@ -58,7 +58,7 @@ export class EnumType extends AType implements IType {
const { components } = this.rawAbiType;

// `components` array guaranteed to always exist for structs/enums
const enumComponents = components as IRawAbiTypeComponent[];
const enumComponents = components as JsonAbiArgument[];

if (!enumComponents.every(({ type }) => typeHash[type] === EmptyType.swayType)) {
return undefined;
Expand All @@ -73,7 +73,7 @@ export class EnumType extends AType implements IType {
const { components } = this.rawAbiType;

// `components` array guaranteed to always exist for structs/enums
const enumComponents = components as IRawAbiTypeComponent[];
const enumComponents = components as JsonAbiArgument[];

const attributeKey: 'inputLabel' | 'outputLabel' = `${target}Label`;

Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/EvmAddressType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import type { IRawAbiTypeRoot } from '../../index';
import type { JsonAbiType } from '../../index';
import { findType } from '../../utils/findType';
import { makeType } from '../../utils/makeType';
import * as parseTypeArgumentsMod from '../../utils/parseTypeArguments';
Expand All @@ -21,7 +21,7 @@ describe('EvmAddressType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.EVM_ADDRESS);

const rawTypes = project.abiContents.types;
const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

const suitableForEvmAddress = EvmAddressType.isSuitableFor({ type: EvmAddressType.swayType });
const suitableForStruct = EvmAddressType.isSuitableFor({ type: StructType.swayType });
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/OptionType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import type { IRawAbiTypeRoot } from '../../index';
import type { JsonAbiType } from '../../index';
import { findType } from '../../utils/findType';
import { makeType } from '../../utils/makeType';

Expand All @@ -20,7 +20,7 @@ describe('OptionType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.OPTION_SIMPLE);
const rawTypes = project.abiContents.types;

const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

return { types };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/ResultType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import type { IRawAbiTypeRoot } from '../../index';
import type { JsonAbiType } from '../../index';
import { parseTypes } from '../../utils/parseTypes';

import { EnumType } from './EnumType';
Expand All @@ -17,7 +17,7 @@ describe('ResultType.ts', () => {
*/
function getResultType() {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.FULL);
const rawTypes = project.abiContents.types as IRawAbiTypeRoot[];
const rawTypes = project.abiContents.types as JsonAbiType[];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return parseTypes({ rawAbiTypes: [rawTypes.find((t) => t.type === 'enum Result')!] })[0];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/StructType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import type { IRawAbiTypeRoot } from '../../index';
import type { JsonAbiType } from '../../index';
import { TargetEnum } from '../../types/enums/TargetEnum';
import { findType } from '../../utils/findType';
import { makeType } from '../../utils/makeType';
Expand All @@ -24,7 +24,7 @@ describe('StructType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.STRUCT_SIMPLE);

const rawTypes = project.abiContents.types;
const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

const suitableForStruct = StructType.isSuitableFor({ type: StructType.swayType });
const suitableForU16 = StructType.isSuitableFor({ type: U16Type.swayType });
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/StructType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRawAbiTypeComponent } from '../../index';
import type { JsonAbiArgument } from '../../index';
import type { TargetEnum } from '../../types/enums/TargetEnum';
import type { IType } from '../../types/interfaces/IType';
import { extractStructName } from '../../utils/extractStructName';
Expand Down Expand Up @@ -46,7 +46,7 @@ export class StructType extends AType implements IType {
const { components } = this.rawAbiType;

// `components` array guaranteed to always exist for structs/enums
const structComponents = components as IRawAbiTypeComponent[];
const structComponents = components as JsonAbiArgument[];

// loop through all components
const members = structComponents.map((component) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/TupleType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AbiTypegenProjectsEnum,
getTypegenForcProject,
} from '../../../test/fixtures/forc-projects/index';
import type { IRawAbiTypeRoot } from '../../index';
import type { JsonAbiType } from '../../index';
import { findType } from '../../utils/findType';
import { makeType } from '../../utils/makeType';
import * as parseTypeArgumentsMod from '../../utils/parseTypeArguments';
Expand All @@ -20,7 +20,7 @@ describe('TupleType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.TUPLE_SIMPLE);
const rawTypes = project.abiContents.types;

const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType }));
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

const suitableForTuple = TupleType.isSuitableFor({ type: TupleType.swayType });
const suitableForArray = TupleType.isSuitableFor({ type: ArrayType.swayType });
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/U8Type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRawAbiTypeRoot } from '../../index';
import type { JsonAbiType } from '../../index';
import type { IType } from '../../types/interfaces/IType';

import { AType } from './AType';
Expand All @@ -10,7 +10,7 @@ export class U8Type extends AType implements IType {

public static MATCH_REGEX: RegExp = /^u8$/m;

constructor(params: { rawAbiType: IRawAbiTypeRoot }) {
constructor(params: { rawAbiType: JsonAbiType }) {
super(params);
this.attributes = {
inputLabel: `BigNumberish`,
Expand Down
6 changes: 1 addition & 5 deletions packages/abi-typegen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@ export * from './types/enums/ProgramTypeEnum';
export * from './types/interfaces/IConfigurable';
export * from './types/interfaces/IFile';
export * from './types/interfaces/IFunction';
export * from './types/interfaces/IRawAbi';
export * from './types/interfaces/IRawAbiConfigurable';
export * from './types/interfaces/IRawAbiFunction';
export * from './types/interfaces/IRawAbiType';
export * from './types/interfaces/IRawAbiLoggedTypes';
export * from './types/interfaces/JsonAbi';
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/types/interfaces/IConfigurable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IRawAbiConfigurable } from './IRawAbiConfigurable';
import type { IType } from './IType';
import type { JsonAbiConfigurable } from './JsonAbi';

export interface IConfigurable {
name: string;
type: IType;
rawAbiConfigurable: IRawAbiConfigurable;
rawAbiConfigurable: JsonAbiConfigurable;
}
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/types/interfaces/IFunction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IRawAbiFunction } from './IRawAbiFunction';
import type { IType } from './IType';
import type { JsonAbiFunction } from './JsonAbi';

export interface IFunctionAttributes {
inputs: string;
Expand All @@ -10,7 +10,7 @@ export interface IFunctionAttributes {
export interface IFunction {
types: IType[];
name: string;
rawAbiFunction: IRawAbiFunction;
rawAbiFunction: JsonAbiFunction;
attributes: IFunctionAttributes;
getDeclaration(): string;
}
13 changes: 0 additions & 13 deletions packages/abi-typegen/src/types/interfaces/IRawAbi.ts

This file was deleted.

This file was deleted.

Loading
Loading