@shockpkg/core
Version:
shockpkg core
195 lines (194 loc) • 4.92 kB
TypeScript
import { Package } from './package';
import { IPackagesList, IPackagesListPackage, IPackageUpdated } from './types';
/**
* Packages constructor.
*
* @param path The path to the packages file.
*/
export declare class Packages extends Object {
/**
* Packages data.
*/
protected _packagesList: IPackagesList | null;
/**
* Packages array.
*/
protected _packages: Set<Package>;
/**
* Packages mapped by name.
*/
protected _packagesByName: Map<string, Package>;
/**
* Packages mapped by sha256.
*/
protected _packagesBySha256: Map<string, Package>;
/**
* Packages mapped by unique.
*/
protected _packagesByUnique: Map<string, Package>;
/**
* The path to the packages file.
*/
protected readonly _path: string;
/**
* Format version.
*/
static readonly FORMAT: string;
constructor(path: string);
/**
* Get path of the packages file.
*
* @returns The path.
*/
readonly path: string;
/**
* Get if packages loaded.
*
* @returns Is loaded.
*/
readonly loaded: boolean;
/**
* Update packages.
*
* @param data Encoded data.
* @returns Update report.
*/
update(data: string): {
updated: IPackageUpdated[];
added: IPackageUpdated[];
removed: IPackageUpdated[];
};
/**
* Assert loaded.
*/
assertLoaded(): void;
/**
* Check if the file path exists.
*
* @returns Does exist.
*/
exists(): Promise<boolean>;
/**
* Read the file path.
*/
read(): Promise<void>;
/**
* Write packages to the file path.
*/
write(): Promise<void>;
/**
* Read the file path if the file exists.
*
* @returns Did exist.
*/
readIfExists(): Promise<boolean>;
/**
* Itterate over the packages.
*/
itter(): IterableIterator<Package>;
/**
* Check if package is in this collection.
*
* @param pkg Package instance.
* @returns If the package instance is present.
*/
has(pkg: Package): boolean;
/**
* Assert the package is in this collection.
*
* @param pkg Package instance.
*/
assertHas(pkg: Package): void;
/**
* Get package by the unique name.
*
* @param name Package name.
* @returns The package or null.
*/
byName(name: string): Package | null;
/**
* Get package by the sha256 hash.
*
* @param sha256 Package sha256.
* @returns The package or null.
*/
bySha256(sha256: string): Package | null;
/**
* Get package by the unique value.
*
* @param unique Package unique.
* @returns The package or null.
*/
byUnique(unique: string): Package | null;
/**
* Create a package instance.
*
* @param info Package info.
* @returns Package instance.
*/
protected _createPackage(info: IPackagesListPackage): Package;
/**
* Set the packages list.
*
* @param packagesList Parsed list.
*/
protected _setPackagesList(packagesList: IPackagesList): void;
/**
* Validate format version string.
*
* @param format The format version string.
*/
protected _validateFormat(format: string): void;
/**
* Parse the packages list.
*
* @param packages Packages list.
* @returns Parsed list.
*/
protected _parsePackages(packages: IPackagesListPackage[]): Package[];
/**
* List all packages deep.
*
* @param packages A list of packages.
* @returns A set of all packages and their children.
*/
protected _listPackages(packages: Package[]): Set<Package>;
/**
* Map out package list by name.
* Throws on any duplicates.
*
* @param packages Packages list.
* @returns Map from package name to package.
*/
protected _packagesMapName(packages: Set<Package>): Map<string, Package>;
/**
* Map out package list by sha256.
* Throws on any duplicates.
*
* @param packages Packages list.
* @returns Map from package sha256 to package.
*/
protected _packagesMapSha256(packages: Set<Package>): Map<string, Package>;
/**
* Map out package list by unique.
* Throws on any duplicates.
*
* @param packages Packages list.
* @returns Map from package unique to package.
*/
protected _packagesMapUnique(packages: Set<Package>): Map<string, Package>;
/**
* Parse and cast the encoded data.
*
* @param data Encoded data.
* @returns Parsed and cast data.
*/
protected _parseData(data: string): IPackagesList;
/**
* Cast the parsed data.
*
* @param packages Parsed data.
* @returns Cast data.
*/
protected _castData(packages: any): IPackagesList;
}