-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
patch.go
64 lines (56 loc) · 1.81 KB
/
patch.go
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
61
62
63
64
package main
import (
"fmt"
"github.com/ysmood/gson"
)
func patch(json gson.JSON) {
k := func(k, v string) gson.Query {
return func(obj interface{}) (val interface{}, has bool) {
for _, el := range obj.([]interface{}) {
res := el.(map[string]interface{})[k]
if res == v {
return el, true
}
}
panic("not found")
}
}
index := func(obj interface{}, k, v string) string {
for i, el := range obj.([]interface{}) {
res := el.(map[string]interface{})[k]
if res == v {
return fmt.Sprintf("%d", i)
}
}
panic("not found")
}
getTypes := func(domain string) gson.JSON {
res, _ := json.Gets("domains", k("domain", domain), "types")
return res
}
// TargetTargetInfoType
j, _ := getTypes("Target").Gets(k("id", "TargetInfo"), "properties", k("name", "type"))
j.Set("enum", []string{
"page", "background_page", "service_worker", "shared_worker", "browser", "other",
})
// PageLifecycleEventName
j, _ = json.Gets("domains", k("domain", "Page"), "events", k("name", "lifecycleEvent"), "parameters", k("name", "name"))
j.Set("enum", []string{
"init", "firstPaint", "firstContentfulPaint", "firstImagePaint", "firstMeaningfulPaintCandidate",
"DOMContentLoaded", "load", "networkAlmostIdle", "firstMeaningfulPaint", "networkIdle",
})
// replace these with better type definition
j, _ = getTypes("Input").Gets(k("id", "TimeSinceEpoch"))
j.Set("skip", true)
j, _ = getTypes("Network").Gets(k("id", "TimeSinceEpoch"))
j.Set("skip", true)
j, _ = getTypes("Network").Gets(k("id", "MonotonicTime"))
j.Set("skip", true)
// fix Cookie.Expires
j, _ = getTypes("Network").Gets(k("id", "Cookie"), "properties")
j.Set(index(j.Val(), "name", "expires"), map[string]interface{}{
"$ref": "TimeSinceEpoch",
"description": "Cookie expiration date",
"name": "expires",
})
}