UNPKG

insite-subscriptions-client

Version:

inSite subscriptions client side

94 lines 3.52 kB
import { Subscription } from "./Subscription"; import { clearSymbol, getAsInitialUpdatedSymbol, getAsUpdatesSymbol, getHandleUpdateSymbol, getSubscriptionSymbol, renewSymbol, setHandleUpdateSymbol, subscribeSymbol, unsubscribeSymbol, updateSymbol } from "./symbols"; type GenericItem = Record<string, any> & { _id: string; }; type Item = GenericItem | SubscriptionMapItem; export type Updated<I extends Item = Item> = I[] & { deleted: string[]; added: I[]; }; type SortList = Record<string, -1 | 1>; export type Updates<I extends Item = Item> = ([ "c", item: I ] | [ "d", _id: string ] | [ "i", items: I[], sortList?: SortList | null ] | [ "u", itemUpdates: Partial<I> & { _id: string; }, isAtomicOrUpdatedFields: string[] | true ] | null)[] | null; export type UpdateHandler<I extends Item = Item> = (map: SubscriptionMap<I>, updated: Updated<I>, updates: Updates<I>) => void; declare global { var __insite_subscription_map_sort_function: ((a: Item, b: Item) => -1 | 0 | 1) | undefined; } export declare class SubscriptionMap<I extends Item = Item> extends Map<string, I> { #private; constructor(updates?: Updates<I>, onUpdate?: UpdateHandler<I>); handleUpdate: UpdateHandler<I> | undefined; sortList: SortList | null; sortCompareFunction: ((a: I, b: I) => number) | null; sorted: I[]; sort(): void; [getHandleUpdateSymbol](): UpdateHandler<I> | undefined; [setHandleUpdateSymbol](handleUpdate: UpdateHandler<I>): UpdateHandler<I>; set Item(TheItem: { new (map: SubscriptionMap<I>, updates: GenericItem): I; }); get Item(): { new (map: SubscriptionMap<I>, updates: GenericItem): I; }; update(updates: Updates<I>): this; [updateSymbol]: (updates: Updates<I>) => this; getAsUpdates(): Updates<I>; [getAsUpdatesSymbol]: () => Updates<I>; getAsInitialUpdated(): Updated<I>; [getAsInitialUpdatedSymbol]: () => Updated<I>; clear(): void; [clearSymbol]: () => void; valueOf(): I[]; get [Symbol.toStringTag](): string; static updateSymbol: symbol; static getHandleUpdateSymbol: symbol; static setHandleUpdateSymbol: symbol; static getAsUpdatesSymbol: symbol; static getAsInitialUpdatedSymbol: symbol; static clearSymbol: symbol; static WithSubscription: typeof SubscriptionMapWithSubscription; static Item: typeof SubscriptionMapItem; } export declare class SubscriptionMapWithSubscription<I extends Item = Item> extends SubscriptionMap<I> { constructor(publicationName: string, params: unknown[], onUpdate: UpdateHandler<I>, immediately?: boolean); publicationName: string; params: unknown[]; subscription: Subscription | null; subscribe(): void; get [subscribeSymbol](): () => void; unsubscribe(): void; get [unsubscribeSymbol](): () => void; renew(publicationName?: string, params?: unknown[]): void; get [renewSymbol](): (publicationName?: string, params?: unknown[]) => void; [getSubscriptionSymbol](): Subscription | null; get [Symbol.toStringTag](): string; static subscribeSymbol: symbol; static unsubscribeSymbol: symbol; static renewSymbol: symbol; static getSubscriptionSymbol: symbol; } export declare class SubscriptionMapItem { #private; constructor(map: SubscriptionMap, updates: GenericItem); _id: string; update(updates: GenericItem): void; delete(): void; } export {}; //# sourceMappingURL=SubscriptionMap.d.ts.map