Skip to content

Commit 63d3acc

Browse files
committed
Revert "Revert fast-uri change (ajv-validator#2444)"
This reverts commit c8b37f4.
1 parent c8b37f4 commit 63d3acc

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

docs/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Include human-readable messages in errors. `true` by default. `false` can be pas
344344

345345
### uriResolver
346346

347-
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).
347+
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).
348348

349349
### code <Badge text="v7" />
350350

lib/compile/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import N from "./names"
1414
import {LocalRefs, getFullPath, _getFullPath, inlineRef, normalizeId, resolveUrl} from "./resolve"
1515
import {schemaHasRulesButRef, unescapeFragment} from "./util"
1616
import {validateFunctionCode} from "./validate"
17-
import * as URI from "uri-js"
17+
import {URIComponent} from "fast-uri"
1818
import {JSONType} from "./rules"
1919

2020
export type SchemaRefs = {
@@ -295,7 +295,7 @@ const PREVENT_SCOPE_CHANGE = new Set([
295295

296296
function getJsonPointer(
297297
this: Ajv,
298-
parsedRef: URI.URIComponents,
298+
parsedRef: URIComponent,
299299
{baseId, schema, root}: SchemaEnv
300300
): SchemaEnv | undefined {
301301
if (parsedRef.fragment?.[0] !== "/") return

lib/compile/resolve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {AnySchema, AnySchemaObject, UriResolver} from "../types"
22
import type Ajv from "../ajv"
3-
import type {URIComponents} from "uri-js"
3+
import type {URIComponent} from "fast-uri"
44
import {eachItem} from "./util"
55
import * as equal from "fast-deep-equal"
66
import * as traverse from "json-schema-traverse"
@@ -73,7 +73,7 @@ export function getFullPath(resolver: UriResolver, id = "", normalize?: boolean)
7373
return _getFullPath(resolver, p)
7474
}
7575

76-
export function _getFullPath(resolver: UriResolver, p: URIComponents): string {
76+
export function _getFullPath(resolver: UriResolver, p: URIComponent): string {
7777
const serialized = resolver.serialize(p)
7878
return serialized.split("#")[0] + "#"
7979
}

lib/runtime/uri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as uri from "uri-js"
1+
import * as uri from "fast-uri"
22

33
type URI = typeof uri & {code: string}
44
;(uri as URI).code = 'require("ajv/dist/runtime/uri").default'

lib/types/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as URI from "uri-js"
1+
import {URIComponent} from "fast-uri"
22
import type {CodeGen, Code, Name, ScopeValueSets, ValueScopeName} from "../compile/codegen"
33
import type {SchemaEnv, SchemaCxt, SchemaObjCxt} from "../compile"
44
import type {JSONType} from "../compile/rules"
@@ -238,7 +238,7 @@ export interface RegExpLike {
238238
}
239239

240240
export interface UriResolver {
241-
parse(uri: string): URI.URIComponents
241+
parse(uri: string): URIComponent
242242
resolve(base: string, path: string): string
243-
serialize(component: URI.URIComponents): string
243+
serialize(component: URIComponent): string
244244
}

spec/resolve.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import _Ajv from "./ajv"
44
import type {AnyValidateFunction} from "../dist/types"
55
import type MissingRefError from "../dist/compile/ref_error"
66
import chai from "./chai"
7-
import * as fastUri from "fast-uri"
7+
import * as uriJs from "uri-js"
88
const should = chai.should()
99

10-
const uriResolvers = [undefined, fastUri]
10+
const uriResolvers = [undefined, uriJs]
1111

1212
uriResolvers.forEach((resolver) => {
1313
let describeTitle: string
1414
if (resolver !== undefined) {
15-
describeTitle = "fast-uri resolver"
16-
} else {
1715
describeTitle = "uri-js resolver"
16+
} else {
17+
describeTitle = "fast-uri resolver"
1818
}
1919
describe(describeTitle, () => {
2020
describe("resolve", () => {

0 commit comments

Comments
 (0)