Adapters
Alibaba Cloud Function Compute
Alibaba Cloud Function Compute is the largest serverless platform in China, with a global footprint. Its HTTP trigger (FC 2.0) invokes the function with (req, resp, context), a plain request (body pre-read into a Buffer) and an imperative response. @stone-js/alibaba-fc-http-adaptermaps that to an intention, runs your kernel, and writes the response, so your routes run on FC unchanged.
#Install
npm i @stone-js/alibaba-fc-http-adapter#Enable it
Add the decorator (or the blueprint) to the manifest. Your routes, validation, cookies and request/response model are the runtime-agnostic ones from @stone-js/http-core; nothing in the domain changes.
import { StoneApp } from '@stone-js/core'
import { Routing } from '@stone-js/router'
import { AlibabaFcHttp } from '@stone-js/alibaba-fc-http-adapter'
@AlibabaFcHttp() // Alibaba FC HTTP trigger
@Routing()
@StoneApp({ name: 'tasks' })
export class Application {}import { defineStoneApp } from '@stone-js/core'
import { routerBlueprint } from '@stone-js/router'
import { alibabaFcHttpAdapterBlueprint } from '@stone-js/alibaba-fc-http-adapter'
export const App = defineStoneApp(
{ name: 'tasks' },
[routerBlueprint, alibabaFcHttpAdapterBlueprint]
)#Register the handler
run() returns the (req, resp, context) handler FC invokes. Export it as the function entry point.
// The FC HTTP function entry
exports.handler = await stoneApp.run()#Generic (non-HTTP) triggers
For triggers that are not HTTP, an OSS object change, an MNS/queue message, a Timer or an EventBridge event, use the generic @stone-js/alibaba-fc-adapter with @AlibabaFc(). The function is invoked with (event, context); the adapter normalizes it into an intention whose metadata carries the event payload, so one handler can dispatch on the trigger.
import { AlibabaFc } from '@stone-js/alibaba-fc-adapter'
@AlibabaFc()
@StoneApp({ name: 'workers' })
export class Application {}On a thrown error the adapter rethrows by default so FC applies its retry / dead-letter policy; opt out with stone.adapter.rethrowOnError = false.
#Deploy
Build the function output and deploy with Serverless Devs (s deploy) or the console. The per-invocation container matches the Continuum's per-event context exactly.
npm run build
s deploy # Serverless Devs#Triggers
| Package | Type | Description |
|---|---|---|
| @stone-js/alibaba-fc-http-adapter | @AlibabaFcHttp | HTTP-triggered functions (FC 2.0 req/resp/context). Use with @Routing. |
| @stone-js/alibaba-fc-adapter | @AlibabaFc | Generic event triggers (OSS, MNS, Timer, EventBridge, Log). |