-
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.
first attempt at restructuring tests and implementing class syntax
- Loading branch information
Showing
36 changed files
with
8,182 additions
and
30 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '../src/lib'; |
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
2 changes: 1 addition & 1 deletion
2
src/lib/candid/types/reference/service/canister_function/query_update.ts
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { IDL } from '@dfinity/candid'; | ||
|
||
import { ic } from '../ic'; | ||
import { handleUncaughtError } from './error'; | ||
|
||
type CanisterMethodMode = | ||
| 'query' | ||
| 'update' | ||
| 'init' | ||
| 'heartbeat' | ||
| 'inspectMessage' | ||
| 'postUpgrade' | ||
| 'preUpgrade'; | ||
|
||
export function executeMethod( | ||
mode: CanisterMethodMode, | ||
args: any[], | ||
callback: any, | ||
paramIdls: IDL.Type[], | ||
returnIdl: IDL.Type, | ||
manual: boolean | ||
) { | ||
const decodedArgs = IDL.decode(paramIdls, args[0]); | ||
|
||
const result = getResult(decodedArgs, callback); | ||
|
||
if ( | ||
mode === 'init' || | ||
mode === 'postUpgrade' || | ||
mode === 'inspectMessage' | ||
) { | ||
return; | ||
} | ||
|
||
if ( | ||
result !== undefined && | ||
result !== null && | ||
typeof result.then === 'function' | ||
) { | ||
result | ||
.then((result: any) => { | ||
if (!manual) { | ||
ic.replyRaw( | ||
new Uint8Array(IDL.encode([returnIdl], [result])) | ||
); | ||
} | ||
}) | ||
.catch((error: any) => { | ||
handleUncaughtError(error); | ||
}); | ||
} else { | ||
if (!manual) { | ||
ic.replyRaw(new Uint8Array(IDL.encode([returnIdl], [result]))); | ||
} | ||
} | ||
} | ||
|
||
function getResult(args: any[], callback: any): any { | ||
try { | ||
return callback(...args); | ||
} catch (error) { | ||
handleUncaughtError(error); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { query } from './query'; | ||
export { update } from './update'; | ||
export { IDL } from '@dfinity/candid'; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function markExperimental() { | ||
if (process.env.AZLE_EXPERIMENTAL !== 'true') { | ||
throw new Error(`Azle: the experimental flag must be set`); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { IDL } from '@dfinity/candid'; | ||
|
||
import { isAsync } from '../canister_methods/is_async'; | ||
import { executeMethod } from './execute_method'; | ||
|
||
export function query( | ||
paramIdls: IDL.Type[], | ||
returnIdl: IDL.Type | ||
): MethodDecorator { | ||
return <T>( | ||
target: object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void => { | ||
const originalMethod = descriptor.value; | ||
|
||
const methodCallback = (...args: any[]) => { | ||
executeMethod( | ||
'query', | ||
args, | ||
originalMethod, | ||
paramIdls, | ||
returnIdl, | ||
false // TODO implement manual check | ||
); | ||
}; | ||
|
||
descriptor.value = methodCallback as any; | ||
|
||
globalThis._azleCanisterMethods.queries.push({ | ||
name: propertyKey as string, | ||
composite: isAsync(originalMethod) | ||
// TODO implement guard | ||
}); | ||
|
||
globalThis._azleCanisterMethods.callbacks[propertyKey as string] = | ||
methodCallback; | ||
|
||
return descriptor; | ||
}; | ||
} | ||
|
||
// TODO this implementation is for native decorators | ||
// export function query<This, Args extends any[], Return>( | ||
// paramIdls: IDL.Type[], | ||
// returnIdl: IDL.Type | ||
// ) { | ||
// return ( | ||
// originalMethod: (this: This, ...args: Args) => Return, | ||
// _context: ClassMethodDecoratorContext< | ||
// This, | ||
// (this: This, ...args: Args) => Return | ||
// > | ||
// ) => { | ||
// return function (this: This, ...args: Args): Return { | ||
// executeMethod( | ||
// 'query', | ||
// args, | ||
// originalMethod, | ||
// paramIdls, | ||
// returnIdl, | ||
// false // TODO implement manual check | ||
// ); | ||
|
||
// return undefined as 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { IDL } from '@dfinity/candid'; | ||
|
||
import { executeMethod } from './execute_method'; | ||
|
||
export function update( | ||
paramIdls: IDL.Type[], | ||
returnIdl: IDL.Type | ||
): MethodDecorator { | ||
return <T>( | ||
target: object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void => { | ||
const originalMethod = descriptor.value; | ||
|
||
const methodCallback = (...args: any[]) => { | ||
executeMethod( | ||
'update', | ||
args, | ||
originalMethod, | ||
paramIdls, | ||
returnIdl, | ||
false // TODO implement manual check | ||
); | ||
}; | ||
|
||
descriptor.value = methodCallback as any; | ||
|
||
globalThis._azleCanisterMethods.updates.push({ | ||
name: propertyKey as string | ||
// TODO implement guard | ||
}); | ||
|
||
globalThis._azleCanisterMethods.callbacks[propertyKey as string] = | ||
methodCallback; | ||
|
||
return descriptor; | ||
}; | ||
} |
Oops, something went wrong.