@devrev/airsync-sdk 2.0.0-beta.1 → 2.0.0-beta.11

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 (229) hide show
  1. package/README.md +7 -21
  2. package/dist/attachments-streaming/attachments-streaming-pool.d.ts +6 -7
  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 +69 -61
  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/client.d.ts +4 -0
  14. package/dist/http/client.d.ts.map +1 -0
  15. package/dist/http/client.js +80 -0
  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 +120 -82
  51. package/dist/multithreading/spawn/spawn.d.ts +10 -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 +59 -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 +146 -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 +31 -12
  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 +40 -162
  106. package/dist/types/external-domain-metadata.d.ts.map +1 -1
  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 +751 -0
  126. package/package.json +35 -22
  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 -321
  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 -208
  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 +0 -3
  161. package/dist/http/axios-client-internal.d.ts.map +0 -1
  162. package/dist/http/axios-client-internal.js +0 -66
  163. package/dist/http/axios-client-internal.test.d.ts +0 -2
  164. package/dist/http/axios-client-internal.test.d.ts.map +0 -1
  165. package/dist/http/axios-client-internal.test.js +0 -154
  166. package/dist/http/axios-client.d.ts +0 -27
  167. package/dist/http/axios-client.d.ts.map +0 -1
  168. package/dist/http/axios-client.js +0 -57
  169. package/dist/http/constants.d.ts +0 -4
  170. package/dist/http/constants.d.ts.map +0 -1
  171. package/dist/http/constants.js +0 -6
  172. package/dist/http/index.d.ts +0 -3
  173. package/dist/http/index.d.ts.map +0 -1
  174. package/dist/http/index.js +0 -18
  175. package/dist/http/types.d.ts +0 -17
  176. package/dist/http/types.d.ts.map +0 -1
  177. package/dist/http/types.js +0 -2
  178. package/dist/logger/logger.constants.d.ts +0 -6
  179. package/dist/logger/logger.constants.d.ts.map +0 -1
  180. package/dist/logger/logger.constants.js +0 -13
  181. package/dist/logger/logger.context.d.ts +0 -58
  182. package/dist/logger/logger.context.d.ts.map +0 -1
  183. package/dist/logger/logger.context.js +0 -86
  184. package/dist/logger/logger.test.d.ts +0 -2
  185. package/dist/logger/logger.test.d.ts.map +0 -1
  186. package/dist/logger/logger.test.js +0 -490
  187. package/dist/mappers/mappers.interface.d.ts +0 -294
  188. package/dist/mappers/mappers.interface.d.ts.map +0 -1
  189. package/dist/mappers/mappers.test.d.ts +0 -2
  190. package/dist/mappers/mappers.test.d.ts.map +0 -1
  191. package/dist/mappers/mappers.test.js +0 -107
  192. package/dist/multithreading/create-worker.test.d.ts +0 -2
  193. package/dist/multithreading/create-worker.test.d.ts.map +0 -1
  194. package/dist/multithreading/create-worker.test.js +0 -89
  195. package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
  196. package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
  197. package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
  198. package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +0 -2
  199. package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +0 -1
  200. package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +0 -127
  201. package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -91
  202. package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
  203. package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +0 -22
  204. package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +0 -1
  205. package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +0 -2
  206. package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +0 -1
  207. package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +0 -514
  208. package/dist/multithreading/worker-adapter/worker-adapter.js +0 -745
  209. package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +0 -2
  210. package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +0 -1
  211. package/dist/multithreading/worker-adapter/worker-adapter.test.js +0 -483
  212. package/dist/repo/repo.test.d.ts +0 -2
  213. package/dist/repo/repo.test.d.ts.map +0 -1
  214. package/dist/repo/repo.test.js +0 -131
  215. package/dist/state/state.test.d.ts +0 -2
  216. package/dist/state/state.test.d.ts.map +0 -1
  217. package/dist/state/state.test.js +0 -224
  218. package/dist/types/extraction.test.d.ts +0 -2
  219. package/dist/types/extraction.test.d.ts.map +0 -1
  220. package/dist/types/extraction.test.js +0 -70
  221. package/dist/types/index.d.ts +0 -10
  222. package/dist/types/index.d.ts.map +0 -1
  223. package/dist/types/index.js +0 -18
  224. package/dist/uploader/uploader.helpers.test.d.ts +0 -2
  225. package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
  226. package/dist/uploader/uploader.helpers.test.js +0 -267
  227. package/dist/uploader/uploader.test.d.ts +0 -2
  228. package/dist/uploader/uploader.test.d.ts.map +0 -1
  229. package/dist/uploader/uploader.test.js +0 -589
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAdapter = void 0;
4
+ const node_worker_threads_1 = require("node:worker_threads");
5
+ const constants_1 = require("../../common/constants");
6
+ const errors_1 = require("../../http/errors");
7
+ const logger_1 = require("../../logger/logger");
8
+ const mappers_1 = require("../../mappers/mappers");
9
+ const errors_2 = require("../../types/errors");
10
+ const workers_1 = require("../../types/workers");
11
+ const uploader_1 = require("../../uploader/uploader");
12
+ const emit_1 = require("../emit");
13
+ const spawn_helpers_1 = require("../spawn/spawn.helpers");
14
+ /**
15
+ * Shared state/behavior for both sync modes; owns the `emit` control-protocol
16
+ * flow as a template method with mode-specific hooks.
17
+ */
18
+ class BaseAdapter {
19
+ /** @internal */
20
+ constructor({ event, adapterState, options, }) {
21
+ this._hasWorkerEmitted = false;
22
+ this._isTimeout = false;
23
+ /** @internal */
24
+ this.timeoutSignal = new Promise((resolve) => {
25
+ this.resolveTimeoutSignal = resolve;
26
+ });
27
+ this.event = event;
28
+ this.options = options;
29
+ this.adapterState = adapterState;
30
+ this.uploader = new uploader_1.Uploader({
31
+ event,
32
+ options,
33
+ });
34
+ this._mappers = new mappers_1.Mappers({ event });
35
+ }
36
+ /** Sync mapper records for this event's sync unit, in both extraction and loading. */
37
+ get mappers() {
38
+ return this._mappers;
39
+ }
40
+ /** @internal */
41
+ get hasWorkerEmitted() {
42
+ return this._hasWorkerEmitted;
43
+ }
44
+ /** Set once the soft timeout fires; the task should wrap up and return. */
45
+ get isTimeout() {
46
+ return this._isTimeout;
47
+ }
48
+ /** @internal */
49
+ set isTimeout(value) {
50
+ this._isTimeout = value;
51
+ if (value) {
52
+ this.resolveTimeoutSignal();
53
+ }
54
+ }
55
+ /** Connector-owned state exposed to snap-in code. */
56
+ get state() {
57
+ return this.adapterState.state;
58
+ }
59
+ set state(value) {
60
+ this.adapterState.state = value;
61
+ }
62
+ /** @internal */
63
+ get sdkState() {
64
+ return this.adapterState.sdkState;
65
+ }
66
+ get extractionScope() {
67
+ return this.adapterState.extractionScope;
68
+ }
69
+ /**
70
+ * Persists connector and SDK state right now. State is saved on every emit
71
+ * anyway; call this only to record intent before an external write that
72
+ * must not be repeated. Throws if the save fails.
73
+ */
74
+ async postState() {
75
+ await this.adapterState.postState();
76
+ }
77
+ /**
78
+ * Uploads connector-owned data (e.g. state too large to keep inline) as a
79
+ * gzipped JSONL artifact. Unlike repo uploads it is not reported in the
80
+ * emitted event. Throws on failure.
81
+ */
82
+ async uploadArtifact(itemType, data) {
83
+ var _a;
84
+ const { artifact, error } = await this.uploader.upload(itemType, data);
85
+ if (error || !artifact) {
86
+ throw new errors_1.AirSyncHttpError(`Failed to upload artifact of type ${itemType}. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : 'No artifact returned.'}`);
87
+ }
88
+ return { id: artifact.id };
89
+ }
90
+ /** Downloads an artifact written by {@link uploadArtifact}. Throws on failure. */
91
+ async downloadArtifact(artifactId) {
92
+ const { response, error } = await this.uploader.getJsonObjectByArtifactId({
93
+ artifactId,
94
+ isGzipped: true,
95
+ });
96
+ if (error !== undefined || response === undefined) {
97
+ throw error instanceof errors_1.AirSyncHttpError
98
+ ? error
99
+ : new errors_1.AirSyncHttpError(`Failed to download artifact ${artifactId}. ${(0, logger_1.serializeError)(error)}`);
100
+ }
101
+ return (Array.isArray(response) ? response : [response]);
102
+ }
103
+ /**
104
+ * @internal
105
+ * Mode-specific worker metadata merged into the emitted event. The library
106
+ * version and state-date range are added centrally in `emit`, so subclasses
107
+ * only contribute their own statistics.
108
+ */
109
+ buildWorkerMetadata(
110
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
+ newEventType) {
112
+ return undefined;
113
+ }
114
+ /** @internal Runs before a failure is reported via `emitError`. */
115
+ beforeErrorEmit() { }
116
+ /**
117
+ * Maps a {@link TaskResult} to the phase-appropriate platform event and emits
118
+ * it exactly once. Invoked by the worker driver, not by connectors —
119
+ * connectors signal outcomes by returning a `TaskResult`, never by emitting.
120
+ *
121
+ * @internal
122
+ */
123
+ async emitFromResult(result) {
124
+ const { eventType, illegal } = (0, spawn_helpers_1.getEventTypeForResult)(this.event.payload.event_type, result.status);
125
+ const data = {};
126
+ if (result.status === 'delay') {
127
+ data.delay = result.delaySeconds;
128
+ }
129
+ else if (result.status === 'error') {
130
+ data.error = result.error;
131
+ }
132
+ else if (illegal) {
133
+ data.error = {
134
+ message: `Worker returned status '${result.status}' for a non-resumable phase (${this.event.payload.event_type}), which is not allowed. Emitting an error event instead.`,
135
+ };
136
+ }
137
+ await this.emit(eventType, data);
138
+ }
139
+ /** @internal */
140
+ async emit(newEventType, data) {
141
+ if (this._hasWorkerEmitted) {
142
+ console.warn(`Trying to emit event with event type: ${newEventType}. Ignoring emit request because it has already been emitted.`);
143
+ return;
144
+ }
145
+ try {
146
+ await this.beforeEmit(newEventType);
147
+ // Save state on every emit, except for start and delete events
148
+ if (!constants_1.STATELESS_EVENT_TYPES.includes(this.event.payload.event_type)) {
149
+ console.log(`Saving state before emitting event with event type: ${newEventType}.`);
150
+ await this.adapterState.postState();
151
+ }
152
+ }
153
+ catch (error) {
154
+ console.error('Error while preparing event for emission.', (0, logger_1.serializeError)(error));
155
+ await this.emitError(error);
156
+ return;
157
+ }
158
+ await this.send(newEventType, data);
159
+ }
160
+ /**
161
+ * Emits the phase error for a failed task or pre-emit step. Skips the
162
+ * pre-emit flush and state save, so a failed batch isn't retried; artifacts
163
+ * uploaded before the failure are still reported.
164
+ *
165
+ * @internal
166
+ */
167
+ async emitError(error) {
168
+ if (this._hasWorkerEmitted) {
169
+ return;
170
+ }
171
+ this.beforeErrorEmit();
172
+ const { eventType } = (0, spawn_helpers_1.getEventTypeForResult)(this.event.payload.event_type, 'error');
173
+ await this.send(eventType, { error: { message: (0, logger_1.serializeError)(error) } });
174
+ }
175
+ async send(newEventType, data) {
176
+ try {
177
+ if (data === null || data === void 0 ? void 0 : data.error) {
178
+ data.error = toWireError(data.error);
179
+ }
180
+ await (0, emit_1.emit)({
181
+ eventType: newEventType,
182
+ event: this.event,
183
+ data: Object.assign(Object.assign({}, data), this.buildEmitPayload(newEventType)),
184
+ worker_metadata: this.buildWorkerMetadata(newEventType),
185
+ });
186
+ const message = {
187
+ subject: workers_1.WorkerMessageSubject.WorkerMessageEmitted,
188
+ payload: { eventType: newEventType },
189
+ };
190
+ this.afterEmit(newEventType);
191
+ node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(message);
192
+ this._hasWorkerEmitted = true;
193
+ }
194
+ catch (error) {
195
+ console.error(`Error while emitting event with event type: ${newEventType}.`, (0, logger_1.serializeError)(error));
196
+ node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
197
+ this._hasWorkerEmitted = true;
198
+ }
199
+ }
200
+ }
201
+ exports.BaseAdapter = BaseAdapter;
202
+ /**
203
+ * The platform matches error codes against the whole message, so a coded
204
+ * error is sent as just the code and its details only go to the logs.
205
+ */
206
+ function toWireError({ message, code }) {
207
+ if (!code) {
208
+ return { message: (0, logger_1.truncateMessage)(message) };
209
+ }
210
+ console.error(`Reporting ${code}: ${message}`);
211
+ return { message: (0, errors_2.formatErrorCode)(code) };
212
+ }
@@ -0,0 +1,49 @@
1
+ import { Repo } from '../../repo/repo';
2
+ import { NormalizedAttachment, RepoInterface } from '../../repo/repo.interfaces';
3
+ import { ExternalSystemAttachmentProcessors, ExternalSystemAttachmentStreamingFunction, ItemTypeCount, ProcessAttachmentReturnType } from '../../types/extraction';
4
+ import { TaskResult } from '../../types/workers';
5
+ import { Artifact } from '../../uploader/uploader.interfaces';
6
+ import { BaseAdapter } from './base-adapter';
7
+ /** Adapter passed to extraction tasks (repos, artifacts, attachment streaming). @public */
8
+ export declare class ExtractionAdapter<ConnectorState> extends BaseAdapter<ConnectorState> {
9
+ private _artifacts;
10
+ private _preExtractionItemCounts?;
11
+ private repos;
12
+ private lastExtractedItemType?;
13
+ private currentEventDataLength;
14
+ /** Defaults to true if the scope is empty or the item type is not listed. */
15
+ shouldExtract(itemType: string): boolean;
16
+ initializeRepos(repos: RepoInterface[]): void;
17
+ private createRepo;
18
+ /**
19
+ * SSOR attachments created outside the attachments phase are held in state
20
+ * and reported with ATTACHMENT_EXTRACTION_DONE instead of the current event.
21
+ */
22
+ private isDeferredRepo;
23
+ private isAttachmentsPhase;
24
+ private getOrCreateSsorRepo;
25
+ getRepo(itemType: string): Repo | undefined;
26
+ /** Artifacts uploaded so far that the next emit will report. */
27
+ get artifacts(): readonly Artifact[];
28
+ private addArtifacts;
29
+ /**
30
+ * Per-record-type counts for sync-duration estimation. Set during the
31
+ * metadata phase; the SDK attaches them to the metadata-done event.
32
+ */
33
+ get preExtractionItemCounts(): ItemTypeCount[] | undefined;
34
+ set preExtractionItemCounts(counts: ItemTypeCount[] | undefined);
35
+ private toRfc3339Timestamp;
36
+ private uploadAllRepos;
37
+ /**
38
+ * Streams one attachment into DevRev. Usable in any extraction phase; SSOR
39
+ * records created outside the attachments phase are reported with
40
+ * ATTACHMENT_EXTRACTION_DONE.
41
+ */
42
+ processAttachment(attachment: NormalizedAttachment, stream: ExternalSystemAttachmentStreamingFunction): Promise<ProcessAttachmentReturnType>;
43
+ streamAttachments<NewBatch>({ stream, processors, batchSize, }: {
44
+ stream: ExternalSystemAttachmentStreamingFunction;
45
+ processors?: ExternalSystemAttachmentProcessors<ConnectorState, NormalizedAttachment[], NewBatch>;
46
+ batchSize?: number;
47
+ }): Promise<TaskResult>;
48
+ }
49
+ //# sourceMappingURL=extraction-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extraction-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/extraction-adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAIL,kCAAkC,EAClC,yCAAyC,EAEzC,aAAa,EACb,2BAA2B,EAE5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAkB,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,2FAA2F;AAC3F,qBAAa,iBAAiB,CAC5B,cAAc,CACd,SAAQ,WAAW,CAAC,cAAc,CAAC;IACnC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,wBAAwB,CAAC,CAAkB;IACnD,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,qBAAqB,CAAC,CAAS;IACvC,OAAO,CAAC,sBAAsB,CAAa;IAY3C,6EAA6E;IAC7E,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAOxC,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE;IAatC,OAAO,CAAC,UAAU;IAoDlB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAW3C,gEAAgE;IAChE,IAAI,SAAS,IAAI,SAAS,QAAQ,EAAE,CAEnC;IAED,OAAO,CAAC,YAAY;IAMpB;;;OAGG;IACH,IAAI,uBAAuB,IAAI,aAAa,EAAE,GAAG,SAAS,CAEzD;IAED,IAAI,uBAAuB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,SAAS,EAE9D;IA6HD,OAAO,CAAC,kBAAkB;YAaZ,cAAc;IAmB5B;;;;OAIG;IACG,iBAAiB,CACrB,UAAU,EAAE,oBAAoB,EAChC,MAAM,EAAE,yCAAyC,GAChD,OAAO,CAAC,2BAA2B,CAAC;IAwGjC,iBAAiB,CAAC,QAAQ,EAAE,EAChC,MAAM,EACN,UAAU,EACV,SAAa,GACd,EAAE;QACD,MAAM,EAAE,yCAAyC,CAAC;QAClD,UAAU,CAAC,EAAE,kCAAkC,CAC7C,cAAc,EACd,oBAAoB,EAAE,EACtB,QAAQ,CACT,CAAC;QACF,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,UAAU,CAAC;CAsHxB"}
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtractionAdapter = void 0;
4
+ const attachments_streaming_pool_1 = require("../../attachments-streaming/attachments-streaming-pool");
5
+ const constants_1 = require("../../common/constants");
6
+ const logger_1 = require("../../logger/logger");
7
+ const repo_1 = require("../../repo/repo");
8
+ const extraction_1 = require("../../types/extraction");
9
+ const uploader_helpers_1 = require("../../uploader/uploader.helpers");
10
+ const base_adapter_1 = require("./base-adapter");
11
+ /** Adapter passed to extraction tasks (repos, artifacts, attachment streaming). @public */
12
+ class ExtractionAdapter extends base_adapter_1.BaseAdapter {
13
+ /** @internal */
14
+ constructor(params) {
15
+ super(params);
16
+ this.repos = [];
17
+ this.currentEventDataLength = 0;
18
+ this._artifacts = [];
19
+ }
20
+ /** Defaults to true if the scope is empty or the item type is not listed. */
21
+ shouldExtract(itemType) {
22
+ const scope = this.extractionScope;
23
+ if (Object.keys(scope).length === 0)
24
+ return true;
25
+ if (!(itemType in scope))
26
+ return true;
27
+ return scope[itemType].extract;
28
+ }
29
+ initializeRepos(repos) {
30
+ const existingSsorRepo = this.repos.find((repo) => repo.itemType === constants_1.SSOR_ATTACHMENT);
31
+ this.repos = repos.map((repo) => this.createRepo(repo));
32
+ if (existingSsorRepo &&
33
+ !this.repos.some((repo) => repo.itemType === constants_1.SSOR_ATTACHMENT)) {
34
+ this.repos.push(existingSsorRepo);
35
+ }
36
+ }
37
+ createRepo(repo) {
38
+ const shouldNormalize = repo.itemType !== constants_1.AirSyncDefaultItemTypes.EXTERNAL_DOMAIN_METADATA &&
39
+ repo.itemType !== constants_1.SSOR_ATTACHMENT;
40
+ const isDeferred = this.isDeferredRepo(repo.itemType);
41
+ return new repo_1.Repo(Object.assign(Object.assign({ event: this.event, itemType: repo.itemType }, (shouldNormalize && { normalize: repo.normalize })), { skipConfirmation: repo.itemType === constants_1.AirSyncDefaultItemTypes.EXTERNAL_SYNC_UNITS, onUpload: (artifact) => {
42
+ var _a, _b;
43
+ if (isDeferred) {
44
+ const toDevRev = this.adapterState.sdkState.toDevRev;
45
+ if (toDevRev) {
46
+ (_a = toDevRev.deferredSsorArtifacts) !== null && _a !== void 0 ? _a : (toDevRev.deferredSsorArtifacts = []);
47
+ toDevRev.deferredSsorArtifacts.push(artifact);
48
+ }
49
+ return;
50
+ }
51
+ this.lastExtractedItemType = repo.itemType;
52
+ // Artifact ids are kept in state for later attachment streaming
53
+ if (repo.itemType === constants_1.AirSyncDefaultItemTypes.ATTACHMENTS) {
54
+ (_b = this.adapterState.sdkState.toDevRev) === null || _b === void 0 ? void 0 : _b.attachmentsMetadata.artifactIds.push(artifact.id);
55
+ }
56
+ // Track size of artifact objects that go in the SQS message; flip
57
+ // isTimeout once the threshold is exceeded to force an early emit.
58
+ this.currentEventDataLength += Buffer.byteLength(JSON.stringify(artifact), 'utf8');
59
+ if (this.currentEventDataLength > constants_1.EVENT_SIZE_THRESHOLD_BYTES &&
60
+ !this.isTimeout) {
61
+ this.isTimeout = true;
62
+ }
63
+ }, options: Object.assign(Object.assign({}, this.options), repo.overriddenOptions) }));
64
+ }
65
+ /**
66
+ * SSOR attachments created outside the attachments phase are held in state
67
+ * and reported with ATTACHMENT_EXTRACTION_DONE instead of the current event.
68
+ */
69
+ isDeferredRepo(itemType) {
70
+ return itemType === constants_1.SSOR_ATTACHMENT && !this.isAttachmentsPhase();
71
+ }
72
+ isAttachmentsPhase() {
73
+ const eventType = this.event.payload.event_type;
74
+ return (eventType === extraction_1.EventType.StartExtractingAttachments ||
75
+ eventType === extraction_1.EventType.ContinueExtractingAttachments);
76
+ }
77
+ getOrCreateSsorRepo() {
78
+ let repo = this.repos.find((repo) => repo.itemType === constants_1.SSOR_ATTACHMENT);
79
+ if (!repo) {
80
+ repo = this.createRepo({ itemType: constants_1.SSOR_ATTACHMENT });
81
+ this.repos.push(repo);
82
+ }
83
+ return repo;
84
+ }
85
+ getRepo(itemType) {
86
+ const repo = this.repos.find((repo) => repo.itemType === itemType);
87
+ if (!repo) {
88
+ console.error(`Repo for item type ${itemType} not found.`);
89
+ return;
90
+ }
91
+ return repo;
92
+ }
93
+ /** Artifacts uploaded so far that the next emit will report. */
94
+ get artifacts() {
95
+ return this._artifacts;
96
+ }
97
+ addArtifacts(artifacts) {
98
+ this._artifacts = this._artifacts
99
+ .concat(artifacts)
100
+ .filter((value, index, self) => self.indexOf(value) === index);
101
+ }
102
+ /**
103
+ * Per-record-type counts for sync-duration estimation. Set during the
104
+ * metadata phase; the SDK attaches them to the metadata-done event.
105
+ */
106
+ get preExtractionItemCounts() {
107
+ return this._preExtractionItemCounts;
108
+ }
109
+ set preExtractionItemCounts(counts) {
110
+ this._preExtractionItemCounts = counts;
111
+ }
112
+ /** @internal */
113
+ async beforeEmit(newEventType) {
114
+ var _a;
115
+ console.log(`Uploading all repos before emitting event with event type: ${newEventType}.`);
116
+ await this.uploadAllRepos();
117
+ // When the full extraction cycle completes, commit the extraction window
118
+ // boundaries so subsequent incremental syncs can resume from them.
119
+ if (newEventType === extraction_1.ExtractorEventType.AttachmentExtractionDone) {
120
+ const sdkState = this.adapterState.sdkState;
121
+ // Released before the state save so they're never reported twice.
122
+ const toDevRev = sdkState.toDevRev;
123
+ if ((_a = toDevRev === null || toDevRev === void 0 ? void 0 : toDevRev.deferredSsorArtifacts) === null || _a === void 0 ? void 0 : _a.length) {
124
+ this.addArtifacts(toDevRev.deferredSsorArtifacts);
125
+ toDevRev.deferredSsorArtifacts = [];
126
+ }
127
+ console.log(`Overwriting lastSuccessfulSyncStarted with lastSyncStarted (${sdkState.lastSyncStarted}).`);
128
+ sdkState.lastSuccessfulSyncStarted = sdkState.lastSyncStarted;
129
+ sdkState.lastSyncStarted = '';
130
+ sdkState.pendingWorkersOldest = '';
131
+ sdkState.pendingWorkersNewest = '';
132
+ // Expand boundaries: workersOldest keeps the earliest timestamp seen,
133
+ // workersNewest the latest.
134
+ const extractionStart = this.event.payload.event_context.extract_from;
135
+ const extractionEnd = this.event.payload.event_context.extract_to;
136
+ if (extractionStart &&
137
+ (!sdkState.workersOldest || extractionStart < sdkState.workersOldest)) {
138
+ console.log(`Updating workersOldest from '${sdkState.workersOldest}' to '${extractionStart}'.`);
139
+ sdkState.workersOldest = extractionStart;
140
+ }
141
+ if (extractionEnd &&
142
+ (!sdkState.workersNewest || extractionEnd > sdkState.workersNewest)) {
143
+ console.log(`Updating workersNewest from '${sdkState.workersNewest}' to '${extractionEnd}'.`);
144
+ sdkState.workersNewest = extractionEnd;
145
+ }
146
+ }
147
+ }
148
+ /** @internal */
149
+ buildEmitPayload(newEventType) {
150
+ const isExtractionEvent = Object.values(extraction_1.ExtractorEventType).includes(newEventType);
151
+ if (!isExtractionEvent) {
152
+ return {};
153
+ }
154
+ const payload = { artifacts: [...this._artifacts] };
155
+ if (newEventType === extraction_1.ExtractorEventType.MetadataExtractionDone &&
156
+ this._preExtractionItemCounts) {
157
+ payload.pre_extraction_item_counts = this._preExtractionItemCounts;
158
+ }
159
+ return payload;
160
+ }
161
+ /**
162
+ * @internal
163
+ * Attaches the last-extracted item type and its created/modified date ranges
164
+ * to data/attachment done/progress events, mirroring the metadata v1 sent.
165
+ */
166
+ buildWorkerMetadata(newEventType) {
167
+ if (newEventType !== extraction_1.ExtractorEventType.DataExtractionDone &&
168
+ newEventType !== extraction_1.ExtractorEventType.DataExtractionProgress &&
169
+ newEventType !== extraction_1.ExtractorEventType.AttachmentExtractionDone &&
170
+ newEventType !== extraction_1.ExtractorEventType.AttachmentExtractionProgress) {
171
+ return undefined;
172
+ }
173
+ const repo = this.lastExtractedItemType
174
+ ? this.repos.find((r) => r.itemType === this.lastExtractedItemType)
175
+ : undefined;
176
+ if (!repo) {
177
+ return undefined;
178
+ }
179
+ return {
180
+ item_type: repo.itemType,
181
+ newest_created_date: this.toRfc3339Timestamp(repo.dateRanges.creationDate.newest),
182
+ oldest_created_date: this.toRfc3339Timestamp(repo.dateRanges.creationDate.oldest),
183
+ newest_modified_date: this.toRfc3339Timestamp(repo.dateRanges.modifiedDate.newest),
184
+ oldest_modified_date: this.toRfc3339Timestamp(repo.dateRanges.modifiedDate.oldest),
185
+ };
186
+ }
187
+ toRfc3339Timestamp(ms) {
188
+ if (ms === undefined || !Number.isFinite(ms)) {
189
+ return undefined;
190
+ }
191
+ return new Date(ms).toISOString();
192
+ }
193
+ /** @internal */
194
+ afterEmit() {
195
+ this._artifacts = [];
196
+ }
197
+ async uploadAllRepos() {
198
+ for (const repo of this.repos) {
199
+ await repo.upload();
200
+ if (!this.isDeferredRepo(repo.itemType)) {
201
+ this.addArtifacts(repo.uploadedArtifacts);
202
+ }
203
+ }
204
+ }
205
+ /** @internal */
206
+ beforeErrorEmit() {
207
+ // Report artifacts that uploaded before the failure so they aren't orphaned.
208
+ for (const repo of this.repos) {
209
+ if (!this.isDeferredRepo(repo.itemType)) {
210
+ this.addArtifacts(repo.uploadedArtifacts);
211
+ }
212
+ }
213
+ }
214
+ /**
215
+ * Streams one attachment into DevRev. Usable in any extraction phase; SSOR
216
+ * records created outside the attachments phase are reported with
217
+ * ATTACHMENT_EXTRACTION_DONE.
218
+ */
219
+ async processAttachment(attachment, stream) {
220
+ var _a, _b;
221
+ const response = await stream({
222
+ item: attachment,
223
+ event: this.event,
224
+ });
225
+ if (response.status !== 'success') {
226
+ return response;
227
+ }
228
+ const { httpStream } = response;
229
+ const fileType = attachment.content_type ||
230
+ ((_a = httpStream.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) ||
231
+ 'application/octet-stream';
232
+ const contentLength = (_b = httpStream.headers['content-length']) === null || _b === void 0 ? void 0 : _b.toString();
233
+ const fileSize = contentLength ? parseInt(contentLength) : undefined;
234
+ const { error: artifactUrlError, response: artifactUrlResponse } = await this.uploader.getArtifactUploadUrl(attachment.file_name, fileType, fileSize);
235
+ if (artifactUrlError) {
236
+ (0, uploader_helpers_1.destroyHttpStream)(httpStream);
237
+ return {
238
+ status: 'error',
239
+ error: {
240
+ message: `Error while preparing artifact for attachment ID ${attachment.id}. Skipping attachment. ${(0, logger_1.serializeError)(artifactUrlError)}`,
241
+ fileSize,
242
+ },
243
+ };
244
+ }
245
+ const { error: uploadedArtifactError } = await this.uploader.streamArtifact(artifactUrlResponse, httpStream);
246
+ if (uploadedArtifactError) {
247
+ (0, uploader_helpers_1.destroyHttpStream)(httpStream);
248
+ return {
249
+ status: 'error',
250
+ error: {
251
+ message: `Error while streaming to artifact for attachment ID ${attachment.id}. Skipping attachment. ` +
252
+ (0, logger_1.serializeError)(uploadedArtifactError),
253
+ fileSize,
254
+ },
255
+ };
256
+ }
257
+ const { error: confirmArtifactUploadError } = await this.uploader.confirmArtifactUpload(artifactUrlResponse.artifact_id);
258
+ if (confirmArtifactUploadError) {
259
+ return {
260
+ status: 'error',
261
+ error: {
262
+ message: `Error while confirming upload for attachment ID ${attachment.id}. ` +
263
+ (0, logger_1.serializeError)(confirmArtifactUploadError),
264
+ fileSize,
265
+ },
266
+ };
267
+ }
268
+ const ssorAttachment = {
269
+ id: {
270
+ devrev: artifactUrlResponse.artifact_id,
271
+ external: attachment.id,
272
+ },
273
+ parent_id: {
274
+ external: attachment.parent_id,
275
+ },
276
+ };
277
+ if (attachment.author_id) {
278
+ ssorAttachment.actor_id = {
279
+ external: attachment.author_id,
280
+ };
281
+ }
282
+ // Set inline flag only if it is explicitly set on the attachment.
283
+ if (attachment.inline === true) {
284
+ ssorAttachment.inline = true;
285
+ }
286
+ else if (attachment.inline === false) {
287
+ ssorAttachment.inline = false;
288
+ }
289
+ if (this.isTimeout) {
290
+ (0, uploader_helpers_1.destroyHttpStream)(httpStream);
291
+ return { status: 'success' };
292
+ }
293
+ await this.getOrCreateSsorRepo().push([ssorAttachment]);
294
+ return { status: 'success' };
295
+ }
296
+ async streamAttachments({ stream, processors, batchSize = 1, }) {
297
+ var _a, _b;
298
+ if (batchSize <= 0) {
299
+ console.warn(`The specified batch size (${batchSize}) is invalid. Using 1 instead.`);
300
+ batchSize = 1;
301
+ }
302
+ if (batchSize > 50) {
303
+ console.warn(`The specified batch size (${batchSize}) is too large. Using 50 instead.`);
304
+ batchSize = 50;
305
+ }
306
+ this.initializeRepos([{ itemType: constants_1.SSOR_ATTACHMENT }]);
307
+ const attachmentsMetadata = (_a = this.adapterState.sdkState.toDevRev) === null || _a === void 0 ? void 0 : _a.attachmentsMetadata;
308
+ if (!((_b = attachmentsMetadata === null || attachmentsMetadata === void 0 ? void 0 : attachmentsMetadata.artifactIds) === null || _b === void 0 ? void 0 : _b.length)) {
309
+ console.log(`No attachments metadata artifact IDs found in state.`);
310
+ return { status: 'success' };
311
+ }
312
+ else {
313
+ console.log(`Found ${attachmentsMetadata.artifactIds.length} attachments metadata artifact IDs in state.`);
314
+ }
315
+ while (attachmentsMetadata.artifactIds.length > 0) {
316
+ const attachmentsMetadataArtifactId = attachmentsMetadata.artifactIds[0];
317
+ console.log(`Started processing attachments for attachments metadata artifact ID: ${attachmentsMetadataArtifactId}.`);
318
+ const { attachments, error } = await this.uploader.getAttachmentsFromArtifactId({
319
+ artifact: attachmentsMetadataArtifactId,
320
+ });
321
+ if (error) {
322
+ console.error(`Failed to get attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
323
+ return { status: 'error', error };
324
+ }
325
+ if (!attachments || attachments.length === 0) {
326
+ console.warn(`No attachments found for artifact ID: ${attachmentsMetadataArtifactId}.`);
327
+ attachmentsMetadata.artifactIds.shift();
328
+ attachmentsMetadata.lastProcessed = 0;
329
+ continue;
330
+ }
331
+ console.log(`Found ${attachments.length} attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
332
+ let response;
333
+ if (processors) {
334
+ console.log(`Using custom processors for attachments.`);
335
+ const reducer = processors.reducer;
336
+ const iterator = processors.iterator;
337
+ const reducedAttachments = reducer({
338
+ attachments,
339
+ adapter: this,
340
+ batchSize,
341
+ });
342
+ response = await iterator({
343
+ reducedAttachments,
344
+ adapter: this,
345
+ stream,
346
+ });
347
+ }
348
+ else {
349
+ console.log(`Using attachments streaming pool for attachments streaming.`);
350
+ const attachmentsPool = new attachments_streaming_pool_1.AttachmentsStreamingPool({
351
+ adapter: this,
352
+ attachments,
353
+ batchSize,
354
+ stream,
355
+ });
356
+ response = await attachmentsPool.streamAll();
357
+ }
358
+ if (response.status !== 'success') {
359
+ return response;
360
+ }
361
+ if (this.isTimeout) {
362
+ console.log(`Timeout detected after processing attachments for artifact ID: ${attachmentsMetadataArtifactId}. Returning progress to allow continuation.`);
363
+ return { status: 'progress' };
364
+ }
365
+ console.log(`Finished processing all attachments for artifact ID: ${attachmentsMetadataArtifactId}.`);
366
+ attachmentsMetadata.artifactIds.shift();
367
+ attachmentsMetadata.lastProcessed = 0;
368
+ if (attachmentsMetadata.lastProcessedAttachmentsIdsList) {
369
+ attachmentsMetadata.lastProcessedAttachmentsIdsList.length = 0;
370
+ }
371
+ }
372
+ return { status: 'success' };
373
+ }
374
+ }
375
+ exports.ExtractionAdapter = ExtractionAdapter;
@@ -0,0 +1,26 @@
1
+ import { ExternalSystemAttachment, ExternalSystemLoadingFunction, ItemTypesToLoadParams, LoaderReport } from '../../types/loading';
2
+ import { TaskResult } from '../../types/workers';
3
+ import { BaseAdapter } from './base-adapter';
4
+ /** Adapter passed to loading tasks (item/attachment loading, loader reports). @public */
5
+ export declare class LoadingAdapter<ConnectorState> extends BaseAdapter<ConnectorState> {
6
+ private loaderReports;
7
+ private _processedFiles;
8
+ get reports(): LoaderReport[];
9
+ get processedFiles(): string[];
10
+ loadItemTypes({ itemTypesToLoad, }: ItemTypesToLoadParams): Promise<TaskResult>;
11
+ loadAttachments({ create, }: {
12
+ create: ExternalSystemLoadingFunction<ExternalSystemAttachment>;
13
+ }): Promise<TaskResult>;
14
+ /**
15
+ * Walks the transformer files in `fromDevRev.filesToLoad`, resuming from
16
+ * each file's `lineToProcess`. `getLoader` returns undefined when a file has
17
+ * an item type the connector can't load, which fails the phase.
18
+ */
19
+ private loadFiles;
20
+ private getLoaderBatches;
21
+ private loadItem;
22
+ /** Maps a non-success connector response to a delay or a failed report. */
23
+ private toFailedLoad;
24
+ private loadAttachment;
25
+ }
26
+ //# sourceMappingURL=loading-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loading-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/adapters/loading-adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,wBAAwB,EAGxB,6BAA6B,EAE7B,qBAAqB,EAGrB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAM7C,yFAAyF;AACzF,qBAAa,cAAc,CACzB,cAAc,CACd,SAAQ,WAAW,CAAC,cAAc,CAAC;IACnC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,eAAe,CAAW;IAalC,IAAI,OAAO,IAAI,YAAY,EAAE,CAE5B;IAED,IAAI,cAAc,IAAI,MAAM,EAAE,CAE7B;IA2BK,aAAa,CAAC,EAClB,eAAe,GAChB,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC;IA8BxC,eAAe,CAAC,EACpB,MAAM,GACP,EAAE;QACD,MAAM,EAAE,6BAA6B,CAAC,wBAAwB,CAAC,CAAC;KACjE,GAAG,OAAO,CAAC,UAAU,CAAC;IAavB;;;;OAIG;YACW,SAAS;YAiFT,gBAAgB;YAuBhB,QAAQ;IA+HtB,2EAA2E;IAC3E,OAAO,CAAC,YAAY;YAwBN,cAAc;CA2C7B"}