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/parameter.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
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");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
var _a, _ParameterAccess_loadParameter;
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.ParameterAccess = void 0;
|
|
22
|
+
const date_fns_1 = require("date-fns");
|
|
23
|
+
const dbsingleton_1 = __importDefault(require("./dbsingleton"));
|
|
24
|
+
const errors_1 = require("./errors");
|
|
25
|
+
const result_1 = require("./result");
|
|
26
|
+
const dbutil_1 = require("./dbutil");
|
|
27
|
+
class ParameterAccess {
|
|
28
|
+
static keyExists(key) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const values = yield __classPrivateFieldGet(this, _a, "m", _ParameterAccess_loadParameter).call(this, key);
|
|
31
|
+
if (values.isSuccess())
|
|
32
|
+
return (0, result_1.success)(values.value.length > 0);
|
|
33
|
+
return values;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
static getKey(key, user) {
|
|
37
|
+
if (!!user)
|
|
38
|
+
return user.userId + '_' + key;
|
|
39
|
+
return key;
|
|
40
|
+
}
|
|
41
|
+
static value(key, user, targetDate) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const itemKey = this.getKey(key, user);
|
|
44
|
+
let itemValues = undefined;
|
|
45
|
+
let itemValue = '';
|
|
46
|
+
let errorCount = 0;
|
|
47
|
+
while (errorCount < 3) {
|
|
48
|
+
const result = yield __classPrivateFieldGet(this, _a, "m", _ParameterAccess_loadParameter).call(this, key);
|
|
49
|
+
if (result.isSuccess()) {
|
|
50
|
+
itemValues = result.value;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
errorCount++;
|
|
54
|
+
if (errorCount >= 3) {
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!itemValues || itemValues.length === 0) {
|
|
59
|
+
return (0, result_1.fail)('Unknown error on retrieving parameter', errors_1.DBError);
|
|
60
|
+
}
|
|
61
|
+
if (!!targetDate) {
|
|
62
|
+
const targetDateYYYYMMDD = (0, date_fns_1.format)(targetDate, 'yyyyMMdd');
|
|
63
|
+
const defaultRow = itemValues.find((v) => v.item_fromdate === '');
|
|
64
|
+
if (!!defaultRow) {
|
|
65
|
+
itemValue = defaultRow.item_value;
|
|
66
|
+
}
|
|
67
|
+
const sortedArray = itemValues.sort((a, b) => {
|
|
68
|
+
return a.item_fromdate > b.item_fromdate
|
|
69
|
+
? 1
|
|
70
|
+
: a.item_fromdate === b.item_fromdate
|
|
71
|
+
? 0
|
|
72
|
+
: -1;
|
|
73
|
+
});
|
|
74
|
+
for (var row of sortedArray) {
|
|
75
|
+
//console.log(row.item_fromdate, targetDateYYYYMMDD);
|
|
76
|
+
if (!row.item_value)
|
|
77
|
+
continue;
|
|
78
|
+
if (!row.item_fromdate || !row.item_fromdate.trim())
|
|
79
|
+
itemValue = row.item_value;
|
|
80
|
+
else if (row.item_fromdate === targetDateYYYYMMDD) {
|
|
81
|
+
itemValue = row.item_value;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
else if (targetDateYYYYMMDD > row.item_fromdate)
|
|
85
|
+
itemValue = row.item_value;
|
|
86
|
+
else
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
itemValue = itemValues[0].item_value;
|
|
92
|
+
}
|
|
93
|
+
return (0, result_1.success)(itemValue);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
static booleanValue(key, user, targetDate) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const result = yield ParameterAccess.value(key, user, targetDate);
|
|
99
|
+
if (result.isFailure())
|
|
100
|
+
return result;
|
|
101
|
+
const resultString = result.value;
|
|
102
|
+
return (0, result_1.success)(resultString === 'true');
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
static numberValue(key, user, targetDate) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const result = yield ParameterAccess.value(key, user, targetDate);
|
|
108
|
+
if (result.isFailure())
|
|
109
|
+
return result;
|
|
110
|
+
const resultString = result.value;
|
|
111
|
+
return (0, result_1.success)(+resultString);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// static async stringListValue(
|
|
115
|
+
// key: string,
|
|
116
|
+
// user?: User,
|
|
117
|
+
// targetDate?: Date
|
|
118
|
+
// ): PromiseResult<Array<string>, DBError> {
|
|
119
|
+
// const result = await ParameterAccess.value(key, user, targetDate);
|
|
120
|
+
// if (result.isFailure()) return result;
|
|
121
|
+
// const resultString = result.value;
|
|
122
|
+
// const stringList = JSON.parse(resultString) as string[];
|
|
123
|
+
// return success(stringList);
|
|
124
|
+
// }
|
|
125
|
+
// static async listValue<T>(
|
|
126
|
+
// key: string,
|
|
127
|
+
// user?: User,
|
|
128
|
+
// targetDate?: Date
|
|
129
|
+
// ): PromiseResult<Array<T>, DBError> {
|
|
130
|
+
// const result = await ParameterAccess.value(key, user, targetDate);
|
|
131
|
+
// if (result.isFailure()) return result;
|
|
132
|
+
// const resultString = result.value;
|
|
133
|
+
// const list = JSON.parse(resultString) as Array<T>;
|
|
134
|
+
// return success(list);
|
|
135
|
+
// }
|
|
136
|
+
// static async stringDictionaryValue(
|
|
137
|
+
// key: string,
|
|
138
|
+
// user?: User,
|
|
139
|
+
// targetDate?: Date
|
|
140
|
+
// ): PromiseResult<{ [key: string]: string }, DBError> {
|
|
141
|
+
// const result = await ParameterAccess.value(key, user, targetDate);
|
|
142
|
+
// if (result.isFailure()) return result;
|
|
143
|
+
// const resultString = result.value;
|
|
144
|
+
// const dictionary = JSON.parse(resultString) as { [key: string]: string };
|
|
145
|
+
// return success(dictionary);
|
|
146
|
+
// }
|
|
147
|
+
// static async dictionaryValue<T>(
|
|
148
|
+
// key: string,
|
|
149
|
+
// user?: User,
|
|
150
|
+
// targetDate?: Date
|
|
151
|
+
// ): PromiseResult<{ [key: string]: T }, DBError> {
|
|
152
|
+
// const result = await ParameterAccess.value(key, user, targetDate);
|
|
153
|
+
// if (result.isFailure()) return result;
|
|
154
|
+
// const resultString = result.value;
|
|
155
|
+
// const dictionary = JSON.parse(resultString) as { [key: string]: T };
|
|
156
|
+
// return success(dictionary);
|
|
157
|
+
// }
|
|
158
|
+
// static async base64EncodedValue(key: string): PromiseResult<string, DBError> {
|
|
159
|
+
// const result = await ParameterAccess.value(key);
|
|
160
|
+
// if (result.isFailure()) return result;
|
|
161
|
+
// const resultString = result.value;
|
|
162
|
+
// return success(base64String2String(resultString));
|
|
163
|
+
// }
|
|
164
|
+
static setValue(key, item, user) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const itemKey = this.getKey(key, user);
|
|
167
|
+
const keyExistResult = yield this.keyExists(itemKey);
|
|
168
|
+
const itemValue = item.toString();
|
|
169
|
+
if (keyExistResult.isFailure())
|
|
170
|
+
return keyExistResult;
|
|
171
|
+
//console.log('Key Check Done');
|
|
172
|
+
return yield (0, dbutil_1.genericDBFunction)(`setup gyomu_param_master for ${itemKey}`, (itemKey, itemValue) => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
if (keyExistResult.value) {
|
|
174
|
+
if (!itemValue) {
|
|
175
|
+
//Delete Record
|
|
176
|
+
yield dbsingleton_1.default.gyomu_param_master.delete({
|
|
177
|
+
where: {
|
|
178
|
+
item_key_item_fromdate: {
|
|
179
|
+
item_key: itemKey,
|
|
180
|
+
item_fromdate: '',
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
//Update Record
|
|
187
|
+
yield dbsingleton_1.default.gyomu_param_master.update({
|
|
188
|
+
where: {
|
|
189
|
+
item_key_item_fromdate: {
|
|
190
|
+
item_key: itemKey,
|
|
191
|
+
item_fromdate: '',
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
data: { item_value: itemValue },
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
if (!!itemValue) {
|
|
200
|
+
//Insert
|
|
201
|
+
yield dbsingleton_1.default.gyomu_param_master.create({
|
|
202
|
+
data: {
|
|
203
|
+
item_key: itemKey,
|
|
204
|
+
item_fromdate: '',
|
|
205
|
+
item_value: itemValue,
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return (0, result_1.success)(true);
|
|
211
|
+
}), [itemKey, itemValue]);
|
|
212
|
+
// try {
|
|
213
|
+
// if (keyExistResult.value) {
|
|
214
|
+
// if (!itemValue) {
|
|
215
|
+
// //Delete Record
|
|
216
|
+
// await prisma.gyomu_param_master.delete({
|
|
217
|
+
// where: {
|
|
218
|
+
// item_key_item_fromdate: { item_key: itemKey, item_fromdate: '' },
|
|
219
|
+
// },
|
|
220
|
+
// });
|
|
221
|
+
// } else {
|
|
222
|
+
// //Update Record
|
|
223
|
+
// await prisma.gyomu_param_master.update({
|
|
224
|
+
// where: {
|
|
225
|
+
// item_key_item_fromdate: { item_key: itemKey, item_fromdate: '' },
|
|
226
|
+
// },
|
|
227
|
+
// data: { item_value: itemValue },
|
|
228
|
+
// });
|
|
229
|
+
// }
|
|
230
|
+
// } else {
|
|
231
|
+
// if (!itemValue) {
|
|
232
|
+
// //Insert
|
|
233
|
+
// await prisma.gyomu_param_master.create({
|
|
234
|
+
// data: {
|
|
235
|
+
// item_key: itemKey,
|
|
236
|
+
// item_fromdate: '',
|
|
237
|
+
// item_value: itemValue,
|
|
238
|
+
// },
|
|
239
|
+
// });
|
|
240
|
+
// }
|
|
241
|
+
// }
|
|
242
|
+
// return success(true);
|
|
243
|
+
// } catch (e) {
|
|
244
|
+
// if (
|
|
245
|
+
// e instanceof Prisma.PrismaClientKnownRequestError ||
|
|
246
|
+
// e instanceof Prisma.PrismaClientUnknownRequestError ||
|
|
247
|
+
// e instanceof Prisma.PrismaClientValidationError
|
|
248
|
+
// ) {
|
|
249
|
+
// return new Failure(
|
|
250
|
+
// new DBError('Fail to set data on gyomu_param_master', e)
|
|
251
|
+
// );
|
|
252
|
+
// } else if (e instanceof Prisma.PrismaClientRustPanicError) {
|
|
253
|
+
// throw new CriticalError(
|
|
254
|
+
// 'Critical error on Prisma. Need to terminate the application',
|
|
255
|
+
// e
|
|
256
|
+
// );
|
|
257
|
+
// } else {
|
|
258
|
+
// return new Failure(
|
|
259
|
+
// new DBError(
|
|
260
|
+
// 'Unknown failure to set data on gyomu_param_master',
|
|
261
|
+
// e as Error
|
|
262
|
+
// )
|
|
263
|
+
// );
|
|
264
|
+
// }
|
|
265
|
+
//}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.ParameterAccess = ParameterAccess;
|
|
270
|
+
_a = ParameterAccess, _ParameterAccess_loadParameter = function _ParameterAccess_loadParameter(key) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
return yield (0, dbutil_1.genericDBFunction)('load gyomu_param_master', (key) => __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
//console.log('loading');
|
|
274
|
+
const item_values = yield dbsingleton_1.default.gyomu_param_master.findMany({
|
|
275
|
+
where: { item_key: key },
|
|
276
|
+
});
|
|
277
|
+
//console.log('loaded');
|
|
278
|
+
return (0, result_1.success)(item_values);
|
|
279
|
+
}), [key]);
|
|
280
|
+
// try {
|
|
281
|
+
// const item_values = await prisma.gyomu_param_master.findMany({
|
|
282
|
+
// where: { item_key: key },
|
|
283
|
+
// });
|
|
284
|
+
// return success(item_values);
|
|
285
|
+
// } catch (err) {
|
|
286
|
+
// return new Failure(
|
|
287
|
+
// new DBError('Fail to load gyomu_param_master', err as Error)
|
|
288
|
+
// );
|
|
289
|
+
// }
|
|
290
|
+
});
|
|
291
|
+
};
|
package/lib/result.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseError } from './errors';
|
|
2
|
+
export declare type Result<T, E extends Error> = Success<T> | Failure<E>;
|
|
3
|
+
export declare type PromiseResult<T, E extends Error> = Promise<Result<T, E>>;
|
|
4
|
+
export declare class Success<T> {
|
|
5
|
+
readonly value: T;
|
|
6
|
+
constructor(value: T);
|
|
7
|
+
isSuccess(): this is Success<T>;
|
|
8
|
+
isFailure(): this is Failure<BaseError>;
|
|
9
|
+
}
|
|
10
|
+
export declare class Failure<E extends BaseError> {
|
|
11
|
+
readonly error: E;
|
|
12
|
+
constructor(error: E);
|
|
13
|
+
isSuccess(): this is Success<unknown>;
|
|
14
|
+
isFailure(): this is Failure<E>;
|
|
15
|
+
}
|
|
16
|
+
export declare function fail<E extends BaseError>(message: string, type: {
|
|
17
|
+
new (message: string): E;
|
|
18
|
+
}): Failure<E>;
|
|
19
|
+
export declare function success<T>(object: T): Success<T>;
|
|
20
|
+
export declare function promiseSuccess<T, E extends BaseError>(val: T): PromiseResult<T, E>;
|
|
21
|
+
export declare function promiseFail<T, E extends BaseError>(message: string, type: {
|
|
22
|
+
new (message: string): E;
|
|
23
|
+
}): PromiseResult<T, E>;
|
package/lib/result.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promiseFail = exports.promiseSuccess = exports.success = exports.fail = exports.Failure = exports.Success = void 0;
|
|
4
|
+
class Success {
|
|
5
|
+
constructor(value) {
|
|
6
|
+
this.value = value;
|
|
7
|
+
}
|
|
8
|
+
isSuccess() {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
isFailure() {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Success = Success;
|
|
16
|
+
class Failure {
|
|
17
|
+
constructor(error) {
|
|
18
|
+
this.error = error;
|
|
19
|
+
}
|
|
20
|
+
isSuccess() {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
isFailure() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.Failure = Failure;
|
|
28
|
+
function fail(message, type) {
|
|
29
|
+
return new Failure(new type(message));
|
|
30
|
+
}
|
|
31
|
+
exports.fail = fail;
|
|
32
|
+
function success(object) {
|
|
33
|
+
return new Success(object);
|
|
34
|
+
}
|
|
35
|
+
exports.success = success;
|
|
36
|
+
function promiseSuccess(val) {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
resolve(success(val));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.promiseSuccess = promiseSuccess;
|
|
42
|
+
function promiseFail(message, type) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
resolve(new Failure(new type(message)));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.promiseFail = promiseFail;
|
package/lib/timer.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseError, TimeoutError } from './errors';
|
|
2
|
+
import { PromiseResult, Result } from './result';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param pollingActionName
|
|
6
|
+
* explanation of this aciton during polling
|
|
7
|
+
* @returns
|
|
8
|
+
* Return success(true) when it's good result in polling. Otherwise return success(false)
|
|
9
|
+
* Return Failure with TimeoutError if there is any unexpected error
|
|
10
|
+
*/
|
|
11
|
+
export declare function polling<E extends BaseError>(pollingActionName: string, timeoutSeconds: number, intervalSeconds: number, timerFunc: (...args: any) => PromiseResult<boolean, E>, ...args: any): Promise<Result<boolean, TimeoutError>>;
|
package/lib/timer.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.polling = void 0;
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const result_1 = require("./result");
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param pollingActionName
|
|
18
|
+
* explanation of this aciton during polling
|
|
19
|
+
* @returns
|
|
20
|
+
* Return success(true) when it's good result in polling. Otherwise return success(false)
|
|
21
|
+
* Return Failure with TimeoutError if there is any unexpected error
|
|
22
|
+
*/
|
|
23
|
+
function polling(pollingActionName, timeoutSeconds, intervalSeconds, timerFunc, ...args) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const timeoutTime = new Date().getTime() + timeoutSeconds * 1000;
|
|
26
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
const result = yield timerFunc(...args);
|
|
29
|
+
if (result.isFailure()) {
|
|
30
|
+
return resolve(new result_1.Failure(new errors_1.TimeoutError(`Fail on polling: ${pollingActionName}`, result.error)));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (result.value) {
|
|
34
|
+
return resolve((0, result_1.success)(result.value));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const timerId = yield setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const result = yield timerFunc(...args);
|
|
39
|
+
if (result.isFailure()) {
|
|
40
|
+
clearInterval(timerId);
|
|
41
|
+
return resolve(new result_1.Failure(new errors_1.TimeoutError(`Fail on polling: ${pollingActionName}`, result.error)));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (result.value) {
|
|
45
|
+
clearInterval(timerId);
|
|
46
|
+
return resolve((0, result_1.success)(result.value));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (new Date().getTime() > timeoutTime) {
|
|
50
|
+
//console.log('Timeout');
|
|
51
|
+
clearInterval(timerId);
|
|
52
|
+
return resolve((0, result_1.success)(false));
|
|
53
|
+
}
|
|
54
|
+
}), intervalSeconds * 1000);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
reject(e);
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.polling = polling;
|
package/lib/user.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
isGroup: boolean;
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
userId: string;
|
|
5
|
+
isEqual: (other: User) => boolean;
|
|
6
|
+
isInMember: (groupUser: User) => boolean;
|
|
7
|
+
region: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class UserFactory {
|
|
10
|
+
static getCurrentUser: () => User;
|
|
11
|
+
}
|
package/lib/user.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserFactory = void 0;
|
|
4
|
+
class DummyUser {
|
|
5
|
+
constructor(uid) {
|
|
6
|
+
this.isGroup = false;
|
|
7
|
+
this.isValid = true;
|
|
8
|
+
this.isEqual = (other) => {
|
|
9
|
+
return this.userId === other.userId;
|
|
10
|
+
};
|
|
11
|
+
this.isInMember = (groupUser) => {
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
14
|
+
this.region = '';
|
|
15
|
+
this.userId = uid;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class UserFactory {
|
|
19
|
+
}
|
|
20
|
+
exports.UserFactory = UserFactory;
|
|
21
|
+
UserFactory.getCurrentUser = () => {
|
|
22
|
+
return new DummyUser('testUid');
|
|
23
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DBError, ParseError } from './errors';
|
|
2
|
+
import { PromiseResult } from './result';
|
|
3
|
+
export declare class VariableTranslator {
|
|
4
|
+
#private;
|
|
5
|
+
__supportedMarkets: string[];
|
|
6
|
+
private constructor();
|
|
7
|
+
static getTranslator(market: string): PromiseResult<VariableTranslator, DBError>;
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
parse(inputString: string, targetDate: Date): PromiseResult<string, ParseError>;
|
|
10
|
+
parseDate(keyword: string, targetDate: Date): PromiseResult<Date, ParseError>;
|
|
11
|
+
}
|