-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nammatham): handle functions metadata
- Loading branch information
1 parent
042ed9e
commit 263ecee
Showing
6 changed files
with
88 additions
and
26 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
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,30 +1,51 @@ | ||
import type { HttpTriggerOptions } from '../dist/main'; | ||
import camelCase from 'lodash.camelcase'; | ||
|
||
export class NammathamBase { | ||
protected functions: Record<string, any>[] = []; | ||
import type { NammathamFunction, HttpTriggerOptions, NammathamTrigger } from './types'; | ||
|
||
public getFunctions() { | ||
return this.functions; | ||
} | ||
} | ||
export class Nammatham implements NammathamTrigger { | ||
protected functions: NammathamFunction[] = []; | ||
|
||
export class Nammatham extends NammathamBase { | ||
public get<T extends string>(options: HttpTriggerOptions<T>) { | ||
public get<T extends string>(route: T) { | ||
return this.http({ | ||
...options, | ||
method: ['GET'], | ||
route, | ||
methods: ['GET'], | ||
}); | ||
} | ||
|
||
public post<T extends string>(options: HttpTriggerOptions<T>) { | ||
public post<T extends string>(route: T) { | ||
return this.http({ | ||
...options, | ||
method: ['POST'], | ||
route, | ||
methods: ['POST'], | ||
}); | ||
} | ||
|
||
public http<T extends string>(options: HttpTriggerOptions<T>) { | ||
this.functions.push(options); | ||
if (options.route === undefined && options.name === undefined) { | ||
throw new Error('Route or Name is required'); | ||
} | ||
this.functions.push({ | ||
name: camelCase(options.name ?? options.route), | ||
bindings: [ | ||
{ | ||
type: 'httpTrigger', | ||
// TODO: Add Support default value by configuring in options | ||
authLevel: options.authLevel ?? 'function', | ||
route: options.route, | ||
direction: 'in', | ||
name: 'req', | ||
methods: options.methods ?? ['GET', 'POST', 'PUT', 'DELETE'], | ||
}, | ||
{ | ||
type: 'http', | ||
direction: 'out', | ||
name: 'res', | ||
}, | ||
], | ||
}); | ||
return this; | ||
} | ||
|
||
public getFunctions() { | ||
return this.functions; | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.