@antelopejs/interface-data-api 0.1.5 → 0.1.7
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/dist/components.d.ts +3 -3
- package/dist/components.js +55 -5
- package/dist/components.js.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/tests/components/access_control.test.js +13 -0
- package/dist/tests/components/access_control.test.js.map +1 -1
- package/dist/tests/components/computed.test.js +10 -0
- package/dist/tests/components/computed.test.js.map +1 -1
- package/dist/tests/components/foreign_joined.test.js +18 -0
- package/dist/tests/components/foreign_joined.test.js.map +1 -1
- package/dist/tests/components/joined.test.js +105 -0
- package/dist/tests/components/joined.test.js.map +1 -1
- package/dist/tests/components/listable.test.js +25 -0
- package/dist/tests/components/listable.test.js.map +1 -1
- package/dist/tests/components/mandatory.test.js +21 -0
- package/dist/tests/components/mandatory.test.js.map +1 -1
- package/dist/tests/components/modifier_key.test.js +13 -0
- package/dist/tests/components/modifier_key.test.js.map +1 -1
- package/dist/tests/components/per_action_access.test.js +13 -0
- package/dist/tests/components/per_action_access.test.js.map +1 -1
- package/dist/tests/components/validator.test.js +25 -0
- package/dist/tests/components/validator.test.js.map +1 -1
- package/dist/tests/index/routes.test.js +13 -0
- package/dist/tests/index/routes.test.js.map +1 -1
- package/dist/tests/integration.test.js +169 -0
- package/dist/tests/integration.test.js.map +1 -1
- package/docs/1.introduction.md +128 -0
- package/docs/10.joined.md +146 -0
- package/docs/11.computed.md +152 -0
- package/docs/2.data-controllers.md +120 -0
- package/docs/3.routes.md +320 -0
- package/docs/4.access-rights.md +148 -0
- package/docs/5.validators.md +204 -0
- package/docs/6.listable.md +257 -0
- package/docs/7.foreign-keys.md +285 -0
- package/docs/8.filters.md +175 -0
- package/docs/9.modifiers.md +137 -0
- package/package.json +9 -4
- package/skills/data-api-interface/SKILL.md +91 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: data-api-interface
|
|
3
|
+
description: AntelopeJS interface that generates CRUD REST endpoints from a database table via a DataController class and field decorators (Access, Listable, Mandatory, Sortable, Filter, Foreign, Joined, Computed, Validator). Use when importing @antelopejs/interface-data-api or @antelopejs/interface-data-api/metadata, when building a data controller / data API over an interface-database table, or when working with DataController, DefaultRoutes, RegisterDataController, ModelReference, or filter_/sortKey/sortDirection list query parameters.
|
|
4
|
+
category: antelopejs-interface
|
|
5
|
+
tags: [antelopejs, data-api, crud, rest, decorators]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Data API Interface
|
|
9
|
+
|
|
10
|
+
Declarative CRUD layer on top of `@antelopejs/interface-api` (HTTP) and
|
|
11
|
+
`@antelopejs/interface-database(-decorators)` (storage). You build a controller class with
|
|
12
|
+
`DataController(tableClass, routes, Controller("/path"))`, decorate fields to expose them, and get
|
|
13
|
+
`get/list/new/edit/delete` routes generated. Everything here is consumer-side: there is no proxy
|
|
14
|
+
point of its own to implement — the underlying api/database interfaces do the actual crossings, so
|
|
15
|
+
your module must also import those peer interfaces.
|
|
16
|
+
|
|
17
|
+
## Imports
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { DataController, DefaultRoutes, RegisterDataController, GetDataControllerMeta } from "@antelopejs/interface-data-api";
|
|
21
|
+
import { Access, AccessMode, Listable, Mandatory, Optional, Sortable, Filter, Foreign, Joined, Computed, Validator, ModelReference, ModifierKey } from "@antelopejs/interface-data-api/metadata";
|
|
22
|
+
import { Parameters, Query, Validation } from "@antelopejs/interface-data-api/components";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`/components` is only needed for custom route callbacks (query building, validation helpers).
|
|
26
|
+
|
|
27
|
+
## Minimal consumption example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { Controller } from "@antelopejs/interface-api";
|
|
31
|
+
import { DataController, DefaultRoutes, RegisterDataController } from "@antelopejs/interface-data-api";
|
|
32
|
+
import { Access, AccessMode, Listable, Mandatory, ModelReference, Sortable } from "@antelopejs/interface-data-api/metadata";
|
|
33
|
+
import { BasicDataModel, Field, Model, RegisterTable, Table } from "@antelopejs/interface-database-decorators";
|
|
34
|
+
|
|
35
|
+
@RegisterTable("tasks", "default")
|
|
36
|
+
class Task extends Table {
|
|
37
|
+
declare _id: string;
|
|
38
|
+
|
|
39
|
+
@Field("string")
|
|
40
|
+
declare summary: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class TaskModel extends BasicDataModel(Task, "tasks") {}
|
|
44
|
+
|
|
45
|
+
@RegisterDataController()
|
|
46
|
+
class TaskAPI extends DataController(Task, DefaultRoutes.All, Controller("/tasks")) {
|
|
47
|
+
@ModelReference()
|
|
48
|
+
@Model(TaskModel, "my-database")
|
|
49
|
+
declare taskModel: TaskModel;
|
|
50
|
+
|
|
51
|
+
@Listable()
|
|
52
|
+
@Access(AccessMode.ReadOnly)
|
|
53
|
+
declare _id: string;
|
|
54
|
+
|
|
55
|
+
@Listable()
|
|
56
|
+
@Sortable()
|
|
57
|
+
@Mandatory("new")
|
|
58
|
+
@Access(AccessMode.ReadWrite)
|
|
59
|
+
declare summary: string;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This exposes `GET /tasks/get?id=`, `GET /tasks/list`, `POST /tasks/new`, `PUT /tasks/edit?id=`,
|
|
64
|
+
`DELETE /tasks/delete?id=` (repeat `id` to delete several).
|
|
65
|
+
|
|
66
|
+
## Gotchas
|
|
67
|
+
|
|
68
|
+
- `@RegisterDataController()` is mandatory: it wires field decorators, parameter providers, and
|
|
69
|
+
routes. A `@ModelReference()` property holding a `@Model` instance is required too (`Query.GetModel`
|
|
70
|
+
throws 500 without it).
|
|
71
|
+
- Fields with no decorator are invisible to the API — neither returned nor writable; visibility
|
|
72
|
+
requires `@Access`. `@Optional()` only registers a field as not-mandatory (it does not expose it).
|
|
73
|
+
- `list` responds `{ results, total, offset, limit }`. `limit` defaults to 10 and is capped at 100
|
|
74
|
+
(`maxPage`). Sorting uses `sortKey`/`sortDirection` query params and requires `@Sortable` on the
|
|
75
|
+
field (400 otherwise). List responses only include `@Listable` fields unless `noPluck` is set.
|
|
76
|
+
- Filters come from `filter_<name>=<mode>:<value>` query params (plain value means `eq`); modes are
|
|
77
|
+
`eq|ne|gt|ge|lt|le` (the default filter compares the raw query-string value — pass a custom filter
|
|
78
|
+
function to cast for numeric ranges). Only fields declared with `@Filter()` are filterable.
|
|
79
|
+
- `@Joined` and `@Computed` fields are materialized in-database, so `@Sortable` and `@Filter()` work
|
|
80
|
+
efficiently on them — but those decorators must still be applied explicitly. Such fields are
|
|
81
|
+
forced read-only and to non-indexed sorting.
|
|
82
|
+
- Route selection: pass a subset like `{ get: DefaultRoutes.Get, list: DefaultRoutes.List }` instead
|
|
83
|
+
of `DefaultRoutes.All`; use `DefaultRoutes.WithOptions(route, options, endpoint)` to rename an
|
|
84
|
+
endpoint or preset parameter options.
|
|
85
|
+
- `@Access` accepts per-action overrides, e.g. `@Access(AccessMode.ReadOnly, { edit: AccessMode.ReadWrite })`.
|
|
86
|
+
|
|
87
|
+
## Deeper reference
|
|
88
|
+
|
|
89
|
+
See this package's `docs/` chapters — Introduction, Data Controllers, Routes, Access Rights,
|
|
90
|
+
Validators, Listable Fields, Foreign Keys, Filters, Modifiers, Joined Fields, Computed Fields — and
|
|
91
|
+
the shipped `.d.ts` files for exact signatures. Do not duplicate them here.
|