This commit is contained in:
Akim Mamedov
2023-11-16 21:16:03 +07:00
parent 26bfc36985
commit ec830bca76
17 changed files with 86 additions and 115 deletions

View File

@ -17,7 +17,7 @@
import { JSONValue } from "@fluencelabs/interfaces";
import { it, describe, expect } from "vitest";
import { ExpirationError, SendError } from "../../jsPeer/errors.js";
import { ExpirationError } from "../../jsPeer/errors.js";
import { CallServiceData } from "../../jsServiceHost/interfaces.js";
import { handleTimeout } from "../../particle/Particle.js";
import { registerHandlersHelper, withClient } from "../../util/testUtils.js";

View File

@ -82,6 +82,9 @@ export const callAquaFunction = async ({
registerParticleScopeService(peer, particle, service);
}
// If fireAndForget is enabled, then function call completed when one of the two conditions is met:
// 1. The particle is sent to the network
// 2. All CallRequests are executed, e.g., all variable loading and local function calls are completed
if (!fireAndForget) {
registerParticleScopeService(peer, particle, responseService(resolve));
}
@ -89,9 +92,6 @@ export const callAquaFunction = async ({
registerParticleScopeService(peer, particle, injectRelayService(peer));
registerParticleScopeService(peer, particle, errorHandlingService(reject));
// If function is void, then it's completed when one of the two conditions is met:
// 1. The particle is sent to the network (state 'sent')
// 2. All CallRequests are executed, e.g., all variable loading and local function calls are completed (state 'localWorkDone')
peer.internals.initiateParticle(particle, resolve, reject);
});

View File

@ -28,7 +28,9 @@ interface RegisterServiceArgs {
service: ServiceImpl;
}
const findAllPossibleServiceMethods = (service: ServiceImpl): Set<string> => {
const findAllPossibleRegisteredServiceFunctions = (
service: ServiceImpl,
): Set<string> => {
let prototype: Record<string, unknown> = service;
const serviceMethods = new Set<string>();
@ -60,17 +62,17 @@ export const registerService = ({
throw new Error("Service ID must be specified");
}
const serviceMethods = findAllPossibleServiceMethods(service);
const serviceFunctions = findAllPossibleRegisteredServiceFunctions(service);
for (const method of serviceMethods) {
for (const serviceFunction of serviceFunctions) {
// The function has type of (arg1, arg2, arg3, ... , ParticleContext) => CallServiceResultType | void
// Account for the fact that user service might be defined as a class - .bind(...)
const handler = service[method];
const handler = service[serviceFunction];
const userDefinedHandler = handler.bind(service);
const serviceDescription = userHandlerService(
serviceId,
method,
serviceFunction,
userDefinedHandler,
);

View File

@ -334,6 +334,7 @@ export abstract class FluencePeer {
registerTracing(this, "tracingSrv", this._classServices.tracing);
}
// TODO: too long, refactor
private _startParticleProcessing() {
this._particleSourceSubscription = this.connection.particleSource.subscribe(
{

View File

@ -41,7 +41,6 @@ export class NodeUtils {
}
try {
// Strange enough, but Buffer type works here, while reading with encoding 'utf-8' doesn't
const data = await readFile(path, "base64");
return {

View File

@ -45,7 +45,7 @@ export class Srv {
if (!this.securityGuard_create(callParams)) {
return {
success: false,
error: ["Security guard validation failed"],
error: ["Marine services could be registered on %init_peer_id% only"],
service_id: null,
};
}
@ -80,7 +80,7 @@ export class Srv {
if (!this.securityGuard_remove(callParams)) {
return {
success: false,
error: ["Security guard validation failed"],
error: ["Marine services could be remove on %init_peer_id% only"],
service_id: null,
};
}

View File

@ -23,11 +23,11 @@ export function registerNodeUtils(
serviceId: string,
service: NodeUtils,
) {
const anyService: Record<never, unknown> = service;
const nodeUtilsService: Record<never, unknown> = service;
registerService({
peer,
service: anyService,
service: nodeUtilsService,
serviceId,
});
}

View File

@ -45,11 +45,11 @@ export function registerSig(
serviceId: string,
service: Sig,
) {
const anyService: Record<never, unknown> = service;
const sigService: Record<never, unknown> = service;
registerService({
peer,
service: anyService,
service: sigService,
serviceId,
});
}

View File

@ -23,12 +23,12 @@ export function registerSrv(
serviceId: string,
service: Srv,
) {
const anyService: Record<never, unknown> = service;
const singleModuleService: Record<never, unknown> = service;
registerService({
peer,
serviceId,
service: anyService,
service: singleModuleService,
});
}

View File

@ -19,7 +19,6 @@
*/
import { registerService } from "../../compilerSupport/registerService.js";
import { ServiceImpl } from "../../compilerSupport/types.js";
import { FluencePeer } from "../../jsPeer/FluencePeer.js";
import { ParticleContext } from "../../jsServiceHost/interfaces.js";
import { Tracing } from "../Tracing.js";
@ -39,13 +38,11 @@ export function registerTracing(
serviceId: string,
service: Tracing,
) {
const tracingService: Record<never, unknown> = service;
registerService({
peer,
serviceId,
// TODO: fix this after changing registerService signature
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
service: service as unknown as ServiceImpl,
service: tracingService,
});
}
// Functions