import { Stream } from "stream" ; import IRequest , { HttpMethod } from "../../table/generated/IRequest" ; import BatchOperation from "./BatchOperation" ; import BatchRequestHeaders from "./BatchRequestHeaders" ; import * as Models from "../../table/generated/artifacts/models" ; import BatchTableUpdateEntityOptionalParams from "../../table/batch/BatchTableUpdateEntityOptionalParams" ; import BatchTableDeleteEntityOptionalParams from "../../table/batch/BatchTableDeleteEntityOptionalParams" ; import IOptionalParams from "../../table/batch/IOptionalParams" ; export default class BatchRequest implements IRequest { public response ? : any ; private headers : BatchRequestHeaders ; private batchOperation : BatchOperation ; public contentID : number | undefined ; public constructor ( batchOperation ) { this . batchOperation = batchOperation ; this . headers = new BatchRequestHeaders ( batchOperation . rawHeaders ) ; this . params = new BatchTableUpdateEntityOptionalParams ( ) ; } public params : IOptionalParams ; public ingestOptionalParams ( params ) { this . params = params ; if ( this . getHeader ( "x-ms-client-request-id" ) !== undefined ) { this . params . requestId = this . getHeader ( "x-ms-client-request-id" ) ; } if ( this . getHeader ( "maxdataserviceversion" ) ?. includes ( "3.0" ) ) { this . params . dataServiceVersion = Models . DataServiceVersion4 . ThreeFullStopZero ; } const body = this . getBody ( ) ; if ( body != null && body !== "" && ! ( this . params instanceof BatchTableDeleteEntityOptionalParams ) ) { this . params . tableEntityProperties = JSON . parse ( body ) ; } const options = new Object ( ) as Models . QueryOptions ; if ( this . getHeader ( "accept" ) ?. includes ( "minimalmeta" ) ) { options . format = Models . OdataMetadataFormat . Applicationjsonodataminimalmetadata ; } else if ( this . getHeader ( "accept" ) ?. includes ( "fullmeta" ) ) { options . format = Models . OdataMetadataFormat . Applicationjsonodatafullmetadata ; } else { options . format = Models . OdataMetadataFormat . Applicationjsonodatanometadata ; } this . params . queryOptions = options ; } public getMethod ( ) { if ( this . batchOperation . httpMethod != null ) { return this . batchOperation . httpMethod ; } else { throw new Error ( "httpMethod invalid on batch operation" ) ; } } public getUrl ( ) { if ( this . batchOperation . uri != null && this . batchOperation . path != null ) { return this . batchOperation . uri ; } else { throw new Error ( "uri or path null when calling getUrl on BatchRequest" ) ; } } public getEndpoint ( ) { throw new Error ( "Method not implemented." ) ; } public getPath ( ) { if ( this . batchOperation . path != null ) { return this . batchOperation . path ; } else { throw new Error ( "path null  when calling getPath on BatchRequest" ) ; } } public getBodyStream ( ) { if ( this . batchOperation . jsonRequestBody != null ) { return Stream . Readable . from ( this . batchOperation . jsonRequestBody ) ; } else { throw new Error ( "body null  when calling getBodyStream on BatchRequest" ) ; } } public setBody ( body ) { throw new Error ( "Method not implemented." ) ; } public getBody ( ) { if ( this . batchOperation . jsonRequestBody != null ) { return this . batchOperation . jsonRequestBody ; } else { throw new Error ( "body null  when calling getBody on BatchRequest" ) ; } } public getHeader ( field ) { return this . headers . header ( field ) ; } public getHeaders ( ) { throw new Error ( "Method not implemented." ) ; } public getRawHeaders ( ) { return this . batchOperation . rawHeaders ; } public getQuery ( key ) { switch ( key ) { case "$format" : return this . params . queryOptions ?. format ; case "$top" : return this . params . queryOptions ?. top ?. toLocaleString ( ) ; case "$select" : return this . params . queryOptions ?. select ; case "$filter" : return this . params . queryOptions ?. filter ; default : break ; } throw new Error ( "unknown query options type." ) ; } public getProtocol ( ) { if ( this . batchOperation . protocol !== null && this . batchOperation . protocol !== undefined ) { return this . batchOperation . protocol ; } else { const protocolMatch = this . getUrl ( ) . match ( /https?/ ) ; if ( protocolMatch !== null && protocolMatch ! . length > 0 ) { this . batchOperation . protocol = protocolMatch [ 0 ] ; return this . batchOperation . protocol ; } throw new Error ( "protocol null when calling getProtocol on BatchRequest" ) ; } } }