diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d9ee7a2465..fbca8bc3e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,6 +72,7 @@ jobs: "examples/bytes", "examples/call_raw", "examples/candid_encoding", + "examples/canister", "examples/complex_init", "examples/composite_queries", "examples/counter", @@ -115,7 +116,6 @@ jobs: "examples/randomness", "examples/rejections", "examples/robust_imports", - "examples/service", "examples/simple_erc20", "examples/simple_user_accounts", "examples/stable_memory", diff --git a/canisters/ledger/index.ts b/canisters/ledger/index.ts index 9c2079d61d..bc72dfe770 100644 --- a/canisters/ledger/index.ts +++ b/canisters/ledger/index.ts @@ -8,15 +8,14 @@ import { blob, + Canister, nat, nat8, nat32, nat64, Null, Opt, - Principal, Record, - Service, query, update, text, @@ -298,7 +297,7 @@ export const DecimalsResult = Record({ export type Address = text; export const Address = text; -export const Ledger = Service({ +export const Ledger = Canister({ // Transfers tokens from a subaccount of the caller to the destination address. // The source address is computed from the principal of the caller and the specified subaccount. // When successful, returns the index of the block containing the transaction. diff --git a/canisters/management/index.ts b/canisters/management/index.ts index bb91f40189..4202551d9c 100644 --- a/canisters/management/index.ts +++ b/canisters/management/index.ts @@ -1,7 +1,7 @@ import { blob, + Canister, Principal, - Service, update, Vec, Void @@ -44,7 +44,7 @@ export * from './canister_management'; export * from './http_request'; export * from './t_ecdsa'; -export const managementCanister = Service({ +export const managementCanister = Canister({ // bitcoin bitcoin_get_balance: update([GetBalanceArgs], Satoshi), bitcoin_get_current_fee_percentiles: update( diff --git a/examples/async_await/src/async_await.ts b/examples/async_await/src/async_await.ts index 52c5b25604..741af4584c 100644 --- a/examples/async_await/src/async_await.ts +++ b/examples/async_await/src/async_await.ts @@ -1,7 +1,7 @@ -import { blob, ic, Service, update, Void } from 'azle'; +import { blob, Canister, ic, update, Void } from 'azle'; import { managementCanister } from 'azle/canisters/management'; -export default Service({ +export default Canister({ getRandomnessDirectly: update([], blob, async () => { return await ic.call(managementCanister.raw_rand); }), diff --git a/examples/audio_recorder/src/index.ts b/examples/audio_recorder/src/index.ts index 397627fc68..f92ff358ee 100644 --- a/examples/audio_recorder/src/index.ts +++ b/examples/audio_recorder/src/index.ts @@ -1,5 +1,6 @@ import { blob, + Canister, ic, nat64, Opt, @@ -8,7 +9,6 @@ import { query, Record, Result, - Service, StableBTreeMap, text, update, @@ -39,7 +39,7 @@ const AudioRecorderError = Variant({ let users = StableBTreeMap(principal, User, 0); let recordings = StableBTreeMap(principal, Recording, 1); -export default Service({ +export default Canister({ createUser: update([text], User, (username) => { const id = generateId(); const user: typeof User = { diff --git a/examples/bitcoin/src/index.ts b/examples/bitcoin/src/index.ts index 89b95f62dd..3ef821f36a 100644 --- a/examples/bitcoin/src/index.ts +++ b/examples/bitcoin/src/index.ts @@ -1,4 +1,4 @@ -import { blob, bool, ic, None, Service, text, update, Vec } from 'azle'; +import { blob, bool, Canister, ic, None, text, update, Vec } from 'azle'; import { GetUtxosResult, managementCanister, @@ -10,7 +10,7 @@ const BITCOIN_API_CYCLE_COST = 100_000_000n; const BITCOIN_BASE_TRANSACTION_COST = 5_000_000_000n; const BITCOIN_CYCLE_COST_PER_TRANSACTION_BYTE = 20_000_000n; -export default Service({ +export default Canister({ getBalance: update([text], Satoshi, async (address) => { return await ic.call(managementCanister.bitcoin_get_balance, { args: [ diff --git a/examples/blob_array/src/index.ts b/examples/blob_array/src/index.ts index 87a84ebb3f..ece9c60312 100644 --- a/examples/blob_array/src/index.ts +++ b/examples/blob_array/src/index.ts @@ -1,6 +1,6 @@ -import { blob, query, Service, Vec } from 'azle'; +import { blob, Canister, query, Vec } from 'azle'; -export default Service({ +export default Canister({ getBlob: query([], blob, () => { return stringToBlob('hello'); }), diff --git a/examples/bytes/src/index.ts b/examples/bytes/src/index.ts index f368b667ff..8d41d50c6f 100644 --- a/examples/bytes/src/index.ts +++ b/examples/bytes/src/index.ts @@ -1,6 +1,6 @@ -import { blob, Service, update } from 'azle'; +import { blob, Canister, update } from 'azle'; -export default Service({ +export default Canister({ getBytes: update([blob], blob, (bytes) => { return bytes; }) diff --git a/examples/call_raw/src/call_raw.ts b/examples/call_raw/src/call_raw.ts index 510f2b94b6..7e353583bd 100644 --- a/examples/call_raw/src/call_raw.ts +++ b/examples/call_raw/src/call_raw.ts @@ -1,6 +1,15 @@ -import { ic, nat, nat64, principal, Result, Service, text, update } from 'azle'; +import { + Canister, + ic, + nat, + nat64, + principal, + Result, + text, + update +} from 'azle'; -export default Service({ +export default Canister({ executeCallRaw: update( [principal, text, text, nat64], Result(text, text), diff --git a/examples/candid_encoding/src/index.ts b/examples/candid_encoding/src/index.ts index d6ce91bf50..4cb819872a 100644 --- a/examples/candid_encoding/src/index.ts +++ b/examples/candid_encoding/src/index.ts @@ -1,6 +1,6 @@ -import { blob, ic, query, Service, text } from 'azle'; +import { blob, Canister, ic, query, text } from 'azle'; -export default Service({ +export default Canister({ // encodes a Candid string to Candid bytes candidEncode: query([text], blob, (candidString) => { return ic.candidEncode(candidString); diff --git a/examples/service/.gitignore b/examples/canister/.gitignore similarity index 100% rename from examples/service/.gitignore rename to examples/canister/.gitignore diff --git a/examples/canister/dfx.json b/examples/canister/dfx.json new file mode 100644 index 0000000000..ead5507fec --- /dev/null +++ b/examples/canister/dfx.json @@ -0,0 +1,31 @@ +{ + "canisters": { + "canister": { + "type": "custom", + "build": "npx azle canister", + "root": "src", + "ts": "src/index.ts", + "candid": "src/index.did", + "wasm": ".azle/canister/canister.wasm", + "gzip": true, + "declarations": { + "output": "test/dfx_generated/canister", + "node_compatibility": true + }, + "env": ["SOME_CANISTER_PRINCIPAL"] + }, + "some_canister": { + "type": "custom", + "build": "npx azle some_canister", + "root": "src", + "ts": "src/some_canister.ts", + "candid": "src/some_canister.did", + "wasm": ".azle/some_canister/some_canister.wasm", + "gzip": true, + "declarations": { + "output": "test/dfx_generated/some_canister", + "node_compatibility": true + } + } + } +} diff --git a/examples/service/package-lock.json b/examples/canister/package-lock.json similarity index 99% rename from examples/service/package-lock.json rename to examples/canister/package-lock.json index 4eb4d38813..739abc6212 100644 --- a/examples/service/package-lock.json +++ b/examples/canister/package-lock.json @@ -1,5 +1,5 @@ { - "name": "service", + "name": "canister", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/examples/service/package.json b/examples/canister/package.json similarity index 100% rename from examples/service/package.json rename to examples/canister/package.json diff --git a/examples/canister/src/index.did b/examples/canister/src/index.did new file mode 100644 index 0000000000..dc020cd99a --- /dev/null +++ b/examples/canister/src/index.did @@ -0,0 +1,8 @@ +type rec_0 = record {someCanister:service {query1:() -> (bool) query; update1:() -> (text) }}; +service: () -> { + canisterParam: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; + canisterReturnType: () -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; + canisterNestedReturnType: () -> (rec_0); + canisterList: (vec service {query1:() -> (bool) query; update1:() -> (text) }) -> (vec service {query1:() -> (bool) query; update1:() -> (text) }); + canisterCrossCanisterCall: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (text); +} diff --git a/examples/canister/src/index.ts b/examples/canister/src/index.ts new file mode 100644 index 0000000000..454d917ab3 --- /dev/null +++ b/examples/canister/src/index.ts @@ -0,0 +1,55 @@ +import { + Canister, + ic, + Principal, + query, + Record, + text, + update, + Vec +} from 'azle'; +import SomeCanister from './some_canister'; + +const Wrapper = Record({ + someCanister: SomeCanister +}); + +export default Canister({ + canisterParam: query([SomeCanister], SomeCanister, (someCanister) => { + return someCanister; + }), + canisterReturnType: query([], SomeCanister, () => { + return SomeCanister( + Principal.fromText( + process.env.SOME_CANISTER_PRINCIPAL ?? + ic.trap('process.env.SOME_CANISTER_PRINCIPAL is undefined') + ) + ); + }), + canisterNestedReturnType: update([], Wrapper, () => { + return { + someCanister: SomeCanister( + Principal.fromText( + process.env.SOME_CANISTER_PRINCIPAL ?? + ic.trap( + 'process.env.SOME_CANISTER_PRINCIPAL is undefined' + ) + ) + ) + }; + }), + canisterList: update( + [Vec(SomeCanister)], + Vec(SomeCanister), + (someCanisters) => { + return someCanisters; + } + ), + canisterCrossCanisterCall: update( + [SomeCanister], + text, + async (someCanister) => { + return await ic.call(someCanister.update1); + } + ) +}); diff --git a/examples/service/src/some_service.did b/examples/canister/src/some_canister.did similarity index 100% rename from examples/service/src/some_service.did rename to examples/canister/src/some_canister.did diff --git a/examples/canister/src/some_canister.ts b/examples/canister/src/some_canister.ts new file mode 100644 index 0000000000..af479598b9 --- /dev/null +++ b/examples/canister/src/some_canister.ts @@ -0,0 +1,10 @@ +import { bool, Canister, query, text, update } from 'azle'; + +export default Canister({ + query1: query([], bool, () => { + return true; + }), + update1: update([], text, () => { + return 'SomeCanister update1'; + }) +}); diff --git a/examples/service/test/pretest.ts b/examples/canister/test/pretest.ts similarity index 61% rename from examples/service/test/pretest.ts rename to examples/canister/test/pretest.ts index 13c9c4d5ab..3238c7c3bd 100644 --- a/examples/service/test/pretest.ts +++ b/examples/canister/test/pretest.ts @@ -4,20 +4,20 @@ import { getCanisterId } from 'azle/test'; async function pretest() { await new Promise((resolve) => setTimeout(resolve, 5000)); - execSync(`dfx canister uninstall-code service || true`, { + execSync(`dfx canister uninstall-code canister || true`, { stdio: 'inherit' }); - execSync(`dfx canister uninstall-code some_service || true`, { + execSync(`dfx canister uninstall-code some_canister || true`, { stdio: 'inherit' }); - execSync(`dfx canister create some_service || true`, { + execSync(`dfx canister create some_canister || true`, { stdio: 'inherit' }); execSync( - `SOME_SERVICE_PRINCIPAL=${getCanisterId('some_service')} dfx deploy`, + `SOME_CANISTER_PRINCIPAL=${getCanisterId('some_canister')} dfx deploy`, { stdio: 'inherit' } diff --git a/examples/canister/test/test.ts b/examples/canister/test/test.ts new file mode 100644 index 0000000000..70781ac568 --- /dev/null +++ b/examples/canister/test/test.ts @@ -0,0 +1,11 @@ +import { getCanisterId, runTests } from 'azle/test'; +import { createActor } from './dfx_generated/canister'; +import { getTests } from './tests'; + +const canister = createActor(getCanisterId('canister'), { + agentOptions: { + host: 'http://127.0.0.1:8000' + } +}); + +runTests(getTests(canister)); diff --git a/examples/service/test/tests.ts b/examples/canister/test/tests.ts similarity index 64% rename from examples/service/test/tests.ts rename to examples/canister/test/tests.ts index 5228c3d415..af62813fd1 100644 --- a/examples/service/test/tests.ts +++ b/examples/canister/test/tests.ts @@ -1,17 +1,17 @@ import { getCanisterId, Test } from 'azle/test'; -import { _SERVICE } from './dfx_generated/service/service.did'; +import { _SERVICE } from './dfx_generated/canister/canister.did'; import { ActorSubclass } from '@dfinity/agent'; import { execSync } from 'child_process'; // TODO these tests should be rewritten to use @dfinity/agent once this issue is resolved: https://github.com/dfinity/agent-js/issues/702 // TODO this issue also needs to be resolved: https://forum.dfinity.org/t/services-wont-deserialize-properly-if-functions-arent-in-alphabetical-order/20885 -export function getTests(serviceCanister: ActorSubclass<_SERVICE>): Test[] { +export function getTests(canister: ActorSubclass<_SERVICE>): Test[] { return [ { - name: 'serviceParam', + name: 'canisterParam', test: async () => { const result = execSync( - `dfx canister call service serviceParam '(service "aaaaa-aa")'` + `dfx canister call canister canisterParam '(service "aaaaa-aa")'` ) .toString() .trim(); @@ -22,10 +22,10 @@ export function getTests(serviceCanister: ActorSubclass<_SERVICE>): Test[] { } }, { - name: 'serviceReturnType', + name: 'canisterReturnType', test: async () => { const result = execSync( - `dfx canister call service serviceReturnType` + `dfx canister call canister canisterReturnType` ) .toString() .trim(); @@ -33,15 +33,15 @@ export function getTests(serviceCanister: ActorSubclass<_SERVICE>): Test[] { return { Ok: result === - `(service "${getCanisterId('some_service')}")` + `(service "${getCanisterId('some_canister')}")` }; } }, { - name: 'serviceNestedReturnType', + name: 'canisterNestedReturnType', test: async () => { const result = execSync( - `dfx canister call service serviceNestedReturnType` + `dfx canister call canister canisterNestedReturnType` ) .toString() .trim(); @@ -49,17 +49,17 @@ export function getTests(serviceCanister: ActorSubclass<_SERVICE>): Test[] { return { Ok: result === - `(record { someService = service "${getCanisterId( - 'some_service' + `(record { someCanister = service "${getCanisterId( + 'some_canister' )}" })` }; } }, { - name: 'serviceList', + name: 'canisterList', test: async () => { const result = execSync( - `dfx canister call service serviceList '(vec { service "r7inp-6aaaa-aaaaa-aaabq-cai"; service "rrkah-fqaaa-aaaaa-aaaaq-cai" })'` + `dfx canister call canister canisterList '(vec { service "r7inp-6aaaa-aaaaa-aaabq-cai"; service "rrkah-fqaaa-aaaaa-aaaaq-cai" })'` ) .toString() .trim(); @@ -77,18 +77,18 @@ export function getTests(serviceCanister: ActorSubclass<_SERVICE>): Test[] { } }, { - name: 'serviceCrossCanisterCall', + name: 'canisterCrossCanisterCall', test: async () => { const result = execSync( - `dfx canister call service serviceCrossCanisterCall '(service "${getCanisterId( - 'some_service' + `dfx canister call canister canisterCrossCanisterCall '(service "${getCanisterId( + 'some_canister' )}")'` ) .toString() .trim(); return { - Ok: result === '("SomeService update1")' + Ok: result === '("SomeCanister update1")' }; } } diff --git a/examples/service/tsconfig.json b/examples/canister/tsconfig.json similarity index 100% rename from examples/service/tsconfig.json rename to examples/canister/tsconfig.json diff --git a/examples/complex_init/src/index.ts b/examples/complex_init/src/index.ts index e3e82435d6..f1dc9f6126 100644 --- a/examples/complex_init/src/index.ts +++ b/examples/complex_init/src/index.ts @@ -1,4 +1,4 @@ -import { init, Opt, query, Record, Service, text, Tuple } from 'azle'; +import { Canister, init, Opt, query, Record, text, Tuple } from 'azle'; const User = Record({ id: text @@ -7,8 +7,7 @@ const User = Record({ let greeting: text = 'Hello User'; let user: Opt = []; -// TODO tuple types aren't done, they don't have TypeScript types -export default Service({ +export default Canister({ init: init([Tuple(text, User)], (tuple) => { greeting = tuple[0]; user = [tuple[1]]; diff --git a/examples/composite_queries/canisters/canister1/index.ts b/examples/composite_queries/canisters/canister1/index.ts index 97f43d5270..309cabb66c 100644 --- a/examples/composite_queries/canisters/canister1/index.ts +++ b/examples/composite_queries/canisters/canister1/index.ts @@ -1,11 +1,11 @@ import { + Canister, ic, init, Manual, nat, Principal, query, - Service, text, update } from 'azle'; @@ -20,7 +20,7 @@ const incCounter = query([], nat, async () => { return counter; }); -const service = Service({ +export default Canister({ init: init([], () => { canister2 = Canister2( Principal.fromText( @@ -67,7 +67,7 @@ const service = Service({ // Composite query calling queries on the same canister incCanister1: query([], nat, async () => { // TODO This is not an ideal solution but will work for now - const self = Service({ + const self = Canister({ incCounter })(ic.id()); @@ -88,5 +88,3 @@ const service = Service({ return counter + canister2AResult + canister2BResult; }) }); - -export default service; diff --git a/examples/composite_queries/canisters/canister2/index.ts b/examples/composite_queries/canisters/canister2/index.ts index 801031a1db..a92de92cf3 100644 --- a/examples/composite_queries/canisters/canister2/index.ts +++ b/examples/composite_queries/canisters/canister2/index.ts @@ -1,11 +1,11 @@ import { + Canister, ic, init, Manual, nat, Principal, query, - Service, text, update } from 'azle'; @@ -14,7 +14,7 @@ import Canister3 from '../canister3'; let canister3: typeof Canister3; let counter: nat = 0n; -export default Service({ +export default Canister({ init: init([], () => { canister3 = Canister3( Principal.fromText( diff --git a/examples/composite_queries/canisters/canister3/index.ts b/examples/composite_queries/canisters/canister3/index.ts index 09f6345349..79412aad61 100644 --- a/examples/composite_queries/canisters/canister3/index.ts +++ b/examples/composite_queries/canisters/canister3/index.ts @@ -1,6 +1,6 @@ -import { query, Service, text } from 'azle'; +import { Canister, query, text } from 'azle'; -export default Service({ +export default Canister({ deepQuery: query([], text, () => { return 'Hello from Canister 3'; }) diff --git a/examples/counter/src/index.ts b/examples/counter/src/index.ts index 4ede974d3d..0251b1159e 100644 --- a/examples/counter/src/index.ts +++ b/examples/counter/src/index.ts @@ -1,8 +1,8 @@ -import { nat64, query, Service, update } from 'azle'; +import { Canister, nat64, query, update } from 'azle'; let count: nat64 = 0n; -export default Service({ +export default Canister({ readCount: query([], nat64, () => { return count; }), diff --git a/examples/cross_canister_calls/canisters/canister1/index.ts b/examples/cross_canister_calls/canisters/canister1/index.ts index c145fe69a6..a000a7ee4c 100644 --- a/examples/cross_canister_calls/canisters/canister1/index.ts +++ b/examples/cross_canister_calls/canisters/canister1/index.ts @@ -1,10 +1,10 @@ import { + Canister, ic, init, nat64, Opt, Principal, - Service, text, update, Vec, @@ -15,7 +15,7 @@ import { Account, AccountArgs } from '../canister2/types'; let canister2: typeof Canister2; -export default Service({ +export default Canister({ init: init([], () => { canister2 = Canister2( Principal.fromText( diff --git a/examples/cross_canister_calls/canisters/canister2/index.ts b/examples/cross_canister_calls/canisters/canister2/index.ts index fbfc9dcd0e..941034695a 100644 --- a/examples/cross_canister_calls/canisters/canister2/index.ts +++ b/examples/cross_canister_calls/canisters/canister2/index.ts @@ -1,10 +1,10 @@ import { + Canister, ic, nat64, None, Opt, query, - Service, Some, text, update, @@ -23,7 +23,7 @@ let state: State = { notification: '' }; -export default Service({ +export default Canister({ transfer: update([text, text, nat64], nat64, (from, to, amount) => { const fromAccount: typeof Account | undefined = state.accounts[from]; if (fromAccount === undefined) { diff --git a/examples/cycles/canisters/cycles/index.ts b/examples/cycles/canisters/cycles/index.ts index ba36a6a3a1..a32a1e2f46 100644 --- a/examples/cycles/canisters/cycles/index.ts +++ b/examples/cycles/canisters/cycles/index.ts @@ -1,6 +1,6 @@ -import { ic, nat, nat64, query, Service, update } from 'azle'; +import { Canister, ic, nat, nat64, query, update } from 'azle'; -export default Service({ +export default Canister({ receiveCycles: update([], nat64, () => { return ic.msgCyclesAccept(ic.msgCyclesAvailable() / 2n); }), diff --git a/examples/cycles/canisters/intermediary/index.ts b/examples/cycles/canisters/intermediary/index.ts index a3f30483be..a58b8b032b 100644 --- a/examples/cycles/canisters/intermediary/index.ts +++ b/examples/cycles/canisters/intermediary/index.ts @@ -1,11 +1,11 @@ import { + Canister, ic, init, nat, nat64, Principal, query, - Service, update, Void } from 'azle'; @@ -13,7 +13,7 @@ import Cycles from '../cycles'; let cyclesCanister: typeof Cycles; -export default Service({ +export default Canister({ init: init([], () => { cyclesCanister = Cycles( Principal.fromText( diff --git a/examples/date/src/index.ts b/examples/date/src/index.ts index ecb930d0ad..8afde80654 100644 --- a/examples/date/src/index.ts +++ b/examples/date/src/index.ts @@ -1,6 +1,6 @@ -import { nat32, nat64, query, Service, text } from 'azle'; +import { Canister, nat32, nat64, query, text } from 'azle'; -export default Service({ +export default Canister({ getDate: query([text], nat32, (isoString) => { return new Date(isoString).getDate(); }), diff --git a/examples/ethereum_json_rpc/src/index.ts b/examples/ethereum_json_rpc/src/index.ts index ca027448b0..be3f8801e8 100644 --- a/examples/ethereum_json_rpc/src/index.ts +++ b/examples/ethereum_json_rpc/src/index.ts @@ -1,9 +1,9 @@ import { + Canister, ic, init, nat32, query, - Service, StableBTreeMap, text, update @@ -16,7 +16,7 @@ import { let stableStorage = StableBTreeMap(text, text, 0); -export default Service({ +export default Canister({ init: init([text], (ethereumUrl) => { stableStorage.insert('ethereumUrl', ethereumUrl); }), diff --git a/examples/guard_functions/src/index.ts b/examples/guard_functions/src/index.ts index 17971544c9..ecb9df1fe6 100644 --- a/examples/guard_functions/src/index.ts +++ b/examples/guard_functions/src/index.ts @@ -1,4 +1,4 @@ -import { bool, ic, Manual, nat32, query, Service, update } from 'azle'; +import { bool, Canister, ic, Manual, nat32, query, update } from 'azle'; import { allowAll, incrementCounterAndAllowAll, @@ -13,7 +13,7 @@ export let state = { heartbeatTick: 0 }; -export default Service({ +export default Canister({ getCounter: query([], nat32, () => { return state.counter; }), diff --git a/examples/heartbeat/src/heartbeat_async/index.ts b/examples/heartbeat/src/heartbeat_async/index.ts index 5a9da50bad..ea3097c7aa 100644 --- a/examples/heartbeat/src/heartbeat_async/index.ts +++ b/examples/heartbeat/src/heartbeat_async/index.ts @@ -1,9 +1,9 @@ -import { blob, ic, heartbeat, query, Service } from 'azle'; +import { blob, Canister, ic, heartbeat, query } from 'azle'; import { managementCanister } from 'azle/canisters/management'; let initialized: blob = Uint8Array.from([]); -export default Service({ +export default Canister({ heartbeat: heartbeat(async () => { const randomness = await ic.call(managementCanister.raw_rand); diff --git a/examples/heartbeat/src/heartbeat_sync/index.ts b/examples/heartbeat/src/heartbeat_sync/index.ts index 2220dd2ee1..d79d5218dc 100644 --- a/examples/heartbeat/src/heartbeat_sync/index.ts +++ b/examples/heartbeat/src/heartbeat_sync/index.ts @@ -1,8 +1,8 @@ -import { bool, heartbeat, query, Service } from 'azle'; +import { bool, Canister, heartbeat, query } from 'azle'; let initialized = false; -export default Service({ +export default Canister({ heartbeat: heartbeat(() => { initialized = true; console.log('heartbeat initialized', initialized); diff --git a/examples/ic_api/src/index.ts b/examples/ic_api/src/index.ts index 6756afa481..b39a95fa84 100644 --- a/examples/ic_api/src/index.ts +++ b/examples/ic_api/src/index.ts @@ -1,5 +1,6 @@ import { blob, + Canister, empty, ic, int8, @@ -8,10 +9,8 @@ import { nat32, nat64, Opt, - Principal, query, update, - Service, bool, text, principal, @@ -26,7 +25,7 @@ import { // string: text; // }; -export default Service({ +export default Canister({ // // returns the argument data as an array. // argDataZeroParams(): Vec { // return ic.argData(); diff --git a/examples/imports/src/index.ts b/examples/imports/src/index.ts index 6b8a64506a..5a6df45091 100644 --- a/examples/imports/src/index.ts +++ b/examples/imports/src/index.ts @@ -1,8 +1,8 @@ -import { query, int, Service, text } from 'azle'; +import { Canister, int, query, text } from 'azle'; import { one, two, three } from './library'; import { sha224 } from 'js-sha256'; -export default Service({ +export default Canister({ getOne: query([], text, () => { return one(); }), diff --git a/examples/init/src/index.ts b/examples/init/src/index.ts index 45d75cc059..1143e97148 100644 --- a/examples/init/src/index.ts +++ b/examples/init/src/index.ts @@ -1,4 +1,5 @@ import { + Canister, init, None, Null, @@ -7,7 +8,6 @@ import { Principal, query, Record, - Service, Some, text, Variant @@ -26,7 +26,7 @@ let user: Opt = None; let reaction: Opt = None; let owner: Opt = None; -export default Service({ +export default Canister({ init: init( [User, Reaction, principal], (initUser, initReaction, initOwner) => { diff --git a/examples/inspect_message/src/index.ts b/examples/inspect_message/src/index.ts index 127310617c..7482fecf52 100644 --- a/examples/inspect_message/src/index.ts +++ b/examples/inspect_message/src/index.ts @@ -1,6 +1,6 @@ -import { bool, ic, inspectMessage, Service, update } from 'azle'; +import { bool, Canister, ic, inspectMessage, update } from 'azle'; -export default Service({ +export default Canister({ inspectMessage: inspectMessage(() => { console.log('inspectMessage called'); diff --git a/examples/key_value_store/src/index.ts b/examples/key_value_store/src/index.ts index 4cbeb6709f..ec8660721c 100644 --- a/examples/key_value_store/src/index.ts +++ b/examples/key_value_store/src/index.ts @@ -1,8 +1,8 @@ -import { None, Opt, query, Service, Some, text, update, Void } from 'azle'; +import { Canister, None, Opt, query, Some, text, update, Void } from 'azle'; let store: Map = new Map(); -export default Service({ +export default Canister({ get: query([text], Opt(text), (key) => { const keyOrUndefined = store.get(key); diff --git a/examples/ledger_canister/canisters/ledger_canister/index.ts b/examples/ledger_canister/canisters/ledger_canister/index.ts index f45130e06b..69e715bc6d 100644 --- a/examples/ledger_canister/canisters/ledger_canister/index.ts +++ b/examples/ledger_canister/canisters/ledger_canister/index.ts @@ -1,4 +1,5 @@ import { + Canister, ic, init, nat32, @@ -8,7 +9,6 @@ import { principal, Principal, query, - Service, Some, text, update @@ -28,7 +28,7 @@ import { let icpCanister: typeof Ledger; -export default Service({ +export default Canister({ init: init([], () => { icpCanister = Ledger( Principal.fromText( diff --git a/examples/list_of_lists/src/index.ts b/examples/list_of_lists/src/index.ts index df607d344d..474f2054de 100644 --- a/examples/list_of_lists/src/index.ts +++ b/examples/list_of_lists/src/index.ts @@ -1,6 +1,7 @@ import { blob, bool, + Canister, empty, float32, float64, @@ -21,7 +22,6 @@ import { query, Record, reserved, - Service, text, Variant, Vec @@ -40,7 +40,7 @@ const State = Variant({ const BasicFunc = Func([text], text, 'query'); -export default Service({ +export default Canister({ listOfStringOne: query([Vec(text)], Vec(text), (param) => { return param; }), diff --git a/examples/management_canister/src/index.ts b/examples/management_canister/src/index.ts index cb3e4cb0b5..d0f51f95a0 100644 --- a/examples/management_canister/src/index.ts +++ b/examples/management_canister/src/index.ts @@ -3,13 +3,13 @@ import { blob, bool, + Canister, ic, nat, None, principal, Principal, query, - Service, Some, update } from 'azle'; @@ -29,7 +29,7 @@ let state: State = { createdCanisterId: Principal.fromText('aaaaa-aa') }; -export default Service({ +export default Canister({ executeCreateCanister: update([], CreateCanisterResult, async () => { const createCanisterResult = await ic.call( managementCanister.create_canister, diff --git a/examples/manual_reply/src/index.ts b/examples/manual_reply/src/index.ts index c1c2b6bcbc..8ef6a7eb15 100644 --- a/examples/manual_reply/src/index.ts +++ b/examples/manual_reply/src/index.ts @@ -1,6 +1,7 @@ import { blob, bool, + Canister, float32, ic, int, @@ -12,9 +13,7 @@ import { query, Record, reserved, - Service, text, - Tuple, update, Variant, Vec, @@ -62,7 +61,7 @@ const Element = Record({ state: State }); -export default Service({ +export default Canister({ // Updates manualUpdate: update( [text], diff --git a/examples/motoko_examples/calc/src/index.ts b/examples/motoko_examples/calc/src/index.ts index 2e49226add..7aea24e566 100644 --- a/examples/motoko_examples/calc/src/index.ts +++ b/examples/motoko_examples/calc/src/index.ts @@ -1,8 +1,8 @@ -import { int, None, Opt, Service, Some, update, Void } from 'azle'; +import { Canister, int, None, Opt, Some, update, Void } from 'azle'; let cell: int = 0n; -export default Service({ +export default Canister({ add: update([int], int, (n) => { cell += n; diff --git a/examples/motoko_examples/counter/src/index.ts b/examples/motoko_examples/counter/src/index.ts index 989f0daff2..5dadff756d 100644 --- a/examples/motoko_examples/counter/src/index.ts +++ b/examples/motoko_examples/counter/src/index.ts @@ -1,8 +1,8 @@ -import { nat, query, Service, update, Void } from 'azle'; +import { Canister, nat, query, update, Void } from 'azle'; let counter: nat = 0n; -export default Service({ +export default Canister({ get: query([], nat, () => { return counter; }), diff --git a/examples/motoko_examples/echo/src/index.ts b/examples/motoko_examples/echo/src/index.ts index 21723acb28..91c7d57595 100644 --- a/examples/motoko_examples/echo/src/index.ts +++ b/examples/motoko_examples/echo/src/index.ts @@ -1,6 +1,6 @@ -import { query, Service, text } from 'azle'; +import { Canister, query, text } from 'azle'; -export default Service({ +export default Canister({ say: query([text], text, (phrase) => { return phrase; }) diff --git a/examples/motoko_examples/factorial/src/index.ts b/examples/motoko_examples/factorial/src/index.ts index 5e2f112f86..e46971e6f2 100644 --- a/examples/motoko_examples/factorial/src/index.ts +++ b/examples/motoko_examples/factorial/src/index.ts @@ -1,6 +1,6 @@ -import { nat, Service, update } from 'azle'; +import { Canister, nat, update } from 'azle'; -export default Service({ +export default Canister({ // Calculate the product of all positive integers less than or equal to `n`. fac: update([nat], nat, (n) => { return go(n); diff --git a/examples/motoko_examples/hello-world/src/index.ts b/examples/motoko_examples/hello-world/src/index.ts index 20b07aaf0e..66621bb857 100644 --- a/examples/motoko_examples/hello-world/src/index.ts +++ b/examples/motoko_examples/hello-world/src/index.ts @@ -1,6 +1,6 @@ -import { query, Service, Void } from 'azle'; +import { Canister, query, Void } from 'azle'; -export default Service({ +export default Canister({ main: query([], Void, () => { console.log('Hello World!'); }) diff --git a/examples/motoko_examples/hello/src/hello/index.ts b/examples/motoko_examples/hello/src/hello/index.ts index b6a65ca074..ee6855686b 100644 --- a/examples/motoko_examples/hello/src/hello/index.ts +++ b/examples/motoko_examples/hello/src/hello/index.ts @@ -1,6 +1,6 @@ -import { query, Service, text } from 'azle'; +import { Canister, query, text } from 'azle'; -export default Service({ +export default Canister({ greet: query([text], text, (name) => { return `Hello, ${name}!`; }) diff --git a/examples/motoko_examples/http_counter/src/index.ts b/examples/motoko_examples/http_counter/src/index.ts index 6634ea591f..dfc5d2a69c 100644 --- a/examples/motoko_examples/http_counter/src/index.ts +++ b/examples/motoko_examples/http_counter/src/index.ts @@ -1,6 +1,7 @@ import { blob, bool, + Canister, Func, ic, init, @@ -10,7 +11,6 @@ import { Opt, query, Record, - Service, Some, StableBTreeMap, text, @@ -61,7 +61,7 @@ const HttpRequest = Record({ let stableStorage = StableBTreeMap(text, nat, 0); -export default Service({ +export default Canister({ init: init([], () => { stableStorage.insert('counter', 0n); }), diff --git a/examples/motoko_examples/minimal-counter-dapp/src/minimal_dapp/index.ts b/examples/motoko_examples/minimal-counter-dapp/src/minimal_dapp/index.ts index ecc2b4f330..69b888debf 100644 --- a/examples/motoko_examples/minimal-counter-dapp/src/minimal_dapp/index.ts +++ b/examples/motoko_examples/minimal-counter-dapp/src/minimal_dapp/index.ts @@ -1,8 +1,8 @@ -import { Service, nat, query, update } from 'azle'; +import { Canister, nat, query, update } from 'azle'; let counter: nat = 0n; -export default Service({ +export default Canister({ count: update([], nat, () => { counter += 1n; diff --git a/examples/motoko_examples/persistent-storage/src/index.ts b/examples/motoko_examples/persistent-storage/src/index.ts index 88cab41e04..081bafc679 100644 --- a/examples/motoko_examples/persistent-storage/src/index.ts +++ b/examples/motoko_examples/persistent-storage/src/index.ts @@ -1,11 +1,11 @@ import { bool, + Canister, ic, init, nat, postUpgrade, query, - Service, StableBTreeMap, text, update @@ -14,7 +14,7 @@ import { let stableStorage = StableBTreeMap(text, nat, 0); let redeployed = false; -export default Service({ +export default Canister({ init: init([], () => { stableStorage.insert('counter', 0n); }), diff --git a/examples/motoko_examples/phone-book/src/phone_book/index.ts b/examples/motoko_examples/phone-book/src/phone_book/index.ts index fcd5c82f7b..cb4d935f43 100644 --- a/examples/motoko_examples/phone-book/src/phone_book/index.ts +++ b/examples/motoko_examples/phone-book/src/phone_book/index.ts @@ -1,9 +1,9 @@ import { + Canister, None, Opt, query, Record, - Service, Some, text, update, @@ -17,7 +17,7 @@ export const Entry = Record({ let phoneBook = new Map(); -export default Service({ +export default Canister({ insert: update([text, Entry], Void, (name, entry) => { phoneBook.set(name, entry); }), diff --git a/examples/motoko_examples/quicksort/src/index.ts b/examples/motoko_examples/quicksort/src/index.ts index 950ae2be5c..d42c06b81a 100644 --- a/examples/motoko_examples/quicksort/src/index.ts +++ b/examples/motoko_examples/quicksort/src/index.ts @@ -1,8 +1,8 @@ -import { int, Vec, query, Service } from 'azle'; +import { Canister, int, Vec, query } from 'azle'; import { Int } from './comparison'; import * as Quicksort from './quicksort'; -export default Service({ +export default Canister({ sort: query([Vec(int)], Vec(int), (xs) => { return Quicksort.sortBy(xs, Int.compare); }) diff --git a/examples/motoko_examples/simple-to-do/src/index.ts b/examples/motoko_examples/simple-to-do/src/index.ts index a24558d7f2..49e5d952c5 100644 --- a/examples/motoko_examples/simple-to-do/src/index.ts +++ b/examples/motoko_examples/simple-to-do/src/index.ts @@ -1,9 +1,9 @@ import { bool, + Canister, nat, query, Record, - Service, text, update, Vec, @@ -18,7 +18,7 @@ export const ToDo = Record({ let todos: Map = new Map(); let nextId: nat = 0n; -export default Service({ +export default Canister({ getTodos: query([], Vec(ToDo), () => { return Array.from(todos.values()); }), diff --git a/examples/motoko_examples/superheroes/src/superheroes/index.ts b/examples/motoko_examples/superheroes/src/superheroes/index.ts index f9f4e78828..a46342a215 100644 --- a/examples/motoko_examples/superheroes/src/superheroes/index.ts +++ b/examples/motoko_examples/superheroes/src/superheroes/index.ts @@ -1,12 +1,12 @@ import { bool, + Canister, nat32, None, Opt, query, Record, Recursive, - Service, Some, text, Tuple, @@ -41,7 +41,7 @@ let superheroes: Map = new Map(); /** * High-Level API */ -export default Service({ +export default Canister({ // Create a superhero. create: update([Superhero], SuperheroId, (superhero) => { let superheroId = next; diff --git a/examples/motoko_examples/threshold_ecdsa/src/index.ts b/examples/motoko_examples/threshold_ecdsa/src/index.ts index b84a8c5998..bc52ebb770 100644 --- a/examples/motoko_examples/threshold_ecdsa/src/index.ts +++ b/examples/motoko_examples/threshold_ecdsa/src/index.ts @@ -1,4 +1,4 @@ -import { blob, ic, None, Record, Service, update } from 'azle'; +import { blob, Canister, ic, None, Record, update } from 'azle'; import { managementCanister } from 'azle/canisters/management'; const PublicKey = Record({ @@ -9,7 +9,7 @@ const Signature = Record({ signature: blob }); -export default Service({ +export default Canister({ publicKey: update([], PublicKey, async () => { const caller = ic.caller().toUint8Array(); diff --git a/examples/motoko_examples/whoami/src/index.ts b/examples/motoko_examples/whoami/src/index.ts index 5d6a8ddd45..d693a676a1 100644 --- a/examples/motoko_examples/whoami/src/index.ts +++ b/examples/motoko_examples/whoami/src/index.ts @@ -1,11 +1,11 @@ import { + Canister, ic, init, postUpgrade, principal, Principal, query, - Service, update } from 'azle'; @@ -17,7 +17,7 @@ const whoami = update([], principal, () => { return ic.caller(); }); -export default Service({ +export default Canister({ // Manually save the calling principal and argument for later access. init: init([principal], (somebody) => { install = ic.caller(); @@ -43,7 +43,7 @@ export default Service({ // Return the principal identifier of this canister. id: update([], principal, async () => { // TODO This is not an ideal solution but will work for now - const self = Service({ + const self = Canister({ whoami })(ic.id()); diff --git a/examples/notify_raw/canisters/canister1/index.ts b/examples/notify_raw/canisters/canister1/index.ts index 2b6cf4ae17..5517642cd4 100644 --- a/examples/notify_raw/canisters/canister1/index.ts +++ b/examples/notify_raw/canisters/canister1/index.ts @@ -1,6 +1,6 @@ -import { ic, Principal, Service, update, Void } from 'azle'; +import { Canister, ic, Principal, update, Void } from 'azle'; -export default Service({ +export default Canister({ sendNotification: update([], Void, () => { return ic.notifyRaw( Principal.fromText( diff --git a/examples/notify_raw/canisters/canister2/index.ts b/examples/notify_raw/canisters/canister2/index.ts index dc2581be94..b45bf9ac85 100644 --- a/examples/notify_raw/canisters/canister2/index.ts +++ b/examples/notify_raw/canisters/canister2/index.ts @@ -1,8 +1,8 @@ -import { bool, query, Service, update, Void } from 'azle'; +import { bool, Canister, query, update, Void } from 'azle'; let notified: boolean = false; -export default Service({ +export default Canister({ receiveNotification: update([], Void, () => { notified = true; }), diff --git a/examples/null_example/src/index.ts b/examples/null_example/src/index.ts index 6df8ab67fe..e53353e059 100644 --- a/examples/null_example/src/index.ts +++ b/examples/null_example/src/index.ts @@ -1,4 +1,4 @@ -import { ic, int, Null, query, Record, Service, update, Void } from 'azle'; +import { Canister, ic, int, Null, query, Record, update, Void } from 'azle'; const PartiallyNullRecord = Record({ firstItem: int, @@ -17,7 +17,7 @@ const ThreeNullRecord = Record({ thirdItem: Null }); -export default Service({ +export default Canister({ nullFunction: query([Null], Null, (param) => { return param; }), diff --git a/examples/optional_types/src/index.ts b/examples/optional_types/src/index.ts index 667e2b04be..aaaa6462ee 100644 --- a/examples/optional_types/src/index.ts +++ b/examples/optional_types/src/index.ts @@ -1,6 +1,6 @@ // TODO let's add more examples here, really test it out -import { bool, Null, Opt, query, Record, Service, text, Vec } from 'azle'; +import { bool, Canister, Null, Opt, query, Record, text, Vec } from 'azle'; const Element = Record({ id: text @@ -14,7 +14,7 @@ const Html = Record({ head: Opt(Head) }); -export default Service({ +export default Canister({ getHtml: query([], Html, () => { return { head: [] diff --git a/examples/outgoing_http_requests/src/index.ts b/examples/outgoing_http_requests/src/index.ts index 7ff6d68109..5d5624a21c 100644 --- a/examples/outgoing_http_requests/src/index.ts +++ b/examples/outgoing_http_requests/src/index.ts @@ -1,10 +1,10 @@ import { + Canister, ic, Manual, None, Principal, query, - Service, Some, update } from 'azle'; @@ -14,7 +14,7 @@ import { managementCanister } from 'azle/canisters/management'; -export default Service({ +export default Canister({ xkcd: update([], HttpResponse, async () => { return await ic.call(managementCanister.http_request, { args: [ diff --git a/examples/pre_and_post_upgrade/src/index.ts b/examples/pre_and_post_upgrade/src/index.ts index 2fbab823d1..0a6cfbc33e 100644 --- a/examples/pre_and_post_upgrade/src/index.ts +++ b/examples/pre_and_post_upgrade/src/index.ts @@ -1,11 +1,11 @@ import { + Canister, init, nat64, postUpgrade, preUpgrade, query, Record, - Service, StableBTreeMap, text, update, @@ -24,7 +24,7 @@ let entries: { [key: string]: nat64; } = {}; -export default Service({ +export default Canister({ init: init([], () => { console.log('init'); diff --git a/examples/primitive_types/src/index.ts b/examples/primitive_types/src/index.ts index d2ed955a3e..5e860f43be 100644 --- a/examples/primitive_types/src/index.ts +++ b/examples/primitive_types/src/index.ts @@ -1,5 +1,6 @@ import { bool, + Canister, empty, float32, float64, @@ -18,11 +19,10 @@ import { Principal, query, reserved, - Service, text } from 'azle'; -export default Service({ +export default Canister({ getString: query([], text, () => { return 'string'; }), diff --git a/examples/principal/src/index.ts b/examples/principal/src/index.ts index 66028d8a4c..34603f5207 100644 --- a/examples/principal/src/index.ts +++ b/examples/principal/src/index.ts @@ -1,11 +1,11 @@ import { blob, + Canister, Null, Principal, principal, query, Record, - Service, text, Variant } from 'azle'; @@ -21,7 +21,7 @@ const Status = Variant({ Offline: Null }); -export default Service({ +export default Canister({ principalReturnType: query([], principal, () => { return Principal.fromText('aaaaa-aa'); }), diff --git a/examples/query/src/index.ts b/examples/query/src/index.ts index 339988b81e..6f2e04e8ce 100644 --- a/examples/query/src/index.ts +++ b/examples/query/src/index.ts @@ -1,6 +1,6 @@ -import { query, Service, text } from 'azle'; +import { Canister, query, text } from 'azle'; -export default Service({ +export default Canister({ simpleQuery: query([], text, () => { return 'This is a query function'; }) diff --git a/examples/randomness/src/index.ts b/examples/randomness/src/index.ts index 1d0144ac75..b41f514d3b 100644 --- a/examples/randomness/src/index.ts +++ b/examples/randomness/src/index.ts @@ -1,8 +1,8 @@ -import { bool, float64, postUpgrade, query, Service, update } from 'azle'; +import { bool, Canister, float64, postUpgrade, query, update } from 'azle'; let redeployed = false; -export default Service({ +export default Canister({ postUpgrade: postUpgrade([], () => { redeployed = true; }), diff --git a/examples/rejections/canisters/rejections/index.ts b/examples/rejections/canisters/rejections/index.ts index 07beff84d1..e5016cebc4 100644 --- a/examples/rejections/canisters/rejections/index.ts +++ b/examples/rejections/canisters/rejections/index.ts @@ -1,28 +1,28 @@ import { + Canister, ic, init, Principal, RejectionCode, - Service, text, update, Void } from 'azle'; -import SomeService from '../some_service'; +import SomeCanister from '../some_canister'; -const Nonexistent = Service({ +const Nonexistent = Canister({ method: update([], Void) }); -let someService: typeof SomeService; +let someCanister: typeof SomeCanister; let nonexistentCanister: typeof Nonexistent; -export default Service({ +export default Canister({ init: init([], () => { - someService = SomeService( + someCanister = SomeCanister( Principal.fromText( - process.env.SOME_SERVICE_PRINCIPAL ?? - ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') + process.env.SOME_CANISTER_PRINCIPAL ?? + ic.trap('process.env.SOME_CANISTER_PRINCIPAL is undefined') ) ); @@ -31,7 +31,7 @@ export default Service({ ); }), getRejectionCodeNoError: update([], RejectionCode, async () => { - await ic.call(someService.accept); + await ic.call(someCanister.accept); return ic.rejectCode(); }), @@ -44,21 +44,21 @@ export default Service({ }), getRejectionCodeCanisterReject: update([], RejectionCode, async () => { try { - await ic.call(someService.reject, { args: ['reject'] }); + await ic.call(someCanister.reject, { args: ['reject'] }); } catch (error) {} return ic.rejectCode(); }), getRejectionCodeCanisterError: update([], RejectionCode, async () => { try { - await ic.call(someService.error); + await ic.call(someCanister.error); } catch (error) {} return ic.rejectCode(); }), getRejectionMessage: update([text], text, async (message: text) => { try { - await ic.call(someService.reject, { args: [message] }); + await ic.call(someCanister.reject, { args: [message] }); } catch (error) {} return ic.rejectMessage(); diff --git a/examples/rejections/canisters/some_service/index.did b/examples/rejections/canisters/some_canister/index.did similarity index 100% rename from examples/rejections/canisters/some_service/index.did rename to examples/rejections/canisters/some_canister/index.did diff --git a/examples/rejections/canisters/some_service/index.ts b/examples/rejections/canisters/some_canister/index.ts similarity index 81% rename from examples/rejections/canisters/some_service/index.ts rename to examples/rejections/canisters/some_canister/index.ts index b1e9544360..a8802683ce 100644 --- a/examples/rejections/canisters/some_service/index.ts +++ b/examples/rejections/canisters/some_canister/index.ts @@ -1,6 +1,6 @@ -import { bool, empty, ic, Manual, query, Service, text } from 'azle'; +import { bool, Canister, empty, ic, Manual, query, text } from 'azle'; -export default Service({ +export default Canister({ reject: query( [text], Manual(empty), diff --git a/examples/rejections/dfx.json b/examples/rejections/dfx.json index 651260f12f..e3c7053726 100644 --- a/examples/rejections/dfx.json +++ b/examples/rejections/dfx.json @@ -12,18 +12,18 @@ "output": "test/dfx_generated/rejections", "node_compatibility": true }, - "env": ["SOME_SERVICE_PRINCIPAL"] + "env": ["SOME_CANISTER_PRINCIPAL"] }, - "some_service": { + "some_canister": { "type": "custom", - "build": "npx azle some_service", - "root": "canisters/some_service", - "ts": "canisters/some_service/index.ts", - "candid": "canisters/some_service/index.did", - "wasm": ".azle/some_service/some_service.wasm", + "build": "npx azle some_canister", + "root": "canisters/some_canister", + "ts": "canisters/some_canister/index.ts", + "candid": "canisters/some_canister/index.did", + "wasm": ".azle/some_canister/some_canister.wasm", "gzip": true, "declarations": { - "output": "test/dfx_generated/some_service", + "output": "test/dfx_generated/some_canister", "node_compatibility": true } } diff --git a/examples/rejections/test/pretest.ts b/examples/rejections/test/pretest.ts index 6ddfac6ab5..2ae9ad0cb6 100644 --- a/examples/rejections/test/pretest.ts +++ b/examples/rejections/test/pretest.ts @@ -8,16 +8,16 @@ async function pretest() { stdio: 'inherit' }); - execSync(`dfx canister uninstall-code some_service || true`, { + execSync(`dfx canister uninstall-code some_canister || true`, { stdio: 'inherit' }); - execSync(`dfx canister create some_service`, { + execSync(`dfx canister create some_canister`, { stdio: 'inherit' }); execSync( - `SOME_SERVICE_PRINCIPAL=${getCanisterId('some_service')} dfx deploy`, + `SOME_CANISTER_PRINCIPAL=${getCanisterId('some_canister')} dfx deploy`, { stdio: 'inherit' } diff --git a/examples/robust_imports/src/azle_coverage/fruit.ts b/examples/robust_imports/src/azle_coverage/fruit.ts index 698b7013d6..8d113848b9 100644 --- a/examples/robust_imports/src/azle_coverage/fruit.ts +++ b/examples/robust_imports/src/azle_coverage/fruit.ts @@ -31,7 +31,7 @@ export { query as quince, Record as Raspberry, reserved as rambutan, - Service as Strawberry, + Canister as Strawberry, StableBTreeMap as Soncoya, text as tangerine, Tuple as Tamarind, diff --git a/examples/robust_imports/src/azle_coverage/index.ts b/examples/robust_imports/src/azle_coverage/index.ts index 2a5b2d992f..1954098317 100644 --- a/examples/robust_imports/src/azle_coverage/index.ts +++ b/examples/robust_imports/src/azle_coverage/index.ts @@ -41,7 +41,7 @@ import kiwi, { import { ic as lemon, int16 as coconut } from 'azle'; import * as starFruit from './fruit'; -const FruitDeliveryService = Strawberry({ +const FruitDeliveryCanister = Strawberry({ deliver: ugni([], tangerine), is_delivered: quince([], blackberry) }); @@ -173,11 +173,11 @@ export const addSigFigs = kiwi([fig32], fig64, (figs) => { return figs; }); -export const checkService = kiwi( - [FruitDeliveryService], - FruitDeliveryService, - (service) => { - return service; +export const checkCanister = kiwi( + [FruitDeliveryCanister], + FruitDeliveryCanister, + (canister) => { + return canister; } ); diff --git a/examples/robust_imports/src/import_coverage/index.ts b/examples/robust_imports/src/import_coverage/index.ts index 63e0a5bc2b..b29dad7f83 100644 --- a/examples/robust_imports/src/import_coverage/index.ts +++ b/examples/robust_imports/src/import_coverage/index.ts @@ -53,7 +53,7 @@ export const MyCavernousVariant = ic.CavernousVariant({ sixteen: ic.Null }); -const SomeService = ic.fathomlessService({ +const SomeCanister = ic.fathomlessCanister({ query1: ic.query([], ic.bool), update1: ic.azle.update([], ic.text) }); @@ -100,11 +100,11 @@ export const returnWeird = ic.azle.query([], ic.nat8, () => { return -10_000n; }); -export const returnFathomlessService = ic.azle.query( - [SomeService], - SomeService, - (service) => { - return service; +export const returnFathomlessCanister = ic.azle.query( + [SomeCanister], + SomeCanister, + (canister) => { + return canister; } ); diff --git a/examples/robust_imports/src/import_coverage/types.ts b/examples/robust_imports/src/import_coverage/types.ts index 291f7a74e7..a97737e857 100644 --- a/examples/robust_imports/src/import_coverage/types.ts +++ b/examples/robust_imports/src/import_coverage/types.ts @@ -111,7 +111,7 @@ export {}; export { DeepVariant }; export { ProfoundInt8 as DeepInt8 }; export { - deepDefault as fathomlessService, + deepDefault as fathomlessCanister, deepStar as fathomlessStar, DeepRecord as CoveredRecord, CavernousRecord, diff --git a/examples/robust_imports/src/index.did b/examples/robust_imports/src/index.did index 7bf8c3c211..87519fe4c8 100644 --- a/examples/robust_imports/src/index.did +++ b/examples/robust_imports/src/index.did @@ -27,11 +27,11 @@ service: () -> { 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; + returnFathomlessCanister: (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; + checkCanister: (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; @@ -58,7 +58,7 @@ service: () -> { simpleDeepQuery: () -> () query; simpleAzleQuery: () -> () query; simpleQuery: () -> () query; - checkServiceAlias: (service {testQuery:() -> (text) query}) -> (service {testQuery:() -> (text) query}) query; + checkCanisterAlias: (service {testQuery:() -> (text) query}) -> (service {testQuery:() -> (text) query}) query; getMyRecord: () -> (rec_15) query; getMyRecordAlias: () -> (rec_18) query; getSuperAlias: () -> (rec_21) query; diff --git a/examples/robust_imports/src/index.ts b/examples/robust_imports/src/index.ts index f261168770..ba63406a44 100644 --- a/examples/robust_imports/src/index.ts +++ b/examples/robust_imports/src/index.ts @@ -1,12 +1,12 @@ // Named Imports -import { Service } from 'azle'; +import { Canister } from 'azle'; import { myVariantToMyDeepVariant, myFathomlessVariantToMyCavernousVariant, returnVec, returnFathomlessVec, returnWeird, - returnFathomlessService, + returnFathomlessCanister, makeCavernousRecord, typeCheck } from './import_coverage'; @@ -17,7 +17,7 @@ import { buyHoneydew, keepIlamaClean, addSigFigs, - checkService, + checkCanister, checkWatermelonForSeeds, compareApplesToOranges, handleFarkleberries, @@ -46,7 +46,7 @@ import { simpleDeepQuery, simpleAzleQuery, simpleQuery, - checkServiceAlias, + checkCanisterAlias, getMyRecord, getMyRecordAlias, getSuperAlias, @@ -60,13 +60,13 @@ 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({ +export default Canister({ myVariantToMyDeepVariant, myFathomlessVariantToMyCavernousVariant, returnVec, returnFathomlessVec, returnWeird, - returnFathomlessService, + returnFathomlessCanister, makeCavernousRecord, typeCheck, collectIcaco, @@ -75,7 +75,7 @@ export default Service({ buyHoneydew, keepIlamaClean, addSigFigs, - checkService, + checkCanister, checkWatermelonForSeeds, compareApplesToOranges, handleFarkleberries, @@ -102,7 +102,7 @@ export default Service({ simpleDeepQuery, simpleAzleQuery, simpleQuery, - checkServiceAlias, + checkCanisterAlias, getMyRecord, getMyRecordAlias, getSuperAlias, diff --git a/examples/robust_imports/src/type_alias_decls/index.ts b/examples/robust_imports/src/type_alias_decls/index.ts index 56f68d599d..5df9664099 100644 --- a/examples/robust_imports/src/type_alias_decls/index.ts +++ b/examples/robust_imports/src/type_alias_decls/index.ts @@ -123,17 +123,17 @@ export const simpleQuery = types.$queryAlias([], types.VoidAlias, () => { console.log(HELLO_WORLD); }); -const AliasedService = types.DeepServiceAlias({ +const AliasedCanister = types.DeepCanisterAlias({ testQuery: types.$queryAlias([], azle.text) }); -export const AliasedServiceAlias = AliasedService; +export const AliasedCanisterAlias = AliasedCanister; -export const checkServiceAlias = azle.query( - [AliasedService], - AliasedService, - (service) => { - return service; +export const checkCanisterAlias = azle.query( + [AliasedCanister], + AliasedCanister, + (canister) => { + return canister; } ); diff --git a/examples/robust_imports/src/type_alias_decls/types.ts b/examples/robust_imports/src/type_alias_decls/types.ts index 85ab51b7d1..62d8f70f11 100644 --- a/examples/robust_imports/src/type_alias_decls/types.ts +++ b/examples/robust_imports/src/type_alias_decls/types.ts @@ -61,7 +61,8 @@ 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 DeepCanisterAlias = + deep.deepAlias.deeperAlias.deepestAlias.Canister; export const DeepStableBTreeMapAlias = deep.deepAlias.deeperAlias.deepestAlias.StableBTreeMap; export const DeepTextAlias = deep.deepAlias.deeperAlias.deepestAlias.text; diff --git a/examples/robust_imports/src/types/deep/shallow.ts b/examples/robust_imports/src/types/deep/shallow.ts index bc13dd2b33..5bdd3f3925 100644 --- a/examples/robust_imports/src/types/deep/shallow.ts +++ b/examples/robust_imports/src/types/deep/shallow.ts @@ -1,2 +1,2 @@ -import { Service } from 'azle'; -export default Service; +import { Canister } from 'azle'; +export default Canister; diff --git a/examples/robust_imports/test/tests.ts b/examples/robust_imports/test/tests.ts index 3e38cc7f97..31ada846db 100644 --- a/examples/robust_imports/test/tests.ts +++ b/examples/robust_imports/test/tests.ts @@ -79,10 +79,10 @@ function getImportCoverageTests(ic: ActorSubclass<_SERVICE>): Test[] { } }, { - name: 'returnFathomlessService', + name: 'returnFathomlessCanister', test: async () => { const result = execSync( - `dfx canister call robust_imports returnFathomlessService '(service "aaaaa-aa")'` + `dfx canister call robust_imports returnFathomlessCanister '(service "aaaaa-aa")'` ) .toString() .trim(); @@ -152,10 +152,10 @@ function getAzleCoverageTests(fruit: ActorSubclass<_SERVICE>): Test[] { } }, { - name: 'check service', + name: 'check canister', test: async () => { const result = execSync( - `dfx canister call robust_imports checkService '(service "aaaaa-aa")'` + `dfx canister call robust_imports checkCanister '(service "aaaaa-aa")'` ) .toString() .trim(); @@ -441,10 +441,10 @@ function getTypeAliasDeclTests(canister: ActorSubclass<_SERVICE>): Test[] { } }, { - name: 'check service alias', + name: 'check canister alias', test: async () => { const result = execSync( - `dfx canister call robust_imports checkServiceAlias '(service "aaaaa-aa")'` + `dfx canister call robust_imports checkCanisterAlias '(service "aaaaa-aa")'` ) .toString() .trim(); diff --git a/examples/service/dfx.json b/examples/service/dfx.json deleted file mode 100644 index ce6a67c9ea..0000000000 --- a/examples/service/dfx.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "canisters": { - "service": { - "type": "custom", - "build": "npx azle service", - "root": "src", - "ts": "src/index.ts", - "candid": "src/index.did", - "wasm": ".azle/service/service.wasm", - "gzip": true, - "declarations": { - "output": "test/dfx_generated/service", - "node_compatibility": true - }, - "env": ["SOME_SERVICE_PRINCIPAL"] - }, - "some_service": { - "type": "custom", - "build": "npx azle some_service", - "root": "src", - "ts": "src/some_service.ts", - "candid": "src/some_service.did", - "wasm": ".azle/some_service/some_service.wasm", - "gzip": true, - "declarations": { - "output": "test/dfx_generated/some_service", - "node_compatibility": true - } - } - } -} diff --git a/examples/service/src/index.did b/examples/service/src/index.did deleted file mode 100644 index 72535f4276..0000000000 --- a/examples/service/src/index.did +++ /dev/null @@ -1,8 +0,0 @@ -type rec_0 = record {someService:service {query1:() -> (bool) query; update1:() -> (text) }}; -service: () -> { - serviceParam: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; - serviceReturnType: () -> (service {query1:() -> (bool) query; update1:() -> (text) }) query; - serviceNestedReturnType: () -> (rec_0); - serviceList: (vec service {query1:() -> (bool) query; update1:() -> (text) }) -> (vec service {query1:() -> (bool) query; update1:() -> (text) }); - serviceCrossCanisterCall: (service {query1:() -> (bool) query; update1:() -> (text) }) -> (text); -} diff --git a/examples/service/src/index.ts b/examples/service/src/index.ts deleted file mode 100644 index c62cbb1770..0000000000 --- a/examples/service/src/index.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { ic, Principal, query, Record, Service, text, update, Vec } from 'azle'; -import SomeService from './some_service'; - -const Wrapper = Record({ - someService: SomeService -}); - -export default Service({ - serviceParam: query([SomeService], SomeService, (someService) => { - return someService; - }), - serviceReturnType: query([], SomeService, () => { - return SomeService( - Principal.fromText( - process.env.SOME_SERVICE_PRINCIPAL ?? - ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') - ) - ); - }), - serviceNestedReturnType: update([], Wrapper, () => { - return { - someService: SomeService( - Principal.fromText( - process.env.SOME_SERVICE_PRINCIPAL ?? - ic.trap( - 'process.env.SOME_SERVICE_PRINCIPAL is undefined' - ) - ) - ) - }; - }), - serviceList: update( - [Vec(SomeService)], - Vec(SomeService), - (someServices) => { - return someServices; - } - ), - serviceCrossCanisterCall: update( - [SomeService], - text, - async (someService) => { - return await ic.call(someService.update1); - } - ) -}); diff --git a/examples/service/src/some_service.ts b/examples/service/src/some_service.ts deleted file mode 100644 index 39a9a7e74c..0000000000 --- a/examples/service/src/some_service.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { bool, query, Service, text, update } from 'azle'; - -export default Service({ - query1: query([], bool, () => { - return true; - }), - update1: update([], text, () => { - return 'SomeService update1'; - }) -}); diff --git a/examples/service/test/test.ts b/examples/service/test/test.ts deleted file mode 100644 index 34160f9c5d..0000000000 --- a/examples/service/test/test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getCanisterId, runTests } from 'azle/test'; -import { createActor } from '../test/dfx_generated/service'; -import { getTests } from './tests'; - -const serviceCanister = createActor(getCanisterId('service'), { - agentOptions: { - host: 'http://127.0.0.1:8000' - } -}); - -runTests(getTests(serviceCanister)); diff --git a/examples/simple_erc20/src/index.ts b/examples/simple_erc20/src/index.ts index ca2c2949c0..ddb308aa9b 100644 --- a/examples/simple_erc20/src/index.ts +++ b/examples/simple_erc20/src/index.ts @@ -1,4 +1,4 @@ -import { bool, nat64, query, Service, text, update } from 'azle'; +import { bool, Canister, nat64, query, text, update } from 'azle'; type Account = { address: string; @@ -21,7 +21,7 @@ let state: State = { totalSupply: 0n }; -export default Service({ +export default Canister({ initializeSupply: update( [text, text, text, nat64], bool, diff --git a/examples/simple_user_accounts/src/index.ts b/examples/simple_user_accounts/src/index.ts index 9b532416aa..7ce98dba36 100644 --- a/examples/simple_user_accounts/src/index.ts +++ b/examples/simple_user_accounts/src/index.ts @@ -1,9 +1,9 @@ import { + Canister, None, Opt, query, Record, - Service, Some, text, update, @@ -25,7 +25,7 @@ const User = Record({ username: text }); -export default Service({ +export default Canister({ getUserById: query([text], Opt(User), (id) => { const userOrUndefined = db.users[id]; return userOrUndefined ? Some(userOrUndefined) : None; diff --git a/examples/stable_memory/src/index.ts b/examples/stable_memory/src/index.ts index aef3b7e2bf..a1ea822675 100644 --- a/examples/stable_memory/src/index.ts +++ b/examples/stable_memory/src/index.ts @@ -1,6 +1,6 @@ -import { blob, ic, nat32, nat64, query, Service, update, Void } from 'azle'; +import { blob, Canister, ic, nat32, nat64, query, update, Void } from 'azle'; -export default Service({ +export default Canister({ stableSize: query([], nat32, () => { return ic.stableSize(); }), diff --git a/examples/stable_structures/src/canister1/index.ts b/examples/stable_structures/src/canister1/index.ts index f02334b584..6cbb2e90dd 100644 --- a/examples/stable_structures/src/canister1/index.ts +++ b/examples/stable_structures/src/canister1/index.ts @@ -1,4 +1,4 @@ -import { Service, bool, postUpgrade, query } from 'azle'; +import { bool, Canister, postUpgrade, query } from 'azle'; import { stableMap0Methods } from './stable_map_0'; import { stableMap1Methods } from './stable_map_1'; import { stableMap2Methods } from './stable_map_2'; @@ -7,7 +7,7 @@ import { stableMap4Methods } from './stable_map_4'; let redeployed = false; -export default Service({ +export default Canister({ postUpgrade: postUpgrade([], () => { redeployed = true; }), diff --git a/examples/stable_structures/src/canister2/index.ts b/examples/stable_structures/src/canister2/index.ts index 3e55a41f3d..ab3db1f8da 100644 --- a/examples/stable_structures/src/canister2/index.ts +++ b/examples/stable_structures/src/canister2/index.ts @@ -1,4 +1,4 @@ -import { Service, bool, postUpgrade, query } from 'azle'; +import { bool, Canister, postUpgrade, query } from 'azle'; import { stableMap5Methods } from './stable_map_5'; import { stableMap6Methods } from './stable_map_6'; import { stableMap7Methods } from './stable_map_7'; @@ -7,7 +7,7 @@ import { stableMap9Methods } from './stable_map_9'; let redeployed = false; -export default Service({ +export default Canister({ postUpgrade: postUpgrade([], () => { redeployed = true; }), diff --git a/examples/stable_structures/src/canister3/index.ts b/examples/stable_structures/src/canister3/index.ts index 609149a9b9..d456906b3a 100644 --- a/examples/stable_structures/src/canister3/index.ts +++ b/examples/stable_structures/src/canister3/index.ts @@ -1,4 +1,4 @@ -import { Service, bool, postUpgrade, query } from 'azle'; +import { bool, Canister, postUpgrade, query } from 'azle'; import { stableMap10Methods } from './stable_map_10'; import { stableMap11Methods } from './stable_map_11'; @@ -7,7 +7,7 @@ import { stableMap13Methods } from './stable_map_13'; let redeployed = false; -export default Service({ +export default Canister({ postUpgrade: postUpgrade([], () => { redeployed = true; }), diff --git a/examples/timers/src/timers.ts b/examples/timers/src/timers.ts index 9646fada1e..95ffd9811d 100644 --- a/examples/timers/src/timers.ts +++ b/examples/timers/src/timers.ts @@ -1,12 +1,12 @@ import { blob, bool, + Canister, Duration, ic, int8, query, Record, - Service, text, TimerId, update, @@ -41,7 +41,7 @@ let statusReport: typeof StatusReport = { repeatCrossCanister: Uint8Array.from([]) }; -export default Service({ +export default Canister({ clearTimer: update([TimerId], Void, (timerId) => { ic.clearTimer(timerId); console.log(`timer ${timerId} cancelled`); diff --git a/examples/update/src/index.ts b/examples/update/src/index.ts index e53ee6478e..f00940b92f 100644 --- a/examples/update/src/index.ts +++ b/examples/update/src/index.ts @@ -1,8 +1,8 @@ -import { query, Service, text, update, Void } from 'azle'; +import { Canister, query, text, update, Void } from 'azle'; let currentMessage: string = ''; -export default Service({ +export default Canister({ getCurrentMessage: query([], text, () => { return currentMessage; }), diff --git a/src/lib_functional/candid/index.ts b/src/lib_functional/candid/index.ts index adb5c74671..868d6e968e 100644 --- a/src/lib_functional/candid/index.ts +++ b/src/lib_functional/candid/index.ts @@ -45,7 +45,9 @@ import { Tuple } from '../../lib_new'; -export type TypeMapping = T extends IDL.TextClass +export type TypeMapping = T extends () => any + ? ReturnType + : T extends IDL.TextClass ? string : T extends AzleBool ? bool @@ -75,13 +77,9 @@ export type TypeMapping = T extends IDL.TextClass ? float32 : T extends never[] ? void - : T extends AzleTuple - ? any - : // : T extends AzleTuple<[infer U]> - // ? [TypeMapping] - // : T extends AzleTuple<[infer U, infer W]> - // ? [TypeMapping, TypeMapping] - T extends AzleVec + : T extends AzleTuple + ? { [K in keyof U]: TypeMapping } + : T extends AzleVec ? TypeMapping[] : T extends AzleOpt ? [TypeMapping] | [] diff --git a/src/lib_functional/candid/reference/service.ts b/src/lib_functional/candid/reference/service.ts index d10beb45db..bf7ab2049f 100644 --- a/src/lib_functional/candid/reference/service.ts +++ b/src/lib_functional/candid/reference/service.ts @@ -12,11 +12,11 @@ import { } from '../../../lib_new/utils'; import { CanisterMethodInfo } from '../../canister_methods'; -type ServiceOptions = { +type CanisterOptions = { [key: string]: CanisterMethodInfo; }; -type ServiceReturn = { +type CanisterReturn = { [EndpointName in keyof T]: T[EndpointName] extends CanisterMethodInfo< infer Params, infer Return @@ -27,11 +27,11 @@ type ServiceReturn = { : never; }; -type CallableObject = { +type CallableObject = { (principal: Principal): CallableObject; -} & ServiceReturn; +} & CanisterReturn; -export function Service( +export function Canister( serviceOptions: T ): CallableObject { const callbacks = Object.entries(serviceOptions).reduce((acc, entry) => { diff --git a/src/lib_new/primitives.ts b/src/lib_new/primitives.ts index 73293015cc..f9dcf8bcb0 100644 --- a/src/lib_new/primitives.ts +++ b/src/lib_new/primitives.ts @@ -214,7 +214,7 @@ export class AzleVec { } } -export class AzleTuple { +export class AzleTuple { constructor(t: CandidClass[]) { this._azleTypes = t; } @@ -233,7 +233,7 @@ export function Vec(t: T): AzleVec { } // TODO I am not sure of any of these types... but its working so... -export function Tuple(...types: any[]): AzleTuple { +export function Tuple(...types: T): AzleTuple { // const idlTypes = types.map((value) => { // return toIDLType(value); // });