@aldea/core
Advanced tools
Comparing version 0.3.5 to 0.3.9
# @aldea/core | ||
## 0.3.9 | ||
### Patch Changes | ||
- 3a8cc57: Fixes to make interface return type work. | ||
## 0.3.5 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { findClass, findFunction, } from './abi/query.js'; | ||
import { findClass, findFunction, findInterface, } from './abi/query.js'; | ||
import { AbiSchema, PkgSchema } from './bcs/schemas.js'; | ||
@@ -35,3 +35,3 @@ import { CodeKind, MethodKind, } from './abi/types.js'; | ||
*/ | ||
class BCS { | ||
export class BCS { | ||
static pkg = (() => { | ||
@@ -489,3 +489,2 @@ const bcs = new BCS({ addPkgTypes: true }); | ||
} | ||
export { BCS }; | ||
// Trys to find either a jig, function, or method from the abi matching the | ||
@@ -501,7 +500,18 @@ // specified name. | ||
const [_, jigName, sep, methodName] = match; | ||
const kind = methodName === 'constructor' ? MethodKind.CONSTRUCTOR : (sep === '$' ? MethodKind.INSTANCE : MethodKind.STATIC); | ||
method = findClass(abi, jigName)?.methods.find(m => m.kind === kind && m.name === methodName); | ||
const node = abi.exports.find(a => a.code.name === jigName); | ||
if (node && node.kind === CodeKind.CLASS) { | ||
const klass = node.code; | ||
const kind = methodName === 'constructor' ? MethodKind.CONSTRUCTOR : (sep === '$' ? MethodKind.INSTANCE : MethodKind.STATIC); | ||
method = klass.methods.find(m => m.kind === kind && m.name === methodName); | ||
} | ||
if (node && node.kind === CodeKind.INTERFACE) { | ||
const int = node.code; | ||
method = int.methods.find(m => m.name === methodName); | ||
} | ||
} | ||
else { | ||
jig = findClass(abi, name) || undefined; | ||
if (!jig) { | ||
jig = findInterface(abi, name) || undefined; | ||
} | ||
method = findFunction(abi, name) || undefined; | ||
@@ -545,3 +555,3 @@ } | ||
const parents = []; | ||
let parent = findClass(abi, jig.extends); | ||
let parent = findClass(abi, jig.extends || 'Jig'); | ||
while (parent) { | ||
@@ -548,0 +558,0 @@ parents.unshift(parent); |
{ | ||
"name": "@aldea/core", | ||
"description": "Core Aldea data structuresand cryptographic functions.", | ||
"version": "0.3.5", | ||
"version": "0.3.9", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
import { findClass, findFunction, } from './abi/query.js' | ||
import {findClass, findFunction, findInterface,} from './abi/query.js' | ||
import { AbiSchema, PkgSchema } from './bcs/schemas.js' | ||
@@ -10,3 +10,3 @@ | ||
FieldNode, | ||
FunctionNode, | ||
FunctionNode, InterfaceNode, | ||
MethodKind, | ||
@@ -287,3 +287,3 @@ MethodNode, | ||
// Iterates over parents to include inherited fields too. | ||
private collectJigFieldTypes(jig: ClassNode): TypeNode[] { | ||
private collectJigFieldTypes(jig: ClassNode | InterfaceNode): TypeNode[] { | ||
const fields: FieldNode[] = [] | ||
@@ -580,7 +580,7 @@ | ||
function abiPluck(abi: Abi | undefined, name: string): Partial<{ | ||
jig: ClassNode, | ||
jig: ClassNode | InterfaceNode, | ||
method: FunctionNode | MethodNode, | ||
}> { | ||
if (!abi) return {} | ||
let jig: ClassNode | undefined | ||
let jig: ClassNode | InterfaceNode | undefined | ||
let method: FunctionNode | MethodNode | undefined | ||
@@ -591,8 +591,17 @@ const match = name.match(/^(\w+)(\$|_)(\w+)$/) | ||
const [_, jigName, sep, methodName] = match | ||
const kind = methodName === 'constructor' ? MethodKind.CONSTRUCTOR : ( | ||
sep === '$' ? MethodKind.INSTANCE : MethodKind.STATIC | ||
) | ||
method = findClass(abi, jigName)?.methods.find(m => m.kind === kind && m.name === methodName) | ||
const node = abi.exports.find(a => a.code.name === jigName) | ||
if (node && node.kind === CodeKind.CLASS) { | ||
const klass = node.code as ClassNode | ||
const kind = methodName === 'constructor' ? MethodKind.CONSTRUCTOR : (sep === '$' ? MethodKind.INSTANCE : MethodKind.STATIC) | ||
method = klass.methods.find(m => m.kind === kind && m.name === methodName) | ||
} | ||
if (node && node.kind === CodeKind.INTERFACE) { | ||
const int = node.code as InterfaceNode | ||
method = int.methods.find(m => m.name === methodName) | ||
} | ||
} else { | ||
jig = findClass(abi, name) || undefined | ||
if (!jig) { | ||
jig = findInterface(abi, name) || undefined | ||
} | ||
method = findFunction(abi, name) || undefined | ||
@@ -638,5 +647,5 @@ } | ||
// Collects the parents of the given jig ClassNode. | ||
function collectJigParents(abi: Abi, jig: ClassNode): ClassNode[] { | ||
function collectJigParents(abi: Abi, jig: ClassNode | InterfaceNode): ClassNode[] { | ||
const parents: ClassNode[] = [] | ||
let parent = findClass(abi, jig.extends) | ||
let parent = findClass(abi, jig.extends || 'Jig') | ||
while (parent) { | ||
@@ -643,0 +652,0 @@ parents.unshift(parent) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1382608
16144