-
Notifications
You must be signed in to change notification settings - Fork 2
/
runtime.js
54 lines (49 loc) · 1.25 KB
/
runtime.js
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
'use strict'
const {
getEventPropertyLookup,
getEventTypeWithProperties,
} = require('./events')
function getRuntimeEventTypes(runtime) {
if (!runtime) return []
let propertyTypeLookup
const eventTypes = runtime.getEventTypesList().map(eventType => {
if (!propertyTypeLookup)
propertyTypeLookup = getEventPropertyLookup(eventType)
return {
name: eventType.getName(),
properties: getEventTypeWithProperties({ eventType, propertyTypeLookup }),
}
})
return eventTypes
}
function getRuntimeEventProperties({
runtime,
eventTypes = getRuntimeEventTypes(runtime),
}) {
const allProperties = []
eventTypes.forEach(({ name: eventName, properties }) => {
properties.forEach(({ name: propName, type, hasMultiple }) => {
const match = allProperties.find(
prop =>
prop.name === propName &&
prop.type === type &&
prop.hasMultiple === hasMultiple
)
if (match) {
match.eventTypes.push(eventName)
} else {
allProperties.push({
name: propName,
eventTypes: [eventName],
type,
hasMultiple,
})
}
})
})
return allProperties
}
module.exports = {
getRuntimeEventTypes,
getRuntimeEventProperties,
}