From aa9b51fc61cf64cffe7df438b7d890ed536ec169 Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 8 Dec 2023 14:28:57 -0600 Subject: [PATCH 1/2] use stableJson everywhere --- examples/audio_recorder/src/index.ts | 9 +++++++-- examples/ethereum_json_rpc/src/index.ts | 3 ++- examples/func_types/canisters/func_types/index.ts | 3 ++- examples/motoko_examples/http_counter/src/index.ts | 3 ++- examples/motoko_examples/persistent-storage/src/index.ts | 3 ++- examples/pre_and_post_upgrade/src/index.ts | 3 ++- examples/stable_structures/src/canister1/stable_map_0.ts | 3 ++- examples/stable_structures/src/canister1/stable_map_1.ts | 3 ++- examples/stable_structures/src/canister1/stable_map_2.ts | 3 ++- examples/stable_structures/src/canister1/stable_map_3.ts | 3 ++- examples/stable_structures/src/canister1/stable_map_4.ts | 7 ++++++- examples/stable_structures/src/canister2/stable_map_5.ts | 3 ++- examples/stable_structures/src/canister2/stable_map_6.ts | 3 ++- examples/stable_structures/src/canister2/stable_map_7.ts | 3 ++- examples/stable_structures/src/canister2/stable_map_8.ts | 3 ++- examples/stable_structures/src/canister2/stable_map_9.ts | 3 ++- .../stable_structures/src/canister3/stable_map_10.ts | 7 ++++++- .../stable_structures/src/canister3/stable_map_11.ts | 3 ++- .../stable_structures/src/canister3/stable_map_12.ts | 3 ++- .../stable_structures/src/canister3/stable_map_13.ts | 3 ++- .../stable_structures/src/canister3/stable_map_14.ts | 3 ++- .../stable_structures/src/canister3/stable_map_15.ts | 3 ++- .../stable_structures/src/canister3/stable_map_16.ts | 4 ++-- .../stable_structures/src/canister3/stable_map_17.ts | 4 ++-- 24 files changed, 61 insertions(+), 27 deletions(-) diff --git a/examples/audio_recorder/src/index.ts b/examples/audio_recorder/src/index.ts index 0e9a3b4ff3..4ee9ad0da5 100644 --- a/examples/audio_recorder/src/index.ts +++ b/examples/audio_recorder/src/index.ts @@ -11,6 +11,7 @@ import { Record, Result, StableBTreeMap, + stableJson, text, update, Variant, @@ -40,8 +41,12 @@ const AudioRecorderError = Variant({ }); type AudioRecorderError = typeof AudioRecorderError.tsType; -let users = StableBTreeMap(Principal, User, 0); -let recordings = StableBTreeMap(Principal, Recording, 1); +let users = StableBTreeMap(stableJson, stableJson, 0); +let recordings = StableBTreeMap( + stableJson, + stableJson, + 1 +); export default Canister({ createUser: update([text], User, (username) => { diff --git a/examples/ethereum_json_rpc/src/index.ts b/examples/ethereum_json_rpc/src/index.ts index c9ce2e593e..0bcd209df3 100644 --- a/examples/ethereum_json_rpc/src/index.ts +++ b/examples/ethereum_json_rpc/src/index.ts @@ -7,6 +7,7 @@ import { query, Some, StableBTreeMap, + stableJson, text, update } from 'azle'; @@ -16,7 +17,7 @@ import { managementCanister } from 'azle/canisters/management'; -let stableStorage = StableBTreeMap(text, text, 0); +let stableStorage = StableBTreeMap(stableJson, stableJson, 0); export default Canister({ init: init([text], (ethereumUrl) => { diff --git a/examples/func_types/canisters/func_types/index.ts b/examples/func_types/canisters/func_types/index.ts index 7fe30ca573..42bf4cc907 100644 --- a/examples/func_types/canisters/func_types/index.ts +++ b/examples/func_types/canisters/func_types/index.ts @@ -9,6 +9,7 @@ import { query, Record, StableBTreeMap, + stableJson, update, Variant, Vec, @@ -47,7 +48,7 @@ const NullFunc = Func( 'query' ); -let stableStorage = StableBTreeMap(text, StableFunc, 0); +let stableStorage = StableBTreeMap(stableJson, stableJson, 0); export default Canister({ init: init([], () => { diff --git a/examples/motoko_examples/http_counter/src/index.ts b/examples/motoko_examples/http_counter/src/index.ts index 334d68972a..a5b19cece7 100644 --- a/examples/motoko_examples/http_counter/src/index.ts +++ b/examples/motoko_examples/http_counter/src/index.ts @@ -13,6 +13,7 @@ import { Record, Some, StableBTreeMap, + stableJson, text, Tuple, update, @@ -60,7 +61,7 @@ const HttpRequest = Record({ certificate_version: Opt(nat16) }); -let stableStorage = StableBTreeMap(text, nat, 0); +let stableStorage = StableBTreeMap(stableJson, stableJson, 0); export default Canister({ init: init([], () => { diff --git a/examples/motoko_examples/persistent-storage/src/index.ts b/examples/motoko_examples/persistent-storage/src/index.ts index 70407264e4..3067885d26 100644 --- a/examples/motoko_examples/persistent-storage/src/index.ts +++ b/examples/motoko_examples/persistent-storage/src/index.ts @@ -7,11 +7,12 @@ import { postUpgrade, query, StableBTreeMap, + stableJson, text, update } from 'azle'; -let stableStorage = StableBTreeMap(text, nat, 0); +let stableStorage = StableBTreeMap(stableJson, stableJson, 0); let redeployed = false; export default Canister({ diff --git a/examples/pre_and_post_upgrade/src/index.ts b/examples/pre_and_post_upgrade/src/index.ts index d2770f42ab..335e5ff69e 100644 --- a/examples/pre_and_post_upgrade/src/index.ts +++ b/examples/pre_and_post_upgrade/src/index.ts @@ -7,6 +7,7 @@ import { query, Record, StableBTreeMap, + stableJson, text, update, Vec, @@ -19,7 +20,7 @@ const Entry = Record({ }); type Entry = typeof Entry; -let stableStorage = StableBTreeMap>(text, Vec(Entry), 0); +let stableStorage = StableBTreeMap>(stableJson, stableJson, 0); let entries: { [key: string]: nat64; diff --git a/examples/stable_structures/src/canister1/stable_map_0.ts b/examples/stable_structures/src/canister1/stable_map_0.ts index cd7ec78c15..49f24ba299 100644 --- a/examples/stable_structures/src/canister1/stable_map_0.ts +++ b/examples/stable_structures/src/canister1/stable_map_0.ts @@ -5,13 +5,14 @@ import { Opt, query, StableBTreeMap, + stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap0 = StableBTreeMap(nat8, text, 0); +let stableMap0 = StableBTreeMap(stableJson, stableJson, 0); export const stableMap0Methods = { stableMap0ContainsKey: query([nat8], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_1.ts b/examples/stable_structures/src/canister1/stable_map_1.ts index 077ce4d2fd..3364d6a728 100644 --- a/examples/stable_structures/src/canister1/stable_map_1.ts +++ b/examples/stable_structures/src/canister1/stable_map_1.ts @@ -6,12 +6,13 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; -let stableMap1 = StableBTreeMap(nat16, blob, 1); +let stableMap1 = StableBTreeMap(stableJson, stableJson, 1); export const stableMap1Methods = { stableMap1ContainsKey: query([nat16], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_2.ts b/examples/stable_structures/src/canister1/stable_map_2.ts index 95492ab6aa..5648c53005 100644 --- a/examples/stable_structures/src/canister1/stable_map_2.ts +++ b/examples/stable_structures/src/canister1/stable_map_2.ts @@ -6,12 +6,13 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; -let stableMap2 = StableBTreeMap(nat32, nat, 2); +let stableMap2 = StableBTreeMap(stableJson, stableJson, 2); export const stableMap2Methods = { stableMap2ContainsKey: query([nat32], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_3.ts b/examples/stable_structures/src/canister1/stable_map_3.ts index 5be0912d2c..9e47c7bf69 100644 --- a/examples/stable_structures/src/canister1/stable_map_3.ts +++ b/examples/stable_structures/src/canister1/stable_map_3.ts @@ -5,13 +5,14 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; import { Reaction } from '../types'; -let stableMap3 = StableBTreeMap(Reaction, int, 3); +let stableMap3 = StableBTreeMap(stableJson, stableJson, 3); export const stableMap3Methods = { stableMap3ContainsKey: query([Reaction], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_4.ts b/examples/stable_structures/src/canister1/stable_map_4.ts index 56415d1977..68d8b45054 100644 --- a/examples/stable_structures/src/canister1/stable_map_4.ts +++ b/examples/stable_structures/src/canister1/stable_map_4.ts @@ -5,13 +5,18 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; import { User } from '../types'; -export let stableMap4 = StableBTreeMap(User, float32, 4); +export let stableMap4 = StableBTreeMap( + stableJson, + stableJson, + 4 +); export const stableMap4Methods = { stableMap4ContainsKey: query([User], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_5.ts b/examples/stable_structures/src/canister2/stable_map_5.ts index 9d588b3175..fd2c8a589a 100644 --- a/examples/stable_structures/src/canister2/stable_map_5.ts +++ b/examples/stable_structures/src/canister2/stable_map_5.ts @@ -6,12 +6,13 @@ import { query, update, StableBTreeMap, + stableJson, Vec, text, Tuple } from 'azle'; -let stableMap5 = StableBTreeMap, float64>(Opt(text), float64, 5); +let stableMap5 = StableBTreeMap, float64>(stableJson, stableJson, 5); export const stableMap5Methods = { stableMap5ContainsKey: query([Opt(text)], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_6.ts b/examples/stable_structures/src/canister2/stable_map_6.ts index a3f9d90379..b1a58435e8 100644 --- a/examples/stable_structures/src/canister2/stable_map_6.ts +++ b/examples/stable_structures/src/canister2/stable_map_6.ts @@ -5,11 +5,12 @@ import { query, update, StableBTreeMap, + stableJson, Vec, Tuple } from 'azle'; -let stableMap6 = StableBTreeMap, bool>(Vec(nat64), bool, 6); +let stableMap6 = StableBTreeMap, bool>(stableJson, stableJson, 6); export const stableMap6Methods = { stableMap6ContainsKey: query([Vec(nat64)], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_7.ts b/examples/stable_structures/src/canister2/stable_map_7.ts index 8f9f491aba..b94049dc67 100644 --- a/examples/stable_structures/src/canister2/stable_map_7.ts +++ b/examples/stable_structures/src/canister2/stable_map_7.ts @@ -5,12 +5,13 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; -let stableMap7 = StableBTreeMap(Null, Null, 7); +let stableMap7 = StableBTreeMap(stableJson, stableJson, 7); export const stableMap7Methods = { stableMap7ContainsKey: query([Null], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_8.ts b/examples/stable_structures/src/canister2/stable_map_8.ts index 14f5a6cc39..3255bab1a2 100644 --- a/examples/stable_structures/src/canister2/stable_map_8.ts +++ b/examples/stable_structures/src/canister2/stable_map_8.ts @@ -6,11 +6,12 @@ import { query, update, StableBTreeMap, + stableJson, Vec, Tuple } from 'azle'; -let stableMap8 = StableBTreeMap(bool, Null, 8); +let stableMap8 = StableBTreeMap(stableJson, stableJson, 8); export const stableMap8Methods = { stableMap8ContainsKey: query([bool], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_9.ts b/examples/stable_structures/src/canister2/stable_map_9.ts index 2c06ad8f60..fb364fac5f 100644 --- a/examples/stable_structures/src/canister2/stable_map_9.ts +++ b/examples/stable_structures/src/canister2/stable_map_9.ts @@ -6,12 +6,13 @@ import { query, update, StableBTreeMap, + stableJson, Vec, text, Tuple } from 'azle'; -let stableMap9 = StableBTreeMap>(float64, Vec(text), 9); +let stableMap9 = StableBTreeMap>(stableJson, stableJson, 9); export const stableMap9Methods = { stableMap9ContainsKey: query([float64], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_10.ts b/examples/stable_structures/src/canister3/stable_map_10.ts index a3a5f650be..5473353665 100644 --- a/examples/stable_structures/src/canister3/stable_map_10.ts +++ b/examples/stable_structures/src/canister3/stable_map_10.ts @@ -5,12 +5,17 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; -let stableMap10 = StableBTreeMap>(float32, Opt(bool), 10); +let stableMap10 = StableBTreeMap>( + stableJson, + stableJson, + 10 +); export const stableMap10Methods = { stableMap10ContainsKey: query([float32], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_11.ts b/examples/stable_structures/src/canister3/stable_map_11.ts index 713d882e8c..6ebbc6f19d 100644 --- a/examples/stable_structures/src/canister3/stable_map_11.ts +++ b/examples/stable_structures/src/canister3/stable_map_11.ts @@ -5,13 +5,14 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; import { User } from '../types'; -let stableMap11 = StableBTreeMap(nat, User, 11); +let stableMap11 = StableBTreeMap(stableJson, stableJson, 11); export const stableMap11Methods = { stableMap11ContainsKey: query([nat], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_12.ts b/examples/stable_structures/src/canister3/stable_map_12.ts index d94223abf1..3443fe7b3a 100644 --- a/examples/stable_structures/src/canister3/stable_map_12.ts +++ b/examples/stable_structures/src/canister3/stable_map_12.ts @@ -5,13 +5,14 @@ import { Opt, query, StableBTreeMap, + stableJson, Tuple, update, Vec } from 'azle'; import { Reaction } from '../types'; -let stableMap12 = StableBTreeMap(blob, Reaction, 12); +let stableMap12 = StableBTreeMap(stableJson, stableJson, 12); export const stableMap12Methods = { stableMap12ContainsKey: query([blob], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_13.ts b/examples/stable_structures/src/canister3/stable_map_13.ts index 65fb014e70..72254b3082 100644 --- a/examples/stable_structures/src/canister3/stable_map_13.ts +++ b/examples/stable_structures/src/canister3/stable_map_13.ts @@ -5,13 +5,14 @@ import { Principal, query, StableBTreeMap, + stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap13 = StableBTreeMap(text, Principal, 13); +let stableMap13 = StableBTreeMap(stableJson, stableJson, 13); export const stableMap13Methods = { stableMap13ContainsKey: query([text], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_14.ts b/examples/stable_structures/src/canister3/stable_map_14.ts index 60f352eaf5..8db17c5dad 100644 --- a/examples/stable_structures/src/canister3/stable_map_14.ts +++ b/examples/stable_structures/src/canister3/stable_map_14.ts @@ -4,6 +4,7 @@ import { Opt, query, StableBTreeMap, + stableJson, text, Tuple, update, @@ -11,7 +12,7 @@ import { } from 'azle'; import { Callback } from '../types'; -let stableMap14 = StableBTreeMap(text, Callback, 14); +let stableMap14 = StableBTreeMap(stableJson, stableJson, 14); export const stableMap14Methods = { stableMap14ContainsKey: query([text], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_15.ts b/examples/stable_structures/src/canister3/stable_map_15.ts index 7b89f5b8ab..d27e0d11d2 100644 --- a/examples/stable_structures/src/canister3/stable_map_15.ts +++ b/examples/stable_structures/src/canister3/stable_map_15.ts @@ -4,6 +4,7 @@ import { Opt, query, StableBTreeMap, + stableJson, text, Tuple, update, @@ -11,7 +12,7 @@ import { } from 'azle'; import { Callback } from '../types'; -let stableMap15 = StableBTreeMap(Callback, text, 15); +let stableMap15 = StableBTreeMap(stableJson, stableJson, 15); export const stableMap15Methods = { stableMap15ContainsKey: query([Callback], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_16.ts b/examples/stable_structures/src/canister3/stable_map_16.ts index c1090be395..a6cc8e991b 100644 --- a/examples/stable_structures/src/canister3/stable_map_16.ts +++ b/examples/stable_structures/src/canister3/stable_map_16.ts @@ -6,14 +6,14 @@ import { query, Some, StableBTreeMap, - StableJson, + stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap16 = StableBTreeMap(text, StableJson(), 16); +let stableMap16 = StableBTreeMap(stableJson, stableJson, 16); export const stableMap16Methods = { stableMap16ContainsKey: query([text], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_17.ts b/examples/stable_structures/src/canister3/stable_map_17.ts index c30b3ac39e..932a23ed4c 100644 --- a/examples/stable_structures/src/canister3/stable_map_17.ts +++ b/examples/stable_structures/src/canister3/stable_map_17.ts @@ -4,14 +4,14 @@ import { Opt, query, StableBTreeMap, - StableJson, + stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap17 = StableBTreeMap<{}, text>(StableJson(), text, 17); +let stableMap17 = StableBTreeMap<{}, text>(stableJson, stableJson, 17); export const stableMap17Methods = { stableMap17ContainsKey: query([text], bool, (key) => { From 05aede47abb9acbad6231402a9b0fb5f8af7399d Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Fri, 8 Dec 2023 14:48:10 -0600 Subject: [PATCH 2/2] change StableBTreeMap params, remove stableJson make default --- examples/audio_recorder/src/index.ts | 9 ++------- examples/ethereum_json_rpc/src/index.ts | 3 +-- .../func_types/canisters/func_types/index.ts | 3 +-- .../motoko_examples/http_counter/src/index.ts | 3 +-- .../persistent-storage/src/index.ts | 3 +-- examples/pre_and_post_upgrade/src/index.ts | 3 +-- .../robust_imports/src/azle_coverage/index.ts | 2 +- .../src/type_alias_decls/index.ts | 2 +- .../src/index.ts | 19 +++---------------- .../src/canister1/stable_map_0.ts | 3 +-- .../src/canister1/stable_map_1.ts | 3 +-- .../src/canister1/stable_map_2.ts | 3 +-- .../src/canister1/stable_map_3.ts | 3 +-- .../src/canister1/stable_map_4.ts | 7 +------ .../src/canister2/stable_map_5.ts | 3 +-- .../src/canister2/stable_map_6.ts | 3 +-- .../src/canister2/stable_map_7.ts | 3 +-- .../src/canister2/stable_map_8.ts | 3 +-- .../src/canister2/stable_map_9.ts | 3 +-- .../src/canister3/stable_map_10.ts | 7 +------ .../src/canister3/stable_map_11.ts | 3 +-- .../src/canister3/stable_map_12.ts | 3 +-- .../src/canister3/stable_map_13.ts | 3 +-- .../src/canister3/stable_map_14.ts | 3 +-- .../src/canister3/stable_map_15.ts | 3 +-- .../src/canister3/stable_map_16.ts | 3 +-- .../src/canister3/stable_map_17.ts | 3 +-- .../arbitraries/stable_b_tree_map_arb.ts | 2 +- .../stable_structures/stable_b_tree_map.ts | 7 ++++--- .../stable_structures/stable_b_tree_map.ts | 2 +- 30 files changed, 36 insertions(+), 84 deletions(-) diff --git a/examples/audio_recorder/src/index.ts b/examples/audio_recorder/src/index.ts index 4ee9ad0da5..d80788a69d 100644 --- a/examples/audio_recorder/src/index.ts +++ b/examples/audio_recorder/src/index.ts @@ -11,7 +11,6 @@ import { Record, Result, StableBTreeMap, - stableJson, text, update, Variant, @@ -41,12 +40,8 @@ const AudioRecorderError = Variant({ }); type AudioRecorderError = typeof AudioRecorderError.tsType; -let users = StableBTreeMap(stableJson, stableJson, 0); -let recordings = StableBTreeMap( - stableJson, - stableJson, - 1 -); +let users = StableBTreeMap(0); +let recordings = StableBTreeMap(1); export default Canister({ createUser: update([text], User, (username) => { diff --git a/examples/ethereum_json_rpc/src/index.ts b/examples/ethereum_json_rpc/src/index.ts index 0bcd209df3..737ed70933 100644 --- a/examples/ethereum_json_rpc/src/index.ts +++ b/examples/ethereum_json_rpc/src/index.ts @@ -7,7 +7,6 @@ import { query, Some, StableBTreeMap, - stableJson, text, update } from 'azle'; @@ -17,7 +16,7 @@ import { managementCanister } from 'azle/canisters/management'; -let stableStorage = StableBTreeMap(stableJson, stableJson, 0); +let stableStorage = StableBTreeMap(0); export default Canister({ init: init([text], (ethereumUrl) => { diff --git a/examples/func_types/canisters/func_types/index.ts b/examples/func_types/canisters/func_types/index.ts index 42bf4cc907..970c3af842 100644 --- a/examples/func_types/canisters/func_types/index.ts +++ b/examples/func_types/canisters/func_types/index.ts @@ -9,7 +9,6 @@ import { query, Record, StableBTreeMap, - stableJson, update, Variant, Vec, @@ -48,7 +47,7 @@ const NullFunc = Func( 'query' ); -let stableStorage = StableBTreeMap(stableJson, stableJson, 0); +let stableStorage = StableBTreeMap(0); export default Canister({ init: init([], () => { diff --git a/examples/motoko_examples/http_counter/src/index.ts b/examples/motoko_examples/http_counter/src/index.ts index a5b19cece7..f212e6fb44 100644 --- a/examples/motoko_examples/http_counter/src/index.ts +++ b/examples/motoko_examples/http_counter/src/index.ts @@ -13,7 +13,6 @@ import { Record, Some, StableBTreeMap, - stableJson, text, Tuple, update, @@ -61,7 +60,7 @@ const HttpRequest = Record({ certificate_version: Opt(nat16) }); -let stableStorage = StableBTreeMap(stableJson, stableJson, 0); +let stableStorage = StableBTreeMap(0); export default Canister({ init: init([], () => { diff --git a/examples/motoko_examples/persistent-storage/src/index.ts b/examples/motoko_examples/persistent-storage/src/index.ts index 3067885d26..a307d91dd9 100644 --- a/examples/motoko_examples/persistent-storage/src/index.ts +++ b/examples/motoko_examples/persistent-storage/src/index.ts @@ -7,12 +7,11 @@ import { postUpgrade, query, StableBTreeMap, - stableJson, text, update } from 'azle'; -let stableStorage = StableBTreeMap(stableJson, stableJson, 0); +let stableStorage = StableBTreeMap(0); let redeployed = false; export default Canister({ diff --git a/examples/pre_and_post_upgrade/src/index.ts b/examples/pre_and_post_upgrade/src/index.ts index 335e5ff69e..0061289c66 100644 --- a/examples/pre_and_post_upgrade/src/index.ts +++ b/examples/pre_and_post_upgrade/src/index.ts @@ -7,7 +7,6 @@ import { query, Record, StableBTreeMap, - stableJson, text, update, Vec, @@ -20,7 +19,7 @@ const Entry = Record({ }); type Entry = typeof Entry; -let stableStorage = StableBTreeMap>(stableJson, stableJson, 0); +let stableStorage = StableBTreeMap>(0); let entries: { [key: string]: nat64; diff --git a/examples/robust_imports/src/azle_coverage/index.ts b/examples/robust_imports/src/azle_coverage/index.ts index adef513697..8ac3e06b1a 100644 --- a/examples/robust_imports/src/azle_coverage/index.ts +++ b/examples/robust_imports/src/azle_coverage/index.ts @@ -93,7 +93,7 @@ export const Watermelon = Voavanga({ Seedless: Nutmeg }); -let soncoya = Soncoya(nectarine8, PreparedFruit, 0); +let soncoya = Soncoya(0); function gatherGrapes() { const opt = soncoya.get(0); diff --git a/examples/robust_imports/src/type_alias_decls/index.ts b/examples/robust_imports/src/type_alias_decls/index.ts index 23d8cb2376..6b5abc341f 100644 --- a/examples/robust_imports/src/type_alias_decls/index.ts +++ b/examples/robust_imports/src/type_alias_decls/index.ts @@ -210,7 +210,7 @@ export const returnFuncAlias = azle.query( } ); -let stableMap = types.DeepStableBTreeMapAlias(azle.nat16, azle.text, 1); +let stableMap = types.DeepStableBTreeMapAlias(1); export const setStable = azle.update( [azle.nat16, azle.text], diff --git a/examples/stable_b_tree_map_instruction_threshold/src/index.ts b/examples/stable_b_tree_map_instruction_threshold/src/index.ts index ebecad5643..8c260b37f9 100644 --- a/examples/stable_b_tree_map_instruction_threshold/src/index.ts +++ b/examples/stable_b_tree_map_instruction_threshold/src/index.ts @@ -7,7 +7,6 @@ import { query, Record, StableBTreeMap, - stableJson, text, update, Vec, @@ -20,11 +19,7 @@ const SmallRecord = Record({ }); type SmallRecord = typeof SmallRecord.tsType; -let smallRecordMap = StableBTreeMap( - stableJson, - stableJson, - 0 -); +let smallRecordMap = StableBTreeMap(0); const MediumRecord = Record({ id: text, @@ -34,11 +29,7 @@ const MediumRecord = Record({ }); type MediumRecord = typeof MediumRecord.tsType; -let mediumRecordMap = StableBTreeMap( - stableJson, - stableJson, - 1 -); +let mediumRecordMap = StableBTreeMap(1); const LargeRecord = Record({ id: text, @@ -51,11 +42,7 @@ const LargeRecord = Record({ }); type LargeRecord = typeof LargeRecord.tsType; -let largeRecordMap = StableBTreeMap( - stableJson, - stableJson, - 2 -); +let largeRecordMap = StableBTreeMap(2); export default Canister({ insertSmallRecord: update([nat32], Void, (numToInsert) => { diff --git a/examples/stable_structures/src/canister1/stable_map_0.ts b/examples/stable_structures/src/canister1/stable_map_0.ts index 49f24ba299..f581518b80 100644 --- a/examples/stable_structures/src/canister1/stable_map_0.ts +++ b/examples/stable_structures/src/canister1/stable_map_0.ts @@ -5,14 +5,13 @@ import { Opt, query, StableBTreeMap, - stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap0 = StableBTreeMap(stableJson, stableJson, 0); +let stableMap0 = StableBTreeMap(0); export const stableMap0Methods = { stableMap0ContainsKey: query([nat8], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_1.ts b/examples/stable_structures/src/canister1/stable_map_1.ts index 3364d6a728..f77f6e29e7 100644 --- a/examples/stable_structures/src/canister1/stable_map_1.ts +++ b/examples/stable_structures/src/canister1/stable_map_1.ts @@ -6,13 +6,12 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; -let stableMap1 = StableBTreeMap(stableJson, stableJson, 1); +let stableMap1 = StableBTreeMap(1); export const stableMap1Methods = { stableMap1ContainsKey: query([nat16], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_2.ts b/examples/stable_structures/src/canister1/stable_map_2.ts index 5648c53005..4d27f267f1 100644 --- a/examples/stable_structures/src/canister1/stable_map_2.ts +++ b/examples/stable_structures/src/canister1/stable_map_2.ts @@ -6,13 +6,12 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; -let stableMap2 = StableBTreeMap(stableJson, stableJson, 2); +let stableMap2 = StableBTreeMap(2); export const stableMap2Methods = { stableMap2ContainsKey: query([nat32], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_3.ts b/examples/stable_structures/src/canister1/stable_map_3.ts index 9e47c7bf69..834279876b 100644 --- a/examples/stable_structures/src/canister1/stable_map_3.ts +++ b/examples/stable_structures/src/canister1/stable_map_3.ts @@ -5,14 +5,13 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; import { Reaction } from '../types'; -let stableMap3 = StableBTreeMap(stableJson, stableJson, 3); +let stableMap3 = StableBTreeMap(3); export const stableMap3Methods = { stableMap3ContainsKey: query([Reaction], bool, (key) => { diff --git a/examples/stable_structures/src/canister1/stable_map_4.ts b/examples/stable_structures/src/canister1/stable_map_4.ts index 68d8b45054..20f2f91d2e 100644 --- a/examples/stable_structures/src/canister1/stable_map_4.ts +++ b/examples/stable_structures/src/canister1/stable_map_4.ts @@ -5,18 +5,13 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; import { User } from '../types'; -export let stableMap4 = StableBTreeMap( - stableJson, - stableJson, - 4 -); +export let stableMap4 = StableBTreeMap(4); export const stableMap4Methods = { stableMap4ContainsKey: query([User], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_5.ts b/examples/stable_structures/src/canister2/stable_map_5.ts index fd2c8a589a..0ac3f24c76 100644 --- a/examples/stable_structures/src/canister2/stable_map_5.ts +++ b/examples/stable_structures/src/canister2/stable_map_5.ts @@ -6,13 +6,12 @@ import { query, update, StableBTreeMap, - stableJson, Vec, text, Tuple } from 'azle'; -let stableMap5 = StableBTreeMap, float64>(stableJson, stableJson, 5); +let stableMap5 = StableBTreeMap, float64>(5); export const stableMap5Methods = { stableMap5ContainsKey: query([Opt(text)], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_6.ts b/examples/stable_structures/src/canister2/stable_map_6.ts index b1a58435e8..e5f16cf5b7 100644 --- a/examples/stable_structures/src/canister2/stable_map_6.ts +++ b/examples/stable_structures/src/canister2/stable_map_6.ts @@ -5,12 +5,11 @@ import { query, update, StableBTreeMap, - stableJson, Vec, Tuple } from 'azle'; -let stableMap6 = StableBTreeMap, bool>(stableJson, stableJson, 6); +let stableMap6 = StableBTreeMap, bool>(6); export const stableMap6Methods = { stableMap6ContainsKey: query([Vec(nat64)], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_7.ts b/examples/stable_structures/src/canister2/stable_map_7.ts index b94049dc67..d65509a255 100644 --- a/examples/stable_structures/src/canister2/stable_map_7.ts +++ b/examples/stable_structures/src/canister2/stable_map_7.ts @@ -5,13 +5,12 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; -let stableMap7 = StableBTreeMap(stableJson, stableJson, 7); +let stableMap7 = StableBTreeMap(7); export const stableMap7Methods = { stableMap7ContainsKey: query([Null], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_8.ts b/examples/stable_structures/src/canister2/stable_map_8.ts index 3255bab1a2..e0000200b7 100644 --- a/examples/stable_structures/src/canister2/stable_map_8.ts +++ b/examples/stable_structures/src/canister2/stable_map_8.ts @@ -6,12 +6,11 @@ import { query, update, StableBTreeMap, - stableJson, Vec, Tuple } from 'azle'; -let stableMap8 = StableBTreeMap(stableJson, stableJson, 8); +let stableMap8 = StableBTreeMap(8); export const stableMap8Methods = { stableMap8ContainsKey: query([bool], bool, (key) => { diff --git a/examples/stable_structures/src/canister2/stable_map_9.ts b/examples/stable_structures/src/canister2/stable_map_9.ts index fb364fac5f..a5a00f9933 100644 --- a/examples/stable_structures/src/canister2/stable_map_9.ts +++ b/examples/stable_structures/src/canister2/stable_map_9.ts @@ -6,13 +6,12 @@ import { query, update, StableBTreeMap, - stableJson, Vec, text, Tuple } from 'azle'; -let stableMap9 = StableBTreeMap>(stableJson, stableJson, 9); +let stableMap9 = StableBTreeMap>(9); export const stableMap9Methods = { stableMap9ContainsKey: query([float64], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_10.ts b/examples/stable_structures/src/canister3/stable_map_10.ts index 5473353665..8a663b7094 100644 --- a/examples/stable_structures/src/canister3/stable_map_10.ts +++ b/examples/stable_structures/src/canister3/stable_map_10.ts @@ -5,17 +5,12 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; -let stableMap10 = StableBTreeMap>( - stableJson, - stableJson, - 10 -); +let stableMap10 = StableBTreeMap>(10); export const stableMap10Methods = { stableMap10ContainsKey: query([float32], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_11.ts b/examples/stable_structures/src/canister3/stable_map_11.ts index 6ebbc6f19d..f14d8aa4b5 100644 --- a/examples/stable_structures/src/canister3/stable_map_11.ts +++ b/examples/stable_structures/src/canister3/stable_map_11.ts @@ -5,14 +5,13 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; import { User } from '../types'; -let stableMap11 = StableBTreeMap(stableJson, stableJson, 11); +let stableMap11 = StableBTreeMap(11); export const stableMap11Methods = { stableMap11ContainsKey: query([nat], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_12.ts b/examples/stable_structures/src/canister3/stable_map_12.ts index 3443fe7b3a..b4b7eb4e2a 100644 --- a/examples/stable_structures/src/canister3/stable_map_12.ts +++ b/examples/stable_structures/src/canister3/stable_map_12.ts @@ -5,14 +5,13 @@ import { Opt, query, StableBTreeMap, - stableJson, Tuple, update, Vec } from 'azle'; import { Reaction } from '../types'; -let stableMap12 = StableBTreeMap(stableJson, stableJson, 12); +let stableMap12 = StableBTreeMap(12); export const stableMap12Methods = { stableMap12ContainsKey: query([blob], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_13.ts b/examples/stable_structures/src/canister3/stable_map_13.ts index 72254b3082..a7510fbd8f 100644 --- a/examples/stable_structures/src/canister3/stable_map_13.ts +++ b/examples/stable_structures/src/canister3/stable_map_13.ts @@ -5,14 +5,13 @@ import { Principal, query, StableBTreeMap, - stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap13 = StableBTreeMap(stableJson, stableJson, 13); +let stableMap13 = StableBTreeMap(13); export const stableMap13Methods = { stableMap13ContainsKey: query([text], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_14.ts b/examples/stable_structures/src/canister3/stable_map_14.ts index 8db17c5dad..240ac823b8 100644 --- a/examples/stable_structures/src/canister3/stable_map_14.ts +++ b/examples/stable_structures/src/canister3/stable_map_14.ts @@ -4,7 +4,6 @@ import { Opt, query, StableBTreeMap, - stableJson, text, Tuple, update, @@ -12,7 +11,7 @@ import { } from 'azle'; import { Callback } from '../types'; -let stableMap14 = StableBTreeMap(stableJson, stableJson, 14); +let stableMap14 = StableBTreeMap(14); export const stableMap14Methods = { stableMap14ContainsKey: query([text], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_15.ts b/examples/stable_structures/src/canister3/stable_map_15.ts index d27e0d11d2..097fdbbd66 100644 --- a/examples/stable_structures/src/canister3/stable_map_15.ts +++ b/examples/stable_structures/src/canister3/stable_map_15.ts @@ -4,7 +4,6 @@ import { Opt, query, StableBTreeMap, - stableJson, text, Tuple, update, @@ -12,7 +11,7 @@ import { } from 'azle'; import { Callback } from '../types'; -let stableMap15 = StableBTreeMap(stableJson, stableJson, 15); +let stableMap15 = StableBTreeMap(15); export const stableMap15Methods = { stableMap15ContainsKey: query([Callback], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_16.ts b/examples/stable_structures/src/canister3/stable_map_16.ts index a6cc8e991b..6677d28fa3 100644 --- a/examples/stable_structures/src/canister3/stable_map_16.ts +++ b/examples/stable_structures/src/canister3/stable_map_16.ts @@ -6,14 +6,13 @@ import { query, Some, StableBTreeMap, - stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap16 = StableBTreeMap(stableJson, stableJson, 16); +let stableMap16 = StableBTreeMap(16); export const stableMap16Methods = { stableMap16ContainsKey: query([text], bool, (key) => { diff --git a/examples/stable_structures/src/canister3/stable_map_17.ts b/examples/stable_structures/src/canister3/stable_map_17.ts index 932a23ed4c..ccdef796e0 100644 --- a/examples/stable_structures/src/canister3/stable_map_17.ts +++ b/examples/stable_structures/src/canister3/stable_map_17.ts @@ -4,14 +4,13 @@ import { Opt, query, StableBTreeMap, - stableJson, text, Tuple, update, Vec } from 'azle'; -let stableMap17 = StableBTreeMap<{}, text>(stableJson, stableJson, 17); +let stableMap17 = StableBTreeMap<{}, text>(17); export const stableMap17Methods = { stableMap17ContainsKey: query([text], bool, (key) => { diff --git a/property_tests/arbitraries/stable_b_tree_map_arb.ts b/property_tests/arbitraries/stable_b_tree_map_arb.ts index b7b72157a7..a5b4370659 100644 --- a/property_tests/arbitraries/stable_b_tree_map_arb.ts +++ b/property_tests/arbitraries/stable_b_tree_map_arb.ts @@ -27,7 +27,7 @@ export const StableBTreeMapArb = fc return { name, imports, - definition: `let ${name} = StableBTreeMap<${keySample.src.candidTypeAnnotation}, ${valueSample.src.candidTypeAnnotation}>(stableJson, stableJson, ${memoryId});`, + definition: `let ${name} = StableBTreeMap<${keySample.src.candidTypeAnnotation}, ${valueSample.src.candidTypeAnnotation}>(${memoryId});`, keySample, valueSample }; diff --git a/src/lib/stable_structures/stable_b_tree_map.ts b/src/lib/stable_structures/stable_b_tree_map.ts index b62bdd2c8b..66e1d75111 100644 --- a/src/lib/stable_structures/stable_b_tree_map.ts +++ b/src/lib/stable_structures/stable_b_tree_map.ts @@ -2,6 +2,7 @@ import { None, Opt, Some } from '../candid/types/constructed/opt'; import { nat64 } from '../candid/types/primitive/nats/nat64'; import { nat8 } from '../candid/types/primitive/nats/nat8'; import { decode } from '../candid/serde'; +import { stableJson } from './stable_json'; export interface Serializable { toBytes: (data: any) => Uint8Array; @@ -9,9 +10,9 @@ export interface Serializable { } export function StableBTreeMap( - keySerializable: Serializable, - valueSerializable: Serializable, - memoryIdNumber: nat8 + memoryIdNumber: nat8, + keySerializable: Serializable = stableJson, + valueSerializable: Serializable = stableJson ) { const memoryId = memoryIdNumber.toString(); diff --git a/type_tests/stable_structures/stable_b_tree_map.ts b/type_tests/stable_structures/stable_b_tree_map.ts index ef2ecc5323..b3a05f27ab 100644 --- a/type_tests/stable_structures/stable_b_tree_map.ts +++ b/type_tests/stable_structures/stable_b_tree_map.ts @@ -7,7 +7,7 @@ import { AssertType, NotAnyAndExact } from '../assert_type'; // TODO these tests just make sure that the basic methods are there // TODO we want to maybe test that the type arguments work correctly as well -let mapText = StableBTreeMap(text, text, 0); +let mapText = StableBTreeMap(0); export type TestContainsKey = AssertType< NotAnyAndExact boolean>