Skip to content

Commit

Permalink
make stable b tree map a class
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Dec 19, 2024
1 parent f2eb55c commit 6a4d21d
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Recording = {
};

export default class {
users = StableBTreeMap<Principal, User>(0);
recordings = StableBTreeMap<Principal, Recording>(1);
users = new StableBTreeMap<Principal, User>(0);
recordings = new StableBTreeMap<Principal, Recording>(1);

@update([IDL.Text], User)
createUser(username: string): User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from 'azle/canisters/management';

export default class {
stableStorage = StableBTreeMap<string, string>(0);
stableStorage = new StableBTreeMap<string, string>(0);

@init([IDL.Text])
init(ethereumUrl: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const NullFunc = IDL.Func(
type NullFunc = Func;

export default class {
stableStorage = StableBTreeMap<string, StableFunc>(0);
stableStorage = new StableBTreeMap<string, StableFunc>(0);

@init([])
init(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type HttpResponse = {
};

export default class {
stableStorage = StableBTreeMap<string, bigint>(0);
stableStorage = new StableBTreeMap<string, bigint>(0);

@init([])
init(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'azle';

export default class {
stableStorage = StableBTreeMap<string, bigint>(0);
stableStorage = new StableBTreeMap<string, bigint>(0);
redeployed = false;

@init([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Entry = {
};

export default class {
stableStorage = StableBTreeMap<string, Entry[]>(0);
stableStorage = new StableBTreeMap<string, Entry[]>(0);

entries: {
[key: string]: bigint;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ type LargeRecord = {
};

export default class {
smallRecordMap = StableBTreeMap<string, SmallRecord>(0);
mediumRecordMap = StableBTreeMap<string, MediumRecord>(1);
largeRecordMap = StableBTreeMap<string, LargeRecord>(2);
smallRecordMap = new StableBTreeMap<string, SmallRecord>(0);
mediumRecordMap = new StableBTreeMap<string, MediumRecord>(1);
largeRecordMap = new StableBTreeMap<string, LargeRecord>(2);

@update([IDL.Nat32])
insertSmallRecord(numToInsert: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { IDL, query, StableBTreeMap, update } from 'azle';
import { Reaction, User } from '../types';

export default class {
stableMap0 = StableBTreeMap<number, string>(0);
stableMap1 = StableBTreeMap<number, Uint8Array>(1);
stableMap2 = StableBTreeMap<number, bigint>(2);
stableMap3 = StableBTreeMap<Reaction, bigint>(3);
stableMap4 = StableBTreeMap<User, number>(4);
stableMap0 = new StableBTreeMap<number, string>(0);
stableMap1 = new StableBTreeMap<number, Uint8Array>(1);
stableMap2 = new StableBTreeMap<number, bigint>(2);
stableMap3 = new StableBTreeMap<Reaction, bigint>(3);
stableMap4 = new StableBTreeMap<User, number>(4);

@query([], IDL.Bool)
getRedeployed(): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IDL, query, StableBTreeMap, update } from 'azle';

export default class {
stableMap5 = StableBTreeMap<[string] | [], number>(5);
stableMap6 = StableBTreeMap<bigint[], boolean>(6);
stableMap7 = StableBTreeMap<null, null>(7);
stableMap8 = StableBTreeMap<boolean, null>(8);
stableMap9 = StableBTreeMap<number, string[]>(9);
stableMap5 = new StableBTreeMap<[string] | [], number>(5);
stableMap6 = new StableBTreeMap<bigint[], boolean>(6);
stableMap7 = new StableBTreeMap<null, null>(7);
stableMap8 = new StableBTreeMap<boolean, null>(8);
stableMap9 = new StableBTreeMap<number, string[]>(9);

@query([], IDL.Bool)
getRedeployed(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { IDL, Principal, query, StableBTreeMap, update } from 'azle';
import { Callback, Reaction, User } from '../types';

export default class {
stableMap10 = StableBTreeMap<number, [boolean] | []>(10);
stableMap11 = StableBTreeMap<bigint, User>(11);
stableMap12 = StableBTreeMap<Uint8Array, Reaction>(12);
stableMap13 = StableBTreeMap<string, Principal>(13);
stableMap14 = StableBTreeMap<string, Callback>(14);
stableMap15 = StableBTreeMap<Callback, string>(15);
stableMap16 = StableBTreeMap<string, object>(16);
stableMap17 = StableBTreeMap<object, string>(17);
stableMap10 = new StableBTreeMap<number, [boolean] | []>(10);
stableMap11 = new StableBTreeMap<bigint, User>(11);
stableMap12 = new StableBTreeMap<Uint8Array, Reaction>(12);
stableMap13 = new StableBTreeMap<string, Principal>(13);
stableMap14 = new StableBTreeMap<string, Callback>(14);
stableMap15 = new StableBTreeMap<Callback, string>(15);
stableMap16 = new StableBTreeMap<string, object>(16);
stableMap17 = new StableBTreeMap<object, string>(17);

@query([], IDL.Bool)
getRedeployed(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const CanisterConfigArb = fc
> => {
const globalDeclarations = [
/*TS*/ `const PRE_UPGRADE_HOOK_EXECUTED = 'PRE_UPGRADE_HOOK_EXECUTED';`,
/*TS*/ `let stable = StableBTreeMap<string, boolean>(0);`
/*TS*/ `let stable = new StableBTreeMap<string, boolean>(0);`
];

return {
Expand Down
2 changes: 1 addition & 1 deletion examples/stable/test/property/ic_api/caller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AssertType, NotAnyAndExact } from 'azle/type_tests/assert_type';
export default class {
initCaller: Principal | null = null;
postUpgradeCaller: Principal | null = null;
preUpgradeCaller = StableBTreeMap<'PRE_UPGRADE_CALLER', Principal>(0);
preUpgradeCaller = new StableBTreeMap<'PRE_UPGRADE_CALLER', Principal>(0);
inspectMessageCaller: Principal | null = null;

@init([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import { AssertType, NotAnyAndExact } from 'azle/type_tests/assert_type';
export default class {
initCanisterVersion: bigint | null = null;
postUpgradeCanisterVersion: bigint | null = null;
preUpgradeCanisterVersion = StableBTreeMap<'PRE_UPGRADE_VERSION', bigint>(
0
);
preUpgradeCanisterVersion = new StableBTreeMap<
'PRE_UPGRADE_VERSION',
bigint
>(0);
inspectMessageCanisterVersion: bigint | null = null;
meaninglessState: bigint = 0n;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const PRE_UPGRADE_DATA = new Uint8Array([

export default class {
data: Uint8Array = new Uint8Array();
stableStorage = StableBTreeMap<string, boolean>(0);
stableStorage = new StableBTreeMap<string, boolean>(0);
afterFirstPostUpgrade = false;

@init([IDL.Bool, IDL.Vec(IDL.Nat8)])
Expand Down
2 changes: 1 addition & 1 deletion examples/stable/test/property/ic_api/id/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AssertType, NotAnyAndExact } from 'azle/type_tests/assert_type';
export default class {
initId: Principal | null = null;
postUpgradeId: Principal | null = null;
preUpgradeId = StableBTreeMap<'PRE_UPGRADE_ID', Principal>(0);
preUpgradeId = new StableBTreeMap<'PRE_UPGRADE_ID', Principal>(0);
inspectMessageId: Principal | null = null;

@init([])
Expand Down
Loading

0 comments on commit 6a4d21d

Please sign in to comment.