mirror of
https://github.com/koush/scrypted.git
synced 2026-05-05 22:00:27 +01:00
utils: add type assertions for strictNullChecks compliance
Fix strictNullChecks in utility modules: - rpc.ts: make onProxySerialization optional (used with ?.), add definite assignment for killedDeferred - state.ts: cast catch block error to Error - level.ts: add definite assignment for curId - threading.ts: cast catch block errors to Error - http-interfaces.ts: cast catch block error to Error - plugin-http.ts: cast catch block errors to Error, fix abstract method return type - usertoken.ts: make aclId optional in UserToken constructor
This commit is contained in:
@@ -110,7 +110,7 @@ export class HttpResponseImpl implements HttpResponse {
|
||||
this.res.end();
|
||||
}
|
||||
catch (e) {
|
||||
this.res.destroy(e);
|
||||
this.res.destroy(e as Error);
|
||||
}
|
||||
finally {
|
||||
peer.kill();
|
||||
|
||||
@@ -16,7 +16,7 @@ function createLevelDocument(documentConstructor: any, json: any) {
|
||||
}
|
||||
|
||||
export class WrappedLevel extends Level<string, string | number> {
|
||||
curId: number;
|
||||
curId!: number;
|
||||
|
||||
override async open(): Promise<void>;
|
||||
override async open(options?: OpenOptions): Promise<void> {
|
||||
|
||||
@@ -38,7 +38,7 @@ export abstract class PluginHttp<T> {
|
||||
|
||||
abstract handleEngineIOEndpoint(req: Request, res: ServerResponse, endpointRequest: HttpRequest, pluginData: T): void;
|
||||
abstract handleRequestEndpoint(req: Request, res: Response, endpointRequest: HttpRequest, pluginData: T): void;
|
||||
abstract getEndpointPluginData(req: Request, endpoint: string, isUpgrade: boolean, isEngineIOEndpoint: boolean): Promise<T>;
|
||||
abstract getEndpointPluginData(req: Request, endpoint: string, isUpgrade: boolean, isEngineIOEndpoint: boolean): Promise<T | undefined>;
|
||||
abstract handleWebSocket(endpoint: string, httpRequest: HttpRequest, ws: WebSocket, pluginData: T): Promise<void>;
|
||||
abstract checkUpgrade(req: Request, res: Response, pluginData: T): void;
|
||||
|
||||
@@ -129,7 +129,7 @@ export abstract class PluginHttp<T> {
|
||||
catch (e) {
|
||||
res.header('Content-Type', 'text/plain');
|
||||
res.status(500);
|
||||
res.send(e.toString());
|
||||
res.send((e as Error).toString());
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ export abstract class PluginHttp<T> {
|
||||
catch (e) {
|
||||
res.header('Content-Type', 'text/plain');
|
||||
res.status(500);
|
||||
res.send(e.toString());
|
||||
res.send((e as Error).toString());
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ export class RpcPeer {
|
||||
finalizers = new FinalizationRegistry(entry => this.finalize(entry as LocalProxiedEntry));
|
||||
nameDeserializerMap = new Map<string, RpcSerializer>();
|
||||
onProxyTypeSerialization = new Map<string, (value: any) => void>();
|
||||
onProxySerialization: (value: any) => {
|
||||
onProxySerialization?: (value: any) => {
|
||||
proxyId: string;
|
||||
properties: any;
|
||||
};
|
||||
@@ -301,7 +301,7 @@ export class RpcPeer {
|
||||
transportSafeArgumentTypes = RpcPeer.getDefaultTransportSafeArgumentTypes();
|
||||
killed: Promise<string>;
|
||||
killedSafe: Promise<void>;
|
||||
killedDeferred: Deferred;
|
||||
killedDeferred!: Deferred;
|
||||
tags: any = {};
|
||||
yieldedAsyncIterators = new Set<AsyncGenerator>();
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ export class ScryptedStateManager extends EventRegistry {
|
||||
}
|
||||
catch (e) {
|
||||
logger.log('e', 'Refresh failed');
|
||||
logger.log('e', e.toString());
|
||||
logger.log('e', (e as Error).toString());
|
||||
}
|
||||
finally {
|
||||
delete this.refreshThrottles[id];
|
||||
|
||||
@@ -39,7 +39,7 @@ export async function newThread<T>(...args: any[]): Promise<T> {
|
||||
thread_worker_threads.parentPort!.postMessage(thread_v8.serialize(message));
|
||||
}
|
||||
catch (e) {
|
||||
reject?.(e);
|
||||
reject?.(e as Error);
|
||||
}
|
||||
});
|
||||
mainPeer.transportSafeArgumentTypes.add(Buffer.name);
|
||||
@@ -79,7 +79,7 @@ export async function newThread<T>(...args: any[]): Promise<T> {
|
||||
worker.postMessage(v8.serialize(message));
|
||||
}
|
||||
catch (e) {
|
||||
reject?.(e);
|
||||
reject?.(e as Error);
|
||||
}
|
||||
});
|
||||
threadPeer.transportSafeArgumentTypes.add(Buffer.name);
|
||||
|
||||
@@ -2,7 +2,7 @@ export const ONE_DAY_MILLISECONDS = 86400000;
|
||||
export const ONE_YEAR_MILLISECONDS = ONE_DAY_MILLISECONDS * 365;
|
||||
|
||||
export class UserToken {
|
||||
constructor(public username: string, public aclId: string, public timestamp = Date.now(), public duration = ONE_DAY_MILLISECONDS) {
|
||||
constructor(public username: string, public aclId?: string, public timestamp = Date.now(), public duration = ONE_DAY_MILLISECONDS) {
|
||||
}
|
||||
|
||||
static validateToken(token: string): UserToken {
|
||||
|
||||
Reference in New Issue
Block a user