Skip to content

Commit

Permalink
refactor list of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Sep 25, 2023
1 parent 09b6cbf commit 650af54
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 533 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
# "examples/complex_types",
# "examples/func_types",
# "examples/generics",
# "examples/key_value_store",
# "examples/ledger_canister",
# "examples/list_of_lists",
# "examples/management_canister",
# "examples/manual_reply",
# "examples/motoko_examples/calc",
Expand Down Expand Up @@ -113,6 +111,8 @@ jobs:
"examples/init",
"examples/imports",
"examples/inspect_message",
"examples/key_value_store",
"examples/list_of_lists",
"examples/primitive_types",
"examples/principal",
"examples/query",
Expand Down
3 changes: 2 additions & 1 deletion examples/list_of_lists/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"root": "src",
"ts": "src/index.ts",
"candid": "src/index.did",
"wasm": ".azle/list_of_lists/list_of_lists.wasm.gz",
"wasm": ".azle/list_of_lists/list_of_lists.wasm",
"gzip": true,
"declarations": {
"output": "dfx_generated/list_of_lists",
"node_compatibility": true
Expand Down
481 changes: 124 additions & 357 deletions examples/list_of_lists/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/list_of_lists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"azle": "0.17.1"
},
"devDependencies": {
"@dfinity/agent": "0.14.1",
"fast-equals": "4.0.3",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"@dfinity/agent": "^0.19.2",
"fast-equals": "^5.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
}
309 changes: 147 additions & 162 deletions examples/list_of_lists/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
blob,
bool,
candid,
empty,
float32,
float64,
Func,
func,
int,
int16,
int32,
Expand All @@ -20,7 +18,6 @@ import {
Null,
Opt,
principal,
Principal,
query,
Record,
reserved,
Expand All @@ -30,48 +27,34 @@ import {
Vec
} from 'azle';

class Person extends Record {
@candid(text)
name: text;
const Person = Record({
name: text,
age: nat8
});

@candid(nat8)
age: nat8;
}
const State = Variant({
solid: Null,
liquid: Null,
gas: Null
});

class State extends Variant {
@candid(Null)
solid: Null;
const BasicFunc = Func([text], text, 'query');

@candid(Null)
liquid: Null;

@candid(Null)
gas: Null;
}

@func([text], text, 'query')
class BasicFunc extends Func {}

export default class extends Service {
@query([Vec(text)], Vec(text))
listOfStringOne(param: Vec<text>): Vec<text> {
export default Service({
listOfStringOne: query([Vec(text)], Vec(text), (param) => {
return param;
}

@query([Vec(Vec(text))], Vec(Vec(text)))
listOfStringTwo(params: Vec<Vec<text>>): Vec<Vec<text>> {
}),
listOfStringTwo: query([Vec(Vec(text))], Vec(Vec(text)), (params) => {
return params;
}

@query([Vec(Vec(Vec(Vec(text))))], Vec(Vec(Vec(Vec(text)))))
listOfStringFour(
params: Vec<Vec<Vec<Vec<text>>>>
): Vec<Vec<Vec<Vec<text>>>> {
return params;
}

@query([], Vec(Vec(Vec(Vec(Vec(Vec(Vec(int8))))))))
listOfListOfInt8(): Vec<Vec<Vec<Vec<Vec<Vec<Vec<int8>>>>>>> {
}),
listOfStringFour: query(
[Vec(Vec(Vec(Vec(text))))],
Vec(Vec(Vec(Vec(text)))),
(params) => {
return params;
}
),
listOfListOfInt8: query([], Vec(Vec(Vec(Vec(Vec(Vec(Vec(int8))))))), () => {
return [
[
[
Expand All @@ -93,133 +76,135 @@ export default class extends Service {
[[[[[3]]]], [[[[4]]]]]
]
];
}

@query([Vec(Vec(Vec(Null)))], Vec(Vec(Vec(Null))))
listOfNull(param: Vec<Vec<Vec<null>>>): Vec<Vec<Vec<null>>> {
return param;
}

@query([Vec(Vec(Vec(bool)))], Vec(Vec(Vec(bool))))
listOfBool(param: Vec<Vec<Vec<bool>>>): Vec<Vec<Vec<bool>>> {
return param;
}

@query([Vec(Vec(Vec(text)))], Vec(Vec(Vec(text))))
listOfString(param: Vec<Vec<Vec<text>>>): Vec<Vec<Vec<text>>> {
return param;
}

@query([Vec(Vec(Vec(Opt(text))))], Vec(Vec(Vec(Opt(text)))))
listOfOptionString(
param: Vec<Vec<Vec<Opt<text>>>>
): Vec<Vec<Vec<Opt<text>>>> {
return param;
}

@query([], Vec(Vec(Vec(empty))))
listOfEmpty(): Vec<Vec<Vec<empty>>> {
}),
listOfNull: query([Vec(Vec(Vec(Null)))], Vec(Vec(Vec(Null))), (param) => {
return param;
}),
listOfBool: query([Vec(Vec(Vec(bool)))], Vec(Vec(Vec(bool))), (param) => {
return param;
}),
listOfString: query([Vec(Vec(Vec(text)))], Vec(Vec(Vec(text))), (param) => {
return param;
}),
listOfOptionString: query(
[Vec(Vec(Vec(Opt(text))))],
Vec(Vec(Vec(Opt(text)))),
(param) => {
return param;
}
),
listOfEmpty: query([], Vec(Vec(Vec(empty))), () => {
throw new Error('Anything you want');
}

@query([], Vec(Vec(Vec(reserved))))
listOfReserved(): Vec<Vec<Vec<reserved>>> {
}),
listOfReserved: query([], Vec(Vec(Vec(reserved))), () => {
return [
[['A'], ['n']],
[
['y', 't', 'h'],
['i', 'n', 'g']
]
];
}

@query([Vec(Vec(Vec(BasicFunc)))], Vec(Vec(Vec(BasicFunc))))
listOfFunc(param: Vec<Vec<Vec<BasicFunc>>>): Vec<Vec<Vec<BasicFunc>>> {
return param;
}

@query([Vec(Vec(Vec(principal)))], Vec(Vec(Vec(principal))))
listOfPrincipal(param: Vec<Vec<Vec<Principal>>>): Vec<Vec<Vec<Principal>>> {
return param;
}

@query([Vec(Vec(Vec(float64)))], Vec(Vec(Vec(float64))))
listOfF64(param: Vec<Vec<Vec<float64>>>): Vec<Vec<Vec<float64>>> {
return param;
}

@query([Vec(Vec(Vec(float32)))], Vec(Vec(Vec(float32))))
listOfF32(param: Vec<Vec<Vec<float32>>>): Vec<Vec<Vec<float32>>> {
return param;
}

@query([Vec(Vec(Vec(int)))], Vec(Vec(Vec(int))))
listOfInt(param: Vec<Vec<Vec<int>>>): Vec<Vec<Vec<int>>> {
return param;
}

@query([Vec(Vec(Vec(int64)))], Vec(Vec(Vec(int64))))
listOfInt64(param: Vec<Vec<Vec<int64>>>): Vec<Vec<Vec<int64>>> {
return param;
}

@query([Vec(Vec(Vec(int32)))], Vec(Vec(Vec(int32))))
listOfInt32(param: Vec<Vec<Vec<int32>>>): Vec<Vec<Vec<int32>>> {
return param;
}

@query([Vec(Vec(Vec(int16)))], Vec(Vec(Vec(int16))))
listOfInt16(param: Vec<Vec<Vec<int16>>>): Vec<Vec<Vec<int16>>> {
return param;
}

@query([Vec(Vec(Vec(int8)))], Vec(Vec(Vec(int8))))
listOfInt8(param: Vec<Vec<Vec<int8>>>): Vec<Vec<Vec<int8>>> {
return param;
}

@query([Vec(Vec(Vec(nat)))], Vec(Vec(Vec(nat))))
listOfNat(param: Vec<Vec<Vec<nat>>>): Vec<Vec<Vec<nat>>> {
return param;
}

@query([Vec(Vec(Vec(nat64)))], Vec(Vec(Vec(nat64))))
listOfNat64(param: Vec<Vec<Vec<nat64>>>): Vec<Vec<Vec<nat64>>> {
return param;
}

@query([Vec(Vec(Vec(nat32)))], Vec(Vec(Vec(nat32))))
listOfNat32(param: Vec<Vec<Vec<nat32>>>): Vec<Vec<Vec<nat32>>> {
return param;
}

@query([Vec(Vec(Vec(nat16)))], Vec(Vec(Vec(nat16))))
listOfNat16(param: Vec<Vec<Vec<nat16>>>): Vec<Vec<Vec<nat16>>> {
return param;
}

@query([Vec(Vec(Vec(nat8)))], Vec(Vec(Vec(nat8))))
listOfNat8(param: Vec<Vec<Vec<nat8>>>): Vec<Vec<Vec<nat8>>> {
return param;
}

@query([Vec(Vec(Vec(Person)))], Vec(Vec(Vec(Person))))
listOfRecord(param: Vec<Vec<Vec<Person>>>): Vec<Vec<Vec<Person>>> {
return param;
}

@query([Vec(Vec(Vec(State)))], Vec(Vec(Vec(State))))
listOfVariant(param: Vec<Vec<Vec<State>>>): Vec<Vec<Vec<State>>> {
return param;
}

@query([Vec(blob)], Vec(blob))
listOfBlob(param: Vec<blob>): Vec<blob> {
return param;
}

@query([Vec(Vec(blob))], Vec(Vec(blob)))
listOfListOfBlob(param: Vec<Vec<blob>>): Vec<Vec<blob>> {
return param;
}
}
}),
listOfFunc: query(
[Vec(Vec(Vec(BasicFunc)))],
Vec(Vec(Vec(BasicFunc))),
(param) => {
return param;
}
),
listOfPrincipal: query(
[Vec(Vec(Vec(principal)))],
Vec(Vec(Vec(principal))),
(param) => {
return param;
}
),
listOfF64: query(
[Vec(Vec(Vec(float64)))],
Vec(Vec(Vec(float64))),
(param) => {
return param;
}
),
listOfF32: query(
[Vec(Vec(Vec(float32)))],
Vec(Vec(Vec(float32))),
(param) => {
return param;
}
),
listOfInt: query([Vec(Vec(Vec(int)))], Vec(Vec(Vec(int))), (param) => {
return param;
}),
listOfInt64: query(
[Vec(Vec(Vec(int64)))],
Vec(Vec(Vec(int64))),
(param) => {
return param;
}
),
listOfInt32: query(
[Vec(Vec(Vec(int32)))],
Vec(Vec(Vec(int32))),
(param) => {
return param;
}
),
listOfInt16: query(
[Vec(Vec(Vec(int16)))],
Vec(Vec(Vec(int16))),
(param) => {
return param;
}
),
listOfInt8: query([Vec(Vec(Vec(int8)))], Vec(Vec(Vec(int8))), (param) => {
return param;
}),
listOfNat: query([Vec(Vec(Vec(nat)))], Vec(Vec(Vec(nat))), (param) => {
return param;
}),
listOfNat64: query(
[Vec(Vec(Vec(nat64)))],
Vec(Vec(Vec(nat64))),
(param) => {
return param;
}
),
listOfNat32: query(
[Vec(Vec(Vec(nat32)))],
Vec(Vec(Vec(nat32))),
(param) => {
return param;
}
),
listOfNat16: query(
[Vec(Vec(Vec(nat16)))],
Vec(Vec(Vec(nat16))),
(param) => {
return param;
}
),
listOfNat8: query([Vec(Vec(Vec(nat8)))], Vec(Vec(Vec(nat8))), (param) => {
return param;
}),
listOfRecord: query(
[Vec(Vec(Vec(Person)))],
Vec(Vec(Vec(Person))),
(param) => {
return param;
}
),
listOfVariant: query(
[Vec(Vec(Vec(State)))],
Vec(Vec(Vec(State))),
(param) => {
return param;
}
),
listOfBlob: query([Vec(blob)], Vec(blob), (param) => {
return param;
}),
listOfListOfBlob: query([Vec(Vec(blob))], Vec(Vec(blob)), (param) => {
return param;
})
});
Loading

0 comments on commit 650af54

Please sign in to comment.