@loutrejs/loutre
v0.10.1
Published
LoutreのApplication Graph Kernelです。Application Definition / Model、Module、DI、Environment、Arguments、Lifecycle、Runtime Capability、generic Layer、Kernel bootstrapを提供します。
Readme
@loutrejs/loutre
LoutreのApplication Graph Kernelです。Application Definition / Model、Module、DI、Environment、Arguments、Lifecycle、Runtime Capability、generic Layer、Kernel bootstrapを提供します。
HTTP、Task、MessagePort、WebSocketは同じpackageのsubpathからExecution Extensionとして提供します。
Install
npm install @loutrejs/loutre新しいApplicationはinitializerから作成できます。
npm create loutre@latest my-appApplication Model
Applicationの構成はdefineApplication()でcanonical Application Modelへcompileされます。
import { defineApplication, defineModule } from '@loutrejs/loutre'
import { http } from '@loutrejs/loutre/http'
import { z } from 'zod'
const HealthContract = http.contract({
health: {
method: 'GET',
path: '/health',
responses: {
ok: { status: 200, body: z.string() },
},
},
})
const HealthHttp = http.implementation({
name: 'HealthHttp',
contract: HealthContract,
factory: () => ({
health: (ctx) => ctx.response.ok({ body: 'ok' }),
}),
})
const AppModule = defineModule({
executions: [HealthHttp],
})
export default defineApplication({ modules: [AppModule] })Kernel bootstrap
portableなApplicationはroot packageから起動できます。
import { bootstrapApplication } from '@loutrejs/loutre'
import { bindHttpServer } from '@loutrejs/loutre/http'
const app = await bootstrapApplication({
application,
capabilities: [bindHttpServer({ runtime: 'test' })],
})
const response = await app.http.fetch(new Request('http://localhost/health'))ExtensionがApplication Modelに存在するときだけ、そのExtensionのHost APIがApplicationへ合成されます。
Entry points
| Entry point | Role |
| ------------------------------- | --------------------------------------------- |
| @loutrejs/loutre | Application Graph Kernel / Kernel bootstrap |
| @loutrejs/loutre/http | HTTP Execution Extension |
| @loutrejs/loutre/tasks | Task / Trigger / Queue Execution Extension |
| @loutrejs/loutre/message-port | MessagePort Execution Extension |
| @loutrejs/loutre/websocket | WebSocket Execution Extension |
| @loutrejs/loutre/graph | Application Model graph projection |
| @loutrejs/loutre/runtime | Runtime capability / Kernel runtime primitive |
| @loutrejs/loutre/http/openapi | OpenAPI projection |
| @loutrejs/loutre/presentation | startup presentation |
| @loutrejs/loutre/runtime/* | portable Runtime adapter |
Node.js listener ownership is provided by @loutrejs/node.
Architecture invariant
Core never interprets HTTP, Task, MessagePort, or WebSocket identity. Execution Extensions compile their definitions into the single Application Model and own their runtime semantics, Host API, and Graph projection.
