mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-05 02:10:18 +00:00
feat!: Expose updated JS Client API via js-client.api
package (#246)
This commit is contained in:
parent
9667c4fec6
commit
d4bb8fb429
105
.github/workflows/tests.yml
vendored
105
.github/workflows/tests.yml
vendored
@ -1,4 +1,8 @@
|
|||||||
name: Run tests with worflow_call
|
name: Run tests
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: .
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
@ -30,83 +34,32 @@ jobs:
|
|||||||
name: "Run tests"
|
name: "Run tests"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
permissions:
|
strategy:
|
||||||
contents: read
|
matrix:
|
||||||
id-token: write
|
node-version: [16.x, 17.x, 18.x]
|
||||||
|
|
||||||
strategy:
|
steps:
|
||||||
matrix:
|
- uses: actions/checkout@v2
|
||||||
node-version:
|
|
||||||
- 16.x
|
|
||||||
- 17.x
|
|
||||||
|
|
||||||
steps:
|
- name: Setup Node.js ${{ matrix.node-version }}
|
||||||
- name: Import secrets
|
uses: actions/setup-node@v1
|
||||||
uses: hashicorp/vault-action@v2.4.3
|
with:
|
||||||
with:
|
node-version: ${{ matrix.node-version }}
|
||||||
url: https://vault.fluence.dev
|
|
||||||
path: jwt/github
|
|
||||||
role: ci
|
|
||||||
method: jwt
|
|
||||||
jwtGithubAudience: "https://github.com/fluencelabs"
|
|
||||||
jwtTtl: 300
|
|
||||||
secrets: |
|
|
||||||
kv/docker-registry/basicauth/ci username | DOCKER_USERNAME ;
|
|
||||||
kv/docker-registry/basicauth/ci password | DOCKER_PASSWORD
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Setup pnpm
|
||||||
uses: docker/login-action@v2
|
uses: pnpm/action-setup@v2.2.4
|
||||||
with:
|
with:
|
||||||
registry: docker.fluence.dev
|
version: 7
|
||||||
username: ${{ env.DOCKER_USERNAME }}
|
|
||||||
password: ${{ env.DOCKER_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Checkout
|
- name: Run container with Fluence node
|
||||||
uses: actions/checkout@v3
|
run: |
|
||||||
with:
|
docker pull fluencelabs/fluence
|
||||||
repository: fluencelabs/fluence-js
|
docker run -d --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj --local --aqua-pool-size 2
|
||||||
ref: ${{ inputs.ref }}
|
|
||||||
|
|
||||||
- name: Pull rust-peer image
|
- run: pnpm i
|
||||||
run: docker pull $RUST_PEER_IMAGE
|
- run: pnpm -r build
|
||||||
|
env:
|
||||||
- name: Run rust-peer
|
CI: true
|
||||||
uses: isbang/compose-action@v1.4.1
|
- run: pnpm -r test
|
||||||
with:
|
env:
|
||||||
compose-file: ".github/e2e/docker-compose.yml"
|
CI: true
|
||||||
down-flags: "--volumes"
|
|
||||||
|
|
||||||
- name: Setup pnpm
|
|
||||||
uses: pnpm/action-setup@v2.2.4
|
|
||||||
with:
|
|
||||||
version: 7
|
|
||||||
|
|
||||||
- name: Setup node ${{ matrix.node-version }} with self-hosted registry
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
registry-url: "https://npm.fluence.dev"
|
|
||||||
cache: "pnpm"
|
|
||||||
|
|
||||||
- run: pnpm i
|
|
||||||
|
|
||||||
- name: Set avm version
|
|
||||||
if: inputs.avm-version != 'null'
|
|
||||||
uses: fluencelabs/github-actions/npm-set-dependency@main
|
|
||||||
with:
|
|
||||||
package: "@fluencelabs/avm"
|
|
||||||
version: ${{ inputs.avm-version }}
|
|
||||||
working-directory: packages/fluence-js
|
|
||||||
package-manager: pnpm
|
|
||||||
|
|
||||||
- name: Set marine-js version
|
|
||||||
if: inputs.marine-js-version != 'null'
|
|
||||||
uses: fluencelabs/github-actions/npm-set-dependency@main
|
|
||||||
with:
|
|
||||||
package: "@fluencelabs/marine-js"
|
|
||||||
version: ${{ inputs.marine-js-version }}
|
|
||||||
working-directory: packages/fluence-js
|
|
||||||
package-manager: pnpm
|
|
||||||
|
|
||||||
- run: pnpm -r build
|
|
||||||
- run: pnpm -r test
|
|
||||||
|
112
.github/workflows/tests.yml.disabled
vendored
Normal file
112
.github/workflows/tests.yml.disabled
vendored
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
name: Run tests with worflow_call
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
rust-peer-image:
|
||||||
|
description: "rust-peer image tag"
|
||||||
|
type: string
|
||||||
|
default: "fluencelabs/fluence:minimal"
|
||||||
|
avm-version:
|
||||||
|
description: "@fluencelabs/avm version"
|
||||||
|
type: string
|
||||||
|
default: "null"
|
||||||
|
marine-js-version:
|
||||||
|
description: "@fluencelabs/marine-js version"
|
||||||
|
type: string
|
||||||
|
default: "null"
|
||||||
|
ref:
|
||||||
|
description: "git ref to checkout to"
|
||||||
|
type: string
|
||||||
|
default: "master"
|
||||||
|
|
||||||
|
env:
|
||||||
|
RUST_PEER_IMAGE: "${{ inputs.rust-peer-image }}"
|
||||||
|
FORCE_COLOR: true
|
||||||
|
CI: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
fluence-js:
|
||||||
|
name: "Run tests"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version:
|
||||||
|
- 16.x
|
||||||
|
- 17.x
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Import secrets
|
||||||
|
uses: hashicorp/vault-action@v2.4.3
|
||||||
|
with:
|
||||||
|
url: https://vault.fluence.dev
|
||||||
|
path: jwt/github
|
||||||
|
role: ci
|
||||||
|
method: jwt
|
||||||
|
jwtGithubAudience: "https://github.com/fluencelabs"
|
||||||
|
jwtTtl: 300
|
||||||
|
secrets: |
|
||||||
|
kv/docker-registry/basicauth/ci username | DOCKER_USERNAME ;
|
||||||
|
kv/docker-registry/basicauth/ci password | DOCKER_PASSWORD
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: docker.fluence.dev
|
||||||
|
username: ${{ env.DOCKER_USERNAME }}
|
||||||
|
password: ${{ env.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: fluencelabs/fluence-js
|
||||||
|
ref: ${{ inputs.ref }}
|
||||||
|
|
||||||
|
- name: Pull rust-peer image
|
||||||
|
run: docker pull $RUST_PEER_IMAGE
|
||||||
|
|
||||||
|
- name: Run rust-peer
|
||||||
|
uses: isbang/compose-action@v1.4.1
|
||||||
|
with:
|
||||||
|
compose-file: ".github/e2e/docker-compose.yml"
|
||||||
|
down-flags: "--volumes"
|
||||||
|
|
||||||
|
- name: Setup pnpm
|
||||||
|
uses: pnpm/action-setup@v2.2.4
|
||||||
|
with:
|
||||||
|
version: 7
|
||||||
|
|
||||||
|
- name: Setup node ${{ matrix.node-version }} with self-hosted registry
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
registry-url: "https://npm.fluence.dev"
|
||||||
|
cache: "pnpm"
|
||||||
|
|
||||||
|
- run: pnpm i
|
||||||
|
|
||||||
|
- name: Set avm version
|
||||||
|
if: inputs.avm-version != 'null'
|
||||||
|
uses: fluencelabs/github-actions/npm-set-dependency@main
|
||||||
|
with:
|
||||||
|
package: "@fluencelabs/avm"
|
||||||
|
version: ${{ inputs.avm-version }}
|
||||||
|
working-directory: packages/fluence-js
|
||||||
|
package-manager: pnpm
|
||||||
|
|
||||||
|
- name: Set marine-js version
|
||||||
|
if: inputs.marine-js-version != 'null'
|
||||||
|
uses: fluencelabs/github-actions/npm-set-dependency@main
|
||||||
|
with:
|
||||||
|
package: "@fluencelabs/marine-js"
|
||||||
|
version: ${{ inputs.marine-js-version }}
|
||||||
|
working-directory: packages/fluence-js
|
||||||
|
package-manager: pnpm
|
||||||
|
|
||||||
|
- run: pnpm -r build
|
||||||
|
- run: pnpm -r test
|
@ -13,10 +13,9 @@
|
|||||||
},
|
},
|
||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"http-server": "14.1.1",
|
"http-server": "14.1.1",
|
||||||
"@types/node": "16.11.59",
|
"@types/node": "18.13.0",
|
||||||
"ts-node": "10.9.1",
|
"ts-node": "10.9.1",
|
||||||
"typescript": "4.7",
|
"typescript": "4.7",
|
||||||
"@fluencelabs/aqua-lib": "0.6.0",
|
"@fluencelabs/aqua-lib": "0.6.0",
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/fluence": "workspace:0.60.0",
|
"@fluencelabs/js-client.api": "0.10.0",
|
||||||
"@fluencelabs/fluence-network-environment": "1.0.13",
|
"@fluencelabs/fluence-network-environment": "1.0.13",
|
||||||
"base64-js": "1.5.1"
|
"base64-js": "1.5.1"
|
||||||
},
|
},
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
* Aqua version: 0.9.4
|
* Aqua version: 0.9.4
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluencePeer } from '@fluencelabs/fluence';
|
|
||||||
import type { CallParams$$ } from '@fluencelabs/fluence/dist/internal/compilerSupport/v4';
|
// eslint-disable
|
||||||
import { callFunction$$, registerService$$ } from '@fluencelabs/fluence/dist/internal/compilerSupport/v4';
|
//ts-nocheck
|
||||||
|
import type { IFluenceClient as IFluenceClient$$, CallParams as CallParams$$ } from '@fluencelabs/js-client.api';
|
||||||
|
import { v5_callFunction as callFunction$$, v5_registerService as registerService$$ } from '@fluencelabs/js-client.api';
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ import { callFunction$$, registerService$$ } from '@fluencelabs/fluence/dist/int
|
|||||||
export type SmokeTestResult = [string | null, string[]];
|
export type SmokeTestResult = [string | null, string[]];
|
||||||
export function smokeTest(label: string, config?: { ttl?: number }): Promise<SmokeTestResult>;
|
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(peer: IFluenceClient$$, label: string, config?: { ttl?: number }): Promise<SmokeTestResult>;
|
||||||
|
|
||||||
export function smokeTest(...args: any) {
|
export function smokeTest(...args: any) {
|
||||||
let script = `
|
let script = `
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { fromByteArray } from 'base64-js';
|
import { fromByteArray } from 'base64-js';
|
||||||
import { Fluence } from '@fluencelabs/fluence';
|
import { Fluence } from '@fluencelabs/js-client.api';
|
||||||
import { krasnodar } from '@fluencelabs/fluence-network-environment';
|
import { krasnodar } from '@fluencelabs/fluence-network-environment';
|
||||||
import { smokeTest } from './_aqua/smoke_test.js';
|
import { smokeTest } from './_aqua/smoke_test.js';
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/fluence": "workspace:0.60.0",
|
"@fluencelabs/js-client.api": "0.10.0",
|
||||||
"@test/aqua_for_test": "workspace:*",
|
"@test/aqua_for_test": "workspace:*",
|
||||||
"@testing-library/jest-dom": "5.16.5",
|
"@testing-library/jest-dom": "5.16.5",
|
||||||
"@testing-library/react": "13.4.0",
|
"@testing-library/react": "13.4.0",
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/fluence": "workspace:0.60.0",
|
"@fluencelabs/js-client.api": "0.10.0",
|
||||||
"@fluencelabs/js-client.node": "0.1.0",
|
"@fluencelabs/js-client.node": "0.1.0",
|
||||||
"@test/aqua_for_test": "workspace:*"
|
"@test/aqua_for_test": "workspace:*"
|
||||||
},
|
},
|
||||||
|
33
packages/client/api/dtsbundle.cjs
Normal file
33
packages/client/api/dtsbundle.cjs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
// If won't use `@ts-check` - just remove that comments (with `@type` JSDoc below).
|
||||||
|
|
||||||
|
/** @type import('dts-bundle-generator/config-schema').OutputOptions */
|
||||||
|
const commonOutputParams = {
|
||||||
|
inlineDeclareGlobals: false,
|
||||||
|
sortNodes: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type import('dts-bundle-generator/config-schema').BundlerConfig */
|
||||||
|
const config = {
|
||||||
|
compilationOptions: {
|
||||||
|
preferredConfigPath: './tsconfig.json',
|
||||||
|
},
|
||||||
|
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
filePath: './src/index.ts',
|
||||||
|
outFile: './dist/index.d.ts',
|
||||||
|
noCheck: false,
|
||||||
|
|
||||||
|
libraries: {
|
||||||
|
importedLibraries: ['node', '@types/node'],
|
||||||
|
inlinedLibraries: ['@fluencelabs/avm', '@fluencelabs/marine-js'],
|
||||||
|
},
|
||||||
|
|
||||||
|
output: commonOutputParams,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
@ -1,36 +1,25 @@
|
|||||||
{
|
{
|
||||||
"_1": "This should actually be named @fluencelabs/js-client.api. Naming it fluence-js is needed for backward compat w/ aqua compiler",
|
"name": "@fluencelabs/js-client.api",
|
||||||
"name": "@fluencelabs/fluence",
|
"version": "0.10.0",
|
||||||
"version": "0.60.0",
|
|
||||||
"description": "JS Client API",
|
"description": "JS Client API",
|
||||||
"main": "./dist/index.js",
|
|
||||||
"typings": "./dist/index.d.ts",
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10",
|
"node": ">=10",
|
||||||
"pnpm": ">=3"
|
"pnpm": ">=3"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"_2": "dist/internal/ export is needed for backward compat w/ aqua compiler",
|
"source": "src/index.js",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"umd:main": "dist/index.umd.js",
|
||||||
|
"module": "dist/index.mjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.js",
|
"require": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts"
|
"default": "./dist/index.modern.mjs"
|
||||||
},
|
|
||||||
"./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"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc"
|
"build": "microbundle --generateTypes false src/index.ts && dts-bundle-generator --config dtsbundle.cjs"
|
||||||
},
|
},
|
||||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
@ -38,5 +27,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/interfaces": "0.5.0"
|
"@fluencelabs/interfaces": "0.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {}
|
"devDependencies": {
|
||||||
|
"@fluencelabs/avm": "0.35.4",
|
||||||
|
"@fluencelabs/marine-js": "0.3.44",
|
||||||
|
"microbundle": "0.15.1",
|
||||||
|
"dts-bundle-generator": "7.2.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,36 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { FnConfig, FunctionCallDef, ServiceDef } from '@fluencelabs/interfaces/compilerSupport';
|
import type { FnConfig, FunctionCallDef, ServiceDef } from '@fluencelabs/interfaces';
|
||||||
import type { IFluenceClient } from '@fluencelabs/interfaces/fluenceClient';
|
import type { IFluenceClient } from '@fluencelabs/interfaces';
|
||||||
import { getArgumentTypes } from '@fluencelabs/interfaces/compilerSupport';
|
import { getArgumentTypes } from '@fluencelabs/interfaces';
|
||||||
import { isFluencePeer } from '@fluencelabs/interfaces/fluenceClient';
|
import { isFluencePeer } from '@fluencelabs/interfaces';
|
||||||
|
|
||||||
import { getDefaultPeer } from '../index.js';
|
import { getDefaultPeer } from '../util.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
|
* Convenience function to support Aqua `func` generation backend
|
||||||
@ -66,7 +42,6 @@ export const callFunction = async (rawFnArgs: Array<any>, def: FunctionCallDef,
|
|||||||
/**
|
/**
|
||||||
* Convenience function to support Aqua `service` generation backend
|
* 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
|
* 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 args - raw arguments passed by user to the generated function
|
||||||
* @param def - service definition generated by the Aqua compiler
|
* @param def - service definition generated by the Aqua compiler
|
||||||
*/
|
*/
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export { IFluenceClient } from './implementation.js';
|
|
||||||
export { CallParams as CallParams$$ } from './implementation.js';
|
|
||||||
export {
|
|
||||||
ArrayType as ArrayType$$,
|
|
||||||
ArrowType as ArrowType$$,
|
|
||||||
ArrowWithCallbacks as ArrowWithCallbacks$$,
|
|
||||||
ArrowWithoutCallbacks as ArrowWithoutCallbacks$$,
|
|
||||||
BottomType as BottomType$$,
|
|
||||||
FnConfig as FnConfig$$,
|
|
||||||
FunctionCallConstants as FunctionCallConstants$$,
|
|
||||||
FunctionCallDef as FunctionCallDef$$,
|
|
||||||
LabeledProductType as LabeledProductType$$,
|
|
||||||
NilType as NilType$$,
|
|
||||||
NonArrowType as NonArrowType$$,
|
|
||||||
OptionType as OptionType$$,
|
|
||||||
ProductType as ProductType$$,
|
|
||||||
ScalarNames as ScalarNames$$,
|
|
||||||
ScalarType as ScalarType$$,
|
|
||||||
ServiceDef as ServiceDef$$,
|
|
||||||
StructType as StructType$$,
|
|
||||||
TopType as TopType$$,
|
|
||||||
UnlabeledProductType as UnlabeledProductType$$,
|
|
||||||
callFunction as callFunction$$,
|
|
||||||
registerService as registerService$$,
|
|
||||||
} from './implementation.js';
|
|
@ -1,40 +1,33 @@
|
|||||||
import type { IFluenceClient, ClientOptions } from '@fluencelabs/interfaces/fluenceClient';
|
import { getDefaultPeer } from './util.js';
|
||||||
|
import type { IFluenceClient, ClientOptions } from '@fluencelabs/interfaces';
|
||||||
|
export type { IFluenceClient, ClientOptions, CallParams } from '@fluencelabs/interfaces';
|
||||||
|
|
||||||
export { IFluenceClient, ClientOptions, 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';
|
||||||
|
|
||||||
// TODO: hack needed to kinda have backward compat with compiler api
|
export {
|
||||||
export type FluencePeer = IFluenceClient;
|
callFunction as v5_callFunction,
|
||||||
|
registerService as v5_registerService,
|
||||||
const getPeerFromGlobalThis = (): IFluenceClient | undefined => {
|
} from './compilerSupport/implementation.js';
|
||||||
// @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
|
* Public interface to Fluence JS
|
||||||
|
41
packages/client/api/src/util.ts
Normal file
41
packages/client/api/src/util.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import type { IFluenceClient } from '@fluencelabs/interfaces';
|
||||||
|
|
||||||
|
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: ';
|
||||||
|
|
||||||
|
// Let's assume that if the library has not been loaded in 5 seconds, then the user has forgotten to add the script tag
|
||||||
|
const POLL_PEER_TIMEOUT = 5000;
|
||||||
|
|
||||||
|
// The script might be cached so need to try loading it ASAP, thus short interval
|
||||||
|
const POLL_PEER_INTERVAL = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) => {
|
||||||
|
// This function is internal
|
||||||
|
// Make it sure that would be zero way for unnecessary types
|
||||||
|
// to break out into the public API
|
||||||
|
let interval: any;
|
||||||
|
let hits = POLL_PEER_TIMEOUT / POLL_PEER_INTERVAL;
|
||||||
|
interval = setInterval(() => {
|
||||||
|
if (hits === 0) {
|
||||||
|
clearInterval(interval);
|
||||||
|
reject(REJECT_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = getPeerFromGlobalThis();
|
||||||
|
if (res) {
|
||||||
|
clearInterval(interval);
|
||||||
|
resolve(res);
|
||||||
|
}
|
||||||
|
hits--;
|
||||||
|
}, POLL_PEER_INTERVAL);
|
||||||
|
});
|
||||||
|
};
|
@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../../tsconfig.json",
|
"extends": "../../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./dist"
|
"outDir": "./dist",
|
||||||
|
"skipLibCheck": false
|
||||||
},
|
},
|
||||||
|
"include": ["./src/**/*"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/js-peer": "0.5.0",
|
"@fluencelabs/js-peer": "0.6.0",
|
||||||
"@fluencelabs/avm": "0.35.3",
|
"@fluencelabs/avm": "0.35.3",
|
||||||
"@fluencelabs/marine-js": "0.3.42",
|
"@fluencelabs/marine-js": "0.3.42",
|
||||||
"platform": "1.3.6"
|
"platform": "1.3.6"
|
||||||
|
@ -1,22 +1 @@
|
|||||||
# 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/
|
tmp/
|
||||||
|
|
||||||
dist
|
|
||||||
esm
|
|
||||||
types
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
.idea
|
|
||||||
|
@ -71,6 +71,7 @@ const buildClient = async () => {
|
|||||||
});
|
});
|
||||||
workerConfig.build!.rollupOptions = {
|
workerConfig.build!.rollupOptions = {
|
||||||
plugins: [
|
plugins: [
|
||||||
|
// @ts-ignore
|
||||||
inject.default({
|
inject.default({
|
||||||
Buffer: ['buffer', 'Buffer'],
|
Buffer: ['buffer', 'Buffer'],
|
||||||
process: 'process',
|
process: 'process',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@fluencelabs/js-client.web.standalone",
|
"name": "@fluencelabs/js-client.web.standalone",
|
||||||
"version": "0.1.0",
|
"version": "0.11.0",
|
||||||
"description": "TypeScript implementation of Fluence Peer",
|
"description": "TypeScript implementation of Fluence Peer",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"typings": "./dist/index.d.ts",
|
"typings": "./dist/index.d.ts",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/js-peer": "0.5.0",
|
"@fluencelabs/js-peer": "0.6.0",
|
||||||
"buffer": "6.0.3",
|
"buffer": "6.0.3",
|
||||||
"process": "0.11.10"
|
"process": "0.11.10"
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/js-peer": "workspace:0.60.0"
|
"@fluencelabs/js-peer": "0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "16.11.59",
|
"@types/node": "16.11.59",
|
||||||
|
@ -17,6 +17,14 @@
|
|||||||
"./compilerSupport": {
|
"./compilerSupport": {
|
||||||
"import": "./dist/compilerSupport.js",
|
"import": "./dist/compilerSupport.js",
|
||||||
"types": "./dist/compilerSupport.d.ts"
|
"types": "./dist/compilerSupport.d.ts"
|
||||||
|
},
|
||||||
|
"./dist/fluenceClient": {
|
||||||
|
"import": "./dist/fluenceClient.js",
|
||||||
|
"types": "./dist/fluenceClient.d.ts"
|
||||||
|
},
|
||||||
|
"./dist/compilerSupport": {
|
||||||
|
"import": "./dist/compilerSupport.js",
|
||||||
|
"types": "./dist/compilerSupport.d.ts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typesVersions": {
|
"typesVersions": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { SecurityTetraplet } from '@fluencelabs/avm';
|
import type { SecurityTetraplet } from '@fluencelabs/avm';
|
||||||
import type { LogLevel } from '@fluencelabs/marine-js/dist/types';
|
import type { LogLevel } from '@fluencelabs/marine-js/dist/types';
|
||||||
import type { MultiaddrInput } from '@multiformats/multiaddr';
|
// import type { MultiaddrInput } from '@multiformats/multiaddr';
|
||||||
import { FnConfig, FunctionCallDef, ServiceDef } from './compilerSupport.js';
|
import type { FnConfig, FunctionCallDef, ServiceDef } from './compilerSupport.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Peer ID's id as a base58 string (multihash/CIDv0).
|
* Peer ID's id as a base58 string (multihash/CIDv0).
|
||||||
@ -52,7 +52,8 @@ type Node = {
|
|||||||
multiaddr: string;
|
multiaddr: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RelayOptions = string | MultiaddrInput | Node;
|
// TODO: either drop support for this exact type or get it back
|
||||||
|
export type RelayOptions = string | /* MultiaddrInput | */ Node;
|
||||||
|
|
||||||
export type KeyTypes = 'RSA' | 'Ed25519' | 'secp256k1';
|
export type KeyTypes = 'RSA' | 'Ed25519' | 'secp256k1';
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@fluencelabs/js-peer",
|
"name": "@fluencelabs/js-peer",
|
||||||
"version": "0.5.0",
|
"version": "0.6.0",
|
||||||
"description": "TypeScript implementation of Fluence Peer",
|
"description": "TypeScript implementation of Fluence Peer",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"typings": "./dist/index.d.ts",
|
"typings": "./dist/index.d.ts",
|
||||||
|
876
pnpm-lock.yaml
generated
876
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user