import type { Graffiti, GraffitiSession, JSONSchema, GraffitiObjectBase, GraffitiObjectStream, GraffitiObjectStreamEntry, GraffitiObjectUrl, GraffitiObjectStreamTombstone } from "@graffiti-garden/api"; export type * from "@graffiti-garden/api"; /** * A result from a Graffiti object stream without errors. */ export type GraffitiObjectStreamSuccess = GraffitiObjectStreamEntry | GraffitiObjectStreamTombstone; export type GraffitiSynchronizeCallback = (object: GraffitiObjectStreamSuccess<{}>) => void; export interface GraffitiSynchronizeOptions { /** * Allows synchronize to listen to all objects, not just those * that the session is allowed to see. This is useful to get a * global view of all Graffiti objects passsing through the system, * for example to build a client-side cache. Additional mechanisms * should be in place to ensure that users do not see objects or * properties they are not allowed to see. * * Default: `false` */ omniscient?: boolean; } /** * Wraps the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html) * so that changes made or received in one part of an application * are automatically routed to other parts of the application. * This is an important tool for building responsive * and consistent user interfaces, and is built upon to make * the [Graffiti Vue Plugin](https://vue.graffiti.garden/variables/GraffitiPlugin.html) * and possibly other front-end libraries in the future. * * [See a live example](/example). * * Specifically, this library provides the following *synchronize* * methods to correspond with each of the following Graffiti API methods: * * | API Method | Synchronize Method | * |------------|--------------------| * | {@link get} | {@link synchronizeGet} | * | {@link discover} | {@link synchronizeDiscover} | * * Whenever a change is made via {@link post} and {@link delete} or * received from {@link get}, {@link discover}, and {@link continueDiscover}, * those changes are forwarded to the appropriate synchronize method. * Each synchronize method returns an iterator that streams these changes * continually until the user calls `return` on the iterator or `break`s out of the loop, * allowing for live updates without additional polling. * * Example 1: Suppose a user publishes a post using {@link post}. If the feed * displaying that user's posts is using {@link synchronizeDiscover} to listen for changes, * then the user's new post will instantly appear in their feed, giving the UI a * responsive feel. * * Example 2: Suppose one of a user's friends changes their name. As soon as the * user's application receives one notice of that change (using {@link get} * or {@link discover}), then {@link synchronizeDiscover} listeners can be used to update * all instance's of that friend's name in the user's application instantly, * providing a consistent user experience. * * Additionally, the library supplies a {@link synchronizeAll} method that can be used * to stream all the Graffiti changes that an application is aware of, which can be used * for caching or history building. * * The source code for this library is [available on GitHub](https://github.com/graffiti-garden/wrapper-synchronize/). * * @groupDescription 0 - Synchronize Methods * This group contains methods that listen for changes made via * {@link post}, and {@link delete} or fetched from * {@link get}, {@link discover}, or {@link continueDiscover} and then * streams appropriate changes to provide a responsive and consistent user experience. */ export declare class GraffitiSynchronize implements Graffiti { protected readonly graffiti: Graffiti; protected readonly callbacks: Set; protected readonly options: GraffitiSynchronizeOptions; login: Graffiti["login"]; logout: Graffiti["logout"]; sessionEvents: Graffiti["sessionEvents"]; postMedia: Graffiti["postMedia"]; getMedia: Graffiti["getMedia"]; deleteMedia: Graffiti["deleteMedia"]; actorToHandle: Graffiti["actorToHandle"]; handleToActor: Graffiti["handleToActor"]; /** * Wraps a Graffiti API instance to provide the synchronize methods. * The GraffitiSyncrhonize class rather than the Graffiti class * must be used for all functions for the synchronize methods to work. */ constructor( /** * The [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html) * instance to wrap. */ graffiti: Graffiti, options?: GraffitiSynchronizeOptions); protected synchronize(matchObject: (object: GraffitiObjectBase) => boolean, channels: string[], schema: Schema, session?: GraffitiSession | null, seenUrls?: Set): AsyncGenerator>; /** * This method has the same signature as {@link discover} but listens for * changes made via {@link post} and {@link delete} or * fetched from {@link get}, {@link discover}, and {@link continueDiscover} * and then streams appropriate changes to provide a responsive and * consistent user experience. * * Unlike {@link discover}, this method continuously listens for changes * and will not terminate unless the user calls the `return` method on the iterator * or `break`s out of the loop. * * @group 0 - Synchronize Methods */ synchronizeDiscover(channels: string[], schema: Schema, session?: GraffitiSession | null): AsyncGenerator>; /** * This method has the same signature as {@link get} but * listens for changes made via {@link post}, and {@link delete} or * fetched from {@link get}, {@link discover}, and {@link continueDiscover} and then * streams appropriate changes to provide a responsive and consistent user experience. * * Unlike {@link get}, which returns a single result, this method continuously * listens for changes which are output as an asynchronous stream, similar * to {@link discover}. * * @group 0 - Synchronize Methods */ synchronizeGet(objectUrl: string | GraffitiObjectUrl, schema: Schema, session?: GraffitiSession | null | undefined): AsyncGenerator>; /** * Streams changes made to *any* object in *any* channel * and made by *any* user. You may want to use it in conjuction with * {@link GraffitiSynchronizeOptions.omniscient} to get a global view * of all Graffiti objects passing through the system. This is useful * for building a client-side cache, for example. * * Be careful using this method. Without additional filters it can * expose the user to content out of context. * * @group 0 - Synchronize Methods */ synchronizeAll(schema: Schema, session?: GraffitiSession | null): AsyncGenerator>; protected synchronizeDispatch(objectUpdate: GraffitiObjectStreamSuccess<{}>, waitForListeners?: boolean): Promise; get: Graffiti["get"]; post: Graffiti["post"]; delete: Graffiti["delete"]; protected objectStream(iterator: GraffitiObjectStream): GraffitiObjectStream; discover: Graffiti["discover"]; continueDiscover: Graffiti["continueDiscover"]; } //# sourceMappingURL=index.d.ts.map