Skip to content

Commit

Permalink
Add missing idlFactory export in TypeScript declarations (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev authored Nov 6, 2023
1 parent 699e5cb commit 05dab77
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rust/candid/src/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ fn pp_actor<'a>(env: &'a TypeEnv, ty: &'a Type) -> RcDoc<'a> {
pub fn compile(env: &TypeEnv, actor: &Option<Type>) -> String {
let header = r#"import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';
"#;
let def_list: Vec<_> = env.0.iter().map(|pair| pair.0.as_ref()).collect();
let defs = pp_defs(env, &def_list);
let actor = match actor {
None => RcDoc::nil(),
Some(actor) => pp_actor(env, actor),
Some(actor) => pp_actor(env, actor)
.append(RcDoc::line())
.append("export declare const idlFactory: IDL.InterfaceFactory;"),
};
let doc = RcDoc::text(header)
.append(RcDoc::line())
Expand Down
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/actor.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type f = ActorMethod<[number], number>;
export type g = f;
Expand All @@ -11,3 +12,4 @@ export interface _SERVICE {
'h' : g,
'o' : ActorMethod<[o], o>,
}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/class.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type List = [] | [[bigint, List]];
export interface _SERVICE {
'get' : ActorMethod<[], List>,
'set' : ActorMethod<[List], List>,
}
export declare const idlFactory: IDL.InterfaceFactory;
1 change: 1 addition & 0 deletions rust/candid/tests/assets/ok/comment.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type id = number;

2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/cyclic.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type A = [] | [B];
export type B = [] | [C];
Expand All @@ -8,3 +9,4 @@ export type X = Y;
export type Y = Z;
export type Z = A;
export interface _SERVICE { 'f' : ActorMethod<[A, B, C, X, Y, Z], undefined> }
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/escape.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface t {
'\"' : bigint,
Expand All @@ -8,3 +9,4 @@ export interface t {
'\\\n\'\"' : bigint,
}
export interface _SERVICE { '\n\'\"\'\'\"\"\r\t' : ActorMethod<[t], undefined> }
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/example.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type A = B;
export type B = [] | [A];
Expand Down Expand Up @@ -46,3 +47,4 @@ export interface _SERVICE {
'i' : f,
'x' : ActorMethod<[a, b], [[] | [a], [] | [b]]>,
}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/fieldnat.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface non_tuple { _1_ : string, _2_ : string }
export type tuple = [string, string];
Expand All @@ -12,3 +13,4 @@ export interface _SERVICE {
'bib' : ActorMethod<[[bigint]], { _0_ : bigint }>,
'foo' : ActorMethod<[{ _2_ : bigint }], { _2_ : bigint, '_2' : bigint }>,
}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/keyword.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type if_ = {
'branch' : { 'val' : bigint, 'left' : if_, 'right' : if_ }
Expand Down Expand Up @@ -30,3 +31,4 @@ export interface _SERVICE {
undefined
>,
}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/management.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type bitcoin_address = string;
export type bitcoin_network = { 'mainnet' : null } |
Expand Down Expand Up @@ -170,3 +171,4 @@ export interface _SERVICE {
undefined
>,
}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/recursion.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type A = B;
export type B = [] | [A];
Expand All @@ -13,3 +14,4 @@ export type tree = {
} |
{ 'leaf' : bigint };
export interface _SERVICE extends s {}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/recursive_class.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface s { 'next' : ActorMethod<[], Principal> }
export interface _SERVICE extends s {}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/service.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export type Func = ActorMethod<[], Principal>;
export interface Service { 'f' : Func }
Expand All @@ -17,3 +18,4 @@ export interface _SERVICE {
{ 'b' : { 'f' : [] | [[Principal, string]] } }
>,
}
export declare const idlFactory: IDL.InterfaceFactory;
2 changes: 2 additions & 0 deletions rust/candid/tests/assets/ok/unicode.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface A {
'\u{e000}' : bigint,
Expand All @@ -17,3 +18,4 @@ export interface _SERVICE {
'函数名' : ActorMethod<[A], B>,
'👀' : ActorMethod<[bigint], bigint>,
}
export declare const idlFactory: IDL.InterfaceFactory;

0 comments on commit 05dab77

Please sign in to comment.