diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a28f3c936d..d9ee7a2465 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,6 @@ # "examples/func_types", # "examples/generics", # "examples/motoko_examples/superheroes", # blocked by recursive -# "examples/robust_imports", # "examples/run_time_errors", # "examples/tuple_types", @@ -83,8 +82,8 @@ jobs: "examples/guard_functions", "examples/heartbeat", "examples/ic_api", - "examples/init", "examples/imports", + "examples/init", "examples/inspect_message", "examples/key_value_store", "examples/ledger_canister", @@ -115,6 +114,7 @@ jobs: "examples/query", "examples/randomness", "examples/rejections", + "examples/robust_imports", "examples/service", "examples/simple_erc20", "examples/simple_user_accounts", diff --git a/examples/robust_imports/dfx.json b/examples/robust_imports/dfx.json index 489d439660..80c639f3ec 100644 --- a/examples/robust_imports/dfx.json +++ b/examples/robust_imports/dfx.json @@ -6,12 +6,12 @@ "root": "src", "ts": "src/index.ts", "candid": "src/index.did", - "wasm": ".azle/robust_imports/robust_imports.wasm.gz", + "wasm": ".azle/robust_imports/robust_imports.wasm", + "gzip": true, "declarations": { "output": "dfx_generated/robust_imports", "node_compatibility": true - }, - "opt_level": "1" + } } } } diff --git a/examples/robust_imports/src/azle_coverage/fruit.ts b/examples/robust_imports/src/azle_coverage/fruit.ts index 37223b804b..698b7013d6 100644 --- a/examples/robust_imports/src/azle_coverage/fruit.ts +++ b/examples/robust_imports/src/azle_coverage/fruit.ts @@ -1,18 +1,16 @@ -import { $query as $kiwi, Alias } from 'azle'; -export default $kiwi; +import { query as kiwi } from 'azle'; +export default kiwi; export { - Alias as Apple, + bool as blackberry, blob as banana, - CallResult as Cherry, empty as elderberry, float32 as fig32, float64 as fig64, Func as Farkleberry, - GuardResult as Grapes, - $heartbeat as $honeydew, - $init as $icaco, - $inspectMessage as $ilama, + heartbeat as honeydew, + init as icaco, + inspectMessage as ilama, int as iceApple, int8 as iceApple8, int16 as iceApple16, @@ -24,26 +22,21 @@ export { nat16 as nectarine16, nat32 as nectarine32, nat64 as nectarine64, - Oneway as Orange, + Null as Nutmeg, Opt as Olive, - $postUpgrade as $pomegranate, - $preUpgrade as $pineapple, + postUpgrade as pomegranate, + preUpgrade as pineapple, + principal as peach, Principal as Peach, - $query as $quince, - Query as Quince, + query as quince, Record as Raspberry, reserved as rambutan, Service as Strawberry, - serviceQuery as santol, - serviceUpdate as sapodilla, StableBTreeMap as Soncoya, text as tangerine, Tuple as Tamarind, - $update as $ugni, - Update as Ugni, + update as ugni, Variant as Voavanga, - Vec as Lime + Vec as Lime, + Void as Vanilla } from 'azle'; -export type blackberry = boolean; -export type nutmeg = null; -export type vanilla = void; diff --git a/examples/robust_imports/src/azle_coverage/index.ts b/examples/robust_imports/src/azle_coverage/index.ts index 0ebee8269d..2a5b2d992f 100644 --- a/examples/robust_imports/src/azle_coverage/index.ts +++ b/examples/robust_imports/src/azle_coverage/index.ts @@ -1,15 +1,13 @@ -import $kiwi, { +import kiwi, { banana, blackberry, - Cherry, elderberry, fig32, fig64, Farkleberry, - Grapes, - $honeydew, - $icaco, - $ilama, + honeydew, + icaco, + ilama, iceApple, iceApple8, iceApple16, @@ -21,107 +19,96 @@ import $kiwi, { nectarine16, nectarine32, nectarine64, - nutmeg, - Orange, + Nutmeg, Olive, - $pomegranate, - $pineapple, + pomegranate, + pineapple, + peach, Peach, - $quince, - Quince, + quince, Raspberry, rambutan, Strawberry, - santol, - sapodilla, Soncoya, tangerine, Tamarind, - $ugni, - Ugni, + ugni, Voavanga, Lime, - vanilla + Vanilla } from './fruit'; -import { match as marionberry, ic as lemon, int16 as coconut } from 'azle'; +import { ic as lemon, int16 as coconut } from 'azle'; import * as starFruit from './fruit'; -class FruitDeliveryService extends Strawberry { - @sapodilla - deliver: () => Cherry; - - @santol - is_delivered: () => Cherry; -} - -export type PreparedFruit = Raspberry<{ - honeydewCount: nectarine16; - areIcacosCollected: boysenberry; - isPineappleCut: boysenberry; - arePomegranateArilsSeparated: boysenberry; - areGrapesGathered: boysenberry; - isIlamaWashed: boysenberry; - areRambutanSkinsRemoved: boysenberry; - haveElderberriesBeenPicked: boysenberry; -}>; - -type OrangeAndFarkleberry = Farkleberry void>>; -type QuinceAndFarkleberry = Farkleberry< - Quince<(param1: tangerine) => tangerine> ->; -type UgniAndFarkleberry = Farkleberry tangerine>>; - -type TamarindAndFarkleberry = Tamarind< - [UgniAndFarkleberry, OrangeAndFarkleberry, QuinceAndFarkleberry] ->; - -export type NectarineBasket = Raspberry<{ - nat: nectarine; - nat8: nectarine8; - nat16: nectarine16; - nat32: nectarine32; - nat64: nectarine64; - starNat: starFruit.nectarine; -}>; - -export type IceAppleBasket = Raspberry<{ - int: iceApple; - int8: iceApple8; - int16: iceApple16; - int32: iceApple32; - int64: iceApple64; - starInt: starFruit.iceApple; -}>; - -export type boysenberry = boolean; - -export type Watermelon = Voavanga<{ - Seeds: nutmeg; - Seedless: nutmeg; -}>; - -let soncoya = new Soncoya(0, 10, 1_000); - -function gatherGrapes(): Grapes { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - areGrapesGathered: true - }); - }, - None: () => {} - }); - return { - Ok: null - }; +const FruitDeliveryService = Strawberry({ + deliver: ugni([], tangerine), + is_delivered: quince([], blackberry) +}); + +export const boysenberry = blackberry; + +export const PreparedFruit = Raspberry({ + honeydewCount: nectarine16, + areIcacosCollected: boysenberry, + isPineappleCut: boysenberry, + arePomegranateArilsSeparated: boysenberry, + areGrapesGathered: boysenberry, + isIlamaWashed: boysenberry, + areRambutanSkinsRemoved: boysenberry, + haveElderberriesBeenPicked: boysenberry +}); + +const OrangeAndFarkleberry = Farkleberry([tangerine], Vanilla, 'oneway'); +const QuinceAndFarkleberry = Farkleberry([tangerine], tangerine, 'query'); +const UgniAndFarkleberry = Farkleberry([tangerine], tangerine, 'update'); + +const TamarindAndFarkleberry = Tamarind( + UgniAndFarkleberry, + OrangeAndFarkleberry, + QuinceAndFarkleberry +); + +export const NectarineBasket = Raspberry({ + nat: nectarine, + nat8: nectarine8, + nat16: nectarine16, + nat32: nectarine32, + nat64: nectarine64, + starNat: starFruit.nectarine +}); + +export const IceAppleBasket = Raspberry({ + int: iceApple, + int8: iceApple8, + int16: iceApple16, + int32: iceApple32, + int64: iceApple64, + starInt: starFruit.iceApple +}); + +export const Watermelon = Voavanga({ + Seeds: Nutmeg, + Seedless: Nutmeg +}); + +let soncoya = Soncoya(nectarine8, PreparedFruit, 0); + +function gatherGrapes() { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + areGrapesGathered: true + }); + } } -$icaco; -export function collectIcaco(): void { - let preparedFruit: PreparedFruit = { +export const collectIcaco = icaco([], () => { + const preparedFruit: typeof PreparedFruit = { honeydewCount: 0, areIcacosCollected: true, isPineappleCut: false, @@ -133,212 +120,212 @@ export function collectIcaco(): void { }; soncoya.insert(0, preparedFruit); -} - -$pineapple; -export function cutPineapple(): void { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - isPineappleCut: true - }); - }, - None: () => {} - }); -} - -$pomegranate; -export function separateArilsFromPith(): void { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - arePomegranateArilsSeparated: true - }); - }, - None: () => {} - }); -} - -$honeydew; -export function buyHoneydew(): void { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - honeydewCount: preparedFruit.honeydewCount + 1 - }); - }, - None: () => {} - }); -} +}); + +export const cutPineapple = pineapple(() => { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + isPineappleCut: true + }); + } +}); + +export const separateArilsFromPith = pomegranate([], () => { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + arePomegranateArilsSeparated: true + }); + } +}); + +export const buyHoneydew = honeydew(() => { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + honeydewCount: preparedFruit.honeydewCount + 1 + }); + } +}); -$ilama; -export function keepIlamaClean(): void { +export const keepIlamaClean = ilama(() => { console.log(`Method "${lemon.methodName()}" was called`); if (lemon.methodName() === 'dirtyIlama') { return; } lemon.acceptMessage(); -} +}); -$kiwi; -export function addSigFigs(figs: fig32): fig64 { +export const addSigFigs = kiwi([fig32], fig64, (figs) => { return figs; -} +}); -$kiwi; -export function checkService( - service: FruitDeliveryService -): FruitDeliveryService { - return service; -} +export const checkService = kiwi( + [FruitDeliveryService], + FruitDeliveryService, + (service) => { + return service; + } +); -$kiwi; -export function checkWatermelonForSeeds( - shouldHaveSeeds: blackberry, - watermelon: Watermelon -): vanilla { - marionberry(watermelon, { - Seedless: () => { +export const checkWatermelonForSeeds = kiwi( + [blackberry, Watermelon], + Vanilla, + (shouldHaveSeeds, watermelon) => { + if ('Seedless' in watermelon) { if (shouldHaveSeeds) { lemon.trap('Watermelon is seedless when it should have seeds'); } - }, - Seeds: () => { + } + if ('Seeds' in watermelon) { if (!shouldHaveSeeds) { lemon.trap( 'Watermelon is has seeds when it should be seedless' ); } } - }); -} - -$kiwi; -export function compareApplesToOranges( - apples: IceAppleBasket, - oranges: NectarineBasket -): boysenberry { - return ( - apples.int === oranges.nat && - apples.int8 === oranges.nat8 && - apples.int16 === oranges.nat16 && - apples.int32 === oranges.nat32 && - apples.int64 === oranges.nat64 && - apples.starInt === oranges.starNat - ); -} + } +); + +export const compareApplesToOranges = kiwi( + [IceAppleBasket, NectarineBasket], + boysenberry, + (apples, oranges) => { + return ( + apples.int === oranges.nat && + apples.int8 === oranges.nat8 && + apples.int16 === oranges.nat16 && + apples.int32 === oranges.nat32 && + apples.int64 === oranges.nat64 && + apples.starInt === oranges.starNat + ); + } +); -$kiwi; -export function handleFarkleberries( - orange: OrangeAndFarkleberry, - quince: QuinceAndFarkleberry, - ugni: UgniAndFarkleberry -): TamarindAndFarkleberry { - return [ugni, orange, quince]; -} +export const handleFarkleberries = kiwi( + [OrangeAndFarkleberry, QuinceAndFarkleberry, UgniAndFarkleberry], + TamarindAndFarkleberry, + (orange, quince, ugni) => { + return [ugni, orange, quince]; + } +); -$kiwi; -export function getManagementPeach(): Peach { +export const getManagementPeach = kiwi([], peach, () => { return Peach.fromText('aaaaa-aa'); -} +}); -$kiwi; -export function pitOlives(olive: Olive): boysenberry { - return marionberry(olive, { - Some: (berry) => { - return berry; - }, - None: () => { - return false; - } - }); -} +export const pitOlives = kiwi([Olive(boysenberry)], boysenberry, (olive) => { + if (olive.length === 0) { + return false; + } + + const berry = olive[0]; + + return berry; +}); -$kiwi; -export function peelBanana(banana: banana): nectarine8 { +export const peelBanana = kiwi([banana], nectarine8, (banana) => { if (banana.length < 1) { return 0; } return banana[0]; -} - -$kiwi; -export function putTheCoconutInTheLime(coconut: coconut): Lime { - return [coconut]; -} +}); -$kiwi; -export function isMangoTrickyToEat(): Mango { - lemon.reply(true); -} - -$quince({ guard: gatherGrapes }); -export function isFruitPrepared(): boysenberry { - return marionberry(soncoya.get(0), { - Some: (pf) => { - return ( - pf.honeydewCount > 0 && - pf.areIcacosCollected && - pf.isPineappleCut && - pf.arePomegranateArilsSeparated && - pf.areGrapesGathered && - pf.isIlamaWashed && - pf.areRambutanSkinsRemoved && - !pf.haveElderberriesBeenPicked - ); - }, - None: () => { +export const putTheCoconutInTheLime = kiwi( + [coconut], + Lime(coconut), + (coconut) => { + return [coconut]; + } +); + +export const isMangoTrickyToEat = kiwi( + [], + Mango(boysenberry), + () => { + lemon.reply(true, blackberry); + }, + { manual: true } +); + +export const isFruitPrepared = quince( + [], + boysenberry, + () => { + const opt = soncoya.get(0); + + if (opt.length === 0) { return false; } - }); -} -$ugni; -export function removeRambutanSkins(): rambutan { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - areRambutanSkinsRemoved: true - }); - }, - None: () => {} - }); - return 'rambutan skins'; -} + const pf = opt[0]; + + return ( + pf.honeydewCount > 0 && + pf.areIcacosCollected && + pf.isPineappleCut && + pf.arePomegranateArilsSeparated && + pf.areGrapesGathered && + pf.isIlamaWashed && + pf.areRambutanSkinsRemoved && + !pf.haveElderberriesBeenPicked + ); + }, + { guard: gatherGrapes } +); + +export const removeRambutanSkins = ugni([], rambutan, () => { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + areRambutanSkinsRemoved: true + }); + } -$ugni; -export function dirtyIlama(): void { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - isIlamaWashed: false - }); - }, - None: () => {} - }); -} + return 'rambutan skins'; +}); + +export const dirtyIlama = ugni([], Vanilla, () => { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + isIlamaWashed: false + }); + } +}); + +export const pickElderberry = ugni([], elderberry, () => { + const opt = soncoya.get(0); + + if (opt.length !== 0) { + const preparedFruit = opt[0]; + soncoya.remove(0); + soncoya.insert(0, { + ...preparedFruit, + haveElderberriesBeenPicked: true + }); + } -$ugni; -export function pickElderberry(): elderberry { - marionberry(soncoya.get(0), { - Some: (preparedFruit) => { - soncoya.remove(0); - soncoya.insert(0, { - ...preparedFruit, - haveElderberriesBeenPicked: true - }); - }, - None: () => {} - }); throw 'All out of elderberries'; -} +}); diff --git a/examples/robust_imports/src/import_coverage/index.ts b/examples/robust_imports/src/import_coverage/index.ts index db6e8e3484..63e0a5bc2b 100644 --- a/examples/robust_imports/src/import_coverage/index.ts +++ b/examples/robust_imports/src/import_coverage/index.ts @@ -1,152 +1,156 @@ -import $icQuery, * as ic from './types'; +import icQuery, * as ic from './types'; import { text, text as mT, text as mDT, text as mCT } from './types'; import dollarSignQuery from './types'; -import query, { int8, int8 as variInt, match } from './types'; -import type { CoveredOpt, CoveredVec, coveredInt16 } from './types'; +import query, { int8, int8 as variInt } from './types'; +import { CoveredOpt, CoveredVec, coveredInt16 } from './types'; -export type MyCavernousRecord = ic.CavernousRecord<{ - coveredRecord: MyCoveredRecord; - myRecord: MyRecord; - fathomlessRecord: MyFathomlessRecord; - myTuple: MyTuple; - myDeepTuple: MyDeepTuple; - myCavernousTuple: MyCavernousTuple; -}>; -export type MyCoveredRecord = ic.CoveredRecord<{ - count: ic.fathomlessStar.DeepInt8; - name: ic.text; - type_name: ic.azle.text; - greeting: ic.FathomlessOpt; -}>; -export type MyRecord = ic.Record<{ - int1: ic.cavernousDefault; - int2: ic.profoundDefault; - int3: ic.bottomlessDefault; - int4: ic.DeepInt8; - int5: ic.FathomlessInt8; - int6: ic.profoundStar.DeepInt8; - int7: ic.FathomlessInt; - int8: ic.ProfoundInt; - int9: ic.fathomlessStar.default; -}>; -export type MyFathomlessRecord = ic.FathomlessRecord<{ - mytext: text; -}>; -export type MyTuple = ic.CoveredTuple<[mT]>; -export type MyDeepTuple = ic.DeepTuple<[mDT]>; -export type MyCavernousTuple = ic.CavernousTuple<[mCT]>; +export const MyCoveredRecord = ic.CoveredRecord({ + count: ic.fathomlessStar.DeepInt8, + name: ic.text, + type_name: ic.azle.text, + greeting: ic.FathomlessOpt(ic.text) +}); +export const MyRecord = ic.Record({ + int1: ic.cavernousDefault, + int2: ic.profoundDefault, + int3: ic.bottomlessDefault, + int4: ic.DeepInt8, + int5: ic.FathomlessInt8, + int6: ic.profoundStar.DeepInt8, + int7: ic.FathomlessInt, + int8: ic.ProfoundInt, + int9: ic.fathomlessStar.default +}); +export const MyFathomlessRecord = ic.FathomlessRecord({ + mytext: text +}); +export const MyTuple = ic.CoveredTuple(mT); +export const MyDeepTuple = ic.DeepTuple(mDT); +export const MyCavernousTuple = ic.CavernousTuple(mCT); -export type MyVariant = ic.CoveredVariant<{ - Thing: variInt; - String: ic.text; -}>; -export type MyDeepVariant = ic.DeepVariant<{ - Thing: int8; -}>; -export type MyFathomlessVariant = ic.FathomlessVariant<{ - MyInt8: ic.int8; - MyInt16: ic.int16; -}>; -export type MyCavernousVariant = ic.CavernousVariant<{ - eight: null; - sixteen: null; -}>; +export const MyCavernousRecord = ic.CavernousRecord({ + coveredRecord: MyCoveredRecord, + myRecord: MyRecord, + fathomlessRecord: MyFathomlessRecord, + myTuple: MyTuple, + myDeepTuple: MyDeepTuple, + myCavernousTuple: MyCavernousTuple +}); -class SomeService extends ic.fathomlessService { - @ic.serviceQuery - query1: () => ic.azle.CallResult; +export const MyVariant = ic.CoveredVariant({ + Thing: variInt, + String: ic.text +}); +export const MyDeepVariant = ic.DeepVariant({ + Thing: int8 +}); +export const MyFathomlessVariant = ic.FathomlessVariant({ + MyInt8: ic.int8, + MyInt16: ic.int16 +}); +export const MyCavernousVariant = ic.CavernousVariant({ + eight: ic.Null, + sixteen: ic.Null +}); - @ic.azle.serviceUpdate - update1: () => ic.CallResult; -} +const SomeService = ic.fathomlessService({ + query1: ic.query([], ic.bool), + update1: ic.azle.update([], ic.text) +}); -query; -export function myVariantToMyDeepVariant(mV: MyVariant): MyDeepVariant { - return match(mV, { - Thing: (thing) => { - let result: MyDeepVariant = { Thing: thing }; +export const myVariantToMyDeepVariant = query( + [MyVariant], + MyDeepVariant, + (mV) => { + if (mV.Thing !== undefined) { + const thing = mV.Thing; + let result: typeof MyDeepVariant = { Thing: thing }; return result; - }, - String: () => { - throw 'Cannot convert to MyDeepVariant'; } - }); -} -query; -export function myFathomlessVariantToMyCavernousVariant( - mV: MyFathomlessVariant -): MyCavernousVariant { - return match(mV, { - MyInt8: () => { + throw 'Cannot convert to MyDeepVariant'; + } +); + +export const myFathomlessVariantToMyCavernousVariant = query( + [MyFathomlessVariant], + MyCavernousVariant, + (mV) => { + if ('MyInt8' in mV) { return { eight: null }; - }, - MyInt16: () => { - return { sixteen: null }; } - }); -} -ic.$query; -export function returnVec(): ic.Vec { + return { sixteen: null }; + } +); + +export const returnVec = ic.query([], ic.Vec(ic.azle.blob), () => { return [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6, 7])]; -} +}); -$icQuery; -export function returnFathomlessVec(): ic.FathomlessVec { - return [1, 2, 3, 4, 5, 6, 7]; -} +export const returnFathomlessVec = icQuery( + [], + ic.FathomlessVec(ic.azle.int16), + () => { + return [1, 2, 3, 4, 5, 6, 7]; + } +); -ic.azle.$query; -export function returnWeird(): ic.nat8 { +export const returnWeird = ic.azle.query([], ic.nat8, () => { return -10_000n; -} - -ic.azle.$query; -export function returnFathomlessService(service: SomeService): SomeService { - return service; -} +}); -dollarSignQuery; -export function makeCavernousRecord(): MyCavernousRecord { - return { - coveredRecord: { - count: 10, - name: 'Bob', - type_name: 'Imported Record', - greeting: ic.Opt.Some('Hello there') - }, - myRecord: { - int1: 20, - int2: 30, - int3: 40, - int4: 50, - int5: 60, - int6: 70, - int7: 80, - int8: 90, - int9: 100 - }, - fathomlessRecord: { - mytext: 'my text in a fathomless record' - }, - myTuple: ['my tuple'], - myDeepTuple: ['my deep tuple'], - myCavernousTuple: ['my cavernous tuple'] - }; -} +export const returnFathomlessService = ic.azle.query( + [SomeService], + SomeService, + (service) => { + return service; + } +); -dollarSignQuery; -export function typeCheck(vec: CoveredVec>): coveredInt16 { - if (vec.length === 1) { - return match(vec[0], { - Some: (nat16) => { - return nat16; +export const makeCavernousRecord = dollarSignQuery( + [], + MyCavernousRecord, + () => { + return { + coveredRecord: { + count: 10, + name: 'Bob', + type_name: 'Imported Record', + greeting: ic.Some('Hello there') }, - None: () => { + myRecord: { + int1: 20, + int2: 30, + int3: 40, + int4: 50, + int5: 60, + int6: 70, + int7: 80, + int8: 90, + int9: 100 + }, + fathomlessRecord: { + mytext: 'my text in a fathomless record' + }, + myTuple: ['my tuple'], + myDeepTuple: ['my deep tuple'], + myCavernousTuple: ['my cavernous tuple'] + }; + } +); + +export const typeCheck = dollarSignQuery( + [CoveredVec(CoveredOpt(ic.nat16))], + coveredInt16, + (vec) => { + if (vec.length === 1) { + if (vec[0].length === 0) { return -1; } - }); + + return vec[0][0]; + } + return -2; } - return -2; -} +); diff --git a/examples/robust_imports/src/import_coverage/types.ts b/examples/robust_imports/src/import_coverage/types.ts index d337a3f2eb..291f7a74e7 100644 --- a/examples/robust_imports/src/import_coverage/types.ts +++ b/examples/robust_imports/src/import_coverage/types.ts @@ -61,7 +61,7 @@ import cavernousDefault, { DeepVariant as CavernousVariant } from '../types/deep'; //6 Type import -import type { Opt, Vec as CoveredVec } from 'azle'; +import { Opt, Vec as CoveredVec } from 'azle'; //7 Default import as import { default as defaultInt16 } from '../types/deep'; @@ -141,4 +141,4 @@ export { DeepInt8 as FathomlessInt } from '../types/deep'; // export type ProfoundInt = profoundStar.DeepInt8; export { DeepInt8 as ProfoundInt } from '../types/deep'; //5) export default -export default deepStar.deepAzle.$query; +export default deepStar.deepAzle.query; diff --git a/examples/robust_imports/src/index.did b/examples/robust_imports/src/index.did index df07d81f5a..7bf8c3c211 100644 --- a/examples/robust_imports/src/index.did +++ b/examples/robust_imports/src/index.did @@ -1,144 +1,70 @@ -type IceAppleBasket = record { - "int" : int; - starInt : int; - "int8" : int8; - "int16" : int16; - "int32" : int32; - "int64" : int64; -}; -type MixedConcreteStar = record { star : bool }; -type MyCavernousRecord = record { - myRecord : MyRecord; - myDeepTuple : record { text }; - myCavernousTuple : record { text }; - fathomlessRecord : MyFathomlessRecord; - coveredRecord : MyCoveredRecord; - myTuple : record { text }; -}; -type MyCavernousVariant = variant { sixteen; eight }; -type MyCoveredRecord = record { - type_name : text; - name : text; - count : int8; - greeting : opt text; -}; -type MyDeepRecordFromAlias = record { depth : nat8 }; -type MyDeepVariant = variant { Thing : int8 }; -type MyDeepVariantFromAlias = variant { bad; good; ugly }; -type MyFathomlessRecord = record { mytext : text }; -type MyFathomlessVariant = variant { MyInt16 : int16; MyInt8 : int8 }; -type MyRecord = record { - int1 : int16; - int2 : int16; - int3 : int16; - int4 : int8; - int5 : int8; - int6 : int8; - int7 : int8; - "int8" : int8; - int9 : int16; -}; -type MyRecordFromAlias = record { - id : nat; - list : vec nat16; - name : opt text; - tups : record { text; float64 }; - description : MyDeepVariantFromAlias; - depth : MyDeepRecordFromAlias; -}; -type MyVariant = variant { String : text; Thing : int8 }; -type NectarineBasket = record { - "nat" : nat; - starNat : nat; - "nat8" : nat8; - "nat16" : nat16; - "nat32" : nat32; - "nat64" : nat64; -}; -type NumberAliases = record { - fifth : int; - first : int; - tenth : nat; - third : float64; - eighth : int; - seventh : float64; - second : int; - sixth : float32; - ninth : int8; - eleventh : nat8; - twelfth : float64; - fourth : int; -}; -type Watermelon = variant { Seeds; Seedless }; -type _AzleResult = variant { Ok : bool; Err : text }; -service : () -> { - addSigFigs : (float32) -> (float64) query; - checkPrimAliases : (bool, null, text, int, float64) -> () query; - checkService : ( - service { deliver : () -> (text); is_delivered : () -> (bool) query }, - ) -> ( - service { deliver : () -> (text); is_delivered : () -> (bool) query }, - ) query; - checkServiceAlias : (service { testQuery : () -> (text) query }) -> ( - service { testQuery : () -> (text) query }, - ) query; - checkWatermelonForSeeds : (bool, Watermelon) -> () query; - compareApplesToOranges : (IceAppleBasket, NectarineBasket) -> (bool) query; - compareStars : (MixedConcreteStar, MixedConcreteStar) -> (_AzleResult) query; - deepEmptyAlias : () -> (empty) query; - dirtyIlama : () -> (); - getDeepBlob : (vec nat8) -> (vec nat8) query; - getManagementPeach : () -> (principal) query; - getManualAlias : () -> (float64) query; - getMyRecord : () -> (MyRecordFromAlias) query; - getMyRecordAlias : () -> (MyRecordFromAlias) query; - getNumberAliases : () -> (NumberAliases) query; - getReservedAlias : () -> (reserved) query; - getStable : (nat16) -> (opt text) query; - getSuperAlias : () -> (MyRecordFromAlias) query; - handleFarkleberries : ( - func (text) -> () oneway, - func (text) -> (text) query, - func (text) -> (text), - ) -> ( - record { - func (text) -> (text); - func (text) -> () oneway; - func (text) -> (text) query; - }, - ) query; - helloAzleTextAlias : () -> (text) query; - helloDeepTextAlias : () -> (text) query; - helloMixedTextAlias : () -> (text) query; - helloStirredTextAlias : () -> (text) query; - helloTextAlias : () -> (text) query; - isFruitPrepared : () -> (bool) query; - isMangoTrickyToEat : () -> (bool) query; - makeCavernousRecord : () -> (MyCavernousRecord) query; - myFathomlessVariantToMyCavernousVariant : (MyFathomlessVariant) -> ( - MyCavernousVariant, - ) query; - myVariantToMyDeepVariant : (MyVariant) -> (MyDeepVariant) query; - passPrincipal : (principal) -> (principal) query; - peelBanana : (vec nat8) -> (nat8) query; - pickElderberry : () -> (empty); - pitOlives : (opt bool) -> (bool) query; - putTheCoconutInTheLime : (int16) -> (vec int16) query; - removeRambutanSkins : () -> (reserved); - returnFathomlessService : ( - service { query1 : () -> (bool) query; update1 : () -> (text) }, - ) -> ( - service { query1 : () -> (bool) query; update1 : () -> (text) }, - ) query; - returnFathomlessVec : () -> (vec int16) query; - returnFuncAlias : (func (text) -> (text) query) -> ( - func (text) -> (text) query, - ) query; - returnVec : () -> (vec vec nat8) query; - returnWeird : () -> (int64) query; - setStable : (nat16, text) -> (opt text); - simpleAzleQuery : () -> () query; - simpleDeepQuery : () -> () query; - simpleQuery : () -> () query; - typeCheck : (vec opt nat16) -> (int16) query; -} \ No newline at end of file +type rec_0 = variant {String:text; Thing:int8}; +type rec_1 = variant {Thing:int8}; +type rec_2 = variant {MyInt16:int16; MyInt8:int8}; +type rec_3 = variant {sixteen; eight}; +type rec_6 = record {int1:int16; int2:int16; int3:int16; int4:int8; int5:int8; int6:int8; int7:int8; int8:int8; int9:int16}; +type rec_7 = record {mytext:text}; +type rec_5 = record {type_name:text; name:text; count:int8; greeting:opt text}; +type rec_4 = record {myRecord:rec_6; myDeepTuple:record {text}; myCavernousTuple:record {text}; fathomlessRecord:rec_7; coveredRecord:rec_5; myTuple:record {text}}; +type rec_9 = variant {Seeds; Seedless}; +type rec_10 = record {int:int; starInt:int; int8:int8; int16:int16; int32:int32; int64:int64}; +type rec_11 = record {nat:nat; starNat:nat; nat8:nat8; nat16:nat16; nat32:nat32; nat64:nat64}; +type rec_12 = record {star:bool}; +type rec_13 = record {star:bool}; +type rec_14 = record {fifth:int; first:int; tenth:nat; third:float64; eighth:int; seventh:float64; second:int; sixth:float32; ninth:int8; eleventh:nat8; twelfth:float64; fourth:int}; +type rec_17 = variant {bad; good; ugly}; +type rec_16 = record {depth:nat8}; +type rec_15 = record {id:nat; list:vec nat16; name:opt text; tups:record {text; float64}; description:rec_17; depth:rec_16}; +type rec_20 = variant {bad; good; ugly}; +type rec_19 = record {depth:nat8}; +type rec_18 = record {id:nat; list:vec nat16; name:opt text; tups:record {text; float64}; description:rec_20; depth:rec_19}; +type rec_23 = variant {bad; good; ugly}; +type rec_22 = record {depth:nat8}; +type rec_21 = record {id:nat; list:vec nat16; name:opt text; tups:record {text; float64}; description:rec_23; depth:rec_22}; +service: () -> { + myVariantToMyDeepVariant: (rec_0) -> (rec_1) query; + myFathomlessVariantToMyCavernousVariant: (rec_2) -> (rec_3) query; + returnVec: () -> (vec vec nat8) query; + returnFathomlessVec: () -> (vec int16) query; + returnWeird: () -> (int64) query; + returnFathomlessService: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; + makeCavernousRecord: () -> (rec_4) query; + typeCheck: (vec opt nat16) -> (int16) query; + addSigFigs: (float32) -> (float64) query; + checkService: (service {deliver:() -> (text) ; is_delivered:() -> (bool) query}) -> (service {deliver:() -> (text) ; is_delivered:() -> (bool) query}) query; + checkWatermelonForSeeds: (bool, rec_9) -> () query; + compareApplesToOranges: (rec_10, rec_11) -> (bool) query; + handleFarkleberries: (func (text) -> () oneway, func (text) -> (text) query, func (text) -> (text) ) -> (record {func (text) -> (text) ; func (text) -> () oneway; func (text) -> (text) query}) query; + getManagementPeach: () -> (principal) query; + pitOlives: (opt bool) -> (bool) query; + peelBanana: (vec nat8) -> (nat8) query; + putTheCoconutInTheLime: (int16) -> (vec int16) query; + isMangoTrickyToEat: () -> (bool) query; + isFruitPrepared: () -> (bool) query; + removeRambutanSkins: () -> (reserved); + dirtyIlama: () -> (); + pickElderberry: () -> (empty); + compareStars: (rec_12, rec_13) -> (variant {Ok:bool; Err:text}) query; + helloTextAlias: () -> (text) query; + helloAzleTextAlias: () -> (text) query; + helloMixedTextAlias: () -> (text) query; + helloDeepTextAlias: () -> (text) query; + helloStirredTextAlias: () -> (text) query; + getDeepBlob: (vec nat8) -> (vec nat8) query; + deepEmptyAlias: () -> (empty) query; + getNumberAliases: () -> (rec_14) query; + passPrincipal: (principal) -> (principal) query; + getReservedAlias: () -> (reserved) query; + simpleDeepQuery: () -> () query; + simpleAzleQuery: () -> () query; + simpleQuery: () -> () query; + checkServiceAlias: (service {testQuery:() -> (text) query}) -> (service {testQuery:() -> (text) query}) query; + getMyRecord: () -> (rec_15) query; + getMyRecordAlias: () -> (rec_18) query; + getSuperAlias: () -> (rec_21) query; + getManualAlias: () -> (float64) query; + returnFuncAlias: (func (text) -> (text) query) -> (func (text) -> (text) query) query; + setStable: (nat16, text) -> (opt text); + getStable: (nat16) -> (opt text) query; + checkPrimAliases: (bool, null, text, int, float64) -> () query; +} diff --git a/examples/robust_imports/src/index.ts b/examples/robust_imports/src/index.ts index e6bf68cfc1..f261168770 100644 --- a/examples/robust_imports/src/index.ts +++ b/examples/robust_imports/src/index.ts @@ -1,8 +1,114 @@ // Named Imports -export * from './import_coverage'; -export * from './azle_coverage'; -export * from './type_alias_decls'; -export * from './ts_primitives'; +import { Service } from 'azle'; +import { + myVariantToMyDeepVariant, + myFathomlessVariantToMyCavernousVariant, + returnVec, + returnFathomlessVec, + returnWeird, + returnFathomlessService, + makeCavernousRecord, + typeCheck +} from './import_coverage'; +import { + collectIcaco, + cutPineapple, + separateArilsFromPith, + buyHoneydew, + keepIlamaClean, + addSigFigs, + checkService, + checkWatermelonForSeeds, + compareApplesToOranges, + handleFarkleberries, + getManagementPeach, + pitOlives, + peelBanana, + putTheCoconutInTheLime, + isMangoTrickyToEat, + isFruitPrepared, + removeRambutanSkins, + dirtyIlama, + pickElderberry +} from './azle_coverage'; +import { + compareStars, + helloTextAlias, + helloAzleTextAlias, + helloMixedTextAlias, + helloDeepTextAlias, + helloStirredTextAlias, + getDeepBlob, + deepEmptyAlias, + getNumberAliases, + passPrincipal, + getReservedAlias, + simpleDeepQuery, + simpleAzleQuery, + simpleQuery, + checkServiceAlias, + getMyRecord, + getMyRecordAlias, + getSuperAlias, + getManualAlias, + returnFuncAlias, + setStable, + getStable +} from './type_alias_decls'; +import { checkPrimAliases } from './ts_primitives'; // Not Named Imports import './azle_coverage/fruit'; // Shouldn't do anything. It's just here to make sure it doesn't do anything + +export default Service({ + myVariantToMyDeepVariant, + myFathomlessVariantToMyCavernousVariant, + returnVec, + returnFathomlessVec, + returnWeird, + returnFathomlessService, + makeCavernousRecord, + typeCheck, + collectIcaco, + cutPineapple, + separateArilsFromPith, + buyHoneydew, + keepIlamaClean, + addSigFigs, + checkService, + checkWatermelonForSeeds, + compareApplesToOranges, + handleFarkleberries, + getManagementPeach, + pitOlives, + peelBanana, + putTheCoconutInTheLime, + isMangoTrickyToEat, + isFruitPrepared, + removeRambutanSkins, + dirtyIlama, + pickElderberry, + compareStars, + helloTextAlias, + helloAzleTextAlias, + helloMixedTextAlias, + helloDeepTextAlias, + helloStirredTextAlias, + getDeepBlob, + deepEmptyAlias, + getNumberAliases, + passPrincipal, + getReservedAlias, + simpleDeepQuery, + simpleAzleQuery, + simpleQuery, + checkServiceAlias, + getMyRecord, + getMyRecordAlias, + getSuperAlias, + getManualAlias, + returnFuncAlias, + setStable, + getStable, + checkPrimAliases +}); diff --git a/examples/robust_imports/src/ts_primitives/index.ts b/examples/robust_imports/src/ts_primitives/index.ts index e701fc1766..fab9758fe6 100644 --- a/examples/robust_imports/src/ts_primitives/index.ts +++ b/examples/robust_imports/src/ts_primitives/index.ts @@ -1,21 +1,18 @@ -import { $query } from 'azle'; +import { bool, float64, int, Null, query, text, Void } from 'azle'; -export type MyBool = boolean; -export type MyNull = null; -export type MyString = string; -export type MyBigInt = bigint; -export type MyNumber = number; -export type MyVoid = void; +export const MyBool = bool; +export const MyNull = Null; +export const MyString = text; +export const MyBigInt = int; +export const MyNumber = float64; +export const MyVoid = Void; -$query; -export function checkPrimAliases( - param1: MyBool, - param2: MyNull, - param3: MyString, - param4: MyBigInt, - param5: MyNumber -): MyVoid { - if (param1) { - console.log(`${param2}, ${param3}, ${param4}, ${param5}`); +export const checkPrimAliases = query( + [MyBool, MyNull, MyString, MyBigInt, MyNumber], + MyVoid, + (param1, param2, param3, param4, param5) => { + if (param1) { + console.log(`${param2}, ${param3}, ${param4}, ${param5}`); + } } -} +); diff --git a/examples/robust_imports/src/type_alias_decls/index.ts b/examples/robust_imports/src/type_alias_decls/index.ts index b986982609..56f68d599d 100644 --- a/examples/robust_imports/src/type_alias_decls/index.ts +++ b/examples/robust_imports/src/type_alias_decls/index.ts @@ -1,215 +1,229 @@ import * as types from './types'; import * as azle from 'azle'; -function offDuty(): types.DeepGuardResultAlias { - return { Ok: null }; -} +function offDuty() {} const HELLO_WORLD = 'Hello, World!'; -type LocalNumberAlias = types.Float64Alias; - -type NumberAliases = azle.Record<{ - first: types.AzleIntAlias; - second: types.IntAlias; - third: types.Float64Alias; - fourth: types.MixedIntAlias; - fifth: types.StirredIntAlias; - sixth: types.DeepFloat32Alias; - seventh: types.DeepFloat64Alias; - eighth: types.DeepIntAlias; - ninth: types.DeepInt8Alias; - tenth: types.DeepNatAlias; - eleventh: types.DeepNat8Alias; - twelfth: LocalNumberAlias; -}>; +const LocalNumberAlias = types.Float64Alias; + +const NumberAliases = azle.Record({ + first: types.AzleIntAlias, + second: types.IntAlias, + third: types.Float64Alias, + fourth: types.MixedIntAlias, + fifth: types.StirredIntAlias, + sixth: types.DeepFloat32Alias, + seventh: types.DeepFloat64Alias, + eighth: types.DeepIntAlias, + ninth: types.DeepInt8Alias, + tenth: types.DeepNatAlias, + eleventh: types.DeepNat8Alias, + twelfth: LocalNumberAlias +}); import { MixedConcreteStar } from './types'; import { Result } from 'azle'; -azle.$query; -export function compareStars( - record: MixedConcreteStar, - concrete: MixedConcreteStar -): Result { - return azle.Result.Ok(record.star === concrete.star); -} - -azle.$query; -export function helloTextAlias(): types.TextAlias { - return HELLO_WORLD; -} -azle.$query; -export function helloAzleTextAlias(): types.AzleTextAlias { +export const compareStars = azle.query( + [MixedConcreteStar, MixedConcreteStar], + Result(azle.bool, azle.text), + (record, concrete) => { + return azle.Result.Ok(record.star === concrete.star); + } +); + +export const helloTextAlias = azle.query([], types.TextAlias, () => { return HELLO_WORLD; -} +}); -azle.$query; -export function helloMixedTextAlias(): types.MixedTextAlias { +export const helloAzleTextAlias = azle.query([], types.AzleTextAlias, () => { return HELLO_WORLD; -} +}); -azle.$query; -export function helloDeepTextAlias(): types.DeepTextAlias { +export const helloMixedTextAlias = azle.query([], types.MixedTextAlias, () => { return HELLO_WORLD; -} +}); -azle.$query; -export function helloStirredTextAlias(): types.StirredTextAlias { +export const helloDeepTextAlias = azle.query([], types.DeepTextAlias, () => { return HELLO_WORLD; -} +}); + +export const helloStirredTextAlias = azle.query( + [], + types.StirredTextAlias, + () => { + return HELLO_WORLD; + } +); -azle.$query; -export function getDeepBlob(blob: types.DeepBlobAlias): types.DeepBlobAlias { - return blob; -} +export const getDeepBlob = azle.query( + [types.DeepBlobAlias], + types.DeepBlobAlias, + (blob) => { + return blob; + } +); -azle.$query; -export function deepEmptyAlias(): types.DeepEmptyAlias { +export const deepEmptyAlias = azle.query([], types.DeepEmptyAlias, () => { throw 'empty'; -} - -azle.$query({ guard: offDuty }); -export function getNumberAliases(): NumberAliases { - return { - first: 1n, - second: 2n, - third: 3, - fourth: 4n, - fifth: 5n, - sixth: 6, - seventh: 7, - eighth: 8n, - ninth: 9, - tenth: 10n, - eleventh: 11, - twelfth: 12 - }; -} +}); + +export const getNumberAliases = azle.query( + [], + NumberAliases, + () => { + return { + first: 1n, + second: 2n, + third: 3, + fourth: 4n, + fifth: 5n, + sixth: 6, + seventh: 7, + eighth: 8n, + ninth: 9, + tenth: 10n, + eleventh: 11, + twelfth: 12 + }; + }, + { guard: offDuty } +); -azle.$query; -export function passPrincipal( - principal: types.DeepPrincipalAlias -): types.DeepPrincipalAlias { - return principal; -} +export const passPrincipal = azle.query( + [types.DeepPrincipalAlias], + types.DeepPrincipalAlias, + (principal) => { + return principal; + } +); -azle.$query; -export function getReservedAlias(): types.DeepReservedAlias { +export const getReservedAlias = azle.query([], types.DeepReservedAlias, () => { return 'anything'; -} - -types.Deep$queryAlias; -export function simpleDeepQuery(): types.VoidAlias { - console.log(HELLO_WORLD); -} +}); + +export const simpleDeepQuery = types.Deep$queryAlias( + [], + types.VoidAlias, + () => { + console.log(HELLO_WORLD); + } +); -types.Azle$queryAlias; -export function simpleAzleQuery(): types.VoidAlias { - console.log(HELLO_WORLD); -} +export const simpleAzleQuery = types.Azle$queryAlias( + [], + types.VoidAlias, + () => { + console.log(HELLO_WORLD); + } +); -types.$queryAlias; -export function simpleQuery(): types.VoidAlias { +export const simpleQuery = types.$queryAlias([], types.VoidAlias, () => { console.log(HELLO_WORLD); -} +}); -class AliasedService extends types.DeepServiceAlias { - @types.DeepServiceQueryAlias - testQuery: () => azle.CallResult; -} +const AliasedService = types.DeepServiceAlias({ + testQuery: types.$queryAlias([], azle.text) +}); -export type AliasedServiceAlias = AliasedService; +export const AliasedServiceAlias = AliasedService; -azle.$query; -export function checkServiceAlias(service: AliasedService): AliasedService { - return service; -} +export const checkServiceAlias = azle.query( + [AliasedService], + AliasedService, + (service) => { + return service; + } +); export type MyLocalNumberAlias = number; -export type MyDeepRecordFromAlias = types.DeepRecordAlias<{ depth: azle.nat8 }>; -export type MyDeepVariantFromAlias = types.DeepVariantAlias<{ - good: null; - bad: null; - ugly: null; -}>; -export type MyAliasToMyDeepRecordFromAlias = MyDeepRecordFromAlias; -export type MyRecordFromAlias = types.RecordAlias<{ - id: azle.nat; - name: types.DeepOptAlias; - depth: MyAliasToMyDeepRecordFromAlias; - tups: types.DeepTupleAlias<[string, types.Float64Alias]>; - description: MyDeepVariantFromAlias; - list: types.DeepVecAlias; -}>; -export type MyRecordFromAliasAlias = MyRecordFromAlias; -export type SuperAlias = MyRecordFromAliasAlias; - -azle.$query; -export function getMyRecord(): MyRecordFromAlias { +export const MyDeepRecordFromAlias = types.DeepRecordAlias({ + depth: azle.nat8 +}); +export const MyDeepVariantFromAlias = types.DeepVariantAlias({ + good: azle.Null, + bad: azle.Null, + ugly: azle.Null +}); +export const MyAliasToMyDeepRecordFromAlias = MyDeepRecordFromAlias; +export const MyRecordFromAlias = types.RecordAlias({ + id: azle.nat, + name: types.DeepOptAlias(azle.text), + depth: MyAliasToMyDeepRecordFromAlias, + tups: types.DeepTupleAlias(azle.text, types.Float64Alias), + description: MyDeepVariantFromAlias, + list: types.DeepVecAlias(azle.nat16) +}); +export const MyRecordFromAliasAlias = MyRecordFromAlias; +export const SuperAlias = MyRecordFromAliasAlias; + +export const getMyRecord = azle.query([], MyRecordFromAlias, () => { return { id: 7n, - name: azle.Opt.Some('Bob'), + name: azle.Some('Bob'), depth: { depth: 3 }, tups: ['Hello', 1.23], description: { ugly: null }, list: [1, 2, 3, 4, 5, 6, 7] }; -} +}); -azle.$query; -export function getMyRecordAlias(): MyRecordFromAliasAlias { +export const getMyRecordAlias = azle.query([], MyRecordFromAliasAlias, () => { return { id: 8n, - name: azle.Opt.Some('Alice'), + name: azle.Some('Alice'), depth: { depth: 3 }, tups: ['Hello', 1.23], description: { ugly: null }, list: [1, 2, 3, 4, 5, 6, 7] }; -} +}); -azle.$query; -export function getSuperAlias(): SuperAlias { +export const getSuperAlias = azle.query([], SuperAlias, () => { return { id: 9n, - name: azle.Opt.Some('Eve'), + name: azle.Some('Eve'), depth: { depth: 3 }, tups: ['Hello', 1.23], description: { ugly: null }, list: [1, 2, 3, 4, 5, 6, 7] }; -} - -azle.$query; -export function getManualAlias(): types.DeepManualAlias { - azle.ic.reply(9.87); -} - -type MyFuncFromAlias = types.DeepFuncAlias< - types.DeepQueryAlias<(param1: azle.text) => azle.text> ->; - -azle.$query; -export function returnFuncAlias(func: MyFuncFromAlias): MyFuncFromAlias { - return func; -} - -let stableMap = new types.DeepStableBTreeMapAlias( - 1, - 10, - 1_000 +}); + +export const getManualAlias = azle.query( + [], + types.DeepManualAlias(azle.float64), + () => { + azle.ic.reply(9.87, azle.float64); + }, + { manual: true } ); -azle.$update; -export function setStable( - key: azle.nat16, - value: azle.text -): types.DeepOptAlias { - return stableMap.insert(key, value); -} - -azle.$query; -export function getStable(key: azle.nat16): types.DeepOptAlias { - return stableMap.get(key); -} +const MyFuncFromAlias = types.DeepFuncAlias([azle.text], azle.text, 'query'); + +export const returnFuncAlias = azle.query( + [MyFuncFromAlias], + MyFuncFromAlias, + (func) => { + return func; + } +); + +let stableMap = types.DeepStableBTreeMapAlias(azle.nat16, azle.text, 1); + +export const setStable = azle.update( + [azle.nat16, azle.text], + types.DeepOptAlias(azle.text), + (key, value) => { + return stableMap.insert(key, value); + } +); + +export const getStable = azle.query( + [azle.nat16], + types.DeepOptAlias(azle.text), + (key) => { + return stableMap.get(key); + } +); diff --git a/examples/robust_imports/src/type_alias_decls/mixed_alias/user_defined_types.ts b/examples/robust_imports/src/type_alias_decls/mixed_alias/user_defined_types.ts index 7ace74b3bb..e3751c4f85 100644 --- a/examples/robust_imports/src/type_alias_decls/mixed_alias/user_defined_types.ts +++ b/examples/robust_imports/src/type_alias_decls/mixed_alias/user_defined_types.ts @@ -1,4 +1,4 @@ import * as azle from 'azle'; -export type StarRecord = azle.Record<{ star: boolean }>; -export type StartRecordAlias = azle.Record; +export const StarRecord = azle.Record({ star: azle.bool }); +export const StartRecordAlias = azle.Record; diff --git a/examples/robust_imports/src/type_alias_decls/types.ts b/examples/robust_imports/src/type_alias_decls/types.ts index 1e263e51db..85ab51b7d1 100644 --- a/examples/robust_imports/src/type_alias_decls/types.ts +++ b/examples/robust_imports/src/type_alias_decls/types.ts @@ -4,81 +4,67 @@ import { mixedAlias } from './mixed_alias'; import { mixedAlias as stirredAlias } from './mixed_alias'; import { deepAlias } from './deep_alias'; import * as azle from 'azle'; -import { Record, int, $query } from 'azle'; +import { Record, int, query } from 'azle'; -export type AzleRecordAlias = azle.Record; -export type AzleIntAlias = azle.int; -export type AzleTextAlias = azle.text; -export const Azle$queryAlias = azle.$query; +export const AzleRecordAlias = azle.Record; +export const AzleIntAlias = azle.int; +export const AzleTextAlias = azle.text; +export const Azle$queryAlias = azle.query; -export type RecordAlias = Record; -export type IntAlias = int; -export type TextAlias = string; -export type Float64Alias = number; -export type VoidAlias = void; -export const $queryAlias = $query; -export type UserDefinedAlias = Record<{ num: Float64Alias }>; +export const RecordAlias = Record; +export const IntAlias = int; +export const TextAlias = azle.text; +export const Float64Alias = azle.float64; +export const VoidAlias = azle.Void; +export const $queryAlias = query; +export const UserDefinedAlias = Record({ num: Float64Alias }); -export type MixedIntAlias = +export const MixedIntAlias = mixed.mixedAlias.deepAlias.deeperAlias.deepestAlias.int; -export type MixedTextAlias = mixedAlias.deepAlias.deeperAlias.deepestAlias.text; -export type MixedRecordAlias = - mixedAlias.deepAlias.deeperAlias.deepestAlias.Record; -export type MixedUserDefinedAlias = - mixedAlias.deepAlias.deeperAlias.deepestAlias.Record<{ - num: MixedIntAlias; - }>; -export type MixedStarRecord = mixed.mixedAlias.StarRecord; -export type MixedConcreteStar = mixed.mixedAlias.StartRecordAlias<{ - star: boolean; -}>; +export const MixedTextAlias = + mixedAlias.deepAlias.deeperAlias.deepestAlias.text; +export const MixedRecordAlias = + mixedAlias.deepAlias.deeperAlias.deepestAlias.Record; +export const MixedUserDefinedAlias = + mixedAlias.deepAlias.deeperAlias.deepestAlias.Record({ + num: MixedIntAlias + }); +export const MixedStarRecord = mixed.mixedAlias.StarRecord; +export const MixedConcreteStar = mixed.mixedAlias.StartRecordAlias({ + star: azle.bool +}); -export type StirredTextAlias = +export const StirredTextAlias = stirredAlias.deepAlias.deeperAlias.deepestAlias.text; -export type StirredIntAlias = deepAlias.deeperAlias.deepestAlias.int; -export type StirredRecordAlias = - stirredAlias.deepAlias.deeperAlias.deepestAlias.Record; -export type StirredUserDefinedAlias = - mixedAlias.deepAlias.deeperAlias.deepestAlias.Record<{ - num: StirredIntAlias; - }>; +export const StirredIntAlias = deepAlias.deeperAlias.deepestAlias.int; +export const StirredRecordAlias = + stirredAlias.deepAlias.deeperAlias.deepestAlias.Record; +export const StirredUserDefinedAlias = + mixedAlias.deepAlias.deeperAlias.deepestAlias.Record({ + num: StirredIntAlias + }); -export type DeepBlobAlias = deep.deepAlias.deeperAlias.deepestAlias.blob; -export type DeepEmptyAlias = deep.deepAlias.deeperAlias.deepestAlias.empty; -export type DeepFloat32Alias = deep.deepAlias.deeperAlias.deepestAlias.float32; -export type DeepFloat64Alias = deep.deepAlias.deeperAlias.deepestAlias.float64; -export type DeepFuncAlias< - T extends - | azle.Query - | azle.Update - | azle.Oneway -> = deep.deepAlias.deeperAlias.deepestAlias.Func; -export type DeepGuardResultAlias = - deep.deepAlias.deeperAlias.deepestAlias.GuardResult; -export type DeepIntAlias = deep.deepAlias.deeperAlias.deepestAlias.int; -export type DeepInt8Alias = deep.deepAlias.deeperAlias.deepestAlias.int8; -export type DeepManualAlias = - deep.deepAlias.deeperAlias.deepestAlias.Manual; -export type DeepNatAlias = deep.deepAlias.deeperAlias.deepestAlias.nat; -export type DeepNat8Alias = deep.deepAlias.deeperAlias.deepestAlias.nat8; -export type DeepOptAlias = deep.deepAlias.deeperAlias.deepestAlias.Opt; -export type DeepPrincipalAlias = - deep.deepAlias.deeperAlias.deepestAlias.Principal; -export const Deep$queryAlias = deep.deepAlias.deeperAlias.deepestAlias.$query; -export type DeepQueryAlias any> = - deep.deepAlias.deeperAlias.deepestAlias.Query; -export type DeepRecordAlias = - deep.deepAlias.deeperAlias.deepestAlias.Record; -export type DeepReservedAlias = +export const DeepBlobAlias = deep.deepAlias.deeperAlias.deepestAlias.blob; +export const DeepEmptyAlias = deep.deepAlias.deeperAlias.deepestAlias.empty; +export const DeepFloat32Alias = deep.deepAlias.deeperAlias.deepestAlias.float32; +export const DeepFloat64Alias = deep.deepAlias.deeperAlias.deepestAlias.float64; +export const DeepFuncAlias = deep.deepAlias.deeperAlias.deepestAlias.Func; +export const DeepIntAlias = deep.deepAlias.deeperAlias.deepestAlias.int; +export const DeepInt8Alias = deep.deepAlias.deeperAlias.deepestAlias.int8; +export const DeepManualAlias = deep.deepAlias.deeperAlias.deepestAlias.Manual; +export const DeepNatAlias = deep.deepAlias.deeperAlias.deepestAlias.nat; +export const DeepNat8Alias = deep.deepAlias.deeperAlias.deepestAlias.nat8; +export const DeepOptAlias = deep.deepAlias.deeperAlias.deepestAlias.Opt; +export const DeepPrincipalAlias = + deep.deepAlias.deeperAlias.deepestAlias.principal; +export const Deep$queryAlias = deep.deepAlias.deeperAlias.deepestAlias.query; +export const DeepRecordAlias = deep.deepAlias.deeperAlias.deepestAlias.Record; +export const DeepReservedAlias = deep.deepAlias.deeperAlias.deepestAlias.reserved; export const DeepServiceAlias = deep.deepAlias.deeperAlias.deepestAlias.Service; -export const DeepServiceQueryAlias = - deep.deepAlias.deeperAlias.deepestAlias.serviceQuery; export const DeepStableBTreeMapAlias = deep.deepAlias.deeperAlias.deepestAlias.StableBTreeMap; -export type DeepTextAlias = deep.deepAlias.deeperAlias.deepestAlias.text; -export type DeepTupleAlias = - deep.deepAlias.deeperAlias.deepestAlias.Tuple; -export type DeepVariantAlias = - deep.deepAlias.deeperAlias.deepestAlias.Variant; -export type DeepVecAlias = deep.deepAlias.deeperAlias.deepestAlias.Vec; +export const DeepTextAlias = deep.deepAlias.deeperAlias.deepestAlias.text; +export const DeepTupleAlias = deep.deepAlias.deeperAlias.deepestAlias.Tuple; +export const DeepVariantAlias = deep.deepAlias.deeperAlias.deepestAlias.Variant; +export const DeepVecAlias = deep.deepAlias.deeperAlias.deepestAlias.Vec; diff --git a/examples/robust_imports/test/tests.ts b/examples/robust_imports/test/tests.ts index 2153e3f177..3e38cc7f97 100644 --- a/examples/robust_imports/test/tests.ts +++ b/examples/robust_imports/test/tests.ts @@ -3,7 +3,6 @@ import { Principal } from '@dfinity/principal'; import { execSync } from 'child_process'; import { _SERVICE } from '../dfx_generated/robust_imports/robust_imports.did'; import { ActorSubclass } from '@dfinity/agent'; -import { match } from 'azle'; export function getTests( robustImportsCanister: ActorSubclass<_SERVICE> @@ -323,7 +322,7 @@ function getAzleCoverageTests(fruit: ActorSubclass<_SERVICE>): Test[] { { name: 'deploy', prep: async () => { - execSync(`dfx deploy`, { + execSync(`dfx deploy --upgrade-unchanged`, { stdio: 'inherit' }); } @@ -514,9 +513,12 @@ function getTypeAliasDeclTests(canister: ActorSubclass<_SERVICE>): Test[] { { star: true }, { star: true } ); - return { - Ok: match(result, { Ok: () => true, Err: () => false }) - }; + + if ('Ok' in result) { + return { Ok: true }; + } + + return { Ok: false }; } } ];