Skip to content

Commit

Permalink
Merge branch 'next' into feature/FIRESDK-23
Browse files Browse the repository at this point in the history
  • Loading branch information
ChakrabortySubhrajyoti committed Nov 3, 2022
2 parents 71a1994 + 570866a commit 28b0ba5
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 54 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,17 @@
# [1.7.0-next.3](https://github.com/rdkcentral/firebolt-openrpc/compare/v1.7.0-next.2...v1.7.0-next.3) (2022-10-31)


### Bug Fixes

* Only generate docs for used schema files ([ff08978](https://github.com/rdkcentral/firebolt-openrpc/commit/ff08978477ef8eb048c9f4c9d9a96e2fe66fc868))

# [1.7.0-next.2](https://github.com/rdkcentral/firebolt-openrpc/compare/v1.7.0-next.1...v1.7.0-next.2) (2022-10-31)


### Bug Fixes

* Interfaceless providers ([#68](https://github.com/rdkcentral/firebolt-openrpc/issues/68)) ([ceb3040](https://github.com/rdkcentral/firebolt-openrpc/commit/ceb304018c2e0eb7cf5ac6f9bcd5b44bab0cb083))

# [1.7.0-next.1](https://github.com/rdkcentral/firebolt-openrpc/compare/v1.6.2-next.1...v1.7.0-next.1) (2022-10-24)


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.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@firebolt-js/openrpc",
"version": "1.7.0-next.1",
"version": "1.7.0-next.3",
"description": "The Firebolt SDK Code & Doc Generator",
"main": "src/js/sdk/index.mjs",
"type": "module",
Expand Down Expand Up @@ -36,7 +36,7 @@
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",
"husky": "^8.0.0",
"husky": "^8.0.1",
"jest": "^27.3.1",
"semantic-release": "^19.0.5"
},
Expand Down
1 change: 0 additions & 1 deletion src/js/shared/Events/index.mjs
Expand Up @@ -229,7 +229,6 @@ export const prioritize = function(...args) {
}

const unsubscribe = (key) => {
console.log(key)
const [module, event] = key.split('.').slice(0, 2)
Transport.send(module, 'on' + event[0].toUpperCase() + event.substr(1), { listen: false })
}
Expand Down
18 changes: 17 additions & 1 deletion src/modules/advanced.json
Expand Up @@ -11,6 +11,10 @@
"tags": [
{
"name": "event"
},
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"summary": "A temporal set method that lists Advanced objects.",
Expand Down Expand Up @@ -61,7 +65,9 @@
},
{
"name": "capabilities",
"x-uses": "xrn:firebolt:capability:test:test"
"x-uses": [
"xrn:firebolt:capability:test:test"
]
}
],
"params": [
Expand Down Expand Up @@ -100,6 +106,10 @@
"tags": [
{
"name": "temporal-set"
},
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"summary": "A temporal set method that lists Advanced objects.",
Expand Down Expand Up @@ -136,6 +146,12 @@
{
"name": "action",
"summary": "A method that takes an Advanced object.",
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"description": "A method for testing advanced method generation.",
"params": [
{
Expand Down
28 changes: 27 additions & 1 deletion src/modules/simple.json
Expand Up @@ -9,6 +9,12 @@
{
"name": "method",
"summary": "A method.",
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"description": "A method for testing basic method generation.",
"params": [
{
Expand Down Expand Up @@ -68,7 +74,9 @@
},
{
"name": "capabilities",
"x-uses": "xrn:firebolt:capability:test:test"
"x-uses": [
"xrn:firebolt:capability:test:test"
]
}
],
"description": "A property for testing basic property generation.",
Expand Down Expand Up @@ -119,6 +127,12 @@
"description": {
"$ref": "file:../descriptions/modules/Simple/methodWithMarkdownDescription.md"
},
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"params": [
{
"name": "parameter",
Expand Down Expand Up @@ -172,6 +186,12 @@
"name": "methodWithSchema",
"summary": "A method using a schema.",
"description": "A method for testing schema-dependent method generation.",
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"params": [
{
"name": "title",
Expand Down Expand Up @@ -211,6 +231,12 @@
"name": "methodWithMethodAttribute",
"summary": "A method using a method-attribute transform.",
"description": "A method for testing sub-method generation.",
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"params": [
{
"name": "title",
Expand Down
40 changes: 37 additions & 3 deletions src/schemas/firebolt-openrpc.json
Expand Up @@ -35,12 +35,22 @@
"Method": {
"type": "object",
"required": [
"examples"
"examples",
"tags"
],
"properties": {
"examples": {
"type": "array",
"minItems": 1
},
"tags": {
"type": "array",
"items": {
"type": "object"
},
"contains": {
"$ref": "#/definitions/CapabilitiesTag"
}
}
},
"allOf": [
Expand Down Expand Up @@ -78,8 +88,12 @@
},
{
"if": {
"required": [ "tags"],
"required": [ "tags", "name"],
"properties": {
"name": {
"type": "string",
"pattern": "^onRequest"
},
"tags": {
"type": "array",
"contains": {
Expand Down Expand Up @@ -853,8 +867,28 @@
},
"x-allow-focus": {
"type": "boolean"
},
"x-response-for": {
"type": "string"
},
"x-allow-focus-for": {
"type": "string"
},
"x-error-for": {
"type": "string"
}
}
},
"anyOf": [
{
"required": [ "x-uses"]
},
{
"required": [ "x-manages"]
},
{
"required": [ "x-provides"]
}
]
}
]
},
Expand Down
5 changes: 3 additions & 2 deletions util/docs/index.mjs
Expand Up @@ -56,9 +56,10 @@ const run = ({
// All the streams we care about.
const combinedTemplates = combineStreamObjects(loadFilesIntoObject(sharedTemplateFolder, '.md', '/template/markdown/'), loadFilesIntoObject(templateFolder, '.md', '/template/markdown/'))
const combinedSchemas = combineStreamObjects(schemaFetcher(sharedSchemasFolder), schemaFetcher(schemasFolder))

const usedSchemasFilter = (schema, modules) => Object.values(modules).find(module => JSON.stringify(module).match(new RegExp("\"" + schema.$id + "(#[^\"]+)?\""))) // filter out schemas nobody references...

const generateDocs = templates => modules => schemas => version => h(Object.entries(modules))
.concat(Object.entries(schemas))
.concat(Object.entries(schemas).filter(([_, schema]) => usedSchemasFilter(schema, modules)))
.flatMap(([_, module]) => {
const documentOptions = {
asPath: asPath,
Expand Down
8 changes: 3 additions & 5 deletions util/docs/macros/index.mjs
Expand Up @@ -27,7 +27,7 @@ import pointfree from 'crocks/pointfree/index.js'
const { filter, option, map } = pointfree
import isArray from 'crocks/predicates/isArray.js'
import safe from 'crocks/Maybe/safe.js'
import { getProvidedCapabilities, isRPCOnlyMethod, isTemporalSetMethod } from '../../shared/modules.mjs'
import { getProvidedCapabilities, isRPCOnlyMethod, isTemporalSetMethod, isProviderInterfaceMethod } from '../../shared/modules.mjs'

var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));

Expand Down Expand Up @@ -62,7 +62,6 @@ const hasNonEmptyEventAttribute = (method, attribute) => {
const isEvent = method => hasTag(method, 'event')
const isProviderFocusMethod = method => method.tags && method.tags.find(t => t['x-allow-focus-for'])
const isProviderResponseMethod = method => method.tags && method.tags.find(t => t['x-response-for'])
const isProviderMethod = method => isEvent(method) && hasNonEmptyEventAttribute(method, 'x-provides')
const isFullyDocumentedEvent = method => isEvent(method) && !hasTag(method, 'rpc-only') && !hasEventAttribute(method, 'x-alternative') && !hasEventAttribute(method, 'x-pulls-for')
const isSetter = method => method.tags && method.tags.find(t => t['x-setter-for'])
const isTocMethod = method => !isEvent(method) && !isProviderFocusMethod(method) && !isProviderResponseMethod(method)
Expand All @@ -88,7 +87,7 @@ function insertMacros(data = '', moduleJson = {}, templates = {}, schemas = {},
const additionalEvents = moduleJson.methods && moduleJson.methods.filter( method => isEvent(method) && !isFullyDocumentedEvent(method))
const additionalMethods = moduleJson.methods && moduleJson.methods.filter( method => !isEvent(method) && isRPCOnlyMethod(method) )
const hasEvents = (additionalEvents && additionalEvents.length > 0) || (events && events.length > 0) //(methods && methods.find(method => isEvent(method) && !isProviderMethod(method)))
const providerMethods = moduleJson.methods && moduleJson.methods.filter( method => isProviderMethod(method))
const providerMethods = moduleJson.methods && moduleJson.methods.filter( method => isProviderInterfaceMethod(method))
const hasProviderMethods = (providerMethods && providerMethods.length > 0)

const capabilities = moduleJson.methods && getProvidedCapabilities(moduleJson)
Expand Down Expand Up @@ -300,7 +299,6 @@ function insertMacros(data = '', moduleJson = {}, templates = {}, schemas = {},
if (methods) {
data = data
.replace(/\$\{toc.methods\}/g, methods.filter(isTocMethod).map(m => ' - [' + m.name + '](#' + m.name.toLowerCase() + ')').join('\n'))
// .replace(/\$\{toc.events\}/g, methods.filter(m => isEvent(m) && !isProviderMethod(m)).map(m => ' - [' + m.name[2].toLowerCase() + m.name.substr(3) + '](#' + m.name.substr(2).toLowerCase() + ')').join('\n'))
.replace(/\$\{toc.providers\}/g, capabilities.map(c => ` - [${getProviderName(c, moduleJson, schemas)}](#${getProviderName(c, moduleJson, schemas).toLowerCase()})`).join('\n'))
}

Expand Down Expand Up @@ -985,7 +983,7 @@ function getExternalSchemaLinks(json = {}, schemas = {}, options = {}) {

function generateJavaScriptExample(example, m, moduleJson = {}, templates = {}) {
if (m.name.match(/^on[A-Z]/)) {
if (isProviderMethod(m)) {
if (isProviderInterfaceMethod(m)) {
return generateProviderExample(m, moduleJson, templates)
} else {
return generateEventExample(m, moduleJson)
Expand Down
8 changes: 4 additions & 4 deletions util/sdk/macros/index.mjs
Expand Up @@ -30,7 +30,7 @@ import predicates from 'crocks/predicates/index.js'
import isNil from 'crocks/core/isNil.js'
const { isObject, isArray, propEq, pathSatisfies, propSatisfies } = predicates

import { isExcludedMethod, isRPCOnlyMethod, isProviderMethod, getPayloadFromEvent, providerHasNoParameters, isTemporalSetMethod, hasMethodAttributes, getMethodAttributes, isEventMethodWithContext } from '../../shared/modules.mjs'
import { isExcludedMethod, isRPCOnlyMethod, isProviderInterfaceMethod, getPayloadFromEvent, providerHasNoParameters, isTemporalSetMethod, hasMethodAttributes, getMethodAttributes, isEventMethodWithContext } from '../../shared/modules.mjs'
import { getTemplateForMethod } from '../../shared/template.mjs'
import { getMethodSignatureParams } from '../../shared/javascript.mjs'
import isEmpty from 'crocks/core/isEmpty.js'
Expand Down Expand Up @@ -164,7 +164,7 @@ const providedCapabilitiesOrEmptyArray = compose(
option([]),
map(caps => [... new Set(caps)]),
map(map(m => m.tags.find(t => t['x-provides'])['x-provides'])), // grab the capabilty it provides
map(filter(isProviderMethod)),
map(filter(isProviderInterfaceMethod)),
getMethods
)

Expand All @@ -180,7 +180,7 @@ const providersOrEmptyArray = compose(
}
return e
})),
map(filter(isProviderMethod)),
map(filter(isProviderInterfaceMethod)),
getMethods
)

Expand Down Expand Up @@ -469,7 +469,7 @@ function generateMethods(json = {}, templates = {}, onlyEvents = false) {
option([]),
map(filter(m => !onlyEvents || isEventMethod(m))),
map(filter(not(isRPCOnlyMethod))),
map(filter(not(isProviderMethod))),
map(filter(not(isProviderInterfaceMethod))),
map(filter(not(isExcludedMethod))),
getMethods
)(json)
Expand Down
2 changes: 2 additions & 0 deletions util/shared/helpers.mjs
Expand Up @@ -55,6 +55,7 @@ const clearDirectory = dir => fsRemoveDirectory(dir, {recursive: true})
const isFile = dir => fsStat(dir).map(statObj => statObj.isFile())

const logSuccess = message => console.log(`\x1b[32m ✓ \x1b[0m\x1b[2m ${message}\x1b[0m`)
const logInfo = message => console.log(`\x1b[38;5;202m ⓘ \x1b[0m\x1b[2m ${message}\x1b[0m`)
const logError = message => console.log(`\x1b[31m ✗ \x1b[0m\x1b[2m ${message}\x1b[0m`)
const logHeader = message => console.log(`\x1b[0m\x1b[7m\x1b[32m${message}\x1b[0m\n`)

Expand Down Expand Up @@ -277,6 +278,7 @@ export {
fsWriteFile,
fsReadFile,
logSuccess,
logInfo,
logError,
logHeader,
getFilename,
Expand Down

0 comments on commit 28b0ba5

Please sign in to comment.