Skip to content

Commit 6558c8c

Browse files
authored
Update dependencies and CI image (#232)
* [CI] Upgrade to the latest CI image and upgrade babel deps and types * Upgrade semver * Upgrade @types/node * Upgrade to husy 9 * Update eslint, jest, typescript * Add prepare script for husky * Upgrade @types/node and maplibre * Add prettier to the lint script and lint fixes * Upgrade maplibre * Upgrade node-fetch * Upgrade lru-cache * Downgrade lru-cache to 7.18.3 * [skip-ci] Update changelog
1 parent 8791b32 commit 6558c8c

12 files changed

+2193
-3411
lines changed

.buildkite/pipeline.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
agents:
2-
image: "docker.elastic.co/ci-agent-images/ems/buildkite-agent-node20:0.1"
2+
image: "docker.elastic.co/ci-agent-images/ems/buildkite-agent-node20:0.4"
33
cpu: "2"
44
memory: "2G"
55

.eslintignore

-1
This file was deleted.

.eslintrc

-18
This file was deleted.

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn test

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
## Added
99

1010
## Changed
11-
11+
- Update dependencies #232
1212

1313
## [8.5.1] - 2023-11-09
1414

eslint.config.mjs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import tseslint from 'typescript-eslint';
5+
import globals from 'globals';
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
...tseslint.configs.recommended,
10+
{
11+
ignores: ["target","*.config.js"]
12+
},
13+
{
14+
files: ['**/*.{ts,tsx,mts,cts}'],
15+
rules: {
16+
'no-undef': 'off',
17+
'@typescript-eslint/ban-types': 'off'
18+
},
19+
"languageOptions": {
20+
"globals": {
21+
...globals.node
22+
}
23+
}
24+
},
25+
);

package.json

+23-24
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"browser": "target/web/index.js",
77
"types": "target/index.d.ts",
88
"scripts": {
9+
"prepare": "husky",
910
"prelint": "tsc --noEmit",
10-
"lint": "eslint . --ext .ts,.tsx",
11+
"lint": "prettier --check src/* && eslint .",
1112
"pretest": "yarn lint",
1213
"test": "jest",
1314
"build": "tsc --emitDeclarationOnly && yarn build-web && yarn build-node",
@@ -29,20 +30,14 @@
2930
"url": "https://github.com/elastic/ems-client/issues"
3031
},
3132
"homepage": "https://github.com/elastic/ems-client#readme",
32-
"husky": {
33-
"hooks": {
34-
"pre-commit": "yarn test"
35-
}
36-
},
3733
"dependencies": {
3834
"@types/geojson": "^7946.0.14",
39-
"@types/lru-cache": "^5.1.0",
4035
"@types/topojson-client": "^3.1.4",
4136
"@types/topojson-specification": "^1.0.5",
4237
"chroma-js": "^2.1.0",
4338
"lodash": "^4.17.15",
44-
"lru-cache": "^6.0.0",
45-
"semver": "7.6.0",
39+
"lru-cache": "7.18.3",
40+
"semver": "7.6.2",
4641
"topojson-client": "^3.1.0"
4742
},
4843
"devDependencies": {
@@ -51,25 +46,29 @@
5146
"@babel/plugin-proposal-class-properties": "^7.5.5",
5247
"@babel/preset-env": "^7.5.5",
5348
"@babel/preset-typescript": "^7.9.0",
49+
"@eslint/js": "^9.3.0",
5450
"@types/chroma-js": "^2.1.3",
55-
"@types/jest": "^26.0.10",
51+
"@types/eslint__js": "^8.42.3",
52+
"@types/jest": "^29.5.12",
5653
"@types/lodash": "^4.14.150",
57-
"@types/node": "^13.13.5",
54+
"@types/node": "^20.12.13",
5855
"@types/node-fetch": "^2.5.7",
5956
"@types/semver": "^7.1.0",
60-
"@typescript-eslint/eslint-plugin": "^2.33.0",
61-
"@typescript-eslint/parser": "^2.33.0",
62-
"babel-jest": "^26.3.0",
63-
"eslint": "^7.0.0",
64-
"eslint-config-prettier": "^6.11.0",
65-
"eslint-plugin-prettier": "^3.1.3",
66-
"husky": "^4.2.5",
67-
"jest": "^26.4.0",
68-
"maplibre-gl": "2.1.9",
69-
"node-fetch": "^2.6.1",
70-
"prettier": "^2.0.5",
71-
"ts-jest": "^26.2.0",
72-
"typescript": "4.6.3"
57+
"@typescript-eslint/eslint-plugin": "^7.11.0",
58+
"@typescript-eslint/parser": "^7.11.0",
59+
"babel-jest": "^29.7.0",
60+
"eslint": "^9.3.0",
61+
"eslint-config-prettier": "^9.1.0",
62+
"eslint-plugin-prettier": "^5.1.3",
63+
"globals": "^15.3.0",
64+
"husky": "^9.0.11",
65+
"jest": "^29.7.0",
66+
"maplibre-gl": "4.3.2",
67+
"node-fetch": "^2.7.0",
68+
"prettier": "^3.2.5",
69+
"ts-jest": "^29.1.4",
70+
"typescript": "^5.4.5",
71+
"typescript-eslint": "^7.11.0"
7372
},
7473
"engines": {
7574
"node": ">=18 <=20"

src/ems_client.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ export class EMSClient {
290290
if (!response.ok) {
291291
throw new Error(response.statusText);
292292
}
293-
return response ? await response.json() : null;
293+
if (response) {
294+
return (await response.json()) as Promise<T>;
295+
} else {
296+
throw new Error('Response not found');
297+
}
294298
} catch (e) {
295299
if (e instanceof Error) {
296300
throw e;
@@ -307,7 +311,7 @@ export class EMSClient {
307311
*/
308312
addQueryParams(additionalQueryParams: { [key: string]: string }): void {
309313
for (const key in additionalQueryParams) {
310-
if (additionalQueryParams.hasOwnProperty(key)) {
314+
if (Object.prototype.hasOwnProperty.call(additionalQueryParams, key)) {
311315
if (additionalQueryParams[key] !== this._queryParams[key]) {
312316
//changes detected.
313317
this._queryParams = _.assign({}, this._queryParams, additionalQueryParams);
@@ -426,7 +430,7 @@ export class EMSClient {
426430
}
427431

428432
private _invalidateSettings(): void {
429-
this._cache.reset();
433+
this._cache.clear();
430434
this._getMainCatalog = _.once(async (): Promise<EmsCatalogManifest> => {
431435
const services = [];
432436
if (this._tileApiUrl) {

src/tms_service.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ export class TMSService extends AbstractEmsService {
169169
if (url) {
170170
const sourceUrl = this._proxyPath + this._getAbsoluteUrl(url);
171171
const extendedUrl = this._emsClient.extendUrlWithParams(sourceUrl);
172-
const sourceJson = await this._emsClient.getManifest<VectorSourceSpecification>(
173-
extendedUrl
174-
);
172+
const sourceJson =
173+
await this._emsClient.getManifest<VectorSourceSpecification>(extendedUrl);
175174
const tiles = sourceJson?.tiles?.map((tileUrl) => {
176175
const directUrl = this._proxyPath + this._getAbsoluteUrl(tileUrl);
177176
return this._emsClient.extendUrlWithParams(directUrl);
@@ -374,33 +373,41 @@ export class TMSService extends AbstractEmsService {
374373

375374
async getMinZoom(format = 'vector'): Promise<number | undefined> {
376375
switch (format) {
377-
case 'vector':
376+
case 'vector': {
378377
const { sources } = (await this._getVectorStyleJsonInlined()) || { sources: {} };
379378
return Math.min(
380379
...Object.values(sources)
381-
.map(({ minzoom }) => minzoom)
380+
.map((s) => {
381+
return s && s instanceof Object && 'minzoom' in s ? s['minzoom'] : null;
382+
})
382383
.filter((minzoom): minzoom is number => Number.isFinite(minzoom))
383384
);
384-
case 'raster':
385+
}
386+
case 'raster': {
385387
const { minzoom } = (await this._getRasterStyleJson()) || {};
386388
return minzoom;
389+
}
387390
default:
388391
return;
389392
}
390393
}
391394

392395
async getMaxZoom(format = 'vector'): Promise<number | undefined> {
393396
switch (format) {
394-
case 'vector':
397+
case 'vector': {
395398
const { sources } = (await this._getVectorStyleJsonInlined()) || { sources: {} };
396399
return Math.max(
397400
...Object.values(sources)
398-
.map(({ maxzoom }) => maxzoom)
401+
.map((s) => {
402+
return s && s instanceof Object && 'maxzoom' in s ? s['maxzoom'] : null;
403+
})
399404
.filter((maxzoom): maxzoom is number => Number.isFinite(maxzoom))
400405
);
401-
case 'raster':
406+
}
407+
case 'raster': {
402408
const { maxzoom } = (await this._getRasterStyleJson()) || {};
403409
return maxzoom;
410+
}
404411
default:
405412
return;
406413
}
@@ -425,13 +432,12 @@ export class TMSService extends AbstractEmsService {
425432
vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
426433
}
427434
if (!vectorFormats.length) {
428-
// eslint-disable-next-line max-len
429435
throw new Error(
430436
`Cannot find ${formatType} tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`
431437
);
432438
}
433439
const defaultStyle = vectorFormats[0];
434-
if (defaultStyle && defaultStyle.hasOwnProperty('url')) {
440+
if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
435441
return defaultStyle.url;
436442
}
437443
}
@@ -445,7 +451,7 @@ export class TMSService extends AbstractEmsService {
445451
private async _getSpriteSheetRootPath(): Promise<string> {
446452
const vectorStyleJson = await this._getVectorStyleJsonRaw();
447453
if (vectorStyleJson?.sprite) {
448-
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite);
454+
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite.toString());
449455
} else {
450456
return '';
451457
}

test/__snapshots__/ems_client.test.ts.snap

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`.getFileLayers[1] - getGeoJson defaults should convert topojson to geojson 1`] = `
4-
Object {
5-
"features": Array [
6-
Object {
7-
"geometry": Object {
8-
"coordinates": Array [
9-
Array [
10-
Array [
4+
{
5+
"features": [
6+
{
7+
"geometry": {
8+
"coordinates": [
9+
[
10+
[
1111
72.77144284428442,
1212
62.593,
1313
],
14-
Array [
14+
[
1515
50.625,
1616
50.06444104410441,
1717
],
18-
Array [
18+
[
1919
91.7565793579358,
2020
35.46,
2121
],
22-
Array [
22+
[
2323
93.867,
2424
58.2621401140114,
2525
],
26-
Array [
26+
[
2727
72.77144284428442,
2828
62.593,
2929
],
3030
],
3131
],
3232
"type": "Polygon",
3333
},
34-
"properties": Object {
34+
"properties": {
3535
"foo": "bar",
3636
},
3737
"type": "Feature",
@@ -42,37 +42,37 @@ Object {
4242
`;
4343

4444
exports[`.getFileLayers[1] - getGeoJson limited cache 1`] = `
45-
Object {
46-
"features": Array [
47-
Object {
48-
"geometry": Object {
49-
"coordinates": Array [
50-
Array [
51-
Array [
45+
{
46+
"features": [
47+
{
48+
"geometry": {
49+
"coordinates": [
50+
[
51+
[
5252
72.77144284428442,
5353
62.593,
5454
],
55-
Array [
55+
[
5656
50.625,
5757
50.06444104410441,
5858
],
59-
Array [
59+
[
6060
91.7565793579358,
6161
35.46,
6262
],
63-
Array [
63+
[
6464
93.867,
6565
58.2621401140114,
6666
],
67-
Array [
67+
[
6868
72.77144284428442,
6969
62.593,
7070
],
7171
],
7272
],
7373
"type": "Polygon",
7474
},
75-
"properties": Object {
75+
"properties": {
7676
"foo": "bar",
7777
},
7878
"type": "Feature",

test/ems_client_util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function getEMSClient(options = {}) {
4242

4343
const getManifestMock = jest
4444
.spyOn(emsClient, 'getManifest')
45-
.mockImplementation(async (url: string): Promise<any> => {
45+
.mockImplementation(async (url: string): Promise<Object | unknown> => {
4646
//simulate network calls
4747
if (url.startsWith('https://foobar')) {
4848
return EMS_CATALOGUE;

0 commit comments

Comments
 (0)