-
Notifications
You must be signed in to change notification settings - Fork 133
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
Modify generate-type-predicates to only include interfaces that have … #1444
Modify generate-type-predicates to only include interfaces that have … #1444
Conversation
@Roaders it looks like everything is being generated twice (two copies of each type constant and is* function). Also can we discuss what's being generated here and the use cases again? I've found the is* typeguard functions useful, but I am concerned that through the use of the convert functions, they may be more expensive than necessary and will return false (I think) if there are any excess properties... If they are for typing rather than full validation they could just be based on checking the type fields... The message unions (intended to help create discriminated unions #1387 (comment)) seem to serve a similar role, as I could either do: public onMessage(message: RequestMessage): void{
switch(message.type){
case: "raiseIntentRequest":
...
break;
case "raiseIntentForContextRequest":
...
break;
default:
...
console.log(`Unknown message type encountered: ` + message.type);
} or //Edit: removed, was not correct The former would (currently) be more efficient. Do we need both? I'm also concerned about the type constants generated and whether encouraging use of them is a mistake, adding complexity to code without benefit... They obscure the underlying values in code while not providing the usual benefit of a constant (a single place to set and change the value). Use of the generated types for messages would already confirm that the type field values are correct... The main thing we need (that the quicktype generated code doesn't give us) is a consistent, clean way to determine the type of an incoming message - where I believe this code currently provides us two competing methods of doing so. I am aware that @robmoffat has the opposite opinion on use of the constants in code. We need to bring this to ground to progress the fdc3-for-web implementation. Finally, perhaps we should just replace the schema-generated group types (e.g. AppRequestMessage) with their discriminated union counter parts (i.e. RequestMessage) to avoid duplication? |
339477c
to
5ac033d
Compare
Have pushed some updates.
I still have to create the additional |
Hmmmm.... the diff is now huge... Could this just be because I deleted BrowserTypes and regenerated with the functions in a different order? |
5ac033d
to
524834b
Compare
@kriswest is the above valid typescript? I had never seen a switch statement like that (switching on the object then using type predicates for the cases). When I try it I get compile errors: //this is fine
if (isAddIntentListenerRequest(message)) {
return this.onAddIntentListenerRequest(message, sourceApp);
}
switch (message) {
// this gives a compile error:
// Type 'boolean' is not comparable to type 'AddContextListenerRequest | BroadcastRequest | CreatePrivateChannelRequest | FindInstancesRequest
case isAddEventListenerRequest(message):
return this.onAddIntentListenerRequest(message, sourceApp);
} |
524834b
to
7979770
Compare
Added the valid type predicates and sped up the normal predicate. Added some progress messages (generation is a bit slow). Added comments to type predicates. |
No its not valid - does narrow the type for you inside the cases, but doesn't make a correct comparison. My bad. A switch on message.type with the discriminated union and type strings in the cases should narrow the type inside the cases and check that the strings are valid - I'll test that later when back at my desk. |
Its not that bad, looks to me mostly like the replacement union types, the is* functions and isValid* functions. The new functions LGTM based on a quick glance. |
I undid my changes to the file and just ran the type predicates script on it rather than generating from fresh. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
one of the checks is failing. what do I need to do to fixs that? is it test coverage? |
@Roaders theres a test failing due to a typing issue (somethign that may need an adjustment after your changes) and then something is up with the code coverage reporting. I'll take a look at the first issue and see if I can resolve. TO do that I'm going to merge this PR into branch on the FINOS repo and then open a new PR. |
0bda0f1
into
finos:fdc3-for-web-impl-update-type-predicates
Describe your change
Modification of the generate-type-predicates code to build unions types of interfaces not based on the interface name but based on the
type
declared in the interface. Iftype
extends theRequestMessageType
union then the interface is included in theRequestMessage
unionRelated Issue
Contributor License Agreement
Review Checklist
DesktopAgent
,Channel
,PrivateChannel
,Listener
,Bridging
)?JSDoc comments on interfaces and types should be matched to the main documentation in /docs
Conformance test definitions should cover all required aspects of an FDC3 Desktop Agent implementation, which are usually marked with a MUST keyword, and optional features (SHOULD or MAY) where the format of those features is defined
The Web Connection protocol and Desktop Agent Communication Protocol schemas must be able to support all necessary aspects of the Desktop Agent API, while Bridging must support those aspects necessary for Desktop Agents to communicate with each other
npm run build
) run and the results checked in?Generated code will be found at
/src/api/BrowserTypes.ts
and/or/src/bridging/BridgingTypes.ts
BaseContext
schema applied viaallOf
(as it is in existing types)?title
anddescription
provided for all properties defined in the schema?npm run build
) run and the results checked in?Generated code will be found at
/src/context/ContextTypes.ts
THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE FINOS CORPORATE CONTRIBUTOR LICENSE AGREEMENT.
THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.