* Build the binding-neutral model from the AST. Type refs are CDDL names. * Shape per domain key: * { commands: [{ method, name, params, result }], * events: [{ method, name, params }] } * `params`/`result` are null when there are no params / no return value.
(ast)
| 628 | * `params`/`result` are null when there are no params / no return value. |
| 629 | */ |
| 630 | function buildModel(ast) { |
| 631 | const model = {} |
| 632 | const resultTypes = buildResultTypeNames(ast) |
| 633 | const ensure = (domain) => (model[domain] ??= { commands: [], events: [] }) |
| 634 | |
| 635 | for (const c of extractCommands(ast)) { |
| 636 | const result = c.cddlName + 'Result' |
| 637 | ensure(c.domain).commands.push({ |
| 638 | method: c.methodStr, |
| 639 | name: c.methodName, |
| 640 | params: c.hasParams ? c.paramsCddl : null, |
| 641 | result: resultTypes.has(result) ? result : null, |
| 642 | }) |
| 643 | } |
| 644 | |
| 645 | for (const e of extractEvents(ast)) { |
| 646 | ensure(e.domain).events.push({ |
| 647 | method: e.methodStr, |
| 648 | name: e.eventName, |
| 649 | params: e.paramsCddl || null, |
| 650 | }) |
| 651 | } |
| 652 | |
| 653 | return model |
| 654 | } |
| 655 | |
| 656 | /** Result type names the spec defines with a value; an absent or `EmptyResult`-aliased result is void. */ |
| 657 | function buildResultTypeNames(ast) { |
no test coverage detected