UNPKG

@cboulanger/zotero-sync-couchbase

Version:

Couchbase store for @retorquere/zotero-sync

117 lines (116 loc) 3.81 kB
import type { Zotero } from "@retorquere/zotero-sync/typings/zotero"; /** * Options that can be passed as the last arguments to the Store constructor */ export interface StoreOptions { /** * The name of the bucket that contains the zotero data. Defaults to "zotero" */ bucketName?: string; /** * An optional function that translates a user-or-group prefix to a valid * couchbase scope name. Defaults to {@link Store#createScopeNameFromPrefixImpl} * @param user_or_group_prefix */ createScopeNameFromPrefixFunc?: (user_or_group_prefix: string) => string; /** * Timeout in microseconds that is waited for the couchbase server to create * the needed objects asynchronously ; defaults to 5000 ms */ timeout?: number; } export declare class Store implements Zotero.Store { libraries: string[]; readonly timeout: number; private readonly url; private readonly username; private readonly password; private readonly options; private readonly bucketName; private cluster?; constructor(url: string, username: string, password: string, options?: StoreOptions); /** * Returns the couchbase Cluster instance * @return Promise<Cluster> */ getCluster(): Promise<Cluster>; /** * Returns the couchbase bucket in which the zotero data is stored * @returns {Promise<Bucket>} */ getBucket(): Promise<Bucket>; /** * Given a zotero REST API user-or-group prefix (e.g. users/12345 or groups/12345), return * a library id that can be stored as a scope name in couchbase. * @param {String} user_or_group_prefix * @protected */ createScopeNameFromPrefix(user_or_group_prefix: string): string; /** * The default implementation shortens the prefix to "u12345" or "g12345", * respectively. * @param {String} user_or_group_prefix * @protected */ protected createScopeNameFromPrefixImpl(user_or_group_prefix: string): string; /** * Removes a library from the store * @implements Zotero.Store.remove * @param user_or_group_prefix */ remove(user_or_group_prefix: string): Promise<void>; /** * Gets a library, creating it if it doesn't exist. * @implements Zotero.Store.get * @param user_or_group_prefix * @return {Promise<Library>} */ get(user_or_group_prefix: string): Promise<Library>; } /** * Implementation of a Zotero library object */ export declare class Library implements Zotero.Library { name: string; version: number; protected synchronizedObjectTypes: string[]; private readonly user_or_group_prefix; private readonly store; private cbCollections; constructor(store: Store, user_or_group_prefix: string); /** * Returns "user" or "group" */ getType(): string; /** * Initialize the library instance. This creates the necessary couchbase * collections. Resolves with the library instance when done. */ init(): Promise<Library>; /** * Adds a Zotero collection object * @param {Zotero.Collection} collection */ add_collection(collection: Zotero.Collection): Promise<void>; /** * Removes a Zotero collection object * @param {string[]} keys */ remove_collections(keys: string[]): Promise<void>; /** * Adds a Zotero item object * @param {Zotero.Item.Any} item */ add(item: Zotero.Item.Any): Promise<void>; /** * Removes an Zotero item object * @param {string[]} keys */ remove(keys: string[]): Promise<void>; /** * Saves the Library * @param {String?} name Descriptive Name of the library * @param {Number} version */ save(name: string, version: number): Promise<void>; }