Repository navigation
docs(skills): describe ControllerClass typing and the Controller-only route rule - #106
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Module authors and agents who write a controller from the api-interface skill alone should see two breaking changes. #68 typed
ControllerClass, and #67 made a route decorator outside a Controller class throw.docs/2.controllers.mdandUPGRADING.mdcover both. The skill, which ships throughantelopeJs.skills, named neither.What
skills/api-interface/SKILL.mdnow says the following.Controller(location)returns aControllerClass<object>, so a bare instance has no string index.Controller(location, Base)returns aControllerClass<Base>that types the instances, with an example. Route decorators apply only to classes built byController,PartialControllerorextend, and to their subclasses. Any other class throwsTypeError: Route decorators apply to Controller classes; <name> has no locationwhen it is defined.skills/api-interface/cases.jsongainsapi-interface-route-on-plain-class, an eval case built on thatTypeError.Skill files only. No TSDoc or
docs/change, so this PR does not overlap ANT-1812.Proof
The code that enforces the documented rules:
src/controller.ts:276-289. TheControlleroverloads returnControllerClass<object>without a base andControllerClass<T>withbase: Class<T>.ControllerClass<T = object>is declared atsrc/controller.ts:9.src/routes.ts:131-136.ProcessCallback, which every route decorator calls, throws theTypeErrorwhenisControllerClass(target.constructor)is false.src/controller.ts:301-307.isControllerClassrequires the staticlocationandextendthatControllerandextendassign. Subclasses inherit both.src/tests/route-decorators.test.ts:91-97(refuse a method of a class that Controller did not create) andsrc/tests/controller-class-default.test.ts:10-17(names no string index on a bare ControllerClass instance).I type-checked the skill's new example in a scratch file under
src/withpnpm exec tsc --noEmit -p ., then deleted the file.StoreControllercompiled. AController("/bare")subclass that readthis.booksfailed as the skill says:pnpm run checksat 70acc3d: