pdf-oxide 0.3.24

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.
Files changed (62) hide show
  1. package/README.md +218 -0
  2. package/binding.gyp +35 -0
  3. package/package.json +78 -0
  4. package/src/builders/annotation-builder.ts +367 -0
  5. package/src/builders/conversion-options-builder.ts +257 -0
  6. package/src/builders/index.ts +12 -0
  7. package/src/builders/metadata-builder.ts +317 -0
  8. package/src/builders/pdf-builder.ts +386 -0
  9. package/src/builders/search-options-builder.ts +151 -0
  10. package/src/document-editor-manager.ts +318 -0
  11. package/src/errors.ts +1629 -0
  12. package/src/form-field-manager.ts +666 -0
  13. package/src/hybrid-ml-manager.ts +283 -0
  14. package/src/index.ts +453 -0
  15. package/src/managers/accessibility-manager.ts +338 -0
  16. package/src/managers/annotation-manager.ts +439 -0
  17. package/src/managers/barcode-manager.ts +235 -0
  18. package/src/managers/batch-manager.ts +533 -0
  19. package/src/managers/cache-manager.ts +486 -0
  20. package/src/managers/compliance-manager.ts +375 -0
  21. package/src/managers/content-manager.ts +339 -0
  22. package/src/managers/document-utility-manager.ts +922 -0
  23. package/src/managers/dom-pdf-creator.ts +365 -0
  24. package/src/managers/editing-manager.ts +514 -0
  25. package/src/managers/enterprise-manager.ts +478 -0
  26. package/src/managers/extended-managers.ts +437 -0
  27. package/src/managers/extraction-manager.ts +583 -0
  28. package/src/managers/final-utilities.ts +429 -0
  29. package/src/managers/hybrid-ml-advanced.ts +479 -0
  30. package/src/managers/index.ts +239 -0
  31. package/src/managers/layer-manager.ts +500 -0
  32. package/src/managers/metadata-manager.ts +303 -0
  33. package/src/managers/ocr-manager.ts +756 -0
  34. package/src/managers/optimization-manager.ts +262 -0
  35. package/src/managers/outline-manager.ts +196 -0
  36. package/src/managers/page-manager.ts +289 -0
  37. package/src/managers/pattern-detection.ts +440 -0
  38. package/src/managers/rendering-manager.ts +863 -0
  39. package/src/managers/search-manager.ts +385 -0
  40. package/src/managers/security-manager.ts +345 -0
  41. package/src/managers/signature-manager.ts +1664 -0
  42. package/src/managers/streams.ts +618 -0
  43. package/src/managers/xfa-manager.ts +500 -0
  44. package/src/pdf-creator-manager.ts +494 -0
  45. package/src/properties.ts +522 -0
  46. package/src/result-accessors-manager.ts +867 -0
  47. package/src/tests/advanced-features.test.ts +414 -0
  48. package/src/tests/advanced.test.ts +266 -0
  49. package/src/tests/extended-managers.test.ts +316 -0
  50. package/src/tests/final-utilities.test.ts +455 -0
  51. package/src/tests/foundation.test.ts +315 -0
  52. package/src/tests/high-demand.test.ts +257 -0
  53. package/src/tests/specialized.test.ts +97 -0
  54. package/src/thumbnail-manager.ts +272 -0
  55. package/src/types/common.ts +142 -0
  56. package/src/types/document-types.ts +457 -0
  57. package/src/types/index.ts +6 -0
  58. package/src/types/manager-types.ts +284 -0
  59. package/src/types/native-bindings.ts +517 -0
  60. package/src/workers/index.ts +7 -0
  61. package/src/workers/pool.ts +274 -0
  62. package/src/workers/worker.ts +131 -0
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Comprehensive test suite for Phase 6 Extended Managers.
3
+ * Tests: DocumentExtendedManager, PerformanceManager, BatchProcessingManager, UtilitiesManager
4
+ */
5
+
6
+ import { describe, it, expect, beforeEach } from '@jest/globals';
7
+
8
+ import DocumentExtendedManager from '../managers/document-extended-manager';
9
+ import PerformanceManager from '../managers/performance-manager';
10
+ import BatchProcessingManager from '../managers/batch-processing-manager';
11
+ import UtilitiesManager from '../managers/utilities-manager';
12
+
13
+ describe('Phase 6 Extended Managers', () => {
14
+ describe('DocumentExtendedManager', () => {
15
+ let manager: DocumentExtendedManager;
16
+
17
+ beforeEach(() => {
18
+ manager = new DocumentExtendedManager();
19
+ });
20
+
21
+ it('should get document title as string or null', () => {
22
+ const result = manager.getDocumentTitle();
23
+ expect(result).toBeNull || expect(typeof result).toBe('string');
24
+ });
25
+
26
+ it('should set document title and return boolean', () => {
27
+ const result = manager.setDocumentTitle('Test Document');
28
+ expect(typeof result).toBe('boolean');
29
+ });
30
+
31
+ it('should get document author as string or null', () => {
32
+ const result = manager.getDocumentAuthor();
33
+ expect(result).toBeNull || expect(typeof result).toBe('string');
34
+ });
35
+
36
+ it('should set document author and return boolean', () => {
37
+ const result = manager.setDocumentAuthor('John Doe');
38
+ expect(typeof result).toBe('boolean');
39
+ });
40
+
41
+ it('should check if document is encrypted', () => {
42
+ const result = manager.isDocumentEncrypted();
43
+ expect(typeof result).toBe('boolean');
44
+ });
45
+
46
+ it('should get page count as non-negative integer', () => {
47
+ const result = manager.getPageCount();
48
+ expect(typeof result).toBe('number');
49
+ expect(result).toBeGreaterThanOrEqual(0);
50
+ });
51
+
52
+ it('should get document size as non-negative integer', () => {
53
+ const result = manager.getDocumentSize();
54
+ expect(typeof result).toBe('number');
55
+ expect(result).toBeGreaterThanOrEqual(0);
56
+ });
57
+
58
+ it('should get document metadata as object or null', () => {
59
+ const result = manager.getDocumentMetadata();
60
+ expect(result === null || typeof result === 'object').toBe(true);
61
+ });
62
+
63
+ it('should perform title roundtrip in integration', () => {
64
+ const title = 'Integration Test Document';
65
+ manager.setDocumentTitle(title);
66
+ // In real scenario, would retrieve and compare
67
+ });
68
+ });
69
+
70
+ describe('PerformanceManager', () => {
71
+ let manager: PerformanceManager;
72
+
73
+ beforeEach(() => {
74
+ manager = new PerformanceManager();
75
+ });
76
+
77
+ it('should start timer and return string ID', () => {
78
+ const timerId = manager.startTimer('test_operation');
79
+ expect(typeof timerId).toBe('string');
80
+ expect(timerId).toContain('test_operation');
81
+ });
82
+
83
+ it('should get metrics as array', () => {
84
+ const metrics = manager.getMetrics();
85
+ expect(Array.isArray(metrics)).toBe(true);
86
+ });
87
+
88
+ it('should reset metrics and return boolean', () => {
89
+ const result = manager.resetMetrics();
90
+ expect(typeof result).toBe('boolean');
91
+ });
92
+
93
+ it('should enable caching and return boolean', () => {
94
+ const result = manager.enableCaching();
95
+ expect(typeof result).toBe('boolean');
96
+ });
97
+
98
+ it('should disable caching and return boolean', () => {
99
+ const result = manager.disableCaching();
100
+ expect(typeof result).toBe('boolean');
101
+ });
102
+
103
+ it('should clear cache and return boolean', () => {
104
+ const result = manager.clearCache();
105
+ expect(typeof result).toBe('boolean');
106
+ });
107
+
108
+ it('should get cache size as non-negative integer', () => {
109
+ const result = manager.getCacheSize();
110
+ expect(typeof result).toBe('number');
111
+ expect(result).toBeGreaterThanOrEqual(0);
112
+ });
113
+
114
+ it('should measure timer performance and complete quickly', async () => {
115
+ const timerId = manager.startTimer('perf_test');
116
+ await new Promise((resolve) => setTimeout(resolve, 10));
117
+ const result = manager.stopTimer(timerId);
118
+ expect(result).toBeDefined();
119
+ });
120
+
121
+ it('should track memory usage as non-negative integer', () => {
122
+ const result = manager.getMemoryUsage();
123
+ expect(typeof result).toBe('number');
124
+ expect(result).toBeGreaterThanOrEqual(0);
125
+ });
126
+ });
127
+
128
+ describe('BatchProcessingManager', () => {
129
+ let manager: BatchProcessingManager;
130
+
131
+ beforeEach(() => {
132
+ manager = new BatchProcessingManager();
133
+ });
134
+
135
+ it('should create batch job and return job or null', () => {
136
+ const job = manager.createBatchJob('job_001', '/path/to/file.pdf', 'extract');
137
+ // Job can be null or object
138
+ });
139
+
140
+ it('should submit batch job and return boolean', () => {
141
+ const result = manager.submitBatchJob('job_001');
142
+ expect(typeof result).toBe('boolean');
143
+ });
144
+
145
+ it('should get batch job status as string or null', () => {
146
+ const status = manager.getBatchJobStatus('job_001');
147
+ expect(status === null || typeof status === 'string').toBe(true);
148
+ });
149
+
150
+ it('should get batch job progress between 0 and 100', () => {
151
+ const progress = manager.getBatchJobProgress('job_001');
152
+ expect(typeof progress).toBe('number');
153
+ expect(progress).toBeGreaterThanOrEqual(0);
154
+ expect(progress).toBeLessThanOrEqual(100);
155
+ });
156
+
157
+ it('should list batch jobs as array', () => {
158
+ const jobs = manager.listBatchJobs();
159
+ expect(Array.isArray(jobs)).toBe(true);
160
+ });
161
+
162
+ it('should clear batch jobs and return non-negative count', () => {
163
+ const count = manager.clearBatchJobs(true);
164
+ expect(typeof count).toBe('number');
165
+ expect(count).toBeGreaterThanOrEqual(0);
166
+ });
167
+
168
+ it('should complete full job lifecycle', () => {
169
+ // Create
170
+ const job = manager.createBatchJob('test_job', '/test.pdf', 'process');
171
+ // Submit
172
+ manager.submitBatchJob('test_job');
173
+ // Check status
174
+ const status = manager.getBatchJobStatus('test_job');
175
+ // Check progress
176
+ const progress = manager.getBatchJobProgress('test_job');
177
+ expect(progress).toBeGreaterThanOrEqual(0);
178
+ });
179
+ });
180
+
181
+ describe('UtilitiesManager', () => {
182
+ let manager: UtilitiesManager;
183
+
184
+ beforeEach(() => {
185
+ manager = new UtilitiesManager();
186
+ });
187
+
188
+ it('should validate document and return boolean', () => {
189
+ const result = manager.validateDocument();
190
+ expect(typeof result).toBe('boolean');
191
+ });
192
+
193
+ it('should get document statistics as object or null', () => {
194
+ const stats = manager.getDocumentStatistics();
195
+ expect(stats === null || typeof stats === 'object').toBe(true);
196
+ });
197
+
198
+ it('should remove pages and return boolean', () => {
199
+ const result = manager.removePages([1, 2, 3]);
200
+ expect(typeof result).toBe('boolean');
201
+ });
202
+
203
+ it('should duplicate pages and return boolean', () => {
204
+ const result = manager.duplicatePages(0, 2);
205
+ expect(typeof result).toBe('boolean');
206
+ });
207
+
208
+ it('should add watermark and return boolean', () => {
209
+ const result = manager.addWatermark('DRAFT', 0.5);
210
+ expect(typeof result).toBe('boolean');
211
+ });
212
+
213
+ it('should add page numbers and return boolean', () => {
214
+ const result = manager.addPageNumbers('Page {n}');
215
+ expect(typeof result).toBe('boolean');
216
+ });
217
+
218
+ it('should merge PDFs and return boolean', () => {
219
+ const result = manager.mergePDFs('/output.pdf', ['/file1.pdf', '/file2.pdf']);
220
+ expect(typeof result).toBe('boolean');
221
+ });
222
+
223
+ it('should split PDF and return integer', () => {
224
+ const result = manager.splitPDF('/output_dir', 10);
225
+ expect(typeof result).toBe('number');
226
+ });
227
+
228
+ it('should rotate PDF and return boolean', () => {
229
+ const result = manager.rotatePDF(90, '/output.pdf');
230
+ expect(typeof result).toBe('boolean');
231
+ });
232
+
233
+ it('should scale PDF and return boolean', () => {
234
+ const result = manager.scalePDF(1.5, '/output.pdf');
235
+ expect(typeof result).toBe('boolean');
236
+ });
237
+
238
+ it('should reorder pages and return boolean', () => {
239
+ const result = manager.reorderPages([3, 2, 1, 0]);
240
+ expect(typeof result).toBe('boolean');
241
+ });
242
+
243
+ it('should complete document transformation pipeline', () => {
244
+ // Add watermark
245
+ manager.addWatermark('CONFIDENTIAL', 0.5);
246
+ // Add page numbers
247
+ manager.addPageNumbers('Page {n}');
248
+ // Could add more transformations
249
+ });
250
+ });
251
+
252
+ describe('Edge Cases', () => {
253
+ it('should handle empty string title gracefully', () => {
254
+ const manager = new DocumentExtendedManager();
255
+ const result = manager.setDocumentTitle('');
256
+ expect(typeof result).toBe('boolean');
257
+ });
258
+
259
+ it('should handle invalid page indices gracefully', () => {
260
+ const manager = new UtilitiesManager();
261
+ const result = manager.removePages([-1, 999]);
262
+ expect(typeof result).toBe('boolean');
263
+ });
264
+
265
+ it('should handle null parameters without crashing', () => {
266
+ const manager = new UtilitiesManager();
267
+ expect(() => {
268
+ manager.addWatermark(null as any, 0.5);
269
+ }).not.toThrow();
270
+ });
271
+ });
272
+
273
+ describe('Performance Tests', () => {
274
+ it('should handle 100 batch jobs in reasonable time', () => {
275
+ const manager = new BatchProcessingManager();
276
+ const start = Date.now();
277
+
278
+ for (let i = 0; i < 100; i++) {
279
+ manager.createBatchJob(`job_${i}`, `/file_${i}.pdf`, 'process');
280
+ }
281
+
282
+ const elapsed = Date.now() - start;
283
+ expect(elapsed).toBeLessThan(1000); // Less than 1 second for 100 jobs
284
+ });
285
+
286
+ it('should have reasonable memory overhead for manager creation', () => {
287
+ const memBefore = (process.memoryUsage().heapUsed / 1024 / 1024);
288
+
289
+ for (let i = 0; i < 10; i++) {
290
+ new DocumentExtendedManager();
291
+ }
292
+
293
+ const memAfter = (process.memoryUsage().heapUsed / 1024 / 1024);
294
+ const memUsed = memAfter - memBefore;
295
+
296
+ // Memory usage should be reasonable
297
+ expect(memUsed).toBeLessThan(50); // Less than 50MB for 10 managers
298
+ });
299
+
300
+ it('should handle concurrent timer operations safely', async () => {
301
+ const manager = new PerformanceManager();
302
+ const promises: Promise<any>[] = [];
303
+
304
+ for (let i = 0; i < 10; i++) {
305
+ promises.push(
306
+ new Promise((resolve) => {
307
+ resolve(manager.startTimer('test'));
308
+ })
309
+ );
310
+ }
311
+
312
+ const results = await Promise.all(promises);
313
+ expect(results.length).toBe(10);
314
+ });
315
+ });
316
+ });