/** * @license * Copyright Borda All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://borda.dev/license */ import { Observable } from 'rxjs'; import { Document } from '@borda/client'; export interface FastOptions { /** * memoized data identifier */ key?: string; app?: string; /** * define a custom path used to extract data before memoization */ path?: string; /** * define the response mode * @default 'straight' */ mode?: 'straight' | 'detailed'; /** * define a custom differ function */ differ?: (prev: any, next: any) => boolean; /** * define if data can be mutated. default to false. */ mutable?: boolean; } export declare function from(source: Promise): Observable; /** * The `fast` decorator is a wrapper used around any source of data * leveraging memory and disk cache to make it react "fast" to network changes * * @example * * given a source of data like this: * * const q = query('PublicUser') * .limit(10) * .filter({...}) * .sort({...}) * .find({...}) * * you can make it work faster by using the `fast` decorator and subscribing to changes * * import { fast, from } from '@borda/browser'; * * const q = query('PublicUser') * .limit(10) * .filter({...}) * .sort({...}) * .find({...}) * * fast(from(q)).subscribe(results) * * what's happening here? * * 1 - The query result is being cached in memory (redux state) and disk * with an automatic key based on the query parameters * 2 - The query always try to deliver what's faster first (memory or cache) * and then if network result differs from the cached one * it will update the stored data and make a second delivery in the same rxjs stream * * // using an existing promise * * const p = new Promise((resolve, reject) => { * setTimeout(() => { * resolve('hello world') * }, 1000) * }) * * fast(from(p)).subscribe(console.log) // this is wrong * * // since this isn't an elegant query and the snipet above has no key * // we need to set a key if we want the result to be cached * fast('my-key', p).subscribe(console.log) * * // using an existing observable * const o = new Observable((observer) => { * setTimeout(() => { * observer.next('hello world') * }, 1000) * }) * * fast(o).subscribe(console.log) // this is wrong * * // same for pre-made observables, since the snipet above has no key, we need to set one * fast('my-key', o).subscribe(console.log) * * @export */ export declare function fast(source: Observable): Observable; export declare function fast(key: string, source: Observable): Observable; export declare function fast(source: Observable, options: FastOptions): Observable; /** * Fast decorator for Typescript nerds 🤓 * * @example * * ## Angular pipe async example with promise *``` * import { Fast, from } from '@borda/browser'; * * @Component( * template: `{{ myUsersList$ | async | json }}` * ) * class User { * @Fast('latest-users') myUsersList$ = from(getUsersPromise()); * } *``` * Angular pipe async example. * Borda queries have no need of a key. * Unless you want to customize it with your own. * * ``` * class User { * @Fast() latestUsers$ = from( * query('PublicUser') * .pipeline([{ * $sort: { createdAt: -1 }, * }]) * .limit(10) * .aggregate({ allowDiskUse: true })); * } * ``` */ export declare function Fast(key?: string): (target: any, propertyKey: string) => void; export declare function Fast(options?: FastOptions): (target: any, propertyKey: string) => void; export declare function Fast(key?: string, options?: FastOptions): (target: any, propertyKey: string) => void;