@danceroutine/tango-adapters-nuxt
v1.10.3
Published
Nuxt Nitro adapter for Tango viewsets
Readme
@danceroutine/tango-adapters-nuxt
@danceroutine/tango-adapters-nuxt runs Tango views and viewsets inside Nuxt Nitro event handlers.
Nuxt still owns pages, layouts, SSR rendering, and deployment model concerns. This package exists to connect Nitro's event-handler contract to Tango's framework-agnostic resource layer cleanly, so a Tango API can live inside a Nuxt codebase without forcing the resource layer to become Nuxt-specific.
Install
pnpm add @danceroutine/tango-adapters-nuxt nuxt vueIn practice, you will pair this package with Tango schema, ORM, and resources packages.
How it fits into a Nuxt application
A typical Tango + Nuxt stack looks like this:
- define models with
@danceroutine/tango-schema - query and mutate data through
Model.objectsfrom@danceroutine/tango-orm - expose that model-backed behavior through Tango views or viewsets
- adapt those handlers to Nitro event handlers with
NuxtAdapter - register those handlers explicitly through
serverHandlersinnuxt.config.ts
This package is concerned solely with steps 4 and 5. It receives Nuxt Nitro events, invokes the Tango handler, and returns a response in the shape Nitro expects.
Quick start
import { NuxtAdapter } from '@danceroutine/tango-adapters-nuxt';
import { TodoViewSet } from '~/viewsets/TodoViewSet';
const adapter = new NuxtAdapter();
export default adapter.adaptViewSet(new TodoViewSet());Then register that handler in nuxt.config.ts:
export default defineNuxtConfig({
serverHandlers: [
{ route: '/api/todos', handler: './server/tango/todos.ts' },
{ route: '/api/todos/**:tango', handler: './server/tango/todos.ts' },
],
});That gives the adapter one handler for the collection route at /api/todos and the catch-all detail and custom-action routes under /api/todos/**.
Use adaptViewSet(...) when you already have a ready viewset instance in hand. Use adaptViewSetFactory(...) when constructing the viewset requires asynchronous setup. The factory result is memoized inside the adapter, and initialization failures clear that memoized promise so a later request can retry cleanly.
Public API
The root export includes:
NuxtAdapter, the main integration classAdaptNuxtOptionsandAdaptNuxtViewSetOptions- route-facing helper types such as
NuxtAPIView,NuxtCrudViewSet,NuxtEventHandler, andNuxtViewSetFactory
The main adapter entry points are:
adaptViewSet(...)for an already constructed viewsetadaptViewSetFactory(...)for lazy async viewset constructionadaptAPIView(...)forAPIViewadaptGenericAPIView(...)forGenericAPIView-style collection/detail dispatchadaptGenericAPIViewFactory(...)for lazy generic API view construction
NuxtAdapter also exposes toQueryParams(...) for application code that wants the same normalized query contract resources use internally.
Documentation
- Official documentation: https://tangowebframework.dev
- Nuxt blog tutorial: https://tangowebframework.dev/tutorials/nuxt-blog
- API layer topic: https://tangowebframework.dev/topics/api-layer
Development
pnpm --filter @danceroutine/tango-adapters-nuxt build
pnpm --filter @danceroutine/tango-adapters-nuxt typecheck
pnpm --filter @danceroutine/tango-adapters-nuxt testLicense
MIT
