diff --git a/.eslintrc.json b/.eslintrc.json index 8f0d2adc51..8a2ded529e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,13 +3,35 @@ "ignorePatterns": ["**/*"], "plugins": ["@nrwl/nx"], "overrides": [ + { + "files": ["*.ts", "*.tsx"], + "extends": ["plugin:@nrwl/nx/typescript"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "extends": ["plugin:@nrwl/nx/javascript"], + "rules": {} + }, + { + "files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"], + "env": { + "jest": true + }, + "rules": {} + }, { "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], "rules": { - "@typescript-eslint/no-unused-vars": ["error", { - "varsIgnorePattern": "^_", - "argsIgnorePattern": "^_" - }], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "varsIgnorePattern": "^_", + "argsIgnorePattern": "^_" + } + ], + "@typescript-eslint/no-explicit-any": ["off", {}], + "@typescript-eslint/ban-ts-comment": ["off", {}], "@nrwl/nx/enforce-module-boundaries": [ "error", { @@ -24,23 +46,6 @@ } ] } - }, - { - "files": ["*.ts", "*.tsx"], - "extends": ["plugin:@nrwl/nx/typescript"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "extends": ["plugin:@nrwl/nx/javascript"], - "rules": {} - }, - { - "files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"], - "env": { - "jest": true - }, - "rules": {} } ] } diff --git a/apps/zui/src/core/electron-zed-client.ts b/apps/zui/src/core/electron-zed-client.ts new file mode 100644 index 0000000000..bda9dc4adb --- /dev/null +++ b/apps/zui/src/core/electron-zed-client.ts @@ -0,0 +1,6 @@ +import {Client} from "@brimdata/zed-node" +import {net} from "electron" + +export class ElectronZedClient extends Client { + fetch = net.fetch +} diff --git a/apps/zui/src/core/electron-zed-lake.ts b/apps/zui/src/core/electron-zed-lake.ts new file mode 100644 index 0000000000..2f032e3777 --- /dev/null +++ b/apps/zui/src/core/electron-zed-lake.ts @@ -0,0 +1,6 @@ +import {Lake} from "@brimdata/zed-node" +import {net} from "electron" + +export class ElectronZedLake extends Lake { + fetch = net.fetch +} diff --git a/apps/zui/src/core/main/main-object.ts b/apps/zui/src/core/main/main-object.ts index 1392194e25..99383d25a7 100644 --- a/apps/zui/src/core/main/main-object.ts +++ b/apps/zui/src/core/main/main-object.ts @@ -2,7 +2,6 @@ import {app} from "electron" import keytar from "keytar" import {EventEmitter} from "events" import os from "os" -import {Client, Lake} from "@brimdata/zed-node" import {Store as ReduxStore} from "redux" import url from "url" import { @@ -30,6 +29,8 @@ import {getAuthToken} from "../../js/api/core/get-zealot" import {Abortables} from "src/app/core/models/abortables" import * as zui from "src/zui" import log from "electron-log" +import {ElectronZedClient} from "../electron-zed-client" +import {ElectronZedLake} from "../electron-zed-lake" export class MainObject { public isQuitting = false @@ -43,7 +44,7 @@ export class MainObject { const windows = new WindowManager(data) const store = createMainStore(data?.globalState) const appMeta = await getAppMeta() - const lake = new Lake({ + const lake = new ElectronZedLake({ root: args.lakeRoot, port: args.lakePort, logs: args.lakeLogs, @@ -55,7 +56,7 @@ export class MainObject { // Only call this from boot constructor( - readonly lake: Lake, + readonly lake: ElectronZedLake, readonly windows: WindowManager, readonly store: ReduxStore, readonly session: Session, @@ -135,7 +136,7 @@ export class MainObject { const lakeData = Lakes.id(lakeId)(this.store.getState()) const lake = createLake(lakeData) const auth = await this.dispatch(getAuthToken(lake)) - return new Client(lake.getAddress(), {auth}) + return new ElectronZedClient(lake.getAddress(), {auth}) } async createDefaultClient() { diff --git a/apps/zui/src/test/shared/__mocks__/electron.ts b/apps/zui/src/test/shared/__mocks__/electron.ts index be1a8546f0..7899e3c74c 100644 --- a/apps/zui/src/test/shared/__mocks__/electron.ts +++ b/apps/zui/src/test/shared/__mocks__/electron.ts @@ -10,6 +10,11 @@ export const dialog = { showSaveDialog: jest.fn(), } +export const net = { + // @ts-ignore + fetch: (...args) => globalThis.fetch(...args), +} + class WebContents extends EventEmitter { send(channel, ...args) { ipcRenderer.emitter.emit("receive-from-main", channel, ...args) diff --git a/packages/zed-node/src/client.ts b/packages/zed-node/src/client.ts index e70d64d45a..abd3d8702f 100644 --- a/packages/zed-node/src/client.ts +++ b/packages/zed-node/src/client.ts @@ -7,7 +7,7 @@ import { } from '@brimdata/zed-js'; export class Client extends BaseClient { - public fetch = globalThis.fetch; + public fetch = globalThis.fetch.bind(globalThis); async load( data: string | NodeJS.ReadableStream, diff --git a/packages/zed-node/src/lake.ts b/packages/zed-node/src/lake.ts index 14f0b5f6ce..f5e51c7af8 100644 --- a/packages/zed-node/src/lake.ts +++ b/packages/zed-node/src/lake.ts @@ -11,6 +11,7 @@ type ConstructorOpts = { corsOrigins?: string[]; }; export class Lake { + fetch = globalThis.fetch; lake?: ChildProcess; root: string; port: number; @@ -82,7 +83,7 @@ export class Lake { async isUp() { try { - const response = await globalThis.fetch(`http://${this.addr()}/status`); + const response = await this.fetch(`http://${this.addr()}/status`); const text = await response.text(); return text === 'ok'; } catch (e) {