@@ -683,8 +683,13 @@ export async function executeOciComputeOperation(
683683 ( values . metadata !== undefined || values . extendedMetadata !== undefined )
684684 ) {
685685 const current = await client . request ( {
686- endpoint, method : 'GET' , encodedPath : `/20160918/instances/${ encodeURIComponent ( String ( values . instanceId ) ) } ` ,
687- timeoutMs : 30_000 , maxResponseBytes : 2_000_000 , signal, retry : { kind : 'safe' , maxAttempts : 2 } ,
686+ endpoint,
687+ method : 'GET' ,
688+ encodedPath : `/20160918/instances/${ encodeURIComponent ( String ( values . instanceId ) ) } ` ,
689+ timeoutMs : 30_000 ,
690+ maxResponseBytes : 2_000_000 ,
691+ signal,
692+ retry : { kind : 'safe' , maxAttempts : 2 } ,
688693 } )
689694 const existing = parseResource ( current . body )
690695 if ( ! isPlainRecord ( existing ) ) throw new Error ( 'OCI returned an invalid instance' )
@@ -693,48 +698,65 @@ export async function executeOciComputeOperation(
693698 const before = isPlainRecord ( existing [ field ] ) ? existing [ field ] : { }
694699 const after = isPlainRecord ( values [ field ] ) ? values [ field ] : { }
695700 for ( const key of [ 'user_data' , 'ssh_authorized_keys' ] ) {
696- if ( JSON . stringify ( before [ key ] ) !== JSON . stringify ( after [ key ] ) ) throw new Error ( `Updating ${ field } must preserve existing user_data and ssh_authorized_keys` )
701+ if ( JSON . stringify ( before [ key ] ) !== JSON . stringify ( after [ key ] ) )
702+ throw new Error (
703+ `Updating ${ field } must preserve existing user_data and ssh_authorized_keys`
704+ )
697705 }
698706 }
699707 validateOciComputeMetadata ( {
700708 metadata : values . metadata ?? existing . metadata ,
701709 extendedMetadata : values . extendedMetadata ?? existing . extendedMetadata ,
702710 } )
703711 if ( ! headers [ 'if-match' ] ) {
704- if ( ! current . headers . etag ) throw new Error ( 'OCI did not return an ETag for the metadata update' )
712+ if ( ! current . headers . etag )
713+ throw new Error ( 'OCI did not return an ETag for the metadata update' )
705714 headers [ 'if-match' ] = current . headers . etag
706715 }
707716 }
708717 const path = definition . path . replace ( / \{ ( \w + ) \} / g, ( _match , key : string ) => {
709- const value = operation === 'instance_pool_action' && key === 'action'
710- ? String ( values [ key ] ) . toLowerCase ( )
711- : String ( values [ key ] )
718+ const value =
719+ operation === 'instance_pool_action' && key === 'action'
720+ ? String ( values [ key ] ) . toLowerCase ( )
721+ : String ( values [ key ] )
712722 return encodeURIComponent ( value )
713723 } )
714724 const queryPairs : [ string , string ] [ ] = [ ]
715725 for ( const key of definition . query ?? [ ] ) {
716726 if ( values [ key ] !== undefined ) queryPairs . push ( [ key , String ( values [ key ] ) ] )
717727 }
718728 const base = {
719- endpoint, encodedPath : `/20160918${ path } ` , queryPairs, headers,
720- timeoutMs : 30_000 , maxResponseBytes : 2_000_000 , signal,
729+ endpoint,
730+ encodedPath : `/20160918${ path } ` ,
731+ queryPairs,
732+ headers,
733+ timeoutMs : 30_000 ,
734+ maxResponseBytes : 2_000_000 ,
735+ signal,
721736 responseHeaders : [
722737 ...( definition . query ?. includes ( 'page' ) ? [ 'opc-next-page' ] : [ ] ) ,
723738 ...( definition . work ? [ 'opc-work-request-id' ] : [ ] ) ,
724739 ...( definition . location ? [ 'location' ] : [ ] ) ,
725740 ] ,
726741 }
727742 const body = requestBody ( operation , values , definition )
728- const request : OciRequest = definition . method === 'GET'
729- ? { ...base , method : 'GET' , retry : { kind : 'safe' , maxAttempts : 2 } }
730- : definition . method === 'DELETE'
731- ? { ...base , method : 'DELETE' }
732- : {
733- ...base , method : definition . method as 'POST' | 'PUT' ,
734- body : body === undefined ? new Uint8Array ( ) : new TextEncoder ( ) . encode ( JSON . stringify ( body ) ) ,
735- contentType : 'application/json' ,
736- ...( retryToken ? { retry : { kind : 'tokenized' as const , maxAttempts : 2 , retryToken } } : { } ) ,
737- }
743+ const request : OciRequest =
744+ definition . method === 'GET'
745+ ? { ...base , method : 'GET' , retry : { kind : 'safe' , maxAttempts : 2 } }
746+ : definition . method === 'DELETE'
747+ ? { ...base , method : 'DELETE' }
748+ : {
749+ ...base ,
750+ method : definition . method as 'POST' | 'PUT' ,
751+ body :
752+ body === undefined
753+ ? new Uint8Array ( )
754+ : new TextEncoder ( ) . encode ( JSON . stringify ( body ) ) ,
755+ contentType : 'application/json' ,
756+ ...( retryToken
757+ ? { retry : { kind : 'tokenized' as const , maxAttempts : 2 , retryToken } }
758+ : { } ) ,
759+ }
738760 signal ?. throwIfAborted ( )
739761 dispatched = true
740762 const response = await client . request ( request )
@@ -744,29 +766,37 @@ export async function executeOciComputeOperation(
744766 status : response . status ,
745767 requestId : response . opcRequestId ?? response . headers [ 'opc-request-id' ] ?? null ,
746768 etag : response . headers . etag ?? null ,
747- ...( definition . query ?. includes ( 'page' ) ? { nextPage : response . headers [ 'opc-next-page' ] ?? null } : { } ) ,
748- ...( definition . work ? { workRequestId : response . headers [ 'opc-work-request-id' ] ?? null } : { } ) ,
769+ ...( definition . query ?. includes ( 'page' )
770+ ? { nextPage : response . headers [ 'opc-next-page' ] ?? null }
771+ : { } ) ,
772+ ...( definition . work
773+ ? { workRequestId : response . headers [ 'opc-work-request-id' ] ?? null }
774+ : { } ) ,
749775 ...( definition . location ? { location : response . headers . location ?? null } : { } ) ,
750776 ...( retryToken ? { retryToken } : { } ) ,
751777 }
752778 if ( definition . output && definition . projection ) {
753779 const data = parseResource ( response . body )
754- if ( definition . list && ( ! Array . isArray ( data ) || data . length > 100 ) ) throw new Error ( 'OCI returned an invalid or oversized resource page' )
755- const resource = definition . list && Array . isArray ( data )
756- ? data . map ( ( entry ) => projectOciComputeResource ( entry , definition . projection ?? { } ) )
757- : projectOciComputeResource ( data , definition . projection )
780+ if ( definition . list && ( ! Array . isArray ( data ) || data . length > 100 ) )
781+ throw new Error ( 'OCI returned an invalid or oversized resource page' )
782+ const resource =
783+ definition . list && Array . isArray ( data )
784+ ? data . map ( ( entry ) => projectOciComputeResource ( entry , definition . projection ?? { } ) )
785+ : projectOciComputeResource ( data , definition . projection )
758786 Object . assign ( output , { [ definition . output ] : resource } )
759787 }
760788 return { success : true , output }
761789 } catch ( error ) {
762790 const providerError = error instanceof OciClientError ? error : undefined
763- const rejected = ! dispatched || ( providerError ?. status !== undefined && providerError . status < 500 )
791+ const rejected =
792+ ! dispatched || ( providerError ?. status !== undefined && providerError . status < 500 )
764793 return {
765794 success : false ,
766795 retryable : definition . method === 'GET' ,
767- error : providerError ?. status === 412
768- ? 'The resource changed. Read its current state and ETag before submitting another update.'
769- : getErrorMessage ( error , 'OCI Compute operation failed' ) ,
796+ error :
797+ providerError ?. status === 412
798+ ? 'The resource changed. Read its current state and ETag before submitting another update.'
799+ : getErrorMessage ( error , 'OCI Compute operation failed' ) ,
770800 output : {
771801 status : providerError ?. status ?? receivedStatus ?? 0 ,
772802 requestId : providerError ?. opcRequestId ?? receivedRequestId ?? null ,
0 commit comments