Skip to content

Commit

Permalink
Merge pull request #105 from Exabyte-io/feat/SOF-6944
Browse files Browse the repository at this point in the history
SOF-6944: accept schema as optional argument in validation method
  • Loading branch information
pranabdas authored Oct 4, 2024
2 parents 68a4572 + ceb0894 commit 1039be8
Show file tree
Hide file tree
Showing 7 changed files with 1,805 additions and 1,143 deletions.
2 changes: 1 addition & 1 deletion dist/js/entity/in_memory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export declare class InMemoryEntity {
* @summary Clone this entity
*/
clone(extraContext?: object): this;
static validateData(data: AnyObject, clean?: boolean): AnyObject;
static validateData(data: AnyObject, clean?: boolean, jsonSchema?: import("json-schema").JSONSchema7 | undefined): AnyObject;
/**
* @summary Validate entity contents against schema
*/
Expand Down
10 changes: 5 additions & 5 deletions dist/js/entity/in_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ class InMemoryEntity {
...extraContext,
});
}
static validateData(data, clean = false) {
if (!this.jsonSchema) {
static validateData(data, clean = false, jsonSchema = this.jsonSchema) {
if (!jsonSchema) {
return data;
}
const result = clean
? ajv.validateAndClean(data, this.jsonSchema, {
? ajv.validateAndClean(data, jsonSchema, {
coerceTypes: this.allowJsonSchemaTypesCoercing,
})
: ajv.validate(data, this.jsonSchema);
: ajv.validate(data, jsonSchema);
if (!result.isValid) {
throw new EntityError({
code: ValidationErrorCode.IN_MEMORY_ENTITY_DATA_INVALID,
details: {
error: result === null || result === void 0 ? void 0 : result.errors,
json: data,
schema: this.jsonSchema,
schema: jsonSchema,
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js/entity/set/factory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, ordered
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & {
new (...args: any[]): {
Expand Down Expand Up @@ -57,7 +57,7 @@ export declare const constructEntitySetFactoryByConfig: ({ entitySetCls, ordered
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & typeof InMemoryEntitySet) | undefined;
}) => (config: AnyObject, entityCls: EntitySetSchema["entityCls"]) => InMemoryEntitySet;
4 changes: 2 additions & 2 deletions dist/js/entity/set/ordered.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export declare const OrderedInMemoryEntitySet: {
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & {
new (...args: any[]): {
Expand Down Expand Up @@ -53,6 +53,6 @@ export declare const OrderedInMemoryEntitySet: {
readonly slug: string;
readonly isSystemEntity: boolean;
getAsEntityReference(byIdOnly?: boolean): import("@mat3ra/esse/dist/js/types").EntityReferenceSchema;
getEntityByName(entities: import("..").InMemoryEntity[], entity: string, name: string): import("..").InMemoryEntity;
getEntityByName(entities: import("../in_memory").InMemoryEntity[], entity: string, name: string): import("../in_memory").InMemoryEntity;
};
} & typeof InMemoryEntitySet;
Loading

0 comments on commit 1039be8

Please sign in to comment.