Skip to content

Commit

Permalink
chore: Provider updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacivita committed Jun 3, 2024
1 parent 3d3a657 commit f54ed16
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 116 deletions.
21 changes: 18 additions & 3 deletions languages/javascript/src/shared/Gateway/Server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ export async function notify(method, params) {
}

// Register a provider implementation with an interface name
export function provide(interfaceName, provider, methods) {
export function provide(interfaceName, provider) {
providers[interfaceName] = provider
interfaces[interfaceName] = methods
}

// Register a notification listener with an event name
Expand All @@ -66,6 +65,22 @@ export function unsubscribe(event) {
delete listeners[event]
}

export function registerProviderInterface(capability, _interface, method, parameters, response, focusable) {
interfaces[_interface] = interfaces[_interface] || {
capability,
name: _interface,
methods: [],
}

interfaces[_interface].methods.push({
name: method,
parameters,
response,
focusable
})
}


async function getProviderResult(method, params) {
const split = method.split('.')
method = split.pop()
Expand All @@ -74,7 +89,7 @@ async function getProviderResult(method, params) {
if (providers[interfaceName]) {
if (providers[interfaceName][method]) {
// sort the params into an array based on the interface parameter order
const parameters = interfaces[interfaceName].find(m => m.name === method).parameters.map(p => params[p]).filter(p => p !== undefined)
const parameters = interfaces[interfaceName].methods.find(m => m.name === method).parameters.map(p => params[p]).filter(p => p !== undefined)
return await providers[interfaceName][method](...parameters)
}
throw `Method not implemented: ${method}`
Expand Down
4 changes: 2 additions & 2 deletions languages/javascript/src/shared/Gateway/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function unsubscribe(event) {
Server.subscribe(event)
}

export function provide(interfaceName, provider, methods) {
Server.provide(interfaceName, provider, methods)
export function provide(interfaceName, provider) {
Server.provide(interfaceName, provider)
}

export function deprecate (method, alternative) {
Expand Down
4 changes: 2 additions & 2 deletions languages/javascript/templates/declarations/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {Function} callback
${if.deprecated} * @deprecated ${method.deprecation}
${end.if.deprecated} */
function listen(event: '${event.name}'${if.context}, ${event.signature.params}${end.if.context}, callback: (data: ${notifier.value.type}) => void): Promise<number>
function listen(event: '${event.name}'${if.context}, ${event.signature.params}${end.if.context}, callback: (data: ${event.result.type}) => void): Promise<number>

/**
* ${method.summary}
Expand All @@ -15,4 +15,4 @@ ${end.if.deprecated} */
* @param {Function} callback
${if.deprecated} * @deprecated ${method.deprecation}
${end.if.deprecated} */
function once(event: '${event.name}'${if.context}, ${event.signature.params}${end.if.context}, callback: (data: ${notifier.value.type}) => void): Promise<number>
function once(event: '${event.name}'${if.context}, ${event.signature.params}${end.if.context}, callback: (data: ${event.result.type}) => void): Promise<number>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ProvideManager from '../ProvideManager/index.mjs'
import { registerProviderInterface } from '../ProvideManager/index.mjs'
3 changes: 1 addition & 2 deletions languages/javascript/templates/imports/provider.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import ProvideManager from '../ProvideManager/index.mjs'
import { registerProviderInterface } from '../ProvideManager/index.mjs'
import { registerProviderInterface } from '../Gateway/Server.mjs'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
registerProviderInterface('${capability}', '${info.title}', ${interface})
registerProviderInterface('${capability}', '${interface}', '${method.name}', ${method.params.array}, ${method.response}, ${method.focusable})
2 changes: 1 addition & 1 deletion languages/javascript/templates/interfaces/default.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${method.name}(${method.signature.params}, session: ProviderSession): Promise<${method.result.type}>
${method.name}(${method.signature.params}): Promise<${method.result.type}>
2 changes: 1 addition & 1 deletion languages/javascript/templates/interfaces/focusable.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${method.name}(${method.signature.params}, session: FocusableProviderSession): Promise<${method.result.type}>
${method.name}(${method.signature.params}): Promise<${method.result.type}>
6 changes: 3 additions & 3 deletions languages/javascript/templates/methods/provide.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function provide(capability, provider) {
return ProvideManager.provide(capability, provider)
}
// function provide(capability, provider) {
// return ProvideManager.provide(capability, provider)
// }
4 changes: 4 additions & 0 deletions languages/javascript/templates/methods/registration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

function ${method.name}(provider) {
return Gateway.provide('${info.title}', provider)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// Provider Interfaces

interface ProviderSession {
correlationId(): string // Returns the correlation id of the current provider session
}

interface FocusableProviderSession extends ProviderSession {
focus(): Promise<void> // Requests that the provider app be moved into focus to prevent a user experience
}

${providers.list}
2 changes: 0 additions & 2 deletions src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const parsedArgs = Object.assign({}, defaults, nopt(knownOpts, shortHands, proce
const task = process.argv[2]
const signOff = () => console.log('\nThis has been a presentation of \x1b[38;5;202mFirebolt\x1b[0m \u{1F525} \u{1F529}\n')

console.dir(parsedArgs)

try {
if (task === 'slice') {
await slice(parsedArgs).then(signOff)
Expand Down
Loading

0 comments on commit f54ed16

Please sign in to comment.