JSPM

@intent-driven/importer-controllers

0.5.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q59406F
  • License MIT

AST-парсер controllers (Express, Fastify, Nest, Rails) → IDF intent suggestions

Package Exports

  • @intent-driven/importer-controllers

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 планируется (PR 4c)
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 / server whitelist — myCustomThing.get(...) пропускается
  • Path должен быть string-literal — динамические path игнорируются
  • Без TypeScript decorators (Nest) и без routes.rb (Rails)

Roadmap

  • 4b — Fastify (server.get({ url, handler }))
  • 4c — NestJS (@Controller, @Get, @Post decorators)
  • 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.