@@ -5,9 +5,8 @@ import type {
55 EntityMetadata ,
66 RelationshipMetadata ,
77 WhoAmIResponse ,
8- BatchRequest ,
98} from './types.js' ;
10- import { esc , parseMultipartResponse } from './dataverse-client.utils.js' ;
9+ import { esc } from './dataverse-client.utils.js' ;
1110
1211const API_VERSION = '9.2' ;
1312
@@ -364,77 +363,4 @@ export class DataverseClient {
364363 ) ;
365364 }
366365
367- // ─── Batch ───────────────────────────────────────────────────────────────
368-
369- async batchExecute ( requests : BatchRequest [ ] , useChangeset = false ) : Promise < unknown [ ] > {
370- const batchId = `batch_${ Date . now ( ) } ` ;
371- let body = '' ;
372-
373- if ( useChangeset ) {
374- const changesetId = `changeset_${ Date . now ( ) + 1 } ` ;
375- const getOps = requests . filter ( r => r . method === 'GET' ) ;
376- const mutatingOps = requests . filter ( r => r . method !== 'GET' ) ;
377-
378- for ( const req of getOps ) {
379- body += `--${ batchId } \n` ;
380- body += `Content-Type: application/http\n` ;
381- body += `Content-Transfer-Encoding: binary\n\n` ;
382- body += `${ req . method } ${ this . authProvider . environmentUrl } /api/data/v${ API_VERSION } /${ req . url } HTTP/1.1\n` ;
383- body += `Accept: application/json\n\n\n` ;
384- }
385-
386- if ( mutatingOps . length > 0 ) {
387- body += `--${ batchId } \n` ;
388- body += `Content-Type: multipart/mixed; boundary=${ changesetId } \n\n` ;
389- let contentIdCounter = 1 ;
390- for ( const op of mutatingOps ) {
391- body += `--${ changesetId } \n` ;
392- body += `Content-Type: application/http\n` ;
393- body += `Content-Transfer-Encoding: binary\n` ;
394- body += `Content-ID: ${ op . contentId ?? contentIdCounter ++ } \n\n` ;
395- body += `${ op . method } ${ this . authProvider . environmentUrl } /api/data/v${ API_VERSION } /${ op . url } HTTP/1.1\n` ;
396- body += `Content-Type: application/json\n\n` ;
397- if ( op . body ) body += JSON . stringify ( op . body ) ;
398- body += '\n\n' ;
399- }
400- body += `--${ changesetId } --\n` ;
401- }
402- } else {
403- requests . forEach ( ( req ) => {
404- body += `--${ batchId } \n` ;
405- body += `Content-Type: application/http\n` ;
406- body += `Content-Transfer-Encoding: binary\n\n` ;
407- body += `${ req . method } ${ this . authProvider . environmentUrl } /api/data/v${ API_VERSION } /${ req . url } HTTP/1.1\n` ;
408- body += `Content-Type: application/json\n\n` ;
409- if ( req . body ) body += JSON . stringify ( req . body ) ;
410- body += '\n' ;
411- } ) ;
412- }
413-
414- body += `--${ batchId } --` ;
415-
416- const response = await this . requestWithRetry ( ( ) =>
417- this . http . post ( '$batch' , body , {
418- headers : { 'Content-Type' : `multipart/mixed;boundary=${ batchId } ` } ,
419- responseType : 'text' ,
420- } )
421- ) ;
422-
423- try {
424- const contentType = ( response . headers [ 'content-type' ] as string | undefined ) ?? '' ;
425- const boundaryMatch = contentType . match ( / b o u n d a r y = (?: " ( [ ^ " ] + ) " | ( [ ^ ; " \s ] + ) ) / ) ;
426- const responseBoundary = boundaryMatch ?. [ 1 ] ?? boundaryMatch ?. [ 2 ] ;
427-
428- if ( ! responseBoundary ) {
429- process . stderr . write ( '[batchExecute] No multipart boundary in response Content-Type; returning raw data.\n' ) ;
430- return [ response . data ] ;
431- }
432-
433- return parseMultipartResponse ( response . data as string , responseBoundary ) ;
434- } catch ( err ) {
435- process . stderr . write ( `[batchExecute] Failed to parse multipart response; returning raw data. ${ String ( err ) } \n` ) ;
436- return [ response . data ] ;
437- }
438- }
439-
440366}
0 commit comments