mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
* Work through linter issues related to non-null checks and any.
This commit is contained in:
@@ -77,7 +77,7 @@ export const leafletRasterLayer = (source: PMTiles, options: any) => {
|
|||||||
// copied from MapLibre /util/ajax.ts
|
// copied from MapLibre /util/ajax.ts
|
||||||
type RequestParameters = {
|
type RequestParameters = {
|
||||||
url: string;
|
url: string;
|
||||||
headers?: any;
|
headers?: unknown;
|
||||||
method?: "GET" | "POST" | "PUT";
|
method?: "GET" | "POST" | "PUT";
|
||||||
body?: string;
|
body?: string;
|
||||||
type?: "string" | "json" | "arrayBuffer" | "image";
|
type?: "string" | "json" | "arrayBuffer" | "image";
|
||||||
@@ -87,7 +87,7 @@ type RequestParameters = {
|
|||||||
|
|
||||||
type ResponseCallback = (
|
type ResponseCallback = (
|
||||||
error?: Error | null,
|
error?: Error | null,
|
||||||
data?: any | null,
|
data?: unknown | null,
|
||||||
cacheControl?: string | null,
|
cacheControl?: string | null,
|
||||||
expires?: string | null
|
expires?: string | null
|
||||||
) => void;
|
) => void;
|
||||||
|
|||||||
52
js/index.ts
52
js/index.ts
@@ -296,10 +296,13 @@ export class FetchSource implements Source {
|
|||||||
async getBytes(
|
async getBytes(
|
||||||
offset: number,
|
offset: number,
|
||||||
length: number,
|
length: number,
|
||||||
signal?: AbortSignal
|
passedSignal?: AbortSignal
|
||||||
): Promise<RangeResponse> {
|
): Promise<RangeResponse> {
|
||||||
let controller;
|
let controller: AbortController | undefined;
|
||||||
if (!signal) {
|
let signal: AbortSignal | undefined;
|
||||||
|
if (passedSignal) {
|
||||||
|
signal = passedSignal;
|
||||||
|
} else {
|
||||||
// TODO check this works or assert 206
|
// TODO check this works or assert 206
|
||||||
controller = new AbortController();
|
controller = new AbortController();
|
||||||
signal = controller.signal;
|
signal = controller.signal;
|
||||||
@@ -567,9 +570,10 @@ export class ResolvedValueCache {
|
|||||||
|
|
||||||
async getHeader(source: Source, currentEtag?: string): Promise<Header> {
|
async getHeader(source: Source, currentEtag?: string): Promise<Header> {
|
||||||
const cacheKey = source.getKey();
|
const cacheKey = source.getKey();
|
||||||
if (this.cache.has(cacheKey)) {
|
const cacheValue = this.cache.get(cacheKey);
|
||||||
this.cache.get(cacheKey)!.lastUsed = this.counter++;
|
if (cacheValue) {
|
||||||
const data = this.cache.get(cacheKey)?.data;
|
cacheValue.lastUsed = this.counter++;
|
||||||
|
const data = cacheValue.data;
|
||||||
return data as Header;
|
return data as Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,9 +607,10 @@ export class ResolvedValueCache {
|
|||||||
const cacheKey = `${source.getKey()}|${
|
const cacheKey = `${source.getKey()}|${
|
||||||
header.etag || ""
|
header.etag || ""
|
||||||
}|${offset}|${length}`;
|
}|${offset}|${length}`;
|
||||||
if (this.cache.has(cacheKey)) {
|
const cacheValue = this.cache.get(cacheKey);
|
||||||
this.cache.get(cacheKey)!.lastUsed = this.counter++;
|
if (cacheValue) {
|
||||||
const data = this.cache.get(cacheKey)?.data;
|
cacheValue.lastUsed = this.counter++;
|
||||||
|
const data = cacheValue.data;
|
||||||
return data as Entry[];
|
return data as Entry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,9 +639,10 @@ export class ResolvedValueCache {
|
|||||||
const cacheKey = `${source.getKey()}|${
|
const cacheKey = `${source.getKey()}|${
|
||||||
header.etag || ""
|
header.etag || ""
|
||||||
}|${offset}|${length}`;
|
}|${offset}|${length}`;
|
||||||
if (this.cache.has(cacheKey)) {
|
const cacheValue = this.cache.get(cacheKey);
|
||||||
this.cache.get(cacheKey)!.lastUsed = this.counter++;
|
if (cacheValue) {
|
||||||
const data = await this.cache.get(cacheKey)?.data;
|
cacheValue.lastUsed = this.counter++;
|
||||||
|
const data = await cacheValue.data;
|
||||||
return data as ArrayBuffer;
|
return data as ArrayBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,9 +710,10 @@ export class SharedPromiseCache {
|
|||||||
|
|
||||||
async getHeader(source: Source, currentEtag?: string): Promise<Header> {
|
async getHeader(source: Source, currentEtag?: string): Promise<Header> {
|
||||||
const cacheKey = source.getKey();
|
const cacheKey = source.getKey();
|
||||||
if (this.cache.has(cacheKey)) {
|
const cacheValue = this.cache.get(cacheKey);
|
||||||
this.cache.get(cacheKey)!.lastUsed = this.counter++;
|
if (cacheValue) {
|
||||||
const data = await this.cache.get(cacheKey)?.data;
|
cacheValue.lastUsed = this.counter++;
|
||||||
|
const data = await cacheValue.data;
|
||||||
return data as Header;
|
return data as Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,9 +746,10 @@ export class SharedPromiseCache {
|
|||||||
const cacheKey = `${source.getKey()}|${
|
const cacheKey = `${source.getKey()}|${
|
||||||
header.etag || ""
|
header.etag || ""
|
||||||
}|${offset}|${length}`;
|
}|${offset}|${length}`;
|
||||||
if (this.cache.has(cacheKey)) {
|
const cacheValue = this.cache.get(cacheKey);
|
||||||
this.cache.get(cacheKey)!.lastUsed = this.counter++;
|
if (cacheValue) {
|
||||||
const data = await this.cache.get(cacheKey)?.data;
|
cacheValue.lastUsed = this.counter++;
|
||||||
|
const data = await cacheValue.data;
|
||||||
return data as Entry[];
|
return data as Entry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,9 +777,10 @@ export class SharedPromiseCache {
|
|||||||
const cacheKey = `${source.getKey()}|${
|
const cacheKey = `${source.getKey()}|${
|
||||||
header.etag || ""
|
header.etag || ""
|
||||||
}|${offset}|${length}`;
|
}|${offset}|${length}`;
|
||||||
if (this.cache.has(cacheKey)) {
|
const cacheValue = this.cache.get(cacheKey);
|
||||||
this.cache.get(cacheKey)!.lastUsed = this.counter++;
|
if (cacheValue) {
|
||||||
const data = await this.cache.get(cacheKey)?.data;
|
cacheValue.lastUsed = this.counter++;
|
||||||
|
const data = await cacheValue.data;
|
||||||
return data as ArrayBuffer;
|
return data as ArrayBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,6 +826,7 @@ export class SharedPromiseCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// biome-ignore lint: that's just how its capitalized
|
||||||
export class PMTiles {
|
export class PMTiles {
|
||||||
source: Source;
|
source: Source;
|
||||||
cache: Cache;
|
cache: Cache;
|
||||||
|
|||||||
Reference in New Issue
Block a user