Skip to content

Commit

Permalink
Fixed displayName return
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed May 15, 2024
1 parent 0761a18 commit 5d6ab84
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kite9/web-fdc3",
"private": true,
"version": "0.0.15",
"version": "0.0.16",
"workspaces": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@kite9/client",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"version": "0.0.15",
"version": "0.0.16",
"scripts": {
"build": "tsc --module es2022",
"clean": "rimraf dist; rimraf cucumber-report.html; rimraf coverage"
Expand Down
2 changes: 1 addition & 1 deletion packages/da-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/da-proxy",
"version": "0.0.15",
"version": "0.0.16",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/da-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/da-server",
"version": "0.0.15",
"version": "0.0.16",
"files": [
"dist"
],
Expand Down
12 changes: 8 additions & 4 deletions packages/da-server/src/directory/BasicDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ export class BasicDirectory implements Directory {
return lfAugmented as DirectoryIntent[]
}

retrieveIntents(contextType: string, resultType: string | undefined): DirectoryIntent[] {
retrieveAllIntents(): DirectoryIntent[] {
const allIntents = this.retrieveAllApps()
.flatMap(a => this.retrieveIntentsForApp(a))
.filter(i => {
return i.contexts.includes(contextType) && (genericResultTypeSame(resultType, i.resultType))
})

return allIntents
}

retrieveIntents(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryIntent[] {
const matchingIntents = this.retrieveAllIntents()
.filter(i => this.intentMatches(i, contextType, intentName, resultType))
return matchingIntents
}

retrieveApps(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryApp[] {
return this.retrieveAllApps()
.filter(a => this.retrieveIntentsForApp(a)
Expand Down
8 changes: 6 additions & 2 deletions packages/da-server/src/directory/DirectoryInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export type DirectoryApp = schemas['Application'];

export interface Directory {

retrieveAllApps(): DirectoryApp[]

retrieveApps(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryApp[]

retrieveIntents(contextType: string, resultType: string | undefined): DirectoryIntent[]
retrieveAllIntents(): DirectoryIntent[]

retrieveIntents(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryIntent[]

retrieveAppsById(appId: string): DirectoryApp[]

retrieveAllApps(): DirectoryApp[]

}
12 changes: 8 additions & 4 deletions packages/da-server/src/handlers/IntentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ export class IntentHandler implements MessageHandler {
// TODO: Add result type
const { context } = r.payload

const apps1 = this.directory.retrieveIntents(context?.type, undefined).map(di => {
const apps1 = this.directory.retrieveIntents(context?.type, undefined, undefined).map(di => {
return {
intent: {
name: di.intentName
name: di.intentName,
displayName: di.displayName
},
apps: [
{
Expand Down Expand Up @@ -279,7 +280,9 @@ export class IntentHandler implements MessageHandler {
return !running
}) as AppMetadata[]


// just need this for the (deprecated) display name
const allMatchingIntents = this.directory.retrieveIntents(context?.type, intent, resultType)
const displayName = (allMatchingIntents.length > 0) ? allMatchingIntents[0].displayName : undefined

const out = {
meta: {
Expand All @@ -291,7 +294,8 @@ export class IntentHandler implements MessageHandler {
payload: {
appIntent: {
intent: {
name: r.payload.intent
name: intent,
displayName
},
apps: [...apps1, ...apps2]
}
Expand Down
8 changes: 4 additions & 4 deletions packages/da-server/test/features/find-intent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ Feature: Find Intent API
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
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | msg.payload.appIntent.apps[0].appId | to.instanceId |
| findIntentResponse | loanBook | 1 | libraryApp | a1 |
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | msg.payload.appIntent.apps[0].appId | to.instanceId | msg.payload.appIntent.intent.displayName |
| findIntentResponse | loanBook | 1 | libraryApp | a1 | loan book |

Scenario: Find Intents by Context Request
When "App/a1" finds intents with contextType "fdc3.book"
Then messaging will have outgoing posts
| msg.type | msg.payload.appIntents[0].intent.name | msg.payload.appIntents.length | to.instanceId |
| findIntentsByContextResponse | loanBook | 4 | a1 |
| msg.type | msg.payload.appIntents[0].intent.name | msg.payload.appIntents.length | to.instanceId | msg.payload.appIntents[0].intent.displayName |
| findIntentsByContextResponse | loanBook | 4 | a1 | loan book |

Scenario: Successful Find Intents Request With Channel
When "App1/a1" finds intents with intent "streamBook" and contextType "fdc3.book" and result type "channel"
Expand Down
10 changes: 10 additions & 0 deletions packages/da-server/test/step-definitions/intents.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ type ListensFor = {
};
}

function decamelize(str: string, separator: string) {
separator = typeof separator === 'undefined' ? '_' : separator;

return str
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
.toLowerCase();
}

function convertDataTableToListensFor(cw: CustomWorld, dt: DataTable): ListensFor {
const hashes = dt.hashes()
const out: { [key: string]: any } = {}
hashes.forEach(h => {
out[h["Intent Name"]] = {
displayName: decamelize(h["Intent Name"], " "),
contexts: [handleResolve(h["Context Type"], cw)],
resultType: handleResolve(h["Result Type"], cw)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kite9/demo",
"private": true,
"version": "0.0.15",
"version": "0.0.16",
"scripts": {
"dev": "nodemon -w src/server -x tsx src/server/main.ts",
"start": "NODE_ENV=production tsx src/server/main.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-common",
"version": "0.0.15",
"version": "0.0.16",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-workbench/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fdc3-workbench",
"version": "0.0.15",
"version": "0.0.16",
"private": true,
"homepage": ".",
"license": "Apache-2.0",
Expand Down

0 comments on commit 5d6ab84

Please sign in to comment.