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

Default decorators need not be invoked #2400

Merged
merged 14 commits into from
Dec 31, 2024
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
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class {
]);
}

@update([])
@update
async returnPromiseVoid(): Promise<void> {
await call('aaaaa-aa', 'raw_rand', {
returnIdlType: IDL.Vec(IDL.Nat8)
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Candid = {
};

export default class {
@query([])
@query
opt(): void {}

@query([], CandidVariant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class {
return (await call(this.canister2Id, 'trap')) as never;
}

@update([])
@update
sendNotification(): void {
return notify(this.canister2Id, 'receiveNotification', {
paramIdlTypes: [IDL.Text],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class {
});
}

@update([])
@update
sendCyclesNotify(): void {
return notify(this.cyclesPrincipal, 'receiveCycles', {
cycles: 1_000_000n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type NullFunc = Func;
export default class {
stableStorage = new StableBTreeMap<string, StableFunc>(0);

@init([])
@init
init(): void {
this.stableStorage.insert('stableFunc', [
Principal.from('aaaaa-aa'),
Expand Down

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.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class {
}
}

@update([])
@update
clearall(): void {
this.cell = 0n;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class {
this.counter = n;
}

@update([])
@update
inc(): void {
this.counter += 1n;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { query } from 'azle';

export default class {
@query([])
@query
main(): void {
console.info('Hello World!');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export type HttpResponse = {
export default class {
stableStorage = new StableBTreeMap<string, bigint>(0);

@init([])
@init
init(): void {
this.stableStorage.insert('counter', 0n);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default class {
stableStorage = new StableBTreeMap<string, bigint>(0);
redeployed = false;

@init([])
@init
init(): void {
this.stableStorage.insert('counter', 0n);
}

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
this.redeployed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class {
return output;
}

@update([])
@update
clearCompleted(): void {
// NOTE: this syntax isn't supported in Boa. If we revert to using Boa
// we'll need to revert the syntax to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class {
initCalled: boolean = false;
postUpgradeCalled: boolean = false;

@init([])
@init
init(): void {
console.info('Init was called');
this.initCalled = true;
Expand All @@ -21,7 +21,7 @@ export default class {
return globalThis._azleInitCalled;
}

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
console.info('Post Upgrade was called');
this.initCalled = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { candidEncode, notify, Principal, trap, update } from 'azle';

export default class {
@update([])
@update
sendNotification(): void {
return notify(
Principal.fromText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IDL, query, update } from 'azle';
export default class {
notified: boolean = false;

@update([])
@update
receiveNotification(): void {
this.notified = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class {
return param;
}

@query([])
@query
voidIsNotNull(): void {
print(
'Even though they are both None in Python, for Candid null and void are different.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default class {
[key: string]: bigint;
} = {};

@init([])
@init
init(): void {
console.info('init');

this.stableStorage.insert('entries', []);
}

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
console.info('postUpgrade');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IDL, postUpgrade, query, update } from 'azle';
export default class {
redeployed = false;

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
this.redeployed = true;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/stable/test/property/ic_api/caller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class {
preUpgradeCaller = new StableBTreeMap<'PRE_UPGRADE_CALLER', Principal>(0);
inspectMessageCaller: Principal | null = null;

@init([])
@init
init(): void {
this.initCaller = caller();
}
Expand All @@ -34,7 +34,7 @@ export default class {
}
}

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
this.postUpgradeCaller = caller();
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export default class {
}
}

@update([])
@update
setInspectMessageCaller(): void {
this.inspectMessageCaller = caller();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class {
inspectMessageCanisterVersion: bigint | null = null;
meaninglessState: bigint = 0n;

@init([])
@init
init(): void {
this.initCanisterVersion = canisterVersion();
}
Expand All @@ -37,7 +37,7 @@ export default class {
}
}

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
this.postUpgradeCanisterVersion = canisterVersion();
}
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class {
}
}

@update([])
@update
setInspectMessageCanisterVersion(): void {
this.inspectMessageCanisterVersion = canisterVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class {
return certificate !== undefined ? [certificate] : [];
}

@query([])
@query
setDataCertificateInQuery(): void {
setCertifiedData(new Uint8Array([3]));
}
Expand Down
6 changes: 3 additions & 3 deletions examples/stable/test/property/ic_api/id/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class {
preUpgradeId = new StableBTreeMap<'PRE_UPGRADE_ID', Principal>(0);
inspectMessageId: Principal | null = null;

@init([])
@init
init(): void {
this.initId = id();
}
Expand All @@ -34,7 +34,7 @@ export default class {
}
}

@postUpgrade([])
@postUpgrade
postUpgrade(): void {
this.postUpgradeId = id();
}
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class {
}
}

@update([])
@update
setInspectMessageId(): void {
this.inspectMessageId = id();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default class {
reject('Rejection with message');
}

@query([])
@query
noError(): void {}
}
6 changes: 3 additions & 3 deletions examples/stable/test/property/ic_api/time/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
import { AssertType, NotAnyAndExact } from 'azle/type_tests/assert_type';

export default class {
// @init([])
// @init
// init(): void {
// trap(`trapped from init`);
// }

// @postUpgrade([])
// @postUpgrade
// postUpgrade(): void {
// trap(`trapped from postUpgrade`);
// }
Expand All @@ -41,7 +41,7 @@ export default class {
}
}

@update([])
@update
inspectMessageTime(): void {}

@query([], IDL.Nat64)
Expand Down
29 changes: 3 additions & 26 deletions src/lib/stable/canister_methods/heartbeat.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
import { handleUncaughtError } from '../error';
import { executeAndReplyWithCandidSerde } from '../execute_with_candid_serde';
import { decoratorArgumentsHandler, MethodType } from '.';

export function heartbeat<This, Args extends any[], Return>(
originalMethod: (this: This, ...args: Args) => Return,
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext
): void {
const index = globalThis._azleCanisterMethodsIndex++;
const name = context.name as string;
const indexString = index.toString();

globalThis._azleMethodMeta.heartbeat = {
name,
index
};

globalThis._azleCallbacks[indexString] = async (): Promise<void> => {
try {
await executeAndReplyWithCandidSerde(
'heartbeat',
new Uint8Array(),
originalMethod.bind(globalThis._azleCanisterClassInstance),
[],
undefined,
false
);
} catch (error: any) {
handleUncaughtError(error);
}
};
decoratorArgumentsHandler('heartbeat', originalMethod, context);
}
Loading
Loading