Skip to content

Commit 4012c5f

Browse files
feat(ref-imp): copy changes in latest version to 1.0
1 parent 9075aa4 commit 4012c5f

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

lib/core/versions/1.0/DocumentComposer.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

lib/core/versions/1.0/models/ServiceModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
export default interface ServiceModel {
55
id: string;
66
type: string;
7-
serviceEndpoint: string | object;
7+
serviceEndpoint: string | object | Array<string | object>;
88
}

0 commit comments

Comments
 (0)