@intent-driven/importer-controllers
v0.6.0
Published
AST-парсер controllers (Express, Fastify, Nest, Rails) → IDF intent suggestions
Downloads
1,072
Maintainers
Readme
@intent-driven/importer-controllers
AST-парсер controllers (Express, Fastify, Nest, Rails — постепенно) → suggested IDF intents.
Текущая поддержка
| Framework | Статус |
|-----------|--------|
| Express | ✅ v0.1 |
| Fastify | ✅ v0.2 — все 4 patterns: app.<method>(path, handler), 3-arg form (path, opts, handler), declarative app.route({...}), array app.route([{...}]) |
| NestJS | вынесено в @intent-driven/importer-nestjs-typeorm (декораторы Nest + TypeORM в одном пакете) |
| Rails | планируется (PR 4d, opt-in deps) |
Fastify-specific patterns
// Все четыре формы понимаются:
fastify.get('/api/orders', listOrders);
fastify.get('/api/orders', { schema: orderSchema }, listOrders); // 3-arg
fastify.route({ // declarative
method: 'POST',
url: '/api/orders',
preHandler: [authenticated, validateBody],
handler: createOrder,
});
fastify.route([ // array
{ method: 'GET', url: '/api/products', handler: list },
{ method: 'POST', url: '/api/products', handler: create },
]);method: ['GET', 'POST'] (Fastify multi-method) — берётся первый. url или path — оба ключа допустимы.
Использование
import { importControllers } from "@intent-driven/importer-controllers";
const { intents, routes, files } = await importControllers("./src/routes");
console.log(intents);
// [
// {
// name: "create_order",
// target: "Order",
// alpha: "insert",
// method: "POST",
// httpPath: "/api/orders",
// handlerNames: ["validateBody", "createOrderHandler"],
// sources: [{ file: "./src/routes/orders.js", line: 42 }]
// },
// ...
// ]Naming heuristics
POST /api/orders → create_order (alpha=insert)
GET /api/orders → list_orders (alpha=null, read-only)
GET /api/orders/:id → read_order (alpha=null)
PUT /api/orders/:id → update_order (alpha=replace)
PATCH /api/orders/:id → patch_order (alpha=replace)
DELETE /api/orders/:id → delete_order (alpha=remove)
POST /api/orders/:id/cancel → cancel_order (alpha=replace, action-segment)Распознаваемые actions: cancel, approve, reject, publish, archive, unarchive, submit, complete, restore, lock, unlock.
Limitations (PR 4a)
- Только Express-style
app.get|post|put|delete|patch|head|options|all(path, handlers) - Только
app/router/api/serverwhitelist —myCustomThing.get(...)пропускается - Path должен быть string-literal — динамические path игнорируются
- Без TypeScript decorators (Nest) и без routes.rb (Rails)
Roadmap
- 4b — Fastify (
server.get({ url, handler })) - 4d — Rails (
Rails.application.routes.drawчерез ruby parser) - 4e — CLI integration:
idf import controllers <dir>в@intent-driven/cli - 4f — LLM enrichment: synergy с
enricher-claudeдля уточнения intent.alpha и invariants
License
MIT.
