Skip to content

Commit 17cf9e6

Browse files
Implement code review suggestions
Signed-off-by: Andrei Floricel <andrei.floricel@gmail.com>
1 parent 972ff91 commit 17cf9e6

6 files changed

Lines changed: 71 additions & 89 deletions

File tree

src/api/Methods.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717
Intent,
1818
StandardContextType,
1919
StandardIntent,
20-
ContextTypeFor,
2120
ContextType,
2221
} from '..';
23-
import { IntentsConfiguration, StandardContextsSet, StandardIntentsSet } from '../intents/IntentsConfiguration';
22+
import { StandardContextsSet } from '../internal/contextConfiguration';
23+
import { StandardIntentsSet } from '../internal/intentConfiguration';
2424

2525
const DEFAULT_TIMEOUT = 5000;
2626

@@ -200,14 +200,6 @@ export function isStandardIntent(intent: Intent): intent is StandardIntent {
200200
return StandardIntentsSet.has(intent as StandardIntent);
201201
}
202202

203-
/**
204-
* Get the possible context types for a given intent.
205-
* @param intent
206-
*/
207-
export function getPossibleContextsForIntent<I extends StandardIntent>(intent: I): ContextTypeFor<I>[] {
208-
return IntentsConfiguration[intent] ?? [];
209-
}
210-
211203
/**
212204
* Compare numeric semver version number strings (in the form `1.2.3`).
213205
*
@@ -252,5 +244,5 @@ export const versionIsAtLeast: (metadata: ImplementationMetadata, version: strin
252244
version
253245
) => {
254246
let comparison = compareVersionNumbers(metadata.fdc3Version, version);
255-
return comparison === null ? null : comparison >= 0 ? true : false;
247+
return comparison === null ? null : comparison >= 0;
256248
};

src/intents/Intents.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Copyright FINOS FDC3 contributors - see NOTICE file
44
*/
55

6-
import { IntentsConfiguration } from './IntentsConfiguration';
7-
86
/**
97
* @see https://fdc3.finos.org/docs/intents/spec#standard-intents
108
*/
@@ -33,13 +31,6 @@ export type StandardIntent =
3331
*/
3432
export type Intent = StandardIntent | (string & {});
3533

36-
/**
37-
* Typed possible context for a given intent
38-
*
39-
* @example `ContextTypeFor<'StartCall'>` is equivalent to `'fdc3.contact' | 'fdc3.contactList' | 'fdc3.nothing'`
40-
*/
41-
export type ContextTypeFor<I extends StandardIntent> = typeof IntentsConfiguration[I][number];
42-
4334
/**
4435
* @deprecated Use {@link StandardIntent} instead
4536
*/

src/intents/IntentsConfiguration.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { StandardContextType } from '../context/ContextType';
2+
import { exhaustiveStringTuple } from './typeHelpers';
3+
4+
const STANDARD_CONTEXT_TYPES = exhaustiveStringTuple<StandardContextType>()(
5+
'fdc3.action',
6+
'fdc3.chart',
7+
'fdc3.chat.initSettings',
8+
'fdc3.chat.message',
9+
'fdc3.chat.room',
10+
'fdc3.chat.searchCriteria',
11+
'fdc3.contact',
12+
'fdc3.contactList',
13+
'fdc3.country',
14+
'fdc3.currency',
15+
'fdc3.email',
16+
'fdc3.instrument',
17+
'fdc3.instrumentList',
18+
'fdc3.interaction',
19+
'fdc3.message',
20+
'fdc3.organization',
21+
'fdc3.portfolio',
22+
'fdc3.position',
23+
'fdc3.nothing',
24+
'fdc3.timerange',
25+
'fdc3.transactionResult',
26+
'fdc3.valuation'
27+
);
28+
29+
// used internally to check if a given intent/context is a standard one
30+
export const StandardContextsSet = new Set(STANDARD_CONTEXT_TYPES);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { StandardIntent } from '../intents/Intents';
2+
import { exhaustiveStringTuple } from './typeHelpers';
3+
4+
const STANDARD_INTENTS = exhaustiveStringTuple<StandardIntent>()(
5+
'CreateInteraction',
6+
'SendChatMessage',
7+
'StartCall',
8+
'StartChat',
9+
'StartEmail',
10+
'ViewAnalysis',
11+
'ViewChat',
12+
'ViewChart',
13+
'ViewContact',
14+
'ViewHoldings',
15+
'ViewInstrument',
16+
'ViewInteractions',
17+
'ViewMessages',
18+
'ViewNews',
19+
'ViewOrders',
20+
'ViewProfile',
21+
'ViewQuote',
22+
'ViewResearch'
23+
);
24+
25+
// used internally to check if a given intent/context is a standard one
26+
export const StandardIntentsSet = new Set(STANDARD_INTENTS);

src/internal/typeHelpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type AtLeastOne<T> = [T, ...T[]];
2+
3+
/**
4+
* Ensures at compile time that the given string tuple is exhaustive on a given union type, i.e. contains ALL possible values of the given UNION_TYPE.
5+
*/
6+
export const exhaustiveStringTuple = <UNION_TYPE extends string>() => <L extends AtLeastOne<UNION_TYPE>>(
7+
...tuple: L extends any
8+
? Exclude<UNION_TYPE, L[number]> extends never
9+
? L
10+
: Exclude<UNION_TYPE, L[number]>[]
11+
: never
12+
) => tuple;

0 commit comments

Comments
 (0)