-
Notifications
You must be signed in to change notification settings - Fork 114
Support array for serviceEndpoint #1200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Comment on lines
+350
to
+366
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need the same change in ion-sdk. Totally get it if you don't have time to make those changes in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to implement this in ion-sdk as well. I will still create an issue as well, as I am not yet 100% sure when I will find time for the implementation. So I will open the issue, once this PR is merged, right?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @thehenrytsai, I updated ion-sdk (decentralized-identity/ion-sdk#30) as well |
||
| } | ||
| } else { | ||
| throw new SidetreeError(ErrorCode.DocumentComposerPatchServiceEndpointMustBeStringOrNonArrayObject); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,5 @@ | |
| export default interface ServiceModel { | ||
| id: string; | ||
| type: string; | ||
| serviceEndpoint: string | object; | ||
| serviceEndpoint: string | object | Array<string | object>; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably no need for this change, array is an object.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, I just thought it might be better to understand if it's explicit. But I can also revert this change if you like. |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.