fix: 加固 monorepo 质量门禁

This commit is contained in:
root
2026-09-14 10:47:02 +08:00
parent 332bf2fb46
commit 18450201dc
8 changed files with 392 additions and 324 deletions
+8 -1
View File
@@ -3,8 +3,15 @@
"version": "0.0.0",
"private": true,
"type": "module",
"exports": "./src/index.ts",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"test": "vitest run src/index.test.ts"
}
}
+25 -2
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { ErrorCode, ok } from "./index";
import { describe, expect, expectTypeOf, it } from "vitest";
import { ErrorCode, ok, type SuccessResponse } from "./index";
describe("contracts", () => {
it("creates the uniform response envelope", () => {
@@ -10,4 +10,27 @@ describe("contracts", () => {
requestId: "req-1",
});
});
it("preserves literal success response types", () => {
const response = ok({ id: "1" }, "req-1");
expectTypeOf(response).toEqualTypeOf<SuccessResponse<{ id: string }>>();
expectTypeOf(response.code).toEqualTypeOf<ErrorCode.OK>();
expectTypeOf(response.message).toEqualTypeOf<"success">();
});
it("defines the complete error-code contract", () => {
expect(Object.values(ErrorCode)).toEqual([
"OK",
"AUTH_TOKEN_EXPIRED",
"AUTH_REFRESH_REUSED",
"BOTTLE_DAILY_LIMIT",
"BOTTLE_POOL_EMPTY",
"BOTTLE_LEASE_EXPIRED",
"CONTENT_REJECTED",
"USER_BLOCKED",
"CONVERSATION_FORBIDDEN",
"MESSAGE_DUPLICATE",
]);
});
});
+8 -1
View File
@@ -11,7 +11,14 @@ export enum ErrorCode {
MESSAGE_DUPLICATE = "MESSAGE_DUPLICATE",
}
export const ok = <T>(data: T, requestId: string) => ({
export interface SuccessResponse<T> {
code: ErrorCode.OK;
message: "success";
data: T;
requestId: string;
}
export const ok = <T>(data: T, requestId: string): SuccessResponse<T> => ({
code: ErrorCode.OK,
message: "success",
data,
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/index.ts"]
}