-
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.
Merge pull request #1855 from demergent-labs/guard_functions
Guard functions
- Loading branch information
Showing
19 changed files
with
10,234 additions
and
8 deletions.
There are no files selected for viewing
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
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,26 @@ | ||
import { handleUncaughtError } from './error'; | ||
|
||
// TODO guards can be asynchronous right? At least update guards | ||
// TODO query guards should be able to be composite as well | ||
// TODO seems like in ic-cdk they cannot be asynchronous | ||
// TODO but seems like ICP would allow them to be | ||
export function createGlobalGuard( | ||
guard: (() => any) | undefined, | ||
guardedMethodName: string | ||
): string | undefined { | ||
if (guard === undefined) { | ||
return undefined; | ||
} | ||
|
||
const guardName = `_azleGuard_${guardedMethodName}`; | ||
|
||
globalThis._azleGuardFunctions[guardName] = () => { | ||
try { | ||
guard(); | ||
} catch (error) { | ||
handleUncaughtError(error); | ||
} | ||
}; | ||
|
||
return guardName; | ||
} |
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
4 changes: 4 additions & 0 deletions
4
tests/end_to_end/candid_rpc/class_syntax/guard_functions/.gitignore
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,4 @@ | ||
.azle | ||
.dfx | ||
dfx_generated | ||
node_modules |
14 changes: 14 additions & 0 deletions
14
tests/end_to_end/candid_rpc/class_syntax/guard_functions/dfx.json
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,14 @@ | ||
{ | ||
"canisters": { | ||
"guard_functions": { | ||
"type": "azle", | ||
"main": "src/index.ts", | ||
"candid": "src/index.did", | ||
"candid_gen": "custom", | ||
"declarations": { | ||
"output": "test/dfx_generated/guard_functions", | ||
"node_compatibility": true | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/end_to_end/candid_rpc/class_syntax/guard_functions/jest.config.js
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,10 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest', | ||
'^.+\\.js$': 'ts-jest' | ||
}, | ||
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed | ||
}; |
Oops, something went wrong.