From bd39d0d2db56d84d58431d2c791bbe56f145fc1e Mon Sep 17 00:00:00 2001 From: Thada Wangthammang Date: Fri, 1 Mar 2024 21:02:39 +0700 Subject: [PATCH 1/5] feat: make initNammatham.create init AzureFunctions as default adapter when use from main package --- examples/azure-functions-minimal/src/main.ts | 4 ++-- .../azure-functions-timer-trigger/src/nammatham.ts | 4 ++-- .../src/nammatham.ts | 4 ++-- .../azure-functions-with-test/src/nammatham.ts | 3 +-- .../azure-functions-with-trpc/src/nammatham.ts | 4 ++-- examples/azure-functions/src/nammatham.ts | 4 ++-- packages/core/src/init-nammatham.ts | 14 +++++++++----- packages/main/src/main.ts | 10 +++++++++- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/azure-functions-minimal/src/main.ts b/examples/azure-functions-minimal/src/main.ts index f9e845e7..96b909e4 100644 --- a/examples/azure-functions-minimal/src/main.ts +++ b/examples/azure-functions-minimal/src/main.ts @@ -1,6 +1,6 @@ -import { AzureFunctionsAdapter, initNammatham, expressPlugin } from 'nammatham'; +import { initNammatham, expressPlugin } from 'nammatham'; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); const func = n.func; const app = n.app; diff --git a/examples/azure-functions-timer-trigger/src/nammatham.ts b/examples/azure-functions-timer-trigger/src/nammatham.ts index 280c2100..f321be24 100644 --- a/examples/azure-functions-timer-trigger/src/nammatham.ts +++ b/examples/azure-functions-timer-trigger/src/nammatham.ts @@ -1,6 +1,6 @@ -import { initNammatham, AzureFunctionsAdapter } from 'nammatham'; +import { initNammatham } from 'nammatham'; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); n.func; // ^? export const func = n.func; diff --git a/examples/azure-functions-with-inversify/src/nammatham.ts b/examples/azure-functions-with-inversify/src/nammatham.ts index 280c2100..f321be24 100644 --- a/examples/azure-functions-with-inversify/src/nammatham.ts +++ b/examples/azure-functions-with-inversify/src/nammatham.ts @@ -1,6 +1,6 @@ -import { initNammatham, AzureFunctionsAdapter } from 'nammatham'; +import { initNammatham } from 'nammatham'; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); n.func; // ^? export const func = n.func; diff --git a/examples/azure-functions-with-test/src/nammatham.ts b/examples/azure-functions-with-test/src/nammatham.ts index 29502804..e337a0fc 100644 --- a/examples/azure-functions-with-test/src/nammatham.ts +++ b/examples/azure-functions-with-test/src/nammatham.ts @@ -1,7 +1,6 @@ import { initNammatham } from 'nammatham'; -import { AzureFunctionsAdapter } from 'nammatham'; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); export const func = n.func; export const app = n.app; diff --git a/examples/azure-functions-with-trpc/src/nammatham.ts b/examples/azure-functions-with-trpc/src/nammatham.ts index a1755eca..e337a0fc 100644 --- a/examples/azure-functions-with-trpc/src/nammatham.ts +++ b/examples/azure-functions-with-trpc/src/nammatham.ts @@ -1,6 +1,6 @@ -import { initNammatham, AzureFunctionsAdapter } from 'nammatham'; +import { initNammatham } from 'nammatham'; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); export const func = n.func; export const app = n.app; diff --git a/examples/azure-functions/src/nammatham.ts b/examples/azure-functions/src/nammatham.ts index 280c2100..f321be24 100644 --- a/examples/azure-functions/src/nammatham.ts +++ b/examples/azure-functions/src/nammatham.ts @@ -1,6 +1,6 @@ -import { initNammatham, AzureFunctionsAdapter } from 'nammatham'; +import { initNammatham } from 'nammatham'; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); n.func; // ^? export const func = n.func; diff --git a/packages/core/src/init-nammatham.ts b/packages/core/src/init-nammatham.ts index c94280c4..a017c21a 100644 --- a/packages/core/src/init-nammatham.ts +++ b/packages/core/src/init-nammatham.ts @@ -19,12 +19,16 @@ function createRuntime>(adapter?: Ad } as unknown as NammathamRuntime; } -export const initNammatham = { - create = DefaultAdapter>(adapter?: Adapter): NammathamRuntime { - logger.debug(`Using adapter: ${yellow(adapter?.constructor.name ?? 'DefaultAdapter')}`); +export const createInitNammatham = >( + defaultAdapter: Adapter +) => ({ + create(adapter?: Adapter): NammathamRuntime { + logger.debug(`Using adapter: ${yellow(adapter?.constructor.name ?? defaultAdapter?.constructor.name)}`); if (adapter === undefined) { - return createRuntime(new DefaultAdapter() as any); + return createRuntime(defaultAdapter as any); } return createRuntime(adapter); }, -}; +}); + +export const initNammatham = createInitNammatham(new DefaultAdapter()); \ No newline at end of file diff --git a/packages/main/src/main.ts b/packages/main/src/main.ts index 0ac3ec6e..2a453d24 100644 --- a/packages/main/src/main.ts +++ b/packages/main/src/main.ts @@ -1,3 +1,11 @@ +import { createInitNammatham } from '@nammatham/core'; +import { AzureFunctionsAdapter } from '@nammatham/azure-functions'; + export * from '@nammatham/core'; export * from '@nammatham/express'; -export * from '@nammatham/azure-functions'; \ No newline at end of file +export * from '@nammatham/azure-functions'; + +/** + * Initialize Nammatham with the default adapter for Azure Functions + */ +export const initNammatham = createInitNammatham(new AzureFunctionsAdapter()) From 1f7b8a709e8fa24533902465986111e73e298699 Mon Sep 17 00:00:00 2001 From: Thada Wangthammang Date: Fri, 1 Mar 2024 21:04:06 +0700 Subject: [PATCH 2/5] doc: update readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fbd5b82a..d7e0531f 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,12 @@ npm install @nammatham/core @nammatham/azure-functions @nammatham/express You can see [examples](examples) or follow the minimal app getting started below: +> `initNammatham.create()` is a factory function for creating Nammatham App, it's a wrapper for Azure Functions App. + ```typescript -import { initNammatham, AzureFunctionsAdapter, expressPlugin } from "nammatham"; +import { initNammatham, expressPlugin } from "nammatham"; -const n = initNammatham.create(new AzureFunctionsAdapter()); +const n = initNammatham.create(); const func = n.func; const app = n.app; @@ -57,7 +59,7 @@ const helloFunction = func .httpGet('hello', { route: 'hello-world', }) - .handler(async ({trigger, context}) => { + .handler(async ({ trigger, context }) => { context.log('HTTP trigger function processed a request.'); context.debug(`Http function processed request for url "${trigger.url}"`); const name = trigger.query.get('name') || (await trigger.text()) || 'world'; From 7fac9d81fcea53cf7c463481f00a0816385706c1 Mon Sep 17 00:00:00 2001 From: Thada Wangthammang Date: Tue, 2 Apr 2024 21:02:22 +0700 Subject: [PATCH 3/5] feat: add http response helper --- .gitignore | 3 +- README.md | 19 +++--- examples/azure-functions-minimal/src/main.ts | 10 +-- .../src/functions/simple-timer.ts | 4 +- .../src/functions/hello.ts | 12 ++-- .../src/functions/hello.ts | 19 +++--- .../azure-functions/src/functions/blob.ts | 12 ++-- .../azure-functions/src/functions/hello.ts | 19 +++--- packages/azure-functions/src/handler.ts | 7 +- .../azure-functions/src/http/HttpResponse.ts | 68 +++++++++++++++++++ .../azure-functions/src/nammatham-context.ts | 6 +- packages/core/src/init-nammatham.ts | 6 +- 12 files changed, 120 insertions(+), 65 deletions(-) create mode 100644 packages/azure-functions/src/http/HttpResponse.ts diff --git a/.gitignore b/.gitignore index e818b530..8e693c9c 100644 --- a/.gitignore +++ b/.gitignore @@ -135,4 +135,5 @@ inversify-express-utils .azurite tmp -.nx \ No newline at end of file +.nx +sample_code \ No newline at end of file diff --git a/README.md b/README.md index d7e0531f..2ffe6a22 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Type-safe Serverless Library for Azure Functions and friends > > Note: [Nammatham v1](https://www.npmjs.com/package/nammatham) is currently in maintenance mode. no new features are actively being developed +You're reading v2 docs + | Version | Status | Azure Functions
Node.js Lib | Branch | Build Status | | ------- | ----------- | ----------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -37,11 +39,6 @@ Nammatham (นามธรรม in Thai, pronounced `/naam ma tham/`, means **a npm install nammatham@alpha ``` -You can also install independently -```bash -npm install @nammatham/core @nammatham/azure-functions @nammatham/express -``` - ### Example You can see [examples](examples) or follow the minimal app getting started below: @@ -49,7 +46,7 @@ You can see [examples](examples) or follow the minimal app getting started below > `initNammatham.create()` is a factory function for creating Nammatham App, it's a wrapper for Azure Functions App. ```typescript -import { initNammatham, expressPlugin } from "nammatham"; +import { initNammatham, expressPlugin } from 'nammatham'; const n = initNammatham.create(); const func = n.func; @@ -59,11 +56,11 @@ const helloFunction = func .httpGet('hello', { route: 'hello-world', }) - .handler(async ({ trigger, context }) => { - context.log('HTTP trigger function processed a request.'); - context.debug(`Http function processed request for url "${trigger.url}"`); - const name = trigger.query.get('name') || (await trigger.text()) || 'world'; - return { body: `Hello, ${name}!` }; + .handler(async c => { + c.context.log('HTTP trigger function processed a request.'); + c.context.debug(`Http function processed request for url "${c.trigger.url}"`); + const name = c.trigger.query.get('name') || (await c.trigger.text()) || 'world'; + return c.text(`Hello, ${name}!`); }); app.addFunctions(helloFunction); diff --git a/examples/azure-functions-minimal/src/main.ts b/examples/azure-functions-minimal/src/main.ts index 96b909e4..a584d927 100644 --- a/examples/azure-functions-minimal/src/main.ts +++ b/examples/azure-functions-minimal/src/main.ts @@ -9,11 +9,11 @@ app.addFunctions( .httpGet('hello', { route: 'hello-world', }) - .handler(async ({ trigger, context }) => { - context.log('HTTP trigger function processed a request.'); - context.debug(`Http function processed request for url "${trigger.url}"`); - const name = trigger.query.get('name') || (await trigger.text()) || 'world'; - return { body: `Hello, ${name}!` }; + .handler(async c => { + c.context.log('HTTP trigger function processed a request.'); + c.context.debug(`Http function processed request for url "${c.trigger.url}"`); + const name = c.trigger.query.get('name') || (await c.trigger.text()) || 'world'; + return c.text(`Hello, ${name}!`); }) ); diff --git a/examples/azure-functions-timer-trigger/src/functions/simple-timer.ts b/examples/azure-functions-timer-trigger/src/functions/simple-timer.ts index cb61f39b..a93312ae 100644 --- a/examples/azure-functions-timer-trigger/src/functions/simple-timer.ts +++ b/examples/azure-functions-timer-trigger/src/functions/simple-timer.ts @@ -4,7 +4,7 @@ export default func .timer('watcher', { schedule: '*/5 * * * * *', }) - .handler(async ({trigger, context}) => { - context.info('Timer triggered!'); + .handler(async ({ trigger, context }) => { + context.info('Timer triggered!'); trigger.isPastDue ? context.info('Timer is past due!') : null; }); diff --git a/examples/azure-functions-with-inversify/src/functions/hello.ts b/examples/azure-functions-with-inversify/src/functions/hello.ts index 70e48708..f70445b3 100644 --- a/examples/azure-functions-with-inversify/src/functions/hello.ts +++ b/examples/azure-functions-with-inversify/src/functions/hello.ts @@ -15,12 +15,10 @@ export default func .setContext({ services, }) - .handler(async ({ trigger, context, services }) => { - context.log('HTTP trigger function processed a request.'); + .handler(async c => { + c.context.log('HTTP trigger function processed a request.'); - return { - jsonBody: { - data: 'hello world' + services.dataService.getData(), - }, - }; + return c.json({ + data: 'hello world' + services.dataService.getData(), + }); }); diff --git a/examples/azure-functions-with-test/src/functions/hello.ts b/examples/azure-functions-with-test/src/functions/hello.ts index 114ce4af..333f43c9 100644 --- a/examples/azure-functions-with-test/src/functions/hello.ts +++ b/examples/azure-functions-with-test/src/functions/hello.ts @@ -4,20 +4,17 @@ export default func .httpGet('hello', { route: 'hello-world', }) - .handler(async ({ trigger, context }) => { - context.log('HTTP trigger function processed a request.'); - context.debug(`Http function processed request for url "${trigger.url}"`); - const name = trigger.query.get('name') || (await trigger.text()) || 'world'; + .handler(async c => { + c.context.log('HTTP trigger function processed a request.'); + c.context.debug(`Http function processed request for url "${c.trigger.url}"`); + const name = c.trigger.query.get('name') || (await c.trigger.text()) || 'world'; if (name === 'error') { throw new Error('this is an error'); } - const result = { + return c.json({ data: { name: name, - message: `Hello, ${name}!` - } - } - return { - jsonBody: result, - } + message: `Hello, ${name}!`, + }, + }); }); diff --git a/examples/azure-functions/src/functions/blob.ts b/examples/azure-functions/src/functions/blob.ts index 13709701..549eaeba 100644 --- a/examples/azure-functions/src/functions/blob.ts +++ b/examples/azure-functions/src/functions/blob.ts @@ -17,12 +17,10 @@ export default func extraInputs: [blobInput], extraOutputs: [blobOutput], }) - .handler(({ trigger, context }) => { - context.log('function processed work item:', trigger); - const blobInputValue = context.extraInputs.get(blobOutput); + .handler(c => { + c.context.log('function processed work item:', c.trigger); + const blobInputValue = c.context.extraInputs.get(blobOutput); - context.extraOutputs.set(blobOutput, blobInputValue); - return { - body: `Hello ${blobInputValue}`, - }; + c.context.extraOutputs.set(blobOutput, blobInputValue); + return c.text(`Hello ${blobInputValue}`); }); diff --git a/examples/azure-functions/src/functions/hello.ts b/examples/azure-functions/src/functions/hello.ts index 114ce4af..333f43c9 100644 --- a/examples/azure-functions/src/functions/hello.ts +++ b/examples/azure-functions/src/functions/hello.ts @@ -4,20 +4,17 @@ export default func .httpGet('hello', { route: 'hello-world', }) - .handler(async ({ trigger, context }) => { - context.log('HTTP trigger function processed a request.'); - context.debug(`Http function processed request for url "${trigger.url}"`); - const name = trigger.query.get('name') || (await trigger.text()) || 'world'; + .handler(async c => { + c.context.log('HTTP trigger function processed a request.'); + c.context.debug(`Http function processed request for url "${c.trigger.url}"`); + const name = c.trigger.query.get('name') || (await c.trigger.text()) || 'world'; if (name === 'error') { throw new Error('this is an error'); } - const result = { + return c.json({ data: { name: name, - message: `Hello, ${name}!` - } - } - return { - jsonBody: result, - } + message: `Hello, ${name}!`, + }, + }); }); diff --git a/packages/azure-functions/src/handler.ts b/packages/azure-functions/src/handler.ts index cbbf9858..5ebf5422 100644 --- a/packages/azure-functions/src/handler.ts +++ b/packages/azure-functions/src/handler.ts @@ -12,7 +12,7 @@ export class AzureFunctionsHandler< // eslint-disable-next-line @typescript-eslint/ban-types ExtraContext extends Record = {} > extends BaseHandler> { - context: ExtraContext = {} as ExtraContext; + extraContext: ExtraContext = {} as ExtraContext; protected funcHandler!: HandlerFunction; constructor( @@ -31,7 +31,8 @@ export class AzureFunctionsHandler< build(): AzureFunctionsEndpoint { const invokeHandler = (triggerInput: TTriggerType, innocationContext: InvocationContext) => { const nammathamContext = new NammathamContext(innocationContext, triggerInput); - return this.funcHandler({ ...nammathamContext, ...this.context }); + Object.assign(nammathamContext, this.extraContext); + return this.funcHandler(nammathamContext as NammathamContext & ExtraContext); }; return { ...this.functionOption, @@ -43,7 +44,7 @@ export class AzureFunctionsHandler< } setContext>(context: NewItem) { - this.context = { ...this.context, ...context }; + this.extraContext = { ...this.extraContext, ...context }; return this as AzureFunctionsHandler; } diff --git a/packages/azure-functions/src/http/HttpResponse.ts b/packages/azure-functions/src/http/HttpResponse.ts new file mode 100644 index 00000000..9f5a7423 --- /dev/null +++ b/packages/azure-functions/src/http/HttpResponse.ts @@ -0,0 +1,68 @@ +import { Headers } from 'undici'; +import * as type from '@azure/functions'; + +/** + * Re-export from Azure Functions; + */ +export type AzureHttpResponse = type.HttpResponseInit | type.HttpResponse; +export type Request = type.HttpRequest; + +/** + * Http Response Builder wrapping around azure/functions + */ +export class HttpResponse { + protected _headers: Headers; + protected _cookies: NonNullable = []; + protected _httpResponse: type.HttpResponseInit; + + constructor(responseInit?: type.HttpResponseInit) { + this._httpResponse = { + ...responseInit, + status: 200, + }; + this._headers = new Headers(responseInit?.headers); + } + + private build(): type.HttpResponseInit { + return { + ...this._httpResponse, + headers: this._headers, + cookies: this._cookies.length === 0 ? undefined : this._cookies, + }; + } + + public text(body?: string) { + return new type.HttpResponse({ + ...this.build(), + body, + }); + } + + public json(jsonBody: T) { + return new type.HttpResponse({ + ...this.build(), + jsonBody, + }); + } + + public httpResponse(responseInit?: type.HttpResponseInit) { + return new type.HttpResponse(responseInit); + } + + public header(key: string, value: string) { + this._headers.set(key, value); + return this; + } + + public headers(headers: Record) { + for (const [key, value] of Object.entries(headers)) { + this._headers.set(key, value); + } + return this; + } + + public status(status: number) { + this._httpResponse.status = status; + return this; + } +} diff --git a/packages/azure-functions/src/nammatham-context.ts b/packages/azure-functions/src/nammatham-context.ts index d5a34fbc..725e8428 100644 --- a/packages/azure-functions/src/nammatham-context.ts +++ b/packages/azure-functions/src/nammatham-context.ts @@ -1,8 +1,8 @@ -import type { InvocationContext } from '@azure/functions'; +import { type InvocationContext } from '@azure/functions'; -import { NammathamContextBase } from '@nammatham/core'; +import { HttpResponse } from './http/HttpResponse'; -export class NammathamContext extends NammathamContextBase { +export class NammathamContext extends HttpResponse { constructor(public readonly context: InvocationContext, public readonly trigger: TTriggerType) { super(); } diff --git a/packages/core/src/init-nammatham.ts b/packages/core/src/init-nammatham.ts index a017c21a..29defbfe 100644 --- a/packages/core/src/init-nammatham.ts +++ b/packages/core/src/init-nammatham.ts @@ -19,9 +19,7 @@ function createRuntime>(adapter?: Ad } as unknown as NammathamRuntime; } -export const createInitNammatham = >( - defaultAdapter: Adapter -) => ({ +export const createInitNammatham = >(defaultAdapter: Adapter) => ({ create(adapter?: Adapter): NammathamRuntime { logger.debug(`Using adapter: ${yellow(adapter?.constructor.name ?? defaultAdapter?.constructor.name)}`); if (adapter === undefined) { @@ -31,4 +29,4 @@ export const createInitNammatham = > }, }); -export const initNammatham = createInitNammatham(new DefaultAdapter()); \ No newline at end of file +export const initNammatham = createInitNammatham(new DefaultAdapter()); From 647fe3fc76801acb09280b82cdd3a849a2a573d7 Mon Sep 17 00:00:00 2001 From: Thada Wangthammang Date: Tue, 2 Apr 2024 21:25:12 +0700 Subject: [PATCH 4/5] fix: http responses --- .../__test__/helloFunction.test.ts | 19 +++++------ .../azure-functions/src/http/HttpResponse.ts | 33 +++++++++++-------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/examples/azure-functions-with-test/__test__/helloFunction.test.ts b/examples/azure-functions-with-test/__test__/helloFunction.test.ts index 4d9dda75..f9ccc9ac 100644 --- a/examples/azure-functions-with-test/__test__/helloFunction.test.ts +++ b/examples/azure-functions-with-test/__test__/helloFunction.test.ts @@ -1,19 +1,18 @@ import { expect, test } from 'vitest'; import helloFunc from '../src/functions/hello'; import { HttpRequest, InvocationContext } from '@azure/functions'; +import { NammathamContext } from 'nammatham'; test('helloFunc', async () => { const handler = helloFunc.getHandler(); - const result = await handler({ - context: new InvocationContext(), - trigger: new HttpRequest({ - method: 'GET', - url: 'http://localhost:3000/api/hello-world', - query: { - name: 'world', - }, - }), - }); + const nammathamConext = new NammathamContext(new InvocationContext(), new HttpRequest({ + method: 'GET', + url: 'http://localhost:3000/api/hello-world', + query: { + name: 'world', + }, + })) + const result = await handler(nammathamConext); expect(result).toEqual({ jsonBody: { diff --git a/packages/azure-functions/src/http/HttpResponse.ts b/packages/azure-functions/src/http/HttpResponse.ts index 9f5a7423..f5d8ee7d 100644 --- a/packages/azure-functions/src/http/HttpResponse.ts +++ b/packages/azure-functions/src/http/HttpResponse.ts @@ -1,4 +1,3 @@ -import { Headers } from 'undici'; import * as type from '@azure/functions'; /** @@ -10,25 +9,31 @@ export type Request = type.HttpRequest; /** * Http Response Builder wrapping around azure/functions */ +export type Header = Record; export class HttpResponse { - protected _headers: Headers; + protected _headers: Header; protected _cookies: NonNullable = []; protected _httpResponse: type.HttpResponseInit; - constructor(responseInit?: type.HttpResponseInit) { + constructor(responseInit?: Omit & { headers: Header }) { this._httpResponse = { ...responseInit, - status: 200, }; - this._headers = new Headers(responseInit?.headers); + this._headers = responseInit?.headers ?? {}; } private build(): type.HttpResponseInit { - return { + const result = { ...this._httpResponse, - headers: this._headers, - cookies: this._cookies.length === 0 ? undefined : this._cookies, }; + if (Object.values(this._headers).length > 0) { + result.headers = this._headers; + } + + if (this._cookies.length > 0) { + result.cookies = this._cookies; + } + return result; } public text(body?: string) { @@ -38,11 +43,11 @@ export class HttpResponse { }); } - public json(jsonBody: T) { - return new type.HttpResponse({ + public json(jsonBody: T): AzureHttpResponse { + return { ...this.build(), jsonBody, - }); + }; } public httpResponse(responseInit?: type.HttpResponseInit) { @@ -50,13 +55,13 @@ export class HttpResponse { } public header(key: string, value: string) { - this._headers.set(key, value); + this._headers[key] = value; return this; } - public headers(headers: Record) { + public headers(headers: Header) { for (const [key, value] of Object.entries(headers)) { - this._headers.set(key, value); + this._headers[key] = value; } return this; } From b849ed4ddb7e05b3c032ec715c4e66421e8e6856 Mon Sep 17 00:00:00 2001 From: Thada Wangthammang Date: Thu, 11 Apr 2024 14:20:24 +0700 Subject: [PATCH 5/5] feat(azure-functions): add trigger for storageQueue --- packages/azure-functions/src/trigger.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/azure-functions/src/trigger.ts b/packages/azure-functions/src/trigger.ts index 684ff9a4..75a4e27e 100644 --- a/packages/azure-functions/src/trigger.ts +++ b/packages/azure-functions/src/trigger.ts @@ -8,6 +8,7 @@ import type { Timer, TimerFunctionOptions, HttpMethodFunctionOptions, + StorageQueueFunctionOptions, } from '@azure/functions'; import { app } from '@azure/functions'; @@ -92,6 +93,19 @@ export class AzureFunctionsTrigger extends BaseFunctionTrigger { ); } + storageQueue(funcName: string, option: Omit) { + return new AzureFunctionsHandler( + funcName, + this.parseFunctionOption(funcName, option), + funcOption => { + app.storageQueue(funcName, { + ...option, + ...funcOption, + }); + } + ); + } + private parseFunctionOption( funcName: string, opt?: Partial