Skip to content

Commit

Permalink
fix(deps): update dependency ajv to v7 (#966)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency ajv to v7

* fix(deps): update dependency ajv to v7

* refactor(ajv): changes to be compatible with Ajv v7

Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: Sebastian Rettig <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2020
1 parent 16ca257 commit 2f028ac
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 44 deletions.
49 changes: 40 additions & 9 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
],
"dependencies": {
"@types/react": "^16.9.35",
"ajv": "^6.12.0",
"ajv": "^7.0.0",
"ajv-keywords": "^4.0.0",
"axios": "^0.21.0",
"crc": "^3.8.0",
"debug": "^4.1.1",
Expand Down
8 changes: 5 additions & 3 deletions src/H5PEditor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ajv from 'ajv';
import Ajv, { ValidateFunction } from 'ajv';
import ajvKeywords from 'ajv-keywords';
import { PassThrough, Writable, Readable } from 'stream';
import { ReadStream } from 'fs';
import { withFile } from 'tmp-promise';
Expand Down Expand Up @@ -130,7 +131,8 @@ export default class H5PEditor {
this.semanticsLocalizer = new SemanticsLocalizer(translationCallback);
this.dependencyGetter = new DependencyGetter(libraryStorage);

const jsonValidator = new ajv();
const jsonValidator = new Ajv();
ajvKeywords(jsonValidator, 'regexp');
const saveMetadataJsonSchema = require('./schemas/save-metadata.json');
const libraryNameSchema = require('./schemas/library-name-schema.json');
jsonValidator.addSchema([saveMetadataJsonSchema, libraryNameSchema]);
Expand All @@ -145,7 +147,7 @@ export default class H5PEditor {
public libraryManager: LibraryManager;
public packageImporter: PackageImporter;
public temporaryFileManager: TemporaryFileManager;
private contentMetadataValidator: ajv.ValidateFunction;
private contentMetadataValidator: ValidateFunction;

private contentStorer: ContentStorer;
private copyrightSemantics: ISemanticsEntry = defaultCopyrightSemantics as ISemanticsEntry;
Expand Down
8 changes: 5 additions & 3 deletions src/PackageValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ajv from 'ajv';
import Ajv, { ValidateFunction } from 'ajv';
import ajvKeywords from 'ajv-keywords';
import * as path from 'path';
import promisepipe from 'promisepipe';
import { WritableStreamBuffer } from 'stream-buffers';
Expand Down Expand Up @@ -473,7 +474,8 @@ export default class PackageValidator {
}
log.info(`initializing json validators`);

const jsonValidator = new ajv();
const jsonValidator = new Ajv();
ajvKeywords(jsonValidator, 'regexp');
const h5pJsonSchema = require('./schemas/h5p-schema.json');
const libraryNameSchema = require('./schemas/library-name-schema.json');
const librarySchema = require('./schemas/library-schema.json');
Expand Down Expand Up @@ -559,7 +561,7 @@ export default class PackageValidator {
*/
private jsonMustConformToSchema(
filename: string,
schemaValidator: ajv.ValidateFunction,
schemaValidator: ValidateFunction,
errorIdAnyError: string,
errorIdJsonParse?: string,
returnContent: boolean = false,
Expand Down
66 changes: 38 additions & 28 deletions src/schemas/library-name-schema.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "library-name-schema.json",
"title": "h5p library reference",
"description": "A combination of machine name and major + minor version",
"type": "object",
"properties": {
"machineName": {
"type": "string",
"pattern": "^[\\w0-9\\-\\.]{1,255}$"
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "library-name-schema.json",
"title": "h5p library reference",
"description": "A combination of machine name and major + minor version",
"type": "object",
"properties": {
"machineName": {
"type": "string",
"pattern": "^[\\w0-9\\-\\.]{1,255}$"
},
"majorVersion": {
"anyOf": [
{
"type": "number",
"minimum": 0,
"maximum": 99999
},
{
"type": "string",
"pattern": "^[0-9]{1,5}$"
}
]
},
"minorVersion": {
"anyOf": [
{
"type": "number",
"minimum": 0,
"maximum": 99999
},
{
"type": "string",
"pattern": "^[0-9]{1,5}$"
}
]
}
},
"majorVersion": {
"type": ["number", "string"],
"minimum": 0,
"maximum": 99999,
"pattern": "^[0-9]{1,5}$"
},
"minorVersion": {
"type": ["number", "string"],
"minimum": 0,
"maximum": 99999,
"pattern": "^[0-9]{1,5}$"
}
},
"required": [
"machineName",
"majorVersion",
"minorVersion"
]
}
"required": ["machineName", "majorVersion", "minorVersion"]
}

0 comments on commit 2f028ac

Please sign in to comment.