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.
This commit is contained in:
1 parent
7380665cc2
commit
7ee2f1c40d
5 files changed
+33
-35
No files matched your search
@@ -1,9 +1,9 @@
|
|||||||
import { ConfigBase } from '@/napcat-core/helper/config-base';
|
import { ConfigBase } from '@/napcat-core/helper/config-base';
|
||||||
import { NapCatCore } from '@/napcat-core/index';
|
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 { Value } from '@sinclair/typebox/value';
|
||||||
import { TSchema } from '@sinclair/typebox';
|
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import json5 from 'json5';
|
import json5 from 'json5';
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ export type CamelCaseHelper<
|
|||||||
IsFirstChar extends boolean
|
IsFirstChar extends boolean
|
||||||
> = S extends `${infer F}${infer R}`
|
> = S extends `${infer F}${infer R}`
|
||||||
? F extends '_'
|
? F extends '_'
|
||||||
? CamelCaseHelper<R, true, false>
|
? CamelCaseHelper<R, true, false>
|
||||||
: F extends `${number}`
|
: F extends `${number}`
|
||||||
? `${F}${CamelCaseHelper<R, true, false>}`
|
? `${F}${CamelCaseHelper<R, true, false>}`
|
||||||
: CapNext extends true
|
: CapNext extends true
|
||||||
? `${Uppercase<F>}${CamelCaseHelper<R, false, false>}`
|
? `${Uppercase<F>}${CamelCaseHelper<R, false, false>}`
|
||||||
: IsFirstChar extends true
|
: IsFirstChar extends true
|
||||||
? `${Lowercase<F>}${CamelCaseHelper<R, false, false>}`
|
? `${Lowercase<F>}${CamelCaseHelper<R, false, false>}`
|
||||||
: `${F}${CamelCaseHelper<R, false, false>}`
|
: `${F}${CamelCaseHelper<R, false, false>}`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
export type ScalarTypeToTsType<T extends ScalarType> = T extends
|
export type ScalarTypeToTsType<T extends ScalarType> = T extends
|
||||||
@@ -30,14 +30,14 @@ export type ScalarTypeToTsType<T extends ScalarType> = T extends
|
|||||||
| ScalarType.SINT32
|
| ScalarType.SINT32
|
||||||
? number
|
? number
|
||||||
: T extends ScalarType.INT64 | ScalarType.UINT64 | ScalarType.FIXED64 | ScalarType.SFIXED64 | ScalarType.SINT64
|
: T extends ScalarType.INT64 | ScalarType.UINT64 | ScalarType.FIXED64 | ScalarType.SFIXED64 | ScalarType.SINT64
|
||||||
? bigint
|
? bigint
|
||||||
: T extends ScalarType.BOOL
|
: T extends ScalarType.BOOL
|
||||||
? boolean
|
? boolean
|
||||||
: T extends ScalarType.STRING
|
: T extends ScalarType.STRING
|
||||||
? string
|
? string
|
||||||
: T extends ScalarType.BYTES
|
: T extends ScalarType.BYTES
|
||||||
? Uint8Array
|
? Uint8Array
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export interface BaseProtoFieldType<T, O extends boolean, R extends O extends true ? false : boolean> {
|
export interface BaseProtoFieldType<T, O extends boolean, R extends O extends true ? false : boolean> {
|
||||||
kind: 'scalar' | 'message';
|
kind: 'scalar' | 'message';
|
||||||
@@ -93,25 +93,25 @@ export function ProtoField (
|
|||||||
|
|
||||||
export type ProtoFieldReturnType<T, E extends boolean> =
|
export type ProtoFieldReturnType<T, E extends boolean> =
|
||||||
NonNullable<T> extends ScalarProtoFieldType<infer S, infer _O, infer _R>
|
NonNullable<T> extends ScalarProtoFieldType<infer S, infer _O, infer _R>
|
||||||
? ScalarTypeToTsType<S>
|
? ScalarTypeToTsType<S>
|
||||||
: T extends NonNullable<MessageProtoFieldType<infer S, infer _O, infer _R>>
|
: T extends NonNullable<MessageProtoFieldType<infer S, infer _O, infer _R>>
|
||||||
? NonNullable<NapProtoStructType<ReturnType<S>, E>>
|
? NonNullable<NapProtoStructType<ReturnType<S>, E>>
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export type RequiredFieldsBaseType<T, E extends boolean> = {
|
export type RequiredFieldsBaseType<T, E extends boolean> = {
|
||||||
[K in keyof T as T[K] extends { optional: true; } ? never : LowerCamelCase<K & string>]: T[K] extends {
|
[K in keyof T as T[K] extends { optional: true; } ? never : LowerCamelCase<K & string>]: T[K] extends {
|
||||||
repeat: true;
|
repeat: true;
|
||||||
}
|
}
|
||||||
? ProtoFieldReturnType<T[K], E>[]
|
? ProtoFieldReturnType<T[K], E>[]
|
||||||
: ProtoFieldReturnType<T[K], E>;
|
: ProtoFieldReturnType<T[K], E>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OptionalFieldsBaseType<T, E extends boolean> = {
|
export type OptionalFieldsBaseType<T, E extends boolean> = {
|
||||||
[K in keyof T as T[K] extends { optional: true; } ? LowerCamelCase<K & string> : never]?: T[K] extends {
|
[K in keyof T as T[K] extends { optional: true; } ? LowerCamelCase<K & string> : never]?: T[K] extends {
|
||||||
repeat: true;
|
repeat: true;
|
||||||
}
|
}
|
||||||
? ProtoFieldReturnType<T[K], E>[]
|
? ProtoFieldReturnType<T[K], E>[]
|
||||||
: ProtoFieldReturnType<T[K], E>;
|
: ProtoFieldReturnType<T[K], E>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RequiredFieldsType<T, E extends boolean> = E extends true
|
export type RequiredFieldsType<T, E extends boolean> = E extends true
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ describe('NapCat Schemas Compilation', () => {
|
|||||||
test('should compile QuickAction hybrid schema without error', () => {
|
test('should compile QuickAction hybrid schema without error', () => {
|
||||||
const QASchema = Type.Object({
|
const QASchema = Type.Object({
|
||||||
message: OB11PostSendMsgSchema,
|
message: OB11PostSendMsgSchema,
|
||||||
quick_action: OB11ActionMessageSchema
|
quick_action: OB11ActionMessageSchema,
|
||||||
});
|
});
|
||||||
expect(() => TypeCompiler.Compile(QASchema)).not.toThrow();
|
expect(() => TypeCompiler.Compile(QASchema)).not.toThrow();
|
||||||
});
|
});
|
||||||
@@ -39,7 +39,7 @@ describe('NapCat Schemas Validation & Coercion', () => {
|
|||||||
const payload = {
|
const payload = {
|
||||||
message_type: 'private',
|
message_type: 'private',
|
||||||
user_id: 123456,
|
user_id: 123456,
|
||||||
message: [{ type: 'text', data: { text: 'hello' } }]
|
message: [{ type: 'text', data: { text: 'hello' } }],
|
||||||
};
|
};
|
||||||
|
|
||||||
let data: unknown = structuredClone(payload);
|
let data: unknown = structuredClone(payload);
|
||||||
@@ -53,8 +53,8 @@ describe('NapCat Schemas Validation & Coercion', () => {
|
|||||||
test('should validate complex mixed messages correctly', () => {
|
test('should validate complex mixed messages correctly', () => {
|
||||||
const payload = {
|
const payload = {
|
||||||
message_type: 'group',
|
message_type: 'group',
|
||||||
group_id: "654321",
|
group_id: '654321',
|
||||||
message: 'this is a string message'
|
message: 'this is a string message',
|
||||||
};
|
};
|
||||||
|
|
||||||
let data: unknown = structuredClone(payload);
|
let data: unknown = structuredClone(payload);
|
||||||
@@ -82,14 +82,14 @@ describe('NapCat Configuration Loaders', () => {
|
|||||||
enableWebsocket: false,
|
enableWebsocket: false,
|
||||||
messagePostFormat: 'array',
|
messagePostFormat: 'array',
|
||||||
token: '',
|
token: '',
|
||||||
debug: false
|
debug: false,
|
||||||
}],
|
}],
|
||||||
httpSseServers: [],
|
httpSseServers: [],
|
||||||
httpClients: [],
|
httpClients: [],
|
||||||
websocketServers: [],
|
websocketServers: [],
|
||||||
websocketClients: [],
|
websocketClients: [],
|
||||||
plugins: []
|
plugins: [],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
const loaded = loadOneBotConfig(partialConfig);
|
const loaded = loadOneBotConfig(partialConfig);
|
||||||
expect(loaded.network.httpServers[0]?.host).toBe('127.0.0.1');
|
expect(loaded.network.httpServers[0]?.host).toBe('127.0.0.1');
|
||||||
|
|||||||
-1
@@ -96,7 +96,6 @@ declare module 'inversify' {
|
|||||||
export default _inversify_default;
|
export default _inversify_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
declare module 'ip' {
|
declare module 'ip' {
|
||||||
export function toBuffer (ip: any, buffer?: Buffer, offset?: number): Buffer;
|
export function toBuffer (ip: any, buffer?: Buffer, offset?: number): Buffer;
|
||||||
export function toString (buffer: any, offset?: number, length?: number): string;
|
export function toString (buffer: any, offset?: number, length?: number): string;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ const ALLOWED_PACKAGES = [
|
|||||||
'node:', // node: 前缀的内置模块
|
'node:', // node: 前缀的内置模块
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
function isAllowedImport (importPath) {
|
function isAllowedImport (importPath) {
|
||||||
return ALLOWED_PACKAGES.some(pkg => importPath.startsWith(pkg));
|
return ALLOWED_PACKAGES.some(pkg => importPath.startsWith(pkg));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user