Skip to content

Commit

Permalink
Merge branch 'js_rearchitecture' into azle_book_rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Oct 3, 2023
2 parents 3029735 + 605103c commit 2a21d54
Show file tree
Hide file tree
Showing 165 changed files with 3,699 additions and 4,141 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ jobs:
"examples/stable_structures",
"examples/timers",
"examples/tuple_types",
"examples/update"
"examples/update",
"examples/vanilla_js"
]
END
)
Expand Down
2 changes: 1 addition & 1 deletion canisters/icrc/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nat, Record, text } from '../../src/lib_functional';
import { nat, Record, text } from '../../src/lib';

export const BadFee = Record({
expected_fee: nat
Expand Down
2 changes: 1 addition & 1 deletion canisters/icrc/icrc_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Record,
text,
Variant
} from '../../src/lib_functional';
} from '../../src/lib';
import {
BadBurn,
BadFee,
Expand Down
11 changes: 1 addition & 10 deletions canisters/icrc/icrc_2.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
blob,
nat,
nat64,
Null,
Opt,
Principal,
Record,
Variant
} from '../../src/lib_functional';
import { blob, nat, nat64, Null, Opt, Record, Variant } from '../../src/lib';

import {
BadFee,
Expand Down
2 changes: 1 addition & 1 deletion canisters/icrc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
text,
Tuple,
Vec
} from '../../src/lib_functional';
} from '../../src/lib';
import { Account, TransferArgs, TransferResult, Value } from './icrc_1';
import {
AllowanceArgs,
Expand Down
2 changes: 1 addition & 1 deletion canisters/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
Vec,
Principal,
Func
} from '../../src/lib_functional';
} from '../../src/lib';
import * as icrc from '../icrc';

// Amount of tokens, measured in 10^-8 of a token.
Expand Down
2 changes: 1 addition & 1 deletion canisters/management/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
text,
Variant,
Vec
} from '../../src/lib_functional';
} from '../../src/lib';

export type BitcoinAddress = text;
export const BitcoinAddress = text;
Expand Down
137 changes: 137 additions & 0 deletions canisters/management/canister_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// JS docs licensed under:
//
// - https://github.com/dfinity/cdk-rs/blob/main/LICENSE
//
// Some documentation changed from original work.

import {
Record,
Opt,
Vec,
Principal,
Variant,
nat64,
nat8,
Null
} from '../../src/lib';
import { managementCanister } from '.';

/** Argument type of {@link managementCanister.canister_info}. */
export const CanisterInfoArgs = Record({
/** Principle of the canister. */
canister_id: Principal,
/**
* Number of most recent changes requested to be retrieved from canister
* history. No changes are retrieved if this field is `None`.
*/
num_requested_changes: Opt(nat64)
});

/** Details about a canister creation. */
export const CreationRecord = Record({
/** Initial set of canister controllers. */
controllers: Vec(Principal)
});

/** The mode with which a canister is installed. */
export const CanisterInstallMode = Variant({
/** A fresh install of a new canister. */
install: Null,
/** Reinstalling a canister that was already installed. */
reinstall: Null,
/** Upgrade an existing canister. */
upgrade: Null
});

/** Details about a canister code deployment. */
export const CodeDeploymentRecord = Record({
/** See {@link CanisterInstallMode}. */
mode: CanisterInstallMode,
/** A SHA256 hash of the new module installed on the canister. */
module_hash: Vec(nat8)
});

/** Details about updating canister controllers. */
export const ControllersChangeRecord = Record({
/** The full new set of canister controllers. */
controllers: Vec(Principal)
});

/** Provides details on the respective canister change. */
export const CanisterChangeDetails = Variant({
/** See {@link CreationRecord}. */
creation: CreationRecord,
/** Uninstalling canister's module */
code_uninstall: Null,
/** See {@link CodeDeploymentRecord}. */
code_deployment: CodeDeploymentRecord,
/** See {@link ControllersChangeRecord}. */
controllers_change: ControllersChangeRecord
});

/** Details about a canister change initiated by a user. */
export const FromUserRecord = Record({
/** Principle of the user. */
user_id: Principal
});

/**
* Details about a canister change initiated by a canister (called *originator*).
*/
export const FromCanisterRecord = Record({
/** Principle of the originator. */
canister_id: Principal,
/**
* Canister version of the originator when the originator initiated the
* change. This is `None` if the original does not include its canister
* version in the field `sender_canister_version` of the management canister
* payload.
*/
canister_version: Opt(nat64)
});

/** Provides details on who initiated a canister change. */
export const CanisterChangeOrigin = Variant({
/** See {@link FromUserRecord}. */
from_user: FromUserRecord,
/** See {@link FromCanisterRecord}. */
from_canister: FromCanisterRecord
});

/** Represents a canister change as stored in the canister history. */
export const CanisterChange = Record({
/**
* The system timestamp (in nanoseconds since Unix Epoch) at which the
* change was performed
*/
timestamp_nanos: nat64,
/** The canister version after performing the change. */
canister_version: nat64,
/** The change’s origin (a user or a canister). */
origin: CanisterChangeOrigin,
/** The change’s details. */
details: CanisterChangeDetails
});

/** Return type of {@link managementCanister.canister_info}. */
export const CanisterInfoResult = Record({
/**
* Total number of changes ever recorded in canister history. This might be
* higher than the number of canister changes in recent_changes because the
* IC might drop old canister changes from its history (with 20 most recent
* canister changes to always remain in the list).
*/
total_num_changes: nat64,
/**
* The canister changes stored in the order from the oldest to the most
* recent.
*/
recent_changes: Vec(CanisterChange),
/**
* A SHA256 hash of the module installed on the canister. This is null if
* the canister is empty.
*/
module_hash: Opt(Vec(nat8)),
/** Controllers of the canister. */
controllers: Vec(Principal)
});
2 changes: 1 addition & 1 deletion canisters/management/canister_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Variant,
Null,
blob
} from '../../src/lib_functional';
} from '../../src/lib';

export const CanisterId = Principal;
export const UserId = Principal;
Expand Down
2 changes: 1 addition & 1 deletion canisters/management/http_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
nat64,
nat,
Func
} from '../../src/lib_functional';
} from '../../src/lib';

export const HttpHeader = Record({
name: text,
Expand Down
19 changes: 11 additions & 8 deletions canisters/management/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {
blob,
Canister,
Principal,
update,
Vec,
Void
} from '../../src/lib_functional';
// Some JS docs licensed under:
//
// - https://github.com/dfinity/cdk-rs/blob/main/LICENSE
//
// Some documentation changed from original work.

import { blob, Canister, Principal, update, Vec, Void } from '../../src/lib';
import {
GetBalanceArgs,
GetCurrentFeePercentilesArgs,
Expand All @@ -15,6 +14,7 @@ import {
Satoshi,
SendTransactionArgs
} from './bitcoin';
import { CanisterInfoArgs, CanisterInfoResult } from './canister_info';
import {
CanisterStatusArgs,
CanisterStatusResult,
Expand All @@ -40,6 +40,7 @@ import {
} from './t_ecdsa';

export * from './bitcoin';
export * from './canister_info';
export * from './canister_management';
export * from './http_request';
export * from './t_ecdsa';
Expand All @@ -60,6 +61,8 @@ export const managementCanister = Canister({
uninstall_code: update([UninstallCodeArgs], Void),
start_canister: update([StartCanisterArgs], Void),
stop_canister: update([StopCanisterArgs], Void),
/** Get public information about the canister. */
canister_info: update([CanisterInfoArgs], CanisterInfoResult),
canister_status: update([CanisterStatusArgs], CanisterStatusResult),
delete_canister: update([DeleteCanisterArgs], Void),
deposit_cycles: update([DepositCyclesArgs], Void),
Expand Down
2 changes: 1 addition & 1 deletion canisters/management/t_ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
text,
Variant,
Vec
} from '../../src/lib_functional';
} from '../../src/lib';

export const EcdsaCurve = Variant({
secp256k1: Null
Expand Down
27 changes: 8 additions & 19 deletions examples/audio_recorder/src/index.did
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
type rec_2 = record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64};
type rec_3 = record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64};
type rec_4 = record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64};
type rec_5 = record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64};
type rec_6 = variant {RecordingDoesNotExist:principal; UserDoesNotExist:principal};
type rec_7 = record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64};
type rec_8 = variant {RecordingDoesNotExist:principal; UserDoesNotExist:principal};
type rec_9 = record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64};
type rec_10 = record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64};
type rec_11 = record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64};
type rec_12 = variant {RecordingDoesNotExist:principal; UserDoesNotExist:principal};
service: () -> {
createUser: (text) -> (rec_2);
readUsers: () -> (vec rec_3) query;
readUserById: (principal) -> (opt rec_4) query;
deleteUser: (principal) -> (variant {Ok:rec_5; Err:rec_6});
createRecording: (vec nat8, text, principal) -> (variant {Ok:rec_7; Err:rec_8});
readRecordings: () -> (vec rec_9) query;
readRecordingById: (principal) -> (opt rec_10) query;
deleteRecording: (principal) -> (variant {Ok:rec_11; Err:rec_12});
createRecording: (vec nat8, text, principal) -> (variant {Ok:record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64}; Err:variant {RecordingDoesNotExist:principal; UserDoesNotExist:principal}});
createUser: (text) -> (record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64});
deleteRecording: (principal) -> (variant {Ok:record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64}; Err:variant {RecordingDoesNotExist:principal; UserDoesNotExist:principal}});
deleteUser: (principal) -> (variant {Ok:record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64}; Err:variant {RecordingDoesNotExist:principal; UserDoesNotExist:principal}});
readRecordingById: (principal) -> (opt record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64}) query;
readRecordings: () -> (vec record {id:principal; audio:vec nat8; userId:principal; name:text; createdAt:nat64}) query;
readUserById: (principal) -> (opt record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64}) query;
readUsers: () -> (vec record {id:principal; username:text; recordingIds:vec principal; createdAt:nat64}) query;
}
61 changes: 10 additions & 51 deletions examples/icrc/canisters/proxy/index.did
Original file line number Diff line number Diff line change
@@ -1,56 +1,15 @@
type rec_41 = variant {Int:int; Nat:nat; Blob:vec nat8; Text:text};
type rec_42 = record {owner:principal; subaccount:opt vec nat8};
type rec_43 = record {owner:principal; subaccount:opt vec nat8};
type rec_45 = record {owner:principal; subaccount:opt vec nat8};
type rec_44 = record {to:rec_45; fee:opt nat; memo:opt vec nat8; from_subaccount:opt vec nat8; created_at_time:opt nat64; amount:nat};
type rec_53 = record {message:text; error_code:nat};
type rec_49 = record {min_burn_amount:nat};
type rec_52 = record {duplicate_of:nat};
type rec_48 = record {expected_fee:nat};
type rec_51 = record {ledger_time:nat64};
type rec_50 = record {balance:nat};
type rec_47 = variant {GenericError:rec_53; TemporarilyUnavailable; BadBurn:rec_49; Duplicate:rec_52; BadFee:rec_48; CreatedInFuture:rec_51; TooOld; InsufficientFunds:rec_50};
type rec_46 = variant {Ok:nat; Err:rec_47};
type rec_54 = record {url:text; name:text};
type rec_56 = record {owner:principal; subaccount:opt vec nat8};
type rec_55 = record {fee:opt nat; memo:opt vec nat8; from_subaccount:opt vec nat8; created_at_time:opt nat64; amount:nat; expected_allowance:opt nat; expires_at:opt nat64; spender:rec_56};
type rec_65 = record {message:text; error_code:nat};
type rec_64 = record {duplicate_of:nat};
type rec_59 = record {expected_fee:nat};
type rec_61 = record {current_allowance:nat};
type rec_63 = record {ledger_time:nat64};
type rec_62 = record {ledger_time:nat64};
type rec_60 = record {balance:nat};
type rec_58 = variant {GenericError:rec_65; TemporarilyUnavailable; Duplicate:rec_64; BadFee:rec_59; AllowanceChanged:rec_61; CreatedInFuture:rec_63; TooOld; Expired:rec_62; InsufficientFunds:rec_60};
type rec_57 = variant {Ok:nat; Err:rec_58};
type rec_68 = record {owner:principal; subaccount:opt vec nat8};
type rec_67 = record {owner:principal; subaccount:opt vec nat8};
type rec_66 = record {to:rec_68; fee:opt nat; from:rec_67; memo:opt vec nat8; created_at_time:opt nat64; amount:nat};
type rec_77 = record {message:text; error_code:nat};
type rec_74 = record {allowance:nat};
type rec_72 = record {min_burn_amount:nat};
type rec_76 = record {duplicate_of:nat};
type rec_71 = record {expected_fee:nat};
type rec_75 = record {ledger_time:nat64};
type rec_73 = record {balance:nat};
type rec_70 = variant {GenericError:rec_77; TemporarilyUnavailable; InsufficientAllowance:rec_74; BadBurn:rec_72; Duplicate:rec_76; BadFee:rec_71; CreatedInFuture:rec_75; TooOld; InsufficientFunds:rec_73};
type rec_69 = variant {Ok:nat; Err:rec_70};
type rec_79 = record {owner:principal; subaccount:opt vec nat8};
type rec_80 = record {owner:principal; subaccount:opt vec nat8};
type rec_78 = record {account:rec_79; spender:rec_80};
type rec_81 = record {allowance:nat; expires_at:opt nat64};
service: () -> {
icrc1_metadata: () -> (vec record {text; rec_41}) query;
icrc1_name: () -> (text) query;
icrc1_balance_of: (record {owner:principal; subaccount:opt vec nat8}) -> (nat) query;
icrc1_decimals: () -> (nat8) query;
icrc1_symbol: () -> (text) query;
icrc1_fee: () -> (nat) query;
icrc1_metadata: () -> (vec record {text; variant {Int:int; Nat:nat; Blob:vec nat8; Text:text}}) query;
icrc1_minting_account: () -> (opt record {owner:principal; subaccount:opt vec nat8}) query;
icrc1_name: () -> (text) query;
icrc1_supported_standards: () -> (vec record {url:text; name:text}) query;
icrc1_symbol: () -> (text) query;
icrc1_total_supply: () -> (nat) query;
icrc1_minting_account: () -> (opt rec_42) query;
icrc1_balance_of: (rec_43) -> (nat) query;
icrc1_transfer: (rec_44) -> (rec_46);
icrc1_supported_standards: () -> (vec rec_54) query;
icrc2_approve: (rec_55) -> (rec_57);
icrc2_transfer_from: (rec_66) -> (rec_69);
icrc2_allowance: (rec_78) -> (rec_81);
icrc1_transfer: (record {to:record {owner:principal; subaccount:opt vec nat8}; fee:opt nat; memo:opt vec nat8; from_subaccount:opt vec nat8; created_at_time:opt nat64; amount:nat}) -> (variant {Ok:nat; Err:variant {GenericError:record {message:text; error_code:nat}; TemporarilyUnavailable; BadBurn:record {min_burn_amount:nat}; Duplicate:record {duplicate_of:nat}; BadFee:record {expected_fee:nat}; CreatedInFuture:record {ledger_time:nat64}; TooOld; InsufficientFunds:record {balance:nat}}});
icrc2_allowance: (record {account:record {owner:principal; subaccount:opt vec nat8}; spender:record {owner:principal; subaccount:opt vec nat8}}) -> (record {allowance:nat; expires_at:opt nat64});
icrc2_approve: (record {fee:opt nat; memo:opt vec nat8; from_subaccount:opt vec nat8; created_at_time:opt nat64; amount:nat; expected_allowance:opt nat; expires_at:opt nat64; spender:record {owner:principal; subaccount:opt vec nat8}}) -> (variant {Ok:nat; Err:variant {GenericError:record {message:text; error_code:nat}; TemporarilyUnavailable; Duplicate:record {duplicate_of:nat}; BadFee:record {expected_fee:nat}; AllowanceChanged:record {current_allowance:nat}; CreatedInFuture:record {ledger_time:nat64}; TooOld; Expired:record {ledger_time:nat64}; InsufficientFunds:record {balance:nat}}});
icrc2_transfer_from: (record {to:record {owner:principal; subaccount:opt vec nat8}; fee:opt nat; from:record {owner:principal; subaccount:opt vec nat8}; memo:opt vec nat8; created_at_time:opt nat64; amount:nat}) -> (variant {Ok:nat; Err:variant {GenericError:record {message:text; error_code:nat}; TemporarilyUnavailable; InsufficientAllowance:record {allowance:nat}; BadBurn:record {min_burn_amount:nat}; Duplicate:record {duplicate_of:nat}; BadFee:record {expected_fee:nat}; CreatedInFuture:record {ledger_time:nat64}; TooOld; InsufficientFunds:record {balance:nat}}});
}
2 changes: 1 addition & 1 deletion examples/inspect_message/src/index.did
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
service: () -> {
accessible: () -> (bool);
inaccessible: () -> (bool);
alsoInaccessible: () -> (bool);
inaccessible: () -> (bool);
}
1 change: 1 addition & 0 deletions examples/management_canister/src/index.did
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ service: () -> {
executeStopCanister: (principal) -> (bool);
executeUninstallCode: (principal) -> (bool);
executeUpdateSettings: (principal) -> (bool);
getCanisterInfo: (record {canister_id:principal; num_requested_changes:opt nat64}) -> (record {controllers:vec principal; module_hash:opt vec nat8; recent_changes:vec record {timestamp_nanos:nat64; canister_version:nat64; origin:variant {from_user:record {user_id:principal}; from_canister:record {canister_version:opt nat64; canister_id:principal}}; details:variant {creation:record {controllers:vec principal}; code_deployment:record {mode:variant {reinstall; upgrade; install}; module_hash:vec nat8}; controllers_change:record {controllers:vec principal}; code_uninstall}}; total_num_changes:nat64});
getCanisterStatus: (record {canister_id:principal}) -> (record {status:variant {stopped; stopping; running}; memory_size:nat; cycles:nat; settings:record {freezing_threshold:nat; controllers:vec principal; memory_allocation:nat; compute_allocation:nat}; module_hash:opt vec nat8});
getCreatedCanisterId: () -> (principal) query;
getRawRand: () -> (vec nat8);
Expand Down
Loading

0 comments on commit 2a21d54

Please sign in to comment.