Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC Azure/Functions v4 fit with Nammatham APIs (Functional Approach & Type-safe) #82

Closed
mildronize opened this issue Sep 18, 2023 · 3 comments · Fixed by #83
Closed
Labels
func-v4 Azure Functions Node.js v4 Related Issues v2-experiment V2 Experiment Version
Milestone

Comments

@mildronize
Copy link
Collaborator

mildronize commented Sep 18, 2023

From my research, TypeScript 5.0 Decorator support more type-safe decorator, however, most popular typeScript Dependency Injection currently support below TypeScript 5.0 Decorator which must provide following tsconfig.json

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

With TypeScript 5.0 Decorator can evict both tsconfig.json.

Currently issues that most popular is already stuck with TypeScript Decorator below version 5.0:

Another issues about Inversify currently find the new maintainer

@mildronize mildronize added the func-v4 Azure Functions Node.js v4 Related Issues label Sep 18, 2023
@mildronize
Copy link
Collaborator Author

PoC Branch: poc-func-v4.functional-type-safe based on poc-func-v4

@mildronize
Copy link
Collaborator Author

mildronize commented Sep 25, 2023

My PoC and tested with the official v4 azure functions lib

result is in branch: poc-func-v4.functional-type-safe , next.v2-experiment

/**
 * Nammatham v2 - Proof of concept: Type-safe & Functional Style
 * 
 * Github Issue: https://github.com/thaitype/nammatham/issues/82
 * Implementation: https://github.com/thaitype/nammatham/blob/poc-func-v4.functional-type-safe/examples/with-functional/src/functions/copyBlob1.ts
 */

import { initNammatham } from '@nammatham/core';

const nmt = initNammatham.create();

nmt
  .httpGet('CopyBlob', {
    authLevel: 'anonymous',
  })
  .addInput(
    'blobInput',
    nmt.input.storageBlob({
      connection: 'AzureWebJobsStorage',
      path: 'demo-input/xxx.txt',
    })
  )
  .addOutput(
    'blobOutput',
    nmt.output.storageBlob({
      connection: 'AzureWebJobsStorage',
      path: 'demo-output/xxx-{rand-guid}.txt',
    })
  )
  .handler((request, context) => {
    context.log('function processed work item:', request);
    const blobInputValue = context.inputs.blobInput.get();

    context.outputs.blobOutput.set(blobInputValue);
    return {
      body: `Hello ${blobInputValue}`,
    };
  });

@mildronize mildronize added the v2 Nammatham v2 Related issues label Sep 26, 2023
@mildronize mildronize added this to the Version 2.0 milestone Sep 26, 2023
@mildronize mildronize added v2-experiment V2 Experiment Version and removed v2 Nammatham v2 Related issues labels Dec 23, 2023
@mildronize
Copy link
Collaborator Author

The PoC implements addInput and addOutput, it can lead more complex to maintain in the future, so, in v2 upcoming release, it will use inputs and outputs helpers directly from Azure functions packages (@azure/[email protected])

As you can see in the alpha release of v2, you can see the example to use inputs and outputs helpers directly from Azure functions packages, as following code below:

import { input } from '@azure/functions';
import { func } from '../nammatham';

const blobInput = input.storageBlob({
  connection: 'AzureWebJobsStorage',
  path: 'demo-input/xxx.txt',
});

const blobOutput = input.storageBlob({
  connection: 'AzureWebJobsStorage',
  path: 'demo-output/xxx-{rand-guid}.txt',
});

export default func
  .httpGet('CopyBlob', {
    authLevel: 'anonymous',
    extraInputs: [blobInput],
    extraOutputs: [blobOutput],
  })
  .handler((request, ctx) => {
    ctx.context.log('function processed work item:', request);
    const blobInputValue = ctx.context.extraInputs.get(blobOutput);

    ctx.context.extraOutputs.set(blobOutput, blobInputValue);
    return {
      body: `Hello ${blobInputValue}`,
    };
  });

This issue is quite good to PoC how make Nammatham has more fluent APIs, however, this will mark as v2-experiment instead, it can be considered to implement in the future release.

So, this issue can be close now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
func-v4 Azure Functions Node.js v4 Related Issues v2-experiment V2 Experiment Version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant