@ygracs/xepg-lib-js 0.0.19 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -76
- package/LICENSE +1 -1
- package/README.md +10 -8
- package/doc/xepgdoc-lib.md +332 -83
- package/doc/xepgdoc-spec-draft.dtd +65 -0
- package/index.js +5 -2
- package/lib/dts-helper.js +81 -32
- package/lib/file-helper.js +278 -0
- package/lib/xepgdoc-lib.js +580 -301
- package/package.json +7 -5
package/lib/xepgdoc-lib.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.081-20250227]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const fse = require('fs').promises;
|
|
7
5
|
const xmlParser = require('@ygracs/xml-js6');
|
|
8
6
|
|
|
9
7
|
const {
|
|
@@ -18,10 +16,15 @@ const {
|
|
|
18
16
|
} = require('@ygracs/dtf-lib-js');
|
|
19
17
|
|
|
20
18
|
const {
|
|
21
|
-
chkDTSysID,
|
|
19
|
+
chkDTSysID, getDTSysDescr,
|
|
22
20
|
convStringToDTValue, convDTValueToString,
|
|
23
21
|
} = require('./dts-helper.js');
|
|
24
22
|
|
|
23
|
+
const {
|
|
24
|
+
loadFileSync, loadFile,
|
|
25
|
+
saveToFileSync, saveToFile,
|
|
26
|
+
} = require('./file-helper.js');
|
|
27
|
+
|
|
25
28
|
const xObj = require('@ygracs/xobj-lib-js');
|
|
26
29
|
|
|
27
30
|
const TXmlContentParseOptions = xObj.TXmlContentParseOptions;
|
|
@@ -62,8 +65,8 @@ function writeXEpgDocDeclSection(obj, opt){
|
|
|
62
65
|
let doc_def_enc = XEPG_DEF_ENCODING_VALUE;
|
|
63
66
|
let key_name = defParseOptions.settings.declarationKey;
|
|
64
67
|
if (isPlainObject(opt)) {
|
|
65
|
-
xml_ver = readAsString(opt.version, xml_ver);
|
|
66
|
-
doc_def_enc = readAsString(opt.encoding, doc_def_enc);
|
|
68
|
+
xml_ver = readAsString(opt.version, { defValue: xml_ver });
|
|
69
|
+
doc_def_enc = readAsString(opt.encoding, { defValue: doc_def_enc });
|
|
67
70
|
};
|
|
68
71
|
if (isPlainObject(obj) && isNotEmptyString(key_name)) {
|
|
69
72
|
obj[key_name] = {};
|
|
@@ -72,34 +75,6 @@ function writeXEpgDocDeclSection(obj, opt){
|
|
|
72
75
|
};
|
|
73
76
|
};
|
|
74
77
|
|
|
75
|
-
/**
|
|
76
|
-
* @function checkFsError
|
|
77
|
-
* @param {object}
|
|
78
|
-
* @param {Error}
|
|
79
|
-
* @returns {object}
|
|
80
|
-
* @inner
|
|
81
|
-
* @description Checs an error code of a fs ops and sets descr info if succeed
|
|
82
|
-
*/
|
|
83
|
-
function checkFsError(descr, err) {
|
|
84
|
-
let isSucceed = false;
|
|
85
|
-
if (isPlainObject(err) && isPlainObject(descr)) {
|
|
86
|
-
switch (err.code) {
|
|
87
|
-
case 'ENOENT':
|
|
88
|
-
case 'EISDIR':
|
|
89
|
-
case 'EPERM': {
|
|
90
|
-
descr.errCode = err.errno;
|
|
91
|
-
descr.errEvent = err.code;
|
|
92
|
-
descr.errMsg = `ERR_FILE_${err.code}`;
|
|
93
|
-
isSucceed = true;
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
default: {}
|
|
97
|
-
};
|
|
98
|
-
if (isSucceed) descr.isERR = true;
|
|
99
|
-
};
|
|
100
|
-
return { isSucceed, descr };
|
|
101
|
-
};
|
|
102
|
-
|
|
103
78
|
// === module main block ===
|
|
104
79
|
|
|
105
80
|
/***
|
|
@@ -165,14 +140,35 @@ const defParseOptions = new TXmlContentParseOptions();
|
|
|
165
140
|
*/
|
|
166
141
|
|
|
167
142
|
/**
|
|
168
|
-
* @
|
|
143
|
+
* @typedef {Object} xepgShedInfoDesc
|
|
144
|
+
* @property {number} time - a schedule start time
|
|
145
|
+
* @property {string} title - schedule title
|
|
146
|
+
* @property {string} [cat] - schedule category
|
|
147
|
+
* @property {number} [pcmark] - schedule rating
|
|
148
|
+
* @property {string} [descr] - schedule description
|
|
149
|
+
* @description A schedule info descriptor
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @classdesc This class implements an interface of a EPG-schedules list
|
|
169
154
|
*/
|
|
170
155
|
class TXEpgSchedulesList {
|
|
171
|
-
|
|
172
|
-
#
|
|
156
|
+
/** @property {object[]} */
|
|
157
|
+
#_content;// = null;
|
|
158
|
+
/** @property {object} */
|
|
159
|
+
#_options;// = null;
|
|
160
|
+
/** @property {?object} */
|
|
173
161
|
#_dts_src = null;
|
|
162
|
+
/** @property {?object} */
|
|
174
163
|
#_tz_src = null;
|
|
175
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @param {any[]} obj - list of an elements
|
|
167
|
+
* @param {object} [opt] - options
|
|
168
|
+
* @param {?object} [opt.dts_src]
|
|
169
|
+
* @param {?object} [opt.tz_src]
|
|
170
|
+
* @description Creates an instance of the schedules list
|
|
171
|
+
*/
|
|
176
172
|
constructor(obj, opt) {
|
|
177
173
|
const _content = isArray(obj) ? obj : [];
|
|
178
174
|
const _options = isPlainObject(opt) ? opt : {};
|
|
@@ -188,27 +184,48 @@ class TXEpgSchedulesList {
|
|
|
188
184
|
this.#_tz_src = tz_src;
|
|
189
185
|
}
|
|
190
186
|
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
/**
|
|
188
|
+
* @param {(number|string)} value - element index
|
|
189
|
+
* @returns {any}
|
|
190
|
+
* @private
|
|
191
|
+
* @description Returns a raw schedule element
|
|
192
|
+
*/
|
|
193
|
+
#_getItem = function(value) {
|
|
194
|
+
if (this.chkIndex(value)) {
|
|
193
195
|
return this.#_content[Number(value)];
|
|
194
196
|
};
|
|
195
197
|
};
|
|
196
198
|
|
|
197
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Contains a quantity of a schedules
|
|
201
|
+
* @property {number}
|
|
202
|
+
* @readonly
|
|
203
|
+
*/
|
|
204
|
+
get schedQty() {
|
|
198
205
|
return this.#_content.length;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
208
|
// will deprecate
|
|
202
209
|
//get SchedulesQty(){ return this.#_content.length; }
|
|
203
210
|
|
|
204
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Contains a dtstype ID
|
|
213
|
+
* @property {number}
|
|
214
|
+
* @readonly
|
|
215
|
+
*/
|
|
216
|
+
get dtstype() {
|
|
205
217
|
let result = valueToIndex(
|
|
206
218
|
_getXmlChildElementParam(this.#_dts_src, 'value')
|
|
207
219
|
);
|
|
208
220
|
return chkDTSysID(result) ? result : 0; //-1; // // TODO: [?]
|
|
209
221
|
}
|
|
210
222
|
|
|
211
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Contains a TZ-offset
|
|
225
|
+
* @property {number}
|
|
226
|
+
* @readonly
|
|
227
|
+
*/
|
|
228
|
+
get curDocTZ() {
|
|
212
229
|
return (
|
|
213
230
|
this.#_tz_src
|
|
214
231
|
? convTZStringToValue(readXObjParam(this.#_tz_src).trim())
|
|
@@ -216,20 +233,52 @@ class TXEpgSchedulesList {
|
|
|
216
233
|
);
|
|
217
234
|
}
|
|
218
235
|
|
|
219
|
-
|
|
236
|
+
/**
|
|
237
|
+
* @returns {boolean}
|
|
238
|
+
* @description Indicates whether an instance has none member
|
|
239
|
+
*/
|
|
240
|
+
hasNoSchedules() {
|
|
220
241
|
return this.schedQty === 0;
|
|
221
242
|
}
|
|
222
243
|
|
|
223
|
-
|
|
244
|
+
/**
|
|
245
|
+
* @returns {boolean}
|
|
246
|
+
* @description Indicates whether an instance has any member
|
|
247
|
+
*/
|
|
248
|
+
hasSchedules() {
|
|
224
249
|
return this.schedQty > 0;
|
|
225
250
|
}
|
|
226
251
|
|
|
227
|
-
|
|
252
|
+
/**
|
|
253
|
+
* @param {(number|string)} value
|
|
254
|
+
* @returns {boolean}
|
|
255
|
+
* @deprecated
|
|
256
|
+
* @description Checks whether a given value is a valid index
|
|
257
|
+
* and it fits the index range of an instance
|
|
258
|
+
*/
|
|
259
|
+
chkScheduleIndex(value) {
|
|
260
|
+
return this.chkIndex(value);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @param {(number|string)} value - index of some element
|
|
265
|
+
* @returns {boolean}
|
|
266
|
+
* @since 0.0.18
|
|
267
|
+
* @description Checks whether a given value is a valid index
|
|
268
|
+
* and it fits the index range of an instance
|
|
269
|
+
*/
|
|
270
|
+
chkIndex(value) {
|
|
228
271
|
const index = valueToIndex(value);
|
|
229
272
|
return index !== -1 && index < this.schedQty;
|
|
230
273
|
}
|
|
231
274
|
|
|
232
|
-
|
|
275
|
+
/**
|
|
276
|
+
* @param {(number|string)} index - index of some element
|
|
277
|
+
* @returns {xepgShedInfoDesc}
|
|
278
|
+
* @description Returns a schedule info item for instance element
|
|
279
|
+
* addressed by a given index
|
|
280
|
+
*/
|
|
281
|
+
getScheduleInfo(index) {
|
|
233
282
|
//console.log('TXEpgSchedulesList => getScheduleInfo() => was called...');
|
|
234
283
|
const curObj = this.#_getItem(index);
|
|
235
284
|
let tmpObj = {};
|
|
@@ -257,7 +306,11 @@ class TXEpgSchedulesList {
|
|
|
257
306
|
return tmpObj;
|
|
258
307
|
}
|
|
259
308
|
|
|
260
|
-
|
|
309
|
+
/**
|
|
310
|
+
* @returns {xepgShedInfoDesc[]}
|
|
311
|
+
* @description Returns a schedule info for instance members
|
|
312
|
+
*/
|
|
313
|
+
getAllSchedulesInfo() {
|
|
261
314
|
let result = [];
|
|
262
315
|
for (let i = 0; i < this.schedQty; i++) {
|
|
263
316
|
let item = this.getScheduleInfo(i);
|
|
@@ -266,22 +319,45 @@ class TXEpgSchedulesList {
|
|
|
266
319
|
return result;
|
|
267
320
|
}
|
|
268
321
|
|
|
269
|
-
|
|
322
|
+
/**
|
|
323
|
+
* @protected
|
|
324
|
+
*/
|
|
325
|
+
asJSON() {
|
|
270
326
|
return JSON.stringify(this.#_content, null, 2);
|
|
271
327
|
}
|
|
272
328
|
|
|
273
329
|
};
|
|
274
330
|
|
|
275
331
|
/**
|
|
276
|
-
* @
|
|
332
|
+
* @typedef {Object} xepgProvInfoDesc
|
|
333
|
+
* @property {string} [name] - provider name
|
|
334
|
+
* @property {string} [version] - provider version
|
|
335
|
+
* @property {string} schema - document schema
|
|
336
|
+
* @property {string} doctype - document type
|
|
337
|
+
* @description A provider info descriptor
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @classdesc This class implements an interface of a EPG-provider element
|
|
277
342
|
*/
|
|
278
343
|
class TXEpgProviderContainer {
|
|
279
|
-
|
|
280
|
-
#
|
|
344
|
+
/** @property {Object} */
|
|
345
|
+
#_host;// = null;
|
|
346
|
+
/** @property {Object} */
|
|
347
|
+
#_options;// = null;
|
|
348
|
+
/** @property {TXmlContentParseOptions} */
|
|
349
|
+
#_parseOptions;// = null;
|
|
350
|
+
/** @property {?TXEpgDTSProvider} */
|
|
281
351
|
|
|
352
|
+
/**
|
|
353
|
+
* @param {object} obj
|
|
354
|
+
* @param {object} [opt] - options
|
|
355
|
+
* @param {object} [opt.parseOptions]
|
|
356
|
+
* @description Creates an instance of the EPG-provider element
|
|
357
|
+
*/
|
|
282
358
|
constructor(obj, opt) {
|
|
283
359
|
// load content
|
|
284
|
-
const
|
|
360
|
+
const _host = isPlainObject(obj) ? obj : {};
|
|
285
361
|
// load options
|
|
286
362
|
const _options = isPlainObject(opt) ? opt : {};
|
|
287
363
|
let {
|
|
@@ -291,10 +367,12 @@ class TXEpgProviderContainer {
|
|
|
291
367
|
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
292
368
|
_options.parseOptions = parseOptions;
|
|
293
369
|
};
|
|
294
|
-
// save content source
|
|
295
|
-
this.#_content = _content;
|
|
296
370
|
// save options
|
|
297
371
|
this.#_options = _options;
|
|
372
|
+
// save parser options
|
|
373
|
+
this.#_parseOptions = parseOptions;
|
|
374
|
+
// save content source
|
|
375
|
+
this.#_host = _host;
|
|
298
376
|
// init instance
|
|
299
377
|
this.#_init();
|
|
300
378
|
}
|
|
@@ -311,69 +389,86 @@ class TXEpgProviderContainer {
|
|
|
311
389
|
//_options.docTypeETagName = docTypeETagName;
|
|
312
390
|
}
|
|
313
391
|
|
|
314
|
-
|
|
315
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Contains a provider name
|
|
394
|
+
* @property {string}
|
|
395
|
+
*/
|
|
396
|
+
get name() {
|
|
397
|
+
return _getXmlChildElementParam(this.#_host, 'name').trim();
|
|
316
398
|
}
|
|
317
399
|
|
|
318
|
-
set name(value){
|
|
400
|
+
set name(value) {
|
|
319
401
|
this.setName(value);
|
|
320
402
|
}
|
|
321
403
|
|
|
322
|
-
|
|
323
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Contains a version of a provider
|
|
406
|
+
* @property {string}
|
|
407
|
+
*/
|
|
408
|
+
get version() {
|
|
409
|
+
return _getXmlChildElementParam(this.#_host, 'version').trim();
|
|
324
410
|
}
|
|
325
411
|
|
|
326
|
-
set version(value){
|
|
327
|
-
if (this.name !== '') {
|
|
328
|
-
const
|
|
329
|
-
const item = insertXObjElement(
|
|
330
|
-
|
|
331
|
-
'version',
|
|
332
|
-
{ force: true },
|
|
333
|
-
);
|
|
334
|
-
if (item) writeXObjParam(item, _value);
|
|
412
|
+
set version(value) {
|
|
413
|
+
if (typeof value === 'string' && this.name !== '') {
|
|
414
|
+
const opt = { force: true };
|
|
415
|
+
const item = insertXObjElement(this.#_host, 'version', opt);
|
|
416
|
+
if (item) writeXObjParam(item, value.trim());
|
|
335
417
|
};
|
|
336
418
|
}
|
|
337
419
|
|
|
338
|
-
|
|
339
|
-
|
|
420
|
+
/**
|
|
421
|
+
* Contains a version of a document schema
|
|
422
|
+
* @property {string}
|
|
423
|
+
*/
|
|
424
|
+
get schema() {
|
|
425
|
+
return _getXmlChildElementParam(this.#_host, XEPG_DOCSCH_ETAG_NAME).trim();
|
|
340
426
|
}
|
|
341
427
|
|
|
342
|
-
set schema(value){
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
this.#
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
349
|
-
if (item) writeXObjParam(item, _value);
|
|
428
|
+
set schema(value) {
|
|
429
|
+
if (typeof value === 'string') {
|
|
430
|
+
const opt = { force: true };
|
|
431
|
+
const item = insertXObjElement(this.#_host, XEPG_DOCSCH_ETAG_NAME, opt);
|
|
432
|
+
if (item) writeXObjParam(item, value.trim());
|
|
433
|
+
};
|
|
350
434
|
}
|
|
351
435
|
|
|
352
|
-
|
|
353
|
-
|
|
436
|
+
/**
|
|
437
|
+
* Contains a document type
|
|
438
|
+
* @property {string}
|
|
439
|
+
*/
|
|
440
|
+
get doctype() {
|
|
441
|
+
return _getXmlChildElementParam(this.#_host, XEPG_DOCTYP_ETAG_NAME).trim();
|
|
354
442
|
}
|
|
355
443
|
|
|
356
|
-
set doctype(value){
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
this.#
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
);
|
|
363
|
-
if (item) writeXObjParam(item, _value);
|
|
444
|
+
set doctype(value) {
|
|
445
|
+
if (typeof value === 'string') {
|
|
446
|
+
const opt = { force: true };
|
|
447
|
+
const item = insertXObjElement(this.#_host, XEPG_DOCTYP_ETAG_NAME, opt);
|
|
448
|
+
if (item) writeXObjParam(item, value.trim());
|
|
449
|
+
};
|
|
364
450
|
}
|
|
365
451
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
452
|
+
/**
|
|
453
|
+
* @param {string} value - provider name
|
|
454
|
+
* @returns {boolean}
|
|
455
|
+
* @description Sets a provider name
|
|
456
|
+
*/
|
|
457
|
+
setName(value) {
|
|
458
|
+
let isSucceed = false;
|
|
459
|
+
if (typeof value === 'string') {
|
|
460
|
+
const name = value.trim();
|
|
461
|
+
const item = insertXObjElement(this.#_host, 'name', { force: true });
|
|
462
|
+
if (item) isSucceed = writeXObjParam(item, name);
|
|
372
463
|
};
|
|
373
|
-
return
|
|
464
|
+
return isSucceed;
|
|
374
465
|
}
|
|
375
466
|
|
|
376
|
-
|
|
467
|
+
/**
|
|
468
|
+
* @returns {xepgProvInfoDesc}
|
|
469
|
+
* @description Returns a provider info item
|
|
470
|
+
*/
|
|
471
|
+
getInfo() {
|
|
377
472
|
return {
|
|
378
473
|
name: this.name,
|
|
379
474
|
version: this.version,
|
|
@@ -382,18 +477,26 @@ class TXEpgProviderContainer {
|
|
|
382
477
|
};
|
|
383
478
|
}
|
|
384
479
|
|
|
385
|
-
|
|
480
|
+
/**
|
|
481
|
+
* @param {(string[]|xepgProvInfoDesc)} obj - provider info descriptor
|
|
482
|
+
* @returns {void}
|
|
483
|
+
* @description Sets a provider info
|
|
484
|
+
* @todo [since v0.0.21] deprecate use of `obj`-param as array
|
|
485
|
+
*/
|
|
486
|
+
setInfo(obj) {
|
|
386
487
|
if (!isObject(obj)) return;
|
|
387
488
|
let name = '';
|
|
388
489
|
let version = '';
|
|
389
490
|
let schema = '';
|
|
390
491
|
let doctype = '';
|
|
391
492
|
if (isArray(obj)) {
|
|
493
|
+
// // TODO: [!] deprecate
|
|
392
494
|
[ name, version, schema, doctype ] = obj;
|
|
393
495
|
} else {
|
|
394
496
|
if (typeof obj.name === 'string') {
|
|
395
497
|
({ name, version, schema, doctype } = obj);
|
|
396
498
|
} else {
|
|
499
|
+
// // TODO: [?] deprecate
|
|
397
500
|
name = _getXmlChildElementParam(obj, 'name');
|
|
398
501
|
version = _getXmlChildElementParam(obj, 'version');
|
|
399
502
|
schema = _getXmlChildElementParam(obj, XEPG_DOCSCH_ETAG_NAME);
|
|
@@ -411,7 +514,12 @@ class TXEpgProviderContainer {
|
|
|
411
514
|
this.doctype = doctype;
|
|
412
515
|
}
|
|
413
516
|
|
|
414
|
-
|
|
517
|
+
/**
|
|
518
|
+
* @param {(xepgProvInfoDesc|string[])} opt - options
|
|
519
|
+
* @returns {void}
|
|
520
|
+
* @description Sets an initial instance state
|
|
521
|
+
*/
|
|
522
|
+
init(opt) {
|
|
415
523
|
let prov_opt = { ...defXEpgDocOptions.defProviderParam };
|
|
416
524
|
let name = '';
|
|
417
525
|
let version = '';
|
|
@@ -433,15 +541,44 @@ class TXEpgProviderContainer {
|
|
|
433
541
|
this.doctype = doctype;
|
|
434
542
|
}
|
|
435
543
|
|
|
544
|
+
/**
|
|
545
|
+
* @returns {string}
|
|
546
|
+
* @since v0.0.20
|
|
547
|
+
* @description Returns an instance content as a string in an XML-format.
|
|
548
|
+
*/
|
|
549
|
+
saveToXMLString() {
|
|
550
|
+
const options = this.#_parseOptions.js2xml;
|
|
551
|
+
options.ignoreDocType = true;
|
|
552
|
+
options.ignoreDeclaration = true;
|
|
553
|
+
const content = { [`${XEPG_PRVINFO_ETAG_NAME}`]: this.#_host };
|
|
554
|
+
let result = '';
|
|
555
|
+
try {
|
|
556
|
+
result = xmlParser.js2xml(content, options);
|
|
557
|
+
} catch (err) {
|
|
558
|
+
//console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
|
|
559
|
+
result = '';
|
|
560
|
+
//throw err;
|
|
561
|
+
};
|
|
562
|
+
return result;
|
|
563
|
+
}
|
|
564
|
+
|
|
436
565
|
};
|
|
437
566
|
|
|
438
567
|
/**
|
|
439
|
-
* @
|
|
568
|
+
* @classdesc This class implements an instance of a DTS-provider element
|
|
440
569
|
*/
|
|
441
|
-
class
|
|
442
|
-
|
|
443
|
-
#
|
|
570
|
+
class TXEpgDTSProvider {
|
|
571
|
+
/** @property {object} */
|
|
572
|
+
#_content;// = null;
|
|
573
|
+
/** @property {object} */
|
|
574
|
+
#_options;// = null;
|
|
444
575
|
|
|
576
|
+
/**
|
|
577
|
+
* @param {object} obj
|
|
578
|
+
* @param {object} [opt] - options
|
|
579
|
+
* @param {object} [opt.parseOptions]
|
|
580
|
+
* @description Creates an instance of the DTS-provider element
|
|
581
|
+
*/
|
|
445
582
|
constructor(obj, opt) {
|
|
446
583
|
// load content
|
|
447
584
|
const _content = isPlainObject(obj) ? obj : {};
|
|
@@ -462,11 +599,19 @@ class TXepgDTSProvider {
|
|
|
462
599
|
this.#_init();
|
|
463
600
|
}
|
|
464
601
|
|
|
465
|
-
|
|
602
|
+
/**
|
|
603
|
+
* @returns {void}
|
|
604
|
+
* @private
|
|
605
|
+
*/
|
|
606
|
+
#_init() {
|
|
466
607
|
insertXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
|
|
467
608
|
}
|
|
468
609
|
|
|
469
|
-
|
|
610
|
+
/**
|
|
611
|
+
* Contains a dtstype ID
|
|
612
|
+
* @property {number}
|
|
613
|
+
*/
|
|
614
|
+
get dtstype() {
|
|
470
615
|
const item = getXObjElement(this.#_content, XEPG_DTSINFO_ETAG_NAME);
|
|
471
616
|
let result = 0; //-1; // // TODO: [?]
|
|
472
617
|
if (isPlainObject(item)) {
|
|
@@ -476,7 +621,7 @@ class TXepgDTSProvider {
|
|
|
476
621
|
return result;
|
|
477
622
|
}
|
|
478
623
|
|
|
479
|
-
set dtstype(value){
|
|
624
|
+
set dtstype(value) {
|
|
480
625
|
let { index, name } = getDTSysDescr(value);
|
|
481
626
|
if (index !== -1) {
|
|
482
627
|
const item = insertXObjElement(
|
|
@@ -497,13 +642,18 @@ class TXepgDTSProvider {
|
|
|
497
642
|
};
|
|
498
643
|
}
|
|
499
644
|
|
|
500
|
-
|
|
501
|
-
|
|
645
|
+
/**
|
|
646
|
+
* Contains a TZ-offset
|
|
647
|
+
* @property {number}
|
|
648
|
+
*/
|
|
649
|
+
get curDocTZ() {
|
|
650
|
+
const tz = convTZStringToValue(
|
|
502
651
|
_getXmlChildElementParam(this.#_content, XEPG_DOCTZ_ETAG_NAME)
|
|
503
652
|
);
|
|
653
|
+
return Number.isNaN(tz) ? 0 : tz;
|
|
504
654
|
}
|
|
505
655
|
|
|
506
|
-
set curDocTZ(value){
|
|
656
|
+
set curDocTZ(value) {
|
|
507
657
|
let _value = convValueToTZString(value);
|
|
508
658
|
if (_value !== '') {
|
|
509
659
|
let item = insertXObjElement(
|
|
@@ -518,18 +668,38 @@ class TXepgDTSProvider {
|
|
|
518
668
|
};
|
|
519
669
|
|
|
520
670
|
/**
|
|
521
|
-
* @
|
|
671
|
+
* @typedef {Object} xepgChnInfoDesc
|
|
672
|
+
* @property {string} chnid - channel ID
|
|
673
|
+
* @property {string} chname - channel name
|
|
674
|
+
* @property {string} [chngid] - channel 'Group ID'
|
|
675
|
+
* @property {string} [srcurl] - EPG-source URL
|
|
676
|
+
* @description A channel info descriptor
|
|
677
|
+
*/
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* @classdesc This class implements an instance of a EPG-header element
|
|
522
681
|
*/
|
|
523
682
|
class TXEpgHeaderContainer {
|
|
524
|
-
|
|
525
|
-
#
|
|
526
|
-
|
|
683
|
+
/** @property {Object} */
|
|
684
|
+
#_host;// = null;
|
|
685
|
+
/** @property {Object} */
|
|
686
|
+
#_options;// = null;
|
|
687
|
+
/** @property {TXmlContentParseOptions} */
|
|
688
|
+
#_parseOptions;// = null;
|
|
689
|
+
/** @property {TXEpgDTSProvider} */
|
|
690
|
+
#_dtsProv;// = null;
|
|
527
691
|
|
|
692
|
+
/**
|
|
693
|
+
* @param {object} obj
|
|
694
|
+
* @param {object} [opt] - options
|
|
695
|
+
* @param {object} [opt.parseOptions]
|
|
696
|
+
* @description Creates an instance of the EPG-header element
|
|
697
|
+
*/
|
|
528
698
|
constructor(obj, opt) {
|
|
529
699
|
// load content
|
|
530
|
-
const
|
|
700
|
+
const _host = isPlainObject(obj) ? obj : {};
|
|
531
701
|
// load options
|
|
532
|
-
|
|
702
|
+
const _options = isPlainObject(opt) ? opt : {};
|
|
533
703
|
let {
|
|
534
704
|
parseOptions,
|
|
535
705
|
} = _options;
|
|
@@ -537,49 +707,79 @@ class TXEpgHeaderContainer {
|
|
|
537
707
|
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
538
708
|
_options.parseOptions = parseOptions;
|
|
539
709
|
};
|
|
540
|
-
// save content source
|
|
541
|
-
this.#_content = _content;
|
|
542
710
|
// save options
|
|
543
711
|
this.#_options = _options;
|
|
712
|
+
// save parser options
|
|
713
|
+
this.#_parseOptions = parseOptions;
|
|
714
|
+
// save content source
|
|
715
|
+
this.#_host = _host;
|
|
544
716
|
// init DTS-provider
|
|
545
|
-
this.#_dtsProv = new
|
|
717
|
+
this.#_dtsProv = new TXEpgDTSProvider(_host, _options);
|
|
546
718
|
}
|
|
547
719
|
|
|
548
|
-
|
|
720
|
+
/**
|
|
721
|
+
* Returns a `TXEpgDTSProvider` instance
|
|
722
|
+
* @property {TXEpgDTSProvider}
|
|
723
|
+
* @readonly
|
|
724
|
+
*/
|
|
725
|
+
get dts() {
|
|
549
726
|
return this.#_dtsProv;
|
|
550
727
|
}
|
|
551
728
|
|
|
552
|
-
|
|
729
|
+
/**
|
|
730
|
+
* Contains a dtstype ID
|
|
731
|
+
* @property {number}
|
|
732
|
+
* @todo [since v0.0.22] becomes readonly
|
|
733
|
+
*/
|
|
734
|
+
get dtstype() {
|
|
553
735
|
return this.#_dtsProv.dtstype;
|
|
554
736
|
}
|
|
555
737
|
|
|
556
|
-
set dtstype(value){
|
|
738
|
+
set dtstype(value) {
|
|
557
739
|
this.#_dtsProv.dtstype = value;
|
|
558
740
|
}
|
|
559
741
|
|
|
560
|
-
|
|
742
|
+
/**
|
|
743
|
+
* Contains a TZ-offset
|
|
744
|
+
* @property {number}
|
|
745
|
+
* @todo [since v0.0.22] becomes readonly
|
|
746
|
+
*/
|
|
747
|
+
get curDocTZ() {
|
|
561
748
|
return this.#_dtsProv.curDocTZ;
|
|
562
749
|
}
|
|
563
750
|
|
|
564
|
-
set curDocTZ(value){
|
|
751
|
+
set curDocTZ(value) {
|
|
565
752
|
this.#_dtsProv.curDocTZ = value;
|
|
566
753
|
}
|
|
567
754
|
|
|
568
|
-
|
|
569
|
-
|
|
755
|
+
/**
|
|
756
|
+
* @returns {?object}
|
|
757
|
+
* @private
|
|
758
|
+
*/
|
|
759
|
+
#_getProv() {
|
|
760
|
+
const docProv = getXObjElement(this.#_host, XEPG_PRVINFO_ETAG_NAME);
|
|
570
761
|
return isPlainObject(docProv) ? docProv : null;
|
|
571
762
|
}
|
|
572
763
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
764
|
+
/**
|
|
765
|
+
* @returns {?object}
|
|
766
|
+
* @private
|
|
767
|
+
*/
|
|
768
|
+
#_initProv() {
|
|
769
|
+
const _host = this.#_host;
|
|
770
|
+
let docProv = getXObjElement(_host, XEPG_PRVINFO_ETAG_NAME);
|
|
576
771
|
if (!docProv) {
|
|
577
|
-
docProv = insertXObjElement(
|
|
772
|
+
docProv = insertXObjElement(_host, XEPG_PRVINFO_ETAG_NAME);
|
|
578
773
|
};
|
|
579
774
|
return isPlainObject(docProv) ? docProv : null;
|
|
580
775
|
}
|
|
581
776
|
|
|
582
|
-
|
|
777
|
+
/**
|
|
778
|
+
* @property {?TXEpgProviderContainer}
|
|
779
|
+
* @readonly
|
|
780
|
+
* @description Returns a `TXEpgProviderContainer` instance
|
|
781
|
+
*/
|
|
782
|
+
get Provider() {
|
|
583
783
|
const docProv = this.#_getProv();
|
|
584
784
|
return (
|
|
585
785
|
docProv
|
|
@@ -588,8 +788,12 @@ class TXEpgHeaderContainer {
|
|
|
588
788
|
);
|
|
589
789
|
}
|
|
590
790
|
|
|
591
|
-
|
|
592
|
-
|
|
791
|
+
/**
|
|
792
|
+
* @returns {number}
|
|
793
|
+
* @description Returns a document creation date as a timestamp
|
|
794
|
+
*/
|
|
795
|
+
getDocumentDT() {
|
|
796
|
+
let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTO_ETAG_NAME).trim();
|
|
593
797
|
return (
|
|
594
798
|
dt_str !== ''
|
|
595
799
|
? convStringToDTValue(dt_str, this.dtstype, this.curDocTZ)
|
|
@@ -597,18 +801,26 @@ class TXEpgHeaderContainer {
|
|
|
597
801
|
);
|
|
598
802
|
}
|
|
599
803
|
|
|
600
|
-
|
|
804
|
+
/**
|
|
805
|
+
* @returns {void}
|
|
806
|
+
* @description Sets a document creation date to a current system time
|
|
807
|
+
*/
|
|
808
|
+
setDocumentDT() {
|
|
601
809
|
let dt_str = convDTValueToString(Date.now(), this.dtstype, this.curDocTZ);
|
|
602
810
|
let item = insertXObjElement(
|
|
603
|
-
this.#
|
|
811
|
+
this.#_host,
|
|
604
812
|
XEPG_DOCDTO_ETAG_NAME,
|
|
605
813
|
{ force: true },
|
|
606
814
|
);
|
|
607
815
|
if (item) writeXObjParam(item, dt_str);
|
|
608
816
|
}
|
|
609
817
|
|
|
610
|
-
|
|
611
|
-
|
|
818
|
+
/**
|
|
819
|
+
* @returns {number}
|
|
820
|
+
* @description Returns a document expire date as a timestamp
|
|
821
|
+
*/
|
|
822
|
+
getDocumentEDT() {
|
|
823
|
+
let dt_str = _getXmlChildElementParam(this.#_host, XEPG_DOCDTE_ETAG_NAME).trim();
|
|
612
824
|
return (
|
|
613
825
|
dt_str !== ''
|
|
614
826
|
? convStringToDTValue(dt_str, this.dtstype, this.curDocTZ)
|
|
@@ -616,40 +828,58 @@ class TXEpgHeaderContainer {
|
|
|
616
828
|
);
|
|
617
829
|
}
|
|
618
830
|
|
|
619
|
-
|
|
831
|
+
/**
|
|
832
|
+
* @param {any} value - document expire date
|
|
833
|
+
* @returns {void}
|
|
834
|
+
* @description Sets a document expire date to a given time
|
|
835
|
+
*/
|
|
836
|
+
setDocumentEDT(value) {
|
|
620
837
|
// TODO: check if value is a DateTime-string
|
|
621
838
|
let dt_str = convDTValueToString(value, this.dtstype, this.curDocTZ);
|
|
622
839
|
let item = insertXObjElement(
|
|
623
|
-
this.#
|
|
840
|
+
this.#_host,
|
|
624
841
|
XEPG_DOCDTE_ETAG_NAME,
|
|
625
842
|
{ force: true },
|
|
626
843
|
);
|
|
627
844
|
if (item) writeXObjParam(item, dt_str);
|
|
628
845
|
}
|
|
629
846
|
|
|
630
|
-
|
|
631
|
-
|
|
847
|
+
/**
|
|
848
|
+
* @returns {xepgChnInfoDesc}
|
|
849
|
+
* @description Returns a channel info
|
|
850
|
+
*/
|
|
851
|
+
getChannelInfo() {
|
|
852
|
+
const _host = this.#_host;
|
|
853
|
+
/** @type {xepgChnInfoDesc} */
|
|
632
854
|
let item = {
|
|
633
|
-
chnid: _getXmlChildElementParam(
|
|
634
|
-
chname: _getXmlChildElementParam(
|
|
635
|
-
chngid: _getXmlChildElementParam(
|
|
636
|
-
srcurl: _getXmlChildElementParam(
|
|
855
|
+
chnid: _getXmlChildElementParam(_host, XEPG_CHNID_ETAG_NAME).trim(),
|
|
856
|
+
chname: _getXmlChildElementParam(_host, XEPG_CHNNAME_ETAG_NAME).trim(),
|
|
857
|
+
chngid: _getXmlChildElementParam(_host, XEPG_CHNGID_ETAG_NAME).trim(),
|
|
858
|
+
srcurl: _getXmlChildElementParam(_host, XEPG_CHNURL_ETAG_NAME).trim(),
|
|
637
859
|
};
|
|
638
860
|
return item;
|
|
639
861
|
}
|
|
640
862
|
|
|
641
|
-
|
|
863
|
+
/**
|
|
864
|
+
* @param {xepgChnInfoDesc} obj - channel info descriptor
|
|
865
|
+
* @returns {void}
|
|
866
|
+
* @description Sets a channel info
|
|
867
|
+
* @todo [since v0.0.21] deprecate use of `obj`-param as array
|
|
868
|
+
*/
|
|
869
|
+
setChannelInfo(obj) {
|
|
642
870
|
let chnid = '';
|
|
643
871
|
let chname = '';
|
|
644
872
|
let chngid = '';
|
|
645
873
|
let srcurl = '';
|
|
646
874
|
if (isArray(obj)) {
|
|
875
|
+
// // TODO: [!] deprecate
|
|
647
876
|
[ chnid, chname, chngid, srcurl ] = obj;
|
|
648
877
|
} else if (isObject(obj)) {
|
|
649
878
|
({ chnid } = obj);
|
|
650
879
|
if (typeof chnid === 'string') {
|
|
651
880
|
({ chname, chngid, srcurl } = obj);
|
|
652
881
|
} else {
|
|
882
|
+
// // TODO: [?] deprecate
|
|
653
883
|
chnid = _getXmlChildElementParam(obj, XEPG_CHNID_ETAG_NAME).trim();
|
|
654
884
|
chname = _getXmlChildElementParam(obj, XEPG_CHNNAME_ETAG_NAME).trim();
|
|
655
885
|
chngid = _getXmlChildElementParam(obj, XEPG_CHNGID_ETAG_NAME).trim();
|
|
@@ -671,22 +901,31 @@ class TXEpgHeaderContainer {
|
|
|
671
901
|
srcurl = typeof srcurl === 'string' ? srcurl.trim() : '';
|
|
672
902
|
};
|
|
673
903
|
let item = null;
|
|
674
|
-
const
|
|
675
|
-
item = insertXObjElement(
|
|
904
|
+
const _host = this.#_host;
|
|
905
|
+
item = insertXObjElement(_host, XEPG_CHNID_ETAG_NAME, { force: true });
|
|
676
906
|
if (item) writeXObjParam(item, chnid);
|
|
677
|
-
item = insertXObjElement(
|
|
907
|
+
item = insertXObjElement(_host, XEPG_CHNNAME_ETAG_NAME, { force: true });
|
|
678
908
|
if (item) writeXObjParam(item, chname);
|
|
679
|
-
item = insertXObjElement(
|
|
909
|
+
item = insertXObjElement(_host, XEPG_CHNGID_ETAG_NAME, { force: true });
|
|
680
910
|
if (item) writeXObjParam(item, chngid);
|
|
681
|
-
item = insertXObjElement(
|
|
911
|
+
item = insertXObjElement(_host, XEPG_CHNURL_ETAG_NAME, { force: true });
|
|
682
912
|
if (item) writeXObjParam(item, srcurl);
|
|
683
913
|
}
|
|
684
914
|
|
|
915
|
+
/**
|
|
916
|
+
* @returns {?xepgProvInfoDesc}
|
|
917
|
+
* @description Returns a provider info
|
|
918
|
+
*/
|
|
685
919
|
getProviderInfo(){
|
|
686
920
|
const docProv = this.Provider;
|
|
687
921
|
return docProv ? docProv.getInfo() : null;
|
|
688
922
|
}
|
|
689
923
|
|
|
924
|
+
/**
|
|
925
|
+
* @param {xepgProvInfoDesc} obj - provider info descriptor
|
|
926
|
+
* @returns {void}
|
|
927
|
+
* @description Sets a provider info
|
|
928
|
+
*/
|
|
690
929
|
setProviderInfo(obj){
|
|
691
930
|
if (isArray(obj) || isObject(obj)) {
|
|
692
931
|
let docProv = this.Provider;
|
|
@@ -698,17 +937,58 @@ class TXEpgHeaderContainer {
|
|
|
698
937
|
};
|
|
699
938
|
}
|
|
700
939
|
|
|
940
|
+
/**
|
|
941
|
+
* @returns {string}
|
|
942
|
+
* @since v0.0.20
|
|
943
|
+
* @description Returns an instance content as a string in an XML-format.
|
|
944
|
+
*/
|
|
945
|
+
saveToXMLString() {
|
|
946
|
+
const options = this.#_parseOptions.js2xml;
|
|
947
|
+
options.ignoreDocType = true;
|
|
948
|
+
options.ignoreDeclaration = true;
|
|
949
|
+
const content = { [`${XEPG_HEADER_ETAG_NAME}`]: this.#_host };
|
|
950
|
+
let result = '';
|
|
951
|
+
try {
|
|
952
|
+
result = xmlParser.js2xml(content, options);
|
|
953
|
+
} catch (err) {
|
|
954
|
+
//console.log('CHECK: TXEpgHeaderContainer.saveToXMLString() => Error => '+err);
|
|
955
|
+
result = '';
|
|
956
|
+
//throw err;
|
|
957
|
+
};
|
|
958
|
+
return result;
|
|
959
|
+
}
|
|
960
|
+
|
|
701
961
|
};
|
|
702
962
|
|
|
703
963
|
/**
|
|
704
|
-
* @
|
|
705
|
-
*
|
|
964
|
+
* @typedef {Object} fsoDescr
|
|
965
|
+
* @property {boolean} isERR - flag
|
|
966
|
+
* @property {number} [errCode] - error code
|
|
967
|
+
* @property {string} errEvent - event ID
|
|
968
|
+
* @property {string} errMsg - event message
|
|
969
|
+
* @property {string} source - path to file
|
|
970
|
+
* @property {any} content - file content
|
|
971
|
+
* @description A fs ops description.
|
|
972
|
+
*/
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* @classdesc This class implements an interface of the container
|
|
976
|
+
* that manages a content of a XEPG-document
|
|
706
977
|
*/
|
|
707
978
|
class TXEpgContentProvider {
|
|
708
|
-
|
|
709
|
-
#
|
|
710
|
-
|
|
979
|
+
/** @property {Object} */
|
|
980
|
+
#_content;// = null;
|
|
981
|
+
/** @property {Object} */
|
|
982
|
+
#_options;// = null;
|
|
983
|
+
/** @property {?TXmlContentParseOptions} */
|
|
984
|
+
#_parseOptions;// = null;
|
|
711
985
|
|
|
986
|
+
/**
|
|
987
|
+
* @param {object} [opt] - options
|
|
988
|
+
* @param {object} [opt.parseOptions]
|
|
989
|
+
* @param {boolean} [opt.autoBindRoot] - <*reserved*> ([?] - deprecate)
|
|
990
|
+
* @description Creates an instance of the XEPG-content provider
|
|
991
|
+
*/
|
|
712
992
|
constructor(opt) {
|
|
713
993
|
// load options
|
|
714
994
|
const _options = isPlainObject(opt) ? opt : {};
|
|
@@ -731,12 +1011,20 @@ class TXEpgContentProvider {
|
|
|
731
1011
|
this.init();
|
|
732
1012
|
}
|
|
733
1013
|
|
|
734
|
-
|
|
1014
|
+
/**
|
|
1015
|
+
* @returns {?Object}
|
|
1016
|
+
* @private
|
|
1017
|
+
*/
|
|
1018
|
+
#_getRoot() {
|
|
735
1019
|
const docRoot = getXObjElement(this.#_content, XEPG_ROOT_ETAG_NAME);
|
|
736
1020
|
return isPlainObject(docRoot) ? docRoot : null;
|
|
737
1021
|
}
|
|
738
1022
|
|
|
739
|
-
|
|
1023
|
+
/**
|
|
1024
|
+
* @returns {?object}
|
|
1025
|
+
* @private
|
|
1026
|
+
*/
|
|
1027
|
+
#_initRoot() {
|
|
740
1028
|
const _content = this.#_content;
|
|
741
1029
|
let docRoot = getXObjElement(_content, XEPG_ROOT_ETAG_NAME);
|
|
742
1030
|
if (!docRoot) {
|
|
@@ -748,7 +1036,11 @@ class TXEpgContentProvider {
|
|
|
748
1036
|
return isPlainObject(docRoot) ? docRoot : null;
|
|
749
1037
|
}
|
|
750
1038
|
|
|
751
|
-
|
|
1039
|
+
/**
|
|
1040
|
+
* @returns {?Object}
|
|
1041
|
+
* @private
|
|
1042
|
+
*/
|
|
1043
|
+
#_getHdr() {
|
|
752
1044
|
const docRoot = this.#_getRoot();
|
|
753
1045
|
let docHdr = null;
|
|
754
1046
|
if (docRoot) {
|
|
@@ -757,7 +1049,11 @@ class TXEpgContentProvider {
|
|
|
757
1049
|
return isPlainObject(docHdr) ? docHdr : null;
|
|
758
1050
|
}
|
|
759
1051
|
|
|
760
|
-
|
|
1052
|
+
/**
|
|
1053
|
+
* @returns {?object}
|
|
1054
|
+
* @private
|
|
1055
|
+
*/
|
|
1056
|
+
#_initHdr() {
|
|
761
1057
|
let docHdr = this.#_getHdr();
|
|
762
1058
|
if (!docHdr) {
|
|
763
1059
|
let docRoot = this.#_getRoot();
|
|
@@ -769,7 +1065,11 @@ class TXEpgContentProvider {
|
|
|
769
1065
|
return isPlainObject(docHdr) ? docHdr : null;
|
|
770
1066
|
}
|
|
771
1067
|
|
|
772
|
-
|
|
1068
|
+
/**
|
|
1069
|
+
* @returns {?Object}
|
|
1070
|
+
* @private
|
|
1071
|
+
*/
|
|
1072
|
+
#_getBody() {
|
|
773
1073
|
const docRoot = this.#_getRoot();
|
|
774
1074
|
let docBody = null;
|
|
775
1075
|
if (docRoot) {
|
|
@@ -778,7 +1078,11 @@ class TXEpgContentProvider {
|
|
|
778
1078
|
return isPlainObject(docBody) ? docBody : null;
|
|
779
1079
|
}
|
|
780
1080
|
|
|
781
|
-
|
|
1081
|
+
/**
|
|
1082
|
+
* @returns {?object}
|
|
1083
|
+
* @private
|
|
1084
|
+
*/
|
|
1085
|
+
#_initBody() {
|
|
782
1086
|
let docBody = this.#_getBody();
|
|
783
1087
|
if (!docBody) {
|
|
784
1088
|
let docRoot = this.#_getRoot();
|
|
@@ -790,7 +1094,12 @@ class TXEpgContentProvider {
|
|
|
790
1094
|
return isPlainObject(docBody) ? docBody : null;
|
|
791
1095
|
}
|
|
792
1096
|
|
|
793
|
-
|
|
1097
|
+
/**
|
|
1098
|
+
* Returns a `TXEpgHeaderContainer` instance
|
|
1099
|
+
* @property {?TXEpgHeaderContainer}
|
|
1100
|
+
* @readonly
|
|
1101
|
+
*/
|
|
1102
|
+
get Header() {
|
|
794
1103
|
const docHdr = this.#_getHdr();
|
|
795
1104
|
return (
|
|
796
1105
|
docHdr
|
|
@@ -799,21 +1108,38 @@ class TXEpgContentProvider {
|
|
|
799
1108
|
);
|
|
800
1109
|
}
|
|
801
1110
|
|
|
802
|
-
|
|
1111
|
+
/**
|
|
1112
|
+
* Returns a `TXEpgProviderContainer` instance
|
|
1113
|
+
* @property {?TXEpgProviderContainer}
|
|
1114
|
+
* @readonly
|
|
1115
|
+
*/
|
|
1116
|
+
get Provider() {
|
|
803
1117
|
const docHdr = this.Header;
|
|
804
1118
|
return docHdr ? docHdr.Provider : null;
|
|
805
1119
|
}
|
|
806
1120
|
|
|
807
|
-
|
|
1121
|
+
/**
|
|
1122
|
+
* Returns a `TXEpgDTSProvider` instance
|
|
1123
|
+
* @property {?TXEpgDTSProvider}
|
|
1124
|
+
* @readonly
|
|
1125
|
+
*/
|
|
1126
|
+
get dts() {
|
|
808
1127
|
const docHdr = this.Header;
|
|
809
1128
|
return docHdr ? docHdr.dts : null;
|
|
810
1129
|
}
|
|
811
1130
|
|
|
812
1131
|
/* [!] a temporary special method */
|
|
813
|
-
|
|
1132
|
+
/**
|
|
1133
|
+
* @deprecated
|
|
1134
|
+
*/
|
|
814
1135
|
get Content(){ return this; }
|
|
815
1136
|
|
|
816
|
-
|
|
1137
|
+
/**
|
|
1138
|
+
* Returns a `TXEpgSchedulesList` instance
|
|
1139
|
+
* @property {TXEpgSchedulesList}
|
|
1140
|
+
* @readonly
|
|
1141
|
+
*/
|
|
1142
|
+
get SchedulesList() {
|
|
817
1143
|
const _options = this.#_options;
|
|
818
1144
|
const docBody = this.#_getBody();
|
|
819
1145
|
if (docBody && isArray(docBody[XEPG_SCHED_ETAG_NAME])) {
|
|
@@ -828,7 +1154,10 @@ class TXEpgContentProvider {
|
|
|
828
1154
|
};
|
|
829
1155
|
}
|
|
830
1156
|
|
|
831
|
-
|
|
1157
|
+
/**
|
|
1158
|
+
* @returns {void}
|
|
1159
|
+
*/
|
|
1160
|
+
init() {
|
|
832
1161
|
const _options = this.#_options;
|
|
833
1162
|
const _content = this.#_content;
|
|
834
1163
|
const {
|
|
@@ -880,8 +1209,8 @@ class TXEpgContentProvider {
|
|
|
880
1209
|
}
|
|
881
1210
|
|
|
882
1211
|
/**
|
|
883
|
-
* @param {string}
|
|
884
|
-
* @returns {
|
|
1212
|
+
* @param {string} source - a path to a file
|
|
1213
|
+
* @returns {Promise<fsoDescr, Error>}
|
|
885
1214
|
* @throws {Error}
|
|
886
1215
|
* @async
|
|
887
1216
|
* @description Saves a document content to a file.
|
|
@@ -889,88 +1218,77 @@ class TXEpgContentProvider {
|
|
|
889
1218
|
saveToFile(source) {
|
|
890
1219
|
/**/// main part that return promise as a result
|
|
891
1220
|
return new Promise((resolve, reject) => {
|
|
1221
|
+
/** @type {fsoDescr} */
|
|
892
1222
|
let data = {
|
|
893
|
-
isSucceed: false,
|
|
894
|
-
source: typeof source === 'string' ? source.trim() : '',
|
|
895
|
-
content: '',
|
|
896
1223
|
isERR: false,
|
|
1224
|
+
errCode: 0,
|
|
897
1225
|
errEvent: '',
|
|
1226
|
+
errMsg: '',
|
|
1227
|
+
source: '',
|
|
1228
|
+
content: '',
|
|
898
1229
|
};
|
|
899
|
-
|
|
900
|
-
data.isERR = true;
|
|
901
|
-
data.errEvent = (
|
|
902
|
-
typeof source === 'string' ? 'EMPTY_SRCLINK' : 'NO_SRCLINK'
|
|
903
|
-
);
|
|
904
|
-
resolve(data);
|
|
905
|
-
} else {
|
|
1230
|
+
(new Promise((resolve, reject) => {
|
|
906
1231
|
data.content = this.saveToXMLString();
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1232
|
+
resolve(true);
|
|
1233
|
+
})).then(result => {
|
|
1234
|
+
saveToFile(source, data.content, null).then(data => {
|
|
910
1235
|
resolve(data);
|
|
911
1236
|
}).catch(err => {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
} else {
|
|
917
|
-
//console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err);
|
|
918
|
-
//console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err.code);
|
|
919
|
-
reject(err);
|
|
920
|
-
};
|
|
1237
|
+
// // TODO: [?] consider check others
|
|
1238
|
+
//console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err);
|
|
1239
|
+
//console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err.code);
|
|
1240
|
+
reject(err);
|
|
921
1241
|
});
|
|
922
|
-
}
|
|
1242
|
+
}).catch(err => {
|
|
1243
|
+
data.isERR = true;
|
|
1244
|
+
//console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err);
|
|
1245
|
+
//console.log('CHECK: TXEpgContentProvider.saveToFile() => Error => '+err.code);
|
|
1246
|
+
data.errEvent = 'ERR_XEPG_UNKNOWN';
|
|
1247
|
+
resolve(data);
|
|
1248
|
+
});
|
|
923
1249
|
});
|
|
924
1250
|
}
|
|
925
1251
|
|
|
926
1252
|
/**
|
|
927
|
-
* @param {string}
|
|
928
|
-
* @returns {
|
|
929
|
-
* @throws {Error}
|
|
1253
|
+
* @param {string} source - path to a file
|
|
1254
|
+
* @returns {fsoDescr}
|
|
930
1255
|
* @description Saves a document content to a file.
|
|
931
1256
|
*/
|
|
932
1257
|
saveToFileSync(source) {
|
|
1258
|
+
/** @type {fsoDescr} */
|
|
933
1259
|
let data = {
|
|
934
|
-
isSucceed: false,
|
|
935
|
-
source: typeof source === 'string' ? source.trim() : '',
|
|
936
|
-
content: '',
|
|
937
1260
|
isERR: false,
|
|
1261
|
+
errCode: 0,
|
|
938
1262
|
errEvent: '',
|
|
1263
|
+
errMsg: '',
|
|
1264
|
+
source: '',
|
|
1265
|
+
content: '',
|
|
939
1266
|
};
|
|
940
|
-
|
|
1267
|
+
try {
|
|
1268
|
+
data.content = this.saveToXMLString();
|
|
1269
|
+
} catch (err) {
|
|
941
1270
|
data.isERR = true;
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
fs.writeFileSync(data.source, data.content, 'utf8');
|
|
949
|
-
} catch (err) {
|
|
950
|
-
let { isSucceed } = checkFsError(data, err);
|
|
951
|
-
if (isSucceed) {
|
|
952
|
-
data.content = '';
|
|
953
|
-
} else {
|
|
954
|
-
//console.log('CHECK: TXEpgContentProvider.saveToFileSync() => Error => '+err);
|
|
955
|
-
//console.log('CHECK: TXEpgContentProvider.saveToFileSync() => Error => '+err.code);
|
|
956
|
-
throw err;
|
|
957
|
-
};
|
|
958
|
-
};
|
|
1271
|
+
//console.log('CHECK: TXEpgContentProvider.saveToFileSync() => Error => '+err);
|
|
1272
|
+
//console.log('CHECK: TXEpgContentProvider.saveToFileSync() => Error => '+err.code);
|
|
1273
|
+
data.errEvent = 'ERR_XEPG_UNKNOWN';
|
|
1274
|
+
};
|
|
1275
|
+
if (!data.isERR) {
|
|
1276
|
+
data = saveToFileSync(source, data.content, null);
|
|
959
1277
|
};
|
|
960
1278
|
return data;
|
|
961
1279
|
}
|
|
962
1280
|
|
|
963
|
-
|
|
1281
|
+
/**
|
|
1282
|
+
* @param {string} xmlString - a document content in XML-format
|
|
1283
|
+
* @returns {boolean}
|
|
1284
|
+
* @throws {Error}
|
|
1285
|
+
* @since 0.0.18
|
|
1286
|
+
* @description Loads a document content from a string.
|
|
1287
|
+
*/
|
|
1288
|
+
loadFromXMLString(xmlString) {
|
|
964
1289
|
let isSUCCEED = false;
|
|
965
1290
|
if (typeof xmlString === 'string') {
|
|
966
|
-
|
|
967
|
-
let parseOptions = null;
|
|
968
|
-
if (isPlainObject(opt)) {
|
|
969
|
-
parseOptions = new TXmlContentParseOptions(opt);
|
|
970
|
-
// // TODO: init user options
|
|
971
|
-
} else {
|
|
972
|
-
parseOptions = _options.parseOptions;
|
|
973
|
-
};
|
|
1291
|
+
const { parseOptions } = this.#_options;
|
|
974
1292
|
try {
|
|
975
1293
|
this.#_content = xmlParser.xml2js(xmlString, parseOptions.xml2js);
|
|
976
1294
|
// init a document header element
|
|
@@ -997,13 +1315,16 @@ class TXEpgContentProvider {
|
|
|
997
1315
|
return isSUCCEED;
|
|
998
1316
|
}
|
|
999
1317
|
|
|
1318
|
+
/**
|
|
1319
|
+
* @deprecated
|
|
1320
|
+
*/
|
|
1000
1321
|
loadFromString(...args){
|
|
1001
1322
|
return this.loadFromXMLString(...args);
|
|
1002
1323
|
}
|
|
1003
1324
|
|
|
1004
1325
|
/**
|
|
1005
|
-
* @param {string}
|
|
1006
|
-
* @returns {
|
|
1326
|
+
* @param {string} source - path to a file
|
|
1327
|
+
* @returns {Promise<fsoDescr, Error>}
|
|
1007
1328
|
* @throws {Error}
|
|
1008
1329
|
* @async
|
|
1009
1330
|
* @description Loads a document content from a file.
|
|
@@ -1011,24 +1332,11 @@ class TXEpgContentProvider {
|
|
|
1011
1332
|
loadFromFile(source) {
|
|
1012
1333
|
/**/// main part that return promise as a result
|
|
1013
1334
|
return new Promise((resolve, reject) => {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
errEvent: '',
|
|
1020
|
-
};
|
|
1021
|
-
if (data.source === '') {
|
|
1022
|
-
data.isERR = true;
|
|
1023
|
-
data.errEvent = (
|
|
1024
|
-
typeof source === 'string' ? 'EMPTY_SRCLINK' : 'NO_SRCLINK'
|
|
1025
|
-
);
|
|
1026
|
-
resolve(data);
|
|
1027
|
-
} else {
|
|
1028
|
-
fse.readFile(data.source, 'utf8').then(result => {
|
|
1029
|
-
data.content = result;
|
|
1030
|
-
if (result !== '') {
|
|
1031
|
-
if (this.loadFromXMLString(result)) {
|
|
1335
|
+
loadFile(source).then(data => {
|
|
1336
|
+
if (!data.isERR) {
|
|
1337
|
+
if (data.content !== '') {
|
|
1338
|
+
if (this.loadFromXMLString(data.content)) {
|
|
1339
|
+
// // TODO:
|
|
1032
1340
|
data.isLoaded = true;
|
|
1033
1341
|
data.errEvent = 'OPS_IS_SUCCEED';
|
|
1034
1342
|
} else {
|
|
@@ -1039,77 +1347,45 @@ class TXEpgContentProvider {
|
|
|
1039
1347
|
data.isERR = true;
|
|
1040
1348
|
data.errEvent = 'NO_CONTENT';
|
|
1041
1349
|
};
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
//console.log('CHECK: TXEpgContentProvider.loadFromFile() => Error => '+err);
|
|
1050
|
-
//console.log('CHECK: TXEpgContentProvider.loadFromFile() => Error => '+err.code);
|
|
1051
|
-
reject(err);
|
|
1052
|
-
};
|
|
1053
|
-
});
|
|
1054
|
-
};
|
|
1350
|
+
};
|
|
1351
|
+
resolve(data);
|
|
1352
|
+
}).catch(err => {
|
|
1353
|
+
//console.log('CHECK: TXEpgContentProvider.loadFromFile() => Error => '+err);
|
|
1354
|
+
//console.log('CHECK: TXEpgContentProvider.loadFromFile() => Error => '+err.code);
|
|
1355
|
+
reject(err);
|
|
1356
|
+
});
|
|
1055
1357
|
});
|
|
1056
1358
|
}
|
|
1057
1359
|
|
|
1058
1360
|
/**
|
|
1059
|
-
* @param {string}
|
|
1060
|
-
* @returns {
|
|
1061
|
-
* @throws {Error}
|
|
1361
|
+
* @param {string} source - path to a file
|
|
1362
|
+
* @returns {fsoDescr}
|
|
1062
1363
|
* @description Loads a document content from a file.
|
|
1063
1364
|
*/
|
|
1064
1365
|
loadFromFileSync(source) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
if (data.source === '') {
|
|
1073
|
-
data.isERR = true;
|
|
1074
|
-
data.errEvent = (
|
|
1075
|
-
typeof source === 'string' ? 'EMPTY_SRCLINK' : 'NO_SRCLINK'
|
|
1076
|
-
);
|
|
1077
|
-
} else {
|
|
1078
|
-
try {
|
|
1079
|
-
data.content = fs.readFileSync(data.source, 'utf8');
|
|
1080
|
-
if (data.content !== '') {
|
|
1081
|
-
if (this.loadFromXMLString(data.content)) {
|
|
1082
|
-
data.isLoaded = true;
|
|
1083
|
-
data.errEvent = 'OPS_IS_SUCCEED';
|
|
1084
|
-
} else {
|
|
1085
|
-
data.isERR = true;
|
|
1086
|
-
data.errEvent = 'OPS_IS_FAILED';
|
|
1087
|
-
};
|
|
1366
|
+
const data = loadFileSync(source);
|
|
1367
|
+
if (!data.isERR) {
|
|
1368
|
+
if (data.content !== '') {
|
|
1369
|
+
if (this.loadFromXMLString(data.content)) {
|
|
1370
|
+
// // TODO:
|
|
1371
|
+
data.isLoaded = true;
|
|
1372
|
+
data.errEvent = 'OPS_IS_SUCCEED';
|
|
1088
1373
|
} else {
|
|
1089
1374
|
data.isERR = true;
|
|
1090
|
-
data.errEvent = '
|
|
1091
|
-
};
|
|
1092
|
-
} catch (err) {
|
|
1093
|
-
let { isSucceed } = checkFsError(data, err);
|
|
1094
|
-
if (isSucceed) {
|
|
1095
|
-
data.content = '';
|
|
1096
|
-
} else {
|
|
1097
|
-
//console.log('CHECK: TXEpgContentProvider.loadFromFileSync() => Error => '+err);
|
|
1098
|
-
//console.log('CHECK: TXEpgContentProvider.loadFromFileSync() => Error => '+err.code);
|
|
1099
|
-
throw err;
|
|
1375
|
+
data.errEvent = 'OPS_IS_FAILED';
|
|
1100
1376
|
};
|
|
1377
|
+
} else {
|
|
1378
|
+
data.isERR = true;
|
|
1379
|
+
data.errEvent = 'NO_CONTENT';
|
|
1101
1380
|
};
|
|
1102
1381
|
};
|
|
1103
1382
|
return data;
|
|
1104
1383
|
}
|
|
1105
1384
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
asJSON(){
|
|
1385
|
+
/**
|
|
1386
|
+
* @protected
|
|
1387
|
+
*/
|
|
1388
|
+
asJSON() {
|
|
1113
1389
|
return JSON.stringify(this.#_content, null, 2);
|
|
1114
1390
|
}
|
|
1115
1391
|
|
|
@@ -1117,7 +1393,7 @@ class TXEpgContentProvider {
|
|
|
1117
1393
|
|
|
1118
1394
|
// === module exports block ===
|
|
1119
1395
|
|
|
1120
|
-
exports.
|
|
1396
|
+
exports.TXEpgDTSProvider = TXEpgDTSProvider;
|
|
1121
1397
|
exports.TXEpgSchedulesList = TXEpgSchedulesList;
|
|
1122
1398
|
exports.TXEpgProviderContainer = TXEpgProviderContainer;
|
|
1123
1399
|
exports.TXEpgHeaderContainer = TXEpgHeaderContainer;
|
|
@@ -1127,3 +1403,6 @@ exports.XEPG_DEF_PROVIDER_NAME = XEPG_DEF_PROVIDER_NAME;
|
|
|
1127
1403
|
exports.XEPG_DEF_PROVIDER_VER = XEPG_DEF_PROVIDER_VER;
|
|
1128
1404
|
exports.XEPG_DEF_DOCUMENT_TYPE = XEPG_DEF_DOCUMENT_TYPE;
|
|
1129
1405
|
exports.XEPG_DEF_DOCUMENT_SCHEMA = XEPG_DEF_DOCUMENT_SCHEMA;
|
|
1406
|
+
|
|
1407
|
+
/** @deprecated */
|
|
1408
|
+
exports.TXepgDTSProvider = TXEpgDTSProvider;
|