Skip to content

Commit 1039be8

Browse files
authored
Merge pull request #105 from Exabyte-io/feat/SOF-6944
SOF-6944: accept schema as optional argument in validation method
2 parents 68a4572 + ceb0894 commit 1039be8

File tree

7 files changed

+1805
-1143
lines changed

7 files changed

+1805
-1143
lines changed

dist/js/entity/in_memory.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export declare class InMemoryEntity {
4949
* @summary Clone this entity
5050
*/
5151
clone(extraContext?: object): this;
52-
static validateData(data: AnyObject, clean?: boolean): AnyObject;
52+
static validateData(data: AnyObject, clean?: boolean, jsonSchema?: import("json-schema").JSONSchema7 | undefined): AnyObject;
5353
/**
5454
* @summary Validate entity contents against schema
5555
*/

dist/js/entity/in_memory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@ class InMemoryEntity {
105105
...extraContext,
106106
});
107107
}
108-
static validateData(data, clean = false) {
109-
if (!this.jsonSchema) {
108+
static validateData(data, clean = false, jsonSchema = this.jsonSchema) {
109+
if (!jsonSchema) {
110110
return data;
111111
}
112112
const result = clean
113-
? ajv.validateAndClean(data, this.jsonSchema, {
113+
? ajv.validateAndClean(data, jsonSchema, {
114114
coerceTypes: this.allowJsonSchemaTypesCoercing,
115115
})
116-
: ajv.validate(data, this.jsonSchema);
116+
: ajv.validate(data, jsonSchema);
117117
if (!result.isValid) {
118118
throw new EntityError({
119119
code: ValidationErrorCode.IN_MEMORY_ENTITY_DATA_INVALID,
120120
details: {
121121
error: result === null || result === void 0 ? void 0 : result.errors,
122122
json: data,
123-
schema: this.jsonSchema,
123+
schema: jsonSchema,
124124
},
125125
});
126126
}

dist/js/entity/set/factory.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, ordered
2626
readonly slug: string;
2727
readonly isSystemEntity: boolean;
2828
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
29-
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
29+
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
3030
};
3131
} & {
3232
new (...args: any[]): {
@@ -57,7 +57,7 @@ export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, ordered
5757
readonly slug: string;
5858
readonly isSystemEntity: boolean;
5959
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
60-
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
60+
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
6161
};
6262
} & typeof InMemoryEntitySet) | undefined;
6363
}) => (config: AnyObject, entityCls: EntitySetSchema["entityCls"]) => InMemoryEntitySet;

dist/js/entity/set/ordered.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export declare const OrderedInMemoryEntitySet: {
2222
readonly slug: string;
2323
readonly isSystemEntity: boolean;
2424
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
25-
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
25+
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
2626
};
2727
} & {
2828
new (...args: any[]): {
@@ -53,6 +53,6 @@ export declare const OrderedInMemoryEntitySet: {
5353
readonly slug: string;
5454
readonly isSystemEntity: boolean;
5555
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
56-
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
56+
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
5757
};
5858
} & typeof InMemoryEntitySet;

0 commit comments

Comments
 (0)