@pylonts/runtime
v1.1.2
Published
Flow runtime layer — local direct-invocation runtime (scan controllers → DirectRouter); HTTP runtime planned
Readme
@pylonts/runtime
Runtime layer for @pylonts/flow — provides the deps consumed by flow api
steps. Flow steps stay environment-agnostic: they call
deps.getModule(name).getController(Cls).method(body) and swap the runtime
(local / http) without changing flow code.
Local runtime (implemented)
In-process direct invocation — scans project controllers, builds a
DirectRouter (inline controller calls, no HTTP server), and exposes
per-module ModuleHandlers.
import { runLocalFlow } from '@pylonts/runtime';
const flow = await runLocalFlow({
flowsDir: 'flow/flows',
cwd: 'api-admin',
names: ['adminAddBd', 'bdLogin', 'registerMerchant'],
});Or compose manually with createLocalRuntime + @pylonts/flow's
scanFlows/runSteps when finer control is needed:
import { createLocalRuntime } from '@pylonts/runtime';
import { scanFlows, runSteps } from '@pylonts/flow';
const runtime = await createLocalRuntime({ cwd: 'api-admin' });
const index = scanFlows('flow/flows');
const flow = await runSteps({
index,
driver: 'api',
deps: runtime, // { getModule(name) }
names: ['adminAddBd', 'bdLogin', 'registerMerchant'],
});- Controller scan + route registration:
@pylonts/corescanFromDirectory/createDirectRouter(reused, not reimplemented) - Project config scan:
<cwd>/src/config.ts'sdbConfigexport is picked up automatically →createDaoKnexinitializes the global DAO (or passdbConfigexplicitly) - Auth:
module.ctx.token— the facade injects it into every handler call - Instance: default
new controllerClass()(module-level singleton services work out of the box) bootstraphook: project-specific environment singletons that live in framework modules (e.g.@pylonts/token-redis-driver'sinitTokenRedis) — the local runtime stays framework-agnostic and lets the project init them
Planned
- HTTP runtime — real API calls (HMAC 签名 + token 会话, reusing
@pylonts/api-clientsigning/session lifecycle)
API
runLocalFlow({ flowsDir, names, cwd?, bootstrap? })— recommended entry: scan → runtime → runStepscreateLocalRuntime({ cwd?, pattern?, resolveModuleConfig?, dbConfig?, configFile?, bootstrap? })→{ router, modules, getModule(name) }ApiDeps—Pick<LocalRuntime, 'getModule'>, the deps type flow api steps importModuleHandler/ControllerProxy/HandlerNotFoundError— module ctx + typed lazy controller access (from ts-flow, now shared)
