UNPKG

sush

Version:

Core module for SUSH

59 lines (58 loc) 1.29 kB
import Stock, { StockConfig } from './Stock'; /** * `SUSHInfo` is params passed to `SUSHTask`. */ export interface SUSHInfo { /** `id` is the ID of shorten URL. */ id: string; /** `stock` is key/value map. */ stock: Stock; } /** * `SUSHTask` is task for SUSH. * @example * ```js * * function plugin({ id, stock }) { * const newId = `new_${id}`; * stock.set('anyKey', 'https://example.com'); * return { id: newId, stock }; * } * ``` * @example * ```js * * async function asyncPlugin({ id, stock }) { * stock.set('anyKey', await generateUrl()); * return { id, stock }; * } * ``` */ export declare type SUSHTask = (info: SUSHInfo) => SUSHInfo | PromiseLike<SUSHInfo> | Promise<SUSHInfo>; /** * `SUSH` is main class for SUSH. * @example * ```js * * const sush = new SUSH(); * sush.flow([ * somePlugin, * ]) * .catch((err) => { * console.error(err); * }); * ``` */ export default class SUSH { /** `stock` is key/value map. */ stock: Stock; private _location; /** * @param config See `StockConfig`. */ constructor(config?: StockConfig); /** * @param tasks Array of `SUSHTask`. */ flow(tasks: SUSHTask[]): Promise<SUSHInfo>; }