mirror of
https://github.com/fluencelabs/examples
synced 2025-07-04 12:11:34 +00:00
chore(js-client): Update and restructure examples [fixes DXJ-454] (#464)
* Update examples * Update js-client examples * Add cli to example * Fixes * Update js-client * Update js-client version in js-client examples * PR fixes * Remove marine-js * Update locks * Fix aqua * Remove unused import * Adjust import * Change code comment * Update example structures * Fix quickstart examples * Add aqua command to README * Add marine example * Fix image links * Fixes * Misc fixes
This commit is contained in:
8
js-client-examples/node-example/src/aqua/calc.aqua
Normal file
8
js-client-examples/node-example/src/aqua/calc.aqua
Normal file
@ -0,0 +1,8 @@
|
||||
service Calc("calc"):
|
||||
add(n: f32)
|
||||
subtract(n: f32)
|
||||
multiply(n: f32)
|
||||
divide(n: f32)
|
||||
reset()
|
||||
getResult() -> f32
|
||||
|
@ -0,0 +1,13 @@
|
||||
import "./calc.aqua"
|
||||
|
||||
const PEER ?= "12D3KooWKETqJdR26urWDbkRAVRdPQhcYNSJNGMBTn1zuE9kjQmo"
|
||||
const RELAY ?= "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e"
|
||||
|
||||
func demoCalculation() -> f32:
|
||||
on PEER via RELAY:
|
||||
Calc.add(10)
|
||||
Calc.multiply(5)
|
||||
Calc.subtract(8)
|
||||
Calc.divide(6)
|
||||
res <- Calc.getResult()
|
||||
<- res
|
31
js-client-examples/node-example/src/frontend/.gitignore
vendored
Normal file
31
js-client-examples/node-example/src/frontend/.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
/dist
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
|
||||
# fluence
|
||||
|
||||
src/compiled-aqua/*
|
||||
.fluence/
|
@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
semi: true,
|
||||
trailingComma: 'all',
|
||||
singleQuote: true,
|
||||
printWidth: 120,
|
||||
tabWidth: 4,
|
||||
useTabs: false,
|
||||
};
|
16
js-client-examples/node-example/src/frontend/jest.config.cjs
Normal file
16
js-client-examples/node-example/src/frontend/jest.config.cjs
Normal file
@ -0,0 +1,16 @@
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
module.exports = {
|
||||
extensionsToTreatAsEsm: ['.ts'],
|
||||
moduleNameMapper: {
|
||||
'^(\\.{1,2}/.*)\\.js$': '$1',
|
||||
},
|
||||
testPathIgnorePatterns: ['dist'],
|
||||
transform: {
|
||||
'^.+\\.tsx?$': [
|
||||
'ts-jest',
|
||||
{
|
||||
useESM: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
5120
js-client-examples/node-example/src/frontend/package-lock.json
generated
Normal file
5120
js-client-examples/node-example/src/frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
js-client-examples/node-example/src/frontend/package.json
Normal file
24
js-client-examples/node-example/src/frontend/package.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "node-example",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node --loader ts-node/esm ./src/index.ts",
|
||||
"build": "tsc",
|
||||
"test": "jest"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"ts-node": "10.9.1",
|
||||
"@types/node": "20.8.10",
|
||||
"@types/jest": "29.4.0",
|
||||
"jest": "29.4.1",
|
||||
"ts-jest": "29.0.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "^0.5.4"
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { justStop, runServer } from '../main.js';
|
||||
import { demoCalculation } from '../_aqua/demo-calculation.js';
|
||||
import { demoCalculation } from '../compiled-aqua/demo-calculation.js';
|
||||
|
||||
describe('smoke test', () => {
|
||||
it('should work', async () => {
|
@ -1,7 +1,6 @@
|
||||
import '@fluencelabs/js-client.node';
|
||||
import { Fluence } from '@fluencelabs/js-client.api';
|
||||
import { kras } from '@fluencelabs/fluence-network-environment';
|
||||
import { registerCalc, CalcDef } from './_aqua/calc.js';
|
||||
import { Fluence } from '@fluencelabs/js-client';
|
||||
import { registerCalc, CalcDef } from './compiled-aqua/calc.js';
|
||||
import relays from './relays.json' assert { type: "json" };
|
||||
|
||||
class Calc implements CalcDef {
|
||||
private _state: number = 0;
|
||||
@ -31,7 +30,7 @@ class Calc implements CalcDef {
|
||||
}
|
||||
}
|
||||
|
||||
const relay = kras[0];
|
||||
const relay = relays[0];
|
||||
|
||||
// generated with `npx aqua create_keypair`
|
||||
const skBase64 = 'tOpsT08fvYMnRypj3VtSoqWMN5W/AptKsP39yanlkg4=';
|
||||
@ -48,7 +47,7 @@ export async function runServer() {
|
||||
|
||||
registerCalc(new Calc());
|
||||
|
||||
const client = await Fluence.getClient();
|
||||
const client = Fluence.getClient();
|
||||
|
||||
console.log('application started');
|
||||
console.log('peer id is: ', client.getPeerId());
|
46
js-client-examples/node-example/src/frontend/src/relays.json
Normal file
46
js-client-examples/node-example/src/frontend/src/relays.json
Normal file
@ -0,0 +1,46 @@
|
||||
[
|
||||
{
|
||||
"multiaddr": "/dns4/0-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e",
|
||||
"peerId": "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/1-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51",
|
||||
"peerId": "12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/2-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
|
||||
"peerId": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/3-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf",
|
||||
"peerId": "12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/4-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
"peerId": "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/5-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi",
|
||||
"peerId": "12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/6-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS",
|
||||
"peerId": "12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/7-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
|
||||
"peerId": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/8-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn",
|
||||
"peerId": "12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/9-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
"peerId": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt"
|
||||
},
|
||||
{
|
||||
"multiaddr": "/dns4/10-kras.fluence.dev/tcp/9000/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm",
|
||||
"peerId": "12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm"
|
||||
}
|
||||
]
|
19
js-client-examples/node-example/src/frontend/tsconfig.json
Normal file
19
js-client-examples/node-example/src/frontend/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es2015", "dom"],
|
||||
"outDir": "./dist/",
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true,
|
||||
"declarationMap": false,
|
||||
"sourceMap": true,
|
||||
"moduleResolution": "nodenext",
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"include": ["src"]
|
||||
}
|
Reference in New Issue
Block a user