From 63d3acc629ff3bf31770f1a1f79faeebf28efc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 8 Jun 2024 15:09:11 +0300 Subject: [PATCH 1/3] Revert "Revert fast-uri change (#2444)" This reverts commit c8b37f448f77448656222a5a5e279432857f7e9f. --- docs/options.md | 2 +- lib/compile/index.ts | 4 ++-- lib/compile/resolve.ts | 4 ++-- lib/runtime/uri.ts | 2 +- lib/types/index.ts | 6 +++--- spec/resolve.spec.ts | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/options.md b/docs/options.md index 6f74b02b3..fdce7f571 100644 --- a/docs/options.md +++ b/docs/options.md @@ -344,7 +344,7 @@ Include human-readable messages in errors. `true` by default. `false` can be pas ### uriResolver -By default `uriResolver` is undefined and relies on the embedded uriResolver [uri-js](https://github.com/garycourt/uri-js). Pass an object that satisfies the interface [UriResolver](https://github.com/ajv-validator/ajv/blob/master/lib/types/index.ts) to be used in replacement. One alternative is [fast-uri](https://github.com/fastify/fast-uri). +By default `uriResolver` is undefined and relies on the embedded uriResolver [fast-uri](https://github.com/fastify/fast-uri). Pass an object that satisfies the interface [UriResolver](https://github.com/ajv-validator/ajv/blob/master/lib/types/index.ts) to be used in replacement. One alternative is [uri-js](https://github.com/garycourt/uri-js). ### code diff --git a/lib/compile/index.ts b/lib/compile/index.ts index 3dac2699b..bfc393455 100644 --- a/lib/compile/index.ts +++ b/lib/compile/index.ts @@ -14,7 +14,7 @@ import N from "./names" import {LocalRefs, getFullPath, _getFullPath, inlineRef, normalizeId, resolveUrl} from "./resolve" import {schemaHasRulesButRef, unescapeFragment} from "./util" import {validateFunctionCode} from "./validate" -import * as URI from "uri-js" +import {URIComponent} from "fast-uri" import {JSONType} from "./rules" export type SchemaRefs = { @@ -295,7 +295,7 @@ const PREVENT_SCOPE_CHANGE = new Set([ function getJsonPointer( this: Ajv, - parsedRef: URI.URIComponents, + parsedRef: URIComponent, {baseId, schema, root}: SchemaEnv ): SchemaEnv | undefined { if (parsedRef.fragment?.[0] !== "/") return diff --git a/lib/compile/resolve.ts b/lib/compile/resolve.ts index be283866c..b8c4aca39 100644 --- a/lib/compile/resolve.ts +++ b/lib/compile/resolve.ts @@ -1,6 +1,6 @@ import type {AnySchema, AnySchemaObject, UriResolver} from "../types" import type Ajv from "../ajv" -import type {URIComponents} from "uri-js" +import type {URIComponent} from "fast-uri" import {eachItem} from "./util" import * as equal from "fast-deep-equal" import * as traverse from "json-schema-traverse" @@ -73,7 +73,7 @@ export function getFullPath(resolver: UriResolver, id = "", normalize?: boolean) return _getFullPath(resolver, p) } -export function _getFullPath(resolver: UriResolver, p: URIComponents): string { +export function _getFullPath(resolver: UriResolver, p: URIComponent): string { const serialized = resolver.serialize(p) return serialized.split("#")[0] + "#" } diff --git a/lib/runtime/uri.ts b/lib/runtime/uri.ts index 7dd35f9d1..5450549cd 100644 --- a/lib/runtime/uri.ts +++ b/lib/runtime/uri.ts @@ -1,4 +1,4 @@ -import * as uri from "uri-js" +import * as uri from "fast-uri" type URI = typeof uri & {code: string} ;(uri as URI).code = 'require("ajv/dist/runtime/uri").default' diff --git a/lib/types/index.ts b/lib/types/index.ts index b5ef53eeb..39bc51b0b 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -1,4 +1,4 @@ -import * as URI from "uri-js" +import {URIComponent} from "fast-uri" import type {CodeGen, Code, Name, ScopeValueSets, ValueScopeName} from "../compile/codegen" import type {SchemaEnv, SchemaCxt, SchemaObjCxt} from "../compile" import type {JSONType} from "../compile/rules" @@ -238,7 +238,7 @@ export interface RegExpLike { } export interface UriResolver { - parse(uri: string): URI.URIComponents + parse(uri: string): URIComponent resolve(base: string, path: string): string - serialize(component: URI.URIComponents): string + serialize(component: URIComponent): string } diff --git a/spec/resolve.spec.ts b/spec/resolve.spec.ts index 2fe5b1041..a89cccaf7 100644 --- a/spec/resolve.spec.ts +++ b/spec/resolve.spec.ts @@ -4,17 +4,17 @@ import _Ajv from "./ajv" import type {AnyValidateFunction} from "../dist/types" import type MissingRefError from "../dist/compile/ref_error" import chai from "./chai" -import * as fastUri from "fast-uri" +import * as uriJs from "uri-js" const should = chai.should() -const uriResolvers = [undefined, fastUri] +const uriResolvers = [undefined, uriJs] uriResolvers.forEach((resolver) => { let describeTitle: string if (resolver !== undefined) { - describeTitle = "fast-uri resolver" - } else { describeTitle = "uri-js resolver" + } else { + describeTitle = "fast-uri resolver" } describe(describeTitle, () => { describe("resolve", () => { From 8850ef8ca86ffc08e916bc32094a7f79bc9a8b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sat, 8 Jun 2024 15:17:43 +0300 Subject: [PATCH 2/3] fix inports --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ca56231a8..b5f4e33bc 100644 --- a/package.json +++ b/package.json @@ -59,9 +59,9 @@ "runkitExampleFilename": ".runkit_example.js", "dependencies": { "fast-deep-equal": "^3.1.3", + "fast-uri": "^2.3.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" + "require-from-string": "^2.0.2" }, "devDependencies": { "@ajv-validator/config": "^0.5.0", @@ -83,7 +83,6 @@ "dayjs-plugin-utc": "^0.1.2", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", - "fast-uri": "^2.3.0", "glob": "^10.3.10", "husky": "^9.0.11", "if-node-version": "^1.1.1", @@ -104,7 +103,8 @@ "rollup-plugin-terser": "^7.0.2", "ts-node": "^10.9.2", "tsify": "^5.0.4", - "typescript": "5.3.3" + "typescript": "5.3.3", + "uri-js": "^4.4.1" }, "collective": { "type": "opencollective", From 549aeb0122c0b68320f4ceec15e73f0d17a2e35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Mon, 10 Jun 2024 15:38:56 +0300 Subject: [PATCH 3/3] up --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5f4e33bc..5198552a1 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "runkitExampleFilename": ".runkit_example.js", "dependencies": { "fast-deep-equal": "^3.1.3", - "fast-uri": "^2.3.1", + "fast-uri": "^2.4.0", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" },