mirror of
https://github.com/fluencelabs/aqua-ipfs
synced 2025-03-14 20:50:49 +00:00
CI: publish to NPM + auto changelog + separate example (#16)
This commit is contained in:
parent
3e0990c222
commit
a50c2bc9ab
5
.github/workflows/changelog_config.json
vendored
Normal file
5
.github/workflows/changelog_config.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"template": "${{CHANGELOG}}\n\n${{UNCATEGORIZED}}",
|
||||
"pr_template": "- #${{NUMBER}} ${{TITLE}}",
|
||||
"empty_template": "- no changes"
|
||||
}
|
23
.github/workflows/release.yml
vendored
23
.github/workflows/release.yml
vendored
@ -54,6 +54,14 @@ jobs:
|
||||
mv artifacts ipfs-adapter
|
||||
tar -zcvf ipfs-adapter.tar.gz ipfs-adapter
|
||||
|
||||
- name: Build Changelog
|
||||
id: github_release
|
||||
uses: mikepenz/release-changelog-builder-action@v1
|
||||
with:
|
||||
configuration: ".github/workflows/changelog_config.json"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
@ -61,6 +69,7 @@ jobs:
|
||||
tag_name: ${{ env.RELEASE_VERSION }}
|
||||
files: |
|
||||
./service/ipfs-adapter.tar.gz
|
||||
body: ${{steps.github_release.outputs.changelog}}
|
||||
draft: false
|
||||
prerelease: false
|
||||
env:
|
||||
@ -74,4 +83,16 @@ jobs:
|
||||
repo: fluencelabs/node-distro
|
||||
ref: 'main'
|
||||
token: ${{ secrets.PERSONAL_TOKEN }}
|
||||
# inputs: '{ "version": "${{ env.VERSION }}" }'
|
||||
|
||||
### Publish to NPM registry
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: "14"
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
|
||||
- run: |
|
||||
npm version ${{ env.RELEASE_VERSION }}
|
||||
npm publish --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
working-directory: ./aqua
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,7 +15,3 @@
|
||||
**/dist
|
||||
.DS_store
|
||||
.bic_cache
|
||||
|
||||
aqua/typescript/
|
||||
!aqua/typescript/index.ts
|
||||
!aqua/typescript/demo.ts
|
||||
|
31
README.md
31
README.md
@ -1,5 +1,30 @@
|
||||
# Fluence IPFS adapter
|
||||
# Aqua IPFS bindings
|
||||
Native IPFS integration to Aqua language. Orchestrate IPFS file transfer with Aqua scripts.
|
||||
|
||||
## How to use it in TypeScript
|
||||
1. Add the following to your dependencies
|
||||
- `@fluencelabs/aqua-ipfs`
|
||||
- `@fluencelabs/fluence`
|
||||
- `@fluencelabs/fluence-network-environment`
|
||||
2. Import and call
|
||||
```typescript
|
||||
import { put, get_from } from '@fluencelabs/aqua-ipfs';
|
||||
import { createClient } from "@fluencelabs/fluence";
|
||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
||||
|
||||
const fluence = await createClient(krasnodar[1]);
|
||||
let cid = "Qm...";
|
||||
let ipfs = "/ip4/x.x.x.x/tcp/5001/"
|
||||
let getResult = await get_from(fluence, fluence.relayPeerId, cid, ipfs, { ttl: 10000 });
|
||||
```
|
||||
|
||||
## Directory structure
|
||||
- `service` contains Rust service that implements all the IPFS calls by using `ipfs` cli mounted binary
|
||||
- `local-network` contains Docker Compose YAML config to run a local Fluence network of 3 nodes
|
||||
- `aqua` Aqua API of IPFS-adapter, go to its [README](/aqua/README.md)
|
||||
- `service` contains Rust service that implements all the IPFS calls by using `ipfs` cli mounted binary
|
||||
- `example` A simple example of how to use ipfs adapter from TypeScript
|
||||
- `local-network` contains Docker Compose YAML config to run a local Fluence network of 3 nodes
|
||||
|
||||
# Contribution
|
||||
Contributions are welcome!
|
||||
|
||||
`ipfs-adapter` integrates with IPFS by using `ipfs` CLI, so it's possible to expose virtually any IPFS API to Aqua. Feel free to open an issue or contribute APIs and patterns you find useful.
|
||||
|
@ -4,16 +4,7 @@ Public API is defined in [ipfs-api.aqua](/aqua/ipfs-api.aqua).
|
||||
ipfs-adapter service API is defined in [ipfs.aqua](/aqua/ipfs.aqua).
|
||||
|
||||
## How to use Aqua API in TypeScript
|
||||
There's a simple example in [demo.ts](/aqua/typescript/demo.ts)
|
||||
|
||||
### Run demo.ts example on TestNet
|
||||
While in `aqua` directory, `npm start` will run `demo.ts` against Fluence TestNet
|
||||
|
||||
### Run demo.ts example locally
|
||||
1. Go to `local-network`
|
||||
2. Run `docker compose up -d` to start Fluence cluster of 3 nodes
|
||||
3. Go back to `../aqua`
|
||||
4. Run `npm run start:local`
|
||||
There's a simple example in [../example](/example/index.ts)
|
||||
|
||||
## How to update ipfs.aqua from ipfs_pure.wasm
|
||||
While in `aqua` directory, run `npm run generate-aqua`
|
||||
|
Binary file not shown.
33
aqua/package-lock.json
generated
33
aqua/package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@fluencelabs/aqua-ipfs",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.12",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -11,9 +11,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@fluencelabs/aqua-lib": {
|
||||
"version": "0.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-lib/-/aqua-lib-0.1.9.tgz",
|
||||
"integrity": "sha512-WLvwrH98R4BT7NHrzYkJE8f0G61BZi3lVog/W3pmyzYjufxTtxoAS28Zqycbt0ZVpUTfIC016QKu58b4SbhZWw=="
|
||||
"version": "0.1.10",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-lib/-/aqua-lib-0.1.10.tgz",
|
||||
"integrity": "sha512-DB4fE4kqN6T3TcQLzgYuNnHZd2rT0MGQ6Yky/KXfy0HlH/xL2cYQHs0xctDwIRMytA7U3laYvyz7FWPc3wEiNg=="
|
||||
},
|
||||
"@fluencelabs/avm": {
|
||||
"version": "0.10.5",
|
||||
@ -3607,31 +3607,6 @@
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"multiaddr": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/multiaddr/-/multiaddr-10.0.0.tgz",
|
||||
"integrity": "sha512-yP3LzFkM0GORZHNenS8Ok2spsaICRBhxLEohAfKKwwrgHIEWrDUhMRIkh/MONDBThNqaiGl7Ch1H7qblRDNHyg==",
|
||||
"requires": {
|
||||
"dns-over-http-resolver": "^1.0.0",
|
||||
"err-code": "^3.0.1",
|
||||
"is-ip": "^3.1.0",
|
||||
"multiformats": "^9.0.2",
|
||||
"uint8arrays": "^2.1.3",
|
||||
"varint": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"err-code": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/err-code/-/err-code-3.0.1.tgz",
|
||||
"integrity": "sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA=="
|
||||
},
|
||||
"varint": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz",
|
||||
"integrity": "sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"multiaddr-to-uri": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/multiaddr-to-uri/-/multiaddr-to-uri-6.0.0.tgz",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@fluencelabs/aqua-ipfs",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.12",
|
||||
"description": "Aqua IPFS library",
|
||||
"main": "./typescript/dist/index.js",
|
||||
"typings": "./typescript/dist/index.d.ts",
|
||||
@ -13,7 +13,7 @@
|
||||
"typescript/dist/ipfs-api.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-lib": "^0.1.9",
|
||||
"@fluencelabs/aqua-lib": "^0.1.10",
|
||||
"@fluencelabs/fluence": "^0.9.53",
|
||||
"@fluencelabs/fluence-network-environment": "^1.0.10"
|
||||
},
|
||||
@ -45,9 +45,6 @@
|
||||
"homepage": "hhttps://github.com/fluencelabs/ipfs-adapter#readme",
|
||||
"devDependencies": {
|
||||
"@fluencelabs/aqua-cli": "0.1.9-164",
|
||||
"typescript": "^3.9.5",
|
||||
"ipfs-http-client": "^50.1.2",
|
||||
"it-all": "^1.0.5",
|
||||
"uint8arrays": "^2.1.5"
|
||||
"typescript": "^3.9.5"
|
||||
}
|
||||
}
|
||||
|
363
aqua/typescript/ipfs-api.ts
Normal file
363
aqua/typescript/ipfs-api.ts
Normal file
@ -0,0 +1,363 @@
|
||||
/**
|
||||
*
|
||||
* 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.1.9-164
|
||||
*
|
||||
*/
|
||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
||||
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
|
||||
|
||||
|
||||
|
||||
export async function set_timeout(client: FluenceClient, node: string, timeout_sec: number, config?: {ttl?: number}): Promise<void> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "timeout_sec") [] timeout_sec)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("ipfs-adapter" "set_timeout") [timeout_sec])
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.on('getDataSrv', 'timeout_sec', () => {return timeout_sec;});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for set_timeout');
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return Promise.race([promise, Promise.resolve()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function get_from(client: FluenceClient, node: string, hash: string, from: string, config?: {ttl?: number}): Promise<{error:string;path:string;success:boolean}> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<{error:string;path:string;success:boolean}>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "hash") [] hash)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "from") [] from)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("ipfs-adapter" "get_from") [hash from] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.on('getDataSrv', 'hash', () => {return hash;});
|
||||
h.on('getDataSrv', 'from', () => {return from;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for get_from');
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function get_external_swarm_multiaddr(client: FluenceClient, node: string, config?: {ttl?: number}): Promise<{error:string;multiaddr:string;success:boolean}> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("ipfs-adapter" "get_external_swarm_multiaddr") [] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for get_external_swarm_multiaddr');
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function put(client: FluenceClient, node: string, path: string, config?: {ttl?: number}): Promise<{error:string;hash:string;success:boolean}> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<{error:string;hash:string;success:boolean}>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "path") [] path)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("ipfs-adapter" "put") [path] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.on('getDataSrv', 'path', () => {return path;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for put');
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function get_external_api_multiaddr(client: FluenceClient, node: string, config?: {ttl?: number}): Promise<{error:string;multiaddr:string;success:boolean}> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call node ("ipfs-adapter" "get_external_api_multiaddr") [] result)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for get_external_api_multiaddr');
|
||||
})
|
||||
if(config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
8
example/README.md
Normal file
8
example/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Run example on TestNet
|
||||
While in `example` directory, `npm start` will run `index.ts` against Fluence TestNet
|
||||
|
||||
# Run example locally
|
||||
1. Go to `local-network`
|
||||
2. Run `docker compose up -d` to start Fluence cluster of 3 nodes
|
||||
3. Go back to `../example`
|
||||
4. Run `npm run start:local`
|
@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { put, get_from, set_timeout } from './ipfs-api';
|
||||
import { put, get_from, set_timeout } from '@fluencelabs/aqua-ipfs';
|
||||
import {createClient} from "@fluencelabs/fluence";
|
||||
import { Node, testNet} from "@fluencelabs/fluence-network-environment";
|
||||
|
||||
import {createClient, setLogLevel} from "@fluencelabs/fluence";
|
||||
import {stage, krasnodar, Node, testNet} from "@fluencelabs/fluence-network-environment";
|
||||
const { create, globSource, urlSource } = require('ipfs-http-client');
|
||||
const { create, urlSource } = require('ipfs-http-client');
|
||||
const all = require('it-all');
|
||||
const uint8ArrayConcat = require('uint8arrays/concat')
|
||||
|
8562
example/package-lock.json
generated
Normal file
8562
example/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
example/package.json
Normal file
20
example/package.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "ipfs-aqua-example",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple example of how to use ipfs-aqua in TS",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js",
|
||||
"prestart": "npm run build"
|
||||
},
|
||||
"author": "Fluence Labs",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-ipfs": "file:../aqua",
|
||||
"@fluencelabs/fluence": "0.9.53",
|
||||
"ipfs-http-client": "^50.1.2",
|
||||
"it-all": "^1.0.5",
|
||||
"uint8arrays": "^2.1.5"
|
||||
}
|
||||
}
|
69
example/tsconfig.json
Normal file
69
example/tsconfig.json
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user