-
Notifications
You must be signed in to change notification settings - Fork 0
feat(skills): ship a consumer skill with the package #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d51a9c6
feat(skills): ship a consumer skill with the package
Upd4ting 9c6ae90
address greptile review feedback (greploop iteration 1)
Upd4ting 7f18f9c
fix(skills): ship docs with the package
Upd4ting c4dea65
docs(skills): use fictional domains in code examples
Upd4ting File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| name: data-api-interface | ||
| 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. | ||
| category: antelopejs-interface | ||
| tags: [antelopejs, data-api, crud, rest, decorators] | ||
| --- | ||
|
|
||
| # Data API Interface | ||
|
|
||
| Declarative CRUD layer on top of `@antelopejs/interface-api` (HTTP) and | ||
| `@antelopejs/interface-database(-decorators)` (storage). You build a controller class with | ||
| `DataController(tableClass, routes, Controller("/path"))`, decorate fields to expose them, and get | ||
| `get/list/new/edit/delete` routes generated. Everything here is consumer-side: there is no proxy | ||
| point of its own to implement — the underlying api/database interfaces do the actual crossings, so | ||
| your module must also import those peer interfaces. | ||
|
|
||
| ## Imports | ||
|
|
||
| ```typescript | ||
| import { DataController, DefaultRoutes, RegisterDataController, GetDataControllerMeta } from "@antelopejs/interface-data-api"; | ||
| import { Access, AccessMode, Listable, Mandatory, Optional, Sortable, Filter, Foreign, Joined, Computed, Validator, ModelReference, ModifierKey } from "@antelopejs/interface-data-api/metadata"; | ||
| import { Parameters, Query, Validation } from "@antelopejs/interface-data-api/components"; | ||
| ``` | ||
|
|
||
| `/components` is only needed for custom route callbacks (query building, validation helpers). | ||
|
|
||
| ## Minimal consumption example | ||
|
|
||
| ```typescript | ||
| 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, RegisterTable, Table } from "@antelopejs/interface-database-decorators"; | ||
|
|
||
| @RegisterTable("tasks", "default") | ||
| 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, "my-database") | ||
| declare taskModel: TaskModel; | ||
|
|
||
| @Listable() | ||
| @Access(AccessMode.ReadOnly) | ||
| declare _id: string; | ||
|
|
||
| @Listable() | ||
| @Sortable() | ||
| @Mandatory("new") | ||
| @Access(AccessMode.ReadWrite) | ||
| declare summary: string; | ||
| } | ||
| ``` | ||
|
|
||
| This exposes `GET /tasks/get?id=`, `GET /tasks/list`, `POST /tasks/new`, `PUT /tasks/edit?id=`, | ||
| `DELETE /tasks/delete?id=` (repeat `id` to delete several). | ||
|
|
||
| ## Gotchas | ||
|
|
||
| - `@RegisterDataController()` is mandatory: it wires field decorators, parameter providers, and | ||
| routes. A `@ModelReference()` property holding a `@Model` instance is required too (`Query.GetModel` | ||
| throws 500 without it). | ||
| - Fields with no decorator are invisible to the API — neither returned nor writable; visibility | ||
| requires `@Access`. `@Optional()` only registers a field as not-mandatory (it does not expose it). | ||
| - `list` responds `{ results, total, offset, limit }`. `limit` defaults to 10 and is capped at 100 | ||
| (`maxPage`). Sorting uses `sortKey`/`sortDirection` query params and requires `@Sortable` on the | ||
| field (400 otherwise). List responses only include `@Listable` fields unless `noPluck` is set. | ||
| - Filters come from `filter_<name>=<mode>:<value>` query params (plain value means `eq`); modes are | ||
| `eq|ne|gt|ge|lt|le` (the default filter compares the raw query-string value — pass a custom filter | ||
| function to cast for numeric ranges). Only fields declared with `@Filter()` are filterable. | ||
| - `@Joined` and `@Computed` fields are materialized in-database, so `@Sortable` and `@Filter()` work | ||
| efficiently on them — but those decorators must still be applied explicitly. Such fields are | ||
| forced read-only and to non-indexed sorting. | ||
| - Route selection: pass a subset like `{ get: DefaultRoutes.Get, list: DefaultRoutes.List }` instead | ||
| of `DefaultRoutes.All`; use `DefaultRoutes.WithOptions(route, options, endpoint)` to rename an | ||
| endpoint or preset parameter options. | ||
| - `@Access` accepts per-action overrides, e.g. `@Access(AccessMode.ReadOnly, { edit: AccessMode.ReadWrite })`. | ||
|
|
||
| ## Deeper reference | ||
|
|
||
| See this package's `docs/` chapters — Introduction, Data Controllers, Routes, Access Rights, | ||
| Validators, Listable Fields, Foreign Keys, Filters, Modifiers, Joined Fields, Computed Fields — and | ||
| the shipped `.d.ts` files for exact signatures. Do not duplicate them here. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.