Skip to content

Commit

Permalink
fix: ensure that NEAR functions have explicit types (#322)
Browse files Browse the repository at this point in the history
* ensure that NEAR functions have explicit types
  • Loading branch information
itegulov authored Dec 5, 2022
1 parent aee3f04 commit e38d014
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
24 changes: 20 additions & 4 deletions examples/src/nested-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Contract {
}

@call({})
add({ id, text }) {
add({ id, text }: { id: string; text: string }) {
const innerMap = this.outerMap.get(id, {
reconstructor: UnorderedMap.reconstruct,
defaultValue: new UnorderedMap<string>("i_" + id + "_"),
Expand All @@ -21,7 +21,7 @@ export class Contract {
}

@view({})
get({ id, accountId }) {
get({ id, accountId }: { id: string; accountId: string }) {
const innerMap = this.outerMap.get(id, {
reconstructor: UnorderedMap.reconstruct,
});
Expand All @@ -32,7 +32,15 @@ export class Contract {
}

@call({})
add_to_group({ group, id, text }) {
add_to_group({
group,
id,
text,
}: {
group: string;
id: string;
text: string;
}) {
const groupMap = this.groups.get(group, {
reconstructor: UnorderedMap.reconstruct,
defaultValue: new UnorderedMap<UnorderedMap<string>>("g_" + group + "_"),
Expand All @@ -47,7 +55,15 @@ export class Contract {
}

@view({})
get_from_group({ group, id, accountId }) {
get_from_group({
group,
id,
accountId,
}: {
group: string;
id: string;
accountId: string;
}) {
const groupMap = this.groups.get(group, {
reconstructor: UnorderedMap.reconstruct,
});
Expand Down
3 changes: 3 additions & 0 deletions lib/cli/abi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/cli/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ export function runAbiCompilerPlugin(
);
} else if (methodDeclaration.parameters.length === 1) {
const jsonObjectParameter = methodDeclaration.parameters[0];
if (!jsonObjectParameter.type) {
throw Error(
"Expected NEAR function to have explicit types, e.g. `{ id }: {id : string }`"
);
}

if (jsonObjectParameter.type.kind !== ts.SyntaxKind.TypeLiteral) {
throw Error(
"Expected NEAR function to have a single object binding parameter, e.g. `{ id }: { id: string }`"
Expand Down

0 comments on commit e38d014

Please sign in to comment.