Skip to content

thaitype/nammatham

Repository files navigation

Nammatham Logo

Type-safe Serverless Library for Azure Functions and friends

npm version npm download

🚧 Alpha Stage: Internal Use Only 🚧

Please note that Nammatham v2 is currently in its Alpha stage and is intended for internal use only. As we actively develop and refine the platform, be aware that the API may undergo frequent changes.

Note: Nammatham v1 is currently in maintenance mode. no new features are actively being developed

Version Status Azure Functions Node.js Branch Build Status
v1.x Maintenance v3.x v1.x Build & Test codecov
v2.x Alpha v4.x main Tracking v2 Roadmap

Description

Nammatham (นามธรรม in Thai, pronounced /naam ma tham/, means abstract in Thai) is Azure Function Nodejs.

Getting Started for Azure Functions

You can see examples or follow the minimal app getting started below:

import { AzureFunctionsAdapter } from "@nammatham/azure-functions";
import { initNammatham } from "@nammatham/core";
import { expressPlugin } from "@nammatham/express";

const n = initNammatham.create(new AzureFunctionsAdapter());
const func = n.func;
const app = n.app;

const helloFunction = func
  .httpGet('hello', {
    route: 'hello-world',
  })
  .handler(async (request, ctx) => {
    ctx.context.log('HTTP trigger function processed a request.');
    ctx.context.debug(`Http function processed request for url "${request.url}"`);
    const name = request.query.get('name') || (await request.text()) || 'world';
    return { body: `Hello, ${name}!` };
  });

app.addFunctions(helloFunction);
app.register(expressPlugin());
app.start();

Then edit package.json like this;

{
  "main": "dist/src/main.js",
  "scripts": {
    "dev": "cross-env NAMMATHAM_ENV=development tsx watch src/main.ts",
    "start": "tsc && func start"
  }
}

Run Dev Server on locally, (For dev server use tsx watch for reloading run dev server using express )

npm run dev

Run Azure Functions on locally (Using Official Azure Functions Node.js)

npm start

Nammatham Packages

  • core, Nammatham Core package for initializing Nammatham App

Available Adatpers

Available Plugins

  • express, Express Plugin for run server. Nammatham itself doesn't contain any server, enabling this plugin to provide better DX than the original server e.g. Azure Functions Runtime
  • trpc-azure-functions, provide tRPC Plugin for Azure Functions, inclduing express server for local testing.

Talks

Empowering TypeScript on Azure Functions with Nammatham, Azure Open Source Day @ Microsoft Thailand, 25 Mar 2023 (Thai speech, subtitle will added later)

Inspiration

Author

  • Thada Wangthammang, Software Engineer, Thailand