From f4ba1298ef486a3c988872b483d3be63ade587c5 Mon Sep 17 00:00:00 2001 From: tharvik Date: Mon, 12 Feb 2024 10:57:41 +0100 Subject: [PATCH] discojs-core: drop node:url --- discojs/discojs-core/package.json | 1 - discojs/discojs-core/src/client/base.ts | 2 +- discojs/discojs-core/src/client/decentralized/base.ts | 2 -- discojs/discojs-core/src/client/event_connection.ts | 6 +++--- discojs/discojs-core/src/client/federated/base.ts | 2 -- discojs/discojs-core/src/task/task_handler.ts | 2 +- discojs/discojs-web/tsconfig.json | 1 + discojs/tsconfig.base.json | 2 +- 8 files changed, 7 insertions(+), 11 deletions(-) diff --git a/discojs/discojs-core/package.json b/discojs/discojs-core/package.json index 7d62821e3..43e5443b1 100644 --- a/discojs/discojs-core/package.json +++ b/discojs/discojs-core/package.json @@ -29,7 +29,6 @@ "msgpack-lite": "0.1", "simple-peer": "9", "tslib": "2", - "url": "0.11", "ws": "8" }, "devDependencies": { diff --git a/discojs/discojs-core/src/client/base.ts b/discojs/discojs-core/src/client/base.ts index a0bed010d..40db0d18c 100644 --- a/discojs/discojs-core/src/client/base.ts +++ b/discojs/discojs-core/src/client/base.ts @@ -1,5 +1,5 @@ -import { Set } from 'immutable' import axios from 'axios' +import { Set } from 'immutable' import { tf, Task, TrainingInformant, serialization, WeightsContainer } from '..' import { NodeID } from './types' diff --git a/discojs/discojs-core/src/client/decentralized/base.ts b/discojs/discojs-core/src/client/decentralized/base.ts index 4d71146d6..fa588e241 100644 --- a/discojs/discojs-core/src/client/decentralized/base.ts +++ b/discojs/discojs-core/src/client/decentralized/base.ts @@ -1,5 +1,4 @@ import { Map, Set } from 'immutable' -import * as nodeUrl from 'url' import { TrainingInformant, WeightsContainer, serialization } from '../..' import { Client, NodeID } from '..' @@ -96,7 +95,6 @@ export class Base extends Client { } async connect (): Promise { - const URL = typeof window !== 'undefined' ? window.URL : nodeUrl.URL const serverURL = new URL('', this.url.href) switch (this.url.protocol) { case 'http:': diff --git a/discojs/discojs-core/src/client/event_connection.ts b/discojs/discojs-core/src/client/event_connection.ts index 21eaf8e96..8ac678a9b 100644 --- a/discojs/discojs-core/src/client/event_connection.ts +++ b/discojs/discojs-core/src/client/event_connection.ts @@ -1,4 +1,4 @@ -import isomorphic, { WebSocket } from 'isomorphic-ws' +import WebSocket from 'isomorphic-ws' import { EventEmitter } from 'events' import { Peer } from './decentralized/peer' import { NodeID } from './types' @@ -109,7 +109,7 @@ export class WebSocketServer implements EventConnection { const emitter: EventEmitter = new EventEmitter() const server: WebSocketServer = new WebSocketServer(ws, emitter, validateReceived, validateSent) - ws.onmessage = (event: isomorphic.MessageEvent) => { + ws.onmessage = (event: WebSocket.MessageEvent) => { if (!(event.data instanceof ArrayBuffer)) { throw new Error('server did not send an ArrayBuffer') } @@ -125,7 +125,7 @@ export class WebSocketServer implements EventConnection { } return await new Promise((resolve, reject) => { - ws.onerror = (err: isomorphic.ErrorEvent) => + ws.onerror = (err: WebSocket.ErrorEvent) => reject(new Error(`connecting server: ${err.message}`)) // eslint-disable-line @typescript-eslint/restrict-template-expressions ws.onopen = () => resolve(server) }) diff --git a/discojs/discojs-core/src/client/federated/base.ts b/discojs/discojs-core/src/client/federated/base.ts index 515cbfd0f..1984e5c65 100644 --- a/discojs/discojs-core/src/client/federated/base.ts +++ b/discojs/discojs-core/src/client/federated/base.ts @@ -1,4 +1,3 @@ -import * as nodeUrl from 'url' import { Map } from 'immutable' import { serialization, informant, MetadataKey, MetadataValue, WeightsContainer, TrainingInformant } from '../..' @@ -43,7 +42,6 @@ export class Base extends Client { * for the task. */ async connect (): Promise { - const URL = typeof window !== 'undefined' ? window.URL : nodeUrl.URL const serverURL = new URL('', this.url.href) switch (this.url.protocol) { case 'http:': diff --git a/discojs/discojs-core/src/task/task_handler.ts b/discojs/discojs-core/src/task/task_handler.ts index 8a4dfc043..56d66ed2d 100644 --- a/discojs/discojs-core/src/task/task_handler.ts +++ b/discojs/discojs-core/src/task/task_handler.ts @@ -1,5 +1,5 @@ -import { Map } from 'immutable' import axios from 'axios' +import { Map } from 'immutable' import { serialization, tf, WeightsContainer } from '..' import { isTask, Task, TaskID } from './task' diff --git a/discojs/discojs-web/tsconfig.json b/discojs/discojs-web/tsconfig.json index fec0ec3d5..fcc5151a4 100644 --- a/discojs/discojs-web/tsconfig.json +++ b/discojs/discojs-web/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../tsconfig.base.json", "compilerOptions": { + "lib": ["DOM"], "outDir": "dist", "baseUrl": "src" }, diff --git a/discojs/tsconfig.base.json b/discojs/tsconfig.base.json index 64290682b..a6cb0b28a 100644 --- a/discojs/tsconfig.base.json +++ b/discojs/tsconfig.base.json @@ -2,7 +2,7 @@ "compilerOptions": { // TODO ES6 disallow server's test "target": "ES5", - "lib": ["ES5", "DOM"], + "lib": ["ES5"], "strict": true, "noEmitOnError": true,