@jsforce/jsforce-node 3.0.0-next.1 → 3.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,324 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from 'events';
4
+ import { Readable } from 'stream';
5
+ import Connection from '../connection';
6
+ import { Parsable } from '../record-stream';
7
+ import { Record, Schema } from '../types';
8
+ export type IngestOperation = 'insert' | 'update' | 'upsert' | 'delete' | 'hardDelete';
9
+ type BaseJobInfo = {
10
+ id: string;
11
+ object: string;
12
+ createdById: string;
13
+ createdDate: string;
14
+ systemModstamp: string;
15
+ apiVersion: number;
16
+ lineEnding: 'LF' | 'CRLF';
17
+ columnDelimiter: 'BACKQUOTE' | 'CARET' | 'COMMA' | 'PIPE' | 'SEMICOLON' | 'TAB';
18
+ concurrencyMode: 'Parallel';
19
+ contentType: 'CSV';
20
+ numberRecordsProcessed: number;
21
+ retries: number;
22
+ totalProcessingTime: number;
23
+ };
24
+ export type QueryJobInfoV2 = BaseJobInfo & {
25
+ operation: 'query' | 'queryAll';
26
+ state: 'UploadComplete' | 'InProgress' | 'Aborted' | 'JobComplete' | 'Failed';
27
+ jobType: 'V2Query';
28
+ isPkChunkingSupported: boolean;
29
+ };
30
+ export type JobInfoV2 = BaseJobInfo & {
31
+ apexProcessingTime: number;
32
+ apiActiveProcessingTime: number;
33
+ assignmentRuleId?: string;
34
+ contentUrl: string;
35
+ errorMessage?: string;
36
+ externalIdFieldName?: string;
37
+ jobType: 'BigObjectIngest' | 'Classic' | 'V2Ingest';
38
+ operation: IngestOperation;
39
+ state: 'Open' | 'UploadComplete' | 'InProgress' | 'JobComplete' | 'Aborted' | 'Failed';
40
+ numberRecordsFailed: number;
41
+ };
42
+ export type IngestJobV2SuccessfulResults<S extends Schema> = Array<{
43
+ sf__Created: 'true' | 'false';
44
+ sf__Id: string;
45
+ } & S>;
46
+ export type IngestJobV2FailedResults<S extends Schema> = Array<{
47
+ sf__Error: string;
48
+ sf__Id: string;
49
+ } & S>;
50
+ export type IngestJobV2UnprocessedRecords<S extends Schema> = Array<S> | string;
51
+ export type IngestJobV2Results<S extends Schema> = {
52
+ successfulResults: IngestJobV2SuccessfulResults<S>;
53
+ failedResults: IngestJobV2FailedResults<S>;
54
+ unprocessedRecords: IngestJobV2UnprocessedRecords<S>;
55
+ };
56
+ type NewIngestJobOptions = Required<Pick<JobInfoV2, 'object' | 'operation'>> & Partial<Pick<JobInfoV2, 'assignmentRuleId' | 'columnDelimiter' | 'externalIdFieldName' | 'lineEnding' | 'contentType'>>;
57
+ type NewQueryJobOptions = {
58
+ query: string;
59
+ operation: QueryJobInfoV2['operation'];
60
+ } & Partial<Pick<QueryJobInfoV2, 'columnDelimiter' | 'lineEnding'>>;
61
+ type CreateIngestJobV2Options = {
62
+ bodyParams: NewIngestJobOptions;
63
+ pollingOptions: BulkV2PollingOptions;
64
+ };
65
+ type ExistingIngestJobOptions = {
66
+ id: string;
67
+ pollingOptions: BulkV2PollingOptions;
68
+ };
69
+ type CreateQueryJobV2Options = {
70
+ bodyParams: NewQueryJobOptions;
71
+ pollingOptions: BulkV2PollingOptions;
72
+ };
73
+ type ExistingQueryJobV2Options = {
74
+ id: string;
75
+ pollingOptions: BulkV2PollingOptions;
76
+ };
77
+ type BulkV2PollingOptions = {
78
+ pollInterval: number;
79
+ pollTimeout: number;
80
+ };
81
+ export declare class BulkV2<S extends Schema> {
82
+ private connection;
83
+ private logger;
84
+ /**
85
+ * Polling interval in milliseconds
86
+ *
87
+ * Default: 1000 (1 second)
88
+ */
89
+ pollInterval: number;
90
+ /**
91
+ * Polling timeout in milliseconds
92
+ *
93
+ * Default: 30000 (30 seconds)
94
+ */
95
+ pollTimeout: number;
96
+ constructor(connection: Connection<S>);
97
+ /**
98
+ * Create an instance of an ingest job object.
99
+ *
100
+ * @params {NewIngestJobOptions} options object
101
+ * @returns {IngestJobV2} An ingest job instance
102
+ * @example
103
+ * // Upsert records to the Account object.
104
+ *
105
+ * const job = connection.bulk2.createJob({
106
+ * operation: 'insert'
107
+ * object: 'Account',
108
+ * });
109
+ *
110
+ * // create the job in the org
111
+ * await job.open()
112
+ *
113
+ * // upload data
114
+ * await job.uploadData(csvFile)
115
+ *
116
+ * // finished uploading data, mark it as ready for processing
117
+ * await job.close()
118
+ */
119
+ createJob(options: NewIngestJobOptions): IngestJobV2<S>;
120
+ /**
121
+ * Get an ingest or query job instance specified by a given job ID
122
+ *
123
+ * @param options Options object with a job ID
124
+ * @returns IngestJobV2 An ingest job
125
+ */
126
+ job(type: 'query', options: Pick<ExistingQueryJobV2Options, 'id'>): QueryJobV2<S>;
127
+ job(type: 'ingest', options: Pick<ExistingIngestJobOptions, 'id'>): IngestJobV2<S>;
128
+ /**
129
+ * Create, upload, and start bulkload job
130
+ */
131
+ loadAndWaitForResults(options: NewIngestJobOptions & Partial<BulkV2PollingOptions> & {
132
+ input: Record[] | Readable | string;
133
+ }): Promise<IngestJobV2Results<S>>;
134
+ /**
135
+ * Execute bulk query and get a record stream.
136
+ *
137
+ * Default timeout: 10000ms
138
+ *
139
+ * @param soql SOQL query
140
+ * @param BulkV2PollingOptions options object
141
+ *
142
+ * @returns {RecordStream} - Record stream, convertible to a CSV data stream
143
+ */
144
+ query(soql: string, options?: Partial<BulkV2PollingOptions> & {
145
+ scanAll?: boolean;
146
+ columnDelimiter?: QueryJobInfoV2['columnDelimiter'];
147
+ lineEnding?: QueryJobInfoV2['lineEnding'];
148
+ }): Promise<Parsable<Record>>;
149
+ }
150
+ export declare class QueryJobV2<S extends Schema> extends EventEmitter {
151
+ private readonly connection;
152
+ private readonly logger;
153
+ private readonly _id?;
154
+ private readonly bodyParams?;
155
+ private readonly pollingOptions;
156
+ private error;
157
+ private jobInfo?;
158
+ private locator?;
159
+ constructor(conn: Connection<S>, options: ExistingQueryJobV2Options);
160
+ constructor(conn: Connection<S>, options: CreateQueryJobV2Options);
161
+ /**
162
+ * Get the query job ID.
163
+ *
164
+ * @returns {string} query job Id.
165
+ */
166
+ get id(): string;
167
+ /**
168
+ * Get the query job info.
169
+ *
170
+ * @returns {Promise<QueryJobInfoV2>} query job information.
171
+ */
172
+ getInfo(): QueryJobInfoV2;
173
+ /**
174
+ * Creates a query job
175
+ *
176
+ * @returns {Promise<QueryJobInfoV2>} job information.
177
+ */
178
+ open(): Promise<QueryJobInfoV2>;
179
+ /**
180
+ * Abort the job
181
+ *
182
+ * The 'aborted' event is emitted when the job successfully aborts.
183
+ * @returns {Promise<QueryJobInfoV2>} job information.
184
+ */
185
+ abort(): Promise<QueryJobInfoV2>;
186
+ /**
187
+ * Poll for the state of the processing for the job.
188
+ *
189
+ * @param interval Polling interval in milliseconds
190
+ * @param timeout Polling timeout in milliseconds
191
+ * @returns {Promise<Record[]>} A promise that resolves when the job finished being processed.
192
+ */
193
+ poll(interval?: number, timeout?: number): Promise<void>;
194
+ /**
195
+ * Check the latest job status
196
+ *
197
+ * @returns {Promise<QueryJobInfoV2>} job information.
198
+ */
199
+ check(): Promise<QueryJobInfoV2>;
200
+ /**
201
+ * Get the results for a query job as a record stream
202
+ *
203
+ * This method assumes the job finished being processed
204
+ * @returns {RecordStream} - Record stream, convertible to a CSV data stream
205
+ */
206
+ result(): Promise<Parsable<Record>>;
207
+ /**
208
+ * Deletes a query job.
209
+ */
210
+ delete(): Promise<void>;
211
+ private createQueryRequest;
212
+ }
213
+ /**
214
+ * Class for Bulk API V2 Ingest Job
215
+ */
216
+ export declare class IngestJobV2<S extends Schema> extends EventEmitter {
217
+ private readonly connection;
218
+ private readonly logger;
219
+ private readonly _id?;
220
+ private readonly bodyParams?;
221
+ private readonly jobData;
222
+ private pollingOptions;
223
+ private bulkJobSuccessfulResults?;
224
+ private bulkJobFailedResults?;
225
+ private bulkJobUnprocessedRecords?;
226
+ private error;
227
+ private jobInfo?;
228
+ /**
229
+ *
230
+ */
231
+ constructor(conn: Connection<S>, options: ExistingIngestJobOptions);
232
+ constructor(conn: Connection<S>, options: CreateIngestJobV2Options);
233
+ /**
234
+ * Get the query job ID.
235
+ *
236
+ * @returns {string} query job Id.
237
+ */
238
+ get id(): string;
239
+ /**
240
+ * Get the query job info.
241
+ *
242
+ * @returns {Promise<QueryJobInfoV2>} ingest job information.
243
+ */
244
+ getInfo(): JobInfoV2;
245
+ /**
246
+ * Create a job representing a bulk operation in the org
247
+ *
248
+ * @returns {Promise<QueryJobInfoV2>} job information.
249
+ */
250
+ open(): Promise<Partial<JobInfoV2>>;
251
+ /** Upload data for a job in CSV format
252
+ *
253
+ * @param input CSV as a string, or array of records or readable stream
254
+ */
255
+ uploadData(input: string | Record[] | Readable): Promise<void>;
256
+ /**
257
+ * Close opened job
258
+ *
259
+ * This method will notify the org that the upload of job data is complete and is ready for processing.
260
+ */
261
+ close(): Promise<void>;
262
+ /**
263
+ * Set the status to abort
264
+ */
265
+ abort(): Promise<void>;
266
+ /**
267
+ * Poll for the state of the processing for the job.
268
+ *
269
+ * This method will only throw after a timeout. To capture a
270
+ * job failure while polling you must set a listener for the
271
+ * `failed` event before calling it:
272
+ *
273
+ * job.on('failed', (err) => console.error(err))
274
+ * await job.poll()
275
+ *
276
+ * @param interval Polling interval in milliseconds
277
+ * @param timeout Polling timeout in milliseconds
278
+ * @returns {Promise<void>} A promise that resolves when the job finishes successfully
279
+ */
280
+ poll(interval?: number, timeout?: number): Promise<void>;
281
+ /**
282
+ * Check the latest batch status in server
283
+ */
284
+ check(): Promise<JobInfoV2>;
285
+ /** Return all record results
286
+ *
287
+ * This method will return successful, failed and unprocessed records
288
+ *
289
+ * @returns Promise<IngestJobV2Results>
290
+ */
291
+ getAllResults(): Promise<IngestJobV2Results<S>>;
292
+ /** Return successful results
293
+ *
294
+ * The order of records returned is not guaranteed to match the ordering of the uploaded data.
295
+ *
296
+ * @returns Promise<IngestJobV2SuccessfulResults>
297
+ */
298
+ getSuccessfulResults(): Promise<IngestJobV2SuccessfulResults<S>>;
299
+ /** Return failed results
300
+ *
301
+ * The order of records in the response is not guaranteed to match the ordering of records in the original job data.
302
+ *
303
+ * @returns Promise<IngestJobV2SuccessfulResults>
304
+ */
305
+ getFailedResults(): Promise<IngestJobV2FailedResults<S>>;
306
+ /** Return unprocessed results
307
+ *
308
+ * The unprocessed records endpoint returns records as a CSV.
309
+ * If the request helper is able to parse it, you get the records
310
+ * as an array of objects.
311
+ * If unable to parse the it (bad CSV), you get the raw response as a string.
312
+ *
313
+ * The order of records in the response is not guaranteed to match the ordering of records in the original job data.
314
+ *
315
+ * @returns Promise<IngestJobV2UnprocessedRecords>
316
+ */
317
+ getUnprocessedRecords(): Promise<IngestJobV2UnprocessedRecords<S>>;
318
+ /**
319
+ * Deletes an ingest job.
320
+ */
321
+ delete(): Promise<void>;
322
+ private createIngestRequest;
323
+ }
324
+ export default BulkV2;