diff --git a/src/PolykeyAgent.ts b/src/PolykeyAgent.ts index 6085617fde..6f2ad29945 100644 --- a/src/PolykeyAgent.ts +++ b/src/PolykeyAgent.ts @@ -1,4 +1,5 @@ -import type { FileSystem, PolykeyWorkerManagerInterface } from './types'; +import type { FileSystem } from './types'; +import type { PolykeyWorkerManagerInterface } from './workers/types'; import type { Host, Port } from './network/types'; import path from 'path'; diff --git a/src/keys/KeyManager.ts b/src/keys/KeyManager.ts index b9d83c6ab7..9caeee8637 100644 --- a/src/keys/KeyManager.ts +++ b/src/keys/KeyManager.ts @@ -5,8 +5,9 @@ import type { CertificatePem, CertificatePemChain, } from './types'; -import type { FileSystem, PolykeyWorkerManagerInterface } from '../types'; +import type { FileSystem } from '../types'; import type { NodeId } from '../nodes/types'; +import type { PolykeyWorkerManagerInterface } from '../workers/types'; import path from 'path'; import Logger from '@matrixai/logger'; diff --git a/src/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index 496d8f6167..6d320542be 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -9,7 +9,6 @@ import type { DB, DBLevel } from '@matrixai/db'; import type { KeyManager } from '../keys'; import type { NodeManager } from '../nodes'; import type { NodeId } from '../nodes/types'; -import type { PolykeyWorkerManagerInterface } from '../types'; import Logger from '@matrixai/logger'; import { Mutex } from 'async-mutex'; @@ -34,7 +33,6 @@ class NotificationsManager { protected db: DB; protected keyManager: KeyManager; protected nodeManager: NodeManager; - protected workerManager?: PolykeyWorkerManagerInterface; protected messageCap: number; diff --git a/src/types.ts b/src/types.ts index fc50563ff3..33e3a5a6ec 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,4 @@ import type fs from 'fs'; -import type { WorkerManagerInterface } from '@matrixai/workers'; -import type { PolykeyWorkerModule } from './workers'; /** * Plain data dictionary @@ -76,9 +74,6 @@ type LockConfig = { clientPort?: number | undefined; } & POJO; -type PolykeyWorkerManagerInterface = - WorkerManagerInterface; - export { POJO, Opaque, @@ -90,6 +85,4 @@ export { Timer, FileSystem, LockConfig, - PolykeyWorkerManagerInterface, - PolykeyWorkerModule, }; diff --git a/src/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index 60e7640101..e5bf2ea6e4 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -7,8 +7,9 @@ import type { VaultList, Vault, } from './types'; -import type { FileSystem, PolykeyWorkerManagerInterface } from '../types'; +import type { FileSystem } from '../types'; import type { NodeId } from '../nodes/types'; +import type { PolykeyWorkerManagerInterface } from '../workers/types'; import path from 'path'; import Logger from '@matrixai/logger'; diff --git a/src/workers/index.ts b/src/workers/index.ts index 3d96716750..a6cf25ab74 100644 --- a/src/workers/index.ts +++ b/src/workers/index.ts @@ -1,3 +1,5 @@ export { default as polykeyWorker } from './polykeyWorkerModule'; -export type { PolykeyWorkerModule } from './polykeyWorkerModule'; export * as utils from './utils'; + +export type { PolykeyWorkerModule } from './polykeyWorkerModule'; +export type { PolykeyWorkerManagerInterface } from './types'; diff --git a/src/workers/types.ts b/src/workers/types.ts new file mode 100644 index 0000000000..293232ca38 --- /dev/null +++ b/src/workers/types.ts @@ -0,0 +1,7 @@ +import type { WorkerManagerInterface } from '@matrixai/workers'; +import type { PolykeyWorkerModule } from './polykeyWorkerModule'; + +type PolykeyWorkerManagerInterface = + WorkerManagerInterface; + +export type { PolykeyWorkerManagerInterface }; diff --git a/src/workers/utils.ts b/src/workers/utils.ts index a9a2f42999..04c208da07 100644 --- a/src/workers/utils.ts +++ b/src/workers/utils.ts @@ -1,17 +1,19 @@ +import type { PolykeyWorkerModule } from './polykeyWorkerModule'; +import type { PolykeyWorkerManagerInterface } from './types'; + import { WorkerManager } from '@matrixai/workers'; -import { PolykeyWorkerModule } from './polykeyWorkerModule'; -import { spawn, Worker } from 'threads'; import Logger from '@matrixai/logger'; +import { spawn, Worker } from 'threads'; -function createWorkerManager({ +async function createWorkerManager({ cores, logger, }: { cores?: number; logger?: Logger; -}) { - return WorkerManager.createWorkerManager({ - workerFactory: () => spawn(new Worker('../../src/workers/polykeyWorker')), +}): Promise { + return await WorkerManager.createWorkerManager({ + workerFactory: () => spawn(new Worker('./polykeyWorker')), cores, logger, }); diff --git a/tests/workers/polykeyWorker.test.ts b/tests/workers/polykeyWorker.test.ts index b599ec1d3e..da04b6d6a2 100644 --- a/tests/workers/polykeyWorker.test.ts +++ b/tests/workers/polykeyWorker.test.ts @@ -1,4 +1,4 @@ -import type { PolykeyWorkerManagerInterface } from '@/types'; +import type { PolykeyWorkerManagerInterface } from '@/workers/types'; import Logger, { LogLevel, StreamHandler } from '@matrixai/logger'; import { createWorkerManager } from '@/workers/utils'; @@ -8,7 +8,6 @@ describe('Polykey worker', () => { new StreamHandler(), ]); let workerManager: PolykeyWorkerManagerInterface; - beforeAll(async () => { workerManager = await createWorkerManager({ cores: 1, @@ -18,7 +17,6 @@ describe('Polykey worker', () => { afterAll(async () => { await workerManager.destroy(); }); - test('generateKeyPairAsn1', async () => { await workerManager.call(async (w) => { await w.generateKeyPairAsn1(4096);