Skip to content

Commit

Permalink
BlockLoaderExtra config typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ikreymer committed Sep 9, 2024
1 parent 09b4f52 commit 9430331
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
26 changes: 10 additions & 16 deletions src/blockloaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ export type ResponseAbort = {
abort: AbortController | null;
};

export type BlockLoaderExtra = {
arrayBuffer?: Uint8Array;
publicUrl?: string;
fileHandle?: FileSystemFileHandle;
};

export type BlockLoaderOpts = {
url: string;
headers?: Record<string, string> | Headers;
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extra?: Record<string, any>;
extra?: BlockLoaderExtra;
size?: number;
blob?: Blob;
};
Expand All @@ -26,11 +30,7 @@ export type BlockLoaderOpts = {
export async function createLoader(opts: BlockLoaderOpts): Promise<BaseLoader> {
const { url } = opts;

// @ts-expect-error [TODO] - TS4111 - Property 'arrayBuffer' comes from an index signature, so it must be accessed with ['arrayBuffer'].
if (opts.extra?.arrayBuffer) {
// @ts-expect-error [TODO] - TS4111 - Property 'arrayBuffer' comes from an index signature, so it must be accessed with ['arrayBuffer'].
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return new ArrayBufferLoader(opts.extra.arrayBuffer);
}

Expand Down Expand Up @@ -309,19 +309,15 @@ class GoogleDriveLoader extends BaseLoader {
url: string;
headers?: Record<string, string> | Headers;
size?: number;
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extra?: Record<string, any>;
extra?: BlockLoaderExtra;
}) {
super(true);

this.fileId = url.slice("googledrive://".length);
this.apiUrl = `https://www.googleapis.com/drive/v3/files/${this.fileId}?alt=media`;

this.headers = headers || {};
// @ts-expect-error [TODO] - TS4111 - Property 'publicUrl' comes from an index signature, so it must be accessed with ['publicUrl'].
if (extra?.publicUrl) {
// @ts-expect-error [TODO] - TS4111 - Property 'publicUrl' comes from an index signature, so it must be accessed with ['publicUrl'].
this.publicUrl = extra.publicUrl;
}
this.length = size || 0;
Expand Down Expand Up @@ -641,9 +637,7 @@ class FileHandleLoader extends BaseLoader {
}: {
blob?: Blob | null;
size?: number;
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extra?: any;
extra?: BlockLoaderExtra;
url: string;
}) {
super(true);
Expand All @@ -653,7 +647,7 @@ class FileHandleLoader extends BaseLoader {
this.size = blob ? blob.size : size || 0;
this.length = this.size;

this.fileHandle = extra.fileHandle;
this.fileHandle = extra!.fileHandle!;
}

get isValid() {
Expand Down
7 changes: 2 additions & 5 deletions src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ export class CollectionLoader {
}

async initNewColl(
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metadata: Record<string, any>,
metadata: CollMetadata,
extraConfig = {},
type = "archive",
) {
Expand Down Expand Up @@ -671,7 +669,7 @@ export class WorkerLoader extends CollectionLoader {
// [TODO]
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
if (this._fileHandles && this._fileHandles[config.sourceUrl]) {
config.extra = { fileHandle: this._fileHandles[config.sourceUrl] };
config.extra = { fileHandle: this._fileHandles[config.sourceUrl]! };
} else {
progressUpdate(0, "missing_local_file");
return false;
Expand Down Expand Up @@ -895,7 +893,6 @@ Make sure this is a valid URL and you have access to this file.`,

config.ctime = new Date().getTime();

// @ts-expect-error [TODO] - TS4111 - Property 'extra' comes from an index signature, so it must be accessed with ['extra'].
if (this._fileHandles && config.extra?.fileHandle) {
delete this._fileHandles[config.sourceUrl];
}
Expand Down
6 changes: 2 additions & 4 deletions src/swmain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class SWCollections extends WorkerLoader {
prefixes: Prefixes;
colls: Record<string, Collection>;
inited: Promise<boolean> | null;
// @ts-expect-error [TODO] - TS4114 - This member must have an 'override' modifier because it overrides a member in the base class 'WorkerLoader'.
root: string | null;

override root: string | null;
// [TODO]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
defaultConfig: Record<string, any>;
Expand Down Expand Up @@ -102,11 +102,9 @@ export class SWCollections extends WorkerLoader {
if (
this._fileHandles &&
keepFileHandle &&
// @ts-expect-error [TODO] - TS2532 - Object is possibly 'undefined'. | TS4111 - Property 'extra' comes from an index signature, so it must be accessed with ['extra'].
this.colls[name].config.extra?.fileHandle
) {
this._fileHandles[this.colls[name].config.sourceUrl] =
// @ts-expect-error [TODO] - TS2532 - Object is possibly 'undefined'. | TS4111 - Property 'extra' comes from an index signature, so it must be accessed with ['extra'].
this.colls[name].config.extra.fileHandle;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type BaseAsyncIterReader } from "warcio";
import { type ArchiveRequest } from "./request";
import { type ArchiveResponse } from "./response";
import { type BlockLoaderExtra } from "./blockloaders";

export type Source = {
start: number;
Expand Down Expand Up @@ -155,8 +156,7 @@ export type CollConfig = {

headers?: Record<string, string>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
extra?: Record<string, any>;
extra?: BlockLoaderExtra;

noCache?: boolean;

Expand Down

0 comments on commit 9430331

Please sign in to comment.