diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2807bc8f10..1b6932397f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,6 @@ # "examples/generics", # "examples/motoko_examples/superheroes", # blocked by recursive # "examples/motoko_examples/whoami", # blocked by postUpgrade -# "examples/optional_types", # "examples/outgoing_http_requests", # "examples/rejections", # "examples/robust_imports", @@ -111,6 +110,7 @@ jobs: "examples/motoko_examples/threshold_ecdsa", "examples/notify_raw", "examples/null_example", + "examples/optional_types", "examples/pre_and_post_upgrade", "examples/primitive_types", "examples/principal", diff --git a/examples/optional_types/dfx.json b/examples/optional_types/dfx.json index 7846397f0c..172f936b5c 100644 --- a/examples/optional_types/dfx.json +++ b/examples/optional_types/dfx.json @@ -6,7 +6,8 @@ "root": "src", "ts": "src/index.ts", "candid": "src/index.did", - "wasm": ".azle/optional_types/optional_types.wasm.gz", + "wasm": ".azle/optional_types/optional_types.wasm", + "gzip": true, "declarations": { "output": "test/dfx_generated/optional_types", "node_compatibility": true diff --git a/examples/optional_types/src/index.ts b/examples/optional_types/src/index.ts index 80415991dd..780a4a91cb 100644 --- a/examples/optional_types/src/index.ts +++ b/examples/optional_types/src/index.ts @@ -1,72 +1,62 @@ // TODO let's add more examples here, really test it out -import { Opt, query, Record, Vec, text, bool, candid, Null } from 'azle'; +import { bool, Null, Opt, query, Record, Service, text, Vec } from 'azle'; -class Element extends Record { - @candid(text) - id: string; -} +const Element = Record({ + id: text +}); -class Head extends Record { - @candid(Vec(Element)) - elements: Vec; -} +const Head = Record({ + elements: Vec(Element) +}); -class Html extends Record { - @candid(Opt(Head)) - head: Opt; -} +const Html = Record({ + head: Opt(Head) +}); -export default class { - @query([], Html) - getHtml(): Html { - return Html.create({ +export default Service({ + getHtml: query([], Html, () => { + return { head: [] - }); - } + }; + }), - @query([], Opt(Head)) - getHead(): Opt { + getHead: query([], Opt(Head), () => { return [ - Head.create({ + { elements: [] - }) + } ]; - } + }), - @query([], Opt(Head)) - getHeadWithElements(): Opt { + getHeadWithElements: query([], Opt(Head), () => { return [ - Head.create({ + { elements: [ { id: '0' } ] - }) + } ]; - } + }), - @query([Opt(Opt(Element))], Opt(Opt(Element))) - getElement(element: Opt>): Opt> { + getElement: query([Opt(Opt(Element))], Opt(Opt(Element)), (element) => { return element; - } + }), - @query([], Null) - getNull(): Null { + getNull: query([], Null, () => { return null; - } + }), - @query([], Opt(text)) - getOptNull(): Opt { + getOptNull: query([], Opt(text), () => { return []; - } + }), - @query([Opt(text)], bool) - stringToBoolean(optString: Opt): boolean { + stringToBoolean: query([Opt(text)], bool, (optString) => { if (optString.length > 0) { return true; } return false; - } -} + }) +});