Skip to content

Commit

Permalink
bonus return types
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jul 9, 2024
1 parent fb30ed5 commit e91539f
Show file tree
Hide file tree
Showing 206 changed files with 591 additions and 515 deletions.
2 changes: 1 addition & 1 deletion benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function write_reports_to_file(
output_file: string,
benchmark_results: BenchmarkResult[],
num_benchmark_iterations: number
) {
): void {
const markdown_report = create_markdown_report(
benchmark_results,
num_benchmark_iterations,
Expand Down
4 changes: 2 additions & 2 deletions benchmark/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ function generate_benchmarks_string(
)}`;
}

function format_number_to_rust(number: string | number | bigint) {
function format_number_to_rust(number: string | number | bigint): string {
const number_is_negative = number.toString()[0] === '-';
const number_is_decimal_less_than_one =
(number_is_negative === false && Number(number) < 1) ||
Expand Down Expand Up @@ -1683,7 +1683,7 @@ function format_number_to_rust(number: string | number | bigint) {
);
}

function format_number_to_usd(number: number) {
function format_number_to_usd(number: number): string {
return number.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
Expand Down
2 changes: 1 addition & 1 deletion benchmark/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process';

export async function run_setup(argument?: string) {
export async function run_setup(argument?: string): Promise<void> {
execSync(`dfx canister create azle`, {
stdio: 'inherit'
});
Expand Down
4 changes: 2 additions & 2 deletions dfx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getAgentHost(): string {
: `http://127.0.0.1:${getWebServerPort()}`;
}

export async function createAnonymousAgent() {
export async function createAnonymousAgent(): Promise<void> {
const agent = new HttpAgent({
host: getAgentHost()
});
Expand Down Expand Up @@ -185,7 +185,7 @@ export function addController(
canisterName: string,
identityName: string,
principal: string
) {
): Buffer {
const currentIdentity = whoami();
console.info();
console.info(`Adding ${identityName} as a controller for ${canisterName}`);
Expand Down
21 changes: 16 additions & 5 deletions examples/apollo_server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ const typeDefs = `#graphql
}
`;

type Book = {
id: string;
title: string;
rating: number;
};

type Author = {
id: string;
name: string;
};

let books = [
{
id: '0',
Expand Down Expand Up @@ -62,14 +73,14 @@ const authors = [
// This resolver retrieves books from the "books" array above.
const resolvers = {
Query: {
books: () => books,
authors: () => authors,
titles: () => {
books: (): Book[] => books,
authors: (): Author[] => authors,
titles: (): string[] => {
return books.map((book) => book.title);
}
},
Mutation: {
createBook: (parent: any, args: any) => {
createBook: (parent: any, args: any): Book => {
const book = {
id: books.length.toString(),
title: args.title,
Expand All @@ -83,7 +94,7 @@ const resolvers = {
}
};

async function init() {
async function init(): Promise<void> {
const app = express();

const server = new ApolloServer({
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_and_video/src/backend/range_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createReadStream, statSync } from 'fs';
import parseRange from 'range-parser';

export function rangeResponse(maxRange: number = 3_000_000) {
return async (req: Request, res: Response) => {
return async (req: Request, res: Response): Promise<void> => {
const filePath = req.originalUrl;
const fileLength = statSync(filePath).size;

Expand Down
6 changes: 3 additions & 3 deletions examples/basic_bitcoin/test/bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Transaction } from 'bitcoinjs-lib';
import { execSync } from 'child_process';

export function generateToAddress(address: string, blocks: number) {
export function generateToAddress(address: string, blocks: number): void {
execSync(
`.bitcoin/bin/bitcoin-cli -conf=$(pwd)/.bitcoin.conf generatetoaddress ${blocks} ${address}`
);
}

export function generate(blocks: number) {
export function generate(blocks: number): void {
execSync(
`.bitcoin/bin/bitcoin-cli -conf=$(pwd)/.bitcoin.conf -generate ${blocks}`
);
}

export function createWallet(name: string) {
export function createWallet(name: string): void {
execSync(
`.bitcoin/bin/bitcoin-cli -conf=$(pwd)/.bitcoin.conf createwallet ${name}`
);
Expand Down
2 changes: 1 addition & 1 deletion examples/bitcoin/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function createTransaction(from: Utxo, wallets: Wallets): string {
return bitcoinCli.createRawTransaction(input, outputs);
}

export function signTransaction(rawTransaction: string) {
export function signTransaction(rawTransaction: string): string {
console.log(' - sign transaction');
return bitcoinCli.signRawTransactionWithWallet(rawTransaction).hex;
}
1 change: 1 addition & 0 deletions examples/bitcoin_psbt/scripts/bitcoin/transaction_count.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execSync } = require('child_process');

Expand Down
2 changes: 1 addition & 1 deletion examples/ckbtc/test/pretest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function pretest(): void {
});
}

function uninstall(...canisterNames: string[]) {
function uninstall(...canisterNames: string[]): void {
canisterNames.forEach((canisterName) => {
execSync(`dfx canister uninstall-code ${canisterName} || true`, {
stdio: 'inherit'
Expand Down
2 changes: 1 addition & 1 deletion examples/ckbtc/wallet/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function padPrincipalWithZeros(blob: blob): blob {
return newUin8Array;
}

function setupCanisters() {
function setupCanisters(): void {
ckBTC = ICRC(
Principal.fromText(
process.env.CK_BTC_PRINCIPAL ??
Expand Down
23 changes: 12 additions & 11 deletions examples/ckbtc/wallet/frontend/elements/ck-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export class CkApp extends LitElement {
@state()
transferring: boolean = false;

async connectedCallback() {
async connectedCallback(): Promise<void> {
super.connectedCallback();

await this.authenticate();
}

async authenticate() {
async authenticate(): Promise<void> {
const authClient = await AuthClient.create();

if (await authClient.isAuthenticated()) {
Expand All @@ -62,14 +62,14 @@ export class CkApp extends LitElement {
}
}

initialize() {
initialize(): void {
this.createWalletBackend();

this.getBalance();
this.getBitcoinDepositAddress();
}

createWalletBackend() {
createWalletBackend(): void {
const agent = new HttpAgent({
identity: this.identity
});
Expand All @@ -89,7 +89,7 @@ export class CkApp extends LitElement {
this.walletBackend = walletBackend;
}

async getBalance() {
async getBalance(): Promise<void> {
if (this.walletBackend === undefined) {
alert(`walletBackend has not been initialized`);
return;
Expand All @@ -102,7 +102,7 @@ export class CkApp extends LitElement {
this.balance = result;
}

async getBitcoinDepositAddress() {
async getBitcoinDepositAddress(): Promise<void> {
if (this.walletBackend === undefined) {
alert(`walletBackend has not been initialized`);
return;
Expand All @@ -115,7 +115,7 @@ export class CkApp extends LitElement {
this.bitcoinDepositAddress = result;
}

async updateBalance() {
async updateBalance(): Promise<void> {
this.updatingBalance = true;

if (this.walletBackend === undefined) {
Expand All @@ -132,7 +132,7 @@ export class CkApp extends LitElement {
this.updatingBalance = false;
}

async transfer() {
async transfer(): Promise<void> {
this.transferring = true;

if (this.walletBackend === undefined) {
Expand All @@ -157,7 +157,7 @@ export class CkApp extends LitElement {
this.transferring = false;
}

render() {
render(): void {
const identityPrincipalString = this.identity
? this.identity.getPrincipal().toText()
: 'Loading...';
Expand Down Expand Up @@ -190,14 +190,15 @@ export class CkApp extends LitElement {
.disabled=${this.transferring}
type="text"
.value=${this.transferTo}
@input=${(e: any) => (this.transferTo = e.target.value)}
@input=${(e: any): void =>
(this.transferTo = e.target.value)}
/>
Amount:
<input
.disabled=${this.transferring}
type="number"
.value=${this.transferAmount}
@input=${(e: any) =>
@input=${(e: any): void =>
(this.transferAmount = BigInt(e.target.value))}
/>
<button
Expand Down
4 changes: 2 additions & 2 deletions examples/composite_queries/src/canister1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function getCanister2Principal(): string {
throw new Error(`process.env.CANISTER2_PRINCIPAL is not defined`);
}

async function incCanister(canister: any, candidPath: string) {
async function incCanister(canister: any, candidPath: string): Promise<any> {
if (process.env.AZLE_TEST_FETCH === 'true') {
const response = await fetch(
`icp://${canister.principal.toText()}/incCounter`,
Expand All @@ -209,7 +209,7 @@ async function incCanister(canister: any, candidPath: string) {
}
}

async function incCanister2() {
async function incCanister2(): Promise<any> {
if (process.env.AZLE_TEST_FETCH === 'true') {
const response = await fetch(
`icp://${getCanister2Principal()}/incCounter`,
Expand Down
7 changes: 5 additions & 2 deletions examples/ethereum_json_rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export default Canister({
})
});

async function getBalance(url: string, ethereumAddress: string) {
async function getBalance(
url: string,
ethereumAddress: string
): Promise<string> {
if (process.env.AZLE_TEST_FETCH === 'true') {
ic.setOutgoingHttpOptions({
maxResponseBytes: 2_000n,
Expand Down Expand Up @@ -108,7 +111,7 @@ async function getBalance(url: string, ethereumAddress: string) {
return Buffer.from(httpResponse.body.buffer).toString('utf-8');
}
}
async function getBlockByNumber(url: string, number: number) {
async function getBlockByNumber(url: string, number: number): Promise<string> {
if (process.env.AZLE_TEST_FETCH === 'true') {
ic.setOutgoingHttpOptions({
maxResponseBytes: 2_000n,
Expand Down
2 changes: 1 addition & 1 deletion examples/express/src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ app.use(express.static('/dist'));

app.listen();

function changeGlobalState(req: Request, res: Response) {
function changeGlobalState(req: Request, res: Response): void {
globalState = req.body;

res.json(globalState);
Expand Down
12 changes: 6 additions & 6 deletions examples/express/src/frontend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class AzleApp extends LitElement {
@property()
globalStateResponse: string = JSON.stringify({});

async testResSend() {
async testResSend(): Promise<void> {
this.resSendResponse = 'Loading...';

const response = await fetch(`${this.canisterOrigin}/res-send`);
Expand All @@ -28,7 +28,7 @@ export class AzleApp extends LitElement {
this.resSendResponse = responseText;
}

async testResWrite() {
async testResWrite(): Promise<void> {
this.resWriteResponse = 'Loading...';

const response = await fetch(`${this.canisterOrigin}/res-write`);
Expand All @@ -37,7 +37,7 @@ export class AzleApp extends LitElement {
this.resWriteResponse = responseText;
}

async testFileStream() {
async testFileStream(): Promise<void> {
this.fileStreamResponse = 'Loading...';

const response = await fetch(`${this.canisterOrigin}/file-stream`);
Expand All @@ -46,7 +46,7 @@ export class AzleApp extends LitElement {
this.fileStreamResponse = responseText;
}

async testGlobalState() {
async testGlobalState(): Promise<void> {
this.globalStateResponse = 'Loading...';

const response = await fetch(
Expand All @@ -64,7 +64,7 @@ export class AzleApp extends LitElement {
this.globalStateResponse = JSON.stringify(responseJson);
}

async deleteGlobalState() {
async deleteGlobalState(): Promise<void> {
this.globalStateResponse = 'Loading...';

const response = await fetch(
Expand All @@ -78,7 +78,7 @@ export class AzleApp extends LitElement {
this.globalStateResponse = JSON.stringify(responseJson);
}

render() {
render(): any {
return html`
<h1>Azle Express App</h1>
Expand Down
Loading

0 comments on commit e91539f

Please sign in to comment.