Skip to content

Commit 855e34c

Browse files
authored
Merge pull request #1004 from finos/1003-clarify-getresult-on-resolve-to-void
Clarify intended behavior on void intent results
2 parents b52f497 + afb80f6 commit 855e34c

8 files changed

Lines changed: 28 additions & 27 deletions

File tree

docs/api/ref/DesktopAgent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const contactListener = await fdc3.addContextListener('fdc3.contact', (contact,
9595
addIntentListener(intent: string, handler: IntentHandler): Promise<Listener>;
9696
```
9797
98-
Adds a listener for incoming intents from the Desktop Agent. The handler function may return void or a promise that resolves to a [`IntentResult`](Types#intentresult), which is either a [`Context`](Types#context) object, representing any data that should be returned to the app that raised the intent, or a [`Channel`](Channel) or [`PrivateChannel`](PrivateChannel) over which data responses will be sent. The `IntentResult` will be returned to the app that raised the intent via the [`IntentResolution`](Metadata#intentresolution) and retrieved from it using the `getResult()` function.
98+
Adds a listener for incoming intents from the Desktop Agent. The handler function may return void or a promise that resolves to a [`IntentResult`](Types#intentresult), which is either a [`Context`](Types#context) object (representing any data that should be returned to the app that raised the intent), a [`Channel`](Channel), a [`PrivateChannel`](PrivateChannel) over which data responses will be sent, or `void`. The `IntentResult` will be returned to the app that raised the intent via the [`IntentResolution`](Metadata#intentresolution) and retrieved from it using the `getResult()` function.
9999
100100
The Desktop Agent MUST reject the promise returned by the `getResult()` function of `IntentResolution` if any of the following is true:
101101
1. The intent handling function's returned promise rejects.
@@ -642,7 +642,7 @@ If you wish to raise an intent without a context, use the `fdc3.nothing` context
642642
643643
Returns an [`IntentResolution`](Metadata#intentresolution) object with details of the app instance that was selected (or started) to respond to the intent.
644644
645-
Issuing apps may optionally wait on the promise that is returned by the `getResult()` member of the IntentResolution. This promise will resolve when the _receiving app's_ intent handler function returns and resolves a promise. The Desktop Agent resolves the issuing app's promise with the Context object or Channel that is provided as resolution by the receiving app. The Desktop Agent MUST reject the issuing app's promise, with a string from the [`ResultError`](Errors#resulterror) enumeration, if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a promise, or (3) the returned promise resolves to an invalid type.
645+
Issuing apps may optionally wait on the promise that is returned by the `getResult()` member of the `IntentResolution`. This promise will resolve when the _receiving app's_ intent handler function returns and resolves a promise. The Desktop Agent resolves the issuing app's promise with the Context object, Channel object or void that is provided as resolution within the receiving app. The Desktop Agent MUST reject the issuing app's promise, with a string from the [`ResultError`](Errors#resulterror) enumeration, if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a valid response (a promise or void), or (3) the returned promise resolves to an invalid type.
646646
647647
#### Example
648648

docs/api/ref/Errors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ Contains constants representing the errors that can be encountered when calling
139139

140140
```typescript
141141
enum ResultError {
142-
/** Returned if the `IntentHandler` exited without returning a Promise or that
143-
* Promise was not resolved with a Context or Channel object.
142+
/** Returned if the intent handler exited without returning a valid result
143+
* (a promise resolving to a Context, Channel object or void).
144144
*/
145145
NoResultReturned = 'NoResultReturned',
146146

docs/api/ref/Metadata.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,18 @@ interface IntentResolution {
335335
*/
336336
readonly version?: string;
337337

338-
/** Retrieves a promise that will resolve to either `Context` data returned
339-
* by the application that resolves the raised intent or a `Channel`
340-
* established and returned by the app resolving the intent.
338+
/** Retrieves a promise that will resolve to `Context` data returned
339+
* by the application that resolves the raised intent, a `Channel`
340+
* established and returned by the app resolving the intent or void.
341341
*
342342
* A `Channel` returned MAY be of the `PrivateChannel` type. The
343343
* client can then `addContextListener()` on that channel to, for example,
344344
* receive a stream of data.
345345
*
346346
* If an error occurs (i.e. an error is thrown by the handler function,
347-
* the promise it returns is rejected, or a promise is not returned by the
348-
* handler function) then the Desktop Agent MUST reject the promise returned
349-
* by the `getResult()` function of the `IntentResolution` with a string from
347+
* the promise it returns is rejected, or the promise resolved to an invalid
348+
* type) then the Desktop Agent MUST reject the promise returned by the
349+
* `getResult()` function of the `IntentResolution` with a string from
350350
* the `ResultError` enumeration.
351351
*/
352352
getResult(): Promise<IntentResult>;

docs/api/ref/Types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Optional metadata about the context message, including the app that originated t
8686
type IntentHandler = (context: Context, metadata?: ContextMetadata) => Promise<IntentResult> | void;
8787
```
8888

89-
Describes a callback that handles a context event and may return a promise of a Context or Channel object to be returned to the application that raised the intent.
89+
Describes a callback that handles a context event and may return a promise of a Context, Channel object or `void` to be returned to the application that raised the intent.
9090

9191
Used when attaching listeners for raised intents.
9292

@@ -103,10 +103,10 @@ Optional metadata about the intent & context message, including the app that ori
103103
## `IntentResult`
104104

105105
```typescript
106-
type IntentResult = Context | Channel;
106+
type IntentResult = Context | Channel | void;
107107
```
108108

109-
Describes results that an Intent handler may optionally return that should be communicated back to the app that raised the intent, via the [`IntentResolution`](Metadata#intentresolution).
109+
Describes results that an Intent handler may return that should be communicated back to the app that raised the intent, via the [`IntentResolution`](Metadata#intentresolution).
110110

111111
Represented as a union type in TypeScript, however, this type may be rendered as an interface in other languages that both the `Context` and `Channel` types implement, allowing either to be returned by an `IntentHandler`.
112112

src/api/DesktopAgent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export interface DesktopAgent {
236236
*
237237
* Returns an `IntentResolution` object with details of the app instance that was selected (or started) to respond to the intent.
238238
*
239-
* Issuing apps may optionally wait on the promise that is returned by the `getResult()` member of the `IntentResolution`. This promise will resolve when the _receiving app's_ intent handler function returns and resolves a promise. The Desktop Agent resolves the issuing app's promise with the Context object or Channel that is provided as resolution within the receiving app. The Desktop Agent MUST reject the issuing app's promise, with a string from the `ResultError` enumeration, if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a promise, or (3) the returned promise resolves to an invalid type.
239+
* Issuing apps may optionally wait on the promise that is returned by the `getResult()` member of the `IntentResolution`. This promise will resolve when the _receiving app's_ intent handler function returns and resolves a promise. The Desktop Agent resolves the issuing app's promise with the Context object, Channel object or void that is provided as resolution within the receiving app. The Desktop Agent MUST reject the issuing app's promise, with a string from the `ResultError` enumeration, if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a valid response (a promise or void), or (3) the returned promise resolves to an invalid type.
240240
*
241241
* ```javascript
242242
* // raise an intent for resolution by the desktop agent
@@ -293,11 +293,11 @@ export interface DesktopAgent {
293293
raiseIntentForContext(context: Context, app?: AppIdentifier): Promise<IntentResolution>;
294294

295295
/**
296-
* Adds a listener for incoming Intents from the Agent. The handler function may return void or a promise that should resolve to an `IntentResult`, which is either a `Context` object, representing any data that should be returned, or a `Channel` over which data responses will be sent. The IntentResult will be returned to app that raised the intent via the `IntentResolution` and retrieved from it using the `getResult()` function.
296+
* Adds a listener for incoming intents from the Desktop Agent. The handler function may return void or a promise that resolves to an `IntentResult`, which is either a `Context` object, representing any data that should be returned to the app that raised the intent, a `Channel` Object, a `PrivateChannel` over which data responses will be sent, or `void`. The `IntentResult` will be returned to the app that raised the intent via the `IntentResolution` and retrieved from it using the `getResult()` function.
297297
*
298298
* The Desktop Agent MUST reject the promise returned by the `getResult()` function of `IntentResolution` if: (1) the intent handling function's returned promise rejects, (2) the intent handling function doesn't return a promise, or (3) the returned promise resolves to an invalid type.
299299
*
300-
* The `PrivateChannel` type is provided to support synchronisation of data transmitted over returned channels, by allowing both parties to listen for events denoting subscription and unsubscription from the returned channel. `PrivateChannels` are only retrievable via raising an intent.
300+
* The `PrivateChannel` type is provided to support synchronization of data transmitted over returned channels, by allowing both parties to listen for events denoting subscription and unsubscription from the returned channel. `PrivateChannels` are only retrievable via raising an intent.
301301
*
302302
* Optional metadata about the raised intent, including the app that originated the message, SHOULD be provided by the desktop agent implementation.
303303
*

src/api/Errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export enum ResolveError {
3838
}
3939

4040
export enum ResultError {
41-
/** Returned if the intent handler exited without returning a Promise or that Promise was not resolved with a Context or Channel object. */
41+
/** Returned if the intent handler exited without returning a valid result (a promise resolving to a Context, Channel object or void). */
4242
NoResultReturned = 'NoResultReturned',
4343
/** Returned if the Intent handler function processing the raised intent throws an error or rejects the Promise it returned. */
4444
IntentHandlerRejected = 'IntentHandlerRejected',

src/api/IntentResolution.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ export interface IntentResolution {
4949
*/
5050
readonly version?: string;
5151
/**
52-
* Retrieves a promise that will resolve to either `Context` data returned
53-
* by the application that resolves the raised intent or a `Channel`
54-
* established and returned by the app resolving the intent.
52+
* Retrieves a promise that will resolve to `Context` data returned
53+
* by the application that resolves the raised intent, a `Channel`
54+
* established and returned by the app resolving the intent or void.
5555
*
56-
* A `Channel` returned will often be of the `PrivateChannel` type. The
56+
* A `Channel` returned MAY be of the `PrivateChannel` type. The
5757
* client can then `addContextListener()` on that channel to, for example,
5858
* receive a stream of data.
5959
*
60-
* The promise MUST reject with a string from the `ResultError` enumeration
61-
* if an error is thrown by the intent handler, it rejects the returned
62-
* promise, it does not return a promise or the promise resolves to an
63-
* object of an invalid type.
60+
* If an error occurs (i.e. an error is thrown by the handler function,
61+
* the promise it returns is rejected, or the promise resolved to an invalid
62+
* type) then the Desktop Agent MUST reject the promise returned by the
63+
* `getResult()` function of the `IntentResolution` with a string from
64+
* the `ResultError` enumeration.
6465
*/
6566
getResult(): Promise<IntentResult>;
6667
}

src/api/Types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export type ContextHandler = (context: Context, metadata?: ContextMetadata) => v
1818
* Intents can return results that are either context data objects
1919
* or a reference to a Channel.
2020
*/
21-
export type IntentResult = Context | Channel;
21+
export type IntentResult = Context | Channel | void;
2222
/**
2323
* Describes a callback that handles a context event and may return a
24-
* promise of a Context or Channel object to be returned to the
24+
* promise of a Context, Channel object or void to be returned to the
2525
* application that raised the intent.
2626
* Used when attaching listeners for raised intents.
2727
*

0 commit comments

Comments
 (0)