Skip to content

Commit

Permalink
Implement code review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Floricel <andrei.floricel@gmail.com>
  • Loading branch information
andreifloricel committed Mar 12, 2024
1 parent 972ff91 commit 17cf9e6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 89 deletions.
14 changes: 3 additions & 11 deletions src/api/Methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
Intent,
StandardContextType,
StandardIntent,
ContextTypeFor,
ContextType,
} from '..';
import { IntentsConfiguration, StandardContextsSet, StandardIntentsSet } from '../intents/IntentsConfiguration';
import { StandardContextsSet } from '../internal/contextConfiguration';
import { StandardIntentsSet } from '../internal/intentConfiguration';

const DEFAULT_TIMEOUT = 5000;

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

/**
* Get the possible context types for a given intent.
* @param intent
*/
export function getPossibleContextsForIntent<I extends StandardIntent>(intent: I): ContextTypeFor<I>[] {
return IntentsConfiguration[intent] ?? [];
}

/**
* Compare numeric semver version number strings (in the form `1.2.3`).
*
Expand Down Expand Up @@ -252,5 +244,5 @@ export const versionIsAtLeast: (metadata: ImplementationMetadata, version: strin
version
) => {
let comparison = compareVersionNumbers(metadata.fdc3Version, version);
return comparison === null ? null : comparison >= 0 ? true : false;
return comparison === null ? null : comparison >= 0;
};
9 changes: 0 additions & 9 deletions src/intents/Intents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Copyright FINOS FDC3 contributors - see NOTICE file
*/

import { IntentsConfiguration } from './IntentsConfiguration';

/**
* @see https://fdc3.finos.org/docs/intents/spec#standard-intents
*/
Expand Down Expand Up @@ -33,13 +31,6 @@ export type StandardIntent =
*/
export type Intent = StandardIntent | (string & {});

/**
* Typed possible context for a given intent
*
* @example `ContextTypeFor<'StartCall'>` is equivalent to `'fdc3.contact' | 'fdc3.contactList' | 'fdc3.nothing'`
*/
export type ContextTypeFor<I extends StandardIntent> = typeof IntentsConfiguration[I][number];

/**
* @deprecated Use {@link StandardIntent} instead
*/
Expand Down
69 changes: 0 additions & 69 deletions src/intents/IntentsConfiguration.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/internal/contextConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { StandardContextType } from '../context/ContextType';
import { exhaustiveStringTuple } from './typeHelpers';

const STANDARD_CONTEXT_TYPES = exhaustiveStringTuple<StandardContextType>()(
'fdc3.action',
'fdc3.chart',
'fdc3.chat.initSettings',
'fdc3.chat.message',
'fdc3.chat.room',
'fdc3.chat.searchCriteria',
'fdc3.contact',
'fdc3.contactList',
'fdc3.country',
'fdc3.currency',
'fdc3.email',
'fdc3.instrument',
'fdc3.instrumentList',
'fdc3.interaction',
'fdc3.message',
'fdc3.organization',
'fdc3.portfolio',
'fdc3.position',
'fdc3.nothing',
'fdc3.timerange',
'fdc3.transactionResult',
'fdc3.valuation'
);

// used internally to check if a given intent/context is a standard one
export const StandardContextsSet = new Set(STANDARD_CONTEXT_TYPES);
26 changes: 26 additions & 0 deletions src/internal/intentConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { StandardIntent } from '../intents/Intents';
import { exhaustiveStringTuple } from './typeHelpers';

const STANDARD_INTENTS = exhaustiveStringTuple<StandardIntent>()(
'CreateInteraction',
'SendChatMessage',
'StartCall',
'StartChat',
'StartEmail',
'ViewAnalysis',
'ViewChat',
'ViewChart',
'ViewContact',
'ViewHoldings',
'ViewInstrument',
'ViewInteractions',
'ViewMessages',
'ViewNews',
'ViewOrders',
'ViewProfile',
'ViewQuote',
'ViewResearch'
);

// used internally to check if a given intent/context is a standard one
export const StandardIntentsSet = new Set(STANDARD_INTENTS);
12 changes: 12 additions & 0 deletions src/internal/typeHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type AtLeastOne<T> = [T, ...T[]];

/**
* 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.
*/
export const exhaustiveStringTuple = <UNION_TYPE extends string>() => <L extends AtLeastOne<UNION_TYPE>>(
...tuple: L extends any
? Exclude<UNION_TYPE, L[number]> extends never
? L
: Exclude<UNION_TYPE, L[number]>[]
: never
) => tuple;

0 comments on commit 17cf9e6

Please sign in to comment.