Skip to content

Commit

Permalink
Revert "Revert fast-uri change (ajv-validator#2444)"
Browse files Browse the repository at this point in the history
This reverts commit c8b37f4.
  • Loading branch information
gurgunday committed Jun 8, 2024
1 parent c8b37f4 commit 63d3acc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Badge text="v7" />

Expand Down
4 changes: 2 additions & 2 deletions lib/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/compile/resolve.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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] + "#"
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/uri.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 3 additions & 3 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions spec/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 63d3acc

Please sign in to comment.