这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"license-header",
"unused-imports"
],
"ignorePatterns": ["**/node_modules/**/*", "**/dist/**/*"],
"ignorePatterns": ["**/node_modules/", "**/dist/", "**/build/", "**/public/"],
"rules": {
"eqeqeq": [
"error",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules/

# Build directory
**/dist
**/public
13 changes: 7 additions & 6 deletions packages/@tests/smoke/web-cra-ts/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { fileURLToPath } from "url";

import {
CDN_PUBLIC_PATH,
createSymlinkIfNotExists,
JS_CLIENT_DEPS_PATH,
startContentServer,
stopServer,
} from "@test/test-utils";
import { access, symlink } from "fs/promises";

const port = 3001;
const uri = `http://localhost:${port}/`;
Expand All @@ -16,11 +17,11 @@ const publicPath = join(__dirname, "../build/");

const test = async () => {
const localServer = await startContentServer(port, publicPath);
try {
await access(join(publicPath, "source"));
} catch {
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
}
await createSymlinkIfNotExists(CDN_PUBLIC_PATH, join(publicPath, "source"));
await createSymlinkIfNotExists(
JS_CLIENT_DEPS_PATH,
join(publicPath, "node_modules"),
);

console.log("starting puppeteer...");
const browser = await puppeteer.launch();
Expand Down
4 changes: 3 additions & 1 deletion packages/@tests/smoke/web/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ const getRelayTime = () => {

const main = async () => {
console.log("starting fluence...");
fluence.defaultClient = await fluence.clientFactory(relay, {});
fluence.defaultClient = await fluence.clientFactory(relay, {
CDNUrl: "http://localhost:3000",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will URL be reported in an error, if it is not available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will give you runtime error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS-client will throw when you try to run it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the error message include URL? I think it should

});
console.log("started fluence");

console.log("getting relay time...");
Expand Down
14 changes: 8 additions & 6 deletions packages/@tests/smoke/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import { symlink, access } from "fs/promises";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

import {
CDN_PUBLIC_PATH,
createSymlinkIfNotExists,
JS_CLIENT_DEPS_PATH,
startContentServer,
stopServer,
} from "@test/test-utils";
Expand All @@ -33,11 +34,12 @@ const publicPath = join(__dirname, "../public/");
const test = async () => {
const localServer = await startContentServer(port, publicPath);

try {
await access(join(publicPath, "source"));
} catch {
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
}
await createSymlinkIfNotExists(CDN_PUBLIC_PATH, join(publicPath, "source"));

await createSymlinkIfNotExists(
JS_CLIENT_DEPS_PATH,
join(publicPath, "node_modules"),
);

console.log("starting puppeteer...");
const browser = await puppeteer.launch();
Expand Down
33 changes: 33 additions & 0 deletions packages/@tests/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { access, symlink } from "fs/promises";
import { createServer } from "http";
import type { Server } from "http";
import { dirname, join } from "path";
Expand All @@ -28,10 +29,26 @@ export const CDN_PUBLIC_PATH = join(
"../../../core/js-client/dist/browser",
);

export const JS_CLIENT_DEPS_PATH = join(
__dirname,
"../../../core/js-client/node_modules",
);

export const startCdn = (port: number) => {
return startContentServer(port, CDN_PUBLIC_PATH);
};

export const createSymlinkIfNotExists = async (
target: string,
path: string,
) => {
try {
await access(path);
} catch {
await symlink(target, path);
}
};

export const startContentServer = (
port: number,
publicDir: string,
Expand All @@ -44,6 +61,22 @@ export const startContentServer = (
source: "/js-client.min.js",
destination: "/source/index.umd.cjs",
},
// TODO:
// something like this
// {
// source: "/@fluencelabs/:name(\\w+)@:version([\\d.]+)/:path*",
// destination: "/deps/@fluencelabs/:name/:path",
// }
// not supported for some reason. Need to manually iterate over all possible paths
{
source: "/@fluencelabs/:name([\\w-]+)@:version([\\d.]+)/dist/:asset",
destination: "/node_modules/@fluencelabs/:name/dist/:asset",
},
{
source:
"/@fluencelabs/:name([\\w-]+)@:version([\\d.]+)/dist/:prefix/:asset",
destination: "/node_modules/@fluencelabs/:name/dist/:prefix/:asset",
},
],
headers: [
{
Expand Down
8 changes: 0 additions & 8 deletions packages/core/interfaces/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ import { InterfaceToType, MaybePromise } from "./utils.js";
*/
export type PeerIdB58 = string;

/**
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
*/
export type Node = {
peerId: PeerIdB58;
multiaddr: string;
};

/**
* Additional information about a service call
* @typeparam ArgName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { JSONValue } from "../commonTypes.js";
import { IFluenceInternalApi } from "../fluenceClient.js";

import {
FnConfig,
Expand All @@ -38,11 +37,12 @@ export type PassedArgs = { [key: string]: JSONValue | ArgCallbackFunction };
/**
* Arguments for callAquaFunction function
*/
// TODO: move to js-client side
export interface CallAquaFunctionArgs {
/**
* Peer to call the function on
*/
peer: IFluenceInternalApi;
peer: unknown;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a little weird

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be refactored and moved to JS-client. Previous type was essentially the same. I will add TODO to remember this.


/**
* Function definition
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface RegisterServiceArgs {
/**
* Peer to register the service on
*/
peer: IFluenceInternalApi;
peer: unknown;

/**
* Service definition
Expand Down
1 change: 0 additions & 1 deletion packages/core/interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
export * from "./compilerSupport/aquaTypeDefinitions.js";
export * from "./compilerSupport/compilerSupportInterface.js";
export * from "./commonTypes.js";
export * from "./fluenceClient.js";
export * from "./future.js";
14 changes: 7 additions & 7 deletions packages/core/js-client/src/clientPeer/ClientPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
* limitations under the License.
*/

import {
ClientConfig,
ConnectionState,
IFluenceClient,
RelayOptions,
} from "@fluencelabs/interfaces";

import {
RelayConnection,
RelayConnectionConfig,
Expand All @@ -32,6 +25,13 @@ import { IMarineHost } from "../marine/interfaces.js";
import { relayOptionToMultiaddr } from "../util/libp2pUtils.js";
import { logger } from "../util/logger.js";

import {
ClientConfig,
IFluenceClient,
ConnectionState,
RelayOptions,
} from "./types.js";

const log = logger("client");

const DEFAULT_TTL_MS = 7000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
* limitations under the License.
*/

import type { Node } from "./commonTypes.js";
/**
* Peer ID's id as a base58 string (multihash/CIDv0).
*/
export type PeerIdB58 = string;

/**
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
*/
export type Node = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename since it's private now? like, Peer or something

peerId: PeerIdB58;
multiaddr: string;
};

/**
* A node in Fluence network a client can connect to.
Expand All @@ -37,64 +48,6 @@ export type KeyPairOptions = {
source: "random" | Uint8Array;
};

/**
* Configuration used when initiating Fluence Client
*/
export interface ClientConfig {
/**
* Specify the KeyPair to be used to identify the Fluence Peer.
* Will be generated randomly if not specified
*/
keyPair?: KeyPairOptions;

/**
* Options to configure the connection to the Fluence network
*/
connectionOptions?: {
/**
* When the peer established the connection to the network it sends a ping-like message to check if it works correctly.
* The options allows to specify the timeout for that message in milliseconds.
* If not specified the default timeout will be used
*/
skipCheckConnection?: boolean;

/**
* The dialing timeout in milliseconds
*/
dialTimeoutMs?: number;

/**
* The maximum number of inbound streams for the libp2p node.
* Default: 1024
*/
maxInboundStreams?: number;

/**
* The maximum number of outbound streams for the libp2p node.
* Default: 1024
*/
maxOutboundStreams?: number;
};

/**
* Sets the default TTL for all particles originating from the peer with no TTL specified.
* If the originating particle's TTL is defined then that value will be used
* If the option is not set default TTL will be 7000
*/
defaultTtlMs?: number;

/**
* Enables\disabled various debugging features
*/
debug?: {
/**
* If set to true, newly initiated particle ids will be printed to console.
* Useful to see what particle id is responsible for aqua function
*/
printParticleId?: boolean;
};
}

/**
* Fluence JS Client connection states as string literals
*/
Expand Down Expand Up @@ -153,3 +106,66 @@ export interface IFluenceClient extends IFluenceInternalApi {
*/
getRelayPeerId(): string;
}

/**
* Configuration used when initiating Fluence Client
*/
export interface ClientConfig {
/**
* Specify the KeyPair to be used to identify the Fluence Peer.
* Will be generated randomly if not specified
*/
keyPair?: KeyPairOptions;

/**
* Options to configure the connection to the Fluence network
*/
connectionOptions?: {
/**
* When the peer established the connection to the network it sends a ping-like message to check if it works correctly.
* The options allows to specify the timeout for that message in milliseconds.
* If not specified the default timeout will be used
*/
skipCheckConnection?: boolean;

/**
* The dialing timeout in milliseconds
*/
dialTimeoutMs?: number;

/**
* The maximum number of inbound streams for the libp2p node.
* Default: 1024
*/
maxInboundStreams?: number;

/**
* The maximum number of outbound streams for the libp2p node.
* Default: 1024
*/
maxOutboundStreams?: number;
};

/**
* Sets the default TTL for all particles originating from the peer with no TTL specified.
* If the originating particle's TTL is defined then that value will be used
* If the option is not set default TTL will be 7000
*/
defaultTtlMs?: number;

/**
* Property for passing custom CDN Url to load dependencies from browser. https://unpkg.com used by default
*/
CDNUrl?: string;

/**
* Enables\disabled various debugging features
*/
debug?: {
/**
* If set to true, newly initiated particle ids will be printed to console.
* Useful to see what particle id is responsible for aqua function
*/
printParticleId?: boolean;
};
}
Loading