Open Roaders opened 4 days ago
@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 https://github.com/finos/FDC3/pull/1387#issuecomment-2419628543) 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?
Have pushed some updates.
AppRequestMessage
, AgentResponseMessage
and AgentEventMessage
and replaces them with the generated unionsI still have to create the additional validated
type predicate which won't take long in the morning. Do we want to remove the constants? I'm afraid I didn't understand @robmoffat explanation of what they were for.
Hmmmm.... the diff is now huge... Could this just be because I deleted BrowserTypes and regenerated with the functions in a different order?
public onMessage(message: AppRequestMessage): void{ switch(message){ case: isRaiseIntentRequest(message): ... break; case isRaiseIntentForContextRequest(message): ... break; default: ... console.log(`Unknown message type encountered: ` + message.type); }
@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);
}
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.
@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:
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.
Hmmmm.... the diff is now huge... Could this just be because I deleted BrowserTypes and regenerated with the functions in a different order?
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.
Hmmmm.... the diff is now huge... Could this just be because I deleted BrowserTypes and regenerated with the functions in a different order?
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.
one of the checks is failing. what do I need to do to fixs that? is it test coverage?
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.