Skip to content

Commit

Permalink
Merge branch 'next' into feature/x-subscriber-type
Browse files Browse the repository at this point in the history
  • Loading branch information
kschrief authored Jan 9, 2024
2 parents 3009e73 + 0b4d475 commit b5be88e
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 51 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [2.2.0-next.1](https://github.com/rdkcentral/firebolt-openrpc/compare/v2.1.1-next.3...v2.2.0-next.1) (2023-11-30)


### Features

* Improve generated doc formatting ([#155](https://github.com/rdkcentral/firebolt-openrpc/issues/155)) ([4613281](https://github.com/rdkcentral/firebolt-openrpc/commit/46132810ac5e5b0a8b9baa22903cb8a367b46f63))

## [2.1.1-next.3](https://github.com/rdkcentral/firebolt-openrpc/compare/v2.1.1-next.2...v2.1.1-next.3) (2023-11-09)


### Bug Fixes

* Provider openrpc response and error methods have a wrapper object ([#148](https://github.com/rdkcentral/firebolt-openrpc/issues/148)) ([373626e](https://github.com/rdkcentral/firebolt-openrpc/commit/373626ed598447bb670ac67e97ca8ed1bf32f28f))

## [2.1.1-next.2](https://github.com/rdkcentral/firebolt-openrpc/compare/v2.1.1-next.1...v2.1.1-next.2) (2023-11-01)


Expand Down
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ The component may include material which is licensed under other licenses / copy
listed below. Your use of this material within the component is also subject to the terms and
conditions of these licenses. The LICENSE file contains the text of all the licenses which apply
within this component..

npm is a registered trademark of npm, Inc.
6 changes: 2 additions & 4 deletions languages/javascript/templates/examples/default.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ${module} } from '${package.name}'

${module}.${method.name}(${example.params})
.then(${method.result.name} => {
console.log(${method.result.name})
})
let ${method.result.name} = await ${module}.${method.name}(${example.params})
console.log(${method.result.name})
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ${module} } from '${package.name}'

${module}.${method.pulls.for}(function(parameters) {
let success = await ${module}.${method.pulls.for}(async parameters => {
console.log(parameters.entityId)
console.log(parameters.assetId)
return Promise.resolve(${originator.params[1].example.value})
}).then(success => {
console.log(success)
})
return ${originator.params[1].example.value}
})
console.log(success)
6 changes: 2 additions & 4 deletions languages/javascript/templates/examples/polymorphic-pull.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ${module} } from '${package.name}'

${module}.${method.name}(${method.params[1].example.value})
.then(success => {
console.log(success)
})
let success = await ${module}.${method.name}(${method.params[1].example.value})
console.log(success)
6 changes: 2 additions & 4 deletions languages/javascript/templates/examples/setter.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ${module} } from '${package.name}'

${module}.${method.setter.for}(${example.params})
.then(${method.result.name} => {
console.log(${method.result.name})
})
let ${method.result.name} = await ${module}.${method.setter.for}(${example.params})
console.log(${method.result.name})
7 changes: 3 additions & 4 deletions languages/javascript/templates/examples/subscriber.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ${module} } from '${package.name}'

${method.alternative}(value => {
let listenerId = await ${method.alternative}(value => {
console.log(value)
}).then(listenerId => {
console.log(listenerId)
})
})
console.log(listenerId)
2 changes: 1 addition & 1 deletion languages/markdown/templates/codeblocks/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ${info.title} } from '${package.name}'
class My${provider} {
${provider.interface.start}
async ${provider.interface.name}(parameters, session) {
return await Promise.resolve(${provider.interface.example.result})
return ${provider.interface.example.result}
}
${provider.interface.end}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firebolt-js/openrpc",
"version": "2.1.1-next.2",
"version": "2.2.0-next.1",
"description": "The Firebolt SDK Code & Doc Generator",
"main": "languages/javascript/src/sdk.mjs",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
}
}

const paramDelimiter = config.operators ? config.operators.paramDelimiter : ', '
const paramDelimiter = config.operators ? config.operators.paramDelimiter : ''

const temporalItemName = isTemporalSetMethod(methodObj) ? methodObj.result.schema.items && methodObj.result.schema.items.title || 'Item' : ''
const temporalAddName = isTemporalSetMethod(methodObj) ? `on${temporalItemName}Available` : ''
Expand Down
45 changes: 21 additions & 24 deletions src/shared/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -684,21 +684,16 @@ const createResponseFromProvider = (provider, type, json) => {
if (provider.tags.find(t => t[`x-${type.toLowerCase()}`])) {
response.params = [
{
name: type.toLowerCase(),
required: true,
name: "correlationId",
schema: {
allOf: [
{
"$ref": "https://meta.comcast.com/firebolt/types#/definitions/ProviderResponse" // use this schema for both Errors and Results
},
{
"type": "object",
"properties": {
"result": provider.tags.find(t => t[`x-${type.toLowerCase()}`])[`x-${type.toLowerCase()}`]
}
}
]
}
type: "string"
},
required: true
},
{
name: type === 'Error' ? 'error' : "result",
schema: provider.tags.find(t => t[`x-${type.toLowerCase()}`])[`x-${type.toLowerCase()}`],
required: true
}
]

Expand Down Expand Up @@ -739,11 +734,12 @@ const createResponseFromProvider = (provider, type, json) => {
name: schema.examples.length === 1 ? "Example" : `Example #${n++}`,
params: [
{
name: `${type.toLowerCase()}`,
value: {
correlationId: "123",
result: param
}
name: 'correlationId',
value: '123'
},
{
name: 'result',
value: param
}
],
result: {
Expand Down Expand Up @@ -782,11 +778,12 @@ const createResponseFromProvider = (provider, type, json) => {
name: 'Example 1',
params: [
{
name: `${type.toLowerCase()}`,
value: {
correlationId: "123",
result: value
}
name: 'correlationId',
value: '123'
},
{
name: type === 'Error' ? 'error' : 'result',
value
}
],
result: {
Expand Down
55 changes: 55 additions & 0 deletions test/openrpc/simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,61 @@
}
}
]
},
{
"name": "methodWithMultipleParams",
"summary": "A method that takes two parameters",
"description": "A method that takes two parameters",
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"params": [
{
"name": "id",
"required": true,
"schema": {
"type": "number"
},
"summary": "A test number"
},
{
"name": "title",
"required": true,
"schema": {
"type": "string"
},
"summary": "A string test parameter."
}
],
"result": {
"name": "result",
"summary": "A result for testing basic method generation.",
"schema": {
"type": "null"
}
},
"examples": [
{
"name": "Default Example",
"params": [
{
"name": "id",
"value": 42
},
{
"name": "title",
"value": "test"
}
],
"result": {
"name": "Default Result",
"value": null
}
}
]
}
],
"components": {
Expand Down
38 changes: 37 additions & 1 deletion test/suite/simple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,47 @@
*/

import { Simple } from '../../build/sdk/javascript/src/sdk.mjs'
import Setup from '../Setup'
import { expect } from '@jest/globals';


class TransportSpy {

constructor(spy) {
this.spy = spy
this.responder = null
}

async send(msg) {
let parsed = JSON.parse(msg)
this.spy(parsed)
this.responder(JSON.stringify({
jsonrpc: '2.0',
id: parsed.id,
result: {}
}))
}

receive(callback) {
this.responder = callback
}
}

test('Basic', () => {
return Simple.method(true).then(result => {
expect(result.foo).toBe("here's foo")
})
});

test('Multiple Parameters', async () => {
let cb = null;
let promise = new Promise((resolve, reject) => {
cb = resolve
})
window['__firebolt'].setTransportLayer(new TransportSpy(cb))
await Simple.methodWithMultipleParams(5, 'foo')
let msg = await promise
expect(msg.method).toBe('simple.methodWithMultipleParams')
expect(msg.params.id).toBe(5)
expect(msg.params.title).toBe('foo')
console.log(JSON.stringify(msg))
});

0 comments on commit b5be88e

Please sign in to comment.