/// import { PassThrough, Readable } from 'stream'; import { pluginUtils, searchUtils } from '@verdaccio/core'; import { ISyncUplinksOptions, ProxySearchParams } from '@verdaccio/proxy'; import { AbbreviatedManifest, Config, Logger, Manifest, MergeTags, Token, TokenFilter, Version } from '@verdaccio/types'; import { UpdateManifestOptions } from '.'; import { ProxyInstanceList } from './lib/uplink-util'; import { LocalStorage } from './local-storage'; import { IGetPackageOptionsNext, StarManifestBody } from './type'; export type Filters = pluginUtils.ManifestFilter[]; export declare const noSuchFile = "ENOENT"; export declare const resourceNotAvailable = "EAGAIN"; export declare const PROTO_NAME = "__proto__"; declare class Storage { localStorage: LocalStorage; filters: Filters | null; readonly config: Config; readonly logger: Logger; readonly uplinks: ProxyInstanceList; constructor(config: Config); static ABBREVIATED_HEADER: string; /** * Change an existing package (i.e. unpublish one version) Function changes a package info from local storage and all uplinks with write access./ Used storages: local (write) */ changePackage(name: string, metadata: Manifest, revision: string): Promise; removePackage(name: string, revision: any): Promise; /** Remove a tarball from a system Function removes a tarball from local storage. Tarball in question should not be linked to in any existing versions, i.e. package version should be unpublished first. Used storage: local (write) */ removeTarball(name: string, filename: string, _revision: string): Promise; /** * Handle search on packages and proxies. * Iterate all proxies configured and search in all endpoints in v2 and pipe all responses * to a stream, once the proxies request has finished search in local storage for all packages * (privated and cached). */ search(options: ProxySearchParams): Promise; private getTarballFromUpstream; /** * * @param name * @param filename * @param param2 * @returns */ getTarballNext(name: string, filename: string, { signal }: { signal: any; }): Promise; getPackageByVersion(options: IGetPackageOptionsNext): Promise; getPackageManifest(options: IGetPackageOptionsNext): Promise; private convertAbbreviatedManifest; /** * Return a manifest or version based on the options. * @param options {Object} * @returns A package manifest or specific version */ getPackageByOptions(options: IGetPackageOptionsNext): Promise; getLocalDatabase(): Promise; saveToken(token: Token): Promise; deleteToken(user: string, tokenKey: string): Promise; readTokens(filter: TokenFilter): Promise; /** * Initialize the storage asynchronously. * @param config Config * @param filters Filters * @returns Storage instance */ init(config: Config): Promise; /** * Consume the upstream and pipe it to a transformable stream. */ private consumeSearchStream; /** * Retrieve a wrapper that provide access to the package location. * @param {Object} pkgName package name. * @return {Object} */ private getPrivatePackageStorage; /** * Create a tarball stream from a package. * @param name * @param filename * @param options * @returns */ getLocalTarball(pkgName: string, filename: string, { signal }: { signal: AbortSignal; }): Promise; private searchCachedPackages; private removePackageByRevision; /** * Get a package local manifest. * * Fails if package is not found. * @param name package name * @param revision of package * @returns local manifest */ getPackageLocalMetadata(name: string, _revision?: string): Promise; /** * Fail the stream response with an not found error. * @returns */ private createFailureStreamResponseNext; /** * Update a package and merge tags * @param name package name * @param tags list of dist-tags */ mergeTagsNext(name: string, tags: MergeTags): Promise; private getUpLinkForDistFile; updateManifest(manifest: Manifest | StarManifestBody, options: UpdateManifestOptions): Promise; private deprecate; private star; /** * Get local package, on fails return null. * Errors are considered package not found. * @param name * @returns */ private getPackagelocalByNameNext; /** * Convert tarball as string into a Buffer and validate the length. * @param data the tarball data as string * @returns */ private getBufferManifest; /** * Verify if the package exists in the local storage * (the package refers to the package.json), directory would return false. * @param pkgName package name * @returns boolean */ private hasPackage; /** * Create a new package. * This situation happens only of the package does not exist on the cache. * * @param body package metadata * @param options * @returns */ private publishANewVersion; private notify; private getProxyList; /** * Wrap uploadTarballAsStream into a promise. * @param name package name * @param fileName tarball name * @param contentReadable content as readable stream * @param options * @returns */ uploadTarball(name: string, fileName: string, contentReadable: Readable, { signal }: { signal: any; }): Promise; private uploadTarballAsStream; /** * Add a new version to a package. * @param name package name * @param version version * @param metadata version metadata * @param tag tag of the version */ private addVersion; /** * Create an empty new local cache package without versions. * @param name name of the package * @returns */ private createNewLocalCachePackage; /** * * @param name package name * @param uplinksLook * @returns */ private checkPackageRemote; private setDefaultRevision; private writePackage; /** * @param {*} name package name * @param {*} updateHandler function(package, cb) - update function * @param {*} callback callback that gets invoked after it's all updated * @return {Function} */ private updatePackage; /** * * @protected * @param {IGetPackageOptionsNext} options * @return {*} {Promise<[Manifest, any[]]>} * @memberof AbstractStorage */ private getPackageNext; /** * Function fetches package metadata from uplinks and synchronizes it with local data if package is available locally, it MUST be provided in pkginfo. Using this example: "jquery": access: $all publish: $authenticated unpublish: $authenticated # two uplinks setup proxy: ver npmjs # one uplink setup proxy: npmjs A package requires uplinks syncronization if enables the proxy section, uplinks can be more than one, the more are the most slow request will take, the request are made in serial and if 1st call fails, the second will be triggered, otherwise the 1st will reply and others will be discarded. The order is important. Errors on upkinks are considered are, time outs, connection fails and http status 304, in that case the request returns empty body and we want ask next on the list if has fresh updates. */ syncUplinksMetadataNext(name: string, localManifest: Manifest | null, options?: Partial): Promise<[Manifest | null, any]>; /** * Merge a manifest with a remote manifest. * * If the uplinks are not available, the local manifest is returned. * If the uplinks are available, the local manifest is merged with the remote one. * * * @param uplink uplink instance * @param cachedManifest the local cached manifest * @param options options * @returns Returns a promise that resolves with the merged manifest. */ private mergeCacheRemoteMetadata; /** * Apply filters to manifest. * @param manifest * @returns */ applyFilters(manifest: Manifest): Promise<[Manifest, any]>; private _createNewPackageNext; /** * Ensure the dist file remains as the same protocol * @param {Object} hash metadata * @param {String} upLinkKey registry key * @private * @deprecated use _updateUplinkToRemoteProtocolNext (???) */ private updateUplinkToRemoteProtocol; /** * Create or read a package. * * If the package already exists, it will be read. * If the package is not found, it will be created. * If the error is anything else will throw an error * * @param {*} pkgName * @param {*} callback * @return {Function} */ private readCreatePackage; /** Updates the local cache with the merge from the remote/client manifest. The steps are the following. 1. Get the latest version of the package from the cache. 2. If does not exist will return a @param name @param remoteManifest @returns return a merged manifest. */ updateVersionsNext(name: string, remoteManifest: Manifest): Promise; } export { Storage };