declare module 'nimbus-types' { interface NimbusPlugins { LdsBinaryStorePlugin: BinaryStorePlugin; } } /** * A nimbus plugin for interacting with a binary file store. * * The implementation can be used as a "store" where the file in the store is the only * copy and there is essentially no expiration (the file is never stale). Or it can be * used as a "cache" where the canonical copy of the file exists somewhere else (like * on a remote server). * * The caching behavior should follow the "stale-while-revalidate" pattern, where * a cached file (which has a non-null expiration and a canonical URI) should always * return the cached version, and if the file is past expiration (ie: "stale") then * the implementation should attempt to re-downloaded the file from the canonical * URI in the background. * */ export interface BinaryStorePlugin { /** * Caches a binary file in the store. This is meant to locally cache a file * thats source-of-truth exists at the given URL. * * If the file is unable to be downloaded the onError callback will be called. * * This method should return a URI to the file, which may or may not be the * same as the remote URL. In other words, the URI returned to callers should * be treated as opaque by the callers. * * @param url The URL of the file. * @param ttlSeconds The TTL in seconds for this file. The file's expiration * should be calculated by Date.now + ttlSeconds. * @param onSuccess Callback to call with the string representing the URI of * the binary file. * @param onError Callback to call if there was an error. */ cacheBinary(url: string, ttlSeconds: number, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void; /** * Removes the binary file given its URI. * * @param uri The URI of the binary file * @param onSuccess Callback to be called once finished. The wasFound * parameter will be true if the file existed and has been removed, or * false if the file does not exist. * @param onError Callback to call if there was an unexpected error. */ removeBinary(uri: string, onSuccess: (wasFound: boolean) => void, onError: (errorMessage: string) => void): void; /** * Set the canonical URL for the file at the given uri. The file will immediately * be marked as stale (since we know the file's source of truth has changed). * * If there is no file at the given URI then this method will immediately cache * the file at the canonicalUrl (essentially the same as calling {@link cacheBinary}). * * This method should return a URI to the file, which may or may not be * different from the original URI, and may or may not be the same as the * canonicalUrl. * * @param uri The URI of the existing, local binary file * @param canonicalUrl The new, canonical URL (a URL is a type of URI) of the file * @param ttlSeconds The TTL in seconds for this file. The file's expiration * should be calculated by Date.now + ttlSeconds. * @param onSuccess Callback to call with the string representing the new URI * to the file, which may or may not be the same as canonicalUrl. * @param onError Callback to call if there was an error. */ setCanonicalUrl(uri: string, canonicalUrl: string, ttlSeconds: number, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void; /** * Creates a stream that can be used to write buffered chunks of base64-encoded data. * This function should be used in conjunction with writeToStream() and closeStream(). * * @param type The MIME type of the binary file. Ex: "image/png". * @returns A Promise of a string representing the URI of the binary file. NOTE: the URI * to a binary file should be treated as opaque (only use it to pass into methods * on this interface). */ createStream(type: string, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void; /** * Writes a base64-encoded chunk of data to the stream identified by the stream uri provided * by the call from createStream(). * * @param uri The URI of the file. * @returns A Promise of a string representing the URI of the binary file that was succesfully * written to. */ writeToStream(uri: string, chunk: string, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void; /** * Closes the stream represented by the given uri. Once a stream is closed, it cannot be * written to and will cause an error to be returned. * * @param uri The URI of the file. * @returns A Promise of a string representing the URI of the binary file that was succesfully * closed. */ closeStream(uri: string, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void; }