feat!: Standalone web JS Client (#243)
- Move marine-related part into FJS repo (fixes DXJ-184) - Move towards component-oriented architecture (fixes DXJ-183) - Different JS Client distros for node.js and web (fixes DXJ-185) - Update libp2p to 0.42.2 (fixes DXJ-26) - Add JS Client API (fixes DXJ-196, fixes DXJ-177, fixes DXJ-60) - Add Smoke test for JS Client web (fixes DXJ-253) --------- Co-authored-by: Anatoly Laskaris <github_me@nahsi.dev>
52
.github/workflows/release_github.yml
vendored
@ -1,52 +0,0 @@
|
||||
name: "Make github release"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release-github:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Get the version of fluence-js package"
|
||||
id: package-version
|
||||
uses: martinbeentjes/npm-get-version-action@v1.2.3
|
||||
with:
|
||||
path: packages/fluence-js
|
||||
|
||||
- name: Set env
|
||||
run: echo "RELEASE_VERSION=v${{ steps.package-version.outputs.current-version }}" >> $GITHUB_ENV
|
||||
|
||||
- name: "Create tag for release"
|
||||
uses: rickstaa/action-create-tag@v1
|
||||
with:
|
||||
tag: ${{ env.RELEASE_VERSION }}
|
||||
message: ""
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
### Create a release
|
||||
- name: Build Changelog
|
||||
id: changelog
|
||||
uses: mikepenz/release-changelog-builder-action@v3
|
||||
with:
|
||||
configuration: ".github/workflows/changelog_config.json"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Release
|
||||
id: release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
name: Fluence JS ${{ env.RELEASE_VERSION }}
|
||||
tag_name: ${{ env.RELEASE_VERSION }}
|
||||
body: ${{steps.changelog.outputs.changelog}}
|
||||
draft: false
|
||||
prerelease: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
39
.github/workflows/release_packages.yml
vendored
@ -1,39 +0,0 @@
|
||||
name: "Release packages"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release-packages:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
with:
|
||||
version: 7
|
||||
|
||||
- name: "Setup node"
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "16"
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: "Build packages"
|
||||
run: |
|
||||
pnpm i
|
||||
pnpm -r build
|
||||
|
||||
- name: "Publish to npmjs.com"
|
||||
run: |
|
||||
result=$(pnpm --no-git-checks -r publish -filter '@fluencelabs/*' --access public)
|
||||
if [[ $result == "There are no new packages that should be published" ]]
|
||||
then
|
||||
echo ERROR: no packages have been published. Did you forget to bump version?
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CI: true
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
2
.github/workflows/snapshot.yml
vendored
@ -14,7 +14,7 @@ on:
|
||||
ref:
|
||||
description: "git ref to checkout to"
|
||||
type: string
|
||||
default: "master"
|
||||
default: "v0.28.0"
|
||||
outputs:
|
||||
fluence-js-version:
|
||||
description: "@fluencelabs/fluence version"
|
||||
|
3
.github/workflows/tests.yml
vendored
@ -18,7 +18,7 @@ on:
|
||||
ref:
|
||||
description: "git ref to checkout to"
|
||||
type: string
|
||||
default: "master"
|
||||
default: "v0.28.0"
|
||||
|
||||
env:
|
||||
RUST_PEER_IMAGE: "${{ inputs.rust-peer-image }}"
|
||||
@ -29,7 +29,6 @@ jobs:
|
||||
fluence-js:
|
||||
name: "Run tests"
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
8
.prettierrc.cjs
Normal file
@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
semi: true,
|
||||
trailingComma: 'all',
|
||||
singleQuote: true,
|
||||
printWidth: 120,
|
||||
tabWidth: 4,
|
||||
useTabs: false,
|
||||
};
|
@ -28,15 +28,6 @@ Build all packages
|
||||
pnpm -r build
|
||||
```
|
||||
|
||||
### Repository structure
|
||||
|
||||
| Folder | Package | Description |
|
||||
| --------------------------- | ----------------------- | --------------------------------------------- |
|
||||
| packages/fluence-js | @fluencelabs/fluence-js | TypeScript implementation of the Fluence Peer |
|
||||
| packages/fluence-interfaces | @fluencelabs/interfaces | Common interfaces used in Fluence Peer |
|
||||
| packages/fluence-connection | @fluencelabs/connection | Connectivity layer used in Fluence Peer |
|
||||
| packages/fluence-keypair | @fluencelabs/keypair | Key Pair implementation |
|
||||
|
||||
### Running tests
|
||||
|
||||
Tests are split into unit and integration categories. By default integration tests require a locally running Fluence node with 4310 port open for ws connections. The dependency can be started with docker
|
||||
|
@ -1 +0,0 @@
|
||||
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
|
@ -1,22 +0,0 @@
|
||||
:root {
|
||||
--light-code-background: #F5F5F5;
|
||||
--dark-code-background: #1E1E1E;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) { :root {
|
||||
--code-background: var(--light-code-background);
|
||||
} }
|
||||
|
||||
@media (prefers-color-scheme: dark) { :root {
|
||||
--code-background: var(--dark-code-background);
|
||||
} }
|
||||
|
||||
body.light {
|
||||
--code-background: var(--light-code-background);
|
||||
}
|
||||
|
||||
body.dark {
|
||||
--code-background: var(--dark-code-background);
|
||||
}
|
||||
|
||||
pre, code { background: var(--code-background); }
|
Before Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 855 B |
@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@fluencelabs/fluence</title><meta name="description" content="Documentation for @fluencelabs/fluence"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script async src="assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">@fluencelabs/fluence</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><h1>@fluencelabs/fluence </h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><div class="tsd-panel tsd-typography">
|
||||
<a href="#fluence-js" id="fluence-js" style="color: inherit; text-decoration: none;">
|
||||
<h1>Fluence JS</h1>
|
||||
</a>
|
||||
<p>To start developing applications with Fluence JS refer to the official <a href="https://fluence.dev/docs/build/fluence-js/">documentation</a></p>
|
||||
<p>Fluence JS is an implementation of the Fluence protocol for JavaScript-based environments. It can connect browsers, Node.js applications, and so on to the Fluence p2p network.</p>
|
||||
<p>Similar to the <a href="https://github.com/fluencelabs/fluence">Rust Fluence Peer implementation</a> it includes:</p>
|
||||
<ul>
|
||||
<li>Peer-to-peer communication layer (via <a href="https://github.com/libp2p/js-libp2p">js-libp2p</a>)</li>
|
||||
<li><a href="https://github.com/fluencelabs/aquavm">Aqua VM</a></li>
|
||||
<li>Builtin services</li>
|
||||
</ul>
|
||||
<p>Fluence JS can call services and functions on the Fluence network, and expose new APIs to the p2p network directly from TypeScript and JavaScript.
|
||||
<a href="https://github.com/fluencelabs/aqua">Aqua language</a> uses Fluence JS as a compilation target, and they are designed to <a href="https://fluence.dev/docs/build/fluence-js/in-depth#understanding-the-aqua-compiler-output">work in tandem</a>.</p>
|
||||
<p>Fluence JS can be used with any framework of your choice (or even without frameworks).</p>
|
||||
</div></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class="current"><a href="modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="tsd-kind-class"><a href="classes/FluencePeer.html" class="tsd-kind-icon">Fluence<wbr/>Peer</a></li><li class="tsd-kind-class"><a href="classes/KeyPair.html" class="tsd-kind-icon">Key<wbr/>Pair</a></li><li class="tsd-kind-interface tsd-has-type-parameter"><a href="interfaces/CallParams.html" class="tsd-kind-icon">Call<wbr/>Params</a></li><li class="tsd-kind-interface"><a href="interfaces/PeerConfig.html" class="tsd-kind-icon">Peer<wbr/>Config</a></li><li class="tsd-kind-type-alias"><a href="modules.html#AvmLoglevel" class="tsd-kind-icon">Avm<wbr/>Loglevel</a></li><li class="tsd-kind-type-alias"><a href="modules.html#PeerIdB58" class="tsd-kind-icon">Peer<wbr/>Id<wbr/>B58</a></li><li class="tsd-kind-type-alias"><a href="modules.html#PeerStatus" class="tsd-kind-icon">Peer<wbr/>Status</a></li><li class="tsd-kind-variable"><a href="modules.html#Fluence" class="tsd-kind-icon">Fluence</a></li><li class="tsd-kind-function tsd-is-external"><a href="modules.html#loadWasmFromFileSystem" class="tsd-kind-icon">load<wbr/>Wasm<wbr/>From<wbr/>File<wbr/>System</a></li><li class="tsd-kind-function tsd-is-external"><a href="modules.html#loadWasmFromNpmPackage" class="tsd-kind-icon">load<wbr/>Wasm<wbr/>From<wbr/>Npm<wbr/>Package</a></li><li class="tsd-kind-function tsd-is-external"><a href="modules.html#loadWasmFromServer" class="tsd-kind-icon">load<wbr/>Wasm<wbr/>From<wbr/>Server</a></li><li class="tsd-kind-function"><a href="modules.html#setLogLevel" class="tsd-kind-icon">set<wbr/>Log<wbr/>Level</a></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/main.js"></script></body></html>
|
@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>CallParams | @fluencelabs/fluence</title><meta name="description" content="Documentation for @fluencelabs/fluence"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@fluencelabs/fluence</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@fluencelabs/fluence</a></li><li><a href="CallParams.html">CallParams</a></li></ul><h1>Interface CallParams<ArgName> </h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Additional information about a service call</p>
|
||||
</div></div></section><section class="tsd-panel tsd-type-parameters"><h3>Type parameters</h3><ul class="tsd-type-parameters"><li><h4>ArgName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span></h4><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
</div></div></li></ul></section><section class="tsd-panel tsd-hierarchy"><h3>Hierarchy</h3><ul class="tsd-hierarchy"><li><span class="target">CallParams</span></li></ul></section><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section "><h3>Properties</h3><ul class="tsd-index-list"><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#initPeerId" class="tsd-kind-icon">init<wbr/>Peer<wbr/>Id</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#particleId" class="tsd-kind-icon">particle<wbr/>Id</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#signature" class="tsd-kind-icon">signature</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#tetraplets" class="tsd-kind-icon">tetraplets</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#timestamp" class="tsd-kind-icon">timestamp</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#ttl" class="tsd-kind-icon">ttl</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group "><h2>Properties</h2><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="initPeerId" class="tsd-anchor"></a><h3 class="tsd-anchor-link">init<wbr/>Peer<wbr/>Id<a href="#initPeerId" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">init<wbr/>Peer<wbr/>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/commonTypes.ts#L37">src/internal/commonTypes.ts:37</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>The peer id which created the particle</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="particleId" class="tsd-anchor"></a><h3 class="tsd-anchor-link">particle<wbr/>Id<a href="#particleId" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">particle<wbr/>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/commonTypes.ts#L32">src/internal/commonTypes.ts:32</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>The identifier of particle which triggered the call</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="signature" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> signature<a href="#signature" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">signature<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/commonTypes.ts#L52">src/internal/commonTypes.ts:52</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Particle's signature</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="tetraplets" class="tsd-anchor"></a><h3 class="tsd-anchor-link">tetraplets<a href="#tetraplets" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">tetraplets<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type" data-tsd-kind="Type parameter">ArgName</span><span class="tsd-signature-symbol"> extends </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> ? </span><span class="tsd-signature-type">Record</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">ArgName</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">SecurityTetraplet</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol"> : </span><span class="tsd-signature-type">Record</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">never</span><span class="tsd-signature-symbol">></span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/commonTypes.ts#L57">src/internal/commonTypes.ts:57</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Security tetraplets</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="timestamp" class="tsd-anchor"></a><h3 class="tsd-anchor-link">timestamp<a href="#timestamp" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">timestamp<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/commonTypes.ts#L42">src/internal/commonTypes.ts:42</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Particle's timestamp when it was created</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="ttl" class="tsd-anchor"></a><h3 class="tsd-anchor-link">ttl<a href="#ttl" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">ttl<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/commonTypes.ts#L47">src/internal/commonTypes.ts:47</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Time to live in milliseconds. The time after the particle should be expired</p>
|
||||
</div></div></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class=""><a href="../modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="current tsd-kind-interface tsd-has-type-parameter"><a href="CallParams.html" class="tsd-kind-icon">Call<wbr/>Params</a><ul><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#initPeerId" class="tsd-kind-icon">init<wbr/>Peer<wbr/>Id</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#particleId" class="tsd-kind-icon">particle<wbr/>Id</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#signature" class="tsd-kind-icon">signature</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#tetraplets" class="tsd-kind-icon">tetraplets</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#timestamp" class="tsd-kind-icon">timestamp</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="CallParams.html#ttl" class="tsd-kind-icon">ttl</a></li></ul></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="../assets/main.js"></script></body></html>
|
@ -1,52 +0,0 @@
|
||||
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>PeerConfig | @fluencelabs/fluence</title><meta name="description" content="Documentation for @fluencelabs/fluence"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@fluencelabs/fluence</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@fluencelabs/fluence</a></li><li><a href="PeerConfig.html">PeerConfig</a></li></ul><h1>Interface PeerConfig </h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Configuration used when initiating Fluence Peer</p>
|
||||
</div></div></section><section class="tsd-panel tsd-hierarchy"><h3>Hierarchy</h3><ul class="tsd-hierarchy"><li><span class="target">PeerConfig</span></li></ul></section><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section "><h3>Properties</h3><ul class="tsd-index-list"><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#KeyPair" class="tsd-kind-icon">Key<wbr/>Pair</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#avmLogLevel" class="tsd-kind-icon">avm<wbr/>Log<wbr/>Level</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#avmRunner" class="tsd-kind-icon">avm<wbr/>Runner</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#checkConnectionTimeoutMs" class="tsd-kind-icon">check<wbr/>Connection<wbr/>Timeout<wbr/>Ms</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#connectTo" class="tsd-kind-icon">connect<wbr/>To</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#debug" class="tsd-kind-icon">debug</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#defaultTtlMs" class="tsd-kind-icon">default<wbr/>Ttl<wbr/>Ms</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#dialTimeoutMs" class="tsd-kind-icon">dial<wbr/>Timeout<wbr/>Ms</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#marineJS" class="tsd-kind-icon">marineJS</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#skipCheckConnection" class="tsd-kind-icon">skip<wbr/>Check<wbr/>Connection</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group "><h2>Properties</h2><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="KeyPair" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> Key<wbr/>Pair<a href="#KeyPair" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">Key<wbr/>Pair<span class="tsd-signature-symbol">?:</span> <a href="../classes/KeyPair.html" class="tsd-signature-type" data-tsd-kind="Class">KeyPair</a></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L72">src/internal/FluencePeer.ts:72</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Specify the KeyPair to be used to identify the Fluence Peer.
|
||||
Will be generated randomly if not specified</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="avmLogLevel" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> avm<wbr/>Log<wbr/>Level<a href="#avmLogLevel" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">avm<wbr/>Log<wbr/>Level<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">LogLevel</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L66">src/internal/FluencePeer.ts:66</a></li></ul></aside><div class="tsd-comment tsd-typography"><dl class="tsd-comment-tags"><dt>deprecated.</dt><dd><p>AVM run through marine-js infrastructure.</p>
|
||||
</dd><dt>see</dt><dd><p>debug.marineLogLevel option to configure logging level of AVM</p>
|
||||
</dd></dl></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="avmRunner" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> avm<wbr/>Runner<a href="#avmRunner" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">avm<wbr/>Runner<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">AvmRunner</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L104">src/internal/FluencePeer.ts:104</a></li></ul></aside><div class="tsd-comment tsd-typography"><dl class="tsd-comment-tags"><dt>deprecated.</dt><dd><p>AVM run through marine-js infrastructure.</p>
|
||||
</dd><dt>see</dt><dd><p>marineJS option to configure AVM</p>
|
||||
</dd></dl></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="checkConnectionTimeoutMs" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> check<wbr/>Connection<wbr/>Timeout<wbr/>Ms<a href="#checkConnectionTimeoutMs" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">check<wbr/>Connection<wbr/>Timeout<wbr/>Ms<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L79">src/internal/FluencePeer.ts:79</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>When the peer established the connection to the network it sends a ping-like message to check if it works correctly.
|
||||
The options allows to specify the timeout for that message in milliseconds.
|
||||
If not specified the default timeout will be used</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="connectTo" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> connect<wbr/>To<a href="#connectTo" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">connect<wbr/>To<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">ConnectionOption</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L60">src/internal/FluencePeer.ts:60</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Node in Fluence network to connect to.
|
||||
Can be in the form of:</p>
|
||||
<ul>
|
||||
<li>string: multiaddr in string format</li>
|
||||
<li>Multiaddr: multiaddr object, @see <a href="https://github.com/multiformats/js-multiaddr">https://github.com/multiformats/js-multiaddr</a></li>
|
||||
<li>Node: node structure, @see Node</li>
|
||||
<li>Implementation of FluenceConnection class, @see FluenceConnection
|
||||
If not specified the will work locally and would not be able to send or receive particles.</li>
|
||||
</ul>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="debug" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> debug<a href="#debug" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">debug<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-symbol">{ </span>marineLogLevel<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">LogLevel</span><span class="tsd-signature-symbol">; </span>printParticleId<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> }</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L132">src/internal/FluencePeer.ts:132</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Enables\disabled various debugging features</p>
|
||||
</div></div><div class="tsd-type-declaration"><h4>Type declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter"><h5><span class="tsd-flag ts-flagOptional">Optional</span> marine<wbr/>Log<wbr/>Level<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">LogLevel</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Log level for marine services. By default logging is turned off.</p>
|
||||
</div></div></li><li class="tsd-parameter"><h5><span class="tsd-flag ts-flagOptional">Optional</span> print<wbr/>Particle<wbr/>Id<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>If set to true, newly initiated particle ids will be printed to console.
|
||||
Useful to see what particle id is responsible for aqua function</p>
|
||||
</div></div></li></ul></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="defaultTtlMs" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> default<wbr/>Ttl<wbr/>Ms<a href="#defaultTtlMs" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">default<wbr/>Ttl<wbr/>Ms<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L98">src/internal/FluencePeer.ts:98</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Sets the default TTL for all particles originating from the peer with no TTL specified.
|
||||
If the originating particle's TTL is defined then that value will be used
|
||||
If the option is not set default TTL will be 7000</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="dialTimeoutMs" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> dial<wbr/>Timeout<wbr/>Ms<a href="#dialTimeoutMs" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">dial<wbr/>Timeout<wbr/>Ms<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L91">src/internal/FluencePeer.ts:91</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>The dialing timeout in milliseconds</p>
|
||||
</div></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="marineJS" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> marineJS<a href="#marineJS" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">marineJS<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-symbol">{ </span>avmWasmPath<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>marineWasmPath<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>workerScriptPath<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L112">src/internal/FluencePeer.ts:112</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>This option allows to specify the location of various dependencies needed for marine-js.
|
||||
Each key specifies the location of the corresponding dependency.
|
||||
If Fluence peer is started inside browser the location is treated as the path to the file relative to origin.
|
||||
IF Fluence peer is started in nodejs the location is treated as the full path to file on the file system.</p>
|
||||
</div></div><div class="tsd-type-declaration"><h4>Type declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter"><h5>avm<wbr/>Wasm<wbr/>Path<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Configures the path to AVM wasm module</p>
|
||||
</div></div></li><li class="tsd-parameter"><h5>marine<wbr/>Wasm<wbr/>Path<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Configures the path to marine-js control wasm module</p>
|
||||
</div></div></li><li class="tsd-parameter"><h5>worker<wbr/>Script<wbr/>Path<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>Configures path to the marine-js worker script.</p>
|
||||
</div></div></li></ul></div></section><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface"><a id="skipCheckConnection" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span class="tsd-flag ts-flagOptional">Optional</span> skip<wbr/>Check<wbr/>Connection<a href="#skipCheckConnection" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">skip<wbr/>Check<wbr/>Connection<span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/fluencelabs/fluence-js/blob/fea91db/src/internal/FluencePeer.ts#L86">src/internal/FluencePeer.ts:86</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
|
||||
<p>When the peer established the connection to the network it sends a ping-like message to check if it works correctly.
|
||||
If set to true, the ping-like message will be skipped
|
||||
Default: false</p>
|
||||
</div></div></section></section></div><div class="col-4 col-menu menu-sticky-wrap menu-highlight"><nav class="tsd-navigation primary"><ul><li class=""><a href="../modules.html">Exports</a></li></ul></nav><nav class="tsd-navigation secondary menu-sticky"><ul><li class="current tsd-kind-interface"><a href="PeerConfig.html" class="tsd-kind-icon">Peer<wbr/>Config</a><ul><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#KeyPair" class="tsd-kind-icon">Key<wbr/>Pair</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#avmLogLevel" class="tsd-kind-icon">avm<wbr/>Log<wbr/>Level</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#avmRunner" class="tsd-kind-icon">avm<wbr/>Runner</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#checkConnectionTimeoutMs" class="tsd-kind-icon">check<wbr/>Connection<wbr/>Timeout<wbr/>Ms</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#connectTo" class="tsd-kind-icon">connect<wbr/>To</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#debug" class="tsd-kind-icon">debug</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#defaultTtlMs" class="tsd-kind-icon">default<wbr/>Ttl<wbr/>Ms</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#dialTimeoutMs" class="tsd-kind-icon">dial<wbr/>Timeout<wbr/>Ms</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#marineJS" class="tsd-kind-icon">marineJS</a></li><li class="tsd-kind-property tsd-parent-kind-interface"><a href="PeerConfig.html#skipCheckConnection" class="tsd-kind-icon">skip<wbr/>Check<wbr/>Connection</a></li></ul></li></ul></nav></div></div></div><footer class="with-border-bottom"><div class="container"><h2>Legend</h2><div class="tsd-legend-group"><ul class="tsd-legend"><li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li><li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li><li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li></ul><ul class="tsd-legend"><li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li></ul></div><h2>Settings</h2><p>Theme <select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></p></div></footer><div class="container tsd-generator"><p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="../assets/main.js"></script></body></html>
|
25
package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "common-dev-deps",
|
||||
"version": "0.1.0",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"scripts": {
|
||||
"simulate-cdn": "http-server -p 8765 ./packages/client/js-client.web.standalone/dist"
|
||||
},
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"http-server": "14.1.1",
|
||||
"@types/node": "16.11.59",
|
||||
"ts-node": "10.9.1",
|
||||
"typescript": "4.7",
|
||||
"@fluencelabs/aqua-lib": "0.6.0",
|
||||
"@fluencelabs/aqua": "0.9.1-374"
|
||||
}
|
||||
}
|
5
packages/@tests/aqua/_aqua/smoke_test.aqua
Normal file
@ -0,0 +1,5 @@
|
||||
import "@fluencelabs/registry/resources-api.aqua"
|
||||
|
||||
func smokeTest(label: string) -> ?string, *string:
|
||||
res, errors <- createResource(label)
|
||||
<- res, errors
|
28
packages/@tests/aqua/package.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@test/aqua_for_test",
|
||||
"version": "0.1.0",
|
||||
"description": "Shared aqua code for tests",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"compile-aqua": "aqua -i ./_aqua -o ./src/_aqua"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/fluence": "workspace:0.60.0",
|
||||
"@fluencelabs/fluence-network-environment": "1.0.13",
|
||||
"base64-js": "1.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/aqua": "0.9.4",
|
||||
"@fluencelabs/registry": "0.7.0"
|
||||
}
|
||||
}
|
284
packages/@tests/aqua/src/_aqua/smoke_test.ts
Normal file
@ -0,0 +1,284 @@
|
||||
/**
|
||||
*
|
||||
* 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.9.4
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
import type { CallParams$$ } from '@fluencelabs/fluence/dist/internal/compilerSupport/v4';
|
||||
import { callFunction$$, registerService$$ } from '@fluencelabs/fluence/dist/internal/compilerSupport/v4';
|
||||
|
||||
// Services
|
||||
|
||||
// Functions
|
||||
|
||||
export type SmokeTestResult = [string | null, string[]];
|
||||
export function smokeTest(label: string, config?: { ttl?: number }): Promise<SmokeTestResult>;
|
||||
|
||||
export function smokeTest(peer: FluencePeer, label: string, config?: { ttl?: number }): Promise<SmokeTestResult>;
|
||||
|
||||
export function smokeTest(...args: any) {
|
||||
let script = `
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "label") [] label)
|
||||
)
|
||||
(new $resource_id
|
||||
(new $successful
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("peer" "timestamp_sec") [] t)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("registry" "get_key_bytes") [label [] t [] ""] bytes)
|
||||
(xor
|
||||
(call %init_peer_id% ("sig" "sign") [bytes] result)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match result.$.success! false
|
||||
(ap result.$.error.[0]! $error)
|
||||
)
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(ap result.$.signature! result_flat)
|
||||
(call -relay- ("registry" "get_key_id") [label %init_peer_id%] id)
|
||||
)
|
||||
(call -relay- ("op" "string_to_b58") [id] k)
|
||||
)
|
||||
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
|
||||
)
|
||||
(par
|
||||
(fold nodes n-0
|
||||
(par
|
||||
(seq
|
||||
(xor
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call n-0 ("peer" "timestamp_sec") [] t-0)
|
||||
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% t-0] weight)
|
||||
)
|
||||
(call n-0 ("registry" "register_key") [label [] t [] "" result_flat.$.[0]! weight t-0] result-0)
|
||||
)
|
||||
(xor
|
||||
(match result-0.$.success! true
|
||||
(ap true $successful)
|
||||
)
|
||||
(ap result-0.$.error! $error)
|
||||
)
|
||||
)
|
||||
(call n-0 ("op" "noop") [])
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next n-0)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
(new $status
|
||||
(new $result-1
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "sub") [1 1] sub)
|
||||
(new $successful_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [sub 1] successful_incr)
|
||||
(fold $successful s
|
||||
(seq
|
||||
(seq
|
||||
(ap s $successful_test)
|
||||
(canon -relay- $successful_test #successful_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #successful_iter_canon.length successful_incr
|
||||
(null)
|
||||
)
|
||||
(next s)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $successful_test #successful_result_canon)
|
||||
)
|
||||
(ap #successful_result_canon successful_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("math" "sub") [1 1] sub-0)
|
||||
)
|
||||
(ap "ok" $status)
|
||||
)
|
||||
(call -relay- ("peer" "timeout") [6000 "timeout"] $status)
|
||||
)
|
||||
(new $status_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [0 1] status_incr)
|
||||
(fold $status s
|
||||
(seq
|
||||
(seq
|
||||
(ap s $status_test)
|
||||
(canon -relay- $status_test #status_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #status_iter_canon.length status_incr
|
||||
(null)
|
||||
)
|
||||
(next s)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $status_test #status_result_canon)
|
||||
)
|
||||
(ap #status_result_canon status_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match status_gate.$.[0]! "ok"
|
||||
(ap true $result-1)
|
||||
)
|
||||
(ap false $result-1)
|
||||
)
|
||||
)
|
||||
(new $result-1_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [0 1] result-1_incr)
|
||||
(fold $result-1 s
|
||||
(seq
|
||||
(seq
|
||||
(ap s $result-1_test)
|
||||
(canon -relay- $result-1_test #result-1_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #result-1_iter_canon.length result-1_incr
|
||||
(null)
|
||||
)
|
||||
(next s)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $result-1_test #result-1_result_canon)
|
||||
)
|
||||
(ap #result-1_result_canon result-1_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match result-1_gate.$.[0]! false
|
||||
(ap "resource wasn't created: timeout exceeded" $error)
|
||||
)
|
||||
(ap id $resource_id)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(canon %init_peer_id% $resource_id #-resource_id-fix-0)
|
||||
)
|
||||
(ap #-resource_id-fix-0 -resource_id-flat-0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(canon %init_peer_id% $error #error_canon)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||
)
|
||||
`;
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
functionName: 'smokeTest',
|
||||
arrow: {
|
||||
tag: 'arrow',
|
||||
domain: {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
label: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
codomain: {
|
||||
tag: 'unlabeledProduct',
|
||||
items: [
|
||||
{
|
||||
tag: 'option',
|
||||
type: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
tag: 'array',
|
||||
type: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: '-relay-',
|
||||
getDataSrv: 'getDataSrv',
|
||||
callbackSrv: 'callbackSrv',
|
||||
responseSrv: 'callbackSrv',
|
||||
responseFnName: 'response',
|
||||
errorHandlingSrv: 'errorHandlingSrv',
|
||||
errorFnName: 'error',
|
||||
},
|
||||
},
|
||||
script,
|
||||
);
|
||||
}
|
55
packages/@tests/aqua/src/index.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { fromByteArray } from 'base64-js';
|
||||
import { Fluence } from '@fluencelabs/fluence';
|
||||
import { krasnodar } from '@fluencelabs/fluence-network-environment';
|
||||
import { smokeTest } from './_aqua/smoke_test.js';
|
||||
|
||||
// const relay = {
|
||||
// multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
// peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
// };
|
||||
|
||||
const relay = krasnodar[4];
|
||||
|
||||
const rndSk = () => {
|
||||
if (crypto.getRandomValues) {
|
||||
return crypto.getRandomValues(new Uint8Array(32));
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
return globalThis.crypto.webcrypto.getRandomValues(new Uint8Array(32));
|
||||
};
|
||||
|
||||
export const main = async () => {
|
||||
console.log('starting fluence...');
|
||||
await Fluence.start({
|
||||
relay: relay,
|
||||
keyPair: {
|
||||
type: 'Ed25519',
|
||||
source: rndSk(),
|
||||
},
|
||||
});
|
||||
|
||||
console.log('started fluence');
|
||||
const p = await Fluence.getPeer();
|
||||
|
||||
console.log('my peer id: ', p.getStatus().peerId);
|
||||
console.log('my sk id: ', fromByteArray(p.getSk()));
|
||||
|
||||
console.log('running some aqua...');
|
||||
const [res, errors] = await smokeTest('my_resource');
|
||||
if (res === null) {
|
||||
console.log('aqua failed, errors', errors);
|
||||
} else {
|
||||
console.log('aqua finished, result', res);
|
||||
}
|
||||
|
||||
console.log('stopping fluence...');
|
||||
await Fluence.stop();
|
||||
console.log('stopped fluence...');
|
||||
};
|
||||
|
||||
export const runMain = () => {
|
||||
main()
|
||||
.then(() => console.log('done!'))
|
||||
.catch((err) => console.error('error: ', err));
|
||||
};
|
7
packages/@tests/aqua/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
@ -21,3 +21,5 @@
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
public/js-client.min.js
|
@ -1,27 +1,28 @@
|
||||
{
|
||||
"name": "@test/react",
|
||||
"name": "cra-ts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@fluencelabs/fluence": "workspace:*",
|
||||
"@fluencelabs/fluence-network-environment": "^1.0.13",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^16.11.56",
|
||||
"@types/react": "^18.0.18",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"@fluencelabs/fluence": "workspace:0.60.0",
|
||||
"@test/aqua_for_test": "workspace:*",
|
||||
"@testing-library/jest-dom": "5.16.5",
|
||||
"@testing-library/react": "13.4.0",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/jest": "27.5.2",
|
||||
"@types/node": "16.18.12",
|
||||
"@types/react": "18.0.27",
|
||||
"@types/react-dom": "18.0.10",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "^4.8.2",
|
||||
"web-vitals": "^2.1.4"
|
||||
"typescript": "4.9.5",
|
||||
"web-vitals": "2.1.4"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"_test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@ -1,14 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<meta name="description" content="Web site created using create-react-app" />
|
||||
<script src='http://localhost:8765/js-client.min.js' async></script>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
@ -25,8 +24,9 @@
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
@ -39,5 +39,6 @@
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</body>
|
||||
|
||||
</html>
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
9
packages/@tests/frameworks/cra-ts/src/App.test.tsx_
Normal file
@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
26
packages/@tests/frameworks/cra-ts/src/App.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
@ -3,17 +3,18 @@ import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
import { runMain } from '@test/aqua_for_test';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
|
||||
runMain();
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
19
packages/@tests/marine/node/.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
bundle/
|
||||
/dist/
|
||||
/worker/dist/
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
@ -1,6 +1,5 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
testTimeout: 10000,
|
||||
testPathIgnorePatterns: ['dist'],
|
||||
};
|
19
packages/@tests/marine/node/package.json.skip
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@test/marine_node",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "16.11.59",
|
||||
"typescript": "^4.0.0",
|
||||
"@types/jest": "28.1.0",
|
||||
"jest": "28.1.0",
|
||||
"ts-jest": "28.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/avm": "0.32.1",
|
||||
"@fluencelabs/marine.background-runner": "0.1.0",
|
||||
"@fluencelabs/marine.deps-loader.node": "0.1.0"
|
||||
}
|
||||
}
|
54
packages/@tests/marine/node/src/test.spec.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/marine.background-runner';
|
||||
import { InlinedWorkerLoader, WasmNpmLoader } from '@fluencelabs/marine.deps-loader.node';
|
||||
import { callAvm, JSONArray, JSONObject } from '@fluencelabs/avm';
|
||||
|
||||
const vmPeerId = '12D3KooWNzutuy8WHXDKFqFsATvCR6j9cj2FijYbnd47geRKaQZS';
|
||||
|
||||
describe('Nodejs integration tests', () => {
|
||||
it('Smoke test', async () => {
|
||||
let runner: MarineBackgroundRunner | undefined = undefined;
|
||||
try {
|
||||
// arrange
|
||||
const avm = new WasmNpmLoader('@fluencelabs/avm', 'avm.wasm');
|
||||
const control = new WasmNpmLoader('@fluencelabs/marine-js', 'marine-js.wasm');
|
||||
const worker = new InlinedWorkerLoader();
|
||||
runner = new MarineBackgroundRunner(worker, control, () => {});
|
||||
|
||||
await avm.start();
|
||||
|
||||
await runner.start();
|
||||
await runner.createService(avm.getValue(), 'avm');
|
||||
|
||||
const s = `(seq
|
||||
(par
|
||||
(call "${vmPeerId}" ("local_service_id" "local_fn_name") [] result_1)
|
||||
(call "remote_peer_id" ("service_id" "fn_name") [] g)
|
||||
)
|
||||
(call "${vmPeerId}" ("local_service_id" "local_fn_name") [] result_2)
|
||||
)`;
|
||||
|
||||
// act
|
||||
const res = await callAvm(
|
||||
(args: JSONArray | JSONObject) => runner!.callService('avm', 'invoke', args, undefined),
|
||||
{
|
||||
currentPeerId: vmPeerId,
|
||||
initPeerId: vmPeerId,
|
||||
timestamp: Date.now(),
|
||||
ttl: 10000,
|
||||
},
|
||||
s,
|
||||
Buffer.from(''),
|
||||
Buffer.from(''),
|
||||
[],
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(res).toMatchObject({
|
||||
retCode: 0,
|
||||
errorMessage: '',
|
||||
});
|
||||
} finally {
|
||||
runner?.stop();
|
||||
}
|
||||
});
|
||||
});
|
7
packages/@tests/marine/node/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
22
packages/@tests/marine/web/.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
build/
|
||||
public/*.*
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
bundle/
|
||||
/dist/
|
||||
/worker/dist/
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
12
packages/@tests/marine/web/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Webpack App</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello world!</h1>
|
||||
<h2>Tip: Check your console</h2>
|
||||
</body>
|
||||
|
||||
</html>
|
9
packages/@tests/marine/web/jest.config.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
preset: 'jest-puppeteer',
|
||||
testMatch: ['**/?(*.)+(spec|test).[t]s'],
|
||||
testPathIgnorePatterns: ['/node_modules/', 'dist'],
|
||||
testMatch: ['**/test/*.spec.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts?$': 'ts-jest',
|
||||
},
|
||||
};
|
37
packages/@tests/marine/web/package.json.skip
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@test/marine_web",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"start": "webpack serve",
|
||||
"test": "jest",
|
||||
"build": "webpack --mode=production --node-env=production",
|
||||
"build:dev": "webpack --mode=development",
|
||||
"build:prod": "webpack --mode=production --node-env=production",
|
||||
"watch": "webpack --watch",
|
||||
"serve": "webpack serve"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@webpack-cli/generators": "^2.4.1",
|
||||
"css-loader": "^6.5.1",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"install-local": "^3.0.1",
|
||||
"style-loader": "^3.3.1",
|
||||
"ts-loader": "^8.3.0",
|
||||
"typescript": "^4.5.4",
|
||||
"util": "^0.12.4",
|
||||
"webpack": "^5.65.0",
|
||||
"webpack-cli": "^4.9.1",
|
||||
"webpack-dev-server": "^4.6.0",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/jest-environment-puppeteer": "^4.4.1",
|
||||
"@types/puppeteer": "^5.4.4",
|
||||
"jest": "28.1.0",
|
||||
"jest-puppeteer": "^6.0.2",
|
||||
"ts-jest": "28.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/avm": "0.34.4",
|
||||
"js-base64": "^3.7.2",
|
||||
"buffer": "6.0.3"
|
||||
}
|
||||
}
|
56
packages/@tests/marine/web/src/index.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
// @ts-ignore
|
||||
window.Buffer = Buffer;
|
||||
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/marine.background-runner';
|
||||
import { InlinedWorkerLoader, WasmWebLoader } from '@fluencelabs/marine.deps-loader.web';
|
||||
import { callAvm, JSONArray, JSONObject } from '@fluencelabs/avm';
|
||||
import { toUint8Array } from 'js-base64';
|
||||
|
||||
const vmPeerId = '12D3KooWNzutuy8WHXDKFqFsATvCR6j9cj2FijYbnd47geRKaQZS';
|
||||
|
||||
const b = (s: string) => {
|
||||
return toUint8Array(s);
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
const avm = new WasmWebLoader('avm.wasm');
|
||||
const control = new WasmWebLoader('marine-js.wasm');
|
||||
const worker = new InlinedWorkerLoader();
|
||||
const runner = new MarineBackgroundRunner(worker, control, () => {});
|
||||
|
||||
await runner.start();
|
||||
await avm.start();
|
||||
const avmVal = await avm.getValue();
|
||||
await runner.createService(avmVal, 'avm');
|
||||
|
||||
const s = `(seq
|
||||
(par
|
||||
(call "${vmPeerId}" ("local_service_id" "local_fn_name") [] result_1)
|
||||
(call "remote_peer_id" ("service_id" "fn_name") [] g)
|
||||
)
|
||||
(call "${vmPeerId}" ("local_service_id" "local_fn_name") [] result_2)
|
||||
)`;
|
||||
|
||||
// act
|
||||
const res = await callAvm(
|
||||
(args: JSONArray | JSONObject) => runner.callService('avm', 'invoke', args, undefined),
|
||||
{
|
||||
currentPeerId: vmPeerId,
|
||||
initPeerId: vmPeerId,
|
||||
timestamp: Date.now(),
|
||||
ttl: 10000,
|
||||
},
|
||||
s,
|
||||
b(''),
|
||||
b(''),
|
||||
[],
|
||||
);
|
||||
await runner.stop();
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
window.MAIN = main;
|
115
packages/@tests/marine/web/test/test.spec.ts
Normal file
@ -0,0 +1,115 @@
|
||||
import Webpack from 'webpack';
|
||||
import WebpackDevServer from 'webpack-dev-server';
|
||||
import webpackConfig from '../webpack.config.js';
|
||||
import process from 'process';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
// change directory to the location to the test-project.
|
||||
// run all the subsequent Webpack scripts in that directory
|
||||
process.chdir(path.join(__dirname, '..'));
|
||||
|
||||
let server;
|
||||
const port = 8080;
|
||||
|
||||
jest.setTimeout(10000);
|
||||
|
||||
const startServer = async (modifyConfig?) => {
|
||||
const loadInBrowserToDebug = false;
|
||||
// const loadInBrowserToDebug = true; // use this line to debug
|
||||
|
||||
modifyConfig = modifyConfig || ((_) => {});
|
||||
|
||||
const config: any = webpackConfig();
|
||||
modifyConfig(config);
|
||||
config.devServer.open = loadInBrowserToDebug;
|
||||
server = await makeServer(config);
|
||||
};
|
||||
|
||||
// https://stackoverflow.com/questions/42940550/wait-until-webpack-dev-server-is-ready
|
||||
function makeServer(config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const compiler = Webpack(config);
|
||||
|
||||
let compiled = false;
|
||||
let listening = false;
|
||||
|
||||
compiler.hooks.done.tap('tap_name', () => {
|
||||
// console.log('compiled');
|
||||
|
||||
if (listening) resolve(server);
|
||||
else compiled = true;
|
||||
});
|
||||
|
||||
const server = new WebpackDevServer(compiler, config.devServer);
|
||||
|
||||
server.listen(port, '0.0.0.0', (err) => {
|
||||
if (err) return reject(err);
|
||||
|
||||
// console.log('listening');
|
||||
|
||||
if (compiled) {
|
||||
resolve(server);
|
||||
} else {
|
||||
listening = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const stopServer = async () => {
|
||||
console.log('test: stopping server');
|
||||
await server.stop();
|
||||
};
|
||||
|
||||
const publicDir = 'public';
|
||||
|
||||
const copyFile = async (packageName: string, fileName: string) => {
|
||||
const modulePath = require.resolve(packageName);
|
||||
const source = path.join(path.dirname(modulePath), fileName);
|
||||
const dest = path.join(publicDir, fileName);
|
||||
|
||||
return fs.promises.copyFile(source, dest);
|
||||
};
|
||||
|
||||
const copyPublicDeps = async () => {
|
||||
await fs.promises.mkdir(publicDir, { recursive: true });
|
||||
return Promise.all([
|
||||
copyFile('@fluencelabs/marine-js', 'marine-js.wasm'),
|
||||
copyFile('@fluencelabs/avm', 'avm.wasm'),
|
||||
]);
|
||||
};
|
||||
|
||||
const cleanPublicDeps = () => {
|
||||
return fs.promises.rm(publicDir, { recursive: true, force: true });
|
||||
};
|
||||
|
||||
describe('Browser integration tests', () => {
|
||||
beforeEach(async () => {
|
||||
await copyPublicDeps();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await stopServer();
|
||||
await cleanPublicDeps();
|
||||
});
|
||||
|
||||
it('Some test', async () => {
|
||||
console.log('test: starting server...');
|
||||
await startServer();
|
||||
console.log('test: navigating to page...');
|
||||
await page.goto('http://localhost:8080/');
|
||||
|
||||
console.log('test: running script in browser...');
|
||||
const res = await page.evaluate(() => {
|
||||
// @ts-ignore
|
||||
return window.MAIN();
|
||||
});
|
||||
|
||||
console.log('test: checking expectations...');
|
||||
await expect(res).toMatchObject({
|
||||
retCode: 0,
|
||||
errorMessage: '',
|
||||
});
|
||||
});
|
||||
});
|
7
packages/@tests/marine/web/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
65
packages/@tests/marine/web/webpack.config.js
Normal file
@ -0,0 +1,65 @@
|
||||
// Generated using webpack-cli https://github.com/webpack/webpack-cli
|
||||
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
const isProduction = process.env.NODE_ENV == 'production';
|
||||
|
||||
const stylesHandler = 'style-loader';
|
||||
|
||||
const config = {
|
||||
entry: './src/index.ts',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
},
|
||||
devServer: {
|
||||
open: true,
|
||||
host: 'localhost',
|
||||
static: {
|
||||
directory: path.join(__dirname, 'public'),
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'index.html',
|
||||
}),
|
||||
|
||||
// Add your plugins here
|
||||
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(ts|tsx)$/i,
|
||||
loader: 'ts-loader',
|
||||
exclude: ['/node_modules/'],
|
||||
},
|
||||
{
|
||||
test: /\.css$/i,
|
||||
use: [stylesHandler, 'css-loader'],
|
||||
},
|
||||
{
|
||||
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
|
||||
type: 'asset',
|
||||
},
|
||||
|
||||
// Add your rules for custom modules here
|
||||
// Learn more about loaders from https://webpack.js.org/loaders/
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
fallback: {
|
||||
buffer: require.resolve('buffer/'),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = () => {
|
||||
if (isProduction) {
|
||||
config.mode = 'production';
|
||||
} else {
|
||||
config.mode = 'development';
|
||||
}
|
||||
return config;
|
||||
};
|
@ -1,45 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.css";
|
||||
|
||||
import { Fluence } from "@fluencelabs/fluence";
|
||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
||||
|
||||
const relayNode = krasnodar[4];
|
||||
|
||||
function App() {
|
||||
const [connected, setConnected] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
Fluence.start({ connectTo: relayNode })
|
||||
.then(() => {
|
||||
setConnected(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Client initialization failed", err);
|
||||
setConnected(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>Connected: ${connected}</p>
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
@ -1,22 +0,0 @@
|
||||
import { FluencePeer } from "@fluencelabs/fluence";
|
||||
|
||||
const peer = new FluencePeer();
|
||||
|
||||
const main = async () => {
|
||||
await peer.start({});
|
||||
const peerId = peer.getStatus().peerId;
|
||||
if (!peerId) {
|
||||
throw new Error("Peer id is null");
|
||||
}
|
||||
console.log("peer id is: ", peerId);
|
||||
await peer.stop();
|
||||
};
|
||||
|
||||
main()
|
||||
.then(() => console.log("done"))
|
||||
.catch((err) => console.error(err))
|
||||
.finally(() => {
|
||||
if (peer) {
|
||||
peer.stop();
|
||||
}
|
||||
});
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"skipDefaultLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"include": ["src/**/*"]
|
||||
}
|
@ -8,19 +8,18 @@
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "ts-node src/index.ts"
|
||||
"_test": "node --loader ts-node/esm ./src/index.ts"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/fluence": "workspace:*",
|
||||
"ts-node": "^10.9.1"
|
||||
"@fluencelabs/fluence": "workspace:0.60.0",
|
||||
"@fluencelabs/js-client.node": "0.1.0",
|
||||
"@test/aqua_for_test": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.7.13",
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
"devDependencies": {}
|
||||
}
|
4
packages/@tests/smoke_node/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import '@fluencelabs/js-client.node';
|
||||
import { runMain } from '@test/aqua_for_test';
|
||||
|
||||
runMain();
|
7
packages/@tests/smoke_node/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
21
packages/@tests/smoke_web/.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
dist
|
||||
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
||||
|
||||
public/js-client.min.js
|
24
packages/@tests/smoke_web/package.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@tests/smoke_web",
|
||||
"version": "0.1.0",
|
||||
"description": "Smoke test web",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "pnpm copy-script",
|
||||
"serve": "http-server public",
|
||||
"copy-script": "cp ../../client/js-client.web.standalone/dist/js-client.min.js ./public"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/js-client.web.standalone": "workspace:*",
|
||||
"http-server": "14.1.1"
|
||||
}
|
||||
}
|
20
packages/@tests/smoke_web/public/index.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Smoke test for web</title>
|
||||
<script src="./js-client.min.js"></script>
|
||||
<script src="./index.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<h1>Open console f12</h1>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
103
packages/@tests/smoke_web/public/index.js
Normal file
@ -0,0 +1,103 @@
|
||||
const peer = globalThis.defaultPeer;
|
||||
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
};
|
||||
|
||||
const getRelayTime = (relayPeerId) => {
|
||||
const script = `
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call relayPeerId ("peer" "timestamp_ms") [] ts)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [ts])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
`;
|
||||
|
||||
const def = {
|
||||
functionName: 'getRelayTime',
|
||||
arrow: {
|
||||
tag: 'arrow',
|
||||
domain: {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
relayPeerId: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
codomain: {
|
||||
tag: 'unlabeledProduct',
|
||||
items: [
|
||||
{
|
||||
tag: 'scalar',
|
||||
name: 'u64',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: '-relay-',
|
||||
getDataSrv: 'getDataSrv',
|
||||
callbackSrv: 'callbackSrv',
|
||||
responseSrv: 'callbackSrv',
|
||||
responseFnName: 'response',
|
||||
errorHandlingSrv: 'errorHandlingSrv',
|
||||
errorFnName: 'error',
|
||||
},
|
||||
};
|
||||
|
||||
const config = {};
|
||||
|
||||
const args = {};
|
||||
return peer.compilerSupport.callFunction({
|
||||
args,
|
||||
def,
|
||||
config,
|
||||
script,
|
||||
});
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
console.log('starting fluence...');
|
||||
await peer.start({
|
||||
connectTo: relay,
|
||||
});
|
||||
console.log('started fluence');
|
||||
|
||||
console.log('getting relay time...');
|
||||
const res = await getRelayTime(relay.peerId);
|
||||
console.log('got relay time, ', res);
|
||||
|
||||
console.log('stopping fluence...');
|
||||
await peer.stop();
|
||||
console.log('stopped fluence...');
|
||||
};
|
||||
|
||||
main()
|
||||
.then(() => console.log('done!'))
|
||||
.catch((err) => console.error('error: ', err));
|
22
packages/client/api/.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
bundle/
|
||||
tmp/
|
||||
|
||||
dist
|
||||
esm
|
||||
types
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
@ -1,4 +1,4 @@
|
||||
# FluenceJS Keypair
|
||||
# JS Client web
|
||||
|
||||
This package is a part of FluenceJS, the official implementation of the Fluence Peer in typescript. See the [FluenceJS repo](https://github.com/fluencelabs/fluence-js) for more info
|
||||
|
42
packages/client/api/package.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"_1": "This should actually be named @fluencelabs/js-client.api. Naming it fluence-js is needed for backward compat w/ aqua compiler",
|
||||
"name": "@fluencelabs/fluence",
|
||||
"version": "0.60.0",
|
||||
"description": "JS Client API",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"_2": "dist/internal/ export is needed for backward compat w/ aqua compiler",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"./compilerSupport/v5": {
|
||||
"import": "./dist/compilerSupport/v5.js",
|
||||
"types": "./dist/compilerSupport/v5.d.ts"
|
||||
},
|
||||
"./dist/compilerSupport/v5": {
|
||||
"import": "./dist/compilerSupport/v5.js",
|
||||
"types": "./dist/compilerSupport/v5.d.ts"
|
||||
},
|
||||
"./dist/internal/compilerSupport/v4": {
|
||||
"import": "./dist/compilerSupport/v5.js",
|
||||
"types": "./dist/compilerSupport/v5.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/interfaces": "0.5.0"
|
||||
},
|
||||
"devDependencies": {}
|
||||
}
|
181
packages/client/api/src/compilerSupport/implementation.ts
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright 2022 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.
|
||||
*/
|
||||
|
||||
import type { FnConfig, FunctionCallDef, ServiceDef } from '@fluencelabs/interfaces/compilerSupport';
|
||||
import type { IFluenceClient } from '@fluencelabs/interfaces/fluenceClient';
|
||||
import { getArgumentTypes } from '@fluencelabs/interfaces/compilerSupport';
|
||||
import { isFluencePeer } from '@fluencelabs/interfaces/fluenceClient';
|
||||
|
||||
import { getDefaultPeer } from '../index.js';
|
||||
|
||||
export type { IFluenceClient, CallParams } from '@fluencelabs/interfaces/fluenceClient';
|
||||
|
||||
export {
|
||||
ArrayType,
|
||||
ArrowType,
|
||||
ArrowWithCallbacks,
|
||||
ArrowWithoutCallbacks,
|
||||
BottomType,
|
||||
FnConfig,
|
||||
FunctionCallConstants,
|
||||
FunctionCallDef,
|
||||
LabeledProductType,
|
||||
NilType,
|
||||
NonArrowType,
|
||||
OptionType,
|
||||
ProductType,
|
||||
ScalarNames,
|
||||
ScalarType,
|
||||
ServiceDef,
|
||||
StructType,
|
||||
TopType,
|
||||
UnlabeledProductType,
|
||||
} from '@fluencelabs/interfaces/compilerSupport';
|
||||
|
||||
/**
|
||||
* Convenience function to support Aqua `func` generation backend
|
||||
* The compiler only need to generate a call the function and provide the corresponding definitions and the air script
|
||||
*
|
||||
* @param rawFnArgs - raw arguments passed by user to the generated function
|
||||
* @param def - function definition generated by the Aqua compiler
|
||||
* @param script - air script with function execution logic generated by the Aqua compiler
|
||||
*/
|
||||
export const callFunction = async (rawFnArgs: Array<any>, def: FunctionCallDef, script: string): Promise<unknown> => {
|
||||
const { args, peer, config } = await extractFunctionArgs(rawFnArgs, def);
|
||||
return peer.compilerSupport.callFunction({
|
||||
args,
|
||||
def,
|
||||
script,
|
||||
config: config || {},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Convenience function to support Aqua `service` generation backend
|
||||
* The compiler only need to generate a call the function and provide the corresponding definitions and the air script
|
||||
*
|
||||
* @param args - raw arguments passed by user to the generated function
|
||||
* @param def - service definition generated by the Aqua compiler
|
||||
*/
|
||||
export const registerService = async (args: any[], def: ServiceDef): Promise<unknown> => {
|
||||
const { peer, service, serviceId } = await extractServiceArgs(args, def.defaultServiceId);
|
||||
return peer.compilerSupport.registerService({
|
||||
def,
|
||||
service,
|
||||
serviceId,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Arguments could be passed in one these configurations:
|
||||
* [...actualArgs]
|
||||
* [peer, ...actualArgs]
|
||||
* [...actualArgs, config]
|
||||
* [peer, ...actualArgs, config]
|
||||
*
|
||||
* This function select the appropriate configuration and returns
|
||||
* arguments in a structured way of: { peer, config, args }
|
||||
*/
|
||||
const extractFunctionArgs = async (
|
||||
args: any[],
|
||||
def: FunctionCallDef,
|
||||
): Promise<{
|
||||
peer: IFluenceClient;
|
||||
config?: FnConfig;
|
||||
args: { [key: string]: any };
|
||||
}> => {
|
||||
const argumentTypes = getArgumentTypes(def);
|
||||
const argumentNames = Object.keys(argumentTypes);
|
||||
const numberOfExpectedArgs = argumentNames.length;
|
||||
|
||||
let peer: IFluenceClient;
|
||||
let structuredArgs: any[];
|
||||
let config: FnConfig;
|
||||
if (isFluencePeer(args[0])) {
|
||||
peer = args[0];
|
||||
structuredArgs = args.slice(1, numberOfExpectedArgs + 1);
|
||||
config = args[numberOfExpectedArgs + 1];
|
||||
} else {
|
||||
peer = await getDefaultPeer();
|
||||
structuredArgs = args.slice(0, numberOfExpectedArgs);
|
||||
config = args[numberOfExpectedArgs];
|
||||
}
|
||||
|
||||
if (structuredArgs.length !== numberOfExpectedArgs) {
|
||||
throw new Error(`Incorrect number of arguments. Expecting ${numberOfExpectedArgs}`);
|
||||
}
|
||||
|
||||
const argsRes = argumentNames.reduce((acc, name, index) => ({ ...acc, [name]: structuredArgs[index] }), {});
|
||||
|
||||
return {
|
||||
peer: peer,
|
||||
config: config,
|
||||
args: argsRes,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Arguments could be passed in one these configurations:
|
||||
* [serviceObject]
|
||||
* [peer, serviceObject]
|
||||
* [defaultId, serviceObject]
|
||||
* [peer, defaultId, serviceObject]
|
||||
*
|
||||
* Where serviceObject is the raw object with function definitions passed by user
|
||||
*
|
||||
* This function select the appropriate configuration and returns
|
||||
* arguments in a structured way of: { peer, serviceId, service }
|
||||
*/
|
||||
const extractServiceArgs = async (
|
||||
args: any[],
|
||||
defaultServiceId?: string,
|
||||
): Promise<{ peer: IFluenceClient; serviceId: string; service: any }> => {
|
||||
let peer: IFluenceClient;
|
||||
let serviceId: any;
|
||||
let service: any;
|
||||
if (isFluencePeer(args[0])) {
|
||||
peer = args[0];
|
||||
} else {
|
||||
peer = await getDefaultPeer();
|
||||
}
|
||||
|
||||
if (typeof args[0] === 'string') {
|
||||
serviceId = args[0];
|
||||
} else if (typeof args[1] === 'string') {
|
||||
serviceId = args[1];
|
||||
} else {
|
||||
serviceId = defaultServiceId;
|
||||
}
|
||||
|
||||
// Figuring out which overload is the service.
|
||||
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!isFluencePeer(args[0]) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
} else {
|
||||
service = args[2];
|
||||
}
|
||||
|
||||
return {
|
||||
peer: peer,
|
||||
serviceId: serviceId,
|
||||
service: service,
|
||||
};
|
||||
};
|
@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { FluencePeer } from '../FluencePeer';
|
||||
export { CallParams as CallParams$$ } from '../commonTypes';
|
||||
export { IFluenceClient } from './implementation.js';
|
||||
export { CallParams as CallParams$$ } from './implementation.js';
|
||||
export {
|
||||
ArrayType as ArrayType$$,
|
||||
ArrowType as ArrowType$$,
|
||||
@ -38,4 +38,4 @@ export {
|
||||
UnlabeledProductType as UnlabeledProductType$$,
|
||||
callFunction as callFunction$$,
|
||||
registerService as registerService$$,
|
||||
} from './v3';
|
||||
} from './implementation.js';
|
69
packages/client/api/src/index.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import type { IFluenceClient, ClientOptions } from '@fluencelabs/interfaces/fluenceClient';
|
||||
|
||||
export { IFluenceClient, ClientOptions, CallParams } from '@fluencelabs/interfaces/fluenceClient';
|
||||
|
||||
// TODO: hack needed to kinda have backward compat with compiler api
|
||||
export type FluencePeer = IFluenceClient;
|
||||
|
||||
const getPeerFromGlobalThis = (): IFluenceClient | undefined => {
|
||||
// @ts-ignore
|
||||
return globalThis.defaultPeer;
|
||||
};
|
||||
|
||||
// TODO: DXJ-271
|
||||
const REJECT_MESSAGE = 'You probably forgot to add script tag. Read about it here: ';
|
||||
|
||||
/**
|
||||
* Wait until the js client script it loaded and return the default peer from globalThis
|
||||
*/
|
||||
export const getDefaultPeer = (): Promise<IFluenceClient> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let interval: NodeJS.Timer | undefined;
|
||||
let hits = 50;
|
||||
interval = setInterval(() => {
|
||||
if (hits === 0) {
|
||||
clearInterval(interval);
|
||||
reject(REJECT_MESSAGE);
|
||||
}
|
||||
|
||||
let res = getPeerFromGlobalThis();
|
||||
if (res) {
|
||||
clearInterval(interval);
|
||||
resolve(res);
|
||||
}
|
||||
hits--;
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Public interface to Fluence JS
|
||||
*/
|
||||
export const Fluence = {
|
||||
/**
|
||||
* Initializes the default peer: starts the Aqua VM, initializes the default call service handlers
|
||||
* and (optionally) connect to the Fluence network
|
||||
* @param options - object specifying peer configuration
|
||||
*/
|
||||
start: async (options?: ClientOptions): Promise<void> => {
|
||||
const peer = await getDefaultPeer();
|
||||
return peer.start(options);
|
||||
},
|
||||
|
||||
/**
|
||||
* Un-initializes the default peer: stops all the underlying workflows, stops the Aqua VM
|
||||
* and disconnects from the Fluence network
|
||||
*/
|
||||
stop: async (): Promise<void> => {
|
||||
const peer = await getDefaultPeer();
|
||||
return peer.stop();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the default peer instance
|
||||
* @returns the default peer instance
|
||||
*/
|
||||
getPeer: async (): Promise<IFluenceClient> => {
|
||||
return getDefaultPeer();
|
||||
},
|
||||
};
|
7
packages/client/api/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
# FluenceJS interfaces
|
||||
# JS Client node
|
||||
|
||||
This package is a part of FluenceJS, the official implementation of the Fluence Peer in typescript. See the [FluenceJS repo](https://github.com/fluencelabs/fluence-js) for more info
|
||||
|
33
packages/client/js-client.node/package.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@fluencelabs/js-client.node",
|
||||
"version": "0.1.0",
|
||||
"description": "TypeScript implementation of Fluence Peer",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-peer": "0.5.0",
|
||||
"@fluencelabs/avm": "0.35.3",
|
||||
"@fluencelabs/marine-js": "0.3.42",
|
||||
"platform": "1.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/platform": "1.3.4"
|
||||
}
|
||||
}
|
48
packages/client/js-client.node/src/index.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import * as platform from 'platform';
|
||||
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/js-peer/FluencePeer.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/js-peer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker';
|
||||
import { marineLogFunction } from '@fluencelabs/js-peer/dist/js-peer/utils.js';
|
||||
import { WasmLoaderFromNpm } from '@fluencelabs/js-peer/dist/marine/deps-loader/node.js';
|
||||
import { WorkerLoader } from '@fluencelabs/js-peer/dist/marine/worker-script/workerLoader.js';
|
||||
|
||||
throwIfNotSupported();
|
||||
|
||||
export const defaultNames = {
|
||||
avm: {
|
||||
file: 'avm.wasm',
|
||||
package: '@fluencelabs/avm',
|
||||
},
|
||||
marine: {
|
||||
file: 'marine-js.wasm',
|
||||
package: '@fluencelabs/marine-js',
|
||||
},
|
||||
};
|
||||
|
||||
export const makeDefaultPeer = () => {
|
||||
const workerLoader = new WorkerLoader();
|
||||
const controlModuleLoader = new WasmLoaderFromNpm(defaultNames.marine.package, defaultNames.marine.file);
|
||||
const avmModuleLoader = new WasmLoaderFromNpm(defaultNames.avm.package, defaultNames.avm.file);
|
||||
|
||||
const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader, marineLogFunction);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader, undefined);
|
||||
return new FluencePeer(marine, avm);
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.defaultPeer = makeDefaultPeer();
|
||||
|
||||
function throwIfNotSupported() {
|
||||
if (platform.name === 'Node.js' && platform.version) {
|
||||
const version = platform.version.split('.').map(Number);
|
||||
const major = version[0];
|
||||
if (major < 16) {
|
||||
throw new Error(
|
||||
'FluenceJS requires node.js version >= "16.x"; Detected ' +
|
||||
platform.description +
|
||||
' Please update node.js to version 16 or higher.\nYou can use https://nvm.sh utility to update node.js version: "nvm install 17 && nvm use 17 && nvm alias default 17"',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
7
packages/client/js-client.node/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
22
packages/client/js-client.web.standalone/.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
bundle/
|
||||
tmp/
|
||||
|
||||
dist
|
||||
esm
|
||||
types
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
@ -1,4 +1,4 @@
|
||||
# FluenceJS connection
|
||||
# JS Client web
|
||||
|
||||
This package is a part of FluenceJS, the official implementation of the Fluence Peer in typescript. See the [FluenceJS repo](https://github.com/fluencelabs/fluence-js) for more info
|
||||
|
126
packages/client/js-client.web.standalone/build.ts
Normal file
@ -0,0 +1,126 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { fromUint8Array } from 'js-base64';
|
||||
import { build } from 'vite';
|
||||
import { createRequire } from 'module';
|
||||
import type { InlineConfig } from 'vite';
|
||||
import tsconfigPaths from 'vite-tsconfig-paths';
|
||||
import * as inject from '@rollup/plugin-inject';
|
||||
import { replaceCodePlugin } from 'vite-plugin-replace';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const getWorkerScriptPathOrDie = () => {
|
||||
const scriptPath = path.resolve('../../core/js-peer/dist/marine/worker-script/index.js');
|
||||
if (!fs.existsSync(scriptPath)) {
|
||||
console.error('Worker script not found, looking at: ' + scriptPath);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return scriptPath;
|
||||
};
|
||||
|
||||
const commonConfig = (opts: {
|
||||
outDir: string;
|
||||
name: string;
|
||||
entry: string;
|
||||
}): InlineConfig & Required<Pick<InlineConfig, 'build'>> => {
|
||||
return {
|
||||
mode: 'production',
|
||||
build: {
|
||||
minify: 'esbuild',
|
||||
lib: {
|
||||
entry: opts.entry,
|
||||
name: opts.name,
|
||||
fileName: opts.name,
|
||||
},
|
||||
outDir: opts.outDir,
|
||||
},
|
||||
base: '',
|
||||
plugins: [tsconfigPaths()],
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
define: {
|
||||
global: 'globalThis',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const readAsBase64 = async (filePath: string): Promise<string> => {
|
||||
const scriptRaw = await fs.promises.readFile(filePath);
|
||||
const b64 = fromUint8Array(scriptRaw);
|
||||
return b64;
|
||||
};
|
||||
|
||||
const readWasmFromNpmAsBase64 = (pkg: string, wasmFileName: string): Promise<string> => {
|
||||
const pkgPath = require.resolve(pkg);
|
||||
const wasmFilePath = path.join(path.dirname(pkgPath), wasmFileName);
|
||||
return readAsBase64(wasmFilePath);
|
||||
};
|
||||
|
||||
const buildClient = async () => {
|
||||
await fs.promises.mkdir('tmp', { recursive: true });
|
||||
|
||||
// build worker script
|
||||
const workerConfig = commonConfig({
|
||||
outDir: './tmp',
|
||||
entry: getWorkerScriptPathOrDie(),
|
||||
name: 'worker-script',
|
||||
});
|
||||
workerConfig.build!.rollupOptions = {
|
||||
plugins: [
|
||||
inject.default({
|
||||
Buffer: ['buffer', 'Buffer'],
|
||||
process: 'process',
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
await build(workerConfig);
|
||||
|
||||
// build js-client
|
||||
const jsClientConfig = commonConfig({
|
||||
outDir: './dist',
|
||||
entry: './src/index.ts',
|
||||
name: 'js-client',
|
||||
});
|
||||
|
||||
const workerScriptB64 = await readAsBase64('./tmp/worker-script.umd.cjs');
|
||||
const avmBase64 = await readWasmFromNpmAsBase64('@fluencelabs/avm', 'avm.wasm');
|
||||
const marineBase64 = await readWasmFromNpmAsBase64('@fluencelabs/marine-js', 'marine-js.wasm');
|
||||
|
||||
jsClientConfig.plugins!.push(
|
||||
replaceCodePlugin({
|
||||
replacements: [
|
||||
{
|
||||
from: '___worker___',
|
||||
to: workerScriptB64,
|
||||
},
|
||||
{
|
||||
from: '___avm___',
|
||||
to: avmBase64,
|
||||
},
|
||||
{
|
||||
from: '___marine___',
|
||||
to: marineBase64,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
await build(jsClientConfig);
|
||||
|
||||
// We should exclude the script with type=module because
|
||||
// - it might be confusing (i.e won't work in browsers that do not support ESM, or if you miss the `type` attribute)
|
||||
// - there is a problem when using `self.crypto` in web workers
|
||||
await fs.promises.rm('./dist/js-client.js');
|
||||
|
||||
// browsers don't understand `.cjs` extensions, just use `.js`
|
||||
await fs.promises.rename('./dist/js-client.umd.cjs', './dist/js-client.min.js');
|
||||
};
|
||||
|
||||
buildClient()
|
||||
.then(() => console.log('Built successfully'))
|
||||
.catch((err) => console.error('failed', err));
|
36
packages/client/js-client.web.standalone/package.json
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@fluencelabs/js-client.web.standalone",
|
||||
"version": "0.1.0",
|
||||
"description": "TypeScript implementation of Fluence Peer",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "node --loader ts-node/esm ./build.ts"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-peer": "0.5.0",
|
||||
"buffer": "6.0.3",
|
||||
"process": "0.11.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/avm": "0.35.3",
|
||||
"@fluencelabs/marine-js": "0.3.42",
|
||||
"@types/node": "16.11.59",
|
||||
"@types/jest": "28.1.0",
|
||||
"jest": "28.1.0",
|
||||
"ts-jest": "28.0.2",
|
||||
"js-base64": "3.7.2",
|
||||
"@rollup/plugin-inject": "5.0.3",
|
||||
"vite-plugin-replace": "0.1.1",
|
||||
"vite": "4.0.4",
|
||||
"vite-tsconfig-paths": "4.0.3"
|
||||
}
|
||||
}
|
18
packages/client/js-client.web.standalone/src/index.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/js-peer/FluencePeer.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/js-peer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker';
|
||||
import { checkConnection, marineLogFunction } from '@fluencelabs/js-peer/dist/js-peer/utils.js';
|
||||
import { InlinedWorkerLoader, InlinedWasmLoader } from '@fluencelabs/js-peer/dist/marine/deps-loader/common.js';
|
||||
|
||||
export const makeDefaultPeer = () => {
|
||||
const workerLoader = new InlinedWorkerLoader('___worker___');
|
||||
const controlModuleLoader = new InlinedWasmLoader('___marine___');
|
||||
const avmModuleLoader = new InlinedWasmLoader('___avm___');
|
||||
|
||||
const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader, marineLogFunction);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader, undefined);
|
||||
return new FluencePeer(marine, avm);
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.defaultPeer = makeDefaultPeer();
|
8
packages/client/js-client.web.standalone/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
@ -1,12 +1,6 @@
|
||||
# Fluence JS
|
||||
# JS Client web
|
||||
|
||||
[](https://www.npmjs.com/package/@fluencelabs/fluence)
|
||||
|
||||
Official TypeScript implementation of the Fluence Peer.
|
||||
|
||||
## Getting started
|
||||
|
||||
To start developing applications with Fluence JS refer to the official [documentation](https://fluence.dev/docs/build/fluence-js/)
|
||||
This package is a part of FluenceJS, the official implementation of the Fluence Peer in typescript. See the [FluenceJS repo](https://github.com/fluencelabs/fluence-js) for more info
|
||||
|
||||
## Contributing
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@fluencelabs/keypair",
|
||||
"version": "0.2.0",
|
||||
"description": "Keypair implementation for Fluence JS Peer",
|
||||
"name": "@fluencelabs/js-client.web",
|
||||
"version": "0.1.0",
|
||||
"description": "TypeScript implementation of Fluence Peer",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
@ -15,11 +15,12 @@
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"peer-id": "0.16.0",
|
||||
"libp2p-crypto": "0.21.2",
|
||||
"js-base64": "^3.7.2"
|
||||
"@fluencelabs/js-peer": "workspace:0.60.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^4.6.4"
|
||||
"@types/node": "16.11.59",
|
||||
"@types/jest": "28.1.0",
|
||||
"jest": "28.1.0",
|
||||
"ts-jest": "28.0.2"
|
||||
}
|
||||
}
|
23
packages/client/js-client.web/src/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/marine.background-runner';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/avm';
|
||||
import { marineLogFunction } from '@fluencelabs/js-peer/dist/utils';
|
||||
import { FluencePeer } from '@fluencelabs/js-peer/dist/FluencePeer';
|
||||
import { InlinedWorkerLoader, WasmWebLoader } from '@fluencelabs/marine.deps-loader.web';
|
||||
|
||||
export const defaultNames = {
|
||||
avm: 'avm.wasm',
|
||||
marine: 'marine-js.wasm',
|
||||
};
|
||||
|
||||
export const makeDefaultPeer = () => {
|
||||
const workerLoader = new InlinedWorkerLoader();
|
||||
const controlModuleLoader = new WasmWebLoader(defaultNames.marine);
|
||||
const avmModuleLoader = new WasmWebLoader(defaultNames.avm);
|
||||
|
||||
const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader, marineLogFunction);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader, undefined);
|
||||
return new FluencePeer(marine, avm);
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.defaultPeer = makeDefaultPeer();
|
7
packages/client/js-client.web/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|