module config, blueprint id (#993)

This commit is contained in:
Dima 2020-12-04 17:08:35 +03:00 committed by GitHub
parent 14a8463d3a
commit 957c0f90c1
7 changed files with 55 additions and 20 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "fluence",
"version": "0.7.82",
"version": "0.7.93",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -25,9 +25,9 @@
}
},
"@fluencelabs/aquamarine-stepper": {
"version": "0.0.13",
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-stepper/-/aquamarine-stepper-0.0.13.tgz",
"integrity": "sha512-DymSTILKXUeZsyOB9b7zKv4ZfGsbGUCMjCsafUHQIaAsMxD+p4DJsQ4FdHRI6rh9MqWmv5OVFXEpHhqai7fqug=="
"version": "0.0.15",
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-stepper/-/aquamarine-stepper-0.0.15.tgz",
"integrity": "sha512-dCzBlqiR0/EiYzCseIlpE8wbi/jRMLvMsFkTIm0tmhvSfWtBskXLniM9CE4JqyUATAVuBdKJ5HKsufACugGf4A=="
},
"@sinonjs/commons": {
"version": "1.7.2",

View File

@ -1,6 +1,6 @@
{
"name": "fluence",
"version": "0.7.83",
"version": "0.7.95",
"description": "the browser js-libp2p client for the Fluence network",
"main": "./dist/fluence.js",
"typings": "./dist/fluence.d.ts",
@ -15,7 +15,7 @@
"author": "Fluence Labs",
"license": "Apache 2.0",
"dependencies": {
"@fluencelabs/aquamarine-stepper": "0.0.13",
"@fluencelabs/aquamarine-stepper": "0.0.15",
"async": "3.2.0",
"base64-js": "1.3.1",
"bs58": "4.0.1",

View File

@ -64,4 +64,6 @@ declare global {
}
}
window.Fluence = Fluence;
if (typeof window !== "undefined") {
window.Fluence = Fluence;
}

View File

@ -30,6 +30,7 @@ import {
import {instantiateStepper, Stepper} from "./stepper";
import log from "loglevel";
import {waitService} from "./helpers/waitService";
import {ModuleConfig} from "./moduleConfig";
const bs58 = require('bs58')
@ -213,8 +214,9 @@ export class FluenceClient {
/**
* Send a script to add module to a relay. Waiting for a response from a relay.
*/
async addModule(name: string, moduleBase64: string, nodeId?: string, ttl?: number): Promise<void> {
let config = {
async addModule(name: string, moduleBase64: string, config?: ModuleConfig, nodeId?: string, ttl?: number): Promise<void> {
if (!config) {
config = {
name: name,
mem_pages_count: 100,
logger_enabled: true,
@ -224,6 +226,7 @@ export class FluenceClient {
mapped_dirs: {},
}
}
}
let data = new Map()
data.set("module_bytes", moduleBase64)
@ -237,12 +240,12 @@ export class FluenceClient {
/**
* Send a script to add module to a relay. Waiting for a response from a relay.
*/
async addBlueprint(name: string, dependencies: string[], nodeId?: string, ttl?: number): Promise<string> {
async addBlueprint(name: string, dependencies: string[], blueprintId?: string, nodeId?: string, ttl?: number): Promise<string> {
let returnValue = "blueprint_id";
let call = (nodeId: string) => `(call "${nodeId}" ("dist" "add_blueprint") [blueprint] ${returnValue})`
let data = new Map()
data.set("blueprint", { name: name, dependencies: dependencies })
data.set("blueprint", { name: name, dependencies: dependencies, id: blueprintId })
return this.requestResponse("addBlueprint", call, returnValue, data, (args: any[]) => args[0] as string, nodeId, ttl)
}

29
src/moduleConfig.ts Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface ModuleConfig {
name: string,
mem_pages_count?: number,
logger_enabled?: boolean,
wasi?: Wasi,
mounted_binaries?: object
}
export interface Wasi {
envs?: object,
preopened_files?: string[],
mapped_dirs?: object,
}

View File

@ -36,7 +36,7 @@ function wrapScript(selfPeerId: string, script: string, fields: string[]): strin
fields.forEach((v) => {
script = `
(seq
(call "${selfPeerId}" ("" "load") ["${v}"] ${v})
(call %init_peer_id% ("" "load") ["${v}"] ${v})
${script}
)
`

View File

@ -77,7 +77,8 @@ export async function instantiateStepper(pid: PeerId): Promise<Stepper> {
log.debug(str)
break;
case 5:
log.trace(str)
// we don't want a trace in trace logs
log.debug(str)
break;
}
} finally {