@@ -345,22 +345,26 @@ export default class DocumentComposer {
345345 }
346346
347347 // `serviceEndpoint` validations.
348- const serviceEndpoint = service . serviceEndpoint ;
349- if ( typeof serviceEndpoint === 'string' ) {
350- const uri = URI . parse ( service . serviceEndpoint ) ;
351- if ( uri . error !== undefined ) {
352- throw new SidetreeError (
353- ErrorCode . DocumentComposerPatchServiceEndpointStringNotValidUri ,
354- `Service endpoint string '${ serviceEndpoint } ' is not a valid URI.`
355- ) ;
356- }
357- } else if ( typeof serviceEndpoint === 'object' ) {
358- // Allow `object` type only if it is not an array.
359- if ( Array . isArray ( serviceEndpoint ) ) {
360- throw new SidetreeError ( ErrorCode . DocumentComposerPatchServiceEndpointCannotBeAnArray ) ;
348+ // transform URI strings and JSON objects into array so that we can run validations more easily
349+ const serviceEndpointValueAsArray = Array . isArray ( service . serviceEndpoint ) ? service . serviceEndpoint : [ service . serviceEndpoint ] ;
350+ for ( const serviceEndpoint of serviceEndpointValueAsArray ) {
351+ // serviceEndpoint itself must be URI string or non-array object
352+ if ( typeof serviceEndpoint === 'string' ) {
353+ const uri = URI . parse ( serviceEndpoint ) ;
354+ if ( uri . error !== undefined ) {
355+ throw new SidetreeError (
356+ ErrorCode . DocumentComposerPatchServiceEndpointStringNotValidUri ,
357+ `Service endpoint string '${ serviceEndpoint } ' is not a valid URI.`
358+ ) ;
359+ }
360+ } else if ( typeof serviceEndpoint === 'object' ) {
361+ // Allow `object` type only if it is not an array.
362+ if ( Array . isArray ( serviceEndpoint ) ) {
363+ throw new SidetreeError ( ErrorCode . DocumentComposerPatchServiceEndpointCannotBeAnArray ) ;
364+ }
365+ } else {
366+ throw new SidetreeError ( ErrorCode . DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject ) ;
361367 }
362- } else {
363- throw new SidetreeError ( ErrorCode . DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject ) ;
364368 }
365369 }
366370 }
0 commit comments