Skip to content

About

CRUD REST endpoints generated from a database table for AntelopeJS, with access rules, validation and pagination.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

2 watching

Forks

Latest commit

 

History

91 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@antelopejs/interface-data-api

npm License Discord Docs

CRUD REST endpoints generated from a database table: declare a data controller and its fields, and get get, list, new, edit and delete routes with access rules, validation and pagination.

What it offers

  • DataController and @RegisterDataController() turn a table class into a controller with the default routes you pick from DefaultRoutes.
  • @Access, @Mandatory and @Validator decide which fields each route reads and writes, and check them.
  • @Listable, @Sortable and @Filter shape the paginated list route.
  • @Foreign, @Joined and @Computed resolve references, flatten remote fields and add values computed in the database.

Implementations

The package runs in your module and has no implementing module of its own. The project needs modules that implement the interfaces it builds on:

Interface Module
@antelopejs/interface-api @antelopejs/api
@antelopejs/interface-database @antelopejs/mongodb or @antelopejs/rethinkdb

Install

Add the package and the interfaces your controllers import to your module:

pnpm add @antelopejs/interface-data-api @antelopejs/interface-api @antelopejs/interface-database-decorators

Then add the implementations to the project:

ajs project modules add @antelopejs/api @antelopejs/mongodb

Quick start

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");
}

The controller serves GET /tasks/get?id=, GET /tasks/list, POST /tasks/new, PUT /tasks/edit?id= and DELETE /tasks/delete?id=. Fields without @Access stay out of every response.

Documentation

Compatibility

Use with @antelopejs/core 1.x and the following peer dependencies:

Package Supported Tested with
@antelopejs/interface-api >=0.0.15 <1.0.0 0.0.15
@antelopejs/interface-api-util >=0.1.3 <1.0.0 0.1.3
@antelopejs/interface-core >=0.2.4 <1.0.0 0.2.4
@antelopejs/interface-database >=0.1.10 <1.0.0 0.1.11
@antelopejs/interface-database-decorators >=0.1.10 <1.0.0 0.1.10

Contributing

Read CONTRIBUTING.md before you open a pull request. The local checks are:

pnpm install
pnpm lint
pnpm test

License

Apache-2.0

About

CRUD REST endpoints generated from a database table for AntelopeJS, with access rules, validation and pagination.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages