Stone.jsDocs
Paradigm

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

terminalbash
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.

app/Application.tsdeclarativeimperative
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.

index.jsts
// 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.

app/Application.tsts
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.

terminalbash
npm run build
s deploy   # Serverless Devs

#Triggers

PackageTypeDescription
@stone-js/alibaba-fc-http-adapter@AlibabaFcHttpHTTP-triggered functions (FC 2.0 req/resp/context). Use with @Routing.
@stone-js/alibaba-fc-adapter@AlibabaFcGeneric event triggers (OSS, MNS, Timer, EventBridge, Log).

Stone.js

Your app exists in every runtime. Until you run it.

An open-source project by Stone Foundation
Created by Mr. Stone (Evens Pierre)