thaitype / nammatham

Azure Functions Framework
https://nammatham.thaitype.dev/
MIT License
67 stars 2 forks source link

Infer type from NammathamApp Endpoints #124

Open mildronize opened 10 months ago

mildronize commented 10 months ago

Considering the new way to register functions

Do with:

Before

app.addFunctions(blob, hello);

After

Note: remove function name from httpGet first arg

export const myApp = app.addFunctions({ blob, hello });

// Register functions via object, may support type infer in the future
// type Endpoint = InferEndpoint<typeof myApp>

const userFunction = app.createFunctions({
  user: func.httpGet().handler(({ res }) => res.text('OK'));
});

app.mergeFunctions(userFunction);

Existing way

const userFunction = func.httpGet().handler( c => c.text('OK'));

app.addFunctions({
  user: userFunction
});

Single File

import { initNammatham, AzureFunctionsAdapter, expressPlugin } from "nammatham";

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

n.app.addFunctions({
  user: n.func.httpGet().handler( c => c.text('user'));
  post: n.func.httpGet().handler( c => c.text('post'));
})
.register(expressPlugin())
.start();

Standalone Mode (Like azure Function node.js library)

without using nammathamApp;

import { AzureFunctionsTrigger } from "nammatham";

new AzureFunctionsTrigger()
  .httpGet({ name: 'hello' })
  .handler( c => c.text('user'));
  .register();
mildronize commented 7 months ago

PoC defintion at branch: main.poc-inverisfyPlugin-type-safe