gyomu 0.1.0
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/lib/archive/abstract.d.ts +7 -0
- package/lib/archive/abstract.js +30 -0
- package/lib/archive/gz.d.ts +16 -0
- package/lib/archive/gz.js +66 -0
- package/lib/archive/index.d.ts +3 -0
- package/lib/archive/index.js +19 -0
- package/lib/archive/tar.d.ts +17 -0
- package/lib/archive/tar.js +165 -0
- package/lib/archive/zip.d.ts +28 -0
- package/lib/archive/zip.js +254 -0
- package/lib/base64.d.ts +6 -0
- package/lib/base64.js +24 -0
- package/lib/buffer.d.ts +4 -0
- package/lib/buffer.js +23 -0
- package/lib/configurator.d.ts +16 -0
- package/lib/configurator.js +53 -0
- package/lib/dateOperation.d.ts +3 -0
- package/lib/dateOperation.js +23 -0
- package/lib/dbsingleton.d.ts +11 -0
- package/lib/dbsingleton.js +13 -0
- package/lib/dbutil.d.ts +3 -0
- package/lib/dbutil.js +44 -0
- package/lib/dictionary.d.ts +8 -0
- package/lib/dictionary.js +55 -0
- package/lib/encryption.d.ts +17 -0
- package/lib/encryption.js +202 -0
- package/lib/errors.d.ts +31 -0
- package/lib/errors.js +64 -0
- package/lib/excel.d.ts +1 -0
- package/lib/excel.js +34 -0
- package/lib/fileModel.d.ts +96 -0
- package/lib/fileModel.js +170 -0
- package/lib/fileOperation.d.ts +11 -0
- package/lib/fileOperation.js +275 -0
- package/lib/holidays.d.ts +20 -0
- package/lib/holidays.js +200 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +31 -0
- package/lib/milestone.d.ts +19 -0
- package/lib/milestone.js +169 -0
- package/lib/net/_ftp.d.ts +0 -0
- package/lib/net/_ftp.js +228 -0
- package/lib/net/ftp.d.ts +19 -0
- package/lib/net/ftp.js +160 -0
- package/lib/net/remoteConnection.d.ts +11 -0
- package/lib/net/remoteConnection.js +26 -0
- package/lib/net/sftp.d.ts +19 -0
- package/lib/net/sftp.js +155 -0
- package/lib/numberOperation.d.ts +3 -0
- package/lib/numberOperation.js +24 -0
- package/lib/parameter.d.ts +14 -0
- package/lib/parameter.js +291 -0
- package/lib/result.d.ts +23 -0
- package/lib/result.js +47 -0
- package/lib/timer.d.ts +11 -0
- package/lib/timer.js +62 -0
- package/lib/user.d.ts +11 -0
- package/lib/user.js +23 -0
- package/lib/variable.d.ts +11 -0
- package/lib/variable.js +280 -0
- package/lib/web/attribute.d.ts +6 -0
- package/lib/web/attribute.js +29 -0
- package/lib/web/element.d.ts +24 -0
- package/lib/web/element.js +119 -0
- package/lib/web/index.d.ts +7 -0
- package/lib/web/index.js +19 -0
- package/lib/web/page.d.ts +22 -0
- package/lib/web/page.js +102 -0
- package/lib/web/table.d.ts +15 -0
- package/lib/web/table.js +110 -0
- package/lib/web/tableColumn.d.ts +10 -0
- package/lib/web/tableColumn.js +21 -0
- package/lib/web/tableRow.d.ts +10 -0
- package/lib/web/tableRow.js +80 -0
- package/lib/web/util.d.ts +12 -0
- package/lib/web/util.js +22 -0
- package/package.json +63 -0
package/lib/variable.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _VariableTranslator_instances, _VariableTranslator_marketAccess, _VariableTranslator_translateDate, _VariableTranslator_translate, _VariableTranslator_getSupportedMarket;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.VariableTranslator = void 0;
|
|
28
|
+
const dateOperation_1 = require("./dateOperation");
|
|
29
|
+
const dbsingleton_1 = __importDefault(require("./dbsingleton"));
|
|
30
|
+
const holidays_1 = __importDefault(require("./holidays"));
|
|
31
|
+
const date_fns_1 = require("date-fns");
|
|
32
|
+
const errors_1 = require("./errors");
|
|
33
|
+
const result_1 = require("./result");
|
|
34
|
+
const VariableType = {
|
|
35
|
+
Date: 'Date',
|
|
36
|
+
ParamMaster: 'Parameter',
|
|
37
|
+
ParamMasterStringDictionary: 'ParameterDictionary',
|
|
38
|
+
Argument: 'Argument',
|
|
39
|
+
ArgumentFile: 'File',
|
|
40
|
+
};
|
|
41
|
+
const VariableDateKeyword = {
|
|
42
|
+
TODAY: 'TODAY',
|
|
43
|
+
BBOM: 'BBOM',
|
|
44
|
+
NEXTBBOM: 'NEXTBBOM',
|
|
45
|
+
BOM: 'BOM',
|
|
46
|
+
BEOM: 'BEOM',
|
|
47
|
+
NEXTBEOM: 'NEXTBEOM',
|
|
48
|
+
PREVBEOM: 'PREVBEOM',
|
|
49
|
+
EOM: 'EOM',
|
|
50
|
+
NEXTBUS: 'NEXTBUS',
|
|
51
|
+
NEXTDAY: 'NEXTDAY',
|
|
52
|
+
PREVBUS: 'PREVBUS',
|
|
53
|
+
PREVDAY: 'PREVDAY',
|
|
54
|
+
EOY: 'EOY',
|
|
55
|
+
BEOY: 'BEOY',
|
|
56
|
+
BBOY: 'BBOY',
|
|
57
|
+
BOY: 'BOY',
|
|
58
|
+
};
|
|
59
|
+
class VariableTranslator {
|
|
60
|
+
//readonly #ctx: Context;
|
|
61
|
+
constructor(marketAccess) {
|
|
62
|
+
_VariableTranslator_instances.add(this);
|
|
63
|
+
_VariableTranslator_marketAccess.set(this, void 0);
|
|
64
|
+
this.__supportedMarkets = new Array();
|
|
65
|
+
//constructor(marketAccess: MarketDateAccess, ctx: Context) {
|
|
66
|
+
__classPrivateFieldSet(this, _VariableTranslator_marketAccess, marketAccess, "f");
|
|
67
|
+
//this.#ctx = ctx;
|
|
68
|
+
}
|
|
69
|
+
static getTranslator(market) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const result = yield holidays_1.default.getMarketAccess(market);
|
|
72
|
+
if (result.isFailure())
|
|
73
|
+
return result;
|
|
74
|
+
const access = result.value;
|
|
75
|
+
const translator = new VariableTranslator(access);
|
|
76
|
+
yield translator.init();
|
|
77
|
+
return (0, result_1.success)(translator);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
init() {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
this.__supportedMarkets = yield __classPrivateFieldGet(this, _VariableTranslator_instances, "m", _VariableTranslator_getSupportedMarket).call(this);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
parse(inputString, targetDate) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const startIndex = inputString.indexOf('{%');
|
|
88
|
+
const endIndex = inputString.indexOf('%}');
|
|
89
|
+
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
|
|
90
|
+
const prefix = inputString.substring(0, startIndex);
|
|
91
|
+
const keyword = inputString.substring(startIndex + 2, endIndex);
|
|
92
|
+
const suffix = inputString.substring(endIndex + 2);
|
|
93
|
+
const result = yield __classPrivateFieldGet(this, _VariableTranslator_instances, "m", _VariableTranslator_translate).call(this, keyword, targetDate);
|
|
94
|
+
if (result.isFailure())
|
|
95
|
+
return result;
|
|
96
|
+
const parsedString = prefix + result.value + suffix;
|
|
97
|
+
return yield this.parse(parsedString, targetDate);
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
return (0, result_1.success)(inputString);
|
|
101
|
+
// return new Promise((resolve, reject) => {
|
|
102
|
+
// resolve(success(inputString));
|
|
103
|
+
// });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
parseDate(keyword, targetDate) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const parts = keyword.split('$');
|
|
109
|
+
let factorIndex = 1;
|
|
110
|
+
let translateMarketAccess = __classPrivateFieldGet(this, _VariableTranslator_marketAccess, "f");
|
|
111
|
+
// const supportedMarket = await this.#getSupportedMarket();
|
|
112
|
+
for (var item of parts) {
|
|
113
|
+
if (!isNaN(parseInt(item))) {
|
|
114
|
+
factorIndex = parseInt(item);
|
|
115
|
+
}
|
|
116
|
+
else if (this.__supportedMarkets.includes(item)) {
|
|
117
|
+
const result = yield holidays_1.default.getMarketAccess(item);
|
|
118
|
+
if (result.isFailure())
|
|
119
|
+
return new result_1.Failure(new errors_1.ParseError(`Fail to retrieve market data ${item}`, result.error));
|
|
120
|
+
translateMarketAccess = result.value;
|
|
121
|
+
}
|
|
122
|
+
else if (item in VariableDateKeyword) {
|
|
123
|
+
return __classPrivateFieldGet(this, _VariableTranslator_instances, "m", _VariableTranslator_translateDate).call(this, translateMarketAccess, targetDate, item, factorIndex);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return (0, result_1.promiseFail)('No keyword: Not supported', errors_1.ParseError);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.VariableTranslator = VariableTranslator;
|
|
131
|
+
_VariableTranslator_marketAccess = new WeakMap(), _VariableTranslator_instances = new WeakSet(), _VariableTranslator_translateDate = function _VariableTranslator_translateDate(targetMarketAccess, targetDate, dateParameter, factorIndex) {
|
|
132
|
+
switch (dateParameter) {
|
|
133
|
+
case VariableDateKeyword.TODAY:
|
|
134
|
+
return (0, result_1.success)(targetDate);
|
|
135
|
+
case VariableDateKeyword.BBOM:
|
|
136
|
+
// Business Day of Beginning of Month
|
|
137
|
+
return (0, result_1.success)(targetMarketAccess.businessDayOfBeginningMonthWithOffset(targetDate, factorIndex));
|
|
138
|
+
case VariableDateKeyword.NEXTBBOM:
|
|
139
|
+
// Business Day of Beginning of Next Month
|
|
140
|
+
return (0, result_1.success)(targetMarketAccess.businessDayOfBeginningOfNextMonthWithOffset(targetDate, factorIndex));
|
|
141
|
+
case VariableDateKeyword.BOM:
|
|
142
|
+
// Beginning of Month
|
|
143
|
+
return (0, result_1.success)((0, date_fns_1.addDays)((0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), targetDate.getMonth() + 1, 1), factorIndex - 1));
|
|
144
|
+
case VariableDateKeyword.BEOM:
|
|
145
|
+
// Business Day of End Of Month
|
|
146
|
+
return (0, result_1.success)(targetMarketAccess.businessDayOfEndMonthWithOffset(targetDate, factorIndex));
|
|
147
|
+
case VariableDateKeyword.NEXTBEOM:
|
|
148
|
+
// Business Day of End of Next Month
|
|
149
|
+
const twoMonthAfter = (0, date_fns_1.addMonths)(targetDate, 2);
|
|
150
|
+
return (0, result_1.success)(targetMarketAccess.businessDayOfBeginningMonthWithOffset(twoMonthAfter, -factorIndex));
|
|
151
|
+
case VariableDateKeyword.PREVBEOM:
|
|
152
|
+
// Business Day of End of Previous Month
|
|
153
|
+
const bom = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), targetDate.getMonth() + 1, 1);
|
|
154
|
+
return (0, result_1.success)(targetMarketAccess.businessDay(bom, -factorIndex));
|
|
155
|
+
case VariableDateKeyword.EOM:
|
|
156
|
+
// End Of Month
|
|
157
|
+
const nextMonth = (0, date_fns_1.addMonths)(targetDate, 1);
|
|
158
|
+
return (0, result_1.success)((0, date_fns_1.subDays)((0, dateOperation_1.createDateOnly)(nextMonth.getFullYear(), nextMonth.getMonth() + 1, 1), factorIndex));
|
|
159
|
+
case VariableDateKeyword.NEXTBUS:
|
|
160
|
+
// Next Business Day
|
|
161
|
+
return (0, result_1.success)(targetMarketAccess.businessDay(targetDate, factorIndex));
|
|
162
|
+
case VariableDateKeyword.NEXTDAY:
|
|
163
|
+
// Next Day
|
|
164
|
+
return (0, result_1.success)((0, date_fns_1.addDays)(targetDate, factorIndex));
|
|
165
|
+
case VariableDateKeyword.PREVBUS:
|
|
166
|
+
// Previous Business Day
|
|
167
|
+
return (0, result_1.success)(targetMarketAccess.businessDay(targetDate, -factorIndex));
|
|
168
|
+
case VariableDateKeyword.PREVDAY:
|
|
169
|
+
// Previous Day
|
|
170
|
+
return (0, result_1.success)((0, date_fns_1.subDays)(targetDate, factorIndex));
|
|
171
|
+
case VariableDateKeyword.EOY:
|
|
172
|
+
// End of Year
|
|
173
|
+
const nextYear = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + 1, 1, 1);
|
|
174
|
+
return (0, result_1.success)((0, date_fns_1.subDays)(nextYear, factorIndex));
|
|
175
|
+
case VariableDateKeyword.BEOY:
|
|
176
|
+
// Business Day of End of Year
|
|
177
|
+
const nextYear2 = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + 1, 1, 1);
|
|
178
|
+
return (0, result_1.success)(targetMarketAccess.businessDay(nextYear2, -factorIndex));
|
|
179
|
+
case VariableDateKeyword.BBOY:
|
|
180
|
+
// Business Day Of Beginning of Year
|
|
181
|
+
const thisYear = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), 1, 1);
|
|
182
|
+
return (0, result_1.success)(targetMarketAccess.businessDay(thisYear, factorIndex - (targetMarketAccess.isBusinessDay(thisYear) ? 1 : 0)));
|
|
183
|
+
case VariableDateKeyword.BOY:
|
|
184
|
+
// Beginning of Year
|
|
185
|
+
const thisYear2 = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), 1, 1);
|
|
186
|
+
return (0, result_1.success)((0, date_fns_1.addDays)(thisYear2, factorIndex - 1));
|
|
187
|
+
default:
|
|
188
|
+
return (0, result_1.fail)(`${dateParameter} is not supported`, errors_1.ParseError);
|
|
189
|
+
}
|
|
190
|
+
}, _VariableTranslator_translate = function _VariableTranslator_translate(keyword, targetDate) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const parts = keyword.split('$');
|
|
193
|
+
let factorIndex = 1;
|
|
194
|
+
let variableType = VariableType.Date;
|
|
195
|
+
let translateMarketAccess = __classPrivateFieldGet(this, _VariableTranslator_marketAccess, "f");
|
|
196
|
+
//const supportedMarket = await this.#getSupportedMarket();
|
|
197
|
+
const stringList = new Array();
|
|
198
|
+
let dateParameter = (0, result_1.fail)('init', errors_1.ParseError);
|
|
199
|
+
// console.log('keyword', keyword);
|
|
200
|
+
// console.log('parts', parts);
|
|
201
|
+
for (var item of parts) {
|
|
202
|
+
if (!isNaN(parseInt(item))) {
|
|
203
|
+
factorIndex = parseInt(item);
|
|
204
|
+
}
|
|
205
|
+
else if (this.__supportedMarkets.includes(item)) {
|
|
206
|
+
// console.log('Market', item);
|
|
207
|
+
const result = yield holidays_1.default.getMarketAccess(item);
|
|
208
|
+
if (result.isFailure())
|
|
209
|
+
return new result_1.Failure(new errors_1.ParseError(`Fail to retrieve market data ${item}`, result.error));
|
|
210
|
+
translateMarketAccess = result.value;
|
|
211
|
+
}
|
|
212
|
+
else if (item in VariableDateKeyword) {
|
|
213
|
+
// console.log('internal keyword', item);
|
|
214
|
+
dateParameter = yield __classPrivateFieldGet(this, _VariableTranslator_instances, "m", _VariableTranslator_translateDate).call(this, translateMarketAccess, targetDate, item, factorIndex);
|
|
215
|
+
if (dateParameter.isFailure())
|
|
216
|
+
return dateParameter;
|
|
217
|
+
// console.log('parse date', dateParameter);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
switch (item) {
|
|
221
|
+
case 'PARAMMASTER':
|
|
222
|
+
// Retrieve from DB Parameter
|
|
223
|
+
variableType = VariableType.ParamMaster;
|
|
224
|
+
break;
|
|
225
|
+
case 'PARAMDICTIONARY':
|
|
226
|
+
variableType = VariableType.ParamMasterStringDictionary;
|
|
227
|
+
break;
|
|
228
|
+
case 'ARGUMENT':
|
|
229
|
+
variableType = VariableType.Argument;
|
|
230
|
+
break;
|
|
231
|
+
case 'ATTACHMENTFILE':
|
|
232
|
+
variableType = VariableType.ArgumentFile;
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
switch (variableType) {
|
|
236
|
+
case VariableType.Date:
|
|
237
|
+
const translateFormat = item;
|
|
238
|
+
if (!dateParameter || dateParameter.isFailure())
|
|
239
|
+
return (0, result_1.fail)(`Invalid Keyword Setting for date: ${keyword}`, errors_1.ParseError);
|
|
240
|
+
// console.log('format', item, dateParameter);
|
|
241
|
+
if (dateParameter.isFailure())
|
|
242
|
+
return dateParameter;
|
|
243
|
+
// console.log(
|
|
244
|
+
// 'formated date',
|
|
245
|
+
// format(dateParameter.value, translateFormat)
|
|
246
|
+
// );
|
|
247
|
+
stringList.push((0, date_fns_1.format)(dateParameter.value, translateFormat));
|
|
248
|
+
break;
|
|
249
|
+
case VariableType.ParamMaster:
|
|
250
|
+
stringList.push('');
|
|
251
|
+
break;
|
|
252
|
+
case VariableType.ParamMasterStringDictionary:
|
|
253
|
+
stringList.push('');
|
|
254
|
+
break;
|
|
255
|
+
case VariableType.Argument:
|
|
256
|
+
stringList.push(arguments[factorIndex - 1]);
|
|
257
|
+
break;
|
|
258
|
+
case VariableType.ArgumentFile:
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
parts.forEach((item) => __awaiter(this, void 0, void 0, function* () { }));
|
|
265
|
+
//console.log('parsed result', stringList);
|
|
266
|
+
return (0, result_1.success)(stringList.join(''));
|
|
267
|
+
});
|
|
268
|
+
}, _VariableTranslator_getSupportedMarket = function _VariableTranslator_getSupportedMarket() {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
const distinctMarkets = yield dbsingleton_1.default.gyomu_market_holiday.findMany({
|
|
271
|
+
select: { market: true },
|
|
272
|
+
distinct: ['market'],
|
|
273
|
+
});
|
|
274
|
+
const markets = new Array();
|
|
275
|
+
for (var row of distinctMarkets) {
|
|
276
|
+
markets.push(row.market);
|
|
277
|
+
}
|
|
278
|
+
return markets;
|
|
279
|
+
});
|
|
280
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Attribute_attribute;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Attribute = void 0;
|
|
16
|
+
class Attribute {
|
|
17
|
+
constructor(attribute) {
|
|
18
|
+
_Attribute_attribute.set(this, void 0);
|
|
19
|
+
__classPrivateFieldSet(this, _Attribute_attribute, attribute, "f");
|
|
20
|
+
}
|
|
21
|
+
get name() {
|
|
22
|
+
return __classPrivateFieldGet(this, _Attribute_attribute, "f").name;
|
|
23
|
+
}
|
|
24
|
+
get value() {
|
|
25
|
+
return __classPrivateFieldGet(this, _Attribute_attribute, "f").value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Attribute = Attribute;
|
|
29
|
+
_Attribute_attribute = new WeakMap();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Attribute } from './attribute';
|
|
2
|
+
import xpath from 'xpath';
|
|
3
|
+
export declare class DOMElement {
|
|
4
|
+
protected __node: HTMLElement;
|
|
5
|
+
constructor(node: HTMLElement);
|
|
6
|
+
get childElements(): Array<DOMElement>;
|
|
7
|
+
protected getNode<E extends HTMLElement>(): E;
|
|
8
|
+
get id(): string;
|
|
9
|
+
get innerHtml(): string;
|
|
10
|
+
get innerText(): string;
|
|
11
|
+
get childNodeValue(): string;
|
|
12
|
+
get classList(): string[];
|
|
13
|
+
get attributes(): Array<Attribute>;
|
|
14
|
+
getAttribute(name: string): Attribute | undefined;
|
|
15
|
+
searchByXPath(path: string): (string | number | boolean | Attribute | GenericElement<HTMLElement>)[];
|
|
16
|
+
searchOneByXPath(path: string): string | number | boolean | Attribute | GenericElement<HTMLElement> | undefined;
|
|
17
|
+
static parseXPathResultValue(searchValue: xpath.SelectedValue | undefined): string | number | boolean | Attribute | GenericElement<HTMLElement> | undefined;
|
|
18
|
+
static parseXPathResultValidValue(searchValue: xpath.SelectedValue): string | number | boolean | Attribute | GenericElement<HTMLElement>;
|
|
19
|
+
}
|
|
20
|
+
export declare class GenericElement<T extends HTMLElement> extends DOMElement {
|
|
21
|
+
constructor(node: T);
|
|
22
|
+
get node(): T;
|
|
23
|
+
getGenericElementsByTagName<K extends keyof HTMLElementTagNameMap>(qualifiedName: K): GenericElement<HTMLElementTagNameMap[K]>[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GenericElement = exports.DOMElement = void 0;
|
|
7
|
+
const attribute_1 = require("./attribute");
|
|
8
|
+
const xpath_1 = __importDefault(require("xpath"));
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
class DOMElement {
|
|
11
|
+
constructor(node) {
|
|
12
|
+
this.__node = node;
|
|
13
|
+
}
|
|
14
|
+
get childElements() {
|
|
15
|
+
const children = new Array();
|
|
16
|
+
for (var child of Array.from(this.__node.childNodes)) {
|
|
17
|
+
if (child instanceof HTMLElement) {
|
|
18
|
+
const childElement = new DOMElement(child);
|
|
19
|
+
children.push(childElement);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return children;
|
|
23
|
+
}
|
|
24
|
+
getNode() {
|
|
25
|
+
return this.__node;
|
|
26
|
+
}
|
|
27
|
+
get id() {
|
|
28
|
+
return this.__node.id;
|
|
29
|
+
}
|
|
30
|
+
get innerHtml() {
|
|
31
|
+
return this.__node.innerHTML;
|
|
32
|
+
}
|
|
33
|
+
get innerText() {
|
|
34
|
+
var _a;
|
|
35
|
+
return (_a = this.__node.textContent) !== null && _a !== void 0 ? _a : this.childNodeValue;
|
|
36
|
+
}
|
|
37
|
+
get childNodeValue() {
|
|
38
|
+
var _a;
|
|
39
|
+
const cnodes = this.__node.childNodes;
|
|
40
|
+
return cnodes.length > 0 ? (_a = cnodes.item(0).nodeValue) !== null && _a !== void 0 ? _a : '' : '';
|
|
41
|
+
}
|
|
42
|
+
get classList() {
|
|
43
|
+
let classArray = new Array();
|
|
44
|
+
this.__node.classList.forEach((val) => {
|
|
45
|
+
classArray.push(val);
|
|
46
|
+
});
|
|
47
|
+
return classArray;
|
|
48
|
+
}
|
|
49
|
+
get attributes() {
|
|
50
|
+
const attributeArray = new Array();
|
|
51
|
+
const nodeAttributes = this.__node.attributes;
|
|
52
|
+
for (let i = 0; i < nodeAttributes.length; i++) {
|
|
53
|
+
const nodeAttribute = nodeAttributes.item(i);
|
|
54
|
+
if (!!nodeAttribute) {
|
|
55
|
+
const attribute = new attribute_1.Attribute(nodeAttribute);
|
|
56
|
+
attributeArray.push(attribute);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return attributeArray;
|
|
60
|
+
}
|
|
61
|
+
getAttribute(name) {
|
|
62
|
+
const nodeAttribute = this.__node.attributes.getNamedItem(name);
|
|
63
|
+
if (!nodeAttribute)
|
|
64
|
+
return undefined;
|
|
65
|
+
else
|
|
66
|
+
return new attribute_1.Attribute(nodeAttribute);
|
|
67
|
+
}
|
|
68
|
+
searchByXPath(path) {
|
|
69
|
+
return xpath_1.default.select(path, this.__node).map((v) => {
|
|
70
|
+
return DOMElement.parseXPathResultValidValue(v);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
searchOneByXPath(path) {
|
|
74
|
+
const searchValue = xpath_1.default.select(path, this.__node, true);
|
|
75
|
+
return DOMElement.parseXPathResultValue(searchValue);
|
|
76
|
+
}
|
|
77
|
+
static parseXPathResultValue(searchValue) {
|
|
78
|
+
if (!searchValue)
|
|
79
|
+
return undefined;
|
|
80
|
+
return DOMElement.parseXPathResultValidValue(searchValue);
|
|
81
|
+
}
|
|
82
|
+
static parseXPathResultValidValue(searchValue) {
|
|
83
|
+
switch (typeof searchValue) {
|
|
84
|
+
case 'string':
|
|
85
|
+
return searchValue;
|
|
86
|
+
case 'number':
|
|
87
|
+
return searchValue;
|
|
88
|
+
case 'boolean':
|
|
89
|
+
return searchValue;
|
|
90
|
+
default:
|
|
91
|
+
if (searchValue instanceof Attr) {
|
|
92
|
+
return new attribute_1.Attribute(searchValue);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
if (searchValue instanceof HTMLElement) {
|
|
96
|
+
return new GenericElement(searchValue);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new errors_1.WebParseError(`Unsupported Value: ${JSON.stringify(searchValue)}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.DOMElement = DOMElement;
|
|
106
|
+
class GenericElement extends DOMElement {
|
|
107
|
+
constructor(node) {
|
|
108
|
+
super(node);
|
|
109
|
+
}
|
|
110
|
+
get node() {
|
|
111
|
+
return this.__node;
|
|
112
|
+
}
|
|
113
|
+
getGenericElementsByTagName(qualifiedName) {
|
|
114
|
+
return Array.from(this.__node.getElementsByTagName(qualifiedName)).map((element) => {
|
|
115
|
+
return new GenericElement(element);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.GenericElement = GenericElement;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Page, PageOption, PageResponseOption, PageTextOption } from './page';
|
|
2
|
+
export { Attribute } from './attribute';
|
|
3
|
+
export { DOMElement, GenericElement } from './element';
|
|
4
|
+
export { Table } from './table';
|
|
5
|
+
export { TableRow } from './tableRow';
|
|
6
|
+
export { TableColumn } from './tableColumn';
|
|
7
|
+
export { convertGenericElementByTagName, convertHTMLElementByTagName, } from './util';
|
package/lib/web/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertHTMLElementByTagName = exports.convertGenericElementByTagName = exports.TableColumn = exports.TableRow = exports.Table = exports.GenericElement = exports.DOMElement = exports.Attribute = exports.Page = void 0;
|
|
4
|
+
var page_1 = require("./page");
|
|
5
|
+
Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return page_1.Page; } });
|
|
6
|
+
var attribute_1 = require("./attribute");
|
|
7
|
+
Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return attribute_1.Attribute; } });
|
|
8
|
+
var element_1 = require("./element");
|
|
9
|
+
Object.defineProperty(exports, "DOMElement", { enumerable: true, get: function () { return element_1.DOMElement; } });
|
|
10
|
+
Object.defineProperty(exports, "GenericElement", { enumerable: true, get: function () { return element_1.GenericElement; } });
|
|
11
|
+
var table_1 = require("./table");
|
|
12
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
|
|
13
|
+
var tableRow_1 = require("./tableRow");
|
|
14
|
+
Object.defineProperty(exports, "TableRow", { enumerable: true, get: function () { return tableRow_1.TableRow; } });
|
|
15
|
+
var tableColumn_1 = require("./tableColumn");
|
|
16
|
+
Object.defineProperty(exports, "TableColumn", { enumerable: true, get: function () { return tableColumn_1.TableColumn; } });
|
|
17
|
+
var util_1 = require("./util");
|
|
18
|
+
Object.defineProperty(exports, "convertGenericElementByTagName", { enumerable: true, get: function () { return util_1.convertGenericElementByTagName; } });
|
|
19
|
+
Object.defineProperty(exports, "convertHTMLElementByTagName", { enumerable: true, get: function () { return util_1.convertHTMLElementByTagName; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { DOMElement, GenericElement } from './element';
|
|
3
|
+
export declare type PageResponseOption = {
|
|
4
|
+
kind: 'response';
|
|
5
|
+
response: AxiosResponse;
|
|
6
|
+
};
|
|
7
|
+
export declare type PageTextOption = {
|
|
8
|
+
kind: 'html';
|
|
9
|
+
htmlText: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type PageOption = PageResponseOption | PageTextOption;
|
|
12
|
+
export declare class Page {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(option: PageOption);
|
|
15
|
+
getElementById<T extends HTMLElement>(id: string): GenericElement<T> | undefined;
|
|
16
|
+
getDOMElementsByClassName(className: string): DOMElement[];
|
|
17
|
+
getElementsByClassName<T extends HTMLElement>(className: string): GenericElement<T>[];
|
|
18
|
+
get html(): string;
|
|
19
|
+
searchByXPath(path: string): (string | number | boolean | import("./attribute").Attribute | GenericElement<HTMLElement>)[];
|
|
20
|
+
searchOneByXPath(path: string): string | number | boolean | import("./attribute").Attribute | GenericElement<HTMLElement> | undefined;
|
|
21
|
+
get title(): string | undefined;
|
|
22
|
+
}
|
package/lib/web/page.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _Page_response, _Page_xdoc, _Page_htmlString;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Page = void 0;
|
|
19
|
+
const xmlserializer_1 = __importDefault(require("xmlserializer"));
|
|
20
|
+
const xmldom_1 = __importDefault(require("xmldom"));
|
|
21
|
+
// import { tmpNameSync } from 'tmp';
|
|
22
|
+
// import { writeFileSync } from 'fs';
|
|
23
|
+
const element_1 = require("./element");
|
|
24
|
+
const parse5_1 = require("parse5");
|
|
25
|
+
const xpath_1 = __importDefault(require("xpath"));
|
|
26
|
+
class Page {
|
|
27
|
+
constructor(option) {
|
|
28
|
+
_Page_response.set(this, void 0);
|
|
29
|
+
//readonly #dom: JSDOM;
|
|
30
|
+
_Page_xdoc.set(this, void 0);
|
|
31
|
+
_Page_htmlString.set(this, void 0);
|
|
32
|
+
if (option.kind === 'response') {
|
|
33
|
+
__classPrivateFieldSet(this, _Page_response, option.response, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _Page_htmlString, __classPrivateFieldGet(this, _Page_response, "f").data, "f");
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
__classPrivateFieldSet(this, _Page_htmlString, option.htmlText, "f");
|
|
38
|
+
}
|
|
39
|
+
const document = (0, parse5_1.parse)(__classPrivateFieldGet(this, _Page_htmlString, "f"));
|
|
40
|
+
const xhtml = xmlserializer_1.default.serializeToString(document);
|
|
41
|
+
__classPrivateFieldSet(this, _Page_xdoc, new xmldom_1.default.DOMParser().parseFromString(xhtml), "f");
|
|
42
|
+
// this.#dom = new JSDOM(response.data as string);
|
|
43
|
+
// this.#dom.window.document.evaluate;
|
|
44
|
+
}
|
|
45
|
+
getElementById(id) {
|
|
46
|
+
const element = __classPrivateFieldGet(this, _Page_xdoc, "f").getElementById(id);
|
|
47
|
+
if (!element || !element)
|
|
48
|
+
return undefined;
|
|
49
|
+
return new element_1.GenericElement(element);
|
|
50
|
+
}
|
|
51
|
+
getDOMElementsByClassName(className) {
|
|
52
|
+
return Array.from(__classPrivateFieldGet(this, _Page_xdoc, "f").getElementsByClassName(className))
|
|
53
|
+
.filter((value) => {
|
|
54
|
+
if (!value || !value)
|
|
55
|
+
return false;
|
|
56
|
+
return true;
|
|
57
|
+
})
|
|
58
|
+
.map((e) => new element_1.DOMElement(e));
|
|
59
|
+
}
|
|
60
|
+
getElementsByClassName(className) {
|
|
61
|
+
//const elementArray = new Array<HTMLElement>();
|
|
62
|
+
return Array.from(__classPrivateFieldGet(this, _Page_xdoc, "f").getElementsByClassName(className))
|
|
63
|
+
.filter((value) => {
|
|
64
|
+
if (!value || !value)
|
|
65
|
+
return false;
|
|
66
|
+
return true;
|
|
67
|
+
})
|
|
68
|
+
.map((e) => new element_1.GenericElement(e));
|
|
69
|
+
//return elementArray;
|
|
70
|
+
}
|
|
71
|
+
get html() {
|
|
72
|
+
return __classPrivateFieldGet(this, _Page_htmlString, "f");
|
|
73
|
+
}
|
|
74
|
+
searchByXPath(path) {
|
|
75
|
+
return xpath_1.default.select(path, __classPrivateFieldGet(this, _Page_xdoc, "f")).map((v) => {
|
|
76
|
+
return element_1.DOMElement.parseXPathResultValidValue(v);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
searchOneByXPath(path) {
|
|
80
|
+
const searchValue = xpath_1.default.select(path, __classPrivateFieldGet(this, _Page_xdoc, "f"), true);
|
|
81
|
+
return element_1.DOMElement.parseXPathResultValue(searchValue);
|
|
82
|
+
}
|
|
83
|
+
get title() {
|
|
84
|
+
let fileName;
|
|
85
|
+
if (!!__classPrivateFieldGet(this, _Page_response, "f")) {
|
|
86
|
+
if ('Content-Disposition' in __classPrivateFieldGet(this, _Page_response, "f").headers) {
|
|
87
|
+
const headerValue = __classPrivateFieldGet(this, _Page_response, "f").headers['Content-Disposition'];
|
|
88
|
+
fileName = decodeURI(headerValue.substring(headerValue.indexOf('filename=') + 9));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!fileName) {
|
|
92
|
+
const titleElements = __classPrivateFieldGet(this, _Page_xdoc, "f").getElementsByTagName('title');
|
|
93
|
+
if (titleElements.length > 0) {
|
|
94
|
+
const titleElement = titleElements.item(0);
|
|
95
|
+
fileName = titleElement.innerText;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return fileName;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.Page = Page;
|
|
102
|
+
_Page_response = new WeakMap(), _Page_xdoc = new WeakMap(), _Page_htmlString = new WeakMap();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GenericElement } from './element';
|
|
2
|
+
import { TableRow } from './tableRow';
|
|
3
|
+
export declare type TableOption = {
|
|
4
|
+
headerExist: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare class Table extends GenericElement<HTMLTableElement> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(node: HTMLTableElement, { headerExist }?: TableOption);
|
|
9
|
+
__headers: TableRow[];
|
|
10
|
+
__records: TableRow[];
|
|
11
|
+
get rows(): TableRow[];
|
|
12
|
+
toDictionaryArray(): {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|