simpleddp-node
Version:
The aim of this library is to simplify the process of working with meteor server over DDP protocol using external JS environments
62 lines (61 loc) • 2.04 kB
TypeScript
import { ddpOnChange } from './ddpOnChange.js';
import { ddpReactiveCollection } from './ddpReactiveCollection';
import DDPClient from '../DDPClient';
type Filter<T> = boolean | ((value: T, index: number, array: T[]) => any);
/**
* DDP collection class.
*/
export declare class ddpCollection<T> {
private _filter;
private _name;
private _server;
private ddpConnection;
constructor(name: string, server: DDPClient);
/**
* Allows to specify specific documents inside the collection for reactive data and fetching.
* Important: if you change filter function it won't change for the already created reactive objects.
*/
filter<S extends any>(f?: boolean | ((value: T, index: number, array: T[]) => S)): this;
/**
* Imports data inside the collection and emits all relevant events.
* Both string and JS object types are supported.
*/
importData(data: string | object): void;
/**
* Exports data from the collection.
*/
exportData(format: 'string' | 'raw' | undefined): string | object;
/**
* Returns collection data based on filter and on passed settings. Supports skip, limit and sort.
* Order is 'filter' then 'sort' then 'skip' then 'limit'.
* sort is a standard js array sort function.
*/
fetch(settings?: {
skip?: number;
limit?: number;
sort?: ((a: T, b: T) => number) | boolean;
}): T[];
/**
* Returns reactive collection object.
* @see ddpReactiveCollection
*/
reactive(settings?: {
skip?: number | undefined;
limit?: number | undefined;
sort?: false | ((a: T, b: T) => number) | undefined;
} | undefined): ddpReactiveCollection<T>;
/**
* Returns change observer.
* @see ddpOnChange
*/
onChange(f: <P extends {
_id: string;
} & T, N extends {
_id: string;
} & T, PP extends any[]>(args: {
prev?: P;
next?: N;
predicatePassed: PP;
}) => any, filter?: Filter<T>): ReturnType<typeof ddpOnChange>;
}
export {};