Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/fluence-js/aqua/src/node-utils.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data ReadFileResult:
-- Was the call successful or not
success: bool
-- File content in base64 if the call was successful
content: ?string
-- Error message if the call was unsuccessful
error: ?string

service NodeUtils("node_utils"):
-- Read file from file system.
-- returns file content in base64 format
read_file(path: string) -> ReadFileResult
32 changes: 32 additions & 0 deletions packages/fluence-js/aqua/src/single-module-srv.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
alias Bytes : []u8

data ServiceCreationResult:
success: bool
service_id: ?string
error: ?string

data ReadFileResult:
success: bool
content: ?string
error: ?string

data RemoveResult:
success: bool
error: ?string

alias ListServiceResult: []string

service Srv("single_module_srv"):
-- Used to create a service on a certain node
-- Arguments:
-- bytes – a base64 string containing the .wasm module to add.
-- Returns: service_id – the service ID of the created service.
create(wasm_b64_content: string) -> ServiceCreationResult

-- Used to remove a service from a certain node
-- Arguments:
-- service_id – ID of the service to remove
remove(service_id: string) -> RemoveResult

-- Returns a list of services ids running on a peer
list() -> ListServiceResult
40 changes: 40 additions & 0 deletions packages/fluence-js/aqua/tests/srv-tests.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Export

import Srv from "../src/single-module-srv.aqua"
import NodeUtils from "../src/node-utils.aqua"
export happy_path, list_services, file_not_found, service_removed, removing_non_exiting

service Greeting("greeting"):
greeting(name: string) -> string

func happy_path(file_path: string) -> string:
file <- NodeUtils.read_file(file_path)
created_service <- Srv.create(file.content!)
Greeting created_service.service_id!
<- Greeting.greeting("test")

func list_services(file_path: string) -> []string:
file <- NodeUtils.read_file(file_path)
Srv.create(file.content!)
Srv.create(file.content!)
Srv.create(file.content!)
<- Srv.list()

func file_not_found() -> string:
e <- NodeUtils.read_file("/random/incorrect/file")
<- e.error!

func service_removed(file_path: string) -> string:
file <- NodeUtils.read_file(file_path)
created_service <- Srv.create(file.content!)
Greeting created_service.service_id!
Srv.remove(created_service.service_id!)
try:
dontcare <- Greeting.greeting("test")
catch e:
<- e.message

func removing_non_exiting() -> string:
e <- Srv.remove("random_id")
<- e.error!

25 changes: 13 additions & 12 deletions packages/fluence-js/src/__test__/_aqua/marine-js-logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.7.2-314
* Aqua version: 0.7.7-362
*
*/
import { Fluence, FluencePeer } from '../../index';
import { CallParams, callFunction, registerService } from '../../internal/compilerSupport/v3';
import { FluencePeer } from '../../index';
import type { CallParams$$ } from '../../internal/compilerSupport/v4';
import { callFunction$$, registerService$$ } from '../../internal/compilerSupport/v4';

// Services

export interface GreetingRecordDef {
greeting_record: (
callParams: CallParams<null>,
callParams: CallParams$$<null>,
) => { num: number; str: string } | Promise<{ num: number; str: string }>;
log_debug: (callParams: CallParams<null>) => void | Promise<void>;
log_error: (callParams: CallParams<null>) => void | Promise<void>;
log_info: (callParams: CallParams<null>) => void | Promise<void>;
log_trace: (callParams: CallParams<null>) => void | Promise<void>;
log_warn: (callParams: CallParams<null>) => void | Promise<void>;
void_fn: (callParams: CallParams<null>) => void | Promise<void>;
log_debug: (callParams: CallParams$$<null>) => void | Promise<void>;
log_error: (callParams: CallParams$$<null>) => void | Promise<void>;
log_info: (callParams: CallParams$$<null>) => void | Promise<void>;
log_trace: (callParams: CallParams$$<null>) => void | Promise<void>;
log_warn: (callParams: CallParams$$<null>) => void | Promise<void>;
void_fn: (callParams: CallParams$$<null>) => void | Promise<void>;
}
export function registerGreetingRecord(serviceId: string, service: GreetingRecordDef): void;
export function registerGreetingRecord(peer: FluencePeer, serviceId: string, service: GreetingRecordDef): void;

export function registerGreetingRecord(...args: any) {
registerService(args, {
registerService$$(args, {
functions: {
tag: 'labeledProduct',
fields: {
Expand Down Expand Up @@ -133,7 +134,7 @@ export function call_info(...args: any) {
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
`;
return callFunction(
return callFunction$$(
args,
{
functionName: 'call_info',
Expand Down
15 changes: 8 additions & 7 deletions packages/fluence-js/src/__test__/_aqua/marine-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.7.2-314
* Aqua version: 0.7.7-362
*
*/
import { Fluence, FluencePeer } from '../../index';
import { CallParams, callFunction, registerService } from '../../internal/compilerSupport/v3';
import { FluencePeer } from '../../index';
import type { CallParams$$ } from '../../internal/compilerSupport/v4';
import { callFunction$$, registerService$$ } from '../../internal/compilerSupport/v4';

// Services

export interface GreetingDef {
greeting: (name: string, callParams: CallParams<'name'>) => string | Promise<string>;
greeting: (name: string, callParams: CallParams$$<'name'>) => string | Promise<string>;
greeting_record: (
callParams: CallParams<null>,
callParams: CallParams$$<null>,
) => { num: number; str: string } | Promise<{ num: number; str: string }>;
}
export function registerGreeting(service: GreetingDef): void;
Expand All @@ -23,7 +24,7 @@ export function registerGreeting(peer: FluencePeer, service: GreetingDef): void;
export function registerGreeting(peer: FluencePeer, serviceId: string, service: GreetingDef): void;

export function registerGreeting(...args: any) {
registerService(args, {
registerService$$(args, {
defaultServiceId: 'greeting',
functions: {
tag: 'labeledProduct',
Expand Down Expand Up @@ -110,7 +111,7 @@ export function call(...args: any) {
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`;
return callFunction(
return callFunction$$(
args,
{
functionName: 'call',
Expand Down
21 changes: 11 additions & 10 deletions packages/fluence-js/src/__test__/_aqua/sig-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.7.2-314
* Aqua version: 0.7.7-362
*
*/
import { Fluence, FluencePeer } from '../../index';
import { CallParams, callFunction, registerService } from '../../internal/compilerSupport/v3';
import { FluencePeer } from '../../index';
import type { CallParams$$ } from '../../internal/compilerSupport/v4';
import { callFunction$$, registerService$$ } from '../../internal/compilerSupport/v4';

// Services

export interface DataProviderDef {
provide_data: (callParams: CallParams<null>) => number[] | Promise<number[]>;
provide_data: (callParams: CallParams$$<null>) => number[] | Promise<number[]>;
}
export function registerDataProvider(service: DataProviderDef): void;
export function registerDataProvider(serviceId: string, service: DataProviderDef): void;
export function registerDataProvider(peer: FluencePeer, service: DataProviderDef): void;
export function registerDataProvider(peer: FluencePeer, serviceId: string, service: DataProviderDef): void;

export function registerDataProvider(...args: any) {
registerService(args, {
registerService$$(args, {
defaultServiceId: 'data',
functions: {
tag: 'labeledProduct',
Expand Down Expand Up @@ -49,17 +50,17 @@ export function registerDataProvider(...args: any) {
}

export interface SigDef {
get_peer_id: (callParams: CallParams<null>) => string | Promise<string>;
get_peer_id: (callParams: CallParams$$<null>) => string | Promise<string>;
sign: (
data: number[],
callParams: CallParams<'data'>,
callParams: CallParams$$<'data'>,
) =>
| { error: string | null; signature: number[] | null; success: boolean }
| Promise<{ error: string | null; signature: number[] | null; success: boolean }>;
verify: (
signature: number[],
data: number[],
callParams: CallParams<'signature' | 'data'>,
callParams: CallParams$$<'signature' | 'data'>,
) => boolean | Promise<boolean>;
}
export function registerSig(service: SigDef): void;
Expand All @@ -68,7 +69,7 @@ export function registerSig(peer: FluencePeer, service: SigDef): void;
export function registerSig(peer: FluencePeer, serviceId: string, service: SigDef): void;

export function registerSig(...args: any) {
registerService(args, {
registerService$$(args, {
defaultServiceId: 'sig',
functions: {
tag: 'labeledProduct',
Expand Down Expand Up @@ -200,7 +201,7 @@ export function callSig(...args: any) {
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`;
return callFunction(
return callFunction$$(
args,
{
functionName: 'callSig',
Expand Down
Loading