From 7ee2f1c40de1cdac7819b2d0db6aa7e4de4212f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 6 Mar 2026 10:54:31 +0800 Subject: [PATCH] Fix imports and formatting in packages Small cleanup across multiple packages: adjust TypeBox imports (add TSchema) and reorder imports in napcat-core/helper/config.ts; normalize indentation and type formatting in napcat-protobuf/NapProto.ts; add missing trailing commas and minor object formatting fixes in tests (packages/napcat-test/schema.test.ts); remove an extra blank line in external-shims.d.ts; and remove an unnecessary blank line in post-build.mjs. These are whitespace/formatting and minor import fixes to satisfy linting and type checks. --- packages/napcat-core/helper/config.ts | 4 +- packages/napcat-protobuf/NapProto.ts | 48 ++++++++++---------- packages/napcat-test/schema.test.ts | 14 +++--- packages/napcat-types/external-shims.d.ts | 1 - packages/napcat-types/scripts/post-build.mjs | 1 - 5 files changed, 33 insertions(+), 35 deletions(-) diff --git a/packages/napcat-core/helper/config.ts b/packages/napcat-core/helper/config.ts index d0c27946..55e22e2c 100644 --- a/packages/napcat-core/helper/config.ts +++ b/packages/napcat-core/helper/config.ts @@ -1,9 +1,9 @@ import { ConfigBase } from '@/napcat-core/helper/config-base'; import { NapCatCore } from '@/napcat-core/index'; -import { Type, Static } from '@sinclair/typebox'; +import { Type, Static, TSchema } from '@sinclair/typebox'; import { Value } from '@sinclair/typebox/value'; -import { TSchema } from '@sinclair/typebox'; + import path from 'node:path'; import fs from 'node:fs'; import json5 from 'json5'; diff --git a/packages/napcat-protobuf/NapProto.ts b/packages/napcat-protobuf/NapProto.ts index 65c624cb..09e47c3a 100644 --- a/packages/napcat-protobuf/NapProto.ts +++ b/packages/napcat-protobuf/NapProto.ts @@ -10,14 +10,14 @@ export type CamelCaseHelper< IsFirstChar extends boolean > = S extends `${infer F}${infer R}` ? F extends '_' - ? CamelCaseHelper - : F extends `${number}` - ? `${F}${CamelCaseHelper}` - : CapNext extends true - ? `${Uppercase}${CamelCaseHelper}` - : IsFirstChar extends true - ? `${Lowercase}${CamelCaseHelper}` - : `${F}${CamelCaseHelper}` + ? CamelCaseHelper + : F extends `${number}` + ? `${F}${CamelCaseHelper}` + : CapNext extends true + ? `${Uppercase}${CamelCaseHelper}` + : IsFirstChar extends true + ? `${Lowercase}${CamelCaseHelper}` + : `${F}${CamelCaseHelper}` : ''; export type ScalarTypeToTsType = T extends @@ -30,14 +30,14 @@ export type ScalarTypeToTsType = T extends | ScalarType.SINT32 ? number : T extends ScalarType.INT64 | ScalarType.UINT64 | ScalarType.FIXED64 | ScalarType.SFIXED64 | ScalarType.SINT64 - ? bigint - : T extends ScalarType.BOOL - ? boolean - : T extends ScalarType.STRING - ? string - : T extends ScalarType.BYTES - ? Uint8Array - : never; + ? bigint + : T extends ScalarType.BOOL + ? boolean + : T extends ScalarType.STRING + ? string + : T extends ScalarType.BYTES + ? Uint8Array + : never; export interface BaseProtoFieldType { kind: 'scalar' | 'message'; @@ -93,25 +93,25 @@ export function ProtoField ( export type ProtoFieldReturnType = NonNullable extends ScalarProtoFieldType - ? ScalarTypeToTsType - : T extends NonNullable> - ? NonNullable, E>> - : never; + ? ScalarTypeToTsType + : T extends NonNullable> + ? NonNullable, E>> + : never; export type RequiredFieldsBaseType = { [K in keyof T as T[K] extends { optional: true; } ? never : LowerCamelCase]: T[K] extends { repeat: true; } - ? ProtoFieldReturnType[] - : ProtoFieldReturnType; + ? ProtoFieldReturnType[] + : ProtoFieldReturnType; }; export type OptionalFieldsBaseType = { [K in keyof T as T[K] extends { optional: true; } ? LowerCamelCase : never]?: T[K] extends { repeat: true; } - ? ProtoFieldReturnType[] - : ProtoFieldReturnType; + ? ProtoFieldReturnType[] + : ProtoFieldReturnType; }; export type RequiredFieldsType = E extends true diff --git a/packages/napcat-test/schema.test.ts b/packages/napcat-test/schema.test.ts index 0e5184e5..9cd9443b 100644 --- a/packages/napcat-test/schema.test.ts +++ b/packages/napcat-test/schema.test.ts @@ -28,7 +28,7 @@ describe('NapCat Schemas Compilation', () => { test('should compile QuickAction hybrid schema without error', () => { const QASchema = Type.Object({ message: OB11PostSendMsgSchema, - quick_action: OB11ActionMessageSchema + quick_action: OB11ActionMessageSchema, }); expect(() => TypeCompiler.Compile(QASchema)).not.toThrow(); }); @@ -39,7 +39,7 @@ describe('NapCat Schemas Validation & Coercion', () => { const payload = { message_type: 'private', user_id: 123456, - message: [{ type: 'text', data: { text: 'hello' } }] + message: [{ type: 'text', data: { text: 'hello' } }], }; let data: unknown = structuredClone(payload); @@ -53,8 +53,8 @@ describe('NapCat Schemas Validation & Coercion', () => { test('should validate complex mixed messages correctly', () => { const payload = { message_type: 'group', - group_id: "654321", - message: 'this is a string message' + group_id: '654321', + message: 'this is a string message', }; let data: unknown = structuredClone(payload); @@ -82,14 +82,14 @@ describe('NapCat Configuration Loaders', () => { enableWebsocket: false, messagePostFormat: 'array', token: '', - debug: false + debug: false, }], httpSseServers: [], httpClients: [], websocketServers: [], websocketClients: [], - plugins: [] - } + plugins: [], + }, }; const loaded = loadOneBotConfig(partialConfig); expect(loaded.network.httpServers[0]?.host).toBe('127.0.0.1'); diff --git a/packages/napcat-types/external-shims.d.ts b/packages/napcat-types/external-shims.d.ts index 0f8a932e..27d535f6 100644 --- a/packages/napcat-types/external-shims.d.ts +++ b/packages/napcat-types/external-shims.d.ts @@ -96,7 +96,6 @@ declare module 'inversify' { export default _inversify_default; } - declare module 'ip' { export function toBuffer (ip: any, buffer?: Buffer, offset?: number): Buffer; export function toString (buffer: any, offset?: number, length?: number): string; diff --git a/packages/napcat-types/scripts/post-build.mjs b/packages/napcat-types/scripts/post-build.mjs index fece610d..52af6f3b 100644 --- a/packages/napcat-types/scripts/post-build.mjs +++ b/packages/napcat-types/scripts/post-build.mjs @@ -11,7 +11,6 @@ const ALLOWED_PACKAGES = [ 'node:', // node: 前缀的内置模块 ]; - function isAllowedImport (importPath) { return ALLOWED_PACKAGES.some(pkg => importPath.startsWith(pkg)); }