From 63a6d54c63b6033ebe019e681d3dda68989a7be2 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 2 Oct 2023 21:27:43 -0600 Subject: [PATCH] pr fixes --- examples/inspect_message/src/index.did | 2 +- .../generate_candid_and_canister_methods.ts | 2 +- src/lib/{ => candid}/did_visitor.ts | 0 src/lib/candid/index.ts | 77 +++++++------------ .../primitive/floating_point_numbers.ts | 24 ------ src/lib/candid/primitive/integer_numbers.ts | 57 -------------- src/lib/candid/primitive/natural_numbers.ts | 57 -------------- src/lib/candid/{reference => }/recursive.ts | 2 +- src/lib/candid/serde/index.ts | 7 +- .../candid/serde/visitors/decode_visitor.ts | 4 +- .../candid/serde/visitors/encode_visitor.ts | 2 +- src/lib/candid/serde/visitors/index.ts | 2 +- .../candid/{ => types}/constructed/blob.ts | 2 +- .../candid/{ => types}/constructed/index.ts | 3 +- .../candid/{ => types}/constructed/option.ts | 5 +- .../candid/{ => types}/constructed/record.ts | 5 +- .../candid/{ => types}/constructed/tuple.ts | 5 +- .../index.ts => types/constructed/variant.ts} | 7 +- .../candid/{ => types}/constructed/vector.ts | 5 +- src/lib/candid/{ => types}/primitive/bool.ts | 2 +- src/lib/candid/{ => types}/primitive/empty.ts | 2 +- .../candid/types/primitive/floats/float32.ts | 13 ++++ .../candid/types/primitive/floats/float64.ts | 13 ++++ .../candid/types/primitive/floats/index.ts | 2 + src/lib/candid/{ => types}/primitive/index.ts | 6 +- src/lib/candid/types/primitive/ints/index.ts | 5 ++ src/lib/candid/types/primitive/ints/int.ts | 13 ++++ src/lib/candid/types/primitive/ints/int16.ts | 12 +++ src/lib/candid/types/primitive/ints/int32.ts | 12 +++ src/lib/candid/types/primitive/ints/int64.ts | 12 +++ src/lib/candid/types/primitive/ints/int8.ts | 13 ++++ src/lib/candid/types/primitive/nats/index.ts | 5 ++ src/lib/candid/types/primitive/nats/nat.ts | 13 ++++ src/lib/candid/types/primitive/nats/nat16.ts | 13 ++++ src/lib/candid/types/primitive/nats/nat32.ts | 12 +++ src/lib/candid/types/primitive/nats/nat64.ts | 12 +++ src/lib/candid/types/primitive/nats/nat8.ts | 13 ++++ src/lib/candid/{ => types}/primitive/null.ts | 2 +- .../candid/{ => types}/primitive/reserved.ts | 2 +- src/lib/candid/{ => types}/primitive/text.ts | 2 +- src/lib/candid/{ => types}/primitive/void.ts | 0 src/lib/candid/{ => types}/reference/func.ts | 12 +-- src/lib/candid/{ => types}/reference/index.ts | 1 - .../candid/{ => types}/reference/principal.ts | 2 +- .../candid/{ => types}/reference/service.ts | 14 ++-- src/lib/canister_methods/index.ts | 9 ++- src/lib/ic/accept_message.ts | 5 ++ src/lib/{ic.ts => ic/index.ts} | 41 ++++------ src/lib/ic/stable_read.ts | 9 +++ src/lib/stable_b_tree_map.ts | 16 ++-- src/lib/system_types/index.ts | 2 + .../rejection_code.ts | 4 +- .../variant => system_types}/result.ts | 5 +- 53 files changed, 285 insertions(+), 282 deletions(-) rename src/lib/{ => candid}/did_visitor.ts (100%) delete mode 100644 src/lib/candid/primitive/floating_point_numbers.ts delete mode 100644 src/lib/candid/primitive/integer_numbers.ts delete mode 100644 src/lib/candid/primitive/natural_numbers.ts rename src/lib/candid/{reference => }/recursive.ts (94%) rename src/lib/candid/{ => types}/constructed/blob.ts (86%) rename src/lib/candid/{ => types}/constructed/index.ts (85%) rename src/lib/candid/{ => types}/constructed/option.ts (86%) rename src/lib/candid/{ => types}/constructed/record.ts (78%) rename src/lib/candid/{ => types}/constructed/tuple.ts (79%) rename src/lib/candid/{constructed/variant/index.ts => types/constructed/variant.ts} (85%) rename src/lib/candid/{ => types}/constructed/vector.ts (75%) rename src/lib/candid/{ => types}/primitive/bool.ts (85%) rename src/lib/candid/{ => types}/primitive/empty.ts (86%) create mode 100644 src/lib/candid/types/primitive/floats/float32.ts create mode 100644 src/lib/candid/types/primitive/floats/float64.ts create mode 100644 src/lib/candid/types/primitive/floats/index.ts rename src/lib/candid/{ => types}/primitive/index.ts (57%) create mode 100644 src/lib/candid/types/primitive/ints/index.ts create mode 100644 src/lib/candid/types/primitive/ints/int.ts create mode 100644 src/lib/candid/types/primitive/ints/int16.ts create mode 100644 src/lib/candid/types/primitive/ints/int32.ts create mode 100644 src/lib/candid/types/primitive/ints/int64.ts create mode 100644 src/lib/candid/types/primitive/ints/int8.ts create mode 100644 src/lib/candid/types/primitive/nats/index.ts create mode 100644 src/lib/candid/types/primitive/nats/nat.ts create mode 100644 src/lib/candid/types/primitive/nats/nat16.ts create mode 100644 src/lib/candid/types/primitive/nats/nat32.ts create mode 100644 src/lib/candid/types/primitive/nats/nat64.ts create mode 100644 src/lib/candid/types/primitive/nats/nat8.ts rename src/lib/candid/{ => types}/primitive/null.ts (85%) rename src/lib/candid/{ => types}/primitive/reserved.ts (87%) rename src/lib/candid/{ => types}/primitive/text.ts (85%) rename src/lib/candid/{ => types}/primitive/void.ts (100%) rename src/lib/candid/{ => types}/reference/func.ts (78%) rename src/lib/candid/{ => types}/reference/index.ts (73%) rename src/lib/candid/{ => types}/reference/principal.ts (85%) rename src/lib/candid/{ => types}/reference/service.ts (98%) create mode 100644 src/lib/ic/accept_message.ts rename src/lib/{ic.ts => ic/index.ts} (97%) create mode 100644 src/lib/ic/stable_read.ts create mode 100644 src/lib/system_types/index.ts rename src/lib/{candid/constructed/variant => system_types}/rejection_code.ts (70%) rename src/lib/{candid/constructed/variant => system_types}/result.ts (84%) diff --git a/examples/inspect_message/src/index.did b/examples/inspect_message/src/index.did index e731956a3a..e2ac47359e 100644 --- a/examples/inspect_message/src/index.did +++ b/examples/inspect_message/src/index.did @@ -1,5 +1,5 @@ service: () -> { accessible: () -> (bool); - inaccessible: () -> (bool); alsoInaccessible: () -> (bool); + inaccessible: () -> (bool); } diff --git a/src/compiler/generate_candid_and_canister_methods.ts b/src/compiler/generate_candid_and_canister_methods.ts index 74e12c731c..07df622180 100644 --- a/src/compiler/generate_candid_and_canister_methods.ts +++ b/src/compiler/generate_candid_and_canister_methods.ts @@ -3,7 +3,7 @@ import { DEFAULT_VISITOR_DATA, didResultToCandidString, DidVisitor -} from '../lib/did_visitor'; +} from '../lib/candid/did_visitor'; export function generateCandidAndCanisterMethods(mainJs: string): { candid: string; diff --git a/src/lib/did_visitor.ts b/src/lib/candid/did_visitor.ts similarity index 100% rename from src/lib/did_visitor.ts rename to src/lib/candid/did_visitor.ts diff --git a/src/lib/candid/index.ts b/src/lib/candid/index.ts index 2402d181a3..8a76f9de2e 100644 --- a/src/lib/candid/index.ts +++ b/src/lib/candid/index.ts @@ -1,53 +1,32 @@ -import { IDL } from '..'; -import { - AzleBlob, - blob, - AzleVec, - AzleOpt, - AzleInt, - AzleInt64, - AzleInt32, - AzleInt16, - AzleInt8, - AzleNat, - AzleNat64, - AzleNat32, - AzleNat16, - AzleNat8, - AzleFloat64, - AzleFloat32, - AzleResult, - nat, - nat64, - nat32, - nat16, - nat8, - int, - int64, - int32, - int16, - int8, - float64, - float32, - AzleNull, - Null, - AzleReserved, - reserved, - AzleEmpty, - empty, - AzleBool, - bool, - Principal, - AzleTuple, - AzleText, - AzleVoid, - Opt, - Result -} from './'; +import { IDL } from '@dfinity/candid'; +import { AzleBlob, blob } from './types/constructed/blob'; +import { AzleVec } from './types/constructed/vector'; +import { AzleOpt, Opt } from './types/constructed/option'; +import { AzleTuple } from './types/constructed/tuple'; +import { AzleNull, Null } from './types/primitive/null'; +import { AzleReserved, reserved } from './types/primitive/reserved'; +import { AzleEmpty, empty } from './types/primitive/empty'; +import { AzleBool, bool } from './types/primitive/bool'; +import { AzleText } from './types/primitive/text'; +import { AzleVoid } from './types/primitive/void'; +import { AzleFloat32, float32 } from './types/primitive/floats/float32'; +import { AzleFloat64, float64 } from './types/primitive/floats/float64'; +import { AzleInt, int } from './types/primitive/ints/int'; +import { AzleInt8, int8 } from './types/primitive/ints/int8'; +import { AzleInt16, int16 } from './types/primitive/ints/int16'; +import { AzleInt32, int32 } from './types/primitive/ints/int32'; +import { AzleInt64, int64 } from './types/primitive/ints/int64'; +import { AzleNat, nat } from './types/primitive/nats/nat'; +import { AzleNat8, nat8 } from './types/primitive/nats/nat8'; +import { AzleNat16, nat16 } from './types/primitive/nats/nat16'; +import { AzleNat32, nat32 } from './types/primitive/nats/nat32'; +import { AzleNat64, nat64 } from './types/primitive/nats/nat64'; +import { AzleResult, Result } from '../system_types'; +import { Principal } from './types/reference'; -export * from './constructed'; -export * from './primitive'; -export * from './reference'; +export * from './types/constructed'; +export * from './types/primitive'; +export * from './types/reference'; export type TypeMapping = RecursionLevel extends 10 ? T diff --git a/src/lib/candid/primitive/floating_point_numbers.ts b/src/lib/candid/primitive/floating_point_numbers.ts deleted file mode 100644 index 168ed3c4a2..0000000000 --- a/src/lib/candid/primitive/floating_point_numbers.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { IDL } from '../..'; - -export class AzleFloat64 { - _kind: 'AzleFloat64' = 'AzleFloat64'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Float64; - } -} - -export class AzleFloat32 { - _kind: 'AzleFloat32' = 'AzleFloat32'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Float32; - } -} - -export const float32: AzleFloat32 = AzleFloat32 as any; -export type float32 = number; -export const float64: AzleFloat64 = AzleFloat64 as any; -export type float64 = number; diff --git a/src/lib/candid/primitive/integer_numbers.ts b/src/lib/candid/primitive/integer_numbers.ts deleted file mode 100644 index 0be2c1fe0f..0000000000 --- a/src/lib/candid/primitive/integer_numbers.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { IDL } from '../..'; - -export class AzleInt { - _kind: 'AzleInt' = 'AzleInt'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Int; - } -} - -export class AzleInt64 { - _kind: 'AzleInt64' = 'AzleInt64'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Int64; - } -} - -export class AzleInt32 { - _kind: 'AzleInt32' = 'AzleInt32'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Int32; - } -} - -export class AzleInt16 { - _kind: 'AzleInt16' = 'AzleInt16'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Int16; - } -} - -export class AzleInt8 { - _kind: 'AzleInt8' = 'AzleInt8'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Int8; - } -} - -export const int: AzleInt = AzleInt as any; -export type int = bigint; -export const int8: AzleInt8 = AzleInt8 as any; -export type int8 = number; -export const int16: AzleInt16 = AzleInt16 as any; -export type int16 = number; -export const int32: AzleInt32 = AzleInt32 as any; -export type int32 = number; -export const int64: AzleInt64 = AzleInt64 as any; -export type int64 = bigint; diff --git a/src/lib/candid/primitive/natural_numbers.ts b/src/lib/candid/primitive/natural_numbers.ts deleted file mode 100644 index 134ad3cda0..0000000000 --- a/src/lib/candid/primitive/natural_numbers.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { IDL } from '../..'; - -export class AzleNat { - _kind: 'AzleNat' = 'AzleNat'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Nat; - } -} - -export class AzleNat64 { - _kind: 'AzleNat64' = 'AzleNat64'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Nat64; - } -} - -export class AzleNat32 { - _kind: 'AzleNat32' = 'AzleNat32'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Nat32; - } -} - -export class AzleNat16 { - _kind: 'AzleNat16' = 'AzleNat16'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Nat16; - } -} - -export class AzleNat8 { - _kind: 'AzleNat8' = 'AzleNat8'; - _azleCandidType?: '_azleCandidType'; - - static getIDL() { - return IDL.Nat8; - } -} - -export const nat: AzleNat = AzleNat as any; -export type nat = bigint; -export const nat8: AzleNat8 = AzleNat8 as any; -export type nat8 = number; -export const nat16: AzleNat16 = AzleNat16 as any; -export type nat16 = number; -export const nat32: AzleNat32 = AzleNat32 as any; -export type nat32 = number; -export const nat64: AzleNat64 = AzleNat64 as any; -export type nat64 = bigint; diff --git a/src/lib/candid/reference/recursive.ts b/src/lib/candid/recursive.ts similarity index 94% rename from src/lib/candid/reference/recursive.ts rename to src/lib/candid/recursive.ts index 2d5c1da509..f8e34b2f95 100644 --- a/src/lib/candid/reference/recursive.ts +++ b/src/lib/candid/recursive.ts @@ -1,6 +1,6 @@ import { v4 } from 'uuid'; import { IDL } from '@dfinity/candid'; -import { Parent } from '../../to_idl_type'; +import { Parent } from './index'; export function Recursive(idlCallback: any): any { const name = v4(); diff --git a/src/lib/candid/serde/index.ts b/src/lib/candid/serde/index.ts index dac9d57956..8a7caa23db 100644 --- a/src/lib/candid/serde/index.ts +++ b/src/lib/candid/serde/index.ts @@ -1,8 +1,9 @@ import { IDL } from '@dfinity/candid'; -import { AzleVec, AzleOpt, AzleTuple } from '..'; -import { DecodeVisitor, EncodeVisitor } from './visitors/'; -import { CandidType, toIDLType } from '../..'; +import { AzleVec, AzleOpt, AzleTuple } from '../types/constructed'; +import { DecodeVisitor } from './visitors/decode_visitor'; +import { EncodeVisitor } from './visitors/encode_visitor'; +import { CandidType, toIDLType } from '../../candid'; /** * Encodes the provided value as candid blob of the designated type. diff --git a/src/lib/candid/serde/visitors/decode_visitor.ts b/src/lib/candid/serde/visitors/decode_visitor.ts index 402a79279e..777323fbe0 100644 --- a/src/lib/candid/serde/visitors/decode_visitor.ts +++ b/src/lib/candid/serde/visitors/decode_visitor.ts @@ -8,8 +8,8 @@ import { visitTuple, visitVariant, visitVec -} from '.'; -import { Opt } from '../../'; +} from './index'; +import { Opt } from '../../types/constructed'; /** * When we decode a Service we are given a principal. We need to use that diff --git a/src/lib/candid/serde/visitors/encode_visitor.ts b/src/lib/candid/serde/visitors/encode_visitor.ts index 7d01706654..02b1f7d3bd 100644 --- a/src/lib/candid/serde/visitors/encode_visitor.ts +++ b/src/lib/candid/serde/visitors/encode_visitor.ts @@ -8,7 +8,7 @@ import { visitTuple, visitVariant, visitVec -} from '.'; +} from './index'; /** * When we encode a Service we have a service class and we need it to be only diff --git a/src/lib/candid/serde/visitors/index.ts b/src/lib/candid/serde/visitors/index.ts index 457fc9c290..3c68dc138d 100644 --- a/src/lib/candid/serde/visitors/index.ts +++ b/src/lib/candid/serde/visitors/index.ts @@ -1,7 +1,7 @@ import { IDL } from '@dfinity/candid'; import { DecodeVisitor } from './decode_visitor'; import { EncodeVisitor } from './encode_visitor'; -import { AzleResult, Result } from '../../'; +import { AzleResult, Result } from '../../../system_types/result'; export { EncodeVisitor, DecodeVisitor }; /* diff --git a/src/lib/candid/constructed/blob.ts b/src/lib/candid/types/constructed/blob.ts similarity index 86% rename from src/lib/candid/constructed/blob.ts rename to src/lib/candid/types/constructed/blob.ts index 55c8859abb..e2d552057c 100644 --- a/src/lib/candid/constructed/blob.ts +++ b/src/lib/candid/types/constructed/blob.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; export class AzleBlob { _kind: 'AzleBlob' = 'AzleBlob'; diff --git a/src/lib/candid/constructed/index.ts b/src/lib/candid/types/constructed/index.ts similarity index 85% rename from src/lib/candid/constructed/index.ts rename to src/lib/candid/types/constructed/index.ts index 05d67176b9..33c877c1ce 100644 --- a/src/lib/candid/constructed/index.ts +++ b/src/lib/candid/types/constructed/index.ts @@ -1,4 +1,5 @@ -import { CandidType, IDL, Parent, toIDLType } from '../../'; +import { CandidType, Parent, toIDLType } from '../../index'; +import { IDL } from '@dfinity/candid'; export * from './blob'; export * from './option'; diff --git a/src/lib/candid/constructed/option.ts b/src/lib/candid/types/constructed/option.ts similarity index 86% rename from src/lib/candid/constructed/option.ts rename to src/lib/candid/types/constructed/option.ts index efddd2332b..e69e0c45e2 100644 --- a/src/lib/candid/constructed/option.ts +++ b/src/lib/candid/types/constructed/option.ts @@ -1,5 +1,6 @@ -import { CandidType, RequireExactlyOne } from '..'; -import { IDL, Parent, toIDLType } from '../..'; +import { CandidType, Parent, toIDLType } from '../../index'; +import { RequireExactlyOne } from '../constructed/variant'; +import { IDL } from '@dfinity/candid'; /** * Represents an optional value: every {@link Opt} is either `Some` and contains diff --git a/src/lib/candid/constructed/record.ts b/src/lib/candid/types/constructed/record.ts similarity index 78% rename from src/lib/candid/constructed/record.ts rename to src/lib/candid/types/constructed/record.ts index 87610d21cf..623b78dde6 100644 --- a/src/lib/candid/constructed/record.ts +++ b/src/lib/candid/types/constructed/record.ts @@ -1,7 +1,6 @@ -import { CandidType, TypeMapping } from '..'; +import { CandidType, TypeMapping, Parent } from '../../index'; import { IDL } from '@dfinity/candid'; -import { Parent } from '../../to_idl_type'; -import { processMap } from '..'; +import { processMap } from '../constructed'; import { v4 } from 'uuid'; export function Record< diff --git a/src/lib/candid/constructed/tuple.ts b/src/lib/candid/types/constructed/tuple.ts similarity index 79% rename from src/lib/candid/constructed/tuple.ts rename to src/lib/candid/types/constructed/tuple.ts index a7a623f94e..cb49c0ae6d 100644 --- a/src/lib/candid/constructed/tuple.ts +++ b/src/lib/candid/types/constructed/tuple.ts @@ -1,5 +1,6 @@ -import { CandidType } from '..'; -import { Parent, toIDLType, IDL } from '../../'; +import { CandidType } from '../../index'; +import { Parent, toIDLType } from '../../index'; +import { IDL } from '@dfinity/candid'; export class AzleTuple { constructor(t: CandidType[]) { diff --git a/src/lib/candid/constructed/variant/index.ts b/src/lib/candid/types/constructed/variant.ts similarity index 85% rename from src/lib/candid/constructed/variant/index.ts rename to src/lib/candid/types/constructed/variant.ts index e6e646c341..171824cb38 100644 --- a/src/lib/candid/constructed/variant/index.ts +++ b/src/lib/candid/types/constructed/variant.ts @@ -1,10 +1,7 @@ import { CandidType, TypeMapping } from '../..'; -import { processMap } from '../'; +import { processMap } from '.'; import { v4 } from 'uuid'; -import { IDL } from '../../..'; - -export * from './result'; -export * from './rejection_code'; +import { IDL } from '@dfinity/candid'; export function Variant< T extends { diff --git a/src/lib/candid/constructed/vector.ts b/src/lib/candid/types/constructed/vector.ts similarity index 75% rename from src/lib/candid/constructed/vector.ts rename to src/lib/candid/types/constructed/vector.ts index 1664863788..6f9947307c 100644 --- a/src/lib/candid/constructed/vector.ts +++ b/src/lib/candid/types/constructed/vector.ts @@ -1,5 +1,6 @@ -import { CandidType } from '..'; -import { IDL, Parent, toIDLType } from '../..'; +import { CandidType } from '../../index'; +import { Parent, toIDLType } from '../../index'; +import { IDL } from '@dfinity/candid'; export class AzleVec { constructor(t: any) { diff --git a/src/lib/candid/primitive/bool.ts b/src/lib/candid/types/primitive/bool.ts similarity index 85% rename from src/lib/candid/primitive/bool.ts rename to src/lib/candid/types/primitive/bool.ts index 71f3ef3e7f..8a02ef350e 100644 --- a/src/lib/candid/primitive/bool.ts +++ b/src/lib/candid/types/primitive/bool.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; export class AzleBool { _kind: 'AzleBool' = 'AzleBool'; diff --git a/src/lib/candid/primitive/empty.ts b/src/lib/candid/types/primitive/empty.ts similarity index 86% rename from src/lib/candid/primitive/empty.ts rename to src/lib/candid/types/primitive/empty.ts index 0401fbdb75..27d0609058 100644 --- a/src/lib/candid/primitive/empty.ts +++ b/src/lib/candid/types/primitive/empty.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; export class AzleEmpty { _kind: 'AzleEmpty' = 'AzleEmpty'; diff --git a/src/lib/candid/types/primitive/floats/float32.ts b/src/lib/candid/types/primitive/floats/float32.ts new file mode 100644 index 0000000000..ae35a13244 --- /dev/null +++ b/src/lib/candid/types/primitive/floats/float32.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleFloat32 { + _kind: 'AzleFloat32' = 'AzleFloat32'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Float32; + } +} + +export const float32: AzleFloat32 = AzleFloat32 as any; +export type float32 = number; diff --git a/src/lib/candid/types/primitive/floats/float64.ts b/src/lib/candid/types/primitive/floats/float64.ts new file mode 100644 index 0000000000..ee1f8dfac5 --- /dev/null +++ b/src/lib/candid/types/primitive/floats/float64.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleFloat64 { + _kind: 'AzleFloat64' = 'AzleFloat64'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Float64; + } +} + +export const float64: AzleFloat64 = AzleFloat64 as any; +export type float64 = number; diff --git a/src/lib/candid/types/primitive/floats/index.ts b/src/lib/candid/types/primitive/floats/index.ts new file mode 100644 index 0000000000..a099b241e0 --- /dev/null +++ b/src/lib/candid/types/primitive/floats/index.ts @@ -0,0 +1,2 @@ +export * from './float32'; +export * from './float64'; diff --git a/src/lib/candid/primitive/index.ts b/src/lib/candid/types/primitive/index.ts similarity index 57% rename from src/lib/candid/primitive/index.ts rename to src/lib/candid/types/primitive/index.ts index 2e34c13fbc..a3f1914e06 100644 --- a/src/lib/candid/primitive/index.ts +++ b/src/lib/candid/types/primitive/index.ts @@ -1,8 +1,8 @@ export * from './bool'; export * from './empty'; -export * from './floating_point_numbers'; -export * from './integer_numbers'; -export * from './natural_numbers'; +export * from './floats'; +export * from './ints'; +export * from './nats'; export * from './null'; export * from './reserved'; export * from './text'; diff --git a/src/lib/candid/types/primitive/ints/index.ts b/src/lib/candid/types/primitive/ints/index.ts new file mode 100644 index 0000000000..436b5547ed --- /dev/null +++ b/src/lib/candid/types/primitive/ints/index.ts @@ -0,0 +1,5 @@ +export * from './int'; +export * from './int8'; +export * from './int32'; +export * from './int16'; +export * from './int64'; diff --git a/src/lib/candid/types/primitive/ints/int.ts b/src/lib/candid/types/primitive/ints/int.ts new file mode 100644 index 0000000000..4ebde40e80 --- /dev/null +++ b/src/lib/candid/types/primitive/ints/int.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleInt { + _kind: 'AzleInt' = 'AzleInt'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Int; + } +} + +export const int: AzleInt = AzleInt as any; +export type int = bigint; diff --git a/src/lib/candid/types/primitive/ints/int16.ts b/src/lib/candid/types/primitive/ints/int16.ts new file mode 100644 index 0000000000..4577fe8cce --- /dev/null +++ b/src/lib/candid/types/primitive/ints/int16.ts @@ -0,0 +1,12 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleInt16 { + _kind: 'AzleInt16' = 'AzleInt16'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Int16; + } +} +export const int16: AzleInt16 = AzleInt16 as any; +export type int16 = number; diff --git a/src/lib/candid/types/primitive/ints/int32.ts b/src/lib/candid/types/primitive/ints/int32.ts new file mode 100644 index 0000000000..a976e32531 --- /dev/null +++ b/src/lib/candid/types/primitive/ints/int32.ts @@ -0,0 +1,12 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleInt32 { + _kind: 'AzleInt32' = 'AzleInt32'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Int32; + } +} +export const int32: AzleInt32 = AzleInt32 as any; +export type int32 = number; diff --git a/src/lib/candid/types/primitive/ints/int64.ts b/src/lib/candid/types/primitive/ints/int64.ts new file mode 100644 index 0000000000..3a21733a28 --- /dev/null +++ b/src/lib/candid/types/primitive/ints/int64.ts @@ -0,0 +1,12 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleInt64 { + _kind: 'AzleInt64' = 'AzleInt64'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Int64; + } +} +export const int64: AzleInt64 = AzleInt64 as any; +export type int64 = bigint; diff --git a/src/lib/candid/types/primitive/ints/int8.ts b/src/lib/candid/types/primitive/ints/int8.ts new file mode 100644 index 0000000000..cb9e46ecc0 --- /dev/null +++ b/src/lib/candid/types/primitive/ints/int8.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleInt8 { + _kind: 'AzleInt8' = 'AzleInt8'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Int8; + } +} + +export const int8: AzleInt8 = AzleInt8 as any; +export type int8 = number; diff --git a/src/lib/candid/types/primitive/nats/index.ts b/src/lib/candid/types/primitive/nats/index.ts new file mode 100644 index 0000000000..c622c29501 --- /dev/null +++ b/src/lib/candid/types/primitive/nats/index.ts @@ -0,0 +1,5 @@ +export * from './nat'; +export * from './nat8'; +export * from './nat16'; +export * from './nat32'; +export * from './nat64'; diff --git a/src/lib/candid/types/primitive/nats/nat.ts b/src/lib/candid/types/primitive/nats/nat.ts new file mode 100644 index 0000000000..0cc7a539c0 --- /dev/null +++ b/src/lib/candid/types/primitive/nats/nat.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleNat { + _kind: 'AzleNat' = 'AzleNat'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Nat; + } +} + +export const nat: AzleNat = AzleNat as any; +export type nat = bigint; diff --git a/src/lib/candid/types/primitive/nats/nat16.ts b/src/lib/candid/types/primitive/nats/nat16.ts new file mode 100644 index 0000000000..fbcd5cb783 --- /dev/null +++ b/src/lib/candid/types/primitive/nats/nat16.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleNat16 { + _kind: 'AzleNat16' = 'AzleNat16'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Nat16; + } +} + +export const nat16: AzleNat16 = AzleNat16 as any; +export type nat16 = number; diff --git a/src/lib/candid/types/primitive/nats/nat32.ts b/src/lib/candid/types/primitive/nats/nat32.ts new file mode 100644 index 0000000000..f82a8c1c18 --- /dev/null +++ b/src/lib/candid/types/primitive/nats/nat32.ts @@ -0,0 +1,12 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleNat32 { + _kind: 'AzleNat32' = 'AzleNat32'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Nat32; + } +} +export const nat32: AzleNat32 = AzleNat32 as any; +export type nat32 = number; diff --git a/src/lib/candid/types/primitive/nats/nat64.ts b/src/lib/candid/types/primitive/nats/nat64.ts new file mode 100644 index 0000000000..0911576b38 --- /dev/null +++ b/src/lib/candid/types/primitive/nats/nat64.ts @@ -0,0 +1,12 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleNat64 { + _kind: 'AzleNat64' = 'AzleNat64'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Nat64; + } +} +export const nat64: AzleNat64 = AzleNat64 as any; +export type nat64 = bigint; diff --git a/src/lib/candid/types/primitive/nats/nat8.ts b/src/lib/candid/types/primitive/nats/nat8.ts new file mode 100644 index 0000000000..3aa9c8fecb --- /dev/null +++ b/src/lib/candid/types/primitive/nats/nat8.ts @@ -0,0 +1,13 @@ +import { IDL } from '@dfinity/candid'; + +export class AzleNat8 { + _kind: 'AzleNat8' = 'AzleNat8'; + _azleCandidType?: '_azleCandidType'; + + static getIDL() { + return IDL.Nat8; + } +} + +export const nat8: AzleNat8 = AzleNat8 as any; +export type nat8 = number; diff --git a/src/lib/candid/primitive/null.ts b/src/lib/candid/types/primitive/null.ts similarity index 85% rename from src/lib/candid/primitive/null.ts rename to src/lib/candid/types/primitive/null.ts index a47f806cfa..06cef35d3a 100644 --- a/src/lib/candid/primitive/null.ts +++ b/src/lib/candid/types/primitive/null.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; export class AzleNull { _kind: 'AzleNull' = 'AzleNull'; diff --git a/src/lib/candid/primitive/reserved.ts b/src/lib/candid/types/primitive/reserved.ts similarity index 87% rename from src/lib/candid/primitive/reserved.ts rename to src/lib/candid/types/primitive/reserved.ts index 260aba48b3..2c371657af 100644 --- a/src/lib/candid/primitive/reserved.ts +++ b/src/lib/candid/types/primitive/reserved.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; export class AzleReserved { _kind: 'AzleReserved' = 'AzleReserved'; diff --git a/src/lib/candid/primitive/text.ts b/src/lib/candid/types/primitive/text.ts similarity index 85% rename from src/lib/candid/primitive/text.ts rename to src/lib/candid/types/primitive/text.ts index 742cc4be0b..5b21662cfe 100644 --- a/src/lib/candid/primitive/text.ts +++ b/src/lib/candid/types/primitive/text.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; export class AzleText { _kind: 'AzleText' = 'AzleText'; diff --git a/src/lib/candid/primitive/void.ts b/src/lib/candid/types/primitive/void.ts similarity index 100% rename from src/lib/candid/primitive/void.ts rename to src/lib/candid/types/primitive/void.ts diff --git a/src/lib/candid/reference/func.ts b/src/lib/candid/types/reference/func.ts similarity index 78% rename from src/lib/candid/reference/func.ts rename to src/lib/candid/types/reference/func.ts index fc8479f055..94aaf8d54b 100644 --- a/src/lib/candid/reference/func.ts +++ b/src/lib/candid/types/reference/func.ts @@ -1,12 +1,8 @@ -import { CandidType } from '..'; +import { CandidType } from '../../index'; +import { IDL } from '@dfinity/candid'; +import { Principal } from './principal'; import { v4 } from 'uuid'; -import { - Principal, - Parent, - toParamIDLTypes, - toReturnIDLType, - IDL -} from '../../'; +import { Parent, toParamIDLTypes, toReturnIDLType } from '../../index'; type Mode = 'query' | 'update' | 'oneway'; diff --git a/src/lib/candid/reference/index.ts b/src/lib/candid/types/reference/index.ts similarity index 73% rename from src/lib/candid/reference/index.ts rename to src/lib/candid/types/reference/index.ts index de79720dc2..98307ac051 100644 --- a/src/lib/candid/reference/index.ts +++ b/src/lib/candid/types/reference/index.ts @@ -1,4 +1,3 @@ export * from './func'; export * from './service'; export * from './principal'; -export * from './recursive'; diff --git a/src/lib/candid/reference/principal.ts b/src/lib/candid/types/reference/principal.ts similarity index 85% rename from src/lib/candid/reference/principal.ts rename to src/lib/candid/types/reference/principal.ts index aa5081732d..ec3156d6d0 100644 --- a/src/lib/candid/reference/principal.ts +++ b/src/lib/candid/types/reference/principal.ts @@ -1,4 +1,4 @@ -import { IDL } from '../..'; +import { IDL } from '@dfinity/candid'; import { Principal as DfinityPrincipal } from '@dfinity/principal'; export class Principal extends DfinityPrincipal { diff --git a/src/lib/candid/reference/service.ts b/src/lib/candid/types/reference/service.ts similarity index 98% rename from src/lib/candid/reference/service.ts rename to src/lib/candid/types/reference/service.ts index 7f8c519b1e..089ff58b03 100644 --- a/src/lib/candid/reference/service.ts +++ b/src/lib/candid/types/reference/service.ts @@ -1,14 +1,14 @@ import { - IDL, - Principal, TypeMapping, Parent, toParamIDLTypes, - toReturnIDLType, - ic -} from '../..'; -import { CanisterMethodInfo } from '../../canister_methods'; -import { decode, encodeMultiple } from '../serde'; + toReturnIDLType +} from '../../index'; +import { ic } from '../../../ic'; +import { Principal } from './principal'; +import { IDL } from '@dfinity/candid'; +import { CanisterMethodInfo } from '../../../canister_methods'; +import { decode, encodeMultiple } from '../../serde'; type CanisterOptions = { [key: string]: CanisterMethodInfo; diff --git a/src/lib/canister_methods/index.ts b/src/lib/canister_methods/index.ts index 6c4f8c6260..a3483ffd4c 100644 --- a/src/lib/canister_methods/index.ts +++ b/src/lib/canister_methods/index.ts @@ -1,8 +1,9 @@ -import { AzleVoid, IDL } from '../'; +import { AzleVoid } from '../candid/types/primitive/void'; +import { IDL } from '@dfinity/candid'; import { ic } from '../ic'; -import { CandidType, TypeMapping } from '..'; -import { DecodeVisitor, EncodeVisitor } from '../candid/serde/visitors'; -import { Parent } from '../to_idl_type'; +import { CandidType, TypeMapping, Parent } from '../candid'; +import { DecodeVisitor } from '../candid/serde/visitors/decode_visitor'; +import { EncodeVisitor } from '../candid/serde/visitors/encode_visitor'; export * from './heartbeat'; export * from './init'; diff --git a/src/lib/ic/accept_message.ts b/src/lib/ic/accept_message.ts new file mode 100644 index 0000000000..6d3b8d2c5d --- /dev/null +++ b/src/lib/ic/accept_message.ts @@ -0,0 +1,5 @@ +/** + * Accepts the ingress message. Calling from outside the + * {@link $inspectMessage} context will cause the canister to trap. + */ +export function acceptMessage(): void {} diff --git a/src/lib/ic.ts b/src/lib/ic/index.ts similarity index 97% rename from src/lib/ic.ts rename to src/lib/ic/index.ts index ca48bd1eb9..ffe1b37cdc 100644 --- a/src/lib/ic.ts +++ b/src/lib/ic/index.ts @@ -1,20 +1,18 @@ import '@dfinity/candid/lib/esm/idl'; // This must remain or the build fails import { Principal } from '@dfinity/principal'; -import { IDL } from './'; -import { - AzleNat64, - blob, - nat, - nat32, - nat64, - None, - Opt, - Some, - Void -} from './candid'; -import { CandidType, RejectionCode, toIDLType } from '.'; +import { IDL } from '@dfinity/candid'; +import { blob } from '../candid/types/constructed/blob'; +import { Void } from '../candid/types/primitive/void'; +import { AzleNat64, nat64 } from '../candid/types/primitive/nats/nat64'; +import { nat } from '../candid/types/primitive/nats/nat'; +import { nat32 } from '../candid/types/primitive/nats/nat32'; +import { None, Opt, Some } from '../candid/types/constructed/option'; +import { CandidType, toIDLType } from '../candid'; +import { RejectionCode } from '../system_types/rejection_code'; import { v4 } from 'uuid'; -import { EncodeVisitor } from './candid/serde/visitors'; +import { EncodeVisitor } from '../candid/serde/visitors'; +import { acceptMessage } from './accept_message'; +import { stableRead } from './stable_read'; // declare var globalThis: { // ic: Ic; @@ -36,11 +34,12 @@ export type TimerId = nat64; // TODO: Consider modeling this after the correspon export const TimerId: AzleNat64 = AzleNat64 as any; type Ic = { + acceptMessage: typeof acceptMessage; /** * Accepts the ingress message. Calling from outside the * {@link $inspectMessage} context will cause the canister to trap. */ - acceptMessage: () => void; + // acceptMessage: () => void; /** * Returns the argument data as bytes. @@ -382,7 +381,7 @@ type Ic = { * @param length the length of buffer to read * @returns the raw bytes in stable memory */ - stableRead: (offset: number, length: number) => Uint8Array; + stableRead: typeof stableRead; /** * Gets current size of the stable memory (in WASM pages) @@ -461,6 +460,7 @@ type ReturnTypeOfPromise = T extends (...args: any[]) => infer R export const ic: Ic = globalThis._azleIc ? { ...globalThis._azleIc, + stableRead, argDataRaw: () => { return new Uint8Array(globalThis._azleIc.argDataRaw()); }, @@ -838,15 +838,6 @@ export const ic: Ic = globalThis._azleIc globalThis._azleIc.stableGrow(newPagesCandidBytes) )[0]; }, - stableRead: (offset, buffer) => { - const paramsCandidBytes = new Uint8Array( - IDL.encode([IDL.Nat32, IDL.Nat32], [offset, buffer]) - ).buffer; - - return new Uint8Array( - globalThis._azleIc.stableRead(paramsCandidBytes) - ); - }, stableSize: () => { return IDL.decode( [IDL.Nat32], diff --git a/src/lib/ic/stable_read.ts b/src/lib/ic/stable_read.ts new file mode 100644 index 0000000000..0a9f280d94 --- /dev/null +++ b/src/lib/ic/stable_read.ts @@ -0,0 +1,9 @@ +import { IDL } from '@dfinity/candid'; + +export function stableRead(offset: number, buffer: number): Uint8Array { + const paramsCandidBytes = new Uint8Array( + IDL.encode([IDL.Nat32, IDL.Nat32], [offset, buffer]) + ).buffer; + + return new Uint8Array(globalThis._azleIc.stableRead(paramsCandidBytes)); +} diff --git a/src/lib/stable_b_tree_map.ts b/src/lib/stable_b_tree_map.ts index 7c6ed29369..a604619fb4 100644 --- a/src/lib/stable_b_tree_map.ts +++ b/src/lib/stable_b_tree_map.ts @@ -1,14 +1,8 @@ -import { - CandidType, - None, - Opt, - Some, - TypeMapping, - nat64, - nat8, - IDL, - toIDLType -} from '.'; +import { CandidType, TypeMapping, toIDLType } from './candid'; +import { None, Opt, Some } from './candid/types/constructed/option'; +import { IDL } from '@dfinity/candid'; +import { nat64 } from './candid/types/primitive/nats/nat64'; +import { nat8 } from './candid/types/primitive/nats/nat8'; import { encode, decode } from './candid/serde'; export function StableBTreeMap< diff --git a/src/lib/system_types/index.ts b/src/lib/system_types/index.ts new file mode 100644 index 0000000000..3cb190fab4 --- /dev/null +++ b/src/lib/system_types/index.ts @@ -0,0 +1,2 @@ +export * from './rejection_code'; +export * from './result'; diff --git a/src/lib/candid/constructed/variant/rejection_code.ts b/src/lib/system_types/rejection_code.ts similarity index 70% rename from src/lib/candid/constructed/variant/rejection_code.ts rename to src/lib/system_types/rejection_code.ts index b27f539aa0..4c352a7ae0 100644 --- a/src/lib/candid/constructed/variant/rejection_code.ts +++ b/src/lib/system_types/rejection_code.ts @@ -1,5 +1,5 @@ -import { Variant } from '../'; -import { Null } from '../../primitive/null'; +import { Variant } from '../candid/types/constructed/variant'; +import { Null } from '../candid/types/primitive/null'; /** * Indicates an error was encountered during a canister method. diff --git a/src/lib/candid/constructed/variant/result.ts b/src/lib/system_types/result.ts similarity index 84% rename from src/lib/candid/constructed/variant/result.ts rename to src/lib/system_types/result.ts index 9fac837954..d4b90978c5 100644 --- a/src/lib/candid/constructed/variant/result.ts +++ b/src/lib/system_types/result.ts @@ -1,5 +1,6 @@ -import { Parent, RequireExactlyOne, toIDLType } from '../..'; -import { CandidType, IDL } from '../../..'; +import { Parent, toIDLType, CandidType } from '../candid'; +import { RequireExactlyOne } from '../candid/types/constructed/variant'; +import { IDL } from '@dfinity/candid'; export class AzleResult { constructor(ok: any, err: any) {