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.
Files changed (77) hide show
  1. package/lib/archive/abstract.d.ts +7 -0
  2. package/lib/archive/abstract.js +30 -0
  3. package/lib/archive/gz.d.ts +16 -0
  4. package/lib/archive/gz.js +66 -0
  5. package/lib/archive/index.d.ts +3 -0
  6. package/lib/archive/index.js +19 -0
  7. package/lib/archive/tar.d.ts +17 -0
  8. package/lib/archive/tar.js +165 -0
  9. package/lib/archive/zip.d.ts +28 -0
  10. package/lib/archive/zip.js +254 -0
  11. package/lib/base64.d.ts +6 -0
  12. package/lib/base64.js +24 -0
  13. package/lib/buffer.d.ts +4 -0
  14. package/lib/buffer.js +23 -0
  15. package/lib/configurator.d.ts +16 -0
  16. package/lib/configurator.js +53 -0
  17. package/lib/dateOperation.d.ts +3 -0
  18. package/lib/dateOperation.js +23 -0
  19. package/lib/dbsingleton.d.ts +11 -0
  20. package/lib/dbsingleton.js +13 -0
  21. package/lib/dbutil.d.ts +3 -0
  22. package/lib/dbutil.js +44 -0
  23. package/lib/dictionary.d.ts +8 -0
  24. package/lib/dictionary.js +55 -0
  25. package/lib/encryption.d.ts +17 -0
  26. package/lib/encryption.js +202 -0
  27. package/lib/errors.d.ts +31 -0
  28. package/lib/errors.js +64 -0
  29. package/lib/excel.d.ts +1 -0
  30. package/lib/excel.js +34 -0
  31. package/lib/fileModel.d.ts +96 -0
  32. package/lib/fileModel.js +170 -0
  33. package/lib/fileOperation.d.ts +11 -0
  34. package/lib/fileOperation.js +275 -0
  35. package/lib/holidays.d.ts +20 -0
  36. package/lib/holidays.js +200 -0
  37. package/lib/index.d.ts +15 -0
  38. package/lib/index.js +31 -0
  39. package/lib/milestone.d.ts +19 -0
  40. package/lib/milestone.js +169 -0
  41. package/lib/net/_ftp.d.ts +0 -0
  42. package/lib/net/_ftp.js +228 -0
  43. package/lib/net/ftp.d.ts +19 -0
  44. package/lib/net/ftp.js +160 -0
  45. package/lib/net/remoteConnection.d.ts +11 -0
  46. package/lib/net/remoteConnection.js +26 -0
  47. package/lib/net/sftp.d.ts +19 -0
  48. package/lib/net/sftp.js +155 -0
  49. package/lib/numberOperation.d.ts +3 -0
  50. package/lib/numberOperation.js +24 -0
  51. package/lib/parameter.d.ts +14 -0
  52. package/lib/parameter.js +291 -0
  53. package/lib/result.d.ts +23 -0
  54. package/lib/result.js +47 -0
  55. package/lib/timer.d.ts +11 -0
  56. package/lib/timer.js +62 -0
  57. package/lib/user.d.ts +11 -0
  58. package/lib/user.js +23 -0
  59. package/lib/variable.d.ts +11 -0
  60. package/lib/variable.js +280 -0
  61. package/lib/web/attribute.d.ts +6 -0
  62. package/lib/web/attribute.js +29 -0
  63. package/lib/web/element.d.ts +24 -0
  64. package/lib/web/element.js +119 -0
  65. package/lib/web/index.d.ts +7 -0
  66. package/lib/web/index.js +19 -0
  67. package/lib/web/page.d.ts +22 -0
  68. package/lib/web/page.js +102 -0
  69. package/lib/web/table.d.ts +15 -0
  70. package/lib/web/table.js +110 -0
  71. package/lib/web/tableColumn.d.ts +10 -0
  72. package/lib/web/tableColumn.js +21 -0
  73. package/lib/web/tableRow.d.ts +10 -0
  74. package/lib/web/tableRow.js +80 -0
  75. package/lib/web/util.d.ts +12 -0
  76. package/lib/web/util.js +22 -0
  77. package/package.json +63 -0
@@ -0,0 +1,200 @@
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 _MarketDateAccess_instances, _MarketDateAccess_market, _MarketDateAccess_holidays, _MarketDateAccess_initDataLoad;
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const format_1 = __importDefault(require("date-fns/format"));
28
+ const addDays_1 = __importDefault(require("date-fns/addDays"));
29
+ const subDays_1 = __importDefault(require("date-fns/subDays"));
30
+ const date_fns_1 = require("date-fns");
31
+ const dateOperation_1 = require("./dateOperation");
32
+ const dbsingleton_1 = __importDefault(require("./dbsingleton"));
33
+ const dbutil_1 = require("./dbutil");
34
+ const result_1 = require("./result");
35
+ class MarketDateAccess {
36
+ constructor(market) {
37
+ _MarketDateAccess_instances.add(this);
38
+ _MarketDateAccess_market.set(this, void 0);
39
+ _MarketDateAccess_holidays.set(this, new Array());
40
+ __classPrivateFieldSet(this, _MarketDateAccess_market, market, "f");
41
+ //console.log('__marketHolidays', MarketDateAccess.__marketHolidays);
42
+ if (market in MarketDateAccess.__marketHolidays) {
43
+ __classPrivateFieldSet(this, _MarketDateAccess_holidays, MarketDateAccess.__marketHolidays[market], "f");
44
+ return;
45
+ }
46
+ }
47
+ //static async getMarketAccess(market: string, ctx: Context) {
48
+ static getMarketAccess(market) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const access = new MarketDateAccess(market);
51
+ const result = yield __classPrivateFieldGet(access, _MarketDateAccess_instances, "m", _MarketDateAccess_initDataLoad).call(access);
52
+ if (result.isFailure())
53
+ return result;
54
+ return (0, result_1.success)(access);
55
+ });
56
+ }
57
+ isBusinessDay(targetDate) {
58
+ const dayOfWeek = targetDate.getDay();
59
+ const targetYYYYMMDD = (0, format_1.default)(targetDate, 'yyyyMMdd');
60
+ if (dayOfWeek === 0 || dayOfWeek === 6)
61
+ return false;
62
+ const holidayArray = __classPrivateFieldGet(this, _MarketDateAccess_holidays, "f").filter((val) => val === targetYYYYMMDD);
63
+ return !holidayArray || holidayArray.length === 0;
64
+ }
65
+ businessDay(targetDate, dayOffset) {
66
+ if (dayOffset === 0)
67
+ return this.__getNextBusinessDay(this.__getPreviousBusinessDay(targetDate, 1), 1);
68
+ if (dayOffset > 0)
69
+ return this.__getNextBusinessDay(targetDate, dayOffset);
70
+ return this.__getPreviousBusinessDay(targetDate, -dayOffset);
71
+ }
72
+ __getNextBusinessDay(targetDate, dayOffset) {
73
+ let businessDay = targetDate;
74
+ while (dayOffset > 0) {
75
+ businessDay = (0, addDays_1.default)(businessDay, 1);
76
+ if (this.isBusinessDay(businessDay))
77
+ dayOffset--;
78
+ }
79
+ return businessDay;
80
+ }
81
+ __getPreviousBusinessDay(targetDate, dayOffset) {
82
+ let businessDay = targetDate;
83
+ while (dayOffset > 0) {
84
+ businessDay = (0, subDays_1.default)(businessDay, 1);
85
+ if (this.isBusinessDay(businessDay))
86
+ dayOffset--;
87
+ }
88
+ return businessDay;
89
+ }
90
+ businessDayOfBeginningMonthWithOffset(targetDate, dayOffset = 1) {
91
+ let businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), targetDate.getMonth() + 1, 1);
92
+ if (this.isBusinessDay(businessDay)) {
93
+ if (dayOffset > 1)
94
+ return this.businessDay(businessDay, dayOffset - 1);
95
+ else
96
+ return businessDay;
97
+ }
98
+ return this.businessDay(businessDay, dayOffset);
99
+ }
100
+ businessDayOfBeginningOfNextMonthWithOffset(targetDate, dayOffset = 1) {
101
+ let businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + (targetDate.getMonth() === 11 ? 1 : 0), targetDate.getMonth() + 2 + (targetDate.getMonth() === 11 ? -11 : 0), 1);
102
+ let result = businessDay;
103
+ if (dayOffset === 0)
104
+ dayOffset = 1;
105
+ if (this.isBusinessDay(businessDay)) {
106
+ if (dayOffset > 1)
107
+ result = this.businessDay(businessDay, dayOffset - 1);
108
+ }
109
+ else
110
+ result = this.businessDay(businessDay, dayOffset);
111
+ // if (isEqual(result, targetDate) || isAfter(targetDate, result)) {
112
+ // businessDay = addMonths(businessDay, 1);
113
+ // if (this.isBusinessDay(businessDay)) {
114
+ // if (dayOffset > 1)
115
+ // result = this.businessDay(businessDay, dayOffset - 1);
116
+ // } else result = this.businessDay(businessDay, dayOffset);
117
+ // }
118
+ return result;
119
+ }
120
+ businessDayOfBeginningOfPreviousMonthWithOffset(targetDate, dayOffset = 1) {
121
+ let businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + (targetDate.getMonth() === 0 ? -1 : 0), targetDate.getMonth() + 1 + (targetDate.getMonth() === 0 ? 11 : -1), 1);
122
+ let result = businessDay;
123
+ if (this.isBusinessDay(businessDay)) {
124
+ if (dayOffset > 1)
125
+ result = this.businessDay(businessDay, dayOffset - 1);
126
+ }
127
+ else
128
+ result = this.businessDay(businessDay, dayOffset);
129
+ // if (isEqual(result, targetDate) || isAfter(targetDate, result)) {
130
+ // businessDay = addMonths(businessDay, 1);
131
+ // if (this.isBusinessDay(businessDay)) {
132
+ // if (dayOffset > 1)
133
+ // result = this.businessDay(businessDay, dayOffset - 1);
134
+ // } else result = this.businessDay(businessDay, dayOffset);
135
+ // }
136
+ return result;
137
+ }
138
+ businessDayOfEndMonthWithOffset(targetDate, dayOffset) {
139
+ let businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + (targetDate.getMonth() === 11 ? 1 : 0), targetDate.getMonth() + 1 + (targetDate.getMonth() === 11 ? -11 : 1), 1);
140
+ if (dayOffset === 0)
141
+ dayOffset = 1;
142
+ return this.businessDay(businessDay, -dayOffset);
143
+ }
144
+ businessDayOfEndOfNextMonthWithOffset(targetDate, dayOffset) {
145
+ let businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + (targetDate.getMonth() === 11 ? 1 : 0), targetDate.getMonth() + 1 + (targetDate.getMonth() === 11 ? -11 : 1), 1);
146
+ if (dayOffset === 0)
147
+ dayOffset = 1;
148
+ let result = this.businessDay(businessDay, -dayOffset);
149
+ if ((0, date_fns_1.isEqual)(targetDate, result) || (0, date_fns_1.isBefore)(targetDate, result)) {
150
+ businessDay = (0, date_fns_1.addMonths)(businessDay, 1);
151
+ result = this.businessDay(businessDay, -dayOffset);
152
+ }
153
+ return result;
154
+ }
155
+ businessDayOfEndOfPreviousMonthWithOffset(targetDate, dayOffset) {
156
+ const businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), targetDate.getMonth() + 1, 1);
157
+ if (dayOffset === 0)
158
+ dayOffset = 1;
159
+ return this.businessDay(businessDay, -dayOffset);
160
+ }
161
+ businessDayOfBeginningOfYear(targetDate, dayOffset) {
162
+ const businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear(), 1, 1);
163
+ if (this.isBusinessDay(businessDay))
164
+ return this.businessDay(businessDay, dayOffset - 1);
165
+ return this.businessDay(businessDay, dayOffset);
166
+ }
167
+ businessDayOfEndOfYear(targetDate, dayOffset) {
168
+ const businessDay = (0, dateOperation_1.createDateOnly)(targetDate.getFullYear() + 1, 1, 1);
169
+ if (dayOffset === 0)
170
+ dayOffset = 1;
171
+ return this.businessDay(businessDay, -dayOffset);
172
+ }
173
+ }
174
+ exports.default = MarketDateAccess;
175
+ _MarketDateAccess_market = new WeakMap(), _MarketDateAccess_holidays = new WeakMap(), _MarketDateAccess_instances = new WeakSet(), _MarketDateAccess_initDataLoad = function _MarketDateAccess_initDataLoad() {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ if (__classPrivateFieldGet(this, _MarketDateAccess_holidays, "f").length > 0)
178
+ return (0, result_1.success)(true);
179
+ __classPrivateFieldSet(this, _MarketDateAccess_holidays, new Array(), "f");
180
+ const result = yield (0, dbutil_1.genericDBFunction)('load gyomu_market_holiday', () => __awaiter(this, void 0, void 0, function* () {
181
+ //console.log('loading');
182
+ const item_values = yield dbsingleton_1.default.gyomu_market_holiday.findMany({
183
+ where: { market: __classPrivateFieldGet(this, _MarketDateAccess_market, "f") },
184
+ });
185
+ //console.log('loaded');
186
+ return (0, result_1.success)(item_values);
187
+ }), []);
188
+ if (result.isFailure())
189
+ return result;
190
+ const holidays = result.value;
191
+ //console.log('holidays', holidays);
192
+ holidays.forEach((row) => {
193
+ __classPrivateFieldGet(this, _MarketDateAccess_holidays, "f").push(row.holiday);
194
+ });
195
+ //console.log('#holidays', this.#holidays);
196
+ MarketDateAccess.__marketHolidays[__classPrivateFieldGet(this, _MarketDateAccess_market, "f")] = __classPrivateFieldGet(this, _MarketDateAccess_holidays, "f");
197
+ return (0, result_1.success)(true);
198
+ });
199
+ };
200
+ MarketDateAccess.__marketHolidays = {};
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from './base64';
2
+ export * from './buffer';
3
+ export * from './configurator';
4
+ export * from './dictionary';
5
+ export * from './encryption';
6
+ export * from './errors';
7
+ export * from './excel';
8
+ export * from './fileModel';
9
+ export * from './fileOperation';
10
+ export * from './holidays';
11
+ export * from './numberOperation';
12
+ export * from './result';
13
+ export * from './user';
14
+ export * from './web';
15
+ export * from './archive';
package/lib/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base64"), exports);
18
+ __exportStar(require("./buffer"), exports);
19
+ __exportStar(require("./configurator"), exports);
20
+ __exportStar(require("./dictionary"), exports);
21
+ __exportStar(require("./encryption"), exports);
22
+ __exportStar(require("./errors"), exports);
23
+ __exportStar(require("./excel"), exports);
24
+ __exportStar(require("./fileModel"), exports);
25
+ __exportStar(require("./fileOperation"), exports);
26
+ __exportStar(require("./holidays"), exports);
27
+ __exportStar(require("./numberOperation"), exports);
28
+ __exportStar(require("./result"), exports);
29
+ __exportStar(require("./user"), exports);
30
+ __exportStar(require("./web"), exports);
31
+ __exportStar(require("./archive"), exports);
@@ -0,0 +1,19 @@
1
+ import { gyomu_milestone_daily, gyomu_milestone_cdtbl } from '@prisma/client';
2
+ import { DBError } from './errors';
3
+ import { PromiseResult } from './result';
4
+ interface MilestoneExistResultType {
5
+ exists: boolean;
6
+ updateTime: Date | undefined;
7
+ }
8
+ export declare class Milestone {
9
+ #private;
10
+ static exists(milestoneId: string, targetDate: Date, isMonthly?: boolean): PromiseResult<MilestoneExistResultType, DBError>;
11
+ static register(milestoneId: string, targetDate: Date, isMonthly?: boolean): Promise<import("./result").Result<Date, DBError>>;
12
+ static wait(milestoneId: string, targetDate: Date, timeoutSecond: number): Promise<import("./result").Result<boolean, import("./errors").TimeoutError>>;
13
+ static retrieveMilestoneDailyList(targetDateYYYYMMDD: string): Promise<import("./result").Result<gyomu_milestone_daily[], DBError>>;
14
+ static deleteMilestoneDaily(milestoneId: string, targetDateYYYYMMDD: string): Promise<import("./result").Result<gyomu_milestone_daily, DBError>>;
15
+ static milestoneList(): Promise<import("./result").Result<gyomu_milestone_cdtbl[], DBError>>;
16
+ static upsertMilestoneCode(record: gyomu_milestone_cdtbl, milestoneId?: string): Promise<import("./result").Result<gyomu_milestone_cdtbl, DBError>>;
17
+ static deleteMilestoneCode(milestoneId: string): Promise<import("./result").Result<gyomu_milestone_cdtbl, DBError>>;
18
+ }
19
+ export {};
@@ -0,0 +1,169 @@
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, _Milestone_convertTargetDate;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.Milestone = void 0;
22
+ const date_fns_1 = require("date-fns");
23
+ const dbsingleton_1 = __importDefault(require("./dbsingleton"));
24
+ const result_1 = require("./result");
25
+ const timer_1 = require("./timer");
26
+ const dbutil_1 = require("./dbutil");
27
+ class Milestone {
28
+ static exists(milestoneId, targetDate, isMonthly = false) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ let targetDateYYYYMMDD = __classPrivateFieldGet(this, _a, "m", _Milestone_convertTargetDate).call(this, targetDate, isMonthly);
31
+ return yield (0, dbutil_1.genericDBFunction)('check gyomu_milestone_daily existence', (milestoneId, targetDate, isMonthly) => __awaiter(this, void 0, void 0, function* () {
32
+ const record = yield dbsingleton_1.default.gyomu_milestone_daily.findUnique({
33
+ where: {
34
+ target_date_milestone_id: {
35
+ milestone_id: milestoneId,
36
+ target_date: targetDateYYYYMMDD,
37
+ },
38
+ },
39
+ });
40
+ if (!!record)
41
+ return (0, result_1.success)({
42
+ exists: true,
43
+ updateTime: new Date(Number(record.update_time)),
44
+ });
45
+ else
46
+ return (0, result_1.success)({ exists: false, updateTime: undefined });
47
+ }), [milestoneId, targetDate, isMonthly]);
48
+ });
49
+ }
50
+ static register(milestoneId, targetDate, isMonthly = false) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const existsResult = yield this.exists(milestoneId, targetDate, isMonthly);
53
+ if (existsResult.isFailure())
54
+ return existsResult;
55
+ if (existsResult.value.exists)
56
+ return (0, result_1.success)(new Date(Number(existsResult.value.updateTime)));
57
+ let targetDateYYYYMMDD = __classPrivateFieldGet(this, _a, "m", _Milestone_convertTargetDate).call(this, targetDate, isMonthly);
58
+ return yield (0, dbutil_1.genericDBFunction)('register gyomu_milestone_daily record', (milestoneId, targetDate, isMonthly) => __awaiter(this, void 0, void 0, function* () {
59
+ const result = yield dbsingleton_1.default.gyomu_milestone_daily.create({
60
+ data: { milestone_id: milestoneId, target_date: targetDateYYYYMMDD },
61
+ });
62
+ return (0, result_1.success)(new Date(Number(result.update_time)));
63
+ }), [milestoneId, targetDate, isMonthly]);
64
+ });
65
+ }
66
+ static wait(milestoneId, targetDate, timeoutSecond) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ let interval = 5;
69
+ if (timeoutSecond < 60)
70
+ interval = 1;
71
+ return yield (0, timer_1.polling)(`Wait for milestone ${milestoneId} on ${(0, date_fns_1.format)(targetDate, 'yyyyMMdd')} to be on`, timeoutSecond, interval, (milestoneId, targetDate) => __awaiter(this, void 0, void 0, function* () {
72
+ const existsResult = yield this.exists(milestoneId, targetDate);
73
+ if (existsResult.isFailure())
74
+ return existsResult;
75
+ return (0, result_1.success)(existsResult.value.exists);
76
+ }), milestoneId, targetDate);
77
+ });
78
+ }
79
+ static retrieveMilestoneDailyList(targetDateYYYYMMDD) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const targetDateMonthly = targetDateYYYYMMDD.substring(0, 6) + '**';
82
+ return (0, dbutil_1.genericDBFunction)('search milestone_daily', (targetDateYYYYMMDD, targetDateMonthly) => __awaiter(this, void 0, void 0, function* () {
83
+ const records = yield dbsingleton_1.default.gyomu_milestone_daily.findMany({
84
+ where: {
85
+ OR: [
86
+ {
87
+ target_date: targetDateYYYYMMDD,
88
+ },
89
+ { target_date: targetDateMonthly },
90
+ ],
91
+ },
92
+ });
93
+ return (0, result_1.success)(records);
94
+ }), [targetDateYYYYMMDD, targetDateMonthly]);
95
+ });
96
+ }
97
+ static deleteMilestoneDaily(milestoneId, targetDateYYYYMMDD) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return yield (0, dbutil_1.genericDBFunction)('delete gyomu_milestone_daily', (milestoneId, targetDateYYYYMMDD) => __awaiter(this, void 0, void 0, function* () {
100
+ const deletedRecord = yield dbsingleton_1.default.gyomu_milestone_daily.delete({
101
+ where: {
102
+ target_date_milestone_id: {
103
+ milestone_id: milestoneId,
104
+ target_date: targetDateYYYYMMDD,
105
+ },
106
+ },
107
+ });
108
+ return (0, result_1.success)(deletedRecord);
109
+ }), [milestoneId, targetDateYYYYMMDD]);
110
+ });
111
+ }
112
+ static milestoneList() {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ return yield (0, dbutil_1.genericDBFunction)('retrieve gyomu_milestone_cdtbl records', () => __awaiter(this, void 0, void 0, function* () {
115
+ const records = yield dbsingleton_1.default.gyomu_milestone_cdtbl.findMany();
116
+ return (0, result_1.success)(records);
117
+ }), []);
118
+ });
119
+ }
120
+ static upsertMilestoneCode(record, milestoneId) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ let needCreate = true;
123
+ if (!!milestoneId) {
124
+ const result = yield (0, dbutil_1.genericDBFunction)('check existence of gyomu_milestone_cdtbl record', (milestoneId) => __awaiter(this, void 0, void 0, function* () {
125
+ const record = yield dbsingleton_1.default.gyomu_milestone_cdtbl.findUnique({
126
+ where: { milestone_id: milestoneId },
127
+ });
128
+ return (0, result_1.success)(!!record);
129
+ }), [milestoneId]);
130
+ if (result.isFailure())
131
+ return result;
132
+ needCreate = !result.value;
133
+ }
134
+ return yield (0, dbutil_1.genericDBFunction)('Insert gyomu_milestone_cdtbl record', (record, needCreate, milestoneId) => __awaiter(this, void 0, void 0, function* () {
135
+ let result;
136
+ if (needCreate) {
137
+ result = yield dbsingleton_1.default.gyomu_milestone_cdtbl.create({
138
+ data: record,
139
+ });
140
+ }
141
+ else {
142
+ result = yield dbsingleton_1.default.gyomu_milestone_cdtbl.update({
143
+ data: record,
144
+ where: { milestone_id: milestoneId },
145
+ });
146
+ }
147
+ return (0, result_1.success)(result);
148
+ }), [record, needCreate, milestoneId]);
149
+ });
150
+ }
151
+ static deleteMilestoneCode(milestoneId) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ return yield (0, dbutil_1.genericDBFunction)('delete gyomu_milestone_cdtbl record', (milestoneId) => __awaiter(this, void 0, void 0, function* () {
154
+ const result = yield dbsingleton_1.default.gyomu_milestone_cdtbl.delete({
155
+ where: { milestone_id: milestoneId },
156
+ });
157
+ return (0, result_1.success)(result);
158
+ }), [milestoneId]);
159
+ });
160
+ }
161
+ }
162
+ exports.Milestone = Milestone;
163
+ _a = Milestone, _Milestone_convertTargetDate = function _Milestone_convertTargetDate(targetDate, isMonthly) {
164
+ let targetDateYYYYMMDD = (0, date_fns_1.format)(targetDate, 'yyyyMMdd');
165
+ if (isMonthly) {
166
+ targetDateYYYYMMDD = (0, date_fns_1.format)(targetDate, 'yyyyMM') + '**';
167
+ }
168
+ return targetDateYYYYMMDD;
169
+ };
File without changes
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ // import FtpClient from 'ftp';
3
+ // import fs from 'fs';
4
+ // import { PeerCertificate } from 'tls';
5
+ // import { NetworkError } from '../errors';
6
+ // import { FileTransportInfo } from '../fileModel';
7
+ // import { success, fail, Failure, PromiseResult, Result } from '../result';
8
+ // import { RemoteConnection } from './remoteConnection';
9
+ // import path from 'path';
10
+ // export class Ftp {
11
+ // #connectionInformation: RemoteConnection;
12
+ // constructor(connectionConfig: RemoteConnection) {
13
+ // this.#connectionInformation = connectionConfig;
14
+ // this.client = new FtpClient();
15
+ // this.isConnected = false;
16
+ // }
17
+ // client: FtpClient;
18
+ // isConnected: boolean;
19
+ // async #init(): PromiseResult<boolean, NetworkError> {
20
+ // return new Promise((resolve, reject) => {
21
+ // const errProcess = (err: Error) => {
22
+ // resolve(new Failure(new NetworkError('FTP connection Error', err)));
23
+ // };
24
+ // this.client.on('ready', () => {
25
+ // this.isConnected = true;
26
+ // this.client.off('error', errProcess);
27
+ // resolve(success(true));
28
+ // });
29
+ // this.client.once('error', errProcess);
30
+ // const ftpOptions: FtpClient.Options = {
31
+ // host: this.#connectionInformation.serverURL,
32
+ // port: this.#connectionInformation.port,
33
+ // user: this.#connectionInformation.userId,
34
+ // password: this.#connectionInformation.password,
35
+ // secure: this.#connectionInformation.sslEnabled,
36
+ // secureOptions: !this.#connectionInformation.sslEnabled
37
+ // ? undefined
38
+ // : {
39
+ // host: this.#connectionInformation.serverURL,
40
+ // port: this.#connectionInformation.port,
41
+ // checkServerIdentity: (
42
+ // hostname: string,
43
+ // cert: PeerCertificate
44
+ // ) => {
45
+ // return undefined;
46
+ // },
47
+ // },
48
+ // };
49
+ // this.client.connect(ftpOptions);
50
+ // });
51
+ // }
52
+ // async download(transportInformation: FileTransportInfo) {
53
+ // let result;
54
+ // if (!this.isConnected) {
55
+ // result = await this.#init();
56
+ // if (result.isFailure()) return result;
57
+ // if (!result.value) return result;
58
+ // }
59
+ // result = await new Promise<Result<boolean, NetworkError>>(
60
+ // (resolve, reject) => {
61
+ // //if(isBinary)
62
+ // {
63
+ // this.client.binary(async (err: Error) => {
64
+ // if (err)
65
+ // resolve(
66
+ // new Failure(new NetworkError('Fail to set binary mode', err))
67
+ // );
68
+ // this.client.get(
69
+ // transportInformation.sourceFullName.replace(path.sep, '/'),
70
+ // (err, stream) => {
71
+ // if (err)
72
+ // resolve(
73
+ // new Failure(
74
+ // new NetworkError(
75
+ // `Fail to download file ${transportInformation.sourceFileName}`,
76
+ // err
77
+ // )
78
+ // )
79
+ // );
80
+ // stream.on('error', (err) => {
81
+ // resolve(
82
+ // new Failure(
83
+ // new NetworkError(
84
+ // `Fail to download file ${transportInformation.sourceFileName}`,
85
+ // err as Error
86
+ // )
87
+ // )
88
+ // );
89
+ // });
90
+ // stream.once('close', () => {
91
+ // this.client.end();
92
+ // resolve(success(true));
93
+ // });
94
+ // stream.pipe(
95
+ // fs.createWriteStream(transportInformation.destinationFullName)
96
+ // );
97
+ // }
98
+ // );
99
+ // });
100
+ // }
101
+ // }
102
+ // );
103
+ // return result;
104
+ // }
105
+ // async upload(transportInformation: FileTransportInfo) {
106
+ // let result;
107
+ // if (!this.isConnected) {
108
+ // result = await this.#init();
109
+ // if (result.isFailure()) return result;
110
+ // if (!result.value) return result;
111
+ // }
112
+ // result = await new Promise<Result<boolean, NetworkError>>(
113
+ // (resolve, reject) => {
114
+ // //if(isBinary)
115
+ // {
116
+ // this.client.binary(async (err: Error) => {
117
+ // if (err)
118
+ // resolve(
119
+ // new Failure(new NetworkError('Fail to set binary mode', err))
120
+ // );
121
+ // this.client.put(
122
+ // transportInformation.sourceFullName,
123
+ // transportInformation.destinationFullName,
124
+ // (err) => {
125
+ // if (err)
126
+ // resolve(
127
+ // new Failure(
128
+ // new NetworkError(
129
+ // `Fail to upload file ${transportInformation.sourceFileName}`,
130
+ // err
131
+ // )
132
+ // )
133
+ // );
134
+ // resolve(success(true));
135
+ // }
136
+ // );
137
+ // });
138
+ // }
139
+ // }
140
+ // );
141
+ // return result;
142
+ // }
143
+ // async getFileInfo(transportInformation: FileTransportInfo) {
144
+ // let result;
145
+ // if (!this.isConnected) {
146
+ // result = await this.#init();
147
+ // if (result.isFailure()) return result;
148
+ // }
149
+ // let result2 = await new Promise<
150
+ // Result<{ size: number; date: Date }, NetworkError>
151
+ // >((resolve, reject) => {
152
+ // //if(isBinary)
153
+ // {
154
+ // this.client.list(
155
+ // transportInformation.sourceFolderName ?? ''.replace(path.sep, '/'),
156
+ // (err: Error, listing) => {
157
+ // if (err)
158
+ // resolve(
159
+ // new Failure(
160
+ // new NetworkError('Fail to retrieve file information', err)
161
+ // )
162
+ // );
163
+ // for (var information of listing) {
164
+ // if (
165
+ // information.name.toUpperCase() !==
166
+ // transportInformation.sourceFileName.toUpperCase()
167
+ // )
168
+ // continue;
169
+ // resolve(
170
+ // success({ size: information.size, date: information.date })
171
+ // );
172
+ // return;
173
+ // }
174
+ // }
175
+ // );
176
+ // }
177
+ // });
178
+ // return result2;
179
+ // }
180
+ // async listFiles(transportInformation: FileTransportInfo) {
181
+ // let result;
182
+ // if (!this.isConnected) {
183
+ // result = await this.#init();
184
+ // if (result.isFailure()) return result;
185
+ // }
186
+ // let result2 = await new Promise<Result<string[], NetworkError>>(
187
+ // (resolve, reject) => {
188
+ // //if(isBinary)
189
+ // {
190
+ // this.client.list(
191
+ // transportInformation.sourceFolderName ?? ''.replace(path.sep, '/'),
192
+ // (err: Error, listing) => {
193
+ // if (err)
194
+ // resolve(
195
+ // new Failure(
196
+ // new NetworkError('Fail to retrieve file information', err)
197
+ // )
198
+ // );
199
+ // const files = new Array<string>();
200
+ // for (var information of listing) {
201
+ // files.push(information.name);
202
+ // }
203
+ // resolve(success(files));
204
+ // }
205
+ // );
206
+ // }
207
+ // }
208
+ // );
209
+ // return result2;
210
+ // }
211
+ // async close() {
212
+ // return new Promise<Result<boolean, NetworkError>>((resolve, reject) => {
213
+ // if (!this.isConnected) {
214
+ // return;
215
+ // }
216
+ // this.client.once('error', (err) => {
217
+ // resolve(
218
+ // new Failure(new NetworkError('Fail to disconnect', err as Error))
219
+ // );
220
+ // });
221
+ // this.client.on('end', () => {
222
+ // this.isConnected = false;
223
+ // resolve(success(true));
224
+ // });
225
+ // this.client.end();
226
+ // });
227
+ // }
228
+ // }