@@ -56,7 +56,7 @@ const requestResponse = async <T>(
5656 )
5757 ` ;
5858
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 ) ;
6060 return handleResponse ( res ) ;
6161} ;
6262
@@ -66,11 +66,12 @@ const requestResponse = async <T>(
6666 * @returns { Array<string> } - list of available modules on the connected relay
6767 */
6868export const getModules = async ( client : FluenceClient ) : Promise < string [ ] > => {
69+ let callbackFn = "getModules"
6970 const particle = new Particle (
7071 `
7172 (seq
7273 (call __relay ("dist" "get_modules") [] result)
73- (call myPeerId ("_callback" "getModules ") [result])
74+ (call myPeerId ("_callback" "${ callbackFn } ") [result])
7475 )
7576 ` ,
7677 {
@@ -79,7 +80,30 @@ export const getModules = async (client: FluenceClient): Promise<string[]> => {
7980 } ,
8081 ) ;
8182
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 ) ;
83107} ;
84108
85109/**
@@ -94,7 +118,7 @@ export const uploadModule = async (
94118 name : string ,
95119 moduleBase64 : string ,
96120 config ?: ModuleConfig ,
97- ) : Promise < string [ ] > => {
121+ ) : Promise < void > => {
98122 if ( ! config ) {
99123 config = {
100124 name : name ,
@@ -122,7 +146,7 @@ export const uploadModule = async (
122146 )
123147 ` ;
124148
125- return sendParticleAsFetch ( client , new Particle ( script , data ) , 'result' ) ;
149+ return sendParticleAsFetch ( client , new Particle ( script , data ) , 'getModules' , "_callback" ) ;
126150} ;
127151
128152/**
@@ -197,10 +221,11 @@ export const createService = async (
197221 * Get all available blueprints hosted on a connected relay. @deprecated prefer using raw Particles instead
198222 * @param { FluenceClient } client - The Fluence Client instance.
199223 * @param {[string] } nodeId - Optional node peer id to get available blueprints from
224+ * @param {[string] } nodeId - Optional node peer id to deploy service to
200225 * @param {[number] } ttl - Optional ttl for the particle which does the job
201226 * @returns { Array<string> } - List of available blueprints
202227 */
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 [ ] > => {
204229 let returnValue = 'blueprints' ;
205230 let call = ( nodeId : string ) => `(call "${ nodeId } " ("dist" "get_blueprints") [] ${ returnValue } )` ;
206231
@@ -246,6 +271,7 @@ export const addProvider = async (
246271/**
247272 * Get a provider from DHT network from neighborhood around a key. @deprecated prefer using raw Particles instead
248273 * @param { FluenceClient } client - The Fluence Client instance.
274+ * @param {[buffer] } key - get provider by this key
249275 * @param {[string] } nodeId - Optional node peer id to get providers from
250276 * @param {[number] } ttl - Optional ttl for the particle which does the job
251277 * @returns { Array<object> } - List of providers
@@ -269,12 +295,51 @@ export const getProviders = async (client: FluenceClient, key: Buffer, nodeId?:
269295 * @param {[number] } ttl - Optional ttl for the particle which does the job
270296 * @returns { Array<string> } - List of peer ids of neighbors of the node
271297 */
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 [ ] > => {
273299 let returnValue = 'neighborhood' ;
274300 let call = ( nodeId : string ) => `(call "${ nodeId } " ("dht" "neighborhood") [node] ${ returnValue } )` ;
275301
276302 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 ) ;
278343
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 ) ;
280345} ;
0 commit comments