Skip to content

Commit 7dc4400

Browse files
committed
chore: use new ajv logic
1 parent 894d715 commit 7dc4400

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"devDependencies": {
8181
"@babel/preset-typescript": "^7.22.5",
8282
"@exabyte-io/eslint-config": "^2023.8.29-1",
83-
"@mat3ra/esse": "git+https://github.com/Exabyte-io/esse.git#ec69a50cd01bb741f2eb6b613ea601131891e1c9",
83+
"@mat3ra/esse": "git+https://github.com/Exabyte-io/esse.git#33f3c221536f75a93291a65289c75a0043ddbbd6",
8484
"@typescript-eslint/eslint-plugin": "^5.56.0",
8585
"@typescript-eslint/parser": "^5.56.0",
8686
"chai": "^4.3.4",

src/entity/in_memory.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ export class InMemoryEntity {
107107
return object;
108108
}
109109

110-
static validateAndCleanData(data: AnyObject) {
110+
static validateData(data: AnyObject, clean = false) {
111111
if (!this.jsonSchema) {
112112
return data;
113113
}
114-
const result = ajv.validate(data, this.jsonSchema);
114+
const result = clean
115+
? ajv.validateAndClean(data, this.jsonSchema)
116+
: ajv.validate(data, this.jsonSchema);
117+
115118
if (!result.isValid) {
116119
throw new EntityError({
117120
code: ValidationErrorCode.IN_MEMORY_ENTITY_DATA_INVALID,
@@ -131,12 +134,12 @@ export class InMemoryEntity {
131134
validate() {
132135
const ctr = this.constructor as typeof InMemoryEntity;
133136
if (this._json) {
134-
ctr.validateAndCleanData(this._json);
137+
ctr.validateData(this._json);
135138
}
136139
}
137140

138141
clean(config: AnyObject) {
139-
return (this.constructor as typeof InMemoryEntity).validateAndCleanData(config);
142+
return (this.constructor as typeof InMemoryEntity).validateData(config, true);
140143
}
141144

142145
isValid(): boolean {

0 commit comments

Comments
 (0)