@antelopejs/interface-data-api
从一个数据库表格中生成 CRUD REST 端点的羚羊JS 接口. 宣布一个数据控制器及其字段,为 get, (中文(简体) ), list, (中文(简体) ), new, (中文(简体) ), edit 财务报告和审定财务报表 delete 具有进入规则、验证和标记的路线.
部分 羚羊JS用于 羚羊JS 隐形物,用于您的 PostgreSQL 、 MongoDB 或 RethinkDB 数据库的开源后台.
它提供的东西
DataController财务报告和审定财务报表@RegisterDataController()将表格类变成控制器,并附带您从中选择的默认路径DefaultRoutes。 。 。 .@Access决定每个路由读取和写入的字段 .@Mandatory财务报告和审定财务报表@Validator检查书面值.@Listable, (中文(简体) ),@Sortable财务报告和审定财务报表@Filter形状list路线.@Foreign, (中文(简体) ),@Joined财务报告和审定财务报表@Computed解析引用,平整远程字段,并添加数据库中计算的值.
执行情况
软件包在您的模块中运行,没有自己的执行模块. 项目需要执行它所依赖的接口的模块.
| 接口 | 模块 |
|---|---|
@antelopejs/interface-api | @antelopejs/api |
@antelopejs/interface-database | @antelopejs/mongodb 或者说 @antelopejs/rethinkdb |
安装
将软件包及其对等界面添加到您的模块中.
pnpm add @antelopejs/interface-data-api @antelopejs/interface-api @antelopejs/interface-api-util @antelopejs/interface-core @antelopejs/interface-database @antelopejs/interface-database-decorators
然后在项目中添加执行内容.
ajs project modules add @antelopejs/api @antelopejs/mongodb
快开始
import { Controller } from "@antelopejs/interface-api";
import {
DataController,
DefaultRoutes,
RegisterDataController,
} from "@antelopejs/interface-data-api";
import {
Access,
AccessMode,
Listable,
Mandatory,
ModelReference,
Sortable,
} from "@antelopejs/interface-data-api/metadata";
import {
BasicDataModel,
Field,
Model,
RegisterSchema,
RegisterTable,
Table,
} from "@antelopejs/interface-database-decorators";
@RegisterTable("tasks", "todo")
class Task extends Table {
declare _id: string;
@Field("string")
declare summary: string;
}
class TaskModel extends BasicDataModel(Task, "tasks") {}
@RegisterDataController()
class TaskAPI extends DataController(
Task,
DefaultRoutes.All,
Controller("/tasks"),
) {
@ModelReference()
@Model(TaskModel)
declare taskModel: TaskModel;
@Listable()
@Access(AccessMode.ReadOnly)
declare _id: string;
@Listable()
@Sortable()
@Mandatory("new")
@Access(AccessMode.ReadWrite)
declare summary: string;
}
export async function construct() {
await RegisterSchema("todo");
}
控制器服务 GET /tasks/get?id=, (中文(简体) ), GET /tasks/list, (中文(简体) ), POST /tasks/new, (中文(简体) ), PUT /tasks/edit?id= 财务报告和审定财务报表 DELETE /tasks/delete?id=字段 @Access 除非 @Joined 或者说 @Computed 让它只读.
文档
兼容性
软件包宣布这些 @antelopejs/* 相对依赖.
| 软件包 | 支助 | 测试过 |
|---|---|---|
@antelopejs/interface-api | >=0.3.0 <1.0.0 | 0.2.0 |
@antelopejs/interface-api-util | >=0.1.3 <1.0.0 | 0.3.0 |
@antelopejs/interface-core | >=0.2.4 <1.0.0 | 0.4.0 |
@antelopejs/interface-database | >=0.1.10 <1.0.0 | 0.3.0 |
@antelopejs/interface-database-decorators | >=0.1.10 <1.0.0 | 0.2.0 |
捐款
读取 捐款额 在你打开拉动请求之前。 用这些命令进行本地检查.
pnpm install
pnpm lint
pnpm test