Skip to content

Commit

Permalink
rename properties to not have _azle where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Oct 18, 2023
1 parent 17880ca commit 0e7ae9d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
12 changes: 6 additions & 6 deletions src/lib/candid/recursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { CandidType, Parent } from './index';

export type _AzleRecursiveFunction = {
(...args: any[]): CandidType;
_azleName?: string;
_azleIsRecursive?: boolean;
azleName?: string;
isRecursive?: boolean;
getIdl?: (parents: Parent[]) => IDL.Type<any>;
};

Expand All @@ -14,18 +14,18 @@ export function Recursive(candidTypeCallback: any): any {

let result: _AzleRecursiveFunction = (...args: any[]) => {
const candidType = candidTypeCallback();
if (candidType._azleIsCanister) {
if (candidType.isCanister) {
return candidType(...args);
}
return candidType;
};

result._azleName = name;
result._azleIsRecursive = true;
result.azleName = name;
result.isRecursive = true;
result.getIdl = (parents: Parent[]) => {
const idl = IDL.Rec();
let filler = candidTypeCallback();
if (filler._azleIsCanister) {
if (filler.isCanister) {
filler = filler(result);
}
idl.fill(filler.getIdl([...parents, { idl: idl, name }]));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/candid/serde/visitors/decode_visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class DecodeVisitor extends IDL.Visitor<VisitorData, VisitorResult> {

const candid = ty.accept(this, {
js_data: data.js_data[0],
candidType: data.candidType._azleType
candidType: data.candidType.innerType
});

return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/candid/serde/visitors/encode_visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class EncodeVisitor extends IDL.Visitor<VisitorData, VisitorResult> {
if ('Some' in data.js_data) {
const candid = ty.accept(this, {
js_data: data.js_data.Some,
candidType: data.candidType._azleType
candidType: data.candidType.innerType
});

return [candid];
Expand Down
10 changes: 5 additions & 5 deletions src/lib/candid/serde/visitors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function visitTuple(
const fields = components.map((value, index) =>
value.accept(visitor, {
js_data: data.js_data[index],
candidType: data.candidType._azleTypes[index]
candidType: data.candidType.innerTypes[index]
})
);
return [...fields];
Expand All @@ -47,7 +47,7 @@ export function visitVec(
return data.js_data.map((array_elem: any) => {
return ty.accept(visitor, {
js_data: array_elem,
candidType: data.candidType._azleType
candidType: data.candidType.innerType
});
});
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export function visitRec<T>(
data: VisitorData
): VisitorResult {
let candidType = data.candidType();
if (candidType._azleIsCanister) {
if (candidType.isCanister) {
candidType = candidType([]);
}
return ty.accept(visitor, {
Expand All @@ -108,7 +108,7 @@ function visitAzleResult(
const OK_FIELD_INDEX = 0;
const okField = fields[OK_FIELD_INDEX];
const okData = data.js_data['Ok'];
const okClass = data.candidType._azleOk;
const okClass = data.candidType.Ok;

return Result.Ok(
okField[1].accept(visitor, {
Expand All @@ -121,7 +121,7 @@ function visitAzleResult(
const ERR_FIELD_INDEX = 1;
const errField = fields[ERR_FIELD_INDEX];
const errData = data.js_data['Err'];
const errClass = data.candidType._azleErr;
const errClass = data.candidType.Err;
return Result.Err(
errField[1].accept(visitor, {
js_data: errData,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/candid/to_Idl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export function toIdl(
candidType: CandidType,
parents: Parent[] = []
): IDL.Type<any> {
if ('_azleName' in candidType) {
if ('azleName' in candidType) {
const parent = parents.find(
(parent) => parent.name === candidType._azleName
(parent) => parent.name === candidType.azleName
);
// If the parent isn't undefined (ie we found one with the same name)
// this is a recursive type and we should return the parent rec idl
Expand All @@ -21,7 +21,7 @@ export function toIdl(
return parent.idl;
}
}
if ('_azleIsCanister' in candidType && candidType._azleIsCanister) {
if ('isCanister' in candidType && candidType.isCanister) {
return toIdl((candidType as any)(), parents);
}
// All CandidTypes ought to have a getIdl function defined for them
Expand Down
6 changes: 3 additions & 3 deletions src/lib/candid/types/constructed/opt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export function Opt<T>(t: T): AzleOpt<T> {

export class AzleOpt<T> {
constructor(t: any) {
this._azleType = t;
this.innerType = t;
}

_azleType: CandidType;
innerType: CandidType;
_azleCandidType?: '_azleCandidType';
_kind: 'AzleOpt' = 'AzleOpt';

getIdl(parents: Parent[]) {
return IDL.Opt(toIdl(this._azleType, parents));
return IDL.Opt(toIdl(this.innerType, parents));
}
}
6 changes: 3 additions & 3 deletions src/lib/candid/types/constructed/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { IDL } from '@dfinity/candid';

export class AzleTuple<T extends any[]> {
constructor(t: CandidType[]) {
this._azleTypes = t;
this.innerTypes = t;
}

_azleTypes: CandidType[];
innerTypes: CandidType[];
_azleCandidType?: '_azleCandidType';

getIdl(parents: Parent[]) {
const idls = this._azleTypes.map((value) => {
const idls = this.innerTypes.map((value) => {
return toIdl(value, parents);
});
return IDL.Tuple(...idls);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/candid/types/constructed/vec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { IDL } from '@dfinity/candid';

export class AzleVec<T> {
constructor(t: any) {
this._azleType = t;
this.innerType = t;
}

_azleType: CandidType;
innerType: CandidType;
_azleCandidType?: '_azleCandidType';

getIdl(parents: Parent[]) {
return IDL.Vec(toIdl(this._azleType, parents));
return IDL.Vec(toIdl(this.innerType, parents));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/candid/types/reference/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CallableObject<T extends CanisterOptions> = {

type _AzleCanisterReturnType = {
(parentOrPrincipal: _AzleRecursiveFunction | Principal): void;
_azleIsCanister?: boolean;
isCanister?: boolean;
};

export function Canister<T extends CanisterOptions>(
Expand All @@ -40,6 +40,6 @@ export function Canister<T extends CanisterOptions>(

return canisterFunction;
};
result._azleIsCanister = true;
result.isCanister = true;
return result as any;
}
16 changes: 8 additions & 8 deletions src/lib/system_types/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { Parent, toIdl, CandidType } from '../candid';
import { RequireExactlyOne } from '../candid/types/constructed/variant';
import { IDL } from '@dfinity/candid';

export class AzleResult<T, K> {
constructor(ok: any, err: any) {
this._azleOk = ok;
this._azleErr = err;
export class AzleResult<T extends CandidType, K extends CandidType> {
constructor(ok: T, err: K) {
this.Ok = ok;
this.Err = err;
}

_azleOk: any;
_azleErr: any;
Ok: T;
Err: K;

_azleCandidType?: '_azleCandidType';

getIdl(parents: Parent[]) {
return IDL.Variant({
Ok: toIdl(this._azleOk, parents),
Err: toIdl(this._azleErr, parents)
Ok: toIdl(this.Ok, parents),
Err: toIdl(this.Err, parents)
});
}
}
Expand Down

0 comments on commit 0e7ae9d

Please sign in to comment.