Skip to content

Commit

Permalink
chore: rollback to working state
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Dec 11, 2024
1 parent 3fbb2d6 commit 16c340e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/abi/src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { AbiParser } from './abi-parser';
export { AbiParser, AbiSpecification } from './abi-parser';
export * from './abi';
export * from './specifications/v1/specification';
42 changes: 18 additions & 24 deletions packages/abi/src/parser/specifications/v1/resolvable-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export class ResolvableType {
) {
this.metadataType = this.findMetadataType(metadataTypeId);
this.swayType = this.metadataType.type;
this.typeParamsArgsMap ??= this.metadataType.typeParameters?.map((typeParameter) => [
typeParameter,
new ResolvableType(this.abi, typeParameter, undefined),
]);

this.typeParamsArgsMap ??= this.mapTypeParametersAndArgs(this.metadataType, undefined);
let components = this.metadataType.components;

/**
Expand All @@ -47,7 +43,10 @@ export class ResolvableType {
if (swayTypeMatchers.vector(this.metadataType.type)) {
components = components?.map((component) => {
if (component.name === 'buf') {
return component.typeArguments?.[0];
return {
...component.typeArguments?.[0],
name: component.name,
};
}
return component;
}) as AbiComponentV1[];
Expand Down Expand Up @@ -112,8 +111,15 @@ export class ResolvableType {

private mapTypeParametersAndArgs(
metadataType: AbiMetadataTypeV1,
args: (ResolvableType | ResolvedType)[]
args: (ResolvableType | ResolvedType)[] | undefined
): Array<[number, ResolvedType | ResolvableType]> | undefined {
if (!args) {
return metadataType.typeParameters?.map((typeParameter) => [
typeParameter,
new ResolvableType(this.abi, typeParameter, undefined),
]);
}

return metadataType.typeParameters?.map((typeParameter, idx) => [typeParameter, args[idx]]);
}

Expand Down Expand Up @@ -223,17 +229,6 @@ export class ResolvableType {
(typeArgument) => this.handleComponent(parent, typeArgument).type
);

/**
* If there are no type arguments because the metadata type isn't generic,
* we can resolve it immediately.
* This would be the case for e.g. non-generic structs and enums.
*/
if (!typeArgs?.length) {
return new ResolvableType(this.abi, metadataType.metadataTypeId, undefined).resolveInternal(
metadataType.metadataTypeId,
undefined
);
}
const resolvable = new ResolvableType(
this.abi,
metadataType.metadataTypeId,
Expand All @@ -247,7 +242,7 @@ export class ResolvableType {
* then this check will resolve to `false` because there are no concrete type arguments
* to resolve the generics with.
*/
if (typeArgs.every((ta) => ta instanceof ResolvedType)) {
if (typeArgs?.every((typeArgument) => typeArgument instanceof ResolvedType)) {
return resolvable.resolveInternal(metadataType.metadataTypeId, undefined);
}

Expand Down Expand Up @@ -322,11 +317,10 @@ export class ResolvableType {
return this.resolveConcreteType(concreteTypeArg);
});

const typeParamsArgsMap = concreteTypeArgs?.length
? (this.mapTypeParametersAndArgs(this.metadataType, concreteTypeArgs) as Array<
[number, ResolvedType]
>)
: undefined;
const typeParamsArgsMap = this.mapTypeParametersAndArgs(
this.metadataType,
concreteTypeArgs
) as Array<[number, ResolvedType]>;

return this.resolveInternal(concreteType.concreteTypeId, typeParamsArgsMap);
}
Expand Down

0 comments on commit 16c340e

Please sign in to comment.