From 5db9f8b247d620381a8c613d5f09f210aee7c176 Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sat, 11 Jun 2022 10:00:41 -0600 Subject: [PATCH 1/4] feat: add in --uri-resolver --- README.md | 1 + src/commands/help.ts | 2 ++ src/commands/options.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 483db63..72c5ddb 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,7 @@ You can pass the following [Ajv options](https://ajv.js.org/options.html): | Advanced | | `--multiple-of-precision` | precision of multipleOf, pass integer number | | `--messages=false` | do not include text messages in errors | +| `--uri-resolver=` | override embedded uriResolver (uri-js) with alternative (fast-uri) | | `--loop-required=` | max size of `required` to compile to expression (rather than to loop) | | `--loop-enum=` | max size of `enum` to compile to expression (rather than to loop) | | `--own-properties` | only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) | diff --git a/src/commands/help.ts b/src/commands/help.ts index acd473c..d997870 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -234,6 +234,8 @@ Ajv options (see https://github.com/epoberezkin/ajv#options): --own-properties only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) + --uri-resolver= override embedded uriResolver (uri-js) with alternative (fast-uri) + --code-es5 generate ES5 code --code-lines generate multi-line code diff --git a/src/commands/options.ts b/src/commands/options.ts index 99d6ae6..4bd669d 100644 --- a/src/commands/options.ts +++ b/src/commands/options.ts @@ -25,6 +25,7 @@ const ajvOptions: SchemaMap = { ownProperties: {type: "boolean"}, multipleOfPrecision: boolOrNat, messages: {type: "boolean"}, + uriResolver: {type: "string", enum:['fast-uri']}, [`${CODE}es5`]: {type: "boolean"}, [`${CODE}lines`]: {type: "boolean"}, [`${CODE}optimize`]: boolOrNat, From fb0f46265caa4d2a9ffd191f85f8c5b093cb7b59 Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sat, 11 Jun 2022 10:09:47 -0600 Subject: [PATCH 2/4] fix: test fails --- src/commands/options.ts | 2 +- tsconfig.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/options.ts b/src/commands/options.ts index 4bd669d..7473828 100644 --- a/src/commands/options.ts +++ b/src/commands/options.ts @@ -25,7 +25,7 @@ const ajvOptions: SchemaMap = { ownProperties: {type: "boolean"}, multipleOfPrecision: boolOrNat, messages: {type: "boolean"}, - uriResolver: {type: "string", enum:['fast-uri']}, + uriResolver: {type: "string", enum: ["fast-uri"]}, [`${CODE}es5`]: {type: "boolean"}, [`${CODE}lines`]: {type: "boolean"}, [`${CODE}optimize`]: boolOrNat, diff --git a/tsconfig.json b/tsconfig.json index e853025..26d05f9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "allowJs": true, "target": "ES2018", "resolveJsonModule": true, - "esModuleInterop": false + "esModuleInterop": false, + "useUnknownInCatchVariables": false } } From 8f8263d704bd06a413b9c5fe688ddc1159914b16 Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sat, 11 Jun 2022 10:30:49 -0600 Subject: [PATCH 3/4] feat: replace string option with module --- package.json | 1 + src/commands/ajv.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/package.json b/package.json index 1ac8acf..d6f17dd 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "dependencies": { "ajv": "^8.0.0", "fast-json-patch": "^2.0.0", + "fast-uri": "2.1.0", "glob": "^7.1.0", "js-yaml": "^3.14.0", "json-schema-migrate": "^2.0.0", diff --git a/src/commands/ajv.ts b/src/commands/ajv.ts index d06acb5..25d5e84 100644 --- a/src/commands/ajv.ts +++ b/src/commands/ajv.ts @@ -10,6 +10,7 @@ import {getOptions} from "./options" import * as util from "./util" import * as path from "path" import * as draft6metaSchema from "ajv/lib/refs/json-schema-draft-06.json" +import * as fastUri from "fast-uri" type AjvMethod = "addSchema" | "addMetaSchema" @@ -30,6 +31,7 @@ const AjvClass: {[S in SchemaSpec]?: typeof AjvCore} = { export default function (argv: ParsedArgs): AjvCore { const opts = getOptions(argv) + if (argv["uri-resolver"] === "fast-uri") opts.uriResolver = fastUri if (argv.o) opts.code.source = true const Ajv: typeof AjvCore = AjvClass[argv.spec as SchemaSpec] || Ajv7 const ajv = new Ajv(opts) From e320e5a57d4c1bb8a9c7d54277f03b420d091fad Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sat, 11 Jun 2022 10:34:11 -0600 Subject: [PATCH 4/4] fix: dependency to not be strict --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d6f17dd..a3ab6fb 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "dependencies": { "ajv": "^8.0.0", "fast-json-patch": "^2.0.0", - "fast-uri": "2.1.0", + "fast-uri": "^2.1.0", "glob": "^7.1.0", "js-yaml": "^3.14.0", "json-schema-migrate": "^2.0.0",