diff --git a/skills/api-interface/SKILL.md b/skills/api-interface/SKILL.md index dde6e35..a1d45ff 100644 --- a/skills/api-interface/SKILL.md +++ b/skills/api-interface/SKILL.md @@ -79,6 +79,29 @@ Sub-paths: `class Sub extends BookController.extend("archive") {}` mounts at `/books/archive`. `PartialController(BookController)` reuses the same location (and inherited computed properties) to split routes across files. +Typing: `Controller(location)` returns a `ControllerClass`, so a bare +`ControllerClass` instance has no string index. To type the instances, pass a +base class: `Controller(location, Base)` returns a `ControllerClass` +that extends `Base`. + +```ts +class Store { + books = new Map(); +} + +export class StoreController extends Controller("/store", Store) { + @Get(":id") + async getBook(@Parameter("id") id: string) { + return new HTTPResult(200, this.books.get(id) ?? ""); + } +} +``` + +Route decorators apply only to classes built by `Controller`, +`PartialController` or `extend`, and to classes that extend them. On any other +class, the decorator throws `TypeError: Route decorators apply to Controller +classes; has no location` when the class is defined. + ## Gotchas - All decorators are factories and MUST be called, even with zero args: diff --git a/skills/api-interface/cases.json b/skills/api-interface/cases.json index 6f0fb75..b77bace 100644 --- a/skills/api-interface/cases.json +++ b/skills/api-interface/cases.json @@ -57,6 +57,17 @@ "acceptable": ["antelopejs", "ajs-consume-interface"], "mustMention": ["WebsocketHandler", "Connection"] } + }, + { + "id": "api-interface-route-on-plain-class", + "area": "framework", + "style": "clean", + "prompt": "My class has a @Get method, but loading the module throws \"TypeError: Route decorators apply to Controller classes; Handlers has no location\". What is wrong?", + "expect": { + "skills": ["api-interface"], + "acceptable": ["antelopejs", "ajs-consume-interface"], + "mustMention": ["Controller"] + } } ] }