Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@general-galactic/entity-decorators
Advanced tools
This project contains a set of typescript decorators that allow you to mark up your typescript entity classes. You can then use transformers to convert the decorators to things like json schemas and [Joi Schemas](https://joi.dev). You can also write your
This project contains a set of typescript decorators that allow you to mark up your typescript entity classes. You can then use transformers to convert the decorators to things like json schemas and Joi Schemas. You can also write your own decorators and transformers to do whatever you need. Here's what it looks like:
export default class Entity {
@Required()
@MinimumLength(6)
firstName: string
@Optional()
@MinimumValue(1)
articleCount: number
@Required()
@Enumeration( UserTypes.member, UserTypes.owner )
userType: UserTypes
@Required()
@SubObject( Address )
address: Address
@Required()
@ArrayItems( ContactMethod )
@MinimumLength(1)
contactMethods: ContactMethod[]
}
You can then use this class to generate a schema using a tranformer like this:
const transformer = new JoiSchemaTransformer()
const entityJoiSchema = transformer.tranformFromEntityClass( Entity )
entityJoiSchema.validate( entity )
If you use Hapi or Fastify you can use transformers to generate schemas for your routes. These schemas can even be used to generate OpenAPI documentation for your APIs:
HAPI ( gives you runtime validation and Swagger or OpenAPI documentation )
const transformer = new JoiSchemaTransformer()
server.route({
method: 'POST',
path: '/post',
options: {
validate: {
payload: transformer.tranformFromEntityClass( RoutePostBody )
}
},
handler( request, h ) { ... }
})
FASTIFY -> COMING SOON
const transformer = new JsonSchemaTransformer()
fastify.post('/post', {
handler () {},
schema: {
body: transformer.tranformFromEntityClass( RoutePostBody )
}
})
Install from npm: npm i @general-galactic/entity-decorators
.
Required
- must be populated. Will NOT allow null
or undefined
values.Optional
- will allow populated, null
, or undefined
values.Description
- provide notes to the swagger generator - shows up on swagger UI.Enumeration
- provide a finite set of allowed values.SubObject
- used to define to descend into and extract decorators from a sub objects.Scope
- define scopes which are groups of properties. e.g. public, private, etc.MinimumLength
- Minimum string length.MaximumLength
- Maximum string length.Url
- A string that should match a url format.Email
- A string that should match an email format.Phone
- A string that should match a phone format.ISO8601Date
- A string that should match the ISO8601 date format.ArrayItems
- used to define the type of an array of objects. This is required to descend into and extract decorators from the sub objects.MinimumLength
- Minimum array length.MaximumLength
- Maximum array length.MinimumValue
- Minimum number value.MaximumValue
- Maximum number value.NegativeValue
- Negative number values only.PositiveValue
- Positive number values only.ISO8601Date
- A date field that should match the ISO8601 date format.We'd love help fixing bugs and adding new capabilities. Send us a PR :)
FAQs
This project contains a set of typescript decorators that allow you to mark up your typescript entity classes. You can then use transformers to convert the decorators to things like json schemas and [Joi Schemas](https://joi.dev). You can also write your
The npm package @general-galactic/entity-decorators receives a total of 1 weekly downloads. As such, @general-galactic/entity-decorators popularity was classified as not popular.
We found that @general-galactic/entity-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.