-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaceInfo.js
More file actions
60 lines (51 loc) · 2.07 KB
/
interfaceInfo.js
File metadata and controls
60 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// @ts-check
const contentKind = {
Telemetry: 'Telemetry',
Property: 'Property',
Command: 'Command',
Component: 'Component',
Relationship: 'Relationship'
}
export const InterfaceInfo = (
/** @type import("./DtdlOM").DtdlObjectModel */om,
/** @type {String} */ dtmi) => {
/** @type {Array<import("./DtdlOM").TelemetryInfo>} */
const telemetries = []
/** @type {Array<import("./DtdlOM").PropertyInfo>} */
const properties = []
/** @type {Array<import("./DtdlOM").CommandInfo>} */
const commands = []
/** @type {Array<import("./DtdlOM").ComponentInfo>} */
const components = []
/** @type {Array<import("./DtdlOM").RelationshipInfo>} */
const relationships = []
const root = /** @type import("./DtdlOM").InterfaceInfo*/(om[dtmi])
Object.entries(root.contents).forEach(c => {
const elDtmi = c[1]
const el = om[elDtmi]
switch(el.EntityKind) {
case contentKind.Property:
properties.push(/** @type {import("./DtdlOM").PropertyInfo} */(el))
break
case contentKind.Telemetry:
telemetries.push(/** @type {import("./DtdlOM").TelemetryInfo} */(el))
break
case contentKind.Command:
commands.push(/** @type {import("./DtdlOM").CommandInfo} */(el))
break
case contentKind.Component:
components.push(/** @type {import("./DtdlOM").ComponentInfo} */(el))
break
case contentKind.Relationship:
relationships.push(/** @type {import("./DtdlOM").RelationshipInfo} */(el))
break
}
})
const print = (outFn) => {
if (!(outFn instanceof Function)) outFn = console.log
telemetries.forEach(t => outFn(` [T] ${t.name} ${t.schema}`))
properties.forEach(p => outFn(` [P] ${p.name} ${p.schema}`))
commands.forEach(c => outFn(` [C] ${c.name} req: ${c.request} resp: ${c.response}`))
}
return { telemetries, properties, commands, components, relationships, print }
}