{"id":14989342,"url":"https://github.com/chumijs/chumi","last_synced_at":"2025-04-12T00:32:04.821Z","repository":{"id":142859108,"uuid":"610846859","full_name":"chumijs/chumi","owner":"chumijs","description":"🌈A middleware framework based on Koa, providing annotations for Controller, Route, Parameter, Service, and other functionalities at runtime.","archived":false,"fork":false,"pushed_at":"2025-04-11T08:57:44.000Z","size":708,"stargazers_count":4,"open_issues_count":5,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T10:56:12.309Z","etag":null,"topics":["chumi","egg","koa","midway","nest","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chumijs.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-07T15:47:28.000Z","updated_at":"2023-11-23T05:52:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"da7941cc-f173-4f2c-9dee-dccc5ee40615","html_url":"https://github.com/chumijs/chumi","commit_stats":{"total_commits":82,"total_committers":5,"mean_commits":16.4,"dds":"0.19512195121951215","last_synced_commit":"5329fab982b81f5e18b7c272084ed455430f2720"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chumijs%2Fchumi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chumijs%2Fchumi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chumijs%2Fchumi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chumijs%2Fchumi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chumijs","download_url":"https://codeload.github.com/chumijs/chumi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248387427,"owners_count":21095208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chumi","egg","koa","midway","nest","nodejs"],"created_at":"2024-09-24T14:18:09.788Z","updated_at":"2025-04-12T00:32:04.281Z","avatar_url":"https://github.com/chumijs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chumi · [![NPM version](https://img.shields.io/npm/v/chumi.svg)](https://www.npmjs.com/package/chumi) [![build](https://img.shields.io/circleci/build/github/chumijs/chumi/master.svg)](https://circleci.com/gh/chumijs/chumi) [![coverage](https://img.shields.io/codecov/c/github/chumijs/chumi/master.svg)](https://app.codecov.io/gh/chumijs/chumi/tree/master) [![NPM downloads](http://img.shields.io/npm/dm/chumi.svg)](http://www.npmtrends.com/chumi) [![stackblitz demo](https://img.shields.io/badge/stackblitz-chumi-brightgreen)](https://stackblitz.com/edit/node-h13evz)\n\n基于koa，在运行时，提供Controller、Route、Parameter、Service等功能的注解的中间件框架，可以在任何支持koa中间件的项目或者框架里面使用\n\n## 示例\n\n1. [⚡️ 使用koa、vite、vue3搭建一个原始的全栈开发环境，集成chumi示例，帮助开发者更好的组织后端业务代码](https://github.com/chumijs/chumi-vite)\n\n2. [🥚 Egg框架 - 集成chumi示例，由于chumi的多实例特性，可以集成到Egg插件，**目前已经在生产使用验证过**](https://github.com/chumijs/chumi-egg)\n\n3. [🍔 Midway框架 - 集成chumi示例](https://github.com/chumijs/chumi-midway)\n\n4. [🦅 Nest框架 - 集成chumi示例](https://github.com/chumijs/chumi-nest)\n\n5. [🎨 Next.js框架 - 集成chumi示例](https://github.com/chumijs/chumi-next)\n\n6. 🤟 欢迎提供更多的示例...\n\n## 架构图\n\n![image.png](https://s1.ax1x.com/2023/03/09/ppnJJeA.png)\n\n## Apis\n\n```ts\nimport chumi, {\n  Controller,\n  Service,\n  Get,\n  Post,\n  Delete,\n  Put,\n  Param,\n  Query,\n  Body,\n  Header,\n  Files,\n  ApiTags,\n  loadService,\n  loadController,\n  ChumiRequestData,   // TypeScript Types\n  ChumiResponseData,  // TypeScript Types\n} from 'chumi';\n```\n\n## 星链互联\n\n\u003e 拷贝如下代码即可体验。也可以克隆当前项目，安装依赖后，直接使用命令`yarn tsx sample/chumi-chain`运行即可\n\n```ts\nimport Koa, { Context } from 'koa';\nimport chumi, { Controller, Get, Service, loadController, loadService } from 'chumi';\n\nconst app = new Koa();\n\n// Service类\n@Service\nclass S1 {\n  ctx: Context;\n  chain = loadController(Chain);\n  s1 = loadService(S1);\n}\n\n// Controller类\n@Controller()\nclass Chain {\n  ctx: Context;\n  chain = loadController(Chain);\n  s1 = loadService(S1);\n\n  async result() {\n    return this.ctx.path;\n  }\n\n  @Get('/')\n  async index() {\n    // 支持无限调用下去，不管是在service，还是controller，都是支持的\n    return this.chain.chain.s1.s1.chain.chain.s1.s1.chain.chain.s1.s1.chain.chain.result();\n  }\n}\n\napp.use(chumi([Chain]));\n\napp.listen(9000);\n\n```\n\n## 全栈友好\n\n\u003e 1. chumi提供了`ChumiRequestData`和`ChumiResponseData`类型推导泛型函数，可以把控制器函数的入参和返回值类型推断出来\n\u003e\n\u003e 2. 方便在全栈项目中，前后端在接口这一块的入参和出参的数据类型保持一致\n\u003e\n\u003e 3. 具体可以参考完整项目 [`sample/chumi-types`](https://github.com/chumijs/chumi/blob/master/sample/chumi-types)，克隆当前项目，安装依赖后，执行`yarn vite dev --config sample/chumi-types/client/vite.config.ts`命令即可\n\n```ts\n// 核心示例代码\nimport { ChumiRequestData,ChumiResponseData } from 'chumi';\n\n// 接口通用返回格式，我们往往会用到data\n// 这里的data就是对应控制器函数的返回值\nexport interface ApiResponse\u003cT\u003e {\n  ret: 0 | -1;\n  msg: string;\n  data: T;\n}\n\n// 对定义API请求的函数的类型定义\nexport type ApiFunction\u003c\n  T extends abstract new (...args: any) =\u003e any,\n  S extends keyof InstanceType\u003cT\u003e\n\u003e = (...args: ChumiRequestData\u003cT, S\u003e) =\u003e Promise\u003cApiResponse\u003cChumiResponseData\u003cT, S\u003e\u003e\u003e;\n\nexport type ApiResponseData\u003c\n  T extends abstract new (...args: any) =\u003e any,\n  S extends keyof InstanceType\u003cT\u003e\n\u003e = (ReturnType\u003cApiFunction\u003cT, S\u003e\u003e extends Promise\u003cinfer U\u003e ? U : never)['data'];\n\n// 使用\n// 比如我有导入的控制器类为Ctr1，其上面有一个函数getName\n// 那么可以在前端定义如下接口函数\nexport const getName: ApiFunction\u003ctypeof Ctr1, 'getName'\u003e = async (id) =\u003e {\n  return await request.get(`/api/getName?id=${id}`);\n};\n\n// 获取Ctr1控制器里面的getName函数的返回值类型\n// 这里返回的数据，将直接提供给前端使用\n// 所以在全栈项目中，通过该类型，保证了前后端数据的一致性，提升健壮性\nexport type getNameData = ApiResponseData\u003ctypeof Ctr1, 'getName'\u003e;\n```\n\n## 更新日志\n\n点击查看详细的[更新日志](https://github.com/chumijs/chumi/blob/master/CHANGELOG.md)\n\n## License\n\n[MIT](https://github.com/chumijs/chumi/blob/master/LICENSE)\n\nCopyright (c) 2023-present, Topthinking\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fchumijs%2Fchumi.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fchumijs%2Fchumi?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchumijs%2Fchumi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchumijs%2Fchumi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchumijs%2Fchumi/lists"}