UNPKG

4.59 kBTypeScriptView Raw
1/// <reference types="node" />
2import { PassThrough } from 'stream';
3import { Callback, CallbackAction, StringValue } from '../commons';
4import { Config, Logger } from '../configuration';
5import { MergeTags, Package, Token, Version } from '../manifest';
6import { IPlugin } from './commons';
7export declare class IUploadTarball extends PassThrough {
8 abort(): void;
9 done(): void;
10}
11export declare class IReadTarball extends PassThrough {
12 abort(): void;
13}
14export declare type StorageList = string[];
15export interface LocalStorage {
16 list: any;
17 secret: string;
18}
19export interface ILocalStorage {
20 add(name: string): void;
21 remove(name: string): void;
22 get(): StorageList;
23 sync(): void;
24}
25interface TarballActions {
26 addTarball(name: string, filename: string): IUploadTarball;
27 getTarball(name: string, filename: string): IReadTarball;
28 removeTarball(name: string, filename: string, revision: string, callback: Callback): void;
29}
30interface StoragePackageActions extends TarballActions {
31 addVersion(name: string, version: string, metadata: Version, tag: StringValue, callback: Callback): void;
32 mergeTags(name: string, tags: MergeTags, callback: Callback): void;
33 removePackage(name: string, callback: Callback): void;
34 changePackage(name: string, metadata: Package, revision: string, callback: Callback): void;
35}
36export interface IStorageManager<T> extends StoragePackageActions {
37 config: T & Config;
38 logger: Logger;
39 init(config: T & Config, filters: any): Promise<any>;
40 addPackage(name: string, metadata: any, callback: Callback): Promise<any>;
41 getPackage(options: any): void;
42 search(startkey: string, options: any): IReadTarball;
43 getLocalDatabase(callback: Callback): void;
44}
45export interface IBasicStorage<T> extends StoragePackageActions {
46 addPackage(name: string, info: Package, callback: Callback): void;
47 updateVersions(name: string, packageInfo: Package, callback: Callback): void;
48 getPackageMetadata(name: string, callback: Callback): void;
49 search(startKey: string, options: any): IReadTarball;
50 getSecret(config: T & Config): Promise<any>;
51}
52export interface TokenFilter {
53 user: string;
54}
55export interface ITokenActions {
56 saveToken(token: Token): Promise<any>;
57 deleteToken(user: string, tokenKey: string): Promise<any>;
58 readTokens(filter: TokenFilter): Promise<Token[]>;
59}
60/**
61 * This method expect return a Package object
62 * eg:
63 * {
64 * name: string;
65 * time: number;
66 * ... and other props
67 * }
68 *
69 * The `cb` callback object will be executed if:
70 * - it might return object (truly)
71 * - it might reutrn null
72 */
73export declare type onSearchPackage = (item: Package, cb: CallbackAction) => void;
74export declare type onEndSearchPackage = (error?: any) => void;
75export declare type onValidatePackage = (name: string) => boolean;
76export declare type StorageUpdateCallback = (data: Package, cb: CallbackAction) => void;
77export declare type StorageWriteCallback = (name: string, json: Package, callback: Callback) => void;
78export declare type PackageTransformer = (pkg: Package) => Package;
79export declare type ReadPackageCallback = (err: any | null, data?: Package) => void;
80export interface ILocalPackageManager {
81 logger: Logger;
82 writeTarball(pkgName: string): IUploadTarball;
83 readTarball(pkgName: string): IReadTarball;
84 readPackage(fileName: string, callback: ReadPackageCallback): void;
85 createPackage(pkgName: string, value: Package, cb: CallbackAction): void;
86 deletePackage(fileName: string, callback: CallbackAction): void;
87 removePackage(callback: CallbackAction): void;
88 updatePackage(pkgFileName: string, updateHandler: StorageUpdateCallback, onWrite: StorageWriteCallback, transformPackage: PackageTransformer, onEnd: CallbackAction): void;
89 savePackage(fileName: string, json: Package, callback: CallbackAction): void;
90}
91export declare type IPackageStorage = ILocalPackageManager | void;
92export declare type IPluginStorage<T> = ILocalData<T>;
93export declare type IPackageStorageManager = ILocalPackageManager;
94export interface ILocalData<T> extends IPlugin<T>, ITokenActions {
95 logger: Logger;
96 config: T & Config;
97 add(name: string, callback: Callback): void;
98 remove(name: string, callback: Callback): void;
99 get(callback: Callback): void;
100 getSecret(): Promise<string>;
101 setSecret(secret: string): Promise<any>;
102 getPackageStorage(packageInfo: string): IPackageStorage;
103 search(onPackage: onSearchPackage, onEnd: onEndSearchPackage, validateName: onValidatePackage): void;
104}
105export {};