feat: Simplify JS Client public API (#257)

This commit is contained in:
Pavel
2023-02-16 14:38:48 +03:00
committed by GitHub
parent 35dfb1bfbc
commit 9daaf41096
24 changed files with 774 additions and 476 deletions

View File

@ -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;
}
};

View File

@ -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));

View File

@ -30,7 +30,7 @@ export const injectRelayService = (def: FunctionCallDef, peer: IFluenceClient) =
handler: () => {
return {
retCode: ResultCodes.success,
result: peer.getStatus().relayPeerId,
result: peer.internals.getRelayPeerId(),
};
},
};