Merge remote-tracking branch 'origin/master' into tests-fixes

This commit is contained in:
DieMyst 2023-02-22 15:15:37 +04:00
commit 9e212118fc
20 changed files with 110 additions and 59 deletions

View File

@ -1,8 +1,8 @@
{
"packages/client/api": "0.11.3",
"packages/client/js-client.node": "0.6.4",
"packages/client/js-client.web.standalone": "0.13.3",
"packages/client/js-client.node": "0.6.5",
"packages/client/js-client.web.standalone": "0.13.4",
"packages/client/tools": "0.2.1",
"packages/core/interfaces": "0.7.3",
"packages/core/js-peer": "0.8.3"
"packages/core/js-peer": "0.8.4"
}

View File

@ -3,12 +3,13 @@
[![npm](https://img.shields.io/npm/v/@fluencelabs/js-client.api?label=@fluencelabs/js-client.api)](https://www.npmjs.com/package/@fluencelabs/js-client.api)
[![npm](https://img.shields.io/npm/v/@fluencelabs/js-client.web.standalone?label=@fluencelabs/js-client.web.standalone)](https://www.npmjs.com/package/@fluencelabs/js-client.web.standalone)
This is the Javascript client for the [Fluence](https://fluence.network) network.
This is the Javascript client for the [Fluence](https://fluence.network) network. The main role of the JS client is to connect to the Fluence Network and allow you to integrate Aqua code into your application.
## Installation
## Get Started
Adding the Fluence JS client for your web application is very easy.
Adding the Fluence JS client for your web application is very easy:
### Browser-based Apps
1. Add a script tag with the JS Client bundle to your `index.html`. The easiest way to do this is using a CDN (like [JSDELIVR](https://www.jsdelivr.com/) or [UNPKG](https://unpkg.com/)). The script is large, thus we highly recommend to use the `async` attribute.
@ -16,13 +17,15 @@ Adding the Fluence JS client for your web application is very easy:
```html
<head>
<title>Cool App</title>
<script src='https://cdn.jsdelivr.net/npm/@fluencelabs/js-client.web.standalone@0.10.0/dist/js-client.min.js'
async></script>
<title>Cool App</title>
<script
src="https://cdn.jsdelivr.net/npm/@fluencelabs/js-client.web.standalone@0.13.3/dist/js-client.min.js"
async
></script>
</head>
```
If you cannot or don't want to use a CDN, feel free to get the script directly from the `npm` package and host in yourself: `https://www.npmjs.com/package/@fluencelabs/js-client.web.standalone`. You can find the script in the `/dist` directory of the package. (Note: this option means that developers understand what they are doing and know how to serve this file from their own web server.)
If you cannot or don't want to use a CDN, feel free to get the script directly from the [npm package](https://www.npmjs.com/package/@fluencelabs/js-client.web.standalone) and host it yourself. You can find the script in the `/dist` directory of the package. (Note: this option means that developers understand what they are doing and know how to serve this file from their own web server.)
2. Install the following packages:
@ -34,14 +37,30 @@ Adding the Fluence JS client for your web application is very easy:
```
import { Fluence } from "@fluencelabs/js-client.api";
import { krasnodar } from "@fluencelabs/fluence-network-environment";
import { randomKras } from '@fluencelabs/fluence-network-environment';
Fluence.start({
relay: krasnodar[3],
});
Fluence.connect(randomKras());
```
## Use Aqua in a Web Application
### Node.js Apps
1. Install the following packages:
```
npm i @fluencelabs/js-client.api"@fluencelabs/js-client.node @fluencelabs/fluence-network-environment
```
2. Add the following lines at the beginning of your code:
```
import '@fluencelabs/js-client.node';
import { Fluence } from "@fluencelabs/js-client.api";
import { randomKras } from '@fluencelabs/fluence-network-environment';
Fluence.connect(randomKras());
```
## Usage in an Application
Once you've added the client, you can compile [Aqua](https://github.com/fluencelabs/aqua) and run it in your application. To compile Aqua, use [Fluence CLI](https://github.com/fluencelabs/fluence-cli).
@ -100,23 +119,18 @@ Once you've added the client, you can compile [Aqua](https://github.com/fluencel
}
```
**Warning**: Fluence JS client for Node.js is currently broken. We will fix this shortly.
## Development
To hack on the Fluence JS Client itself, please refer to the [development page](./DEVELOPING.md).
## Documentation
The starting point for all documentation related to Fluence is
[fluence.dev](https://fluence.dev/). We also have an active [YouTube channel](https://www.youtube.com/@fluencelabs).
## Support
Please, file an [issue](https://github.com/fluencelabs/fluence-js/issues) if you find a bug. You can also contact us at [Discord](https://discord.com/invite/5qSnPZKh7u) or [Telegram](https://t.me/fluence_project). We will do our best to resolve the issue ASAP.
Please, file an [issue](https://github.com/fluencelabs/js-client/issues) if you find a bug. You can also contact us at [Discord](https://discord.com/invite/5qSnPZKh7u) or [Telegram](https://t.me/fluence_project). We will do our best to resolve the issue ASAP.
## Contributing

View File

@ -6,6 +6,12 @@
* dependencies
* @fluencelabs/js-peer bumped from 0.8.1 to 0.8.2
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @fluencelabs/js-peer bumped from 0.8.3 to 0.8.4
## [0.6.4](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.3...js-client.node-v0.6.4) (2023-02-16)

View File

@ -1,6 +1,6 @@
{
"name": "@fluencelabs/js-client.node",
"version": "0.6.4",
"version": "0.6.5",
"description": "TypeScript implementation of Fluence Peer",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
@ -22,7 +22,7 @@
"author": "Fluence Labs",
"license": "Apache-2.0",
"dependencies": {
"@fluencelabs/js-peer": "0.8.3",
"@fluencelabs/js-peer": "0.8.4",
"@fluencelabs/avm": "0.35.4",
"@fluencelabs/marine-js": "0.3.45",
"platform": "1.3.6"

View File

@ -6,6 +6,20 @@
* dependencies
* @fluencelabs/js-peer bumped from 0.8.1 to 0.8.2
## [0.13.4](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.3...js-client.web.standalone-v0.13.4) (2023-02-22)
### Bug Fixes
* `nodenext` moduleResolution for js peer ([#271](https://github.com/fluencelabs/js-client/issues/271)) ([78d98f1](https://github.com/fluencelabs/js-client/commit/78d98f15c12431dee9fdd7b9869d57760503f8c7))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @fluencelabs/js-peer bumped from 0.8.3 to 0.8.4
## [0.13.3](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.2...js-client.web.standalone-v0.13.3) (2023-02-16)

View File

@ -1,6 +1,6 @@
{
"name": "@fluencelabs/js-client.web.standalone",
"version": "0.13.3",
"version": "0.13.4",
"description": "TypeScript implementation of Fluence Peer",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
@ -16,7 +16,7 @@
"author": "Fluence Labs",
"license": "Apache-2.0",
"dependencies": {
"@fluencelabs/js-peer": "0.8.3",
"@fluencelabs/js-peer": "0.8.4",
"buffer": "6.0.3",
"process": "0.11.10"
},
@ -27,7 +27,7 @@
"@types/jest": "28.1.0",
"jest": "28.1.0",
"ts-jest": "28.0.2",
"js-base64": "3.7.2",
"js-base64": "3.7.5",
"@rollup/plugin-inject": "5.0.3",
"vite-plugin-replace": "0.1.1",
"vite": "4.0.4",

View File

@ -1,5 +1,12 @@
# Changelog
## [0.8.4](https://github.com/fluencelabs/js-client/compare/js-peer-v0.8.3...js-peer-v0.8.4) (2023-02-22)
### Bug Fixes
* `nodenext` moduleResolution for js peer ([#271](https://github.com/fluencelabs/js-client/issues/271)) ([78d98f1](https://github.com/fluencelabs/js-client/commit/78d98f15c12431dee9fdd7b9869d57760503f8c7))
## [0.8.3](https://github.com/fluencelabs/js-client/compare/js-peer-v0.8.2...js-peer-v0.8.3) (2023-02-16)

View File

@ -1,16 +1,17 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
testPathIgnorePatterns: ['dist'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
useESM: true,
},
],
},
"useESM": true
}
]
}
};

View File

@ -1,6 +1,6 @@
{
"name": "@fluencelabs/js-peer",
"version": "0.8.3",
"version": "0.8.4",
"description": "TypeScript implementation of Fluence Peer",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
@ -38,7 +38,7 @@
"@libp2p/peer-id-factory": "2.0.1",
"@libp2p/interface-peer-id": "2.0.1",
"@libp2p/interface-keys": "1.0.7",
"js-base64": "3.7.2",
"js-base64": "3.7.5",
"it-length-prefixed": "8.0.4",
"it-pipe": "2.0.5",
"it-map": "2.0.0",
@ -60,6 +60,6 @@
"@types/uuid": "8.3.2",
"@types/jest": "29.4.0",
"jest": "29.4.1",
"ts-jest": "29.0.5"
"ts-jest": "next"
}
}

View File

@ -17,6 +17,7 @@
import type { PeerIdB58 } from '@fluencelabs/interfaces';
import type { JSONArray, JSONObject, LogLevel } from '@fluencelabs/marine-js/dist/types';
import type { RunParameters, CallResultsArray, InterpreterResult } from '@fluencelabs/avm';
// @ts-ignore
import type { WorkerImplementation } from 'threads/dist/types/master';
export type ParticleHandler = (particle: string) => void;

View File

@ -1,10 +1,10 @@
import { CallParams } from '@fluencelabs/interfaces';
import { toUint8Array } from 'js-base64';
import { CallServiceData } from '../../../interfaces/commonTypes.js';
import { builtInServices } from '../../builtins/common.js';
import { KeyPair } from '../../../keypair/index.js';
import { Sig, defaultSigGuard } from '../../builtins/Sig.js';
import { allowServiceFn } from '../../builtins/securityGuard.js';
import { builtInServices } from '../../builtins/common.js';
const a10b20 = `{
"a": 10,

View File

@ -3,9 +3,9 @@ import { FluenceConnection, ParticleHandler } from '../interfaces/index.js';
import { fromBase64Sk } from '../keypair/index.js';
import { FluencePeer } from './FluencePeer.js';
import { MarineBackgroundRunner } from '../marine/worker/index.js';
import { avmModuleLoader, controlModuleLoader } from './utilsForNode';
import { marineLogFunction } from './utils';
import { MarineBasedAvmRunner } from './avm';
import { avmModuleLoader, controlModuleLoader } from './utilsForNode.js';
import { marineLogFunction } from './utils.js';
import { MarineBasedAvmRunner } from './avm.js';
import log from 'loglevel';
import { WorkerLoaderFromFs } from '../marine/deps-loader/node.js';

View File

@ -1,5 +1,7 @@
// @ts-ignore
import { BlobWorker } from 'threads';
import { fromBase64, toUint8Array } from 'js-base64';
// @ts-ignore
import type { WorkerImplementation } from 'threads/dist/types/master';
import { LazyLoader } from '../../interfaces/index.js';
import { Buffer } from 'buffer';

View File

@ -1,7 +1,9 @@
import { createRequire } from 'module';
import { LazyLoader } from '../../interfaces/index.js';
// @ts-ignore
import type { WorkerImplementation } from 'threads/dist/types/master';
// @ts-ignore
import { Worker } from 'threads';
import { Buffer } from 'buffer';
import * as fs from 'fs';

View File

@ -17,7 +17,9 @@
import { MarineService } from '@fluencelabs/marine-js/dist/MarineService';
import type { Env, MarineServiceConfig } from '@fluencelabs/marine-js/dist/config';
import type { JSONArray, JSONObject, LogMessage } from '@fluencelabs/marine-js/dist/types';
// @ts-ignore
import { Observable, Subject } from 'threads/observable';
// @ts-ignore
import { expose } from 'threads/worker';
let marineServices = new Map<string, MarineService>();

View File

@ -1,6 +1,8 @@
import { LazyLoader } from '../../interfaces/index.js';
// @ts-ignore
import type { WorkerImplementation } from 'threads/dist/types/master';
// @ts-ignore
import { Worker } from 'threads';
export class WorkerLoader extends LazyLoader<WorkerImplementation> {

View File

@ -18,7 +18,9 @@ import type { JSONArray, JSONObject, LogLevel } from '@fluencelabs/marine-js/dis
import { LogFunction, logLevelToEnv } from '@fluencelabs/marine-js/dist/types';
import type { IMarine, IWorkerLoader, IWasmLoader } from '../../interfaces/index.js';
import type { MarineBackgroundInterface } from '../worker-script/index.js';
// @ts-ignore
import { spawn, Thread } from 'threads';
// @ts-ignore
import type { ModuleThread } from 'threads';
export class MarineBackgroundRunner implements IMarine {

View File

@ -2,8 +2,9 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"moduleResolution": "node"
"moduleResolution": "nodenext"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist"],
"esModuleInterop": true
}

24
pnpm-lock.yaml generated
View File

@ -101,7 +101,7 @@ importers:
packages/client/js-client.node:
specifiers:
'@fluencelabs/avm': 0.35.4
'@fluencelabs/js-peer': 0.8.3
'@fluencelabs/js-peer': 0.8.4
'@fluencelabs/marine-js': 0.3.45
'@types/platform': 1.3.4
platform: 1.3.6
@ -116,14 +116,14 @@ importers:
packages/client/js-client.web.standalone:
specifiers:
'@fluencelabs/avm': 0.35.4
'@fluencelabs/js-peer': 0.8.3
'@fluencelabs/js-peer': 0.8.4
'@fluencelabs/marine-js': 0.3.45
'@rollup/plugin-inject': 5.0.3
'@types/jest': 28.1.0
'@types/node': 16.11.59
buffer: 6.0.3
jest: 28.1.0
js-base64: 3.7.2
js-base64: 3.7.5
process: 0.11.10
ts-jest: 28.0.2
vite: 4.0.4
@ -140,7 +140,7 @@ importers:
'@types/jest': 28.1.0
'@types/node': 16.11.59
jest: 28.1.0_@types+node@16.11.59
js-base64: 3.7.2
js-base64: 3.7.5
ts-jest: 28.0.2_byf75w6xilfwy3ncjzlldwxox4
vite: 4.0.4_@types+node@16.11.59
vite-plugin-replace: 0.1.1_vite@4.0.4
@ -192,13 +192,13 @@ importers:
it-map: 2.0.0
it-pipe: 2.0.5
jest: 29.4.1
js-base64: 3.7.2
js-base64: 3.7.5
libp2p: 0.42.2
loglevel: 1.8.1
multiformats: 11.0.1
rxjs: 7.5.5
threads: 1.7.0
ts-jest: 29.0.5
ts-jest: next
ts-pattern: 3.3.3
uint8arrays: 4.0.3
uuid: 8.3.2
@ -223,7 +223,7 @@ importers:
it-length-prefixed: 8.0.4
it-map: 2.0.0
it-pipe: 2.0.5
js-base64: 3.7.2
js-base64: 3.7.5
libp2p: 0.42.2
loglevel: 1.8.1
multiformats: 11.0.1
@ -241,7 +241,7 @@ importers:
'@types/jest': 29.4.0
'@types/uuid': 8.3.2
jest: 29.4.1
ts-jest: 29.0.5_knhdxpg4pvwuf6vrybjt5d2q5i
ts-jest: 29.0.0-next.1_knhdxpg4pvwuf6vrybjt5d2q5i
packages:
@ -10331,12 +10331,8 @@ packages:
- ts-node
dev: true
/js-base64/3.7.2:
resolution: {integrity: sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==}
/js-base64/3.7.5:
resolution: {integrity: sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==}
dev: true
/js-sdsl/4.3.0:
resolution: {integrity: sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==}
@ -14497,8 +14493,8 @@ packages:
yargs-parser: 20.2.9
dev: true
/ts-jest/29.0.5_knhdxpg4pvwuf6vrybjt5d2q5i:
resolution: {integrity: sha512-PL3UciSgIpQ7f6XjVOmbi96vmDHUqAyqDr8YxzopDqX3kfgYtX1cuNeBjP+L9sFXi6nzsGGA6R3fP3DDDJyrxA==}
/ts-jest/29.0.0-next.1_knhdxpg4pvwuf6vrybjt5d2q5i:
resolution: {integrity: sha512-bVo2GDuJiV+cWEYB72tdz2Ips4JDKa04bcKikPULxxUHT4fsoY1zB2zvsrJym18qrFpXyVrIdgJFLfEx2YTkbg==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
hasBin: true
peerDependencies:

View File

@ -8,6 +8,7 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"esModuleInterop": true,
"declaration": true,
"moduleResolution": "nodenext"
}