UNPKG

@ztimson/momentum

Version:

Client library for momentum

47 lines 1.68 kB
import { PathEvent } from '@ztimson/utils'; import { PathEventEmitter, Unsubscribe } from './core'; import { Momentum } from './momentum'; /** Managed product */ export type Product<T = any> = T & { /** Product ID number */ readonly _id: number; /** Name of product */ readonly name: string; /** Cost of product in dollars */ readonly cost: number; /** If a subscription, number of days */ readonly subscription?: number; /** Has available stock */ readonly stocked: boolean; }; /** Get product information */ export declare class Products extends PathEventEmitter { protected momentum: Momentum; private controller; get cache(): import('@ztimson/utils').Cache<string, any>; constructor(momentum: Momentum); /** * Fetch all products * @param {boolean} reload Force reload instead of using cache * @return {Promise<Product[]>} List of products */ all(reload?: boolean): Promise<Product[]>; /** * Fetch specific product information * @param {number} id Product ID * @param {boolean} reload Force reload instead of using cache * @return {Promise<Product>} Found product */ read(id: number | string, reload?: boolean): Promise<Product>; /** * Subscribe to live updates with callback * @param {(value: Product[]) => any | null} callback Received changes * @param opts Scope to single product * @return {() => void} Function to unsubscribe */ sync(callback: (event: PathEvent, value: Product[]) => any | null, opts?: { product?: number; reload?: boolean; }): Unsubscribe; } //# sourceMappingURL=products.d.ts.map