Skip to content

Commit

Permalink
update to Canister from Service
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Sep 28, 2023
1 parent 6d157eb commit 9515e98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions examples/recursion/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
None,
Principal,
query,
Service,
Canister,
Some,
text,
Tuple,
Expand Down Expand Up @@ -35,15 +35,15 @@ const myTupleVar = Variant({ num: int8, varTuple: varTuple });
// Vec can't be recursive by itself. At the end of it all it needs to have a concrete type.
// Opt
// Service
const myService = Recursive(() =>
Service({
serviceQuery: query([myService], myService, (param) => param)
const MyCanister = Recursive(() =>
Canister({
myQuery: query([MyCanister], MyCanister, (param) => param)
})
);
// Func
const myFunc = Recursive(() => Func([myFunc], myFunc, 'query'));

export default Service({
export default Canister({
testRecRecordWithOpt: query([optRecord], optRecord, (param) => param),
testRecRecordWithVec: query([vecRecord], vecRecord, (param) => param),
testRecRecordWithVariant: query([varRecord], varRecord, (param) => param),
Expand Down
13 changes: 8 additions & 5 deletions src/lib_new/method_decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
toReturnIDLType,
CandidTypesDefs,
CandidDef,
extractCandid
extractCandid,
Parent
} from './utils';
import { display } from './utils';
import {
Expand Down Expand Up @@ -181,18 +182,20 @@ export function newTypesToStingArr(newTypes: CandidTypesDefs): string[] {
}

export function handleRecursiveParams(
idls: CandidClass[]
idls: CandidClass[],
parents: Parent[] = []
): [IDL.Type<any>[], CandidDef[], CandidTypesDefs] {
const paramIdls = toParamIDLTypes(idls);
const paramIdls = toParamIDLTypes(idls, parents);
const paramInfo = paramIdls.map((paramIdl) => display(paramIdl, {}));
return [paramIdls, ...extractCandid(paramInfo, {})];
}

export function handleRecursiveReturn(
returnIdl: ReturnCandidClass,
paramCandidTypeDefs: CandidTypesDefs
paramCandidTypeDefs: CandidTypesDefs,
parents: Parent[] = []
): [IDL.Type<any>[], CandidDef[], CandidTypesDefs] {
const returnIdls = toReturnIDLType(returnIdl);
const returnIdls = toReturnIDLType(returnIdl, parents);
const returnInfo = returnIdls.map((returnIdl) => display(returnIdl, {}));
return [returnIdls, ...extractCandid(returnInfo, paramCandidTypeDefs)];
}
Expand Down

0 comments on commit 9515e98

Please sign in to comment.