-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
451 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Directory, DirectoryApp, DirectoryIntent } from "./DirectoryInterface" | ||
|
||
/** | ||
* Basic directory implementation that allows queries over a set of apps. | ||
*/ | ||
export class BasicDirectory implements Directory { | ||
|
||
allApps: DirectoryApp[] | ||
|
||
constructor(apps: DirectoryApp[]) { | ||
this.allApps = apps | ||
} | ||
|
||
/** For retrieving intents */ | ||
|
||
retrieveIntents(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryIntent[] { | ||
return this.retrieveAllIntents().filter(i => this.intentMatches(i, contextType, intentName, resultType)) | ||
} | ||
|
||
intentMatches(i: DirectoryIntent, contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): boolean { | ||
return ((intentName == undefined) || (i.intentName == intentName)) && | ||
((contextType == undefined) || (i.contexts.includes(contextType))) && | ||
((resultType == undefined) || (i.resultType == resultType) || (genericResultType(i.resultType) == resultType)) | ||
} | ||
|
||
retrieveAllIntents(): DirectoryIntent[] { | ||
return this.allApps.flatMap(a => this.retrieveIntentsForApp(a)) | ||
} | ||
|
||
retrieveIntentsForApp(a: DirectoryApp): DirectoryIntent[] { | ||
const lf = a.interop?.intents?.listensFor ?? {} | ||
const lfa = Object.entries(lf) | ||
const lfAugmented = lfa.map(([key, value]) => { | ||
return { | ||
intentName: key, | ||
...value, | ||
appId: a.appId | ||
} | ||
}) | ||
return lfAugmented | ||
} | ||
|
||
|
||
/** For retrieving apps */ | ||
|
||
retrieveApps(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryApp[] { | ||
return this.retrieveAllApps() | ||
.filter(a => this.retrieveIntentsForApp(a) | ||
.filter(i => this.intentMatches(i, contextType, intentName, resultType)) | ||
.length > 0) | ||
} | ||
|
||
retrieveAppsById(appId: string): DirectoryApp[] { | ||
return this.retrieveAllApps().filter(a => a.appId == appId) | ||
} | ||
|
||
retrieveAllApps(): DirectoryApp[] { | ||
return this.allApps | ||
} | ||
|
||
/** | ||
* For FDC3 1.2, retreives by the name of the app | ||
*/ | ||
retrieveAppsByName(name: string): DirectoryApp[] { | ||
return this.retrieveAllApps().filter(a => a.name == name) | ||
} | ||
} | ||
|
||
|
||
function genericResultType(rt: string | undefined): string | undefined { | ||
if (rt == undefined) { | ||
return undefined; | ||
} else if (rt.indexOf('channel<') == 0) { | ||
return 'channel'; | ||
} else { | ||
return rt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { components } from '../directory-schema' | ||
|
||
type schemas = components['schemas'] | ||
|
||
export type DirectoryIntent = schemas['Intent'] & { intentName: string, appId: string } | ||
export type DirectoryApp = schemas['Application']; | ||
|
||
|
||
/** | ||
* This interface wraps the functionality of the FDC3 Directory structure (stored in JSON), | ||
* providing lookup calls to functions that would be handled by inspecting the directory/directories JSON definitions. | ||
*/ | ||
|
||
export interface Directory { | ||
|
||
/** For retrieving intents */ | ||
|
||
//retrieveIntents(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryIntent[] | ||
|
||
retrieveAllIntents(): DirectoryIntent[] | ||
|
||
|
||
/** For retrieving apps */ | ||
|
||
retrieveApps(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryApp[] | ||
|
||
retrieveAppsById(appId: string): DirectoryApp[] | ||
|
||
retrieveAllApps(): DirectoryApp[] | ||
|
||
/** | ||
* For FDC3 1.2, retreives by the name of the app | ||
*/ | ||
retrieveAppsByName(name: string): DirectoryApp[] | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
packages/da-server/src/directory/fdc3-2.1-json-directory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Directory } from "./DirectoryInterface"; | ||
|
||
/** | ||
* Handles loading of JSON from URLs | ||
*/ | ||
export class FDC32_1JSONDirectory implements Directory { | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { AgentRequestMessage, FindIntentAgentRequest, FindIntentAgentResponse } from "@finos/fdc3/dist/bridging/BridgingTypes"; | ||
import { MessageHandler } from "../BasicFDC3Server"; | ||
import { ServerContext } from "../ServerContext"; | ||
import { Directory } from "../directory/DirectoryInterface"; | ||
|
||
export class IntentHandler implements MessageHandler { | ||
|
||
private readonly directory: Directory | ||
|
||
constructor(d: Directory) { | ||
this.directory = d | ||
} | ||
|
||
|
||
accept(msg: AgentRequestMessage, sc: ServerContext): void { | ||
switch (msg.type as string) { | ||
case 'findIntentRequest': return this.findIntentRequest(msg as FindIntentAgentRequest, sc) | ||
} | ||
} | ||
|
||
findIntentRequest(r: FindIntentAgentRequest, sc: ServerContext): void { | ||
const { intent, context, resultType } = r.payload | ||
|
||
const apps = this.directory.retrieveApps(context?.type, intent, resultType) | ||
.map(a => { | ||
return { | ||
appId: a.appId | ||
} | ||
}) | ||
|
||
const out = { | ||
meta: { | ||
requestUuid: r.meta.requestUuid, | ||
timestamp: new Date(), | ||
responseUuid: sc.createUUID() | ||
}, | ||
type: "findIntentResponse", | ||
payload: { | ||
appIntent: { | ||
intent: { | ||
name: r.payload.intent | ||
}, | ||
apps | ||
} | ||
} | ||
} as FindIntentAgentResponse | ||
|
||
sc.post(out) | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: Responding to Directory Requests about Intents | ||
|
||
Background: | ||
Given "libraryApp" is an app with the following intents | ||
| Intent Name | Context Type | Result Type | | ||
| loanBook | fdc3.book | fdc3.loan | | ||
And A newly instantiated FDC3 Server | ||
|
||
Scenario: Failed Find Intents Request | ||
When "App1/a1" finds intents with intent "loanBook" and contextType "fdc3.instrument" and result type "{empty}" | ||
Then messaging will have outgoing posts | ||
| type | payload.appIntent.intent.name | payload.appIntent.apps.length | | ||
| findIntentResponse | loanBook | 0 | | ||
|
||
Scenario: Successful Find Intents Request | ||
When "App1/a1" finds intents with intent "loanBook" and contextType "{empty}" and result type "{empty}" | ||
Then messaging will have outgoing posts | ||
| type | payload.appIntent.intent.name | payload.appIntent.apps.length | payload.appIntent.apps[0].appId | | ||
| findIntentResponse | loanBook | 1 | libraryApp | |
Oops, something went wrong.