mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-04-25 17:52:13 +00:00
Add fname and module name to arguments (#917)
This commit is contained in:
parent
afacef5138
commit
b34c0628c5
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fluence",
|
"name": "fluence",
|
||||||
"version": "0.6.1",
|
"version": "0.6.5",
|
||||||
"description": "the browser js-libp2p client for the Fluence network",
|
"description": "the browser js-libp2p client for the Fluence network",
|
||||||
"main": "./dist/fluence.js",
|
"main": "./dist/fluence.js",
|
||||||
"typings": "./dist/fluence.d.ts",
|
"typings": "./dist/fluence.d.ts",
|
||||||
|
@ -70,9 +70,11 @@ export class FluenceClient {
|
|||||||
* @param target receiver
|
* @param target receiver
|
||||||
* @param args message in the call
|
* @param args message in the call
|
||||||
* @param predicate will be applied to each incoming call until it matches
|
* @param predicate will be applied to each incoming call until it matches
|
||||||
|
* @param moduleId module name
|
||||||
|
* @param fname functin name
|
||||||
*/
|
*/
|
||||||
async sendCallWaitResponse(target: Address, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined)): Promise<any> {
|
async sendCallWaitResponse(target: Address, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined), moduleId?: string, fname?: string): Promise<any> {
|
||||||
await this.sendCall(target, args, true);
|
await this.sendCall(target, args, true, moduleId, fname);
|
||||||
return this.waitResponse(predicate);
|
return this.waitResponse(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +84,13 @@ export class FluenceClient {
|
|||||||
* @param target receiver
|
* @param target receiver
|
||||||
* @param args message in the call
|
* @param args message in the call
|
||||||
* @param reply add a `replyTo` field or not
|
* @param reply add a `replyTo` field or not
|
||||||
|
* @param moduleId module name
|
||||||
|
* @param fname function name
|
||||||
* @param name common field for debug purposes
|
* @param name common field for debug purposes
|
||||||
*/
|
*/
|
||||||
async sendCall(target: Address, args: any, reply?: boolean, name?: string) {
|
async sendCall(target: Address, args: any, reply?: boolean, moduleId?: string, fname?: string, name?: string) {
|
||||||
if (this.connection && this.connection.isConnected()) {
|
if (this.connection && this.connection.isConnected()) {
|
||||||
await this.connection.sendFunctionCall(target, args, reply, name);
|
await this.connection.sendFunctionCall(target, args, reply, moduleId, fname, name);
|
||||||
} else {
|
} else {
|
||||||
throw Error("client is not connected")
|
throw Error("client is not connected")
|
||||||
}
|
}
|
||||||
@ -95,13 +99,14 @@ export class FluenceClient {
|
|||||||
/**
|
/**
|
||||||
* Send call to the service.
|
* Send call to the service.
|
||||||
*
|
*
|
||||||
* @param serviceId
|
* @param moduleId
|
||||||
* @param args message to the service
|
* @param args message to the service
|
||||||
|
* @param fname function name
|
||||||
* @param name common field for debug purposes
|
* @param name common field for debug purposes
|
||||||
*/
|
*/
|
||||||
async sendServiceCall(serviceId: string, args: any, name?: string) {
|
async sendServiceCall(moduleId: string, args: any, fname?: string, name?: string) {
|
||||||
if (this.connection && this.connection.isConnected()) {
|
if (this.connection && this.connection.isConnected()) {
|
||||||
await this.connection.sendServiceCall(serviceId, false, args, name);
|
await this.connection.sendServiceCall(moduleId, false, args, fname, name);
|
||||||
} else {
|
} else {
|
||||||
throw Error("client is not connected")
|
throw Error("client is not connected")
|
||||||
}
|
}
|
||||||
@ -110,13 +115,14 @@ export class FluenceClient {
|
|||||||
/**
|
/**
|
||||||
* Send a call to the local service on a peer the client connected with.
|
* Send a call to the local service on a peer the client connected with.
|
||||||
*
|
*
|
||||||
* @param serviceId
|
* @param moduleId
|
||||||
* @param args message to the service
|
* @param args message to the service
|
||||||
|
* @param fname function name
|
||||||
* @param name common field for debug purposes
|
* @param name common field for debug purposes
|
||||||
*/
|
*/
|
||||||
async sendServiceLocalCall(serviceId: string, args: any, name?: string) {
|
async sendServiceLocalCall(moduleId: string, args: any, fname?: string, name?: string) {
|
||||||
if (this.connection && this.connection.isConnected()) {
|
if (this.connection && this.connection.isConnected()) {
|
||||||
await this.connection.sendServiceCall(serviceId, true, args, name);
|
await this.connection.sendServiceCall(moduleId, true, args, fname, name);
|
||||||
} else {
|
} else {
|
||||||
throw Error("client is not connected")
|
throw Error("client is not connected")
|
||||||
}
|
}
|
||||||
@ -125,24 +131,26 @@ export class FluenceClient {
|
|||||||
/**
|
/**
|
||||||
* Send call to the service and wait a response matches predicate.
|
* Send call to the service and wait a response matches predicate.
|
||||||
*
|
*
|
||||||
* @param serviceId
|
* @param moduleId
|
||||||
* @param args message to the service
|
* @param args message to the service
|
||||||
* @param predicate will be applied to each incoming call until it matches
|
* @param predicate will be applied to each incoming call until it matches
|
||||||
|
* @param fname function name
|
||||||
*/
|
*/
|
||||||
async sendServiceCallWaitResponse(serviceId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined)): Promise<any> {
|
async sendServiceCallWaitResponse(moduleId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined), fname?: string): Promise<any> {
|
||||||
await this.sendServiceCall(serviceId, args);
|
await this.sendServiceCall(moduleId, args, fname, fname);
|
||||||
return await this.waitResponse(predicate);
|
return await this.waitResponse(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a call to the local service and wait a response matches predicate on a peer the client connected with.
|
* Send a call to the local service and wait a response matches predicate on a peer the client connected with.
|
||||||
*
|
*
|
||||||
* @param serviceId
|
* @param moduleId
|
||||||
* @param args message to the service
|
* @param args message to the service
|
||||||
* @param predicate will be applied to each incoming call until it matches
|
* @param predicate will be applied to each incoming call until it matches
|
||||||
|
* @param fname function name
|
||||||
*/
|
*/
|
||||||
async sendServiceLocalCallWaitResponse(serviceId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined)): Promise<any> {
|
async sendServiceLocalCallWaitResponse(moduleId: string, args: any, predicate: (args: any, target: Address, replyTo: Address) => (boolean | undefined), fname?: string): Promise<any> {
|
||||||
await this.sendServiceLocalCall(serviceId, args);
|
await this.sendServiceLocalCall(moduleId, args, fname);
|
||||||
return await this.waitResponse(predicate);
|
return await this.waitResponse(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,10 +238,10 @@ export class FluenceClient {
|
|||||||
/**
|
/**
|
||||||
* Sends a call to register the service_id.
|
* Sends a call to register the service_id.
|
||||||
*/
|
*/
|
||||||
async registerService(serviceId: string, fn: (req: FunctionCall) => void) {
|
async registerService(moduleId: string, fn: (req: FunctionCall) => void) {
|
||||||
await this.connection.registerService(serviceId);
|
await this.connection.registerService(moduleId);
|
||||||
|
|
||||||
this.services.addService(serviceId, fn)
|
this.services.addService(moduleId, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// subscribe new hook for every incoming call, to handle in-service responses and other different cases
|
// subscribe new hook for every incoming call, to handle in-service responses and other different cases
|
||||||
@ -244,10 +252,10 @@ export class FluenceClient {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a call to unregister the service_id.
|
* Sends a call to unregister the service.
|
||||||
*/
|
*/
|
||||||
async unregisterService(serviceId: string) {
|
async unregisterService(moduleId: string) {
|
||||||
if (this.services.deleteService(serviceId)) {
|
if (this.services.deleteService(moduleId)) {
|
||||||
console.warn("unregister is not implemented yet (service: ${serviceId}")
|
console.warn("unregister is not implemented yet (service: ${serviceId}")
|
||||||
// TODO unregister in fluence network when it will be supported
|
// TODO unregister in fluence network when it will be supported
|
||||||
// let regMsg = makeRegisterMessage(serviceId, PeerId.createFromB58String(this.nodePeerId));
|
// let regMsg = makeRegisterMessage(serviceId, PeerId.createFromB58String(this.nodePeerId));
|
||||||
|
@ -89,15 +89,15 @@ export class FluenceConnection {
|
|||||||
/**
|
/**
|
||||||
* Sends remote service_id call.
|
* Sends remote service_id call.
|
||||||
*/
|
*/
|
||||||
async sendServiceCall(serviceId: string, isLocal: boolean, args: any, name?: string) {
|
async sendServiceCall(moduleId: string, isLocal: boolean, args: any, fname?: string, name?: string) {
|
||||||
let target;
|
let target;
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
target = createPeerAddress(this.nodePeerId.toB58String());
|
target = createPeerAddress(this.nodePeerId.toB58String());
|
||||||
} else {
|
} else {
|
||||||
target = createServiceAddress(serviceId);
|
target = createServiceAddress(moduleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
let regMsg = makeCall(serviceId, target, args, this.sender, this.sender, name);
|
let regMsg = makeCall(moduleId, target, args, this.sender, this.sender, fname, name);
|
||||||
await this.sendCall(regMsg);
|
await this.sendCall(regMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,13 +187,13 @@ export class FluenceConnection {
|
|||||||
/**
|
/**
|
||||||
* Send FunctionCall to the connected node.
|
* Send FunctionCall to the connected node.
|
||||||
*/
|
*/
|
||||||
async sendFunctionCall(target: Address, args: any, reply?: boolean, name?: string) {
|
async sendFunctionCall(target: Address, args: any, reply?: boolean, moduleId?: string, fname?: string, name?: string) {
|
||||||
this.checkConnectedOrThrow();
|
this.checkConnectedOrThrow();
|
||||||
|
|
||||||
let replyTo;
|
let replyTo;
|
||||||
if (reply) replyTo = this.sender;
|
if (reply) replyTo = this.sender;
|
||||||
|
|
||||||
let call = makeFunctionCall(genUUID(), target, this.sender, args, undefined, undefined, replyTo, name);
|
let call = makeFunctionCall(genUUID(), target, this.sender, args, moduleId, fname, replyTo, name);
|
||||||
|
|
||||||
await this.sendCall(call);
|
await this.sendCall(call);
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,14 @@ export function callToString(call: FunctionCall) {
|
|||||||
return JSON.stringify(obj)
|
return JSON.stringify(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeFunctionCall(uuid: string, target: Address, sender: Address, args: object, moduleF?: string, fname?: string, replyTo?: Address, name?: string): FunctionCall {
|
export function makeFunctionCall(uuid: string, target: Address, sender: Address, args: object, moduleId?: string, fname?: string, replyTo?: Address, name?: string): FunctionCall {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
target: target,
|
target: target,
|
||||||
reply_to: replyTo,
|
reply_to: replyTo,
|
||||||
sender: sender,
|
sender: sender,
|
||||||
"module": moduleF,
|
"module": moduleId,
|
||||||
fname: fname,
|
fname: fname,
|
||||||
arguments: args,
|
arguments: args,
|
||||||
name: name,
|
name: name,
|
||||||
@ -113,12 +113,12 @@ export function makePeerCall(client: PeerId, msg: any, sender: Address, replyTo?
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to call remote service_id
|
* Message to call remote service
|
||||||
*/
|
*/
|
||||||
export function makeCall(functionId: string, target: Address, args: any, sender: Address, replyTo?: Address, name?: string): FunctionCall {
|
export function makeCall(moduleId: string, target: Address, args: any, sender: Address, replyTo?: Address, fname?: string, name?: string): FunctionCall {
|
||||||
|
|
||||||
|
|
||||||
return makeFunctionCall(genUUID(), target, sender, args, functionId, undefined, replyTo, name);
|
return makeFunctionCall(genUUID(), target, sender, args, moduleId, fname, replyTo, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user