Skip to content

Commit

Permalink
build: upgrade to typescript 5
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jun 25, 2024
1 parent 9826f9a commit d80f34a
Show file tree
Hide file tree
Showing 11 changed files with 723 additions and 730 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
...require('@linzjs/style/.eslintrc.cjs'),
const cfg = {
...require('@linzjs/style/.eslintrc.cjs'),
};

// Disable require await as we use `async foo() { throws Bar }` in a few places
const tsRules = cfg.overrides.find(ovr => ovr.files.find(f => f.endsWith('*.ts')));
tsRules.rules['@typescript-eslint/require-await'] = 'off'

module.exports = cfg;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "ISC",
"description": "",
"devDependencies": {
"@linzjs/style": "^5.1.0",
"@linzjs/style": "^5.4.0",
"@types/node": "^20.0.0",
"lerna": "^8.0.0",
"rimraf": "^4.1.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const commandInfo = command({
},
async handler(args) {
const logger = setupLogger(args);
const paths = [...args.paths, args.path].filter((f) => f != null) as URL[];
const paths = [...args.paths, args.path].filter((f) => f != null);

for (const path of paths) {
if (path.protocol === 's3:') await ensureS3fs();
Expand Down Expand Up @@ -241,7 +241,7 @@ function formatTag(tag: Tag): { key: string; value: string } {
let tagString = JSON.stringify(tag.value) ?? c.dim('null');
if (tagString.length > 256) tagString = tagString.slice(0, 250) + '...';
if (TagFormatters[tag.id]) {
complexType = ` - ${c.magenta(TagFormatters[tag.id]([tag.value as unknown as number]) ?? '??')}`;
complexType = ` - ${c.magenta(TagFormatters[tag.id]([tag.value as number]) ?? '??')}`;
}
return { key, value: tagString + complexType };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__benchmark__/cog.read.benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ async function main(): Promise<void> {
}
}

main();
void main();
2 changes: 1 addition & 1 deletion packages/core/src/__test__/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ async function main(): Promise<void> {
img.bbox;
}

main();
void main();
8 changes: 5 additions & 3 deletions packages/core/src/read/tiff.tag.factory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
import { TiffTag, TiffTagConvertArray } from '../const/tiff.tag.id.js';
import { TiffTagValueType } from '../const/tiff.tag.value.js';
import { Tiff } from '../tiff.js';
Expand Down Expand Up @@ -113,6 +114,7 @@ export function createTag(tiff: Tiff, view: DataViewOffset, offset: number): Tag
}

const dataOffset = getUint(view, offset + 4 + tiff.ifdConfig.pointer, tiff.ifdConfig.pointer, tiff.isLittleEndian);

switch (tagId) {
case TiffTag.TileOffsets:
case TiffTag.TileByteCounts:
Expand Down Expand Up @@ -166,7 +168,7 @@ export async function fetchAllOffsets(tiff: Tiff, tag: TagOffset): Promise<numbe
tag.view.sourceOffset = tag.dataOffset;
}

tag.value = readValue(tiff, tag.id, tag.view, 0, tag.dataType, tag.count) as number[];
tag.value = readValue(tiff, tag.id, tag.view, 0, tag.dataType, tag.count);
tag.isLoaded = true;
return tag.value;
}
Expand All @@ -188,13 +190,13 @@ export async function getValueAt(tiff: Tiff, tag: TagOffset, index: number): Pro
const bytes = await tiff.source.fetch(tag.dataOffset + index * dataTypeSize, dataTypeSize);
const view = new DataView(bytes);
// Skip type conversion to array by using undefined tiff tag id
const value = readValue(tiff, undefined, view, 0, tag.dataType, 1) as number;
const value = readValue(tiff, undefined, view, 0, tag.dataType, 1);
tag.value[index] = value;
return value;
}

// Skip type conversion to array by using undefined tiff tag id
const value = readValue(tiff, undefined, tag.view, index * dataTypeSize, tag.dataType, 1) as number;
const value = readValue(tiff, undefined, tag.view, index * dataTypeSize, tag.dataType, 1);
tag.value[index] = value;
return value;
}
2 changes: 1 addition & 1 deletion packages/core/src/read/tiff.value.reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export function getTiffTagSize(fieldType: TiffTagValueType): ByteSize {
case TiffTagValueType.Ifd8:
return 8;
default:
throw new Error(`Invalid fieldType ${fieldType}`);
throw new Error(`Invalid fieldType ${String(fieldType)}`);
}
}
4 changes: 2 additions & 2 deletions packages/core/src/tiff.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class TiffImage {
if (typeof tag.value === 'string') {
this.tagsGeo.set(key, tag.value.slice(offset, offset + count - 1).trim());
} else if (Array.isArray(tag.value)) {
if (count === 1) this.tagsGeo.set(key, tag.value[offset]);
if (count === 1) this.tagsGeo.set(key, tag.value[offset] as string);
else this.tagsGeo.set(key, tag.value.slice(offset, offset + count));
} else {
throw new Error('Failed to extract GeoTiffTags');
Expand Down Expand Up @@ -600,6 +600,6 @@ function getOffset(tiff: Tiff, x: TagOffset | TagInline<number[]>, index: number
}
// Sparse tiffs may not have the full tileWidth * tileHeight in their offset arrays
if (index >= x.count) return 0;
if (x.type === 'inline') return x.value[index] as number;
if (x.type === 'inline') return x.value[index];
return getValueAt(tiff, x, index);
}
8 changes: 4 additions & 4 deletions packages/core/src/tiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Tiff {
bytes.sourceOffset = 0;

let offset = 0;
const endian = bytes.getUint16(offset, this.isLittleEndian);
const endian = bytes.getUint16(offset, this.isLittleEndian) as TiffEndian;
offset += 2;

this.isLittleEndian = endian === TiffEndian.Little;
Expand All @@ -108,7 +108,7 @@ export class Tiff {
nextOffsetIfd = getUint(bytes, offset, this.ifdConfig.pointer, this.isLittleEndian);
offset += this.ifdConfig.pointer;
} else {
throw new Error(`Only tiff supported version:${this.version}`);
throw new Error(`Only tiff supported version:${String(this.version)}`);
}

const ghostSize = nextOffsetIfd - offset;
Expand All @@ -131,7 +131,7 @@ export class Tiff {
lastView = new DataView(bytes) as DataViewOffset;
lastView.sourceOffset = nextOffsetIfd;
}
nextOffsetIfd = await this.readIfd(nextOffsetIfd, lastView);
nextOffsetIfd = this.readIfd(nextOffsetIfd, lastView);
}

await Promise.all(this.images.map((i) => i.init()));
Expand All @@ -145,7 +145,7 @@ export class Tiff {
* @param offset file offset to read the header from
* @param view offset that contains the bytes for the header
*/
private async readIfd(offset: number, view: DataViewOffset): Promise<number> {
private readIfd(offset: number, view: DataViewOffset): number {
const viewOffset = offset - view.sourceOffset;
const tagCount = getUint(view, viewOffset, this.ifdConfig.offset, this.isLittleEndian);

Expand Down
9 changes: 5 additions & 4 deletions packages/examples/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ import { SourceCallback, SourceMiddleware, SourceRequest, SourceView } from '@ch
import { SourceHttp } from '@chunkd/source-http';
import { Tiff } from '@cogeotiff/core';

import { loadSingleTile } from './example.single.tile';
import { loadSingleTile } from './example.single.tile.js';

// Cache all requests to cogs
const cache = new SourceCache({ size: 16 * 1024 * 1024 }); // 16MB Cache
const chunk = new SourceChunk({ size: 16 * 1024 }); // Chunk requests into 16KB fetches
const fetchLog: SourceMiddleware = {
name: 'fetch:log',
fetch(req: SourceRequest, next: SourceCallback) {
this.fetches.push(req);
this.bytesRead += req.length ?? 0;
console.log('Tiff:fetch', { href: req.source.url.href, offset: req.offset, length: req.length });
return next(req);
},
};

document.addEventListener('DOMContentLoaded', async () => {
async function loadTiff(): Promise<void> {
const tiffSource = new SourceView(new SourceHttp('https://blayne.chard.com/world.webp.google.cog.tiff'), [
chunk,
cache,
Expand All @@ -32,4 +30,7 @@ document.addEventListener('DOMContentLoaded', async () => {

const nodes = await Promise.all([loadSingleTile(tiff)]);
for (const n of nodes) mainEl.appendChild(n);
}
document.addEventListener('DOMContentLoaded', () => {
void loadTiff();
});
Loading

0 comments on commit d80f34a

Please sign in to comment.