Skip to content

Commit

Permalink
Moved demo, raise intent working
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Mar 18, 2024
1 parent 6a1cf5e commit 95a5e15
Show file tree
Hide file tree
Showing 30 changed files with 71 additions and 65 deletions.
26 changes: 13 additions & 13 deletions packages/da-server/src/handlers/IntentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ type ListenerRegistration = {
resultType: string | undefined
}

function createListenerRegistration(msg: any): ListenerRegistration {

function createListenerRegistrationNameOnly(msg: OnAddIntentListenerAgentRequest | OnUnsubscribeIntentListenerAgentRequest): ListenerRegistration {
return {
appId: msg.meta.source?.appId!!,
instanceId: msg.meta.source?.instanceId!!,
intentName: msg.payload.intentName,
contextType: msg.payload.contextType,
resultType: msg.payload.resultType
intentName: msg.payload.intent,
contextType: undefined,
resultType: undefined
}
}

Expand Down Expand Up @@ -110,7 +109,7 @@ class PendingIntent {
}

async accept(arg0: any): Promise<void> {
const actual = createListenerRegistration(arg0)
const actual = createListenerRegistrationNameOnly(arg0)
if (matches(this.expecting, actual) && !this.complete) {
this.complete = true
forwardRequest(this.r, arg0.meta.source, this.sc, this.ih)
Expand Down Expand Up @@ -171,15 +170,15 @@ export class IntentHandler implements MessageHandler {
}

onUnsubscribe(arg0: OnUnsubscribeIntentListenerAgentRequest, _sc: ServerContext): void {
const lr = createListenerRegistration(arg0)
const lr = createListenerRegistrationNameOnly(arg0)
const fi = this.regs.findIndex((e) => matches(e, lr))
if (fi > -1) {
this.regs.splice(fi, 1)
}
}

onAddIntentListener(arg0: OnAddIntentListenerAgentRequest, _sc: ServerContext): void {
const lr = createListenerRegistration(arg0)
const lr = createListenerRegistrationNameOnly(arg0)
this.regs.push(lr)

// see if this intent listener is the destination for any pending intents
Expand All @@ -192,19 +191,20 @@ export class IntentHandler implements MessageHandler {
}

async raiseIntentRequest(arg0: RaiseIntentAgentRequest, sc: ServerContext): Promise<void> {
if (arg0.meta.destination.instanceId) {
const target = arg0.payload.app
if (target.instanceId) {
// ok, targeting a specific, known instance
if (await sc.isAppOpen(arg0.meta.destination)) {
return forwardRequest(arg0, arg0.meta.destination, sc, this)
if (await sc.isAppOpen(target)) {
return forwardRequest(arg0, target, sc, this)
} else {
// instance doesn't exist
return sendError(arg0, sc, ResolveError.TargetInstanceUnavailable)
}
} else if (this.directory.retrieveAppsById(arg0.meta.destination.appId).length > 0) {
} else if (this.directory.retrieveAppsById(target.appId).length > 0) {
// app exists but needs starting
const pi = new PendingIntent(arg0, sc, this)
this.pendingIntents.add(pi)
return sc.open(arg0.meta.destination.appId).then(() => { return undefined })
return sc.open(target.appId).then(() => { return undefined })
} else {
// app doesn't exist
return sendError(arg0, sc, ResolveError.TargetAppUnavailable)
Expand Down
4 changes: 2 additions & 2 deletions packages/da-server/test/features/find-intent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Find Intent API
| returnBook | fdc3.book | {empty} |
| streamAny | fdc3.book | channel |
And A newly instantiated FDC3 Server
And "App1/b1" registers an intent listener for "returnBook" with contextType "fdc3.book" and result type "channel<messages>"
And "App1/b1" registers an intent listener for "returnBook"

Scenario: Unsuccessful Find Intents Request
When "App1/a1" finds intents with intent "loanBook" and contextType "fdc3.instrument" and result type "{empty}"
Expand Down Expand Up @@ -59,7 +59,7 @@ Feature: Find Intent API
| libraryApp | {empty} |

Scenario: Disconnecting The Intent Listener
When "App1/b1" unsubscribes an intent listener for "returnBook" with contextType "fdc3.book" and result type "channel<messages>"
When "App1/b1" unsubscribes an intent listener for "returnBook"
When "App1/a1" finds intents with intent "returnBook" and contextType "fdc3.book" and result type "{empty}"
Then messaging will have outgoing posts
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | to.instanceId | msg.payload.appIntent.apps[0].appId |
Expand Down
6 changes: 3 additions & 3 deletions packages/da-server/test/features/raise-intent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Raising Intents
And "App1/a1" is opened
And "App1/b1" is opened
And "App1/b1" sends hello
And "App1/b1" registers an intent listener for "returnBook" with contextType "fdc3.book" and result type "channel<messages>"
And "App1/b1" registers an intent listener for "returnBook"

Scenario: Raising An Intent To A Non-Existent App
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "NonExistentApp"
Expand All @@ -33,7 +33,7 @@ Feature: Raising Intents
Scenario: Raising An Intent To A Non-Running App
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "libraryApp"
And "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "unusedApp"
And "libraryApp/0" registers an intent listener for "returnBook" with contextType "fdc3.book" and result type "channel<messages>"
And "libraryApp/0" registers an intent listener for "returnBook"
Then running apps will be
| appId | instanceId |
| App1 | a1 |
Expand All @@ -46,7 +46,7 @@ Feature: Raising Intents

Scenario: Raising An Intent To A Non-Running App without A Context Type in the listener
When "App1/a1" raises an intent for "stampBook" with contextType "fdc3.book" on app "libraryApp"
And "libraryApp/0" registers an intent listener for "stampBook" with contextType "{empty}" and result type "channel<messages>"
And "libraryApp/0" registers an intent listener for "stampBook"
Then running apps will be
| appId | instanceId |
| App1 | a1 |
Expand Down
12 changes: 4 additions & 8 deletions packages/da-server/test/step-definitions/intents.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,26 @@ When('{string} finds intents with intent {string} and contextType {string} and r
this.server.receive(message, meta.source)
});

Given('{string} registers an intent listener for {string} with contextType {string} and result type {string}', function (this: CustomWorld, appStr: string, intentName: string, contextType: string, resultType: string) {
Given('{string} registers an intent listener for {string}', function (this: CustomWorld, appStr: string, intent: string) {
const meta = createMeta(this, appStr)
const message = {
type: 'onAddIntentListener',
meta,
payload: {
intentName: handleResolve(intentName, this),
contextType: handleResolve(contextType, this),
resultType: handleResolve(resultType, this),
intent: handleResolve(intent, this)
}
} as OnAddIntentListenerAgentRequest
this.server.receive(message, meta.source)
});


Given('{string} unsubscribes an intent listener for {string} with contextType {string} and result type {string}', function (this: CustomWorld, appStr: string, intentName: string, contextType: string, resultType: string) {
Given('{string} unsubscribes an intent listener for {string}', function (this: CustomWorld, appStr: string, intent: string) {
const meta = createMeta(this, appStr)
const message = {
type: 'onUnsubscribeIntentListener',
meta,
payload: {
intentName: handleResolve(intentName, this),
contextType: handleResolve(contextType, this),
resultType: handleResolve(resultType, this),
intent: handleResolve(intent, this),
}
} as OnUnsubscribeIntentListenerAgentRequest
this.server.receive(message, meta.source)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fdc3-web-demo",
"name": "demo",
"private": true,
"version": "0.0.0",
"scripts": {
Expand All @@ -18,7 +18,6 @@
"@types/uuid": "^9.0.8",
"@types/ws": "^8.5.10",
"client": "workspace:*",
"da-proxy": "workspace:*",
"da-server": "workspace:*",
"express": "^4.18.3",
"fdc3-common": "workspace:*",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ export class DemoServerContext implements ServerContext {
}

async open(appId: string): Promise<AppMetadata> {
const details = this.directory.retrieveAppsById(appId) as DirectoryApp[]
const details: DirectoryApp[] = this.directory.retrieveAppsById(appId) as DirectoryApp[]
if (details.length > 0) {
const url = details[0].details.url
const url = (details[0].details as any)?.url ?? undefined
const window = this.openUrl(url)
const metadata = {
appId,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createAppStartButton(app: DirectoryApp, sc: ServerContext): HTML
button.onclick = () => sc.open(app.appId)
div.appendChild(button)
const p = document.createElement("p")
p.textContent = app.description
p.textContent = app.description ?? ''
div.appendChild(p)
return div
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"target": "ESNext",
"useDefineForClassFields": true,
"module": "NodeNext",
"lib": ["ESNext", "DOM"],
"lib": [
"ESNext",
"DOM"
],
"moduleResolution": "NodeNext",
"strict": true,
"resolveJsonModule": true,
Expand All @@ -15,5 +18,18 @@
"noImplicitReturns": true,
"skipLibCheck": true
},
"include": ["src"]
}
"include": [
"src"
],
"references": [
{
"path": "../fdc3-common"
},
{
"path": "../client"
},
{
"path": "../da-server"
}
]
}
8 changes: 2 additions & 6 deletions packages/fdc3-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ export type OnAddIntentListenerAgentRequest = {
type: 'onAddIntentListener',
meta: PrivateChannelOnAddContextListenerAgentRequestMeta,
payload: {
intentName: string,
contextType: string | undefined,
resultType: string | undefined,
intent: string,
}
}

export type OnUnsubscribeIntentListenerAgentRequest = {
type: 'onUnsubscribeIntentListener',
meta: PrivateChannelOnAddContextListenerAgentRequestMeta,
payload: {
intentName: string,
contextType: string | undefined,
resultType: string | undefined,
intent: string,
}
}
49 changes: 24 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3452,6 +3452,30 @@ __metadata:
languageName: node
linkType: hard

"demo@workspace:packages/demo":
version: 0.0.0-use.local
resolution: "demo@workspace:packages/demo"
dependencies:
"@finos/fdc3": "npm:^2.1.0-beta.6"
"@types/express": "npm:^4.17.15"
"@types/node": "npm:^20.9.3"
"@types/uuid": "npm:^9.0.8"
"@types/ws": "npm:^8.5.10"
client: "workspace:*"
da-server: "workspace:*"
express: "npm:^4.18.3"
fdc3-common: "workspace:*"
nodemon: "npm:^3.0.1"
socket.io: "npm:^4.7.5"
socket.io-client: "npm:^4.7.5"
tsx: "npm:^4.5.0"
typescript: "npm:^5.3.2"
uuid: "npm:^9.0.1"
vite: "npm:^5.0.2"
vite-express: "npm:^0.15.0"
languageName: unknown
linkType: soft

"depd@npm:2.0.0":
version: 2.0.0
resolution: "depd@npm:2.0.0"
Expand Down Expand Up @@ -4579,31 +4603,6 @@ __metadata:
languageName: unknown
linkType: soft

"fdc3-web-demo@workspace:packages/fdc3-web-demo":
version: 0.0.0-use.local
resolution: "fdc3-web-demo@workspace:packages/fdc3-web-demo"
dependencies:
"@finos/fdc3": "npm:^2.1.0-beta.6"
"@types/express": "npm:^4.17.15"
"@types/node": "npm:^20.9.3"
"@types/uuid": "npm:^9.0.8"
"@types/ws": "npm:^8.5.10"
client: "workspace:*"
da-proxy: "workspace:*"
da-server: "workspace:*"
express: "npm:^4.18.3"
fdc3-common: "workspace:*"
nodemon: "npm:^3.0.1"
socket.io: "npm:^4.7.5"
socket.io-client: "npm:^4.7.5"
tsx: "npm:^4.5.0"
typescript: "npm:^5.3.2"
uuid: "npm:^9.0.1"
vite: "npm:^5.0.2"
vite-express: "npm:^0.15.0"
languageName: unknown
linkType: soft

"fdc3-workbench@workspace:packages/fdc3-workbench":
version: 0.0.0-use.local
resolution: "fdc3-workbench@workspace:packages/fdc3-workbench"
Expand Down

0 comments on commit 95a5e15

Please sign in to comment.