-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
583 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IDL } from '../..'; | ||
|
||
export class AzleBlob { | ||
_kind: 'AzleBlob' = 'AzleBlob'; | ||
_azleCandidType?: '_azleCandidType'; | ||
|
||
static getIDL() { | ||
return IDL.Vec(IDL.Nat8); | ||
} | ||
} | ||
|
||
export const blob: AzleBlob = AzleBlob as any; | ||
export type blob = Uint8Array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Parent, toIDLType } from '../../'; | ||
|
||
export * from './blob'; | ||
export * from './option'; | ||
export * from './record'; | ||
export * from './tuple'; | ||
export * from './variant'; | ||
export * from './vector'; | ||
|
||
type CandidMap = { [key: string]: any }; | ||
|
||
export function processMap(targetMap: CandidMap, parent: Parent[]): CandidMap { | ||
const newMap: CandidMap = {}; | ||
|
||
for (const key in targetMap) { | ||
if (targetMap.hasOwnProperty(key)) { | ||
const value = targetMap[key]; | ||
const newValue = toIDLType(value, parent); | ||
newMap[key] = newValue; | ||
} | ||
} | ||
|
||
return newMap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { CandidType, RequireExactlyOne } from '..'; | ||
import { IDL, Parent, toIDLType } from '../..'; | ||
|
||
/** | ||
* Represents an optional value: every {@link Opt} is either `Some` and contains | ||
* a value, or `None` and does not. | ||
*/ | ||
export type Opt<T> = RequireExactlyOne<{ Some: T; None: null }>; | ||
|
||
/** | ||
* Wraps the provided value in a `Some` {@link Opt} | ||
* @param value - the value to be wrapped | ||
* @returns a `Some` {@link Opt} containing the provided value | ||
*/ | ||
export function Some<T>(value: T) { | ||
return { Some: value }; | ||
} | ||
|
||
/** An {@link Opt} representing the absence of a value */ | ||
export const None = { None: null }; | ||
|
||
// TODO what happens if we pass something to Opt() that can't be converted to CandidClass? | ||
export function Opt<T>(t: T): AzleOpt<T> { | ||
// return IDL.Opt(toCandidClass(t)); | ||
return new AzleOpt(t); | ||
} | ||
|
||
export class AzleOpt<T> { | ||
constructor(t: any) { | ||
this._azleType = t; | ||
} | ||
|
||
_azleType: CandidType; | ||
_azleCandidType?: '_azleCandidType'; | ||
_kind: 'AzleOpt' = 'AzleOpt'; | ||
|
||
getIDL(parents: Parent[]) { | ||
return IDL.Opt(toIDLType(this._azleType, parents)); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/lib/candid/reference/record.ts → src/lib/candid/constructed/record.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CandidType } from '..'; | ||
import { Parent, toIDLType, IDL } from '../../'; | ||
|
||
export class AzleTuple<T extends any[]> { | ||
constructor(t: CandidType[]) { | ||
this._azleTypes = t; | ||
} | ||
|
||
_azleTypes: CandidType[]; | ||
_azleCandidType?: '_azleCandidType'; | ||
|
||
getIDL(parents: Parent[]) { | ||
const candidTypes = this._azleTypes.map((value) => { | ||
return toIDLType(value, parents); | ||
}); | ||
return IDL.Tuple(...candidTypes); | ||
} | ||
} | ||
|
||
export function Tuple<T extends any[]>(...types: T): AzleTuple<T> { | ||
return new AzleTuple(types); | ||
} | ||
export type Tuple<T> = T; |
8 changes: 5 additions & 3 deletions
8
src/lib/candid/reference/variant.ts → src/lib/candid/constructed/variant/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/lib/candid/reference/result.ts → src/lib/candid/constructed/variant/result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CandidType } from '..'; | ||
import { IDL, Parent, toIDLType } from '../..'; | ||
|
||
export class AzleVec<T> { | ||
constructor(t: any) { | ||
this._azleType = t; | ||
} | ||
|
||
_azleType: CandidType; | ||
_azleCandidType?: '_azleCandidType'; | ||
|
||
getIDL(parents: Parent[]) { | ||
return IDL.Vec(toIDLType(this._azleType, parents)); | ||
} | ||
} | ||
|
||
export type Vec<T> = T[]; | ||
export function Vec<T>(t: T): AzleVec<T> { | ||
// return IDL.Vec(toCandidClass(t)); | ||
return new AzleVec(t); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IDL } from '../..'; | ||
|
||
export class AzleBool { | ||
_kind: 'AzleBool' = 'AzleBool'; | ||
_azleCandidType?: '_azleCandidType'; | ||
|
||
static getIDL() { | ||
return IDL.Bool; | ||
} | ||
} | ||
|
||
export const bool: AzleBool = AzleBool as any; | ||
export type bool = boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IDL } from '../..'; | ||
|
||
export class AzleEmpty { | ||
_kind: 'AzleEmpty' = 'AzleEmpty'; | ||
_azleCandidType?: '_azleCandidType'; | ||
|
||
static getIDL() { | ||
return IDL.Empty; | ||
} | ||
} | ||
|
||
export const empty: AzleEmpty = AzleEmpty as any; | ||
export type empty = never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export * from './bool'; | ||
export * from './empty'; | ||
export * from './floating_point_numbers'; | ||
export * from './integer_numbers'; | ||
export * from './natural_numbers'; | ||
export * from './null'; | ||
export * from './reserved'; | ||
export * from './text'; | ||
export * from './void'; |
Oops, something went wrong.