Skip to content

Commit cb117b7

Browse files
JS binding for BigInt (#215)
* JS binding for BigInt * fix * clippy
1 parent 68135b5 commit cb117b7

File tree

14 files changed

+41
-57
lines changed

14 files changed

+41
-57
lines changed

rust/candid/src/bindings/javascript.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub mod value {
229229
use IDLValue::*;
230230
match &*v {
231231
Number(_) | Int(_) | Nat(_) | Int64(_) | Nat64(_) => {
232-
RcDoc::text(format!("new BigNumber('{}')", v))
232+
RcDoc::text(format!("BigInt({})", v))
233233
}
234234
Reserved => RcDoc::text("null"),
235235
Principal(id) => RcDoc::text(format!("Principal.fromText('{}')", id)),
@@ -290,7 +290,6 @@ pub mod test {
290290
pub fn test_generate(test: Test) -> String {
291291
let header = r#"// AUTO-GENERATED. DO NOT EDIT.
292292
// tslint:disable
293-
import BigNumber from 'bignumber.js';
294293
import * as IDL from './idl';
295294
import { Buffer } from 'buffer/';
296295
import { Principal } from './principal';

rust/candid/src/bindings/typescript.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ fn pp_ty(ty: &Type) -> RcDoc {
99
match *ty {
1010
Null => str("null"),
1111
Bool => str("boolean"),
12-
Nat => str("BigNumber"),
13-
Int => str("BigNumber"),
12+
Nat => str("bigint"),
13+
Int => str("bigint"),
1414
Nat8 => str("number"),
1515
Nat16 => str("number"),
1616
Nat32 => str("number"),
17-
Nat64 => str("BigNumber"),
17+
Nat64 => str("bigint"),
1818
Int8 => str("number"),
1919
Int16 => str("number"),
2020
Int32 => str("number"),
21-
Int64 => str("BigNumber"),
21+
Int64 => str("bigint"),
2222
Float32 => str("number"),
2323
Float64 => str("number"),
2424
Text => str("string"),
@@ -148,7 +148,6 @@ fn pp_actor<'a>(env: &'a TypeEnv, ty: &'a Type) -> RcDoc<'a> {
148148

149149
pub fn compile(env: &TypeEnv, actor: &Option<Type>) -> String {
150150
let header = r#"import type { Principal } from '@dfinity/agent';
151-
import type BigNumber from 'bignumber.js';
152151
"#;
153152
let def_list: Vec<_> = env.0.iter().map(|pair| pair.0.as_ref()).collect();
154153
let defs = pp_defs(env, &def_list);

rust/candid/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<'de> Deserializer<'de> {
351351
// processed the field_name, field_name will be reset to None.
352352
fn set_field_name(&mut self, field: FieldLabel) {
353353
if self.field_name.is_some() {
354-
panic!(format!("field_name already taken {:?}", self.field_name));
354+
panic!("field_name already taken");
355355
}
356356
self.field_name = Some(field);
357357
}

rust/candid/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
//! ```
247247
//!
248248
249+
#![allow(clippy::upper_case_acronyms)]
250+
249251
pub use candid_derive::{candid_method, export_service, CandidType};
250252
pub use serde::Deserialize;
251253

rust/candid/tests/assets/ok/actor.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Principal } from '@dfinity/agent';
2-
import type BigNumber from 'bignumber.js';
32
export type f = (
43
arg_0: number,
54
) => Promise<number>;
65
export type g = f;
76
export type h = (arg_0: [Principal, string]) => Promise<[Principal, string]>;
87
export type o = [] | [o];
98
export default interface _SERVICE {
10-
'f' : (arg_0: BigNumber) => Promise<[Principal, string]>,
9+
'f' : (arg_0: bigint) => Promise<[Principal, string]>,
1110
'g' : f,
1211
'h' : g,
1312
'o' : (arg_0: o) => Promise<o>,

rust/candid/tests/assets/ok/class.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Principal } from '@dfinity/agent';
2-
import type BigNumber from 'bignumber.js';
32
export type List = [] | [
4-
[BigNumber, List]
3+
[bigint, List]
54
];
65
export default interface _SERVICE {
76
'get' : () => Promise<List>,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import type { Principal } from '@dfinity/agent';
2-
import type BigNumber from 'bignumber.js';
32
export type id = number;
43

rust/candid/tests/assets/ok/cyclic.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { Principal } from '@dfinity/agent';
2-
import type BigNumber from 'bignumber.js';
3-
export type A = [] | [
4-
B
5-
];
2+
export type A = [] | [B];
63
export type B = [] | [C];
74
export type C = A;
85
export type X = Y;

rust/candid/tests/assets/ok/escape.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { Principal } from '@dfinity/agent';
2-
import type BigNumber from 'bignumber.js';
32
export interface t {
4-
'\"' : BigNumber,
5-
'\'' : BigNumber,
6-
'\"\'' : BigNumber,
7-
'\\\n\'\"' : BigNumber,
3+
'\"' : bigint,
4+
'\'' : bigint,
5+
'\"\'' : bigint,
6+
'\\\n\'\"' : bigint,
87
};
98
export default interface _SERVICE {
109
'\n\'\"\'\'\"\"\r\t' : (arg_0: t) => Promise<undefined>,
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import type { Principal } from '@dfinity/agent';
2-
import type BigNumber from 'bignumber.js';
32
export type List = [] | [
4-
{ 'head' : BigNumber, 'tail' : List }
3+
{ 'head' : bigint, 'tail' : List }
54
];
65
export interface broker { 'find' : (arg_0: string) => Promise<Principal> };
76
export type f = (arg_0: List, arg_1: [Principal, string]) => Promise<
87
[] | [List]
98
>;
109
export type my_type = Principal;
1110
export interface nested {
12-
_0_ : BigNumber,
13-
_1_ : BigNumber,
14-
_2_ : [BigNumber, BigNumber],
15-
_3_ : { _0_ : BigNumber, _42_ : BigNumber, _43_ : number },
16-
_40_ : BigNumber,
11+
_0_ : bigint,
12+
_1_ : bigint,
13+
_2_ : [bigint, bigint],
14+
_3_ : { _0_ : bigint, _42_ : bigint, _43_ : number },
15+
_40_ : bigint,
1716
_41_ : { _42_ : null } |
1817
{ 'A' : null } |
1918
{ 'B' : null } |
2019
{ 'C' : null },
21-
_42_ : BigNumber,
20+
_42_ : bigint,
2221
};
2322
export default interface _SERVICE {
2423
'f' : (arg_0: Array<number>, arg_1: [] | [boolean]) => Promise<undefined>,
@@ -27,12 +26,12 @@ export default interface _SERVICE {
2726
arg_1: List,
2827
arg_2: [] | [List],
2928
arg_3: nested,
30-
) => Promise<[BigNumber, Principal]>,
29+
) => Promise<[bigint, Principal]>,
3130
'h' : (
3231
arg_0: Array<[] | [string]>,
33-
arg_1: { 'A' : BigNumber } |
32+
arg_1: { 'A' : bigint } |
3433
{ 'B' : [] | [string] },
3534
arg_2: [] | [List],
36-
) => Promise<{ _42_ : {}, 'id' : BigNumber }>,
35+
) => Promise<{ _42_ : {}, 'id' : bigint }>,
3736
'i' : f,
3837
};

0 commit comments

Comments
 (0)