zotero-bridge 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,280 @@
1
+ /**
2
+ * ZoteroBridge - Zotero SQLite Database Connection Module
3
+ *
4
+ * This module provides direct access to Zotero's SQLite database (zotero.sqlite)
5
+ * for reading and writing reference data.
6
+ *
7
+ * Uses sql.js for pure JavaScript SQLite support (no native compilation required)
8
+ *
9
+ * @author Combjellyshen
10
+ */
11
+ import { Database as SqlJsDatabase } from 'sql.js';
12
+ export interface ZoteroItem {
13
+ itemID: number;
14
+ key: string;
15
+ itemTypeID: number;
16
+ dateAdded: string;
17
+ dateModified: string;
18
+ libraryID: number;
19
+ }
20
+ export interface ZoteroCollection {
21
+ collectionID: number;
22
+ collectionName: string;
23
+ parentCollectionID: number | null;
24
+ key: string;
25
+ libraryID: number;
26
+ }
27
+ export interface ZoteroTag {
28
+ tagID: number;
29
+ name: string;
30
+ type: number;
31
+ }
32
+ export interface ZoteroAttachment {
33
+ itemID: number;
34
+ path: string | null;
35
+ contentType: string | null;
36
+ }
37
+ export declare class ZoteroDatabase {
38
+ private db;
39
+ private dbPath;
40
+ private readonly;
41
+ private SQL;
42
+ constructor(dbPath?: string, readonly?: boolean);
43
+ /**
44
+ * Find the default Zotero database path based on OS
45
+ */
46
+ private findDefaultZoteroDB;
47
+ /**
48
+ * Connect to the Zotero database
49
+ */
50
+ connect(): Promise<void>;
51
+ /**
52
+ * Save changes to the database file
53
+ */
54
+ save(): void;
55
+ /**
56
+ * Disconnect from the database
57
+ */
58
+ disconnect(): void;
59
+ /**
60
+ * Get the database instance
61
+ */
62
+ getDB(): Promise<SqlJsDatabase>;
63
+ /**
64
+ * Get database path
65
+ */
66
+ getPath(): string;
67
+ /**
68
+ * Execute a query and return all results
69
+ */
70
+ private queryAll;
71
+ /**
72
+ * Execute a query and return the first result
73
+ */
74
+ private queryOne;
75
+ /**
76
+ * Execute a statement (INSERT, UPDATE, DELETE)
77
+ */
78
+ private execute;
79
+ /**
80
+ * Get all collections
81
+ */
82
+ getCollections(libraryID?: number): ZoteroCollection[];
83
+ /**
84
+ * Get collection by ID
85
+ */
86
+ getCollectionById(collectionID: number): ZoteroCollection | null;
87
+ /**
88
+ * Get collection by name
89
+ */
90
+ getCollectionByName(name: string, libraryID?: number): ZoteroCollection | null;
91
+ /**
92
+ * Get subcollections of a collection
93
+ */
94
+ getSubcollections(parentCollectionID: number): ZoteroCollection[];
95
+ /**
96
+ * Create a new collection
97
+ */
98
+ createCollection(name: string, parentCollectionID?: number | null, libraryID?: number): number;
99
+ /**
100
+ * Rename a collection
101
+ */
102
+ renameCollection(collectionID: number, newName: string): boolean;
103
+ /**
104
+ * Move a collection to a new parent
105
+ */
106
+ moveCollection(collectionID: number, newParentID: number | null): boolean;
107
+ /**
108
+ * Delete a collection
109
+ */
110
+ deleteCollection(collectionID: number): boolean;
111
+ /**
112
+ * Get all tags with usage count
113
+ */
114
+ getTags(): any[];
115
+ /**
116
+ * Get tag by name
117
+ */
118
+ getTagByName(name: string): any | null;
119
+ /**
120
+ * Create a new tag
121
+ */
122
+ createTag(name: string, _type?: number): number;
123
+ /**
124
+ * Add tag to item
125
+ */
126
+ addTagToItem(itemID: number, tagName: string, type?: number): boolean;
127
+ /**
128
+ * Remove tag from item
129
+ */
130
+ removeTagFromItem(itemID: number, tagName: string): boolean;
131
+ /**
132
+ * Get all tags for an item
133
+ * Note: type is in itemTags table, not tags table
134
+ */
135
+ getItemTags(itemID: number): any[];
136
+ /**
137
+ * Get items in a collection
138
+ */
139
+ getCollectionItems(collectionID: number): ZoteroItem[];
140
+ /**
141
+ * Add item to collection
142
+ */
143
+ addItemToCollection(itemID: number, collectionID: number): boolean;
144
+ /**
145
+ * Remove item from collection
146
+ */
147
+ removeItemFromCollection(itemID: number, collectionID: number): boolean;
148
+ /**
149
+ * Get item by key
150
+ */
151
+ getItemByKey(key: string): ZoteroItem | null;
152
+ /**
153
+ * Search items by title
154
+ */
155
+ searchItems(query: string, limit?: number, libraryID?: number): any[];
156
+ /**
157
+ * Get item details with all fields
158
+ */
159
+ getItemDetails(itemID: number): Record<string, any>;
160
+ /**
161
+ * Get item abstract
162
+ */
163
+ getItemAbstract(itemID: number): string | null;
164
+ /**
165
+ * Set item abstract
166
+ */
167
+ setItemAbstract(itemID: number, abstract: string): boolean;
168
+ /**
169
+ * Get item notes
170
+ */
171
+ getItemNotes(itemID: number): any[];
172
+ /**
173
+ * Add note to item
174
+ */
175
+ addItemNote(parentItemID: number, noteContent: string, title?: string): number;
176
+ /**
177
+ * Get attachment path
178
+ */
179
+ getAttachmentPath(itemID: number): string | null;
180
+ /**
181
+ * Get PDF attachments for an item
182
+ */
183
+ getPDFAttachments(parentItemID: number): ZoteroAttachment[];
184
+ /**
185
+ * Get storage directory path
186
+ */
187
+ getStoragePath(): string;
188
+ /**
189
+ * Find item by DOI
190
+ */
191
+ findItemByDOI(doi: string): any | null;
192
+ /**
193
+ * Find item by ISBN
194
+ */
195
+ findItemByISBN(isbn: string): any | null;
196
+ /**
197
+ * Find item by any identifier (DOI, ISBN, PMID, arXiv, etc.)
198
+ */
199
+ findItemByIdentifier(identifier: string, type?: string): any | null;
200
+ /**
201
+ * Get all annotations for an item's attachments
202
+ */
203
+ getItemAnnotations(parentItemID: number): any[];
204
+ /**
205
+ * Get annotations from a specific attachment
206
+ */
207
+ getAttachmentAnnotations(attachmentID: number): any[];
208
+ /**
209
+ * Get annotations filtered by type
210
+ */
211
+ getAnnotationsByType(parentItemID: number, types: string[]): any[];
212
+ /**
213
+ * Get annotations filtered by color
214
+ */
215
+ getAnnotationsByColor(parentItemID: number, colors: string[]): any[];
216
+ /**
217
+ * Search annotations by text content
218
+ */
219
+ searchAnnotations(query: string, parentItemID?: number): any[];
220
+ /**
221
+ * Search in Zotero's fulltext index
222
+ * fulltextWords: wordID, word
223
+ * fulltextItemWords: wordID, itemID
224
+ */
225
+ searchFulltext(query: string, libraryID?: number): any[];
226
+ /**
227
+ * Get fulltext content for an attachment
228
+ * Note: fulltextContent table may not exist in all Zotero versions
229
+ */
230
+ getFulltextContent(attachmentID: number): string | null;
231
+ /**
232
+ * Get fulltext index status for an item
233
+ */
234
+ getFulltextStatus(attachmentID: number): any;
235
+ /**
236
+ * Advanced fulltext search with context
237
+ */
238
+ searchFulltextWithContext(query: string, contextLength?: number, libraryID?: number): any[];
239
+ /**
240
+ * Get related items (manually linked)
241
+ */
242
+ getRelatedItems(itemID: number): any[];
243
+ /**
244
+ * Find similar items by shared tags
245
+ */
246
+ findSimilarByTags(itemID: number, minSharedTags?: number): any[];
247
+ /**
248
+ * Find similar items by shared creators
249
+ */
250
+ findSimilarByCreators(itemID: number): any[];
251
+ /**
252
+ * Find similar items by shared collection
253
+ */
254
+ findSimilarByCollection(itemID: number): any[];
255
+ /**
256
+ * Generate a unique Zotero key
257
+ *
258
+ * Zotero uses a specific character set that excludes ambiguous characters:
259
+ * - No '0' (zero) - confused with 'O'
260
+ * - No '1' (one) - confused with 'I' or 'L'
261
+ * - No 'I' - confused with '1' or 'L'
262
+ * - No 'L' - confused with '1' or 'I'
263
+ * - No 'O' - confused with '0'
264
+ *
265
+ * Valid characters: 23456789ABCDEFGHJKMNPQRSTUVWXYZ
266
+ */
267
+ private generateKey;
268
+ /**
269
+ * Execute a raw SQL query
270
+ */
271
+ query(sql: string, params?: any[]): any[];
272
+ /**
273
+ * Execute a raw SQL statement
274
+ */
275
+ run(sql: string, params?: any[]): {
276
+ changes: number;
277
+ lastInsertRowid: number;
278
+ };
279
+ }
280
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAkB,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AAK9D,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,M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