Skip to content

Commit

Permalink
adding jsdocs to query and update decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 2, 2025
1 parent 825fe6f commit 77019f7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, IDL, rejectCode, RejectionCode, trap, update } from 'azle';
import { call, IDL, rejectCode, RejectionCode, update } from 'azle';
import { AssertType, NotAnyAndExact } from 'azle/type_tests/assert_type';

export default class {
Expand Down Expand Up @@ -111,8 +111,9 @@ function isRejectionCode(code: RejectionCode): boolean {
}

function getRejectorPrincipal(): string {
return (
process.env.REJECTOR_PRINCIPAL ??
trap('process.env.REJECTOR_PRINCIPAL is undefined')
);
if (process.env.REJECTOR_PRINCIPAL !== undefined) {
return process.env.REJECTOR_PRINCIPAL;
}

throw new Error(`process.env.REJECTOR_PRINCIPAL is undefined`);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call, IDL, rejectMessage, trap, update } from 'azle';
import { call, IDL, rejectMessage, update } from 'azle';
import { AssertType, NotAnyAndExact } from 'azle/type_tests/assert_type';

export default class {
Expand Down Expand Up @@ -38,8 +38,9 @@ async function getRejectMessage(
}

function getRejectorPrincipal(): string {
return (
process.env.REJECTOR_PRINCIPAL ??
trap('process.env.REJECTOR_PRINCIPAL is undefined')
);
if (process.env.REJECTOR_PRINCIPAL !== undefined) {
return process.env.REJECTOR_PRINCIPAL;
}

throw new Error(`process.env.REJECTOR_PRINCIPAL is undefined`);
}
14 changes: 14 additions & 0 deletions src/lib/stable/canister_methods/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ import {
MethodType
} from '.';

/**
* Decorator to mark a method as a query call entry point.
* Query calls are read-only and do not inherit latency from ICP consensus.
*/
export function query<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext<This, MethodType<This, Args, Return>>
): MethodType<ExportedCanisterClass, Args, Return>;

/**
* Decorator to mark a method as a query call entry point.
* Query calls are read-only and do not inherit latency from ICP consensus.
*
* @param paramIdlTypes - Optional array of Candid IDL types for the method parameters. The runtime arguments will be decoded using these types.
* @param returnIdlType - Optional Candid IDL type for the method return value. The runtime return value will be encoded using this type.
* @param options - Optional configuration object
* @param options.composite - Optional flag to indicate that the method should be treated as a composite query method capable of some cross-canister query calls.
* @param options.manual - Optional flag to indicate manual handling of the method's runtime return value. This is meant to be used with `reply`, skipping automatic Candid encoding of the runtime return value.
*/
export function query<This, Args extends any[], Return>(
paramIdlTypes?: IDL.Type[],
returnIdlType?: IDL.Type,
Expand Down
13 changes: 13 additions & 0 deletions src/lib/stable/canister_methods/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ import {
MethodType
} from '.';

/**
* Decorator to mark a method as an update call entry point.
* Update calls are read-write and inherit latency from ICP consensus.
*/
export function update<This, Args extends any[], Return>(
originalMethod: MethodType<This, Args, Return>,
context: ClassMethodDecoratorContext<This, MethodType<This, Args, Return>>
): MethodType<ExportedCanisterClass, Args, Return>;

/**
* Decorator to mark a method as an update call entry point.
* Update calls are read-write and inherit latency from ICP consensus.
*
* @param paramIdlTypes - Optional array of Candid IDL types for the method parameters. The runtime arguments will be decoded using these types.
* @param returnIdlType - Optional Candid IDL type for the method return value. The runtime return value will be encoded using this type.
* @param options - Optional configuration object
* @param options.manual - Optional flag to indicate manual handling of the method's runtime return value. This is meant to be used with `reply`, skipping automatic Candid encoding of the runtime return value.
*/
export function update<This, Args extends any[], Return>(
paramIdlTypes?: IDL.Type[],
returnIdlType?: IDL.Type,
Expand Down

0 comments on commit 77019f7

Please sign in to comment.