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
Register metadata on classes #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks lit.
Wonder what other potential uses of reflect-metadata there are.
@@ -14,10 +13,22 @@ export class Topic extends BaseModel { | |||
name: string; | |||
} | |||
|
|||
@RegisterCrudApi(app, { model: Topic, route: "/topic", memorySize: 512 }) | |||
@CrudApi({ model: Topic, route: "/topic", memorySize: 512 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we stick schema validation on top of it?
Use that library to put decorators on top of fields in Topic
?
https://github.com/typestack/class-validator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's one option and would fit nicely. Would like to look into io-ts again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a library mainly for form validation, that allows to create a schema and then validate user input against it.
If we can stick it on top of the API could kill 2 birds with 1 stone.
// a list of resources we would like infrastructure generated for | ||
export const stackResources = [TopicCrudApi]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to import TopicCrudApi
, but don't need to do so with the function wrapped in Route({ route: "/blargle" })
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you're right we do, just haven't gotten that far yet
This uses reflect-metadata to stash metadata on classes and methods for generating CDK resources. Seems to work pretty well.
See the test to get an idea of how it should work
The idea is this should generate two lambda functions and three APIGW routes:
/album/test
custom route/blargle
function-based route (no class) - can't use a decorator on a function (I think) but we can simply wrap it in a functionTests pass but CI is broken because of this dumb CDK issue