Merge remote-tracking branch 'upstream/type-enhancement' into pr-1549

This commit is contained in:
pohgxz 2026-01-26 16:38:39 +08:00
commit a366abce8f
22 changed files with 800 additions and 253 deletions

View File

@ -39,6 +39,12 @@ export * from './wrapper';
export * from './types/index';
export * from './services/index';
export * from './listeners/index';
export * from './apis/index';
export * from './helper/log';
export * from './helper/qq-basic-info';
export * from './helper/event';
export * from './helper/config';
export * from './helper/proxy-handler';
export enum NapCatCoreWorkingEnv {
Unknown = 0,

View File

@ -11,3 +11,7 @@ export * from './constant';
export * from './graytip';
export * from './emoji';
export * from './service';
export * from './adapter';
export * from './contact';
export * from './file';
export * from './flashfile';

View File

@ -1,4 +1,4 @@
import { NTGroupMemberRole } from '@/napcat-core/index';
import { NTGroupMemberRole } from './group';
import { ActionBarElement, ArkElement, AvRecordElement, CalendarElement, FaceBubbleElement, FaceElement, FileElement, GiphyElement, GrayTipElement, MarketFaceElement, PicElement, PttElement, RecommendedMsgElement, ReplyElement, ShareLocationElement, StructLongMsgElement, TaskTopMsgElement, TextElement, TofuRecordElement, VideoElement, YoloGameResultElement } from './element';
/*

View File

@ -3,3 +3,4 @@ export * from './group';
export * from './user';
export * from './msg';
export * from './quick-action';
export * from './file';

View File

@ -3,6 +3,8 @@ import type { NapCatCore } from 'napcat-core';
import { OneBotConfig } from './config';
import { AnySchema } from 'ajv';
export * from './config';
export class OB11ConfigLoader extends ConfigBase<OneBotConfig> {
constructor (core: NapCatCore, configPath: string, schema: AnySchema) {
super('onebot11', core, configPath, schema);

View File

@ -0,0 +1,5 @@
export * from './message';
export * from './meta';
export * from './notice';
export * from './request';
export * from './OneBotEvent';

View File

@ -0,0 +1 @@
export * from './OB11BaseMessageEvent';

View File

@ -0,0 +1,3 @@
export * from './OB11BaseMetaEvent';
export * from './OB11HeartbeatEvent';
export * from './OB11LifeCycleEvent';

View File

@ -0,0 +1,23 @@
export * from './BotOfflineEvent';
export * from './OB11BaseNoticeEvent';
export * from './OB11FriendAddNoticeEvent';
export * from './OB11FriendRecallNoticeEvent';
export * from './OB11GroupAdminNoticeEvent';
export * from './OB11GroupBanEvent';
export * from './OB11GroupCardEvent';
export * from './OB11GroupDecreaseEvent';
export * from './OB11GroupEssenceEvent';
export * from './OB11GroupGrayTipEvent';
export * from './OB11GroupIncreaseEvent';
export * from './OB11GroupNameEvent';
export * from './OB11GroupNoticeEvent';
export * from './OB11GroupRecallNoticeEvent';
export * from './OB11GroupTitleEvent';
export * from './OB11GroupUploadNoticeEvent';
export * from './OB11InputStatusEvent';
export * from './OB11MsgEmojiLikeEvent';
export * from './OB11OnlineFileNoticeEvent';
export * from './OB11OnlineFileReceiveEvent';
export * from './OB11OnlineFileSendEvent';
export * from './OB11PokeEvent';
export * from './OB11ProfileLikeEvent';

View File

@ -0,0 +1,3 @@
export * from './OB11BaseRequestEvent';
export * from './OB11FriendRequest';
export * from './OB11GroupRequest';

View File

@ -701,4 +701,7 @@ export class NapCatOneBot11Adapter {
}
}
export * from './types';
export * from './types/index';
export * from './api/index';
export * from './event/index';
export * from './config/index';

View File

@ -1,7 +1,7 @@
import type { ActionMap } from 'napcat-onebot/action';
import { EventType } from 'napcat-onebot/event/OneBotEvent';
import type { PluginModule } from 'napcat-onebot/network/plugin';
import type { OB11Message, OB11PostSendMsg } from 'napcat-onebot/types/message';
import type { ActionMap } from 'napcat-types/dist/napcat-onebot/action/index';
import { EventType } from 'napcat-types/dist/napcat-onebot/event/index';
import type { PluginModule } from 'napcat-types/dist/napcat-onebot/network/plugin-manger';
import type { OB11Message, OB11PostSendMsg } from 'napcat-types/dist/napcat-onebot/types/index';
let actions: ActionMap | undefined = undefined;
let startTime: number = Date.now();

View File

@ -6,7 +6,7 @@
"description": "NapCat 内置插件",
"author": "NapNeko",
"dependencies": {
"napcat-onebot": "workspace:*"
"napcat-types": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.0.1"

View File

@ -1,6 +1,6 @@
import type { createActionMap } from 'napcat-onebot/action';
import { EventType } from 'napcat-onebot/event/OneBotEvent';
import type { PluginModule } from 'napcat-onebot/network/plugin';
import type { createActionMap } from 'napcat-types/dist/napcat-onebot/action/index.js';
import { EventType } from 'napcat-types/dist/napcat-onebot/event/index.js';
import type { PluginModule } from 'napcat-types/dist/napcat-onebot/network/plugin-manger';
/**
* napcat 使 @/napcat...使 napcat...

View File

@ -5,7 +5,7 @@
"main": "index.mjs",
"description": "一个高级的 NapCat 插件示例",
"dependencies": {
"napcat-onebot": "workspace:*"
"napcat-types": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.0.1"

View File

@ -0,0 +1,178 @@
// 外部模块 shim提供最小的可运行值和类型避免类型包依赖外部环境
// node:* 模块移除 mock使用系统自带类型
// (ws/express/winston) now provided by real type deps (@types/ws, @types/express, winston)
declare module 'ffmpeg-static' {
const _ffmpeg_static_default: any;
export default _ffmpeg_static_default;
}
declare module 'fluent-ffmpeg' {
const _fluent_ffmpeg_default: any;
export default _fluent_ffmpeg_default;
}
declare module 'sharp' {
const _sharp_default: any;
export default _sharp_default;
}
declare module 'uuid' {
export function v4 (...args: any[]): string;
}
declare module 'axios' {
const _axios_default: any;
export default _axios_default;
}
declare module 'body-parser' {
const _body_parser_default: any;
export default _body_parser_default;
}
declare module 'cors' {
const _cors_default: any;
export default _cors_default;
}
declare module 'file-type' {
export function fileTypeFromFile (path: string): Promise<any>;
}
declare module 'image-size' {
const _image_size_default: any;
export default _image_size_default;
}
declare module 'jimp' {
const _jimp_default: any;
export default _jimp_default;
}
declare module 'qrcode' {
const _qrcode_default: any;
export default _qrcode_default;
}
declare module 'yaml' {
export const parse: (...args: any[]) => any;
export const stringify: (...args: any[]) => any;
}
declare module 'async-mutex' {
export class Mutex {
acquire (): Promise<() => void>;
runExclusive<T> (callback: () => T | Promise<T>): Promise<T>;
}
export class Semaphore {
acquire (): Promise<[() => void, number]>;
runExclusive<T> (callback: () => T | Promise<T>): Promise<T>;
release (): void;
}
const _async_mutex_default: { Mutex: typeof Mutex; Semaphore: typeof Semaphore; };
export default _async_mutex_default;
}
declare module '@sinclair/typebox' {
export const Type: {
Object: (...args: any[]) => any;
String: (...args: any[]) => any;
Number: (...args: any[]) => any;
Boolean: (...args: any[]) => any;
Array: (...args: any[]) => any;
Union: (...args: any[]) => any;
Literal: (...args: any[]) => any;
Optional: (...args: any[]) => any;
Record: (...args: any[]) => any;
Any: (...args: any[]) => any;
} & any;
// Make Static<> actually resolve to a structural type so optional properties work.
export type Static<T> = T extends { static: infer S; } ? S : any;
export interface TSchema { static?: any; }
export interface TObject<T = any> extends TSchema { }
export interface TOptional<T = any> extends TSchema { }
export interface TNumber extends TSchema { }
export interface TString extends TSchema { }
export interface TBoolean extends TSchema { }
export interface TArray<T = any> extends TSchema { }
export interface TUnion<T = any> extends TSchema { }
export interface TLiteral<T = any> extends TSchema { }
export interface TAny extends TSchema { }
export interface TNull extends TSchema { }
export interface TUndefined extends TSchema { }
export interface TVoid extends TSchema { }
}
declare module 'napcat-protobuf' {
export class NapProtoMsg<T = any> {
constructor (schema: any);
decode (buffer: any): T;
encode (value: any): Uint8Array;
}
export function ProtoField (...args: any[]): any;
export type NapProtoEncodeStructType<T> = any;
export type NapProtoDecodeStructType<T> = any;
export type ScalarProtoFieldType<T> = any;
export type MessageProtoFieldType<T> = any;
export const ScalarType: {
STRING: any;
INT64: any;
INT32: any;
UINT32: any;
UINT64: any;
BYTES: any;
BOOL: any;
[key: string]: any;
};
}
declare module 'inversify' {
export class Container {
bind: (...args: any[]) => any;
get: <T = any>(id: any) => T;
}
export function injectable (...args: any[]): any;
export function inject (...args: any[]): any;
export interface ServiceIdentifier<T = any> { }
const _inversify_default: any;
export default _inversify_default;
}
declare module 'ajv' {
export interface AnySchema { [key: string]: any; }
export interface ErrorObject {
keyword: string;
instancePath: string;
schemaPath: string;
params: any;
message?: string;
}
export interface ValidateFunction<T = any> {
(data: any): data is T;
errors: ErrorObject[] | null;
}
class Ajv {
constructor (...args: any[]);
compile<T = any> (schema: any): ValidateFunction<T>;
validate (schemaOrRef: any, data: any): boolean;
errorsText (errors?: any, options?: any): string;
errors: ErrorObject[] | null;
}
export default Ajv;
export { Ajv, ValidateFunction, ErrorObject };
}
declare module 'ip' {
export function toBuffer (ip: any, buffer?: Buffer, offset?: number): Buffer;
export function toString (buffer: any, offset?: number, length?: number): string;
const _ip_default: any;
export default _ip_default;
}

View File

@ -0,0 +1,9 @@
/// <reference path="./external-shims.d.ts" />
// 聚合导出核心库的所有内容(包括枚举、类和类型)
export * from '../napcat-core/index';
// 聚合导出 OneBot 的所有内容
export * from '../napcat-onebot/index';
// Ensure the shims file exists next to the emitted JS as well.
export type { };

View File

@ -0,0 +1,30 @@
{
"name": "napcat-types",
"version": "0.0.1",
"private": true,
"type": "module",
"types": "./dist/napcat-types/index.d.ts",
"files": [
"dist/**/*"
],
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias --project tsconfig.json --outDir dist",
"test": "pnpm -s exec tsc --project tsconfig.json --noEmit"
},
"dependencies": {
"napcat-core": "workspace:*",
"napcat-onebot": "workspace:*",
"@types/node": "^22.10.7",
"@types/express": "^4.17.21",
"@types/ws": "^8.5.12",
"@types/cors": "^2.8.17",
"@types/multer": "^1.4.12",
"@types/winston": "^2.4.4",
"@types/yaml": "^1.9.7",
"@types/ip": "^1.1.3",
"compressing": "^1.10.3"
},
"devDependencies": {
"tsc-alias": "^1.8.16"
}
}

View File

@ -0,0 +1,38 @@
import {
ChatType,
ElementType,
NapCatCore,
NTQQMsgApi,
NapCatOneBot11Adapter,
OB11Message,
OB11BaseMessageEvent,
OB11BaseMetaEvent,
} from './dist/napcat-types/index';
console.log('--- NapCat Comprehensive Type Test ---');
// 1. 测试枚举 (Core)
console.log('ChatType.KCHATTYPEGROUP:', ChatType.KCHATTYPEGROUP); // 应输出 2
console.log('ElementType.TEXT:', ElementType.TEXT); // 应输出 1
// 2. 测试类型 (Core)
const coreStub = {} as NapCatCore;
const apiStub = {} as NTQQMsgApi;
console.log('Core types access check: OK');
// 3. 测试类和类型 (OneBot)
const obAdapterStub = {} as NapCatOneBot11Adapter;
const obMsgStub = {} as OB11Message;
const baseMessageEventStub = {} as OB11BaseMessageEvent;
const baseMetaEventStub = {} as OB11BaseMetaEvent;
console.log('OneBot types and events access check: OK');
// 4. 验证导出完整性
if (ChatType.KCHATTYPEGROUP === 2 && ElementType.TEXT === 1) {
console.log('\n✅ ALL TESTS PASSED: Types, Enums and Events are correctly exported and accessible.');
} else {
console.error('\n❌ TESTS FAILED: Enum value mismatch.');
throw new Error('Test Failed');
}

View File

@ -0,0 +1,20 @@
import { ChatType, ElementType, NapCatCore, NTQQMsgApi } from './index';
console.log('--- NapCat Types Manual Test ---');
// 测试枚举值 (napcat-core enums)
console.log('ChatType.KCHATTYPEGROUP:', ChatType.KCHATTYPEGROUP);
console.log('ElementType.TEXT:', ElementType.TEXT);
// 测试 napcat-core 的类型和类
const coreStub = {} as NapCatCore;
const apiStub = {} as NTQQMsgApi;
console.log('NapCatCore type check:', !!coreStub);
console.log('NTQQMsgApi type check:', !!apiStub);
if (ChatType.KCHATTYPEGROUP === 2 && ElementType.TEXT === 1) {
console.log('Test Passed: core enums and types are correctly exported.');
} else {
throw new Error('Test Failed: Enum values do not match expected values.');
}

View File

@ -0,0 +1,49 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "..",
"baseUrl": ".",
"declaration": true,
"emitDeclarationOnly": true,
"skipLibCheck": true,
"stripInternal": true,
"noEmitOnError": false,
"paths": {
"napcat-core": [
"../napcat-core/index.ts"
],
"napcat-onebot": [
"../napcat-onebot/index.ts"
],
"@/napcat-core/*": [
"../napcat-core/*"
],
"@/napcat-onebot/*": [
"../napcat-onebot/*"
],
"@/napcat-common/*": [
"../napcat-common/*"
],
"@/napcat-webui-backend/*": [
"../napcat-webui-backend/*"
],
"@/*": [
"../*"
]
}
},
"include": [
"./index.ts",
"../napcat-core/**/*.ts",
"../napcat-onebot/**/*.ts",
"../napcat-common/**/*.ts"
],
"files": [
"./external-shims.d.ts"
],
"exclude": [
"node_modules",
"dist"
]
}

File diff suppressed because it is too large Load Diff