Skip to content

Commit

Permalink
Update types/urijs
Browse files Browse the repository at this point in the history
Update types/urijs to the latest
version and update the names for
the types in the code.

Also change the code that previously
accessed the internal "expression"
of URITemplate to remember the URL
instead and remove those accesses.

Fixes TerriaJS#4116
  • Loading branch information
pjonsson committed Jan 2, 2025
1 parent 1b4b675 commit d24497e
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 36 deletions.
4 changes: 3 additions & 1 deletion lib/Core/uriHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const getUriWithoutPath = (anyUri: uri.URI) => {
import type URI from "urijs";

export const getUriWithoutPath = (anyUri: URI) => {
if (!anyUri) {
return undefined;
}
Expand Down
12 changes: 8 additions & 4 deletions lib/Map/ImageryProvider/MapboxVectorTileImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import WebMercatorTilingScheme from "terriajs-cesium/Source/Core/WebMercatorTili
import WindingOrder from "terriajs-cesium/Source/Core/WindingOrder";
import ImageryLayerFeatureInfo from "terriajs-cesium/Source/Scene/ImageryLayerFeatureInfo";
import TileDiscardPolicy from "terriajs-cesium/Source/Scene/TileDiscardPolicy";
import URITemplate from "urijs/src/URITemplate";
import URITemplate, {
type URITemplate as URITemplateType
} from "urijs/src/URITemplate";
import isDefined from "../../Core/isDefined";
import loadArrayBuffer from "../../Core/loadArrayBuffer";
import { ImageryProviderWithGridLayerSupport } from "../Leaflet/ImageryProviderLeafletGridLayer";
Expand Down Expand Up @@ -55,7 +57,8 @@ interface MapboxVectorTileImageryProviderOptions {
export default class MapboxVectorTileImageryProvider
implements ImageryProviderWithGridLayerSupport
{
private readonly _uriTemplate: uri.URITemplate;
private readonly _uriTemplate: URITemplateType;
private readonly _url: string;
private readonly _layerName: string;
private readonly _subdomains: string[];
private readonly _styleFunc: (
Expand All @@ -77,6 +80,7 @@ export default class MapboxVectorTileImageryProvider
private readonly _credit?: Credit | string;

constructor(options: MapboxVectorTileImageryProviderOptions) {
this._url = options.url;
this._uriTemplate = new URITemplate(options.url);
this._layerName = options.layerName;

Expand Down Expand Up @@ -134,7 +138,7 @@ export default class MapboxVectorTileImageryProvider
}

get url() {
return this._uriTemplate.expression;
return this._url;
}

get tileWidth() {
Expand Down Expand Up @@ -530,7 +534,7 @@ export default class MapboxVectorTileImageryProvider
return undefined;
};
const imageryProvider = new MapboxVectorTileImageryProvider({
url: this._uriTemplate.expression,
url: this.url,
layerName: this._layerName,
subdomains: this._subdomains,
rectangle: this._rectangle,
Expand Down
2 changes: 1 addition & 1 deletion lib/ModelMixins/UrlMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function UrlMixin<T extends AbstractConstructor<BaseType>>(Base: T) {
}

@computed
get uri(): uri.URI | undefined {
get uri(): URI | undefined {
if (this.url === undefined) {
return undefined;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Models/Catalog/CatalogReferences/MagdaReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default class MagdaReference extends AccessControlMixin(
}

@computed
get registryUri(): uri.URI | undefined {
get registryUri(): URI | undefined {
const uri = this.uri;
if (uri === undefined) {
return undefined;
Expand Down Expand Up @@ -258,7 +258,7 @@ export default class MagdaReference extends AccessControlMixin(
terria: Terria,
sourceReference: BaseModel | undefined,
distributionFormats: readonly PreparedDistributionFormat[],
magdaUri: uri.URI | undefined,
magdaUri: URI | undefined,
id: string | undefined,
record: JsonObject | undefined,
override: JsonObject | undefined,
Expand Down Expand Up @@ -374,7 +374,7 @@ export default class MagdaReference extends AccessControlMixin(
terria: Terria,
sourceReference: BaseModel | undefined,
distributionFormats: readonly PreparedDistributionFormat[],
magdaUri: uri.URI | undefined,
magdaUri: URI | undefined,
id: string | undefined,
record: JsonObject,
override: JsonObject | undefined,
Expand Down Expand Up @@ -559,7 +559,7 @@ export default class MagdaReference extends AccessControlMixin(
private static createMemberFromTerriaAspect(
terria: Terria,
sourceReference: BaseModel | undefined,
_magdaUri: uri.URI | undefined,
_magdaUri: URI | undefined,
id: string | undefined,
record: JsonObject,
terriaAspect: JsonObject,
Expand Down Expand Up @@ -634,7 +634,7 @@ export default class MagdaReference extends AccessControlMixin(
private static createMemberFromDistributionFormat(
terria: Terria,
sourceReference: BaseModel | undefined,
_magdaUri: uri.URI | undefined,
_magdaUri: URI | undefined,
id: string | undefined,
datasetRecord: JsonObject,
distributionRecord: JsonObject,
Expand Down Expand Up @@ -849,7 +849,7 @@ export default class MagdaReference extends AccessControlMixin(
return loadJson(proxiedUrl, options.magdaReferenceHeaders);
}

protected buildMagdaRecordUri(options: RecordOptions): uri.URI | undefined {
protected buildMagdaRecordUri(options: RecordOptions): URI | undefined {
const registryUri = this.registryUri;
if (options.id === undefined || registryUri === undefined) {
return undefined;
Expand Down
5 changes: 1 addition & 4 deletions lib/Models/Catalog/Ckan/CkanCatalogGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ export class CkanServerStratum extends LoadableStratum(CkanCatalogGroupTraits) {
) as this;
}

static addFilterQuery(
uri: uri.URI,
filterQuery: JsonObject | string
): uri.URI {
static addFilterQuery(uri: URI, filterQuery: JsonObject | string): URI {
if (typeof filterQuery === "string") {
// An encoded filterQuery may look like "fq=+(res_format%3Awms%20OR%20res_format%3AWMS)".
// An unencoded filterQuery may look like "fq=(res_format:wms OR res_format:WMS)".
Expand Down
2 changes: 1 addition & 1 deletion lib/Models/Catalog/Esri/ArcGisImageServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function getBaseURI(item: ArcGisImageServerCatalogItem) {
return uri;
}

async function getJson(item: ArcGisImageServerCatalogItem, uri: uri.URI) {
async function getJson(item: ArcGisImageServerCatalogItem, uri: URI) {
try {
const response = await loadJson(
proxyCatalogItemUrl(item, uri.addQuery("f", "json").toString())
Expand Down
2 changes: 1 addition & 1 deletion lib/Models/Catalog/Ows/WebMapServiceCapabilitiesStratum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class WebMapServiceCapabilitiesStratum extends LoadableStratum(
const layer = layers[i];
const style = i < styles.length ? styles[i] : undefined;

let legendUri: uri.URI | undefined;
let legendUri: URI | undefined;
let legendUrlMimeType: string | undefined;
let legendScaling: number | undefined;

Expand Down
8 changes: 4 additions & 4 deletions lib/Models/Terria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ export default class Terria {
this.modelIdShareKeysMap.set(id, [shareKey]);
}

setupInitializationUrls(baseUri: uri.URI, config: any): void {
setupInitializationUrls(baseUri: URI, config: any): void {
const initializationUrls: string[] = config?.initializationUrls || [];
const initSources: InitSource[] = initializationUrls.map((url) => ({
name: `Init URL from config ${url}`,
Expand Down Expand Up @@ -2002,7 +2002,7 @@ export default class Terria {
async loadMagdaConfig(
configUrl: string,
config: any,
baseUri: uri.URI
baseUri: URI
): Promise<void> {
const aspects = config.aspects;
const configParams = aspects["terria-config"]?.parameters;
Expand Down Expand Up @@ -2179,7 +2179,7 @@ export default class Terria {
}

function generateInitializationUrl(
baseUri: uri.URI,
baseUri: URI,
initFragmentPaths: string[],
url: string
): InitSource {
Expand All @@ -2205,7 +2205,7 @@ async function interpretHash(
terria: Terria,
hashProperties: any,
userProperties: Map<string, any>,
baseUri: uri.URI
baseUri: URI
) {
if (isDefined(hashProperties.clean)) {
runInAction(() => {
Expand Down
1 change: 1 addition & 0 deletions lib/ReactViews/Map/MapNavigation/Items/MyLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import i18next from "i18next";
import { action, observable, runInAction, makeObservable } from "mobx";
import React from "react";
import CesiumCartographic from "terriajs-cesium/Source/Core/Cartographic";
import URI from "urijs";
import createGuid from "terriajs-cesium/Source/Core/createGuid";
import Rectangle from "terriajs-cesium/Source/Core/Rectangle";
import isDefined from "../../../../Core/isDefined";
Expand Down
9 changes: 0 additions & 9 deletions lib/ThirdParty/urijs/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@types/retry": "^0.12.0",
"@types/shpjs": "^3.4.0",
"@types/styled-components": "^5.1.26",
"@types/urijs": "1.19.1",
"@types/urijs": "^1.19.25",
"@visx/axis": "^3.10.1",
"@visx/clip-path": "^3.3.0",
"@visx/event": "^3.3.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2272,10 +2272,10 @@
dependencies:
source-map "^0.6.1"

"@types/[email protected].1":
version "1.19.1"
resolved "https://registry.yarnpkg.com/@types/urijs/-/urijs-1.19.1.tgz#da69e8479eec0bb4580c7cc218d218f107d2d526"
integrity sha512-5waMuQ9z8pH8+5yAyX05bsA7SOl50l5ZkeMripxoOgN2+nSQb4TOSuhWoRlPt7FPIIohk6iBrX/rEktUJa8KfQ==
"@types/urijs@^1.19.25":
version "1.19.25"
resolved "https://registry.yarnpkg.com/@types/urijs/-/urijs-1.19.25.tgz#ac92b53e674c3b108decdbe88dc5f444a2f42f6a"
integrity sha512-XOfUup9r3Y06nFAZh3WvO0rBU4OtlfPB/vgxpjg+NRdGU6CN6djdc6OEiH+PcqHCY6eFLo9Ista73uarf4gnBg==

"@types/webpack-sources@*":
version "3.2.0"
Expand Down

0 comments on commit d24497e

Please sign in to comment.