-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
131 lines (122 loc) · 4.45 KB
/
example.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const definitionSet = require('./receiver/definition-set.js');
const exampleData = [
{
id: 'https://map.naver.com/external/vis?request=getSimpleVersion&apiVersion=1.0&output=json&addversion=true',
json: {
"result": {
"region": {
"rcode": "02190800",
"doCode": "0200000000",
"doName": "경기도",
"siCode": "0219000000",
"siName": "부천시",
"dongCode": "02190800",
"dongName": "성곡동",
"xPos": "126.80348",
"yPos": "37.51675"
},
"weather": {
"weatherCode": "1",
"weatherText": "맑음",
"temperature": "4.0",
"iconURL": "https://ssl.pstatic.net/static/weather/images/w_icon/w_s1.gif",
"detailURL": "http://weather.naver.com/rgn/townWetr.nhn?naverRgnCd=02190800"
}
}
}
},
{
id: 'https://www.facebook.com/api/graphql/',
json: {
data: {
"feedback": {
"can_viewer_react": true,
"viewer_feedback_reaction_info": null,
"id": "ZmVlZGJhY2s6MjEzNzA5MzQ5NjM0MTg5MA==",
"viewer_current_actor": {
"__typename": "User",
"id": "100009173416209"
},
"supported_reactions": [
{
"key": 1
},
{
"key": 2
},
{
"key": 4
},
{
"key": 3
},
{
"key": 7
},
{
"key": 8
}
],
"top_reactions": {
"edges": [
{
"reaction_count": 461,
"node": {
"key": 1,
"id": "1635855486666999"
}
},
{
"reaction_count": 180,
"node": {
"key": 4,
"id": "115940658764963"
}
},
{
"reaction_count": 39,
"node": {
"key": 2,
"id": "1678524932434102"
}
},
{
"reaction_count": 14,
"node": {
"key": 3,
"id": "478547315650144"
}
}
]
},
"reactors": {
"count": 694
}
}
}
}
}
];
exampleData.forEach((example, index) => {
console.log(`***** EXAMPLE ${index} *****`);
const { id: exampleId, json: originalJSON } = example;
console.log('original JSON:\n', originalJSON, '\n')
/**
* NOTE: You can create NOSJ only from the JSON whose model is defined in your definition.
* If not, You cannot recover the NOSJ.
*
* Sender creates NOSJ to send JSON.
*/
const uglify = require('./sender/uglify.js');
const nosj = uglify(originalJSON, exampleId);
console.log('NOSJ:\n', nosj.data, '\n');
/**
* NOTE: Receiver and sender have to share the same definition.
*
* Receiver reads the NOSJ and beautifies it using the definition.
*/
const beautify = require('./receiver/beautify.js');
const definition = definitionSet[exampleId];
const recoveredJson = beautify(nosj.data, definition);
console.log('recovered JSON:\n', recoveredJson, '\n');
});