@@ -56,7 +56,7 @@ const requestResponse = async <T>(
56
56
)
57
57
` ;
58
58
59
- const res = await sendParticleAsFetch < any [ ] > ( client , new Particle ( script , data , ttl ) , '' ) ;
59
+ const res = await sendParticleAsFetch < any [ ] > ( client , new Particle ( script , data , ttl ) , name ) ;
60
60
return handleResponse ( res ) ;
61
61
} ;
62
62
@@ -66,11 +66,12 @@ const requestResponse = async <T>(
66
66
* @returns { Array<string> } - list of available modules on the connected relay
67
67
*/
68
68
export const getModules = async ( client : FluenceClient ) : Promise < string [ ] > => {
69
+ let callbackFn = "getModules"
69
70
const particle = new Particle (
70
71
`
71
72
(seq
72
73
(call __relay ("dist" "get_modules") [] result)
73
- (call myPeerId ("_callback" "getModules ") [result])
74
+ (call myPeerId ("_callback" "${ callbackFn } ") [result])
74
75
)
75
76
` ,
76
77
{
@@ -79,7 +80,30 @@ export const getModules = async (client: FluenceClient): Promise<string[]> => {
79
80
} ,
80
81
) ;
81
82
82
- return sendParticleAsFetch ( client , particle , 'getModules' ) ;
83
+ return sendParticleAsFetch ( client , particle , callbackFn ) ;
84
+ } ;
85
+
86
+ /**
87
+ * Get all available modules hosted on a connected relay. @deprecated prefer using raw Particles instead
88
+ * @param { FluenceClient } client - The Fluence Client instance.
89
+ * @returns { Array<string> } - list of available modules on the connected relay
90
+ */
91
+ export const getInterfaces = async ( client : FluenceClient ) : Promise < string [ ] > => {
92
+ let callbackFn = "getInterfaces"
93
+ const particle = new Particle (
94
+ `
95
+ (seq
96
+ (call __relay ("srv" "get_interfaces") [] result)
97
+ (call myPeerId ("_callback" "${ callbackFn } ") [result])
98
+ )
99
+ ` ,
100
+ {
101
+ __relay : client . relayPeerId ,
102
+ myPeerId : client . selfPeerId ,
103
+ } ,
104
+ ) ;
105
+
106
+ return sendParticleAsFetch ( client , particle , callbackFn ) ;
83
107
} ;
84
108
85
109
/**
@@ -94,7 +118,7 @@ export const uploadModule = async (
94
118
name : string ,
95
119
moduleBase64 : string ,
96
120
config ?: ModuleConfig ,
97
- ) : Promise < string [ ] > => {
121
+ ) : Promise < void > => {
98
122
if ( ! config ) {
99
123
config = {
100
124
name : name ,
@@ -122,7 +146,7 @@ export const uploadModule = async (
122
146
)
123
147
` ;
124
148
125
- return sendParticleAsFetch ( client , new Particle ( script , data ) , 'result' ) ;
149
+ return sendParticleAsFetch ( client , new Particle ( script , data ) , 'getModules' , "_callback" ) ;
126
150
} ;
127
151
128
152
/**
@@ -197,10 +221,11 @@ export const createService = async (
197
221
* Get all available blueprints hosted on a connected relay. @deprecated prefer using raw Particles instead
198
222
* @param { FluenceClient } client - The Fluence Client instance.
199
223
* @param {[string] } nodeId - Optional node peer id to get available blueprints from
224
+ * @param {[string] } nodeId - Optional node peer id to deploy service to
200
225
* @param {[number] } ttl - Optional ttl for the particle which does the job
201
226
* @returns { Array<string> } - List of available blueprints
202
227
*/
203
- export const getBlueprints = async ( client : FluenceClient , nodeId : string , ttl ?: number ) : Promise < string [ ] > => {
228
+ export const getBlueprints = async ( client : FluenceClient , nodeId ? : string , ttl ?: number ) : Promise < string [ ] > => {
204
229
let returnValue = 'blueprints' ;
205
230
let call = ( nodeId : string ) => `(call "${ nodeId } " ("dist" "get_blueprints") [] ${ returnValue } )` ;
206
231
@@ -246,6 +271,7 @@ export const addProvider = async (
246
271
/**
247
272
* Get a provider from DHT network from neighborhood around a key. @deprecated prefer using raw Particles instead
248
273
* @param { FluenceClient } client - The Fluence Client instance.
274
+ * @param {[buffer] } key - get provider by this key
249
275
* @param {[string] } nodeId - Optional node peer id to get providers from
250
276
* @param {[number] } ttl - Optional ttl for the particle which does the job
251
277
* @returns { Array<object> } - List of providers
@@ -269,12 +295,51 @@ export const getProviders = async (client: FluenceClient, key: Buffer, nodeId?:
269
295
* @param {[number] } ttl - Optional ttl for the particle which does the job
270
296
* @returns { Array<string> } - List of peer ids of neighbors of the node
271
297
*/
272
- export const neighborhood = async ( client : FluenceClient , node : string , ttl ?: number ) : Promise < string [ ] > => {
298
+ export const neighborhood = async ( client : FluenceClient , nodeId ? : string , ttl ?: number ) : Promise < string [ ] > => {
273
299
let returnValue = 'neighborhood' ;
274
300
let call = ( nodeId : string ) => `(call "${ nodeId } " ("dht" "neighborhood") [node] ${ returnValue } )` ;
275
301
276
302
let data = new Map ( ) ;
277
- data . set ( 'node' , node ) ;
303
+ if ( nodeId ) data . set ( 'node' , nodeId ) ;
304
+
305
+ return requestResponse ( client , 'neighborhood' , call , returnValue , data , ( args ) => args [ 0 ] as string [ ] , nodeId , ttl ) ;
306
+ } ;
307
+
308
+ /**
309
+ * Upload an AIR script, that will be runned in a loop on a node. @deprecated prefer using raw Particles instead
310
+ * @param { FluenceClient } client - The Fluence Client instance.
311
+ * @param {[string] } script - script to upload
312
+ * @param period how often start script processing, in seconds
313
+ * @param {[string] } nodeId - Optional node peer id to get neighborhood from
314
+ * @param {[number] } ttl - Optional ttl for the particle which does the job
315
+ * @returns {[string] } - script id
316
+ */
317
+ export const addScript = async ( client : FluenceClient , script : string , period ?: number , nodeId ?: string , ttl ?: number ) : Promise < string > => {
318
+ let returnValue = 'id' ;
319
+ let periodV = ""
320
+ if ( period ) periodV = period . toString ( )
321
+ let call = ( nodeId : string ) => `(call "${ nodeId } " ("script" "add") [script ${ periodV } ] ${ returnValue } )` ;
322
+
323
+ let data = new Map ( ) ;
324
+ data . set ( 'script' , script ) ;
325
+ if ( period ) data . set ( 'period' , period )
326
+
327
+ return requestResponse ( client , 'addScript' , call , returnValue , data , ( args ) => args [ 0 ] as string , nodeId , ttl ) ;
328
+ } ;
329
+
330
+ /**
331
+ * Remove an AIR script from a node. @deprecated prefer using raw Particles instead
332
+ * @param { FluenceClient } client - The Fluence Client instance.
333
+ * @param {[string] } id - id of a script
334
+ * @param {[string] } nodeId - Optional node peer id to get neighborhood from
335
+ * @param {[number] } ttl - Optional ttl for the particle which does the job
336
+ */
337
+ export const removeScript = async ( client : FluenceClient , id : string , nodeId ?: string , ttl ?: number ) : Promise < void > => {
338
+ let returnValue = 'empty' ;
339
+ let call = ( nodeId : string ) => `(call "${ nodeId } " ("script" "remove") [script_id] ${ returnValue } )` ;
340
+
341
+ let data = new Map ( ) ;
342
+ data . set ( 'script_id' , id ) ;
278
343
279
- return requestResponse ( client , 'neighborhood ' , call , returnValue , data , ( args ) => args [ 0 ] as string [ ] , node , ttl ) ;
344
+ return requestResponse ( client , 'removeScript ' , call , returnValue , data , ( args ) => { } , nodeId , ttl ) ;
280
345
} ;
0 commit comments