fix: 加固 monorepo 质量门禁
This commit is contained in:
+8
-1
@@ -2,7 +2,14 @@ module.exports = {
|
||||
root: true,
|
||||
env: { es2022: true, node: true },
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
project: ["./tsconfig.base.json"],
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
plugins: ["@typescript-eslint"],
|
||||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
||||
extends: [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended-type-checked",
|
||||
],
|
||||
ignorePatterns: ["node_modules/", "dist/", "coverage/"],
|
||||
};
|
||||
|
||||
+4
-2
@@ -6,7 +6,8 @@
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"typecheck": "tsc --noEmit -p tsconfig.base.json",
|
||||
"lint": "eslint . --ext .ts --max-warnings 0 && prettier --check ."
|
||||
"lint": "eslint . --ext .ts --max-warnings 0 && prettier --check .",
|
||||
"build": "corepack pnpm --recursive run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
||||
@@ -14,6 +15,7 @@
|
||||
"eslint": "^8.57.1",
|
||||
"prettier": "^3.4.2",
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^2.1.8"
|
||||
"vite": "^7.3.2",
|
||||
"vitest": "^4.1.11"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src/index.ts"]
|
||||
}
|
||||
Generated
+329
-315
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -8,8 +8,7 @@
|
||||
"exactOptionalPropertyTypes": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true,
|
||||
"types": ["vitest/globals"]
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["packages/**/*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user