mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-18 02:21:21 +00:00
feat: Simplify JS Client public API (#257)
This commit is contained in:
@ -6,6 +6,7 @@ import {
|
||||
getArgumentTypes,
|
||||
isReturnTypeVoid,
|
||||
IFluenceClient,
|
||||
CallAquaFunction,
|
||||
} from '@fluencelabs/interfaces';
|
||||
|
||||
import {
|
||||
@ -29,13 +30,7 @@ import {
|
||||
* @param args - args in the form of JSON where each key corresponds to the name of the argument
|
||||
* @returns
|
||||
*/
|
||||
export function callFunctionImpl(
|
||||
def: FunctionCallDef,
|
||||
script: string,
|
||||
config: FnConfig,
|
||||
peer: IFluenceClient,
|
||||
args: { [key: string]: any },
|
||||
): Promise<unknown> {
|
||||
export const callAquaFunction: CallAquaFunction = ({ def, script, config, peer, args }) => {
|
||||
const argumentTypes = getArgumentTypes(def);
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
@ -87,4 +82,4 @@ export function callFunctionImpl(
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
};
|
||||
|
@ -1,20 +1,7 @@
|
||||
import type { IFluenceClient, ServiceDef } from '@fluencelabs/interfaces';
|
||||
import type { RegisterService } from '@fluencelabs/interfaces';
|
||||
import { registerGlobalService, userHandlerService } from './services.js';
|
||||
|
||||
export const registerServiceImpl = (
|
||||
peer: IFluenceClient,
|
||||
def: ServiceDef,
|
||||
serviceId: string | undefined,
|
||||
service: any,
|
||||
) => {
|
||||
// TODO: TBH service registration is just putting some stuff into a hashmap
|
||||
// there should not be such a check at all
|
||||
if (!peer.getStatus().isInitialized) {
|
||||
throw new Error(
|
||||
'Could not register the service because the peer is not initialized. Are you passing the wrong peer to the register function?',
|
||||
);
|
||||
}
|
||||
|
||||
export const registerService: RegisterService = ({ peer, def, serviceId, service }) => {
|
||||
// Checking for missing keys
|
||||
const requiredKeys = def.functions.tag === 'nil' ? [] : Object.keys(def.functions.fields);
|
||||
const incorrectServiceDefinitions = requiredKeys.filter((f) => !(f in service));
|
||||
|
@ -30,7 +30,7 @@ export const injectRelayService = (def: FunctionCallDef, peer: IFluenceClient) =
|
||||
handler: () => {
|
||||
return {
|
||||
retCode: ResultCodes.success,
|
||||
result: peer.getStatus().relayPeerId,
|
||||
result: peer.internals.getRelayPeerId(),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user