1
1
import { $ , execaCommand } from 'execa' ;
2
2
import { BINARY } from './constants.js' ;
3
3
4
- export const executeCommand = async ( command , params , options = { } ) => {
4
+ export const executeCommand = async (
5
+ command : string ,
6
+ params : string [ ] ,
7
+ options = { } ,
8
+ ) => {
5
9
const { stdout } = await execaCommand (
6
10
`${ command } ${ params . join ( ' ' ) } ` ,
7
11
options ,
@@ -10,12 +14,12 @@ export const executeCommand = async (command, params, options = {}) => {
10
14
} ;
11
15
12
16
export const agd = {
13
- query : async ( ...params ) => {
17
+ query : async ( ...params : string [ ] ) => {
14
18
const newParams = [ 'query' , ...params , '-o json' ] ;
15
19
const data = await executeCommand ( BINARY , newParams ) ;
16
20
return JSON . parse ( data ) ;
17
21
} ,
18
- tx : async ( ...params ) => {
22
+ tx : async ( ...params : string [ ] ) => {
19
23
const newParams = [
20
24
'tx' ,
21
25
'-bblock' ,
@@ -27,7 +31,7 @@ export const agd = {
27
31
const data = await executeCommand ( BINARY , newParams , { shell : true } ) ;
28
32
return JSON . parse ( data ) ;
29
33
} ,
30
- keys : async ( ...params ) => {
34
+ keys : async ( ...params : string [ ] ) => {
31
35
let newParams = [ 'keys' , ...params ] ;
32
36
let shouldParse = true ;
33
37
@@ -48,15 +52,15 @@ export const agd = {
48
52
49
53
return JSON . parse ( data ) ;
50
54
} ,
51
- export : async ( ...params ) => {
55
+ export : async ( ...params : string [ ] ) => {
52
56
const newParams = [ 'export' , ...params ] ;
53
57
const data = await executeCommand ( BINARY , newParams ) ;
54
58
return JSON . parse ( data ) ;
55
59
} ,
56
60
} ;
57
61
58
62
export const agoric = {
59
- follow : async ( ...params ) => {
63
+ follow : async ( ...params : string [ ] ) => {
60
64
let newParams = [ 'follow' , ...params ] ;
61
65
let parseJson = false ;
62
66
@@ -72,11 +76,11 @@ export const agoric = {
72
76
73
77
return data ;
74
78
} ,
75
- wallet : async ( ...params ) => {
79
+ wallet : async ( ...params : string [ ] ) => {
76
80
const newParams = [ 'wallet' , ...params ] ;
77
81
return executeCommand ( 'agoric' , newParams ) ;
78
82
} ,
79
- run : async ( ...params ) => {
83
+ run : async ( ...params : string [ ] ) => {
80
84
const newParams = [ 'run' , ...params ] ;
81
85
return executeCommand ( 'agoric' , newParams ) ;
82
86
} ,
@@ -88,7 +92,7 @@ export const { stdout: agopsLocation } = await $({
88
92
} ) `yarn bin agops` ;
89
93
90
94
export const agops = {
91
- vaults : async ( ...params ) => {
95
+ vaults : async ( ...params : string [ ] ) => {
92
96
const newParams = [ 'vaults' , ...params ] ;
93
97
94
98
const result = await executeCommand ( agopsLocation , newParams ) ;
@@ -101,19 +105,19 @@ export const agops = {
101
105
102
106
return result ;
103
107
} ,
104
- ec : async ( ...params ) => {
108
+ ec : async ( ...params : string [ ] ) => {
105
109
const newParams = [ 'ec' , ...params ] ;
106
110
return executeCommand ( agopsLocation , newParams ) ;
107
111
} ,
108
- oracle : async ( ...params ) => {
112
+ oracle : async ( ...params : string [ ] ) => {
109
113
const newParams = [ 'oracle' , ...params ] ;
110
114
return executeCommand ( agopsLocation , newParams ) ;
111
115
} ,
112
- perf : async ( ...params ) => {
116
+ perf : async ( ...params : string [ ] ) => {
113
117
const newParams = [ 'perf' , ...params ] ;
114
118
return executeCommand ( agopsLocation , newParams ) ;
115
119
} ,
116
- auctioneer : async ( ...params ) => {
120
+ auctioneer : async ( ...params : string [ ] ) => {
117
121
const newParams = [ 'auctioneer' , ...params ] ;
118
122
return executeCommand ( agopsLocation , newParams ) ;
119
123
} ,
@@ -125,23 +129,23 @@ export const { stdout: bundleSourceLocation } = await $({
125
129
} ) `yarn bin bundle-source` ;
126
130
127
131
/**
128
- * @param {string } filePath
129
- * @param {string } bundleName
130
- * @returns {Promise<string> } Returns the filepath of the bundle
132
+ * @returns Returns the filepath of the bundle
131
133
*/
132
- export const bundleSource = async ( filePath , bundleName ) => {
134
+ export const bundleSource = async ( filePath : string , bundleName : string ) => {
133
135
const output =
134
136
await $ `${ bundleSourceLocation } --cache-json /tmp ${ filePath } ${ bundleName } ` ;
135
137
console . log ( output . stderr ) ;
136
138
return `/tmp/bundle-${ bundleName } .json` ;
137
139
} ;
138
140
139
141
export const wellKnownIdentities = async ( io = { } ) => {
142
+ // @ts -expect-error
140
143
const { agoric : { follow = agoric . follow } = { } } = io ;
141
- const zip = ( xs , ys ) => xs . map ( ( x , i ) => [ x , ys [ i ] ] ) ;
142
- const fromSmallCapsEntries = txt => {
144
+ const zip = ( xs : unknown [ ] , ys : unknown [ ] ) => xs . map ( ( x , i ) => [ x , ys [ i ] ] ) ;
145
+ const fromSmallCapsEntries = ( txt : string ) => {
143
146
const { body, slots } = JSON . parse ( txt ) ;
144
147
const theEntries = zip ( JSON . parse ( body . slice ( 1 ) ) , slots ) . map (
148
+ // @ts -expect-error
145
149
( [ [ name , ref ] , boardID ] ) => {
146
150
const iface = ref . replace ( / ^ \$ \d + \. / , '' ) ;
147
151
return [ name , { iface, boardID } ] ;
@@ -166,11 +170,11 @@ export const wellKnownIdentities = async (io = {}) => {
166
170
} ;
167
171
168
172
export const smallCapsContext = ( ) => {
169
- const slots = [ ] ; // XXX global mutable state
173
+ const slots = [ ] as string [ ] ; // XXX global mutable state
170
174
const smallCaps = {
171
- Nat : n => `+${ n } ` ,
175
+ Nat : ( n : number | bigint ) => `+${ n } ` ,
172
176
// XXX mutates obj
173
- ref : obj => {
177
+ ref : ( obj : any ) => {
174
178
if ( obj . ix ) return obj . ix ;
175
179
const ix = slots . length ;
176
180
slots . push ( obj . boardID ) ;
@@ -179,7 +183,7 @@ export const smallCapsContext = () => {
179
183
} ,
180
184
} ;
181
185
182
- const toCapData = body => {
186
+ const toCapData = ( body : unknown ) => {
183
187
const capData = { body : `#${ JSON . stringify ( body ) } ` , slots } ;
184
188
return JSON . stringify ( capData ) ;
185
189
} ;
0 commit comments