-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
4,268 additions
and
257 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,26 @@ | ||
import { handleUncaughtError } from './error'; | ||
import { executeAndReplyWithCandidSerde } from './execute_with_candid_serde'; | ||
|
||
export function heartbeat<T>( | ||
target: object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void { | ||
export function heartbeat<This, Args extends any[], Return>( | ||
originalMethod: (this: This, ...args: Args) => Return, | ||
context: ClassMethodDecoratorContext | ||
): void { | ||
const index = globalThis._azleCanisterMethodsIndex++; | ||
|
||
globalThis._azleCanisterMethods.heartbeat = { | ||
name: propertyKey as string, | ||
name: context.name as string, | ||
index | ||
}; | ||
|
||
globalThis._azleCanisterMethods.callbacks[index.toString()] = | ||
async (): Promise<void> => { | ||
try { | ||
await (descriptor.value as any).bind(target)(); | ||
} catch (error) { | ||
handleUncaughtError(error); | ||
} | ||
}; | ||
|
||
return descriptor; | ||
globalThis._azleCanisterMethods.callbacks[index.toString()] = ( | ||
...args: any[] | ||
): void => { | ||
executeAndReplyWithCandidSerde( | ||
'heartbeat', | ||
args, | ||
originalMethod.bind(globalThis._azleCanisterClassInstance), | ||
[], | ||
undefined, | ||
false | ||
); | ||
}; | ||
} | ||
|
||
// TODO do we need this? | ||
// TODO it would be nice if QuickJS would just panic | ||
// TODO on all uncaught exceptions | ||
// function executeHeartbeat(callback: any) { | ||
// const result = callback(); | ||
|
||
// if ( | ||
// result !== undefined && | ||
// result !== null && | ||
// typeof result.then === 'function' | ||
// ) { | ||
// result.catch((error: any) => { | ||
// ic.trap(error.toString()); | ||
// }); | ||
// } | ||
|
||
// return; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
import { IDL } from '@dfinity/candid'; | ||
|
||
import { executeWithCandidSerde } from './execute_with_candid_serde'; | ||
import { executeAndReplyWithCandidSerde } from './execute_with_candid_serde'; | ||
|
||
export function init<This, Args extends any[], Return>( | ||
paramIdlTypes: IDL.Type[] | ||
) { | ||
return ( | ||
originalMethod: (this: This, ...args: Args) => Return, | ||
context: ClassMethodDecoratorContext | ||
): void => { | ||
const index = globalThis._azleCanisterMethodsIndex++; | ||
|
||
export function init(paramIdls: IDL.Type[]): MethodDecorator { | ||
return <T>( | ||
target: object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void => { | ||
const originalMethod = (descriptor.value as any).bind(target); | ||
globalThis._azleCanisterMethods.init = { | ||
name: context.name as string, | ||
index | ||
}; | ||
|
||
const methodCallback = (...args: any[]): void => { | ||
executeWithCandidSerde( | ||
globalThis._azleCanisterMethods.callbacks[index.toString()] = ( | ||
...args: any[] | ||
): void => { | ||
executeAndReplyWithCandidSerde( | ||
'init', | ||
args, | ||
originalMethod, | ||
paramIdls, | ||
originalMethod.bind(globalThis._azleCanisterClassInstance), | ||
paramIdlTypes, | ||
undefined, | ||
false // TODO implement manual check | ||
false | ||
); | ||
}; | ||
|
||
descriptor.value = methodCallback as any; | ||
|
||
const index = globalThis._azleCanisterMethodsIndex++; | ||
|
||
globalThis._azleCanisterMethods.init = { | ||
name: propertyKey as string, | ||
index | ||
}; | ||
|
||
globalThis._azleCanisterMethods.callbacks[index.toString()] = | ||
methodCallback; | ||
|
||
return descriptor; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
import { IDL } from '@dfinity/candid'; | ||
|
||
import { executeWithCandidSerde } from './execute_with_candid_serde'; | ||
import { executeAndReplyWithCandidSerde } from './execute_with_candid_serde'; | ||
|
||
export function postUpgrade<This, Args extends any[], Return>( | ||
paramIdlTypes: IDL.Type[] | ||
) { | ||
return ( | ||
originalMethod: (this: This, ...args: Args) => Return, | ||
context: ClassMethodDecoratorContext | ||
): void => { | ||
const index = globalThis._azleCanisterMethodsIndex++; | ||
|
||
export function postUpgrade(paramIdls: IDL.Type[]): MethodDecorator { | ||
return <T>( | ||
target: object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void => { | ||
const originalMethod = (descriptor.value as any).bind(target); | ||
globalThis._azleCanisterMethods.post_upgrade = { | ||
name: context.name as string, | ||
index | ||
}; | ||
|
||
const methodCallback = (...args: any[]): void => { | ||
executeWithCandidSerde( | ||
globalThis._azleCanisterMethods.callbacks[index.toString()] = ( | ||
...args: any[] | ||
): void => { | ||
executeAndReplyWithCandidSerde( | ||
'postUpgrade', | ||
args, | ||
originalMethod, | ||
paramIdls, | ||
originalMethod.bind(globalThis._azleCanisterClassInstance), | ||
paramIdlTypes, | ||
undefined, | ||
false // TODO implement manual check | ||
false | ||
); | ||
}; | ||
|
||
descriptor.value = methodCallback as any; | ||
|
||
const index = globalThis._azleCanisterMethodsIndex++; | ||
|
||
globalThis._azleCanisterMethods.post_upgrade = { | ||
name: propertyKey as string, | ||
index | ||
}; | ||
|
||
globalThis._azleCanisterMethods.callbacks[index.toString()] = | ||
methodCallback; | ||
|
||
return descriptor; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
import { handleUncaughtError } from './error'; | ||
import { executeAndReplyWithCandidSerde } from './execute_with_candid_serde'; | ||
|
||
export function preUpgrade<T>( | ||
target: object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void { | ||
export function preUpgrade<This, Args extends any[], Return>( | ||
originalMethod: (this: This, ...args: Args) => Return, | ||
context: ClassMethodDecoratorContext | ||
): void { | ||
const index = globalThis._azleCanisterMethodsIndex++; | ||
|
||
globalThis._azleCanisterMethods.pre_upgrade = { | ||
name: propertyKey as string, | ||
name: context.name as string, | ||
index | ||
}; | ||
|
||
globalThis._azleCanisterMethods.callbacks[index.toString()] = (): void => { | ||
try { | ||
(descriptor.value as any).bind(target)(); | ||
} catch (error) { | ||
handleUncaughtError(error); | ||
} | ||
globalThis._azleCanisterMethods.callbacks[index.toString()] = ( | ||
...args: any[] | ||
): void => { | ||
executeAndReplyWithCandidSerde( | ||
'preUpgrade', | ||
args, | ||
originalMethod.bind(globalThis._azleCanisterClassInstance), | ||
[], | ||
undefined, | ||
false | ||
); | ||
}; | ||
|
||
return descriptor; | ||
} |
Oops, something went wrong.