@faapi/faapi 0.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/cli/index.js +5743 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +786 -0
- package/dist/index.js +665 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 faapi contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# faapi
|
|
2
|
+
|
|
3
|
+
> 函数即接口 — Function as API
|
|
4
|
+
|
|
5
|
+
faapi 是一个 Node.js 框架,核心理念是"函数即接口"。编写普通 TypeScript 函数即可暴露为 HTTP / WebSocket 接口,类型校验由 TypeScript AST 自动生成,无需手写 schema。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @faapi/faapi
|
|
11
|
+
# 或
|
|
12
|
+
npm install @faapi/faapi
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
要求 Node.js >= 22。
|
|
16
|
+
|
|
17
|
+
## 快速开始
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// app/api/user/handler.ts
|
|
21
|
+
export interface Query {
|
|
22
|
+
page: number;
|
|
23
|
+
pageSize: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function GET(query: Query) {
|
|
27
|
+
return { page: query.page, pageSize: query.pageSize };
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 启动 dev server
|
|
33
|
+
npx faapi
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
访问 `http://localhost:3000/api/user?page=1&pageSize=10` 即可。
|
|
37
|
+
|
|
38
|
+
## 核心能力
|
|
39
|
+
|
|
40
|
+
- 函数即接口:导出 `GET`/`POST` 等函数即声明路由
|
|
41
|
+
- AST 类型校验:TypeScript Compiler API 自动生成运行时校验
|
|
42
|
+
- 洋葱模型中间件:`(ctx, next) => {}`
|
|
43
|
+
- 依赖注入:注入器按参数名匹配 handler 参数
|
|
44
|
+
- WebSocket 路由:导出 `WS` 函数声明
|
|
45
|
+
- SSE 流式响应:`ctx.sse()` 推送
|
|
46
|
+
- 动态路由:`[id]` / `[...slug]` / `(group)`
|
|
47
|
+
- MCP 集成:LLM 可查询路由 schema
|
|
48
|
+
- 配置文件:`faapi.config.ts` 统一响应格式、全局错误处理、生命周期钩子、全局中间件/注入器
|
|
49
|
+
- ESM only
|
|
50
|
+
|
|
51
|
+
## 文档
|
|
52
|
+
|
|
53
|
+
完整文档见 [GitHub 仓库](https://github.com/faapi/faapi#readme)。
|
|
54
|
+
|
|
55
|
+
- [架构与约定](https://github.com/faapi/faapi/blob/main/AGENTS.md)
|
|
56
|
+
- [中间件系统](https://github.com/faapi/faapi/blob/main/packages/faapi/src/middleware/README.md)
|
|
57
|
+
- [路由系统](https://github.com/faapi/faapi/blob/main/packages/faapi/src/router/README.md)
|
|
58
|
+
- [运行时](https://github.com/faapi/faapi/blob/main/packages/faapi/src/runtime/README.md)
|
|
59
|
+
- [配置](https://github.com/faapi/faapi/blob/main/packages/faapi/src/config/README.md)
|
|
60
|
+
- [CLI](https://github.com/faapi/faapi/blob/main/packages/faapi/src/cli/README.md)
|
|
61
|
+
|
|
62
|
+
## 许可证
|
|
63
|
+
|
|
64
|
+
[MIT](https://github.com/faapi/faapi/blob/main/LICENSE)
|