@devrev/airsync-sdk 2.0.0-beta.0 → 2.0.0-beta.10

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 (227) hide show
  1. package/README.md +7 -21
  2. package/dist/attachments-streaming/attachments-streaming-pool.d.ts +7 -1
  3. package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
  4. package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +4 -3
  5. package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
  6. package/dist/attachments-streaming/attachments-streaming-pool.js +70 -33
  7. package/dist/common/constants.d.ts +15 -12
  8. package/dist/common/constants.d.ts.map +1 -1
  9. package/dist/common/constants.js +20 -34
  10. package/dist/common/helpers.d.ts +3 -27
  11. package/dist/common/helpers.d.ts.map +1 -1
  12. package/dist/common/helpers.js +6 -36
  13. package/dist/http/{axios-client-internal.d.ts → client.d.ts} +1 -1
  14. package/dist/http/client.d.ts.map +1 -0
  15. package/dist/http/{axios-client-internal.js → client.js} +7 -4
  16. package/dist/http/errors.d.ts +8 -0
  17. package/dist/http/errors.d.ts.map +1 -0
  18. package/dist/http/errors.js +31 -0
  19. package/dist/index.d.ts +30 -12
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +47 -28
  22. package/dist/logger/logger.d.ts +13 -70
  23. package/dist/logger/logger.d.ts.map +1 -1
  24. package/dist/logger/logger.interfaces.d.ts +4 -7
  25. package/dist/logger/logger.interfaces.d.ts.map +1 -1
  26. package/dist/logger/logger.js +67 -92
  27. package/dist/mappers/mappers.d.ts +10 -43
  28. package/dist/mappers/mappers.d.ts.map +1 -1
  29. package/dist/mappers/mappers.interfaces.d.ts +173 -0
  30. package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
  31. package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +1 -10
  32. package/dist/mappers/mappers.js +32 -46
  33. package/dist/multithreading/adapters/base-adapter.d.ts +39 -0
  34. package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
  35. package/dist/multithreading/adapters/base-adapter.js +212 -0
  36. package/dist/multithreading/adapters/extraction-adapter.d.ts +49 -0
  37. package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
  38. package/dist/multithreading/adapters/extraction-adapter.js +375 -0
  39. package/dist/multithreading/adapters/loading-adapter.d.ts +26 -0
  40. package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -0
  41. package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +12 -0
  42. package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -0
  43. package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +2 -12
  44. package/dist/multithreading/adapters/loading-adapter.js +279 -0
  45. package/dist/multithreading/emit.d.ts +11 -0
  46. package/dist/multithreading/emit.d.ts.map +1 -0
  47. package/dist/multithreading/emit.js +25 -0
  48. package/dist/multithreading/process-task.d.ts +6 -1
  49. package/dist/multithreading/process-task.d.ts.map +1 -1
  50. package/dist/multithreading/process-task.js +124 -51
  51. package/dist/multithreading/spawn/spawn.d.ts +11 -11
  52. package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
  53. package/dist/multithreading/spawn/spawn.helpers.d.ts +12 -11
  54. package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
  55. package/dist/multithreading/spawn/spawn.helpers.js +142 -77
  56. package/dist/multithreading/spawn/spawn.js +74 -75
  57. package/dist/multithreading/worker.js +16 -5
  58. package/dist/repo/repo.d.ts +14 -5
  59. package/dist/repo/repo.d.ts.map +1 -1
  60. package/dist/repo/repo.helpers.d.ts +6 -0
  61. package/dist/repo/repo.helpers.d.ts.map +1 -0
  62. package/dist/repo/repo.helpers.js +16 -0
  63. package/dist/repo/repo.interfaces.d.ts +11 -20
  64. package/dist/repo/repo.interfaces.d.ts.map +1 -1
  65. package/dist/repo/repo.js +36 -22
  66. package/dist/state/base-state.d.ts +58 -0
  67. package/dist/state/base-state.d.ts.map +1 -0
  68. package/dist/state/base-state.js +242 -0
  69. package/dist/state/extraction-state.d.ts +14 -0
  70. package/dist/state/extraction-state.d.ts.map +1 -0
  71. package/dist/state/extraction-state.js +140 -0
  72. package/dist/state/install-initial-domain-mapping.d.ts +4 -0
  73. package/dist/state/install-initial-domain-mapping.d.ts.map +1 -0
  74. package/dist/{common → state}/install-initial-domain-mapping.js +5 -7
  75. package/dist/state/loading-state.d.ts +8 -0
  76. package/dist/state/loading-state.d.ts.map +1 -0
  77. package/dist/state/loading-state.js +29 -0
  78. package/dist/state/state.d.ts +3 -29
  79. package/dist/state/state.d.ts.map +1 -1
  80. package/dist/state/state.interfaces.d.ts +36 -10
  81. package/dist/state/state.interfaces.d.ts.map +1 -1
  82. package/dist/state/state.interfaces.js +17 -1
  83. package/dist/state/state.js +9 -164
  84. package/dist/state/time-value-resolver.d.ts +17 -0
  85. package/dist/state/time-value-resolver.d.ts.map +1 -0
  86. package/dist/state/time-value-resolver.js +110 -0
  87. package/dist/testing/mock-event.d.ts +10 -0
  88. package/dist/testing/mock-event.d.ts.map +1 -0
  89. package/dist/testing/mock-event.js +96 -0
  90. package/dist/testing/mock-server.d.ts +31 -0
  91. package/dist/testing/mock-server.d.ts.map +1 -0
  92. package/dist/testing/mock-server.interfaces.d.ts +54 -0
  93. package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
  94. package/dist/testing/mock-server.interfaces.js +4 -0
  95. package/dist/testing/mock-server.js +297 -0
  96. package/dist/testing/test-adapters.d.ts +22 -0
  97. package/dist/testing/test-adapters.d.ts.map +1 -0
  98. package/dist/testing/test-adapters.js +32 -0
  99. package/dist/types/common.d.ts +4 -37
  100. package/dist/types/common.d.ts.map +1 -1
  101. package/dist/types/common.js +2 -17
  102. package/dist/types/errors.d.ts +15 -0
  103. package/dist/types/errors.d.ts.map +1 -0
  104. package/dist/types/errors.js +28 -0
  105. package/dist/types/external-domain-metadata.d.ts +197 -0
  106. package/dist/types/external-domain-metadata.d.ts.map +1 -0
  107. package/dist/types/extraction.d.ts +135 -278
  108. package/dist/types/extraction.d.ts.map +1 -1
  109. package/dist/types/extraction.js +46 -133
  110. package/dist/types/loading.d.ts +15 -55
  111. package/dist/types/loading.d.ts.map +1 -1
  112. package/dist/types/loading.js +1 -23
  113. package/dist/types/workers.d.ts +70 -103
  114. package/dist/types/workers.d.ts.map +1 -1
  115. package/dist/types/workers.js +1 -6
  116. package/dist/uploader/uploader.d.ts +10 -61
  117. package/dist/uploader/uploader.d.ts.map +1 -1
  118. package/dist/uploader/uploader.helpers.d.ts +7 -27
  119. package/dist/uploader/uploader.helpers.d.ts.map +1 -1
  120. package/dist/uploader/uploader.helpers.js +80 -30
  121. package/dist/uploader/uploader.interfaces.d.ts +19 -54
  122. package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
  123. package/dist/uploader/uploader.interfaces.js +8 -0
  124. package/dist/uploader/uploader.js +72 -124
  125. package/docs/MIGRATION.md +696 -0
  126. package/package.json +37 -20
  127. package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +0 -2
  128. package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +0 -1
  129. package/dist/attachments-streaming/attachments-streaming-pool.test.js +0 -267
  130. package/dist/common/control-protocol.d.ts +0 -10
  131. package/dist/common/control-protocol.d.ts.map +0 -1
  132. package/dist/common/control-protocol.js +0 -31
  133. package/dist/common/errors.d.ts +0 -6
  134. package/dist/common/errors.d.ts.map +0 -1
  135. package/dist/common/errors.js +0 -4
  136. package/dist/common/event-type-translation.d.ts +0 -24
  137. package/dist/common/event-type-translation.d.ts.map +0 -1
  138. package/dist/common/event-type-translation.js +0 -117
  139. package/dist/common/install-initial-domain-mapping.d.ts +0 -4
  140. package/dist/common/install-initial-domain-mapping.d.ts.map +0 -1
  141. package/dist/common/install-initial-domain-mapping.test.d.ts +0 -2
  142. package/dist/common/install-initial-domain-mapping.test.d.ts.map +0 -1
  143. package/dist/common/install-initial-domain-mapping.test.js +0 -207
  144. package/dist/deprecated/adapter/index.d.ts +0 -62
  145. package/dist/deprecated/adapter/index.d.ts.map +0 -1
  146. package/dist/deprecated/adapter/index.js +0 -151
  147. package/dist/deprecated/common/helpers.d.ts +0 -7
  148. package/dist/deprecated/common/helpers.d.ts.map +0 -1
  149. package/dist/deprecated/common/helpers.js +0 -47
  150. package/dist/deprecated/demo-extractor/external_domain_metadata.json +0 -38
  151. package/dist/deprecated/demo-extractor/index.d.ts +0 -18
  152. package/dist/deprecated/demo-extractor/index.d.ts.map +0 -1
  153. package/dist/deprecated/demo-extractor/index.js +0 -161
  154. package/dist/deprecated/http/client.d.ts +0 -22
  155. package/dist/deprecated/http/client.d.ts.map +0 -1
  156. package/dist/deprecated/http/client.js +0 -161
  157. package/dist/deprecated/uploader/index.d.ts +0 -35
  158. package/dist/deprecated/uploader/index.d.ts.map +0 -1
  159. package/dist/deprecated/uploader/index.js +0 -161
  160. package/dist/http/axios-client-internal.d.ts.map +0 -1
  161. package/dist/http/axios-client-internal.test.d.ts +0 -2
  162. package/dist/http/axios-client-internal.test.d.ts.map +0 -1
  163. package/dist/http/axios-client-internal.test.js +0 -154
  164. package/dist/http/axios-client.d.ts +0 -27
  165. package/dist/http/axios-client.d.ts.map +0 -1
  166. package/dist/http/axios-client.js +0 -57
  167. package/dist/http/constants.d.ts +0 -4
  168. package/dist/http/constants.d.ts.map +0 -1
  169. package/dist/http/constants.js +0 -6
  170. package/dist/http/index.d.ts +0 -3
  171. package/dist/http/index.d.ts.map +0 -1
  172. package/dist/http/index.js +0 -18
  173. package/dist/http/types.d.ts +0 -17
  174. package/dist/http/types.d.ts.map +0 -1
  175. package/dist/logger/logger.constants.d.ts +0 -6
  176. package/dist/logger/logger.constants.d.ts.map +0 -1
  177. package/dist/logger/logger.constants.js +0 -13
  178. package/dist/logger/logger.context.d.ts +0 -58
  179. package/dist/logger/logger.context.d.ts.map +0 -1
  180. package/dist/logger/logger.context.js +0 -86
  181. package/dist/logger/logger.test.d.ts +0 -2
  182. package/dist/logger/logger.test.d.ts.map +0 -1
  183. package/dist/logger/logger.test.js +0 -490
  184. package/dist/mappers/mappers.interface.d.ts +0 -294
  185. package/dist/mappers/mappers.interface.d.ts.map +0 -1
  186. package/dist/mappers/mappers.test.d.ts +0 -2
  187. package/dist/mappers/mappers.test.d.ts.map +0 -1
  188. package/dist/mappers/mappers.test.js +0 -107
  189. package/dist/multithreading/create-worker.test.d.ts +0 -2
  190. package/dist/multithreading/create-worker.test.d.ts.map +0 -1
  191. package/dist/multithreading/create-worker.test.js +0 -89
  192. package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
  193. package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
  194. package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
  195. package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +0 -2
  196. package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +0 -1
  197. package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +0 -127
  198. package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -91
  199. package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
  200. package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +0 -22
  201. package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +0 -1
  202. package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +0 -2
  203. package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +0 -1
  204. package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +0 -514
  205. package/dist/multithreading/worker-adapter/worker-adapter.js +0 -747
  206. package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +0 -2
  207. package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +0 -1
  208. package/dist/multithreading/worker-adapter/worker-adapter.test.js +0 -483
  209. package/dist/repo/repo.test.d.ts +0 -2
  210. package/dist/repo/repo.test.d.ts.map +0 -1
  211. package/dist/repo/repo.test.js +0 -131
  212. package/dist/state/state.test.d.ts +0 -2
  213. package/dist/state/state.test.d.ts.map +0 -1
  214. package/dist/state/state.test.js +0 -224
  215. package/dist/types/extraction.test.d.ts +0 -2
  216. package/dist/types/extraction.test.d.ts.map +0 -1
  217. package/dist/types/extraction.test.js +0 -70
  218. package/dist/types/index.d.ts +0 -9
  219. package/dist/types/index.d.ts.map +0 -1
  220. package/dist/types/index.js +0 -18
  221. package/dist/uploader/uploader.helpers.test.d.ts +0 -2
  222. package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
  223. package/dist/uploader/uploader.helpers.test.js +0 -267
  224. package/dist/uploader/uploader.test.d.ts +0 -2
  225. package/dist/uploader/uploader.test.d.ts.map +0 -1
  226. package/dist/uploader/uploader.test.js +0 -589
  227. /package/dist/{http/types.js → types/external-domain-metadata.js} +0 -0
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=worker-adapter.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker-adapter.test.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.test.ts"],"names":[],"mappings":""}
@@ -1,483 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const attachments_streaming_pool_1 = require("../../attachments-streaming/attachments-streaming-pool");
4
- const state_1 = require("../../state/state");
5
- const test_helpers_1 = require("../../tests/test-helpers");
6
- const types_1 = require("../../types");
7
- const worker_adapter_1 = require("./worker-adapter");
8
- /* eslint-disable @typescript-eslint/no-require-imports */
9
- // Mock dependencies
10
- jest.mock('../../common/control-protocol', () => ({
11
- emit: jest.fn().mockResolvedValue({}),
12
- }));
13
- // const mockPostState = jest.spyOn(State.prototype, 'postState').mockResolvedValue(); // Mock to resolve void
14
- // const mockFetchState = jest.spyOn(State.prototype, 'fetchState').mockResolvedValue({}); // Mock to resolve a default state
15
- jest.mock('../../mappers/mappers');
16
- jest.mock('../../uploader/uploader');
17
- // jest.mock('../../state/state');
18
- jest.mock('../../repo/repo');
19
- jest.mock('node:worker_threads', () => ({
20
- parentPort: {
21
- postMessage: jest.fn(),
22
- },
23
- }));
24
- jest.mock('../../attachments-streaming/attachments-streaming-pool', () => {
25
- return {
26
- AttachmentsStreamingPool: jest.fn().mockImplementation(() => {
27
- return {
28
- streamAll: jest.fn().mockResolvedValue(undefined),
29
- };
30
- }),
31
- };
32
- });
33
- describe(worker_adapter_1.WorkerAdapter.name, () => {
34
- let adapter;
35
- let mockEvent;
36
- let mockAdapterState;
37
- beforeEach(() => {
38
- // Reset all mocks
39
- jest.clearAllMocks();
40
- // Create mock objects
41
- mockEvent = (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.StartExtractingData });
42
- const initialState = {
43
- attachments: { completed: false },
44
- lastSyncStarted: '',
45
- lastSuccessfulSyncStarted: '',
46
- snapInVersionId: '',
47
- toDevRev: {
48
- attachmentsMetadata: {
49
- artifactIds: [],
50
- lastProcessed: 0,
51
- lastProcessedAttachmentsIdsList: [],
52
- },
53
- },
54
- };
55
- mockAdapterState = new state_1.State({
56
- event: mockEvent,
57
- initialState: initialState,
58
- });
59
- // Create the adapter instance
60
- adapter = new worker_adapter_1.WorkerAdapter({
61
- event: mockEvent,
62
- adapterState: mockAdapterState,
63
- });
64
- });
65
- describe(worker_adapter_1.WorkerAdapter.prototype.streamAttachments.name, () => {
66
- it('should process all artifact batches successfully', async () => {
67
- const mockStream = jest.fn();
68
- // Set up adapter state with artifact IDs
69
- adapter.state.toDevRev = {
70
- attachmentsMetadata: {
71
- artifactIds: ['artifact1', 'artifact2'],
72
- lastProcessed: 0,
73
- lastProcessedAttachmentsIdsList: [],
74
- },
75
- };
76
- // Mock getting attachments from each artifact
77
- adapter['uploader'].getAttachmentsFromArtifactId = jest
78
- .fn()
79
- .mockResolvedValueOnce({
80
- attachments: [
81
- {
82
- url: 'http://example.com/file1.pdf',
83
- id: 'attachment1',
84
- file_name: 'file1.pdf',
85
- parent_id: 'parent1',
86
- },
87
- {
88
- url: 'http://example.com/file2.pdf',
89
- id: 'attachment2',
90
- file_name: 'file2.pdf',
91
- parent_id: 'parent2',
92
- },
93
- ],
94
- })
95
- .mockResolvedValueOnce({
96
- attachments: [
97
- {
98
- url: 'http://example.com/file3.pdf',
99
- id: 'attachment3',
100
- file_name: 'file3.pdf',
101
- parent_id: 'parent3',
102
- },
103
- ],
104
- });
105
- // Mock the initializeRepos method
106
- adapter.initializeRepos = jest.fn();
107
- const result = await adapter.streamAttachments({
108
- stream: mockStream,
109
- });
110
- expect(adapter.initializeRepos).toHaveBeenCalledWith([
111
- { itemType: 'ssor_attachment' },
112
- ]);
113
- expect(adapter.initializeRepos).toHaveBeenCalledTimes(1);
114
- expect(adapter['uploader'].getAttachmentsFromArtifactId).toHaveBeenCalledTimes(2);
115
- // Verify state was updated correctly
116
- expect(adapter.state.toDevRev.attachmentsMetadata.artifactIds).toEqual([]);
117
- expect(adapter.state.toDevRev.attachmentsMetadata.lastProcessed).toBe(0);
118
- expect(result).toBeUndefined();
119
- });
120
- it('[edge] should handle invalid batch size by using 1 instead', async () => {
121
- const mockStream = jest.fn();
122
- // Set up adapter state with artifact IDs
123
- adapter.state.toDevRev = {
124
- attachmentsMetadata: {
125
- artifactIds: ['artifact1'],
126
- lastProcessed: 0,
127
- lastProcessedAttachmentsIdsList: [],
128
- },
129
- };
130
- // Mock getting attachments
131
- adapter['uploader'].getAttachmentsFromArtifactId = jest
132
- .fn()
133
- .mockResolvedValue({
134
- attachments: [
135
- {
136
- url: 'http://example.com/file1.pdf',
137
- id: 'attachment1',
138
- file_name: 'file1.pdf',
139
- parent_id: 'parent1',
140
- },
141
- ],
142
- });
143
- adapter.initializeRepos = jest.fn();
144
- const result = await adapter.streamAttachments({
145
- stream: mockStream,
146
- batchSize: 0,
147
- });
148
- expect(result).toBeUndefined();
149
- });
150
- it('[edge] should cap batch size to 50 when batchSize is greater than 50', async () => {
151
- const mockStream = jest.fn();
152
- // Set up adapter state with artifact IDs
153
- adapter.state.toDevRev = {
154
- attachmentsMetadata: {
155
- artifactIds: ['artifact1'],
156
- lastProcessed: 0,
157
- lastProcessedAttachmentsIdsList: [],
158
- },
159
- };
160
- // Mock getting attachments
161
- adapter['uploader'].getAttachmentsFromArtifactId = jest
162
- .fn()
163
- .mockResolvedValue({
164
- attachments: [
165
- {
166
- url: 'http://example.com/file1.pdf',
167
- id: 'attachment1',
168
- file_name: 'file1.pdf',
169
- parent_id: 'parent1',
170
- },
171
- ],
172
- });
173
- // Mock the required methods
174
- adapter.initializeRepos = jest.fn();
175
- const result = await adapter.streamAttachments({
176
- stream: mockStream,
177
- batchSize: 100, // Set batch size greater than 50
178
- });
179
- expect(result).toBeUndefined();
180
- });
181
- it('[edge] should handle empty attachments metadata artifact IDs', async () => {
182
- const mockStream = jest.fn();
183
- // Set up adapter state with no artifact IDs
184
- adapter.state.toDevRev = {
185
- attachmentsMetadata: {
186
- artifactIds: [],
187
- lastProcessed: 0,
188
- },
189
- };
190
- const result = await adapter.streamAttachments({
191
- stream: mockStream,
192
- });
193
- expect(result).toBeUndefined();
194
- });
195
- it('[edge] should handle errors when getting attachments', async () => {
196
- const mockStream = jest.fn();
197
- // Set up adapter state with artifact IDs
198
- adapter.state.toDevRev = {
199
- attachmentsMetadata: {
200
- artifactIds: ['artifact1'],
201
- lastProcessed: 0,
202
- lastProcessedAttachmentsIdsList: [],
203
- },
204
- };
205
- // Mock error when getting attachments
206
- const mockError = new Error('Failed to get attachments');
207
- adapter['uploader'].getAttachmentsFromArtifactId = jest
208
- .fn()
209
- .mockResolvedValue({
210
- error: mockError,
211
- });
212
- // Mock methods
213
- adapter.initializeRepos = jest.fn();
214
- const result = await adapter.streamAttachments({
215
- stream: mockStream,
216
- });
217
- expect(result).toEqual({
218
- error: mockError,
219
- });
220
- });
221
- it('[edge] should handle empty attachments array from artifact', async () => {
222
- const mockStream = jest.fn();
223
- // Set up adapter state with artifact IDs
224
- adapter.state.toDevRev = {
225
- attachmentsMetadata: {
226
- artifactIds: ['artifact1'],
227
- lastProcessed: 0,
228
- lastProcessedAttachmentsIdsList: [],
229
- },
230
- };
231
- // Mock getting empty attachments
232
- adapter['uploader'].getAttachmentsFromArtifactId = jest
233
- .fn()
234
- .mockResolvedValue({
235
- attachments: [],
236
- });
237
- // Mock methods
238
- adapter.initializeRepos = jest.fn();
239
- const result = await adapter.streamAttachments({
240
- stream: mockStream,
241
- });
242
- expect(adapter.state.toDevRev.attachmentsMetadata.artifactIds).toEqual([]);
243
- expect(result).toBeUndefined();
244
- });
245
- it('should use custom processors when provided', async () => {
246
- const mockStream = jest.fn();
247
- const mockReducer = jest.fn().mockReturnValue(['custom-reduced']);
248
- const mockIterator = jest.fn().mockResolvedValue({});
249
- // Set up adapter state with artifact IDs
250
- adapter.state.toDevRev = {
251
- attachmentsMetadata: {
252
- artifactIds: ['artifact1'],
253
- lastProcessed: 0,
254
- lastProcessedAttachmentsIdsList: [],
255
- },
256
- };
257
- // Mock getting attachments
258
- adapter['uploader'].getAttachmentsFromArtifactId = jest
259
- .fn()
260
- .mockResolvedValue({
261
- attachments: [{ id: 'attachment1' }],
262
- });
263
- // Mock methods
264
- adapter.initializeRepos = jest.fn();
265
- const result = await adapter.streamAttachments({
266
- stream: mockStream,
267
- processors: {
268
- reducer: mockReducer,
269
- iterator: mockIterator,
270
- },
271
- });
272
- expect(mockReducer).toHaveBeenCalledWith({
273
- attachments: [{ id: 'attachment1' }],
274
- adapter: adapter,
275
- batchSize: 1,
276
- });
277
- expect(mockIterator).toHaveBeenCalledWith({
278
- reducedAttachments: ['custom-reduced'],
279
- adapter: adapter,
280
- stream: mockStream,
281
- });
282
- expect(result).toBeUndefined();
283
- });
284
- it('should handle rate limiting from iterator', async () => {
285
- const mockStream = jest.fn();
286
- attachments_streaming_pool_1.AttachmentsStreamingPool.mockImplementationOnce(() => {
287
- return {
288
- // Return an object with a `streamAll` method that resolves to your desired value.
289
- streamAll: jest.fn().mockResolvedValue({ delay: 30 }),
290
- };
291
- });
292
- // Set up adapter state with artifact IDs
293
- adapter.state.toDevRev = {
294
- attachmentsMetadata: {
295
- artifactIds: ['artifact1'],
296
- lastProcessed: 0,
297
- lastProcessedAttachmentsIdsList: [],
298
- },
299
- };
300
- // Mock getting attachments
301
- adapter['uploader'].getAttachmentsFromArtifactId = jest
302
- .fn()
303
- .mockResolvedValue({
304
- attachments: [{ id: 'attachment1' }],
305
- });
306
- // Mock methods
307
- adapter.initializeRepos = jest.fn();
308
- const result = await adapter.streamAttachments({
309
- stream: mockStream,
310
- });
311
- expect(result).toEqual({
312
- delay: 30,
313
- });
314
- // The artifactIds array should remain unchanged
315
- expect(adapter.state.toDevRev.attachmentsMetadata.artifactIds).toEqual([
316
- 'artifact1',
317
- ]);
318
- });
319
- it('should handle error from iterator', async () => {
320
- const mockStream = jest.fn();
321
- attachments_streaming_pool_1.AttachmentsStreamingPool.mockImplementationOnce(() => {
322
- return {
323
- // Return an object with a `streamAll` method that resolves to your desired value.
324
- streamAll: jest.fn().mockResolvedValue({
325
- error: 'Mock error',
326
- }),
327
- };
328
- });
329
- // Set up adapter state with artifact IDs
330
- adapter.state.toDevRev = {
331
- attachmentsMetadata: {
332
- artifactIds: ['artifact1'],
333
- lastProcessed: 0,
334
- lastProcessedAttachmentsIdsList: [],
335
- },
336
- };
337
- // Mock getting attachments
338
- adapter['uploader'].getAttachmentsFromArtifactId = jest
339
- .fn()
340
- .mockResolvedValue({
341
- attachments: [{ id: 'attachment1' }],
342
- });
343
- // Mock methods
344
- adapter.initializeRepos = jest.fn();
345
- const result = await adapter.streamAttachments({
346
- stream: mockStream,
347
- });
348
- expect(result).toEqual({
349
- error: 'Mock error',
350
- });
351
- // The artifactIds array should remain unchanged
352
- expect(adapter.state.toDevRev.attachmentsMetadata.artifactIds).toEqual([
353
- 'artifact1',
354
- ]);
355
- });
356
- it('should reset lastProcessed and attachment IDs list after processing all artifacts', async () => {
357
- const mockStream = jest.fn();
358
- adapter.state.toDevRev = {
359
- attachmentsMetadata: {
360
- artifactIds: ['artifact1'],
361
- lastProcessed: 0,
362
- lastProcessedAttachmentsIdsList: [],
363
- },
364
- };
365
- adapter['uploader'].getAttachmentsFromArtifactId = jest
366
- .fn()
367
- .mockResolvedValueOnce({
368
- attachments: [
369
- {
370
- url: 'http://example.com/file1.pdf',
371
- id: 'attachment1',
372
- file_name: 'file1.pdf',
373
- parent_id: 'parent1',
374
- },
375
- {
376
- url: 'http://example.com/file2.pdf',
377
- id: 'attachment2',
378
- file_name: 'file2.pdf',
379
- parent_id: 'parent2',
380
- },
381
- {
382
- url: 'http://example.com/file3.pdf',
383
- id: 'attachment3',
384
- file_name: 'file3.pdf',
385
- parent_id: 'parent3',
386
- },
387
- ],
388
- });
389
- adapter.processAttachment = jest.fn().mockResolvedValue(null);
390
- await adapter.streamAttachments({
391
- stream: mockStream,
392
- });
393
- expect(adapter.state.toDevRev.attachmentsMetadata.artifactIds).toHaveLength(0);
394
- expect(adapter.state.toDevRev.attachmentsMetadata.lastProcessed).toBe(0);
395
- });
396
- });
397
- describe(worker_adapter_1.WorkerAdapter.prototype.emit.name, () => {
398
- let counter;
399
- let mockPostMessage;
400
- beforeEach(() => {
401
- counter = { counter: 0 };
402
- // Import the worker_threads module and spy on parentPort.postMessage
403
- const workerThreads = require('node:worker_threads');
404
- mockPostMessage = jest.fn().mockImplementation(() => {
405
- counter.counter += 1;
406
- });
407
- // Spy on the parentPort.postMessage method
408
- if (workerThreads.parentPort) {
409
- jest
410
- .spyOn(workerThreads.parentPort, 'postMessage')
411
- .mockImplementation(mockPostMessage);
412
- }
413
- else {
414
- // If parentPort is null (not in worker context), create a mock
415
- workerThreads.parentPort = {
416
- postMessage: mockPostMessage,
417
- };
418
- }
419
- });
420
- afterEach(() => {
421
- // Restore all mocks
422
- jest.restoreAllMocks();
423
- });
424
- it('should emit only one event when multiple events of same type are sent', async () => {
425
- adapter['adapterState'].postState = jest
426
- .fn()
427
- .mockResolvedValue(undefined);
428
- adapter.uploadAllRepos = jest.fn().mockResolvedValue(undefined);
429
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
430
- reports: [],
431
- processed_files: [],
432
- });
433
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
434
- reports: [],
435
- processed_files: [],
436
- });
437
- expect(counter.counter).toBe(1);
438
- });
439
- it('should emit event when different event type is sent after previous events', async () => {
440
- adapter['adapterState'].postState = jest
441
- .fn()
442
- .mockResolvedValue(undefined);
443
- adapter.uploadAllRepos = jest.fn().mockResolvedValue(undefined);
444
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
445
- reports: [],
446
- processed_files: [],
447
- });
448
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
449
- reports: [],
450
- processed_files: [],
451
- });
452
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
453
- reports: [],
454
- processed_files: [],
455
- });
456
- expect(counter.counter).toBe(1);
457
- });
458
- it('should correctly emit one event even if postState errors', async () => {
459
- adapter['adapterState'].postState = jest
460
- .fn()
461
- .mockRejectedValue(new Error('postState error'));
462
- adapter.uploadAllRepos = jest.fn().mockResolvedValue(undefined);
463
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
464
- reports: [],
465
- processed_files: [],
466
- });
467
- expect(counter.counter).toBe(1);
468
- });
469
- it('should correctly emit one event even if uploadAllRepos errors', async () => {
470
- adapter['adapterState'].postState = jest
471
- .fn()
472
- .mockResolvedValue(undefined);
473
- adapter.uploadAllRepos = jest
474
- .fn()
475
- .mockRejectedValue(new Error('uploadAllRepos error'));
476
- await adapter.emit(types_1.ExtractorEventType.MetadataExtractionError, {
477
- reports: [],
478
- processed_files: [],
479
- });
480
- expect(counter.counter).toBe(1);
481
- });
482
- });
483
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=repo.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repo.test.d.ts","sourceRoot":"","sources":["../../src/repo/repo.test.ts"],"names":[],"mappings":""}
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const constants_1 = require("../common/constants");
4
- const test_helpers_1 = require("../tests/test-helpers");
5
- const types_1 = require("../types");
6
- const repo_1 = require("./repo");
7
- jest.mock('../tests/test-helpers', () => (Object.assign(Object.assign({}, jest.requireActual('../tests/test-helpers')), { normalizeItem: jest.fn() })));
8
- describe(repo_1.Repo.name, () => {
9
- let repo;
10
- let normalize;
11
- beforeEach(() => {
12
- normalize = jest.fn();
13
- repo = new repo_1.Repo({
14
- event: (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.ExtractionDataStart }),
15
- itemType: 'test_item_type',
16
- normalize,
17
- onUpload: jest.fn(),
18
- });
19
- });
20
- afterEach(() => {
21
- jest.clearAllMocks();
22
- });
23
- it('should normalize and push items when array contains items', async () => {
24
- const items = (0, test_helpers_1.createItems)(10);
25
- await repo.push(items);
26
- expect(normalize).toHaveBeenCalledTimes(10);
27
- const normalizedItems = items.map((item) => (0, test_helpers_1.normalizeItem)(item));
28
- expect(repo.getItems()).toEqual(normalizedItems);
29
- });
30
- it('should not normalize items when normalize function is not provided', async () => {
31
- repo = new repo_1.Repo({
32
- event: (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.ExtractionDataStart }),
33
- itemType: 'test_item_type',
34
- onUpload: jest.fn(),
35
- options: {},
36
- });
37
- const items = (0, test_helpers_1.createItems)(10);
38
- await repo.push(items);
39
- expect(normalize).not.toHaveBeenCalled();
40
- });
41
- it('[edge] should not push items when items array is empty', async () => {
42
- await repo.push([]);
43
- expect(repo.getItems()).toEqual([]);
44
- });
45
- it('should not normalize items when item type is external_domain_metadata', async () => {
46
- repo = new repo_1.Repo({
47
- event: (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.ExtractionDataStart }),
48
- itemType: constants_1.AIRDROP_DEFAULT_ITEM_TYPES.EXTERNAL_DOMAIN_METADATA,
49
- normalize,
50
- onUpload: jest.fn(),
51
- options: {},
52
- });
53
- const items = (0, test_helpers_1.createItems)(10);
54
- await repo.push(items);
55
- expect(normalize).not.toHaveBeenCalled();
56
- });
57
- it('should not normalize items when item type is ssor_attachment', async () => {
58
- repo = new repo_1.Repo({
59
- event: (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.ExtractionDataStart }),
60
- itemType: constants_1.AIRDROP_DEFAULT_ITEM_TYPES.SSOR_ATTACHMENT,
61
- normalize,
62
- onUpload: jest.fn(),
63
- options: {},
64
- });
65
- const items = (0, test_helpers_1.createItems)(10);
66
- await repo.push(items);
67
- expect(normalize).not.toHaveBeenCalled();
68
- });
69
- it('should leave 5 items in the items array after pushing 2005 items with batch size of 2000', async () => {
70
- const items = (0, test_helpers_1.createItems)(2005);
71
- await repo.push(items);
72
- expect(repo.getItems().length).toBe(5);
73
- });
74
- it('should normalize all items when pushing 4005 items with batch size of 2000', async () => {
75
- const items = (0, test_helpers_1.createItems)(4005);
76
- await repo.push(items);
77
- expect(normalize).toHaveBeenCalledTimes(4005);
78
- });
79
- it('should upload 2 batches when pushing 4005 items with batch size of 2000', async () => {
80
- const uploadSpy = jest.spyOn(repo, 'upload');
81
- const items = (0, test_helpers_1.createItems)(4005);
82
- await repo.push(items);
83
- expect(uploadSpy).toHaveBeenCalledTimes(2);
84
- uploadSpy.mockRestore();
85
- });
86
- it('should leave 5 items in array after pushing 4005 items with batch size of 2000', async () => {
87
- const items = (0, test_helpers_1.createItems)(4005);
88
- await repo.push(items);
89
- expect(repo.getItems().length).toBe(5);
90
- });
91
- describe('should take batch size into account', () => {
92
- beforeEach(() => {
93
- repo = new repo_1.Repo({
94
- event: (0, test_helpers_1.createEvent)({ eventType: types_1.EventType.ExtractionDataStart }),
95
- itemType: 'test_item_type',
96
- normalize,
97
- onUpload: jest.fn(),
98
- options: {
99
- batchSize: 50,
100
- },
101
- });
102
- });
103
- it('should empty the items array after pushing 50 items with batch size of 50', async () => {
104
- const items = (0, test_helpers_1.createItems)(50);
105
- await repo.push(items);
106
- expect(repo.getItems()).toEqual([]);
107
- });
108
- it('should leave 5 items in the items array after pushing 205 items with batch size of 50', async () => {
109
- const items = (0, test_helpers_1.createItems)(205);
110
- await repo.push(items);
111
- expect(repo.getItems().length).toBe(5);
112
- });
113
- it('should normalize all items when pushing 205 items with batch size of 50', async () => {
114
- const items = (0, test_helpers_1.createItems)(205);
115
- await repo.push(items);
116
- expect(normalize).toHaveBeenCalledTimes(205);
117
- });
118
- it('should upload 4 batches when pushing 205 items with batch size of 50', async () => {
119
- const uploadSpy = jest.spyOn(repo, 'upload');
120
- const items = (0, test_helpers_1.createItems)(205);
121
- await repo.push(items);
122
- expect(uploadSpy).toHaveBeenCalledTimes(4);
123
- uploadSpy.mockRestore();
124
- });
125
- it('should leave 5 items in array after pushing 205 items with batch size of 50', async () => {
126
- const items = (0, test_helpers_1.createItems)(205);
127
- await repo.push(items);
128
- expect(repo.getItems().length).toBe(5);
129
- });
130
- });
131
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=state.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.test.d.ts","sourceRoot":"","sources":["../../src/state/state.test.ts"],"names":[],"mappings":""}