-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTTP response Helper & Make initNammatham create Azure Functions …
…for default (#131)
- Loading branch information
Showing
20 changed files
with
176 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,5 @@ inversify-express-utils | |
|
||
.azurite | ||
tmp | ||
.nx | ||
.nx | ||
sample_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletions
19
examples/azure-functions-with-test/__test__/helloFunction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 type Header = Record<string, string>; | ||
export class HttpResponse { | ||
protected _headers: Header; | ||
protected _cookies: NonNullable<type.HttpResponseInit['cookies']> = []; | ||
protected _httpResponse: type.HttpResponseInit; | ||
|
||
constructor(responseInit?: Omit<type.HttpResponseInit, 'headers'> & { headers: Header }) { | ||
this._httpResponse = { | ||
...responseInit, | ||
}; | ||
this._headers = responseInit?.headers ?? {}; | ||
} | ||
|
||
private build(): type.HttpResponseInit { | ||
const result = { | ||
...this._httpResponse, | ||
}; | ||
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) { | ||
return new type.HttpResponse({ | ||
...this.build(), | ||
body, | ||
}); | ||
} | ||
|
||
public json<T extends object>(jsonBody: T): AzureHttpResponse { | ||
return { | ||
...this.build(), | ||
jsonBody, | ||
}; | ||
} | ||
|
||
public httpResponse(responseInit?: type.HttpResponseInit) { | ||
return new type.HttpResponse(responseInit); | ||
} | ||
|
||
public header(key: string, value: string) { | ||
this._headers[key] = value; | ||
return this; | ||
} | ||
|
||
public headers(headers: Header) { | ||
for (const [key, value] of Object.entries(headers)) { | ||
this._headers[key] = value; | ||
} | ||
return this; | ||
} | ||
|
||
public status(status: number) { | ||
this._httpResponse.status = status; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.