Skip to content
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

Weird Type Definition in Browsers.ts #1275

Closed
robmoffat opened this issue Jul 19, 2024 · 4 comments
Closed

Weird Type Definition in Browsers.ts #1275

robmoffat opened this issue Jul 19, 2024 · 4 comments
Assignees
Labels
FDC3 for Web Browsers question Further information is requested

Comments

@robmoffat
Copy link
Member

Minor Issue

This is probably not wrong, but kinda weird:

export interface FindInstancesRequest {
    /**
     * Metadata for a request message sent by an FDC3-enabled app to a Desktop Agent.
     */
    meta: AddContextListenerRequestMeta;
    /**
     * The message payload typically contains the arguments to FDC3 API functions.
     */
    payload: FindInstancesRequestPayload;
    /**
     * Identifies the type of the message and it is typically set to the FDC3 function name that
     * the message relates to, e.g. 'findIntent', with 'Request' appended.
     */
    type: "findInstancesRequest";
}

why is meta specified as AddContextListenerRequestMeta?

@kriswest
Copy link
Contributor

This is probably one of Quick types annoying type merges... The order that things are generated in affects which name is used. I may be able to work around that way... Alternatively, we really need the --no-combine-classes arg to quick type fixed.

If you see these check if they have the right properties. Also, bear in mind that you usually wouldn't import the oddly named type directly, rather just the top level type

@kriswest
Copy link
Contributor

@robmoffat @Lecss @Roaders @Davidhanson90 I took a brief look at this again - the problem is that QuickType won't guarantee the naming of any sub-types it generates, only of the top-level types that we are generating (e.g. FindIntentsRequest, rather than FindIntentsRequestMetadata) and only where they have a unique title. There are some fudges possible that can guide it to a better name but they depend on the order that files are processed in and are fragile.

The top-level types are those listed at the top of the BrowserTypes.ts file in the sample import statement/Convert class code.

If we wanted to enable stable naming for the subtypes we might have to go as far as fixing quicktype (so the --co-combine-classes parameter actually works) as I think that, even if we change some of the metadata it will still try to combine some of the types where they overlap on 90% of properties. Hence, for now I would stick to trying to use the top-level types only and consider the rest to be an implementation detail you shouldn't interact directly with. Once I get ahead of the FDC3 for Web standard docs PR (no small task) I can try to circle around to quicktype...

Note AppRequest, AgentResponse, AgentEvent, IframeMessage and WebConnectionProtocolMessage should all be structurally compatible with all derived types and are top-level types, so you can use those as utility types in code that will apply to a wide range of messages.

P.S. I've just updated the generated BrowserTypes.ts file after a few corrections. Please pull the new copy and use that and let me know about any unexpected differences.

@kriswest kriswest added question Further information is requested and removed bug Something isn't working labels Jul 23, 2024
@kriswest
Copy link
Contributor

P.S. we could/should control what you can import by re-exporting through index.ts as we do for everything else: https://github.com/finos/FDC3/blob/main/src/index.ts

I've yet to add exports for BrowserTypes to it... That could be done soon, at which point you'd be able to use npm pack to create a sample npm module to work against, simulating what you'd do when this is released (for anything other than the getAgent implementation itself).

@kriswest
Copy link
Contributor

closing as complete - will revisit in review of FDC3 for the Web PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FDC3 for Web Browsers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants