Skip to content

Commit

Permalink
feat(ref-imp): copy changes in latest version to 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolockenvitz committed Oct 18, 2022
1 parent 9075aa4 commit 4012c5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions lib/core/versions/1.0/DocumentComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,26 @@ export default class DocumentComposer {
}

// `serviceEndpoint` validations.
const serviceEndpoint = service.serviceEndpoint;
if (typeof serviceEndpoint === 'string') {
const uri = URI.parse(service.serviceEndpoint);
if (uri.error !== undefined) {
throw new SidetreeError(
ErrorCode.DocumentComposerPatchServiceEndpointStringNotValidUri,
`Service endpoint string '${serviceEndpoint}' is not a valid URI.`
);
}
} else if (typeof serviceEndpoint === 'object') {
// Allow `object` type only if it is not an array.
if (Array.isArray(serviceEndpoint)) {
throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointCannotBeAnArray);
// transform URI strings and JSON objects into array so that we can run validations more easily
const serviceEndpointValueAsArray = Array.isArray(service.serviceEndpoint) ? service.serviceEndpoint : [service.serviceEndpoint];
for (const serviceEndpoint of serviceEndpointValueAsArray) {
// serviceEndpoint itself must be URI string or non-array object
if (typeof serviceEndpoint === 'string') {
const uri = URI.parse(serviceEndpoint);
if (uri.error !== undefined) {
throw new SidetreeError(
ErrorCode.DocumentComposerPatchServiceEndpointStringNotValidUri,
`Service endpoint string '${serviceEndpoint}' is not a valid URI.`
);
}
} else if (typeof serviceEndpoint === 'object') {
// Allow `object` type only if it is not an array.
if (Array.isArray(serviceEndpoint)) {
throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointCannotBeAnArray);
}
} else {
throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject);
}
} else {
throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/versions/1.0/models/ServiceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
export default interface ServiceModel {
id: string;
type: string;
serviceEndpoint: string | object;
serviceEndpoint: string | object | Array<string | object>;
}

0 comments on commit 4012c5f

Please sign in to comment.