Skip to content

Commit 7ee2f1c

Browse files
committed
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.
1 parent 7380665 commit 7ee2f1c

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

packages/napcat-core/helper/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ConfigBase } from '@/napcat-core/helper/config-base';
22
import { NapCatCore } from '@/napcat-core/index';
3-
import { Type, Static } from '@sinclair/typebox';
3+
import { Type, Static, TSchema } from '@sinclair/typebox';
44

55
import { Value } from '@sinclair/typebox/value';
6-
import { TSchema } from '@sinclair/typebox';
6+
77
import path from 'node:path';
88
import fs from 'node:fs';
99
import json5 from 'json5';

packages/napcat-protobuf/NapProto.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export type CamelCaseHelper<
1010
IsFirstChar extends boolean
1111
> = S extends `${infer F}${infer R}`
1212
? F extends '_'
13-
? CamelCaseHelper<R, true, false>
14-
: F extends `${number}`
15-
? `${F}${CamelCaseHelper<R, true, false>}`
16-
: CapNext extends true
17-
? `${Uppercase<F>}${CamelCaseHelper<R, false, false>}`
18-
: IsFirstChar extends true
19-
? `${Lowercase<F>}${CamelCaseHelper<R, false, false>}`
20-
: `${F}${CamelCaseHelper<R, false, false>}`
13+
? CamelCaseHelper<R, true, false>
14+
: F extends `${number}`
15+
? `${F}${CamelCaseHelper<R, true, false>}`
16+
: CapNext extends true
17+
? `${Uppercase<F>}${CamelCaseHelper<R, false, false>}`
18+
: IsFirstChar extends true
19+
? `${Lowercase<F>}${CamelCaseHelper<R, false, false>}`
20+
: `${F}${CamelCaseHelper<R, false, false>}`
2121
: '';
2222

2323
export type ScalarTypeToTsType<T extends ScalarType> = T extends
@@ -30,14 +30,14 @@ export type ScalarTypeToTsType<T extends ScalarType> = T extends
3030
| ScalarType.SINT32
3131
? number
3232
: T extends ScalarType.INT64 | ScalarType.UINT64 | ScalarType.FIXED64 | ScalarType.SFIXED64 | ScalarType.SINT64
33-
? bigint
34-
: T extends ScalarType.BOOL
35-
? boolean
36-
: T extends ScalarType.STRING
37-
? string
38-
: T extends ScalarType.BYTES
39-
? Uint8Array
40-
: never;
33+
? bigint
34+
: T extends ScalarType.BOOL
35+
? boolean
36+
: T extends ScalarType.STRING
37+
? string
38+
: T extends ScalarType.BYTES
39+
? Uint8Array
40+
: never;
4141

4242
export interface BaseProtoFieldType<T, O extends boolean, R extends O extends true ? false : boolean> {
4343
kind: 'scalar' | 'message';
@@ -93,25 +93,25 @@ export function ProtoField (
9393

9494
export type ProtoFieldReturnType<T, E extends boolean> =
9595
NonNullable<T> extends ScalarProtoFieldType<infer S, infer _O, infer _R>
96-
? ScalarTypeToTsType<S>
97-
: T extends NonNullable<MessageProtoFieldType<infer S, infer _O, infer _R>>
98-
? NonNullable<NapProtoStructType<ReturnType<S>, E>>
99-
: never;
96+
? ScalarTypeToTsType<S>
97+
: T extends NonNullable<MessageProtoFieldType<infer S, infer _O, infer _R>>
98+
? NonNullable<NapProtoStructType<ReturnType<S>, E>>
99+
: never;
100100

101101
export type RequiredFieldsBaseType<T, E extends boolean> = {
102102
[K in keyof T as T[K] extends { optional: true; } ? never : LowerCamelCase<K & string>]: T[K] extends {
103103
repeat: true;
104104
}
105-
? ProtoFieldReturnType<T[K], E>[]
106-
: ProtoFieldReturnType<T[K], E>;
105+
? ProtoFieldReturnType<T[K], E>[]
106+
: ProtoFieldReturnType<T[K], E>;
107107
};
108108

109109
export type OptionalFieldsBaseType<T, E extends boolean> = {
110110
[K in keyof T as T[K] extends { optional: true; } ? LowerCamelCase<K & string> : never]?: T[K] extends {
111111
repeat: true;
112112
}
113-
? ProtoFieldReturnType<T[K], E>[]
114-
: ProtoFieldReturnType<T[K], E>;
113+
? ProtoFieldReturnType<T[K], E>[]
114+
: ProtoFieldReturnType<T[K], E>;
115115
};
116116

117117
export type RequiredFieldsType<T, E extends boolean> = E extends true

packages/napcat-test/schema.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('NapCat Schemas Compilation', () => {
2828
test('should compile QuickAction hybrid schema without error', () => {
2929
const QASchema = Type.Object({
3030
message: OB11PostSendMsgSchema,
31-
quick_action: OB11ActionMessageSchema
31+
quick_action: OB11ActionMessageSchema,
3232
});
3333
expect(() => TypeCompiler.Compile(QASchema)).not.toThrow();
3434
});
@@ -39,7 +39,7 @@ describe('NapCat Schemas Validation & Coercion', () => {
3939
const payload = {
4040
message_type: 'private',
4141
user_id: 123456,
42-
message: [{ type: 'text', data: { text: 'hello' } }]
42+
message: [{ type: 'text', data: { text: 'hello' } }],
4343
};
4444

4545
let data: unknown = structuredClone(payload);
@@ -53,8 +53,8 @@ describe('NapCat Schemas Validation & Coercion', () => {
5353
test('should validate complex mixed messages correctly', () => {
5454
const payload = {
5555
message_type: 'group',
56-
group_id: "654321",
57-
message: 'this is a string message'
56+
group_id: '654321',
57+
message: 'this is a string message',
5858
};
5959

6060
let data: unknown = structuredClone(payload);
@@ -82,14 +82,14 @@ describe('NapCat Configuration Loaders', () => {
8282
enableWebsocket: false,
8383
messagePostFormat: 'array',
8484
token: '',
85-
debug: false
85+
debug: false,
8686
}],
8787
httpSseServers: [],
8888
httpClients: [],
8989
websocketServers: [],
9090
websocketClients: [],
91-
plugins: []
92-
}
91+
plugins: [],
92+
},
9393
};
9494
const loaded = loadOneBotConfig(partialConfig);
9595
expect(loaded.network.httpServers[0]?.host).toBe('127.0.0.1');

packages/napcat-types/external-shims.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ declare module 'inversify' {
9696
export default _inversify_default;
9797
}
9898

99-
10099
declare module 'ip' {
101100
export function toBuffer (ip: any, buffer?: Buffer, offset?: number): Buffer;
102101
export function toString (buffer: any, offset?: number, length?: number): string;

packages/napcat-types/scripts/post-build.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const ALLOWED_PACKAGES = [
1111
'node:', // node: 前缀的内置模块
1212
];
1313

14-
1514
function isAllowedImport (importPath) {
1615
return ALLOWED_PACKAGES.some(pkg => importPath.startsWith(pkg));
1716
}

0 commit comments

Comments
 (0)