Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Dec 30, 2024
1 parent 01d4e04 commit b26f871
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 16 deletions.

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

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

4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { decoratorArgumentsHandler, MethodType } from '.';
export function heartbeat<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext
): MethodType<This, Args, Return> {
return decoratorArgumentsHandler('heartbeat', originalMethod, context);
): void {
decoratorArgumentsHandler('heartbeat', originalMethod, context);
}
7 changes: 6 additions & 1 deletion src/lib/stable/canister_methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ export type MethodType<This, Args extends any[], Return> = (
...args: Args
) => Return;

export type DecoratorFunction<This, Args extends any[], Return> = (
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext
) => MethodType<This, Args, Return>;

export function decoratorArgumentsHandler<This, Args extends any[], Return>(
canisterMethodMode: CanisterMethodMode,
param1?: MethodType<This, Args, Return> | IDL.Type[],
param2?: ClassMethodDecoratorContext | IDL.Type,
param3?: { composite?: boolean; manual?: boolean }
): any {
): MethodType<This, Args, Return> | DecoratorFunction<This, Args, Return> {
// First overload - decorator without params
if (typeof param1 === 'function') {
const originalMethod = param1;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDL } from '@dfinity/candid';

import { decoratorArgumentsHandler, MethodType } from '.';
import { decoratorArgumentsHandler, DecoratorFunction, MethodType } from '.';

export function init<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
Expand All @@ -17,6 +17,6 @@ export function init<This, Args extends any[], Return>(
export function init<This, Args extends any[], Return>(
param1?: MethodType<This, Args, Return> | IDL.Type[],
param2?: ClassMethodDecoratorContext
): any {
): MethodType<This, Args, Return> | DecoratorFunction<This, Args, Return> {
return decoratorArgumentsHandler('init', param1, param2);
}
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/inspect_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { decoratorArgumentsHandler, MethodType } from '.';
export function inspectMessage<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext
): MethodType<This, Args, Return> {
return decoratorArgumentsHandler('inspectMessage', originalMethod, context);
): void {
decoratorArgumentsHandler('inspectMessage', originalMethod, context);
}
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/post_upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDL } from '@dfinity/candid';

import { decoratorArgumentsHandler, MethodType } from '.';
import { decoratorArgumentsHandler, DecoratorFunction, MethodType } from '.';

export function postUpgrade<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
Expand All @@ -17,6 +17,6 @@ export function postUpgrade<This, Args extends any[], Return>(
export function postUpgrade<This, Args extends any[], Return>(
param1?: MethodType<This, Args, Return> | IDL.Type[],
param2?: ClassMethodDecoratorContext
): any {
): MethodType<This, Args, Return> | DecoratorFunction<This, Args, Return> {
return decoratorArgumentsHandler('postUpgrade', param1, param2);
}
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/pre_upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { decoratorArgumentsHandler, MethodType } from '.';
export function preUpgrade<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext
): MethodType<This, Args, Return> {
return decoratorArgumentsHandler('preUpgrade', originalMethod, context);
): void {
decoratorArgumentsHandler('preUpgrade', originalMethod, context);
}
4 changes: 2 additions & 2 deletions src/lib/stable/canister_methods/query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDL } from '@dfinity/candid';

import { decoratorArgumentsHandler, MethodType } from '.';
import { decoratorArgumentsHandler, DecoratorFunction, MethodType } from '.';

export function query<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
Expand All @@ -23,6 +23,6 @@ export function query<This, Args extends any[], Return>(
param1?: MethodType<This, Args, Return> | IDL.Type[],
param2?: ClassMethodDecoratorContext | IDL.Type,
param3?: { manual?: boolean }
): any {
): MethodType<This, Args, Return> | DecoratorFunction<This, Args, Return> {
return decoratorArgumentsHandler('query', param1, param2, param3);
}
5 changes: 2 additions & 3 deletions src/lib/stable/canister_methods/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDL } from '@dfinity/candid';

import { decoratorArgumentsHandler, MethodType } from '.';
import { decoratorArgumentsHandler, DecoratorFunction, MethodType } from '.';

export function update<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
Expand All @@ -18,11 +18,10 @@ export function update<This, Args extends any[], Return>(
context: ClassMethodDecoratorContext
) => MethodType<This, Args, Return>;

// TODO get rid of the any return type
export function update<This, Args extends any[], Return>(
param1?: MethodType<This, Args, Return> | IDL.Type[],
param2?: ClassMethodDecoratorContext | IDL.Type,
param3?: { manual?: boolean }
): any {
): MethodType<This, Args, Return> | DecoratorFunction<This, Args, Return> {
return decoratorArgumentsHandler('update', param1, param2, param3);
}

0 comments on commit b26f871

Please sign in to comment.