Skip to content

Commit

Permalink
remove candid from stable structures
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jul 15, 2024
1 parent 4326a9c commit 0ca016f
Show file tree
Hide file tree
Showing 24 changed files with 2,058 additions and 149 deletions.
688 changes: 685 additions & 3 deletions examples/stable_structures/package-lock.json

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister1/stable_map_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
bool,
nat8,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
text,
Tuple,
Expand All @@ -18,10 +20,20 @@ export const stableMap0Methods = {
return stableMap0.containsKey(key);
}),
stableMap0Get: query([nat8], Opt(text), (key) => {
return stableMap0.get(key);
const result = stableMap0.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap0Insert: update([nat8, text], Opt(text), (key, value) => {
return stableMap0.insert(key, value);
const result = stableMap0.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap0IsEmpty: query([], bool, () => {
return stableMap0.isEmpty();
Expand All @@ -36,7 +48,12 @@ export const stableMap0Methods = {
return stableMap0.len();
}),
stableMap0Remove: update([nat8], Opt(text), (key) => {
return stableMap0.remove(key);
const result = stableMap0.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap0Values: query([], Vec(text), () => {
return stableMap0.values();
Expand Down
23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister1/stable_map_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
bool,
nat16,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
Tuple,
update,
Expand All @@ -18,10 +20,20 @@ export const stableMap1Methods = {
return stableMap1.containsKey(key);
}),
stableMap1Get: query([nat16], Opt(blob), (key) => {
return stableMap1.get(key);
const result = stableMap1.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap1Insert: update([nat16, blob], Opt(blob), (key, value) => {
return stableMap1.insert(key, value);
const result = stableMap1.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap1IsEmpty: query([], bool, () => {
return stableMap1.isEmpty();
Expand All @@ -36,7 +48,12 @@ export const stableMap1Methods = {
return stableMap1.len();
}),
stableMap1Remove: update([nat16], Opt(blob), (key) => {
return stableMap1.remove(key);
const result = stableMap1.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap1Values: query([], Vec(blob), () => {
return stableMap1.values();
Expand Down
23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister1/stable_map_2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
nat,
nat32,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
Tuple,
update,
Expand All @@ -18,10 +20,20 @@ export const stableMap2Methods = {
return stableMap2.containsKey(key);
}),
stableMap2Get: query([nat32], Opt(nat), (key) => {
return stableMap2.get(key);
const result = stableMap2.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap2Insert: update([nat32, nat], Opt(nat), (key, value) => {
return stableMap2.insert(key, value);
const result = stableMap2.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap2IsEmpty: query([], bool, () => {
return stableMap2.isEmpty();
Expand All @@ -36,7 +48,12 @@ export const stableMap2Methods = {
return stableMap2.len();
}),
stableMap2Remove: update([nat32], Opt(nat), (key) => {
return stableMap2.remove(key);
const result = stableMap2.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap2Values: query([], Vec(nat), () => {
return stableMap2.values();
Expand Down
23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister1/stable_map_3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
bool,
int,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
Tuple,
update,
Expand All @@ -19,10 +21,20 @@ export const stableMap3Methods = {
return stableMap3.containsKey(key);
}),
stableMap3Get: query([Reaction], Opt(int), (key) => {
return stableMap3.get(key);
const result = stableMap3.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap3Insert: update([Reaction, int], Opt(int), (key, value) => {
return stableMap3.insert(key, value);
const result = stableMap3.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap3IsEmpty: query([], bool, () => {
return stableMap3.isEmpty();
Expand All @@ -37,7 +49,12 @@ export const stableMap3Methods = {
return stableMap3.len();
}),
stableMap3Remove: update([Reaction], Opt(int), (key) => {
return stableMap3.remove(key);
const result = stableMap3.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap3Values: query([], Vec(int), () => {
return stableMap3.values();
Expand Down
23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister1/stable_map_4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
bool,
float32,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
Tuple,
update,
Expand All @@ -19,10 +21,20 @@ export const stableMap4Methods = {
return stableMap4.containsKey(key);
}),
stableMap4Get: query([User], Opt(float32), (key) => {
return stableMap4.get(key);
const result = stableMap4.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap4Insert: update([User, float32], Opt(float32), (key, value) => {
return stableMap4.insert(key, value);
const result = stableMap4.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap4IsEmpty: query([], bool, () => {
return stableMap4.isEmpty();
Expand All @@ -37,7 +49,12 @@ export const stableMap4Methods = {
return stableMap4.len();
}),
stableMap4Remove: update([User], Opt(float32), (key) => {
return stableMap4.remove(key);
const result = stableMap4.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap4Values: query([], Vec(float32), () => {
return stableMap4.values();
Expand Down
23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister2/stable_map_5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
bool,
float64,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
text,
Tuple,
Expand All @@ -18,13 +20,23 @@ export const stableMap5Methods = {
return stableMap5.containsKey(key);
}),
stableMap5Get: query([Opt(text)], Opt(float64), (key) => {
return stableMap5.get(key);
const result = stableMap5.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap5Insert: update(
[Opt(text), float64],
Opt(float64),
(key, value) => {
return stableMap5.insert(key, value);
const result = stableMap5.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}
),
stableMap5IsEmpty: query([], bool, () => {
Expand All @@ -40,7 +52,12 @@ export const stableMap5Methods = {
return stableMap5.len();
}),
stableMap5Remove: update([Opt(text)], Opt(float64), (key) => {
return stableMap5.remove(key);
const result = stableMap5.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap5Values: query([], Vec(float64), () => {
return stableMap5.values();
Expand Down
23 changes: 20 additions & 3 deletions examples/stable_structures/src/canister2/stable_map_6.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
bool,
nat64,
None,
Opt,
query,
Some,
StableBTreeMap,
Tuple,
update,
Expand All @@ -16,10 +18,20 @@ export const stableMap6Methods = {
return stableMap6.containsKey(key);
}),
stableMap6Get: query([Vec(nat64)], Opt(bool), (key) => {
return stableMap6.get(key);
const result = stableMap6.get(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap6Insert: update([Vec(nat64), bool], Opt(bool), (key, value) => {
return stableMap6.insert(key, value);
const result = stableMap6.insert(key, value);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap6IsEmpty: query([], bool, () => {
return stableMap6.isEmpty();
Expand All @@ -34,7 +46,12 @@ export const stableMap6Methods = {
return stableMap6.len();
}),
stableMap6Remove: update([Vec(nat64)], Opt(bool), (key) => {
return stableMap6.remove(key);
const result = stableMap6.remove(key);
if (result === null) {
return None;
} else {
return Some(result);
}
}),
stableMap6Values: query([], Vec(bool), () => {
return stableMap6.values();
Expand Down
25 changes: 22 additions & 3 deletions examples/stable_structures/src/canister2/stable_map_7.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
bool,
nat64,
None,
Null,
Opt,
query,
Some,
StableBTreeMap,
Tuple,
update,
Expand All @@ -17,10 +19,21 @@ export const stableMap7Methods = {
return stableMap7.containsKey(key);
}),
stableMap7Get: query([Null], Opt(Null), (key) => {
return stableMap7.get(key);
const result = stableMap7.get(key);
if (stableMap7.containsKey(key)) {
return Some(result);
} else {
return None;
}
}),
stableMap7Insert: update([Null, Null], Opt(Null), (key, value) => {
return stableMap7.insert(key, value);
const hasOldValue = stableMap7.containsKey(key);
const result = stableMap7.insert(key, value);
if (hasOldValue) {
return Some(result);
} else {
return None;
}
}),
stableMap7IsEmpty: query([], bool, () => {
return stableMap7.isEmpty();
Expand All @@ -35,7 +48,13 @@ export const stableMap7Methods = {
return stableMap7.len();
}),
stableMap7Remove: update([Null], Opt(Null), (key) => {
return stableMap7.remove(key);
const hasOldValue = stableMap7.containsKey(key);
const result = stableMap7.remove(key);
if (hasOldValue) {
return Some(result);
} else {
return None;
}
}),
stableMap7Values: query([], Vec(Null), () => {
return stableMap7.values();
Expand Down
Loading

0 comments on commit 0ca016f

Please sign in to comment.