Skip to content

Commit

Permalink
fix: to make WSClient not be exposed while creation
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Oct 16, 2023
1 parent 6265e3f commit d88bb2d
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/PolykeyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import path from 'path';
import Logger from '@matrixai/logger';
import { CreateDestroyStartStop } from '@matrixai/async-init/dist/CreateDestroyStartStop';
import { RPCClient } from '@matrixai/rpc';
import { WebSocketClient } from '@matrixai/ws';
import { middleware as rpcMiddleware } from '@matrixai/rpc';
import { WebSocketClient } from "@matrixai/ws";
import * as clientMiddleware from './client/middleware';
import { Session } from './sessions';
import * as utils from './utils';
Expand Down Expand Up @@ -35,20 +35,21 @@ interface PolykeyClient extends CreateDestroyStartStop {}
)
class PolykeyClient {
static async createPolykeyClient({
nodePath = config.defaultsUser.nodePath,
streamFactory,
streamKeepAliveTimeoutTime,
parserBufferByteLimit,
fs = require('fs'),
logger = new Logger(this.name),
fresh = false,
}: {
nodePath = config.defaultsUser.nodePath,
streamFactory,
streamKeepAliveTimeoutTime,
parserBufferByteLimit,
fs = require('fs'),
logger = new Logger(this.name),
fresh = false,
}: {
nodePath?: string;
streamFactory: StreamFactory;
streamKeepAliveTimeoutTime?: number;
parserBufferByteLimit?: number;
fs?: FileSystem;
logger?: Logger;
ws?: WebSocketClient
fresh?: boolean;
}): Promise<PolykeyClient> {
logger.info(`Creating ${this.name}`);
Expand All @@ -57,12 +58,12 @@ class PolykeyClient {
}
await utils.mkdirExists(fs, nodePath);
const sessionTokenPath = path.join(nodePath, config.paths.tokenBase);
const webSocketClient = new WebSocketClient();
const session = await Session.createSession({
sessionTokenPath,
logger: logger.getChild(Session.name),
fresh,
});
const ws: WebSocketClient = new WebSocketClient();
const rpcClientClient = new RPCClient({
manifest: clientClientManifest,
streamFactory,
Expand All @@ -77,7 +78,6 @@ class PolykeyClient {
const pkClient = new this({
nodePath,
rpcClientClient: rpcClientClient,
webSocketClient,
session,
fs,
logger,
Expand All @@ -90,31 +90,29 @@ class PolykeyClient {
public readonly nodePath: string;
public readonly session: Session;
public readonly rpcClientClient: RPCClient<typeof clientClientManifest>;
public readonly webSocketClient: WebSocketClient;

protected ws: WebSocketClient;
protected fs: FileSystem;
protected logger: Logger;

constructor({
nodePath,
rpcClientClient,
webSocketClient,
session,
fs,
logger,
}: {
nodePath,
rpcClientClient,
session,
fs,
logger,
}: {
nodePath: string;
rpcClientClient: RPCClient<typeof clientClientManifest>;
webSocketClient: WebSocketClient;
session: Session;
fs: FileSystem;
logger: Logger;
}) {
this.ws = new WebSocketClient();
this.logger = logger;
this.nodePath = nodePath;
this.session = session;
this.rpcClientClient = rpcClientClient;
this.webSocketClient = webSocketClient;
this.fs = fs;
}

Expand Down

0 comments on commit d88bb2d

Please sign in to comment.