migrate JavaScript to TypeScript

This commit is contained in:
tdurieux
2021-08-11 18:18:45 +02:00
parent ee4a20286d
commit caeff49ab0
58 changed files with 6034 additions and 3096 deletions

98
src/types.ts Normal file
View File

@@ -0,0 +1,98 @@
import GitHubDownload from "./source/GitHubDownload";
import GitHubStream from "./source/GitHubStream";
import Zip from "./source/ZIP";
import S3Storage from "./storage/S3";
import FileSystem from "./storage/FileSystem";
import AnonymizedFile from "./AnonymizedFile";
import * as stream from "stream";
import * as archiver from "archiver";
export interface SourceBase {
readonly type: string;
/**
* The url of the source
*/
url?: string;
/**
* Retrieve the fie content
* @param file the file of the content to retrieve
*/
getFileContent(file: AnonymizedFile): Promise<stream.Readable>;
/**
* Get all the files from a specific source
*/
getFiles(): Promise<Tree>;
toJSON(): any;
}
export type Source = GitHubDownload | GitHubStream | Zip;
export interface StorageBase {
type: string;
exists(path: string): Promise<boolean>;
read(path: string): stream.Readable;
write(path: string, data: Buffer): Promise<void>;
listFiles(dir: string): Promise<Tree>;
extractTar(p: string, data: stream.Readable): Promise<void>;
rm(path: string): Promise<void>;
archive(
dir: string,
opt?: {
format?: "zip" | "tar";
fileTransformer?: (p: any) => Transformer;
}
): archiver.Archiver;
mk(path: string): Promise<void>;
}
export type Storage = S3Storage | FileSystem;
export interface Branch {
name: string;
commit: string;
readme?: string;
}
export type RepositoryStatus =
| "ready"
| "preparing"
| "expired"
| "removed"
| "download"
| "queue";
export type SourceStatus = "available" | "unavailable";
export interface Tree {
[key: string]: TreeElement;
}
export type TreeElement = Tree | TreeFile;
export interface TreeFile {
sha: string;
size: number;
}
export interface Loc {
info: { total: number; code: number; commit: number };
languages: {
[key: string]: {
total: number;
code: number;
commit: number;
sum: number;
};
};
}