Fix strict TypeScript checks for client
This commit is contained in:
@@ -32,25 +32,25 @@ export function validateYonexusClientConfig(raw: unknown): YonexusClientConfig {
|
|||||||
const source = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
const source = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||||
const issues: string[] = [];
|
const issues: string[] = [];
|
||||||
|
|
||||||
const mainHost = source.mainHost;
|
const rawMainHost = source.mainHost;
|
||||||
if (!isNonEmptyString(mainHost)) {
|
if (!isNonEmptyString(rawMainHost)) {
|
||||||
issues.push("mainHost is required");
|
issues.push("mainHost is required");
|
||||||
} else if (!isValidWsUrl(mainHost.trim())) {
|
} else if (!isValidWsUrl(rawMainHost.trim())) {
|
||||||
issues.push("mainHost must be a valid ws:// or wss:// URL");
|
issues.push("mainHost must be a valid ws:// or wss:// URL");
|
||||||
}
|
}
|
||||||
|
|
||||||
const identifier = source.identifier;
|
const rawIdentifier = source.identifier;
|
||||||
if (!isNonEmptyString(identifier)) {
|
if (!isNonEmptyString(rawIdentifier)) {
|
||||||
issues.push("identifier is required");
|
issues.push("identifier is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const notifyBotToken = source.notifyBotToken;
|
const rawNotifyBotToken = source.notifyBotToken;
|
||||||
if (!isNonEmptyString(notifyBotToken)) {
|
if (!isNonEmptyString(rawNotifyBotToken)) {
|
||||||
issues.push("notifyBotToken is required");
|
issues.push("notifyBotToken is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminUserId = source.adminUserId;
|
const rawAdminUserId = source.adminUserId;
|
||||||
if (!isNonEmptyString(adminUserId)) {
|
if (!isNonEmptyString(rawAdminUserId)) {
|
||||||
issues.push("adminUserId is required");
|
issues.push("adminUserId is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,10 +58,15 @@ export function validateYonexusClientConfig(raw: unknown): YonexusClientConfig {
|
|||||||
throw new YonexusClientConfigError(issues);
|
throw new YonexusClientConfigError(issues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mainHost = (rawMainHost as string).trim();
|
||||||
|
const identifier = (rawIdentifier as string).trim();
|
||||||
|
const notifyBotToken = (rawNotifyBotToken as string).trim();
|
||||||
|
const adminUserId = (rawAdminUserId as string).trim();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mainHost: mainHost.trim(),
|
mainHost,
|
||||||
identifier: identifier.trim(),
|
identifier,
|
||||||
notifyBotToken: notifyBotToken.trim(),
|
notifyBotToken,
|
||||||
adminUserId: adminUserId.trim()
|
adminUserId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,8 @@ function assertClientStateShape(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Number.isInteger(candidate.updatedAt) || candidate.updatedAt < 0) {
|
const updatedAt = candidate.updatedAt;
|
||||||
|
if (typeof updatedAt !== "number" || !Number.isInteger(updatedAt) || updatedAt < 0) {
|
||||||
throw new YonexusClientStateCorruptionError(
|
throw new YonexusClientStateCorruptionError(
|
||||||
`Client state file has invalid updatedAt value: ${filePath}`
|
`Client state file has invalid updatedAt value: ${filePath}`
|
||||||
);
|
);
|
||||||
|
|||||||
24
plugin/types/ws.d.ts
vendored
Normal file
24
plugin/types/ws.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
declare module "ws" {
|
||||||
|
export type RawData = Buffer | ArrayBuffer | Buffer[] | string;
|
||||||
|
|
||||||
|
export class WebSocket {
|
||||||
|
static readonly OPEN: number;
|
||||||
|
constructor(url: string);
|
||||||
|
readonly readyState: number;
|
||||||
|
send(data: string): void;
|
||||||
|
close(code?: number, reason?: string): void;
|
||||||
|
terminate(): void;
|
||||||
|
on(event: "open", listener: () => void): this;
|
||||||
|
on(event: "message", listener: (data: RawData) => void): this;
|
||||||
|
on(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
||||||
|
on(event: "error", listener: (error: Error) => void): this;
|
||||||
|
once(event: "open", listener: () => void): this;
|
||||||
|
once(event: "error", listener: (error: Error) => void): this;
|
||||||
|
off(event: "error", listener: (error: Error) => void): this;
|
||||||
|
removeAllListeners?(event?: string): this;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WebSocketServer {
|
||||||
|
constructor(options: { host?: string; port: number });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"rootDir": ".",
|
"rootDir": "..",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
@@ -15,7 +15,9 @@
|
|||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"plugin/**/*.ts",
|
"plugin/**/*.ts",
|
||||||
"servers/**/*.ts"
|
"plugin/**/*.d.ts",
|
||||||
|
"servers/**/*.ts",
|
||||||
|
"../Yonexus.Protocol/src/**/*.ts"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist",
|
"dist",
|
||||||
|
|||||||
Reference in New Issue
Block a user