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

fix: ensure that NEAR functions have explicit types #322

Merged
merged 3 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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