mirror of
https://github.com/koush/scrypted.git
synced 2026-05-05 22:00:27 +01:00
plugin: add type assertions for strictNullChecks in runtime workers
Fix strictNullChecks: - child-process-worker.ts: add definite assignment for childProcess - custom-worker.ts: add assertions for pluginDevice and options - node-fork-worker.ts: add catch block type annotation - node-thread-worker.ts: add catch block type annotation - python-worker.ts: add assertions for worker properties
This commit is contained in:
@@ -6,7 +6,7 @@ import { RuntimeWorker, RuntimeWorkerOptions } from "./runtime-worker";
|
||||
export abstract class ChildProcessWorker extends EventEmitter implements RuntimeWorker {
|
||||
public pluginId: string;
|
||||
protected worker: child_process.ChildProcess | undefined;
|
||||
killPromise: Promise<void>;
|
||||
killPromise!: Promise<void>;
|
||||
|
||||
get childProcess() {
|
||||
return this.worker;
|
||||
|
||||
@@ -8,13 +8,13 @@ import { ChildProcessWorker } from "./child-process-worker";
|
||||
import { RuntimeWorkerOptions } from "./runtime-worker";
|
||||
|
||||
export class CustomRuntimeWorker extends ChildProcessWorker {
|
||||
serializer: ReturnType<typeof createRpcDuplexSerializer>;
|
||||
fork: boolean;
|
||||
serializer!: ReturnType<typeof createRpcDuplexSerializer>;
|
||||
fork!: boolean;
|
||||
|
||||
constructor(options: RuntimeWorkerOptions, runtime: ScryptedRuntime) {
|
||||
super(options);
|
||||
|
||||
const pluginDevice = runtime.findPluginDevice(this.pluginId);
|
||||
const pluginDevice = runtime.findPluginDevice(this.pluginId)!;
|
||||
const scryptedRuntimeArguments: ScryptedRuntimeArguments = pluginDevice.state.scryptedRuntimeArguments?.value;
|
||||
if (!scryptedRuntimeArguments)
|
||||
throw new Error('custom runtime requires scryptedRuntimeArguments');
|
||||
@@ -75,7 +75,7 @@ export class CustomRuntimeWorker extends ChildProcessWorker {
|
||||
this.serializer.sendMessage(message, reject, serializationContext);
|
||||
}
|
||||
catch (e) {
|
||||
reject?.(e);
|
||||
reject?.(e as Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ export class NodeForkWorker extends ChildProcessWorker {
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
reject?.(e);
|
||||
reject?.(e as Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ export class NodeThreadWorker extends EventEmitter implements RuntimeWorker {
|
||||
port.postMessage(postMessage, transferList);
|
||||
}
|
||||
catch (e) {
|
||||
reject?.(e);
|
||||
reject?.(e as Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
|
||||
}
|
||||
}
|
||||
|
||||
serializer: ReturnType<typeof createRpcDuplexSerializer>;
|
||||
serializer!: ReturnType<typeof createRpcDuplexSerializer>;
|
||||
peerin: Writable;
|
||||
peerout: Readable;
|
||||
_stdout = new PassThrough();
|
||||
@@ -200,7 +200,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
|
||||
this.serializer.sendMessage(message, reject, serializationContext);
|
||||
}
|
||||
catch (e) {
|
||||
reject?.(e);
|
||||
reject?.(e as Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user