@cboulanger/zotero-sync-bookends
Version:
Bookends store for @retorquere/zotero-sync
191 lines (190 loc) • 6.1 kB
TypeScript
import type { Zotero } from "@retorquere/zotero-sync/typings/zotero";
export declare class Store implements Zotero.Store {
libraries: string[];
fileName: string;
static verbose: boolean;
constructor(fileName: 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;
maxTries: number;
private readonly prefix;
private readonly store;
private groupName?;
private fastForwardTo;
private lastIndex;
private isNew;
private synchronizingMessage;
constructor(store: Store, user_or_group_prefix: string);
/**
* Output additional information to the console if the `verbose` property is true
* @param {string} msg
* @private
*/
private logVerbose;
/**
* Runs a JXA script in the context of the current Bookends library. The following
* constants are predefined when running the passed script fragement:
* ```
* args - the arguments array passed in the second parameter
* bookends - the JXA Bookends Application instance
* libraryWindow - the JXA LibraryWindow instance of the library with the name that had
* been passed to the constructor of the node Library class instance
* ```
* @param {string} cmd
* @param {array} args
* @protected
*/
protected run(cmd: string, args?: any[]): Promise<any>;
/**
* Initialize the library instance. This creates a Bookends group for all library items if it
* does not exist. The group name encodes library metadata in JSON format
*/
init(): Promise<Library>;
/**
* Adds a Bookends group
* @param groupName
*/
protected addGroup(groupName: string): Promise<void>;
/**
* Renames a Bookends group
* @param oldGroupName
* @param newGroupName
* @protected
*/
protected renameGroup(oldGroupName: string, newGroupName: string): Promise<void>;
/**
* Deletes a Bookends group
* @param groupName
* @protected
*/
protected removeGroup(groupName: string): Promise<void>;
/**
* Parse the metadata stored in a group name
* @protected
*/
protected parseGroupName(groupName: string): {
name: string;
data: {
version: number;
prefix: string;
lastIndex: number;
};
};
/**
* Store metadata in the group name
* @param {string?} name
* @protected
*/
protected generateGroupName(name?: string): string;
/**
* Finds a group name by the Zotero library prefix in the contained metadata
* If found, return the name of the group, otherwise return undefined
* @param prefix
* @protected
*/
protected findGroupNameByPrefix(prefix?: string): Promise<string | undefined>;
/**
* Removes the Bookends group containing the library items
*/
delete(): Promise<void>;
/**
* 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>;
/**
* Given item data, generate a unique value for the `citekey` field that can deterministically
* identify the item within the Bookends library. If Zotero had a globally unique id, this would
* be the ideal candidate, but for now we take an URL'ish approach to generating this id.
* @param item
* @protected
*/
protected generateCitekey(item: Zotero.Item.Any | {
key: string;
}): string;
/**
* Translates a zotero item to data that can be imported into bookends
* @param item
* @param citekey
* @protected
*/
protected zoteroToBookends(item: Zotero.Item.Any | any, citekey: string): {
[key: string]: string;
};
/**
* Returns the data of the publication item with the given citeky, or undefined if none such item exists
* @param citekey
* @protected
*/
protected getPublicationByCitekey(citekey: string): Promise<{
[key: string]: string;
} | undefined>;
/**
* Adds a publication item and links it to the current group
* @param {object} data
* @param {string?} groupName Optional name of the group, by default the group that contains the library items
* @protected
*/
protected addPublication(data: {
[key: string]: string;
}, groupName?: string): Promise<void>;
/**
* Updates a publication item
* @param {number} id
* @param {object} data
* @protected
*/
protected updatePublication(id: number, data: {
[key: string]: string;
}): Promise<void>;
/**
* Deletes a publication item
* @param id
* @protected
*/
protected removePublication(id: number): Promise<void>;
/**
* Adds or updates a Zotero item object
* @param {Zotero.Item.Any} item
*/
add(item: Zotero.Item.Any | any): Promise<void>;
/**
* Removes Zotero item objects
* @param {string[]} keys
*/
remove(keys: string[]): Promise<void>;
/**
* Saves the library metadata in the group name
* @protected
*/
protected saveMetadata(): Promise<void>;
/**
* Saves the Library metadata at the end of the sync process
* @param {String} name Descriptive Name of the library
* @param {Number} version
*/
save(name: string, version: number): Promise<void>;
}