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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
'use strict';
const common = require(__dirname + '/common');
const cleaner = require(__dirname + '/cleaner');
/**
* Complete a doc element with info found in table
* @param {HTMLTableRowElement[]} rows The table rows
* @param {Object} doc The doc object
*/
function completeDoc($, rows, doc) {
$(rows).each((i, elem) => {
let tds = $(elem).find('td'); // first is key and last is value
var name = tds
.first()
.text()
.toLowerCase()
.trim();
var value = tds.last();
switch (name) {
case 'dynamic':
doc.dynamic =
value
.text()
.toLowerCase()
.trim() === 'yes';
break;
case 'name':
doc.name = value.text().trim();
break;
case 'system variable':
// Do not overwrite the name
if (typeof doc.name === 'undefined') {
doc.name = value
.text()
.toLowerCase()
.trim();
}
break;
case 'scope':
let scope = value.text().toLowerCase();
if (scope === 'both') {
// found on mysql-cluster-options-variables.html
doc.scope = ['global', 'session'];
} else if (scope != '') {
doc.scope = scope.split(',').map(item => {
if (item.match(/session/)) {
return 'session';
} else if (item.match(/global/)) {
return 'global';
} else {
return item.trim();
}
});
}
if (doc.scope !== undefined) {
doc.scope = doc.scope.filter(function(e) {
return e === 0 || e;
});
}
break;
case 'type':
let type = value
.text()
.toLowerCase()
.trim();
if (type != '') {
doc.type = cleaner.cleanType(type);
}
break;
case 'default value':
case 'default, range':
doc.default = cleaner.cleanDefault(value.text().trim());
break;
case 'valid values':
doc.validValues = $(value)
.find('code')
.get()
.map(el => $(el).text());
break;
case 'minimum value':
if (doc.range == undefined) {
doc.range = {};
}
doc.range.from = parseFloat(value.text().trim());
break;
case 'maximum value':
if (doc.range == undefined) {
doc.range = {};
}
doc.range.to = parseFloat(value.text().trim());
break;
case 'command-line format':
doc.cli = cleaner.cleanCli(value.text().trim());
break;
case 'command line':
if (typeof doc.cli !== 'string') {
doc.cli =
value
.text()
.toLowerCase()
.trim() === 'yes';
}
break;
}
});
}
/**
* Create a doc element
* @param {Element} element The root element
* @returns object The doc object
*/
function createDoc($, element, doc) {
completeDoc($, $(element).find('tbody > tr'), doc);
if (doc.range !== undefined) {
doc.range = cleaner.cleanRange(doc.range);
}
if (doc.name && doc.name.match(cleaner.regexCli)) {
delete doc.name;
}
return doc;
}
function parsePage($, cbSuccess) {
var anchors = [];
$('.informaltable, .table')
.filter(function(i, elem) {
return (
$(elem)
.find('th')
.first()
.text() === 'Property'
);
})
.each(function(i, elem) {
let doc = {
id: $(elem)
.prevAll()
.find('a')
.filter(function(i, el) {
return typeof $(el).attr('name') === 'string' && typeof $(el).attr('class') === 'undefined';
})
.first()
.attr('name'),
};
if (typeof doc.id !== 'string') {
doc.id = $(elem)
.prevAll()
.find('.link')
.first()
.attr('href')
.split('#')[1];
}
createDoc($, elem, doc);
if (typeof doc.cli === 'boolean') {
doc.cli = $(elem)
.prevAll()
.find('.option')
.first()
.text();
if (doc.cli === '') {
delete doc.cli;
}
}
if (!doc.name && doc.cli) {
var matches = doc.cli.match(cleaner.regexCli);
doc.name = matches[2].replace(/-/g, '_');
}
anchors.push(doc);
});
cbSuccess(anchors);
}
const KB_URL = 'https://dev.mysql.com/doc/refman/8.0/en/';
const KB_URL57 = 'https://dev.mysql.com/doc/refman/5.7/en/';
const pages = [
{
url: KB_URL + 'server-system-variables.html',
name: 'server-system-variables',
},
{
url: KB_URL + 'innodb-parameters.html',
name: 'innodb-parameters',
},
{
url: KB_URL + 'performance-schema-system-variables.html',
name: 'performance-schema-system-variables',
},
{
url: KB_URL + 'x-plugin-options-system-variables.html',
name: 'x-plugin-options-system-variables',
},
{
url: KB_URL + 'replication-options-binary-log.html',
name: 'replication-options-binary-log',
},
{
url: KB_URL57 + 'replication-options-binary-log.html',
name: 'replication-options-binary-log_5.7',
},
{
url: KB_URL + 'pluggable-authentication-system-variables.html',
name: 'pluggable-authentication-system-variables',
},
{
url: KB_URL + 'audit-log-reference.html',
name: 'audit-log-reference',
},
{
url: KB_URL + 'replication-options-gtids.html',
name: 'replication-options-gtids',
},
{
url: KB_URL + 'replication-options-slave.html',
name: 'replication-options-slave',
},
{
url: KB_URL + 'replication-options-master.html',
name: 'replication-options-master',
},
{
url: KB_URL + 'replication-options.html',
name: 'replication-options',
},
{
url: KB_URL57 + 'mysql-cluster-options-variables.html',
name: 'mysql-cluster-options-variables',
},
{
url: KB_URL + 'server-options.html',
name: 'server-options',
},
{
url: KB_URL + 'version-tokens-reference.html',
name: 'version-tokens-reference',
},
];
module.exports = {
parsePage: parsePage,
createDoc: createDoc,
completeDoc: completeDoc,
run: () => {
return common.processDataExtraction(pages, 'mysql-', parsePage);
},
};
|