mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-29 07:41:35 +00:00
feat!: Unify all packages (#327)
* * Separate marine worker as a package * Trying to fix tests * Finalizing test fixes * fix: rename back to Fluence CLI (#320) chore: rename back to Fluence CLI * fix(deps): update dependency @fluencelabs/avm to v0.43.1 (#322) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore: release master (#324) * chore: release master * chore: Regenerate pnpm lock file * feat: use marine-js 0.7.2 (#321) * use marine-js 0.5.0 * increace some timeouts * increace some timeouts * use latest marine + remove larger timeouts * propagate CallParameters type * use marine 0.7.2 * Temp use node 18 and 20 * Comment out node 20.x --------- Co-authored-by: Anatoly Laskaris <github_me@nahsi.dev> * chore: Fix test with node 18/20 error message (#323) * Fix test with node 18/20 error message * Run tests on node 18 and 20 * Enhance description * Fix type and obj property --------- Co-authored-by: Anatoly Laskaris <github_me@nahsi.dev> * * Separate marine worker as a package * Trying to fix tests * Finalizing test fixes * * Refactoring packages. * Using CDN to load .wasm deps. * Setting up tests for new architecture * Fix almost all tests * Fix last strange test * Remove package specific packages * Remove avm class as it looks excessive * marine worker new version * misc refactoring/remove console.log's * Rename package js-peer to js-client * Move service info to marine worker * Change CDN path * Fix worker race confition * Remove buffer type * Remove turned off headless mode in platform tests * Remove async keyword to make tests pass * Remove util package * Make js-client.api package just reexport interface from js-client main package * Update package info in CI * Fix review comments * Remove test entry from marine-worker package * Misc fixes * Fix worker type * Add fetchers * Specify correct versions for js-client package * Set first ver for js-client * Update libp2p and related dep versions to the latest * Build all deps into package itself * Fix review * Refine package * Fix comment * Update packages/core/js-client/src/fetchers/browser.ts * Update packages/core/js-client/src/fetchers/index.ts * Update packages/core/js-client/src/fetchers/node.ts * Update packages/core/js-client/src/jsPeer/FluencePeer.ts * Update packages/core/js-client/src/keypair/__test__/KeyPair.spec.ts * Update packages/core/js-client/src/jsPeer/FluencePeer.ts Co-authored-by: shamsartem <shamsartem@gmail.com> * Delete outdated file * Need types for build to work * Inline func call * Add comments to replacement lines. P.S. we can remove some of them after update libp2p --------- Co-authored-by: shamsartem <shamsartem@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: fluencebot <116741523+fluencebot@users.noreply.github.com> Co-authored-by: Valery Antopol <valery.antopol@gmail.com> Co-authored-by: Anatoly Laskaris <github_me@nahsi.dev>
This commit is contained in:
@ -2,6 +2,11 @@
|
||||
|
||||
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
|
||||
|
||||
## Notes
|
||||
|
||||
This package just reexports everything from main library for backward compatibility
|
||||
`export * from '@fluencelabs/js-client';`
|
||||
|
||||
## Contributing
|
||||
|
||||
While the project is still in the early stages of development, you are welcome to track progress and contribute. As the project is undergoing rapid changes, interested contributors should contact the team before embarking on larger pieces of work. All contributors should consult with and agree to our [basic contributing rules](CONTRIBUTING.md).
|
||||
|
@ -24,13 +24,14 @@
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/interfaces": "0.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/avm": "0.43.1",
|
||||
"@fluencelabs/interfaces": "workspace:*",
|
||||
"@fluencelabs/marine-js": "0.7.2",
|
||||
"microbundle": "0.15.1",
|
||||
"dts-bundle-generator": "7.2.0"
|
||||
"dts-bundle-generator": "7.2.0",
|
||||
"microbundle": "0.15.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "0.0.10"
|
||||
}
|
||||
}
|
||||
|
@ -1,178 +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.
|
||||
*/
|
||||
|
||||
import type { FnConfig, FunctionCallDef, ServiceDef } from '@fluencelabs/interfaces';
|
||||
import type { IFluenceClient } from '@fluencelabs/interfaces';
|
||||
import { getArgumentTypes } from '@fluencelabs/interfaces';
|
||||
import { isFluencePeer } from '@fluencelabs/interfaces';
|
||||
|
||||
import { getFluenceInterface } from '../util.js';
|
||||
|
||||
/**
|
||||
* 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 v5_callFunction = async (
|
||||
rawFnArgs: Array<any>,
|
||||
def: FunctionCallDef,
|
||||
script: string,
|
||||
): Promise<unknown> => {
|
||||
const { args, client: peer, config } = await extractFunctionArgs(rawFnArgs, def);
|
||||
|
||||
const fluence = await getFluenceInterface();
|
||||
return fluence.callAquaFunction({
|
||||
args,
|
||||
def,
|
||||
script,
|
||||
config: config || {},
|
||||
peer: peer,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 v5_registerService = async (args: any[], def: ServiceDef): Promise<unknown> => {
|
||||
const { peer, service, serviceId } = await extractServiceArgs(args, def.defaultServiceId);
|
||||
|
||||
const fluence = await getFluenceInterface();
|
||||
return fluence.registerService({
|
||||
def,
|
||||
service,
|
||||
serviceId,
|
||||
peer,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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<{
|
||||
client: 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 {
|
||||
const fluence = await getFluenceInterface();
|
||||
if (!fluence.defaultClient) {
|
||||
throw new Error(
|
||||
'Could not register Aqua service because the client is not initialized. Did you forget to call Fluence.connect()?',
|
||||
);
|
||||
}
|
||||
peer = fluence.defaultClient;
|
||||
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 {
|
||||
client: 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 {
|
||||
const fluence = await getFluenceInterface();
|
||||
if (!fluence.defaultClient) {
|
||||
throw new Error(
|
||||
'Could not register Aqua service because the client is not initialized. Did you forget to call Fluence.connect()?',
|
||||
);
|
||||
}
|
||||
peer = fluence.defaultClient;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
};
|
@ -13,120 +13,5 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { getFluenceInterface, getFluenceInterfaceFromGlobalThis } from './util.js';
|
||||
import {
|
||||
IFluenceClient,
|
||||
ClientConfig,
|
||||
RelayOptions,
|
||||
ConnectionState,
|
||||
CallAquaFunctionType,
|
||||
RegisterServiceType,
|
||||
} from '@fluencelabs/interfaces';
|
||||
export type { IFluenceClient, ClientConfig, CallParams } from '@fluencelabs/interfaces';
|
||||
|
||||
export {
|
||||
ArrayType,
|
||||
ArrowType,
|
||||
ArrowWithCallbacks,
|
||||
ArrowWithoutCallbacks,
|
||||
BottomType,
|
||||
FunctionCallConstants,
|
||||
FunctionCallDef,
|
||||
LabeledProductType,
|
||||
NilType,
|
||||
NonArrowType,
|
||||
OptionType,
|
||||
ProductType,
|
||||
ScalarNames,
|
||||
ScalarType,
|
||||
ServiceDef,
|
||||
StructType,
|
||||
TopType,
|
||||
UnlabeledProductType,
|
||||
CallAquaFunctionType,
|
||||
CallAquaFunctionArgs,
|
||||
PassedArgs,
|
||||
FnConfig,
|
||||
RegisterServiceType,
|
||||
RegisterServiceArgs,
|
||||
} from '@fluencelabs/interfaces';
|
||||
|
||||
export { v5_callFunction, v5_registerService } from './compilerSupport/implementation.js';
|
||||
|
||||
/**
|
||||
* Public interface to Fluence Network
|
||||
*/
|
||||
export const Fluence = {
|
||||
/**
|
||||
* Connect to the Fluence network
|
||||
* @param relay - relay node to connect to
|
||||
* @param config - client configuration
|
||||
*/
|
||||
connect: async (relay: RelayOptions, config?: ClientConfig): Promise<void> => {
|
||||
const fluence = await getFluenceInterface();
|
||||
const client = await fluence.clientFactory(relay, config);
|
||||
fluence.defaultClient = client;
|
||||
},
|
||||
|
||||
/**
|
||||
* Disconnect from the Fluence network
|
||||
*/
|
||||
disconnect: async (): Promise<void> => {
|
||||
const fluence = await getFluenceInterface();
|
||||
await fluence.defaultClient?.disconnect();
|
||||
fluence.defaultClient = undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle connection state changes. Immediately returns the current connection state
|
||||
*/
|
||||
onConnectionStateChange(handler: (state: ConnectionState) => void): ConnectionState {
|
||||
const optimisticResult = getFluenceInterfaceFromGlobalThis();
|
||||
if (optimisticResult && optimisticResult.defaultClient) {
|
||||
return optimisticResult.defaultClient.onConnectionStateChange(handler);
|
||||
}
|
||||
|
||||
getFluenceInterface().then((fluence) => {
|
||||
fluence.defaultClient?.onConnectionStateChange(handler);
|
||||
});
|
||||
|
||||
return 'disconnected';
|
||||
},
|
||||
|
||||
/**
|
||||
* Low level API. Get the underlying client instance which holds the connection to the network
|
||||
* @returns IFluenceClient instance
|
||||
*/
|
||||
getClient: async (): Promise<IFluenceClient> => {
|
||||
const fluence = await getFluenceInterface();
|
||||
if (!fluence.defaultClient) {
|
||||
throw new Error('Fluence client is not initialized. Call Fluence.connect() first');
|
||||
}
|
||||
return fluence.defaultClient;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Low level API. Generally you need Fluence.connect() instead.
|
||||
* @returns IFluenceClient instance
|
||||
*/
|
||||
export const createClient = async (relay: RelayOptions, config?: ClientConfig): Promise<IFluenceClient> => {
|
||||
const fluence = await getFluenceInterface();
|
||||
return await fluence.clientFactory(relay, config);
|
||||
};
|
||||
|
||||
/**
|
||||
* Low level API. Generally you should use code generated by the Aqua compiler.
|
||||
*/
|
||||
export const callAquaFunction: CallAquaFunctionType = async (args) => {
|
||||
const fluence = await getFluenceInterface();
|
||||
return await fluence.callAquaFunction(args);
|
||||
};
|
||||
|
||||
/**
|
||||
* Low level API. Generally you should use code generated by the Aqua compiler.
|
||||
*/
|
||||
export const registerService: RegisterServiceType = async (args) => {
|
||||
const fluence = await getFluenceInterface();
|
||||
return await fluence.registerService(args);
|
||||
};
|
||||
export * from '@fluencelabs/js-client';
|
||||
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 {
|
||||
CallAquaFunctionType,
|
||||
ClientConfig,
|
||||
IFluenceClient,
|
||||
RegisterServiceType,
|
||||
RelayOptions,
|
||||
} from '@fluencelabs/interfaces';
|
||||
|
||||
type PublicFluenceInterface = {
|
||||
defaultClient: IFluenceClient | undefined;
|
||||
clientFactory: (relay: RelayOptions, config?: ClientConfig) => Promise<IFluenceClient>;
|
||||
callAquaFunction: CallAquaFunctionType;
|
||||
registerService: RegisterServiceType;
|
||||
};
|
||||
|
||||
export const getFluenceInterfaceFromGlobalThis = (): PublicFluenceInterface | undefined => {
|
||||
// @ts-ignore
|
||||
return globalThis.fluence;
|
||||
};
|
||||
|
||||
// TODO: fix link DXJ-271
|
||||
const REJECT_MESSAGE = `Could not load Fluence JS Client library.
|
||||
If you are using Node.js that probably means that you forgot in install or import the @fluencelabs/js-client.node package.
|
||||
If you are using a browser, then you probably forgot to add the <script> tag to your HTML.
|
||||
Please refer to the documentation page for more details: https://fluence.dev/docs/build/js-client/installation
|
||||
`;
|
||||
|
||||
// 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 getFluenceInterface = (): Promise<PublicFluenceInterface> => {
|
||||
// If the script is already loaded, then return the value immediately
|
||||
const optimisticResult = getFluenceInterfaceFromGlobalThis();
|
||||
if (optimisticResult) {
|
||||
return Promise.resolve(optimisticResult);
|
||||
}
|
||||
|
||||
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 = getFluenceInterfaceFromGlobalThis();
|
||||
if (res) {
|
||||
clearInterval(interval);
|
||||
resolve(res);
|
||||
}
|
||||
hits--;
|
||||
}, POLL_PEER_INTERVAL);
|
||||
});
|
||||
};
|
21
packages/client/js-client.node/.gitignore
vendored
21
packages/client/js-client.node/.gitignore
vendored
@ -1,21 +0,0 @@
|
||||
# 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
|
||||
esm
|
||||
types
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
@ -1,169 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.1 to 0.8.2
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.3 to 0.8.4
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.4 to 0.8.5
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.7 to 0.8.8
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.8 to 0.8.9
|
||||
|
||||
## [0.7.1](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.7.0...js-client.node-v0.7.1) (2023-08-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency @fluencelabs/avm to v0.43.1 ([#322](https://github.com/fluencelabs/js-client/issues/322)) ([c1d1fa6](https://github.com/fluencelabs/js-client/commit/c1d1fa6659b6dc2c6707786748b3410fab7f1bcd))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.9.0 to 0.9.1
|
||||
* @fluencelabs/interfaces bumped from 0.8.0 to 0.8.1
|
||||
|
||||
## [0.7.0](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.11...js-client.node-v0.7.0) (2023-06-29)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* **avm:** avm 0.40.0 (https://github.com/fluencelabs/js-client/pull/315)
|
||||
|
||||
### Features
|
||||
|
||||
* **avm:** avm 0.40.0 (https://github.com/fluencelabs/js-client/pull/315) ([8bae6e2](https://github.com/fluencelabs/js-client/commit/8bae6e24e62153b567f320ccecc7bce76bc826d1))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.10 to 0.9.0
|
||||
* @fluencelabs/interfaces bumped from 0.7.6 to 0.8.0
|
||||
|
||||
## [0.6.11](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.10...js-client.node-v0.6.11) (2023-06-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support signatures [fixes DXJ-389] ([#310](https://github.com/fluencelabs/js-client/issues/310)) ([a60dfe0](https://github.com/fluencelabs/js-client/commit/a60dfe0d680b4d9ac5092dec64e2ebf478bf80eb))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.9 to 0.8.10
|
||||
* @fluencelabs/interfaces bumped from 0.7.5 to 0.7.6
|
||||
|
||||
## [0.6.8](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.7...js-client.node-v0.6.8) (2023-04-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Cleaning up technical debts ([#295](https://github.com/fluencelabs/js-client/issues/295)) ([0b2f12d](https://github.com/fluencelabs/js-client/commit/0b2f12d8ac223db341d6c30ff403166b3eae2e56))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.6 to 0.8.7
|
||||
* @fluencelabs/interfaces bumped from 0.7.4 to 0.7.5
|
||||
|
||||
## [0.6.7](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.6...js-client.node-v0.6.7) (2023-03-31)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **logs:** Use `debug.js` library for logging [DXJ-327] ([#285](https://github.com/fluencelabs/js-client/issues/285)) ([e95c34a](https://github.com/fluencelabs/js-client/commit/e95c34a79220bd8ecdcee806802ac3d69a2af0cb))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.5 to 0.8.6
|
||||
|
||||
## [0.6.4](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.3...js-client.node-v0.6.4) (2023-02-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Add .npmignore to js-client.node ([#264](https://github.com/fluencelabs/js-client/issues/264)) ([a899a53](https://github.com/fluencelabs/js-client/commit/a899a531fdfd855268ba47170ace9e281b53f0fd))
|
||||
|
||||
## [0.6.3](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.2...js-client.node-v0.6.3) (2023-02-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Trigger release to publish packages that were built ([#262](https://github.com/fluencelabs/js-client/issues/262)) ([47abf38](https://github.com/fluencelabs/js-client/commit/47abf3882956ffbdc52df372db26ba6252e8306b))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.2 to 0.8.3
|
||||
|
||||
## [0.6.1](https://github.com/fluencelabs/js-client/compare/js-client.node-v0.6.0...js-client.node-v0.6.1) (2023-02-16)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Simplify JS Client public API ([#257](https://github.com/fluencelabs/js-client/issues/257)) ([9daaf41](https://github.com/fluencelabs/js-client/commit/9daaf410964d43228192c829c7ff785db6e88081))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.0 to 0.8.1
|
||||
|
||||
## [0.6.0](https://github.com/fluencelabs/fluence-js/compare/js-client.node-v0.5.0...js-client.node-v0.6.0) (2023-02-15)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* Expose updated JS Client API via `js-client.api` package ([#246](https://github.com/fluencelabs/fluence-js/issues/246))
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/fluence-js/issues/243))
|
||||
|
||||
### Features
|
||||
|
||||
* Expose updated JS Client API via `js-client.api` package ([#246](https://github.com/fluencelabs/fluence-js/issues/246)) ([d4bb8fb](https://github.com/fluencelabs/fluence-js/commit/d4bb8fb42964b3ba25154232980b9ae82c21e627))
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/fluence-js/issues/243)) ([9667c4f](https://github.com/fluencelabs/fluence-js/commit/9667c4fec6868f984bba13249f3c47d293396406))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* NodeJS package building ([#248](https://github.com/fluencelabs/fluence-js/issues/248)) ([0d05e51](https://github.com/fluencelabs/fluence-js/commit/0d05e517d89529af513fcb96cfa6c722ccc357a7))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.7.0 to 0.8.0
|
@ -1,11 +0,0 @@
|
||||
# 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
|
||||
|
||||
## Contributing
|
||||
|
||||
While the project is still in the early stages of development, you are welcome to track progress and contribute. As the project is undergoing rapid changes, interested contributors should contact the team before embarking on larger pieces of work. All contributors should consult with and agree to our [basic contributing rules](CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
[Apache 2.0](LICENSE)
|
@ -1,34 +0,0 @@
|
||||
{
|
||||
"name": "@fluencelabs/js-client.node",
|
||||
"version": "0.7.1",
|
||||
"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.9.1",
|
||||
"@fluencelabs/interfaces": "0.8.1",
|
||||
"@fluencelabs/avm": "0.43.1",
|
||||
"@fluencelabs/marine-js": "0.7.2",
|
||||
"platform": "1.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/platform": "1.3.4"
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 * as platform from 'platform';
|
||||
|
||||
import type { RelayOptions, ClientConfig, IFluenceClient } from '@fluencelabs/interfaces';
|
||||
import { ClientPeer, makeClientPeerConfig } from '@fluencelabs/js-peer/dist/clientPeer/ClientPeer.js';
|
||||
import { callAquaFunction } from '@fluencelabs/js-peer/dist/compilerSupport/callFunction.js';
|
||||
import { registerService } from '@fluencelabs/js-peer/dist/compilerSupport/registerService.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/jsPeer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker/index.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';
|
||||
import { doRegisterNodeUtils } from '@fluencelabs/js-peer/dist/services/NodeUtils.js';
|
||||
|
||||
throwIfNotSupported();
|
||||
|
||||
export const defaultNames = {
|
||||
avm: {
|
||||
file: 'avm.wasm',
|
||||
package: '@fluencelabs/avm',
|
||||
},
|
||||
marine: {
|
||||
file: 'marine-js.wasm',
|
||||
package: '@fluencelabs/marine-js',
|
||||
},
|
||||
};
|
||||
|
||||
const createClient = async (relay: RelayOptions, config: ClientConfig): Promise<IFluenceClient> => {
|
||||
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);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader);
|
||||
const { keyPair, peerConfig, relayConfig } = await makeClientPeerConfig(relay, config);
|
||||
const client: IFluenceClient = new ClientPeer(peerConfig, relayConfig, keyPair, marine, avm);
|
||||
registerNodeOnlyServices(client);
|
||||
await client.connect();
|
||||
return client;
|
||||
};
|
||||
|
||||
function registerNodeOnlyServices(client: IFluenceClient) {
|
||||
doRegisterNodeUtils(client);
|
||||
}
|
||||
|
||||
const publicFluenceInterface = {
|
||||
clientFactory: createClient,
|
||||
callAquaFunction,
|
||||
registerService,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.fluence = publicFluenceInterface;
|
||||
|
||||
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(
|
||||
'Fluence JS Client 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"',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
@ -1 +0,0 @@
|
||||
tmp/
|
@ -1 +0,0 @@
|
||||
/dist/
|
@ -1,170 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.1 to 0.8.2
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.4 to 0.8.5
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.7 to 0.8.8
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.8 to 0.8.9
|
||||
|
||||
## [0.14.1](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.14.0...js-client.web.standalone-v0.14.1) (2023-08-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency @fluencelabs/avm to v0.43.1 ([#322](https://github.com/fluencelabs/js-client/issues/322)) ([c1d1fa6](https://github.com/fluencelabs/js-client/commit/c1d1fa6659b6dc2c6707786748b3410fab7f1bcd))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.9.0 to 0.9.1
|
||||
* @fluencelabs/interfaces bumped from 0.8.0 to 0.8.1
|
||||
|
||||
## [0.14.0](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.10...js-client.web.standalone-v0.14.0) (2023-06-29)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* **avm:** avm 0.40.0 (https://github.com/fluencelabs/js-client/pull/315)
|
||||
|
||||
### Features
|
||||
|
||||
* **avm:** avm 0.40.0 (https://github.com/fluencelabs/js-client/pull/315) ([8bae6e2](https://github.com/fluencelabs/js-client/commit/8bae6e24e62153b567f320ccecc7bce76bc826d1))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.10 to 0.9.0
|
||||
* @fluencelabs/interfaces bumped from 0.7.6 to 0.8.0
|
||||
|
||||
## [0.13.10](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.9...js-client.web.standalone-v0.13.10) (2023-06-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support signatures [fixes DXJ-389] ([#310](https://github.com/fluencelabs/js-client/issues/310)) ([a60dfe0](https://github.com/fluencelabs/js-client/commit/a60dfe0d680b4d9ac5092dec64e2ebf478bf80eb))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.9 to 0.8.10
|
||||
* @fluencelabs/interfaces bumped from 0.7.5 to 0.7.6
|
||||
|
||||
## [0.13.7](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.6...js-client.web.standalone-v0.13.7) (2023-04-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Cleaning up technical debts ([#295](https://github.com/fluencelabs/js-client/issues/295)) ([0b2f12d](https://github.com/fluencelabs/js-client/commit/0b2f12d8ac223db341d6c30ff403166b3eae2e56))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.6 to 0.8.7
|
||||
* @fluencelabs/interfaces bumped from 0.7.4 to 0.7.5
|
||||
|
||||
## [0.13.6](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.5...js-client.web.standalone-v0.13.6) (2023-03-31)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **logs:** Use `debug.js` library for logging [DXJ-327] ([#285](https://github.com/fluencelabs/js-client/issues/285)) ([e95c34a](https://github.com/fluencelabs/js-client/commit/e95c34a79220bd8ecdcee806802ac3d69a2af0cb))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.5 to 0.8.6
|
||||
|
||||
## [0.13.4](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.3...js-client.web.standalone-v0.13.4) (2023-02-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* `nodenext` moduleResolution for js peer ([#271](https://github.com/fluencelabs/js-client/issues/271)) ([78d98f1](https://github.com/fluencelabs/js-client/commit/78d98f15c12431dee9fdd7b9869d57760503f8c7))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.3 to 0.8.4
|
||||
|
||||
## [0.13.3](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.2...js-client.web.standalone-v0.13.3) (2023-02-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Trigger release to publish packages that were built ([#262](https://github.com/fluencelabs/js-client/issues/262)) ([47abf38](https://github.com/fluencelabs/js-client/commit/47abf3882956ffbdc52df372db26ba6252e8306b))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.2 to 0.8.3
|
||||
|
||||
## [0.13.1](https://github.com/fluencelabs/js-client/compare/js-client.web.standalone-v0.13.0...js-client.web.standalone-v0.13.1) (2023-02-16)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Simplify JS Client public API ([#257](https://github.com/fluencelabs/js-client/issues/257)) ([9daaf41](https://github.com/fluencelabs/js-client/commit/9daaf410964d43228192c829c7ff785db6e88081))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.0 to 0.8.1
|
||||
|
||||
## [0.13.0](https://github.com/fluencelabs/fluence-js/compare/js-client.web.standalone-v0.12.0...js-client.web.standalone-v0.13.0) (2023-02-15)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* Expose updated JS Client API via `js-client.api` package ([#246](https://github.com/fluencelabs/fluence-js/issues/246))
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/fluence-js/issues/243))
|
||||
|
||||
### Features
|
||||
|
||||
* Expose updated JS Client API via `js-client.api` package ([#246](https://github.com/fluencelabs/fluence-js/issues/246)) ([d4bb8fb](https://github.com/fluencelabs/fluence-js/commit/d4bb8fb42964b3ba25154232980b9ae82c21e627))
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/fluence-js/issues/243)) ([9667c4f](https://github.com/fluencelabs/fluence-js/commit/9667c4fec6868f984bba13249f3c47d293396406))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* NodeJS package building ([#248](https://github.com/fluencelabs/fluence-js/issues/248)) ([0d05e51](https://github.com/fluencelabs/fluence-js/commit/0d05e517d89529af513fcb96cfa6c722ccc357a7))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.7.0 to 0.8.0
|
@ -1,11 +0,0 @@
|
||||
# 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
|
||||
|
||||
## Contributing
|
||||
|
||||
While the project is still in the early stages of development, you are welcome to track progress and contribute. As the project is undergoing rapid changes, interested contributors should contact the team before embarking on larger pieces of work. All contributors should consult with and agree to our [basic contributing rules](CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
[Apache 2.0](LICENSE)
|
@ -1,127 +0,0 @@
|
||||
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: [
|
||||
// @ts-ignore
|
||||
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));
|
@ -1,37 +0,0 @@
|
||||
{
|
||||
"name": "@fluencelabs/js-client.web.standalone",
|
||||
"version": "0.14.1",
|
||||
"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.9.1",
|
||||
"@fluencelabs/interfaces": "0.8.1",
|
||||
"buffer": "6.0.3",
|
||||
"process": "0.11.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/avm": "0.43.1",
|
||||
"@fluencelabs/marine-js": "0.7.2",
|
||||
"@types/node": "16.11.59",
|
||||
"@types/jest": "28.1.0",
|
||||
"jest": "28.1.0",
|
||||
"ts-jest": "28.0.2",
|
||||
"js-base64": "3.7.5",
|
||||
"@rollup/plugin-inject": "5.0.3",
|
||||
"vite-plugin-replace": "0.1.1",
|
||||
"vite": "4.0.4",
|
||||
"vite-tsconfig-paths": "4.0.3"
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 { RelayOptions, ClientConfig, IFluenceClient } from '@fluencelabs/interfaces';
|
||||
import { ClientPeer, makeClientPeerConfig } from '@fluencelabs/js-peer/dist/clientPeer/ClientPeer.js';
|
||||
import { callAquaFunction } from '@fluencelabs/js-peer/dist/compilerSupport/callFunction.js';
|
||||
import { registerService } from '@fluencelabs/js-peer/dist/compilerSupport/registerService.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/jsPeer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker/index.js';
|
||||
import { InlinedWorkerLoader, InlinedWasmLoader } from '@fluencelabs/js-peer/dist/marine/deps-loader/common.js';
|
||||
|
||||
const createClient = async (relay: RelayOptions, config: ClientConfig): Promise<IFluenceClient> => {
|
||||
const workerLoader = new InlinedWorkerLoader('___worker___');
|
||||
const controlModuleLoader = new InlinedWasmLoader('___marine___');
|
||||
const avmModuleLoader = new InlinedWasmLoader('___avm___');
|
||||
|
||||
const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader);
|
||||
const { keyPair, peerConfig, relayConfig } = await makeClientPeerConfig(relay, config);
|
||||
const client: IFluenceClient = new ClientPeer(peerConfig, relayConfig, keyPair, marine, avm);
|
||||
await client.connect();
|
||||
return client;
|
||||
};
|
||||
|
||||
const publicFluenceInterface = {
|
||||
clientFactory: createClient,
|
||||
callAquaFunction,
|
||||
registerService,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.fluence = publicFluenceInterface;
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
21
packages/client/js-client.web/.gitignore
vendored
21
packages/client/js-client.web/.gitignore
vendored
@ -1,21 +0,0 @@
|
||||
# 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
|
||||
esm
|
||||
types
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
@ -1,69 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.7 to 0.8.8
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.8 to 0.8.9
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.10 to 0.9.0
|
||||
* @fluencelabs/interfaces bumped from 0.7.6 to 0.8.0
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.9.0 to 0.9.1
|
||||
* @fluencelabs/interfaces bumped from 0.8.0 to 0.8.1
|
||||
|
||||
## [0.2.3](https://github.com/fluencelabs/js-client/compare/js-client.web-v0.2.2...js-client.web-v0.2.3) (2023-06-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support signatures [fixes DXJ-389] ([#310](https://github.com/fluencelabs/js-client/issues/310)) ([a60dfe0](https://github.com/fluencelabs/js-client/commit/a60dfe0d680b4d9ac5092dec64e2ebf478bf80eb))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.9 to 0.8.10
|
||||
* @fluencelabs/interfaces bumped from 0.7.5 to 0.7.6
|
||||
|
||||
## [0.2.0](https://github.com/fluencelabs/js-client/compare/js-client.web-v0.1.0...js-client.web-v0.2.0) (2023-04-04)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* Expose updated JS Client API via `js-client.api` package ([#246](https://github.com/fluencelabs/js-client/issues/246))
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/js-client/issues/243))
|
||||
|
||||
### Features
|
||||
|
||||
* Cleaning up technical debts ([#295](https://github.com/fluencelabs/js-client/issues/295)) ([0b2f12d](https://github.com/fluencelabs/js-client/commit/0b2f12d8ac223db341d6c30ff403166b3eae2e56))
|
||||
* Expose updated JS Client API via `js-client.api` package ([#246](https://github.com/fluencelabs/js-client/issues/246)) ([d4bb8fb](https://github.com/fluencelabs/js-client/commit/d4bb8fb42964b3ba25154232980b9ae82c21e627))
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/js-client/issues/243)) ([9667c4f](https://github.com/fluencelabs/js-client/commit/9667c4fec6868f984bba13249f3c47d293396406))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* NodeJS package building ([#248](https://github.com/fluencelabs/js-client/issues/248)) ([0d05e51](https://github.com/fluencelabs/js-client/commit/0d05e517d89529af513fcb96cfa6c722ccc357a7))
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
* The following workspace dependencies were updated
|
||||
* dependencies
|
||||
* @fluencelabs/js-peer bumped from 0.8.6 to 0.8.7
|
||||
* @fluencelabs/interfaces bumped from 0.7.4 to 0.7.5
|
@ -1,11 +0,0 @@
|
||||
# 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
|
||||
|
||||
## Contributing
|
||||
|
||||
While the project is still in the early stages of development, you are welcome to track progress and contribute. As the project is undergoing rapid changes, interested contributors should contact the team before embarking on larger pieces of work. All contributors should consult with and agree to our [basic contributing rules](CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
[Apache 2.0](LICENSE)
|
@ -1,28 +0,0 @@
|
||||
{
|
||||
"name": "@fluencelabs/js-client.web",
|
||||
"version": "0.2.5",
|
||||
"description": "TypeScript implementation of Fluence Peer",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-peer": "0.9.1",
|
||||
"@fluencelabs/interfaces": "0.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "16.11.59",
|
||||
"@types/jest": "28.1.0",
|
||||
"jest": "28.1.0",
|
||||
"ts-jest": "28.0.2"
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 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 { RelayOptions, ClientConfig, IFluenceClient } from '@fluencelabs/interfaces';
|
||||
import { ClientPeer, makeClientPeerConfig } from '@fluencelabs/js-peer/dist/clientPeer/ClientPeer.js';
|
||||
import { callAquaFunction } from '@fluencelabs/js-peer/dist/compilerSupport/callFunction.js';
|
||||
import { registerService } from '@fluencelabs/js-peer/dist/compilerSupport/registerService.js';
|
||||
import { MarineBasedAvmRunner } from '@fluencelabs/js-peer/dist/jsPeer/avm.js';
|
||||
import { MarineBackgroundRunner } from '@fluencelabs/js-peer/dist/marine/worker/index.js';
|
||||
import { WasmLoaderFromUrl, WorkerLoaderFromUrl } from '@fluencelabs/js-peer/dist/marine/deps-loader/web.js';
|
||||
|
||||
const defaultNames = {
|
||||
marine: 'marine-js.wasm',
|
||||
avm: 'avm.wasm',
|
||||
worker: 'worker-script.js',
|
||||
};
|
||||
|
||||
const createClient = async (relay: RelayOptions, config: ClientConfig): Promise<IFluenceClient> => {
|
||||
const workerLoader = new WorkerLoaderFromUrl(defaultNames.worker);
|
||||
const controlModuleLoader = new WasmLoaderFromUrl(defaultNames.marine);
|
||||
const avmModuleLoader = new WasmLoaderFromUrl(defaultNames.avm);
|
||||
|
||||
const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader);
|
||||
const avm = new MarineBasedAvmRunner(marine, avmModuleLoader);
|
||||
const { keyPair, peerConfig, relayConfig } = await makeClientPeerConfig(relay, config);
|
||||
const client: IFluenceClient = new ClientPeer(peerConfig, relayConfig, keyPair, marine, avm);
|
||||
await client.connect();
|
||||
return client;
|
||||
};
|
||||
|
||||
const publicFluenceInterface = {
|
||||
clientFactory: createClient,
|
||||
callAquaFunction,
|
||||
registerService,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.fluence = publicFluenceInterface;
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
21
packages/client/tools/.gitignore
vendored
21
packages/client/tools/.gitignore
vendored
@ -1,21 +0,0 @@
|
||||
# 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
|
||||
esm
|
||||
types
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
.idea
|
@ -1,12 +0,0 @@
|
||||
.idea
|
||||
.gitignore
|
||||
node_modules
|
||||
types
|
||||
|
||||
src/
|
||||
|
||||
tsconfig.json
|
||||
webpack.config.js
|
||||
|
||||
bundle
|
||||
pkg
|
@ -1 +0,0 @@
|
||||
/dist/
|
@ -1,19 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## [0.2.1](https://github.com/fluencelabs/js-client/compare/tools-v0.2.0...tools-v0.2.1) (2023-02-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Trigger release to publish packages that were built ([#262](https://github.com/fluencelabs/js-client/issues/262)) ([47abf38](https://github.com/fluencelabs/js-client/commit/47abf3882956ffbdc52df372db26ba6252e8306b))
|
||||
|
||||
## [0.2.0](https://github.com/fluencelabs/fluence-js/compare/tools-v0.1.0...tools-v0.2.0) (2023-02-15)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/fluence-js/issues/243))
|
||||
|
||||
### Features
|
||||
|
||||
* Standalone web JS Client ([#243](https://github.com/fluencelabs/fluence-js/issues/243)) ([9667c4f](https://github.com/fluencelabs/fluence-js/commit/9667c4fec6868f984bba13249f3c47d293396406))
|
@ -1,13 +0,0 @@
|
||||
## Contribute Code
|
||||
|
||||
You are welcome to contribute to Fluence.
|
||||
|
||||
Things you need to know:
|
||||
|
||||
1. You need to **agree to the Contributors License Agreement**. This is a common practice in all major Open Source projects. At the current moment we are unable to accept contributions made on behalf of a company. Only individual contributions will be accepted.
|
||||
2. **Not all proposed contributions can be accepted**. Some features may e.g. just fit a third-party add-on better. The contribution must fit the overall direction of Fluence and really improve it. The more effort you invest, the better you should clarify in advance whether the contribution fits: the best way would be to just open an issue to discuss the contribution you plan to make.
|
||||
|
||||
### Contributor License Agreement
|
||||
|
||||
When you contribute, you have to be aware that your contribution is covered by **Apache License 2.0**, but might relicensed under few other software licenses mentioned in the **Contributor License Agreement**.
|
||||
In particular you need to agree to the [Contributor License Agreement](https://gist.github.com/fluencelabs-org/3f4cbb3cc14c1c0fb9ad99d8f7316ed7). If you agree to its content, you simply have to click on the link posted by the CLA assistant as a comment to the pull request. Click it to check the CLA, then accept it on the following screen if you agree to it. CLA assistant will save this decision for upcoming contributions and will notify you if there is any change to the CLA in the meantime.
|
@ -1,11 +0,0 @@
|
||||
# Fluence JS Client tools
|
||||
|
||||
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
|
||||
|
||||
While the project is still in the early stages of development, you are welcome to track progress and contribute. As the project is undergoing rapid changes, interested contributors should contact the team before embarking on larger pieces of work. All contributors should consult with and agree to our [basic contributing rules](CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
[Apache 2.0](LICENSE)
|
@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "@fluencelabs/tools",
|
||||
"version": "0.2.1",
|
||||
"description": "Fluence JS Client tools",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"copy-marine": "dist/copyMarine.js"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/node": "16.11.59"
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#! /usr/bin/env node
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const firstArgument = process.argv[2];
|
||||
|
||||
if (!firstArgument) {
|
||||
console.log(`Expected exactly 1 argument, got 0. Usage: ${path.basename(process.argv[1])} <destination directory>`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let destPath = firstArgument;
|
||||
if (!path.isAbsolute(destPath)) {
|
||||
destPath = path.join(process.cwd(), destPath);
|
||||
}
|
||||
|
||||
async function copyFile(packageName: string, fileName: string) {
|
||||
const modulePath = require.resolve(packageName);
|
||||
const source = path.join(path.dirname(modulePath), fileName);
|
||||
const dest = path.join(destPath, fileName);
|
||||
|
||||
console.log(`copying ${fileName}`);
|
||||
console.log('from: ', source);
|
||||
console.log('to: ', dest);
|
||||
await fs.promises.copyFile(source, dest);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('ensure directory exists: ', destPath);
|
||||
await fs.promises.mkdir(destPath, { recursive: true });
|
||||
|
||||
await Promise.all([
|
||||
copyFile('@fluencelabs/marine.worker-script', 'marine-js.web.js'),
|
||||
copyFile('@fluencelabs/marine-js', 'marine-js.wasm'),
|
||||
copyFile('@fluencelabs/avm', 'avm.wasm'),
|
||||
]);
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
console.log('done!');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Something went wrong!', err);
|
||||
});
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
Reference in New Issue
Block a user