From 9739f29d4991d91c08f9e102a86d9d6ea122636f Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Wed, 13 Nov 2024 08:56:48 -0500 Subject: [PATCH] feat: add typescript definitions --- types/index.d.ts | 331 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 types/index.d.ts diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..8e4f7cb --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,331 @@ +declare module 'hologit' { + import { Git as GitClient } from 'git-client'; + import { Docker } from 'dockerode'; + + export interface GitOptions { + gitDir: string; + workTree?: string | null; + } + + export interface RepoOptions { + gitDir: string; + ref?: string; + workTree?: string | null; + } + + export interface WorkspaceOptions { + root: TreeObject; + } + + export interface BranchOptions { + workspace: Workspace; + name: string; + } + + export interface SourceOptions { + workspace: Workspace; + name: string; + } + + export interface LensOptions { + workspace: Workspace; + name: string; + path?: string; + } + + export interface ConfigurableOptions { + phantom?: any; + workspace?: Workspace; + } + + export interface GitObjectOptions { + hash: string; + mode?: string | null; + } + + export interface MergeOptions { + files?: string[] | null; + mode?: 'overlay' | 'replace' | 'underlay'; + } + + export interface ProjectionOptions { + debug?: boolean; + lens?: boolean | null; + commitTo?: string | null; + commitMessage?: string | null; + parentCommit?: string | null; + fetch?: boolean | string[]; + cacheFrom?: string | null; + cacheTo?: string | null; + } + + export class Git { + static async get(): Promise; + constructor(options: GitOptions); + gitDir: string; + workTree?: string; + } + + export class BlobObject { + static async write(repo: Repo, content: string): Promise; + static async writeFromFile(repo: Repo, filePath: string): Promise; + + constructor(repo: Repo, options: GitObjectOptions); + + repo: Repo; + hash: string; + mode: string; + isBlob: boolean; + type: 'blob'; + + async read(): Promise; + } + + export class TreeObject { + static getEmptyTreeHash(): string; + static async createFromRef(repo: Repo, ref: string): Promise; + + constructor(repo: Repo, options?: { hash?: string; parent?: TreeObject | null }); + + repo: Repo; + dirty: boolean; + hash: string; + parent: TreeObject | null; + isTree: boolean; + type: 'tree'; + mode: '040000'; + + async getHash(): Promise; + getWrittenHash(): string | null; + markDirty(): void; + async getChild(childPath: string): Promise; + async writeChild(childPath: string, content: string | BlobObject): Promise; + async getChildren(): Promise<{ [key: string]: TreeObject | BlobObject | CommitObject }>; + async getBlobMap(): Promise<{ [key: string]: BlobObject }>; + async deleteChild(childPath: string): Promise; + async getSubtree(subtreePath: string, create?: boolean): Promise; + async getSubtreeStack(subtreePath: string, create?: boolean): Promise; + async write(): Promise; + async merge(input: TreeObject, options?: MergeOptions, basePath?: string, preloadChildren?: boolean): Promise; + async clone(): Promise; + } + + export class CommitObject { + constructor(repo: Repo, options: GitObjectOptions); + + repo: Repo; + hash: string; + mode: string; + isCommit: boolean; + type: 'commit'; + } + + export class Configurable { + constructor(options: ConfigurableOptions); + + phantom?: any; + workspace?: Workspace; + + getWorkspace(): Workspace; + getRepo(): Repo; + async readConfig(): Promise; + async writeConfig(config?: any): Promise; + async getConfig(): Promise; + async getCachedConfig(): Promise; + } + + export class Branch extends Configurable { + constructor(options: BranchOptions); + + name: string; + + getKind(): 'holobranch'; + getConfigPath(): string; + async isDefined(): Promise; + getMapping(key: string): Mapping; + async getMappings(): Promise>; + async composite(options: { + outputTree?: TreeObject; + fetch?: boolean | string[]; + cacheFrom?: string | null; + cacheTo?: string | null; + }): Promise; + getLens(name: string): Lens; + async getLenses(): Promise>; + } + + export class Source extends Configurable { + constructor(options: SourceOptions); + + name: string; + holosourceName: string; + holobranchName: string | null; + + getKind(): 'holosource'; + getConfigPath(): string; + async getSpec(): Promise<{ hash: string; ref: string; data: any }>; + async getCachedSpec(): Promise<{ hash: string; ref: string; data: any }>; + async queryRef(): Promise<{ hash: string; ref: string } | null>; + async hashWorkTree(): Promise; + async getOutputTree(options?: { + working?: boolean | null; + fetch?: boolean | string[]; + cacheFrom?: string | null; + cacheTo?: string | null; + }): Promise; + async getHead(options?: { required?: boolean; working?: boolean | null }): Promise; + async getCachedHead(): Promise; + async getBranch(): Promise; + async fetch(options?: { depth?: number; unshallow?: boolean | null }, ...refs: string[]): Promise<{ refs: string[] }>; + async checkout(options?: { submodule?: boolean }): Promise<{ + path: string; + head: string; + branch: string | null; + url: string; + ref: string; + submodule: boolean; + }>; + } + + export class Lens extends Configurable { + constructor(options: LensOptions); + + name: string; + path: string; + + getKind(): 'hololens'; + getConfigPath(): string; + async buildInputTree(inputRoot?: TreeObject): Promise; + async buildSpec(inputTree: TreeObject): Promise<{ + hash: string; + ref: string; + data: any; + }>; + async executeSpec(specHash: string, options: { + refresh?: boolean; + save?: boolean; + repo?: Repo | null; + cacheFrom?: string | null; + cacheTo?: string | null; + }): Promise; + + static async executeSpec(specHash: string, options: { + refresh?: boolean; + save?: boolean; + repo?: Repo | null; + cacheFrom?: string | null; + cacheTo?: string | null; + }): Promise; + } + + export class Workspace extends Configurable { + constructor(options: WorkspaceOptions); + + root: TreeObject; + + getWorkspace(): Workspace; + getKind(): 'holospace'; + getConfigPath(): string; + async writeWorkingChanges(): Promise; + getBranch(name: string): Branch; + async getBranches(): Promise>; + getSource(name: string): Source; + async getSources(): Promise>; + async getLayers(): Promise>>; + getLens(name: string): Lens; + async getLenses(): Promise>; + } + + export class Repo { + static async getFromEnvironment(options?: { ref?: string; working?: boolean }): Promise; + + constructor(options: RepoOptions); + + gitDir: string; + ref: string; + workTree: string | null; + + async getWorkspace(): Promise; + async createWorkspaceFromRef(ref: string): Promise; + async createWorkspaceFromTreeHash(hash: string): Promise; + async getGit(): Promise; + async resolveRef(ref?: string | null): Promise; + createBlob(options: GitObjectOptions): BlobObject; + async writeBlob(content: string): Promise; + async writeBlobFromFile(filePath: string): Promise; + createTree(options?: { hash?: string; parent?: TreeObject | null }): TreeObject; + async createTreeFromRef(ref: string): Promise; + createCommit(options: GitObjectOptions): CommitObject; + async hasCommit(commit: string): Promise; + async hashWorkTree(): Promise; + async watch(options: { callback: (treeHash: string, commitHash?: string) => void }): Promise<{ + watching: Promise; + cancel: () => void; + }>; + } + + export class Projection { + static async projectBranch(branch: Branch, options?: ProjectionOptions): Promise; + + constructor(options: { branch: Branch }); + + branch: Branch; + workspace: Workspace; + output: Workspace; + + async composite(options: { + fetch?: boolean | string[]; + cacheFrom?: string | null; + cacheTo?: string | null; + }): Promise; + async lens(options: { + cacheFrom?: string | null; + cacheTo?: string | null; + }): Promise; + async commit(ref: string, options?: { + parentCommit?: string | null; + commitMessage?: string | null; + }): Promise; + } + + export class Studio { + static async cleanup(): Promise; + static async getHab(): Promise; + static async getDocker(): Promise; + static async isEnvironmentStudio(): Promise; + static async get(gitDir: string): Promise; + + constructor(options: { gitDir: string; container: any }); + + container: any; + gitDir: string; + + isLocal(): boolean; + async habExec(...command: any[]): Promise; + async habPkgExec(pkg: string, bin: string, ...args: any[]): Promise; + async holoExec(...command: any[]): Promise; + async holoLensExec(spec: string): Promise; + async getPackage(query: string, options?: { install?: boolean }): Promise; + } + + export class Mapping extends Configurable { + constructor(options: { branch: Branch; key: string }); + + branch: Branch; + key: string; + + getWorkspace(): Workspace; + getKind(): 'holomapping'; + getConfigPath(): string; + } + + export class SpecObject extends BlobObject { + static async write(repo: Repo, kind: string, data: any): Promise<{ + hash: string; + ref: string; + }>; + static buildRef(kind: string, hash: string): string; + + isSpec: boolean; + } +}