Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/resource",
"version": "5.4.0",
"version": "5.5.0",
"description": "Add transformation layers between your application data transfer.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
15 changes: 15 additions & 0 deletions src/resource/BaseResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@ export abstract class BaseResource<R = any, I = any> {
*/
private readonly isArray: boolean

/**
* Indicates if the resource should be automatically
* transformed to JSON when constructed. If set to `true`,
* when you construct the resource it will automatically call
* the `toJSON()` method to validate that the schema is valid.
*
* This is useful when you want to fail fast if the schema is not
* valid.
*/
protected autoValidateSchema = true

public constructor(data: I | I[]) {
this.defaultValues = []
this.isArray = Is.Array(data)
this.items = this.isArray ? (data as I[]) : [data as I]

if (this.autoValidateSchema) {
this.toJSON()
}
}

/**
Expand Down
Loading