pg-mvc-service 2.0.43 → 2.0.44

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/index.d.ts ADDED
@@ -0,0 +1,189 @@
1
+ import { AxiosResponse } from "axios";
2
+ import { Request, Response } from 'express';
3
+ import { Pool, PoolClient } from 'pg';
4
+ import { ErrorMessageType, IncomingHttpHeaders } from './src/reqestResponse/RequestType';
5
+ import { ArrayType, EnumType, ObjectType, PrimitiveType } from './src/reqestResponse/ReqResType';
6
+
7
+ import { MethodType } from './src/Service';
8
+ export { MethodType } from './src/Service';
9
+
10
+ import { Base64Client } from './src/clients/Base64Client';
11
+ import { StringClient } from './src/clients/StringClient';
12
+ import { EncryptClient } from './src/clients/EncryptClient';
13
+
14
+ import { AwsS3Client } from './src/clients/AwsS3Client';
15
+ export { AwsS3Client } from './src/clients/AwsS3Client';
16
+
17
+ // models class
18
+ import ValidateClient from './src/models/ValidateClient';
19
+
20
+ import { TableModel } from "./src/models/TableModel";
21
+ export { TableModel } from "./src/models/TableModel";
22
+
23
+ export { TColumnAttribute, TColumnType, TColumnArrayType, TColumn, TColumnDetail, TOperator, TColumnInfo, TQuery, TSelectExpression, TAggregateFuncType, TCondition, TNestedCondition, TSortKeyword, TKeyFormat } from './src/models/Type';
24
+
25
+ export { DayType, MonthType, DateType, HourType, MinuteSecondType } from './src/cron/CronType';
26
+ export { BaseCron } from "./src/cron/BaseCron";
27
+ export { runCron } from "./src/cron/CronExecuter";
28
+
29
+ declare module 'pg-mvc-service' {
30
+ export class Service {
31
+ protected readonly method: MethodType;
32
+ get Method(): MethodType;
33
+ protected readonly endpoint: string;
34
+ get Endpoint(): string;
35
+ protected readonly apiCode: string;
36
+ get ApiCode(): string;
37
+ protected readonly summary: string;
38
+ get Summary(): string;
39
+ protected readonly apiUserAvailable: string;
40
+ get ApiUserAvailable(): string;
41
+ protected readonly request: RequestType;
42
+ get AuthToken(): string;
43
+ protected readonly response: ResponseType;
44
+ protected readonly isTest: boolean;
45
+ protected readonly tags: Array<string>;
46
+ get Tags(): Array<string>;
47
+
48
+ protected readonly req: Request;
49
+ protected readonly res: Response;
50
+ constructor(request: Request, response: Response);
51
+
52
+ public inintialize(): void;
53
+
54
+ protected dbUser?: string;
55
+ protected dbHost?: string;
56
+ protected dbName?: string;
57
+ protected dbPassword?: string;
58
+ protected dbPort?: number;
59
+ protected dbIsSslConnect?: boolean;
60
+ protected checkMaintenance(): Promise<void>;
61
+ protected middleware(): Promise<void>;
62
+
63
+ public resSuccess(): void;
64
+ public handleException(ex: any): void;
65
+ protected outputErrorLog(ex: any): Promise<void>;
66
+
67
+ protected get Pool(): Pool;
68
+ protected get Client(): PoolClient;
69
+
70
+ public startConnect(): Promise<void>;
71
+ public commit(): Promise<void>;
72
+ public rollback(): Promise<void>;
73
+ public release(): Promise<void>;
74
+
75
+ get S3Client(): AwsS3Client;
76
+ get Base64Client(): Base64Client;
77
+ get StringClient(): StringClient;
78
+ get EncryptClient(): EncryptClient;
79
+
80
+ public requestApi<TRequest=Record<string, any>, TResponse={[key: string]: any}>(
81
+ method: MethodType, url: string, params: TRequest, header: {[key: string]: any}): Promise<AxiosResponse<TResponse>>;
82
+ }
83
+
84
+ export interface IParams {
85
+ in: 'header' | 'path',
86
+ name: string,
87
+ require?: boolean,
88
+ description?: string,
89
+ example?: string
90
+ }
91
+ export function createSwagger(services: Service[], name: string, url: string, params: Array<IParams>): string;
92
+
93
+ export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType;
94
+
95
+ export class RequestType {
96
+ constructor();
97
+
98
+ protected properties: { [key: string]: PropertyType; };
99
+ protected paramProperties: Array<(PrimitiveType | EnumType) & { key: string }>;
100
+ protected readonly ERROR_MESSAGE: ErrorMessageType;
101
+
102
+ protected throwException(code: string, message: string): never;
103
+
104
+ public setRequest(request: Request): void;
105
+ get Data(): { [key: string]: any };
106
+ get Headers(): IncomingHttpHeaders;
107
+ get Params(): { [key: string]: any };
108
+ get RemoteAddress(): string | undefined;
109
+ get Authorization(): string | null;
110
+ }
111
+
112
+ export class ResponseType {
113
+ public Data: { [key: string]: any };
114
+
115
+ protected properties: { [key: string]: PropertyType; };
116
+ get ResponseData(): { [key: string]: any };
117
+ }
118
+
119
+ export class AuthException extends Error {
120
+ private id: string;
121
+ get Id(): string;
122
+ constructor(id: string, message?: string);
123
+ }
124
+
125
+ export class ForbiddenException extends Error {
126
+ }
127
+
128
+ export class InputErrorException extends Error {
129
+ private errorId: string;
130
+ get ErrorId(): string;
131
+ private errorLog: string;
132
+ get ErrorLog(): string;
133
+ constructor(errorId: string, message?: string, errorLog?: string);
134
+ }
135
+
136
+ export class MaintenanceException extends Error {
137
+ constructor(message?: string);
138
+ }
139
+
140
+ export class DbConflictException extends Error {
141
+ private errorId: string;
142
+ get ErrorId(): string;
143
+ constructor(errorId: string, message?: string);
144
+ }
145
+
146
+ export class NotFoundException extends Error {
147
+ private errorId: string;
148
+ get ErrorId(): string;
149
+ constructor(errorId: string, message?: string);
150
+ }
151
+
152
+ export class UnprocessableException extends Error {
153
+ private errorId: string;
154
+ get ErrorId(): string;
155
+ constructor(errorId: string, message?: string);
156
+ }
157
+
158
+ export function createTableDoc(models: Array<TableModel>, serviceName?: string): string;
159
+ export function migrate(migrates: Array<MigrateTable>, poolParam: {
160
+ host: string, user: string, dbName: string, password: string, port?: number, isSsl?: boolean
161
+ }): Promise<void>;
162
+ export function rollback(toNumber: number, poolParam: {
163
+ host: string, user: string, dbName: string, password: string, port?: number, isSsl?: boolean
164
+ }): Promise<void>;
165
+ export class MigrateTable {
166
+ protected readonly migrateSql: string;
167
+ protected readonly rollbackSql: string;
168
+ protected readonly addGrantTables: Array<string>;
169
+ protected readonly user: string;
170
+
171
+ constructor();
172
+ constructor(user: string);
173
+ }
174
+
175
+ export class MigrateDatabase {
176
+ constructor(dbName: string, userName: string, pool: Pool);
177
+
178
+ get DbName(): string;
179
+ get UserName(): string;
180
+ get Password(): string | null;
181
+
182
+ public IsExistUser(): Promise<boolean>;
183
+ public CreateUser(password?: string): Promise<void>;
184
+ public IsExistDb(): Promise<boolean>;
185
+ public CreateDb(collateType?: string): Promise<void>;
186
+ public RollbackDbSql(): string;
187
+ public RollbackUserSql(otherUserName: string): string;
188
+ }
189
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.43",
3
+ "version": "2.0.44",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -14,10 +14,6 @@
14
14
  "author": "Sho Nakadaira",
15
15
  "type": "commonjs",
16
16
  "main": "dist/index.js",
17
- "files": [
18
- "dist",
19
- "dist/assets"
20
- ],
21
17
  "scripts": {
22
18
  "build": "rm -rf dist/* && tsc && npm run copy-assets",
23
19
  "copy-assets": "copyfiles -u 2 src/assets/* dist/assets",
@@ -0,0 +1,48 @@
1
+ // PoolManager.ts
2
+ import { Pool } from 'pg';
3
+
4
+ export default class PoolManager {
5
+ private static poolMap: Record<string, Pool> = {};
6
+
7
+ static getPool(user: string, host: string, database: string, password: string, port: number | string, isSslConnect: boolean): Pool {
8
+ const key = `${user}@${host}/${database}`;
9
+ if (!this.poolMap[key]) {
10
+ this.poolMap[key] = new Pool({
11
+ user: user,
12
+ host: host,
13
+ database: database,
14
+ password: password,
15
+ port: Number(port),
16
+ ssl: isSslConnect ? {
17
+ rejectUnauthorized: false
18
+ } : false
19
+ });
20
+ }
21
+
22
+ return this.poolMap[key];
23
+ }
24
+
25
+ static async shutdownAll(): Promise<void> {
26
+ for (const [key, pool] of Object.entries(this.poolMap)) {
27
+ try {
28
+ await pool.end();
29
+ console.log(`Closed pool: ${key}`);
30
+ } catch (e) {
31
+ console.error(`Error closing pool ${key}`, e);
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ // ✅ 自動実行されるシャットダウン登録
38
+ process.on('SIGINT', async () => {
39
+ console.log('🔌 SIGINT received. Closing all pools...');
40
+ await PoolManager.shutdownAll();
41
+ process.exit(0);
42
+ });
43
+
44
+ process.on('SIGTERM', async () => {
45
+ console.log('🔌 SIGTERM received. Closing all pools...');
46
+ await PoolManager.shutdownAll();
47
+ process.exit(0);
48
+ });
package/src/Service.ts ADDED
@@ -0,0 +1,276 @@
1
+ import axios, { AxiosResponse } from "axios";
2
+ import { Request, Response } from 'express';
3
+ import { Pool, type PoolClient } from 'pg';
4
+ import { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException, NotFoundException } from './exceptions/Exception';
5
+ import { RequestType } from './reqestResponse/RequestType';
6
+ import { ResponseType } from './reqestResponse/ResponseType';
7
+ import { AwsS3Client } from './clients/AwsS3Client';
8
+ import { Base64Client } from './clients/Base64Client';
9
+ import { StringClient } from './clients/StringClient';
10
+ import { EncryptClient } from './clients/EncryptClient';
11
+ import PoolManager from './PoolManager';
12
+
13
+ export type MethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
14
+
15
+ export class Service {
16
+ protected readonly method: MethodType = 'GET';
17
+ get Method(): MethodType { return this.method; }
18
+ protected readonly endpoint: string = '';
19
+ get Endpoint(): string { return this.endpoint + this.request.paramPath; }
20
+ protected readonly apiCode: string = '';
21
+ get ApiCode(): string { return this.apiCode; }
22
+ protected readonly summary: string = '';
23
+ get Summary(): string { return `${this.ApiCode !== '' ? this.apiCode + ': ' : ''}${this.summary}`; }
24
+ protected readonly apiUserAvailable: string = '';
25
+ get ApiUserAvailable(): string { return this.apiUserAvailable; }
26
+ protected readonly request: RequestType = new RequestType();
27
+ get Request(): RequestType { return this.request }; // swaggerで必要なので、ここだけ宣言
28
+ get AuthToken(): string { return this.request.Authorization ?? ''; }
29
+ protected readonly response: ResponseType = new ResponseType();
30
+ get Response(): ResponseType { return this.response }; // swaggerで必要なので、ここだけ宣言
31
+ protected readonly isTest: boolean = process.env.NODE_ENV === 'test';
32
+ protected readonly tags: Array<string> = [];
33
+ get Tags(): Array<string> { return this.tags; }
34
+
35
+ protected readonly req: Request;
36
+ protected readonly res: Response;
37
+ constructor(request: Request, response: Response) {
38
+ this.req = request;
39
+ this.res = response;
40
+ }
41
+
42
+ public async inintialize(): Promise<void> {
43
+ this.request.setRequest(this.req);
44
+ await this.checkMaintenance();
45
+ await this.middleware();
46
+ }
47
+
48
+ protected dbUser?: string = process.env.DB_USER;
49
+ protected dbHost?: string = process.env.DB_HOST;
50
+ protected dbName?: string = process.env.DB_DATABASE;
51
+ protected dbPassword?: string = process.env.DB_PASSWORD;
52
+ protected dbPort?: string | number = process.env.DB_PORT;
53
+ protected dbIsSslConnect: boolean = process.env.DB_IS_SSL === 'true';
54
+ private setPool(): Pool {
55
+ if (this.dbUser === undefined) {
56
+ throw new Error("Database user is not configured");
57
+ }
58
+ if (this.dbHost === undefined) {
59
+ throw new Error("Database host is not configured");
60
+ }
61
+ if (this.dbName === undefined) {
62
+ throw new Error("Database name is not configured");
63
+ }
64
+ if (this.dbPassword === undefined) {
65
+ throw new Error("Database password is not configured");
66
+ }
67
+ if (this.dbPort === undefined) {
68
+ throw new Error("Database port is not configured");
69
+ }
70
+
71
+ try {
72
+ return PoolManager.getPool(this.dbUser, this.dbHost, this.dbName, this.dbPassword, this.dbPort, this.dbIsSslConnect);
73
+ } catch (ex) {
74
+ throw new Error("Failed to connect to the database. Please check the connection settings.");
75
+ }
76
+ }
77
+ protected async checkMaintenance(): Promise<void> { }
78
+ protected async middleware(): Promise<void>{ }
79
+
80
+ public resSuccess(): void {
81
+ this.res.status(200).json(this.response.ResponseData);
82
+ }
83
+
84
+ protected async outputErrorLog(ex: any): Promise<void>{ }
85
+ public handleException(ex: any): void {
86
+ // To avoid slowing down the response, make this asynchronous
87
+ this.outputErrorLog(ex).catch((ex) => {
88
+ console.error(ex);
89
+ });
90
+
91
+ if (ex instanceof AuthException) {
92
+ this.res.status(401).json({
93
+ message : "Authentication expired. Please login again."
94
+ });
95
+ return;
96
+ } else if (ex instanceof ForbiddenException) {
97
+ this.res.status(403).json({
98
+ message : 'Forbidden error'
99
+ });
100
+ return;
101
+ } else if (ex instanceof InputErrorException) {
102
+ this.res.status(400).json({
103
+ errorCode : `${this.apiCode}-${ex.ErrorId}`,
104
+ errorMessage : ex.message
105
+ });
106
+ return;
107
+ } else if (ex instanceof DbConflictException) {
108
+ this.res.status(409).json({
109
+ errorCode : `${this.apiCode}-${ex.ErrorId}`,
110
+ errorMessage : ex.message
111
+ });
112
+ return;
113
+ } else if (ex instanceof UnprocessableException) {
114
+ this.res.status(422).json({
115
+ errorCode : `${this.apiCode}-${ex.ErrorId}`,
116
+ errorMessage : ex.message
117
+ });
118
+ return;
119
+ } else if (ex instanceof MaintenanceException) {
120
+ this.res.status(503).json({
121
+ errorMessage : ex.message
122
+ });
123
+ return;
124
+ } else if (ex instanceof NotFoundException) {
125
+ this.res.status(404).json({
126
+ errorCode : `${this.apiCode}-${ex.ErrorId}`,
127
+ errorMessage : ex.message
128
+ });
129
+ return;
130
+ }
131
+
132
+ if (this.isTest) {
133
+ this.res.status(500).json({
134
+ message : ex.stack
135
+ });
136
+ } else {
137
+ this.res.status(500).json({
138
+ message : 'Internal server error'
139
+ });
140
+ }
141
+
142
+ return;
143
+ }
144
+
145
+ private pool?: Pool;
146
+ protected get Pool(): Pool {
147
+ if (this.pool === undefined) {
148
+ this.pool = this.setPool();
149
+ this.pool.query(`SET TIME ZONE '${process.env.TZ ?? 'Asia/Tokyo'}';`);
150
+ }
151
+ return this.pool;
152
+ }
153
+ private client?: PoolClient;
154
+ private isExecuteRollback: boolean = false;
155
+ protected get Client(): PoolClient {
156
+ if (this.client === undefined) {
157
+ throw new Error("Please call this.PoolClient after using the startConnect method.");
158
+ }
159
+ return this.client;
160
+ }
161
+
162
+ public async startConnect(): Promise<void> {
163
+ this.client = await this.Pool.connect();
164
+ await this.Client.query('BEGIN');
165
+ this.isExecuteRollback = true;
166
+ }
167
+
168
+ public async commit(): Promise<void> {
169
+ await this.Client.query('COMMIT');
170
+ this.isExecuteRollback = false;
171
+ }
172
+
173
+ public async rollback(): Promise<void> {
174
+ if (this.isExecuteRollback) {
175
+ await this.Client.query('ROLLBACK');
176
+ }
177
+ this.isExecuteRollback = false;
178
+ }
179
+
180
+ public async release(): Promise<void> {
181
+ await this.rollback();
182
+ if (this.client !== undefined) {
183
+ await this.client.release();
184
+ }
185
+
186
+ if (this.isTest) {
187
+ // In tests, the connection is terminated because it is shut down every time
188
+ await this.Pool.end();
189
+ }
190
+ }
191
+
192
+ private s3Client?: AwsS3Client;
193
+ get S3Client(): AwsS3Client {
194
+ if (this.s3Client === undefined) {
195
+ this.s3Client = new AwsS3Client({
196
+ bucketName: process.env.S3_BUCKET_NAME,
197
+ region: process.env.S3_REGION,
198
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
199
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
200
+ });
201
+ }
202
+ return this.s3Client;
203
+ }
204
+
205
+ private base64Client? : Base64Client;
206
+ get Base64Client(): Base64Client {
207
+ if (this.base64Client === undefined) {
208
+ this.base64Client = new Base64Client();
209
+ }
210
+ return this.base64Client;
211
+ }
212
+
213
+ private stringClient? : StringClient;
214
+ get StringClient(): StringClient {
215
+ if (this.stringClient === undefined) {
216
+ this.stringClient = new StringClient();
217
+ }
218
+ return this.stringClient;
219
+ }
220
+
221
+ private encryptClient?: EncryptClient;
222
+ get EncryptClient(): EncryptClient {
223
+ if (this.encryptClient === undefined) {
224
+ this.encryptClient = new EncryptClient({
225
+ secretKeyHex: process.env.SECRET_KEY_HEX,
226
+ hmacKeyBase64: process.env.HMAC_KEY_BASE64
227
+ });
228
+ }
229
+
230
+ return this.encryptClient;
231
+ }
232
+
233
+ public async requestApi<TRequest=Record<string, any>, TResponse={[key: string]: any}>(
234
+ method: MethodType, url: string, params: TRequest, header: {[key: string]: any}): Promise<AxiosResponse<TResponse>> {
235
+
236
+ // GET,DELETEのparamをURLクエリに
237
+ if (method === 'GET' || method === 'DELETE') {
238
+ for (const [key, value] of Object.entries(params as Record<string, any>)) {
239
+ if (value === undefined || value === null) {
240
+ continue;
241
+ }
242
+
243
+ if (Array.isArray(value)) {
244
+ for (const arrayValue of value) {
245
+ url += url.includes('?') ? '&' : '?';
246
+ url += `${key}=${arrayValue.toString()}`;
247
+ }
248
+ } else {
249
+ url += url.includes('?') ? '&' : '?';
250
+ url += `${key}=${value.toString()}`;
251
+ }
252
+ }
253
+ }
254
+
255
+ try {
256
+ switch (method) {
257
+ case 'GET':
258
+ return await axios.get(url, header === undefined ? {} : { headers: header });
259
+ case 'POST':
260
+ return await axios.post(url, params, header === undefined ? {} : { headers: header });
261
+ case 'PUT':
262
+ return await axios.put(url, params, header === undefined ? {} : { headers: header });
263
+ case 'DELETE':
264
+ return await axios.delete(url, header === undefined ? {} : { headers: header });
265
+ case 'PATCH':
266
+ return await axios.patch(url, params, header === undefined ? {} : { headers: header });
267
+ }
268
+ } catch (ex) {
269
+ let response = (ex as any).response as AxiosResponse<TResponse>;
270
+ if (response && [400, 401, 403, 404, 409, 422].includes(response.status)) {
271
+ return response;
272
+ }
273
+ throw ex;
274
+ }
275
+ }
276
+ }
@@ -0,0 +1,146 @@
1
+ export default class DateTimeUtil {
2
+
3
+ /**
4
+ * Checks if the value is a valid date-time format
5
+ * 値が有効な日付時間形式かどうかを確認します
6
+ * @param value - 検証する値, The value to be validated
7
+ * @returns {boolean} - 値が有効な日付時間形式であるかどうか, Whether the value is a valid date-time format
8
+ */
9
+ private static isErrorDateTime(value: string): boolean {
10
+ try {
11
+ const [datePart, timePart] = value.split(' ');
12
+ const [year, month, day] = datePart.split('-').map(Number);
13
+ let [hour, minute, sec] = [0, 0, 0];
14
+ if (timePart !== undefined) {
15
+ [hour, minute, sec] = timePart.split(':').map(Number);
16
+ }
17
+
18
+ const date = new Date(year, month - 1, day, hour, minute, sec);
19
+ return year !== date.getFullYear() ||
20
+ month !== date.getMonth() + 1 ||
21
+ day !== date.getDate() ||
22
+ hour !== date.getHours() ||
23
+ minute !== date.getMinutes() ||
24
+ sec !== date.getSeconds()
25
+ } catch (error) {
26
+ return true;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Generates a Date object from a string.
32
+ * 文字列からDateオブジェクトを生成します。
33
+ * @param dateString A string representing the date and time (e.g., "2023-10-05 14:30:00")
34
+ * 日付と時間を表す文字列(例: "2023-10-05 14:30:00")
35
+ * @returns Date object
36
+ * Dateオブジェクト
37
+ */
38
+ static toDateFromString(dateString: string): Date {
39
+ const [datePart, timePart] = dateString.split(' ');
40
+ const [year, month, day] = datePart.split('-').map(Number);
41
+ let [hours, minutes, seconds] = [0, 0, 0];
42
+ if (timePart !== undefined) {
43
+ [hours, minutes, seconds] = timePart.split(':').map(Number);
44
+ }
45
+ return new Date(year, month - 1, day, hours, minutes, seconds);
46
+ }
47
+
48
+ /**
49
+ * Formats the specified date.
50
+ * 指定された日付をフォーマットします。
51
+ * @param date The date object to be formatted.
52
+ * フォーマットする対象の日付オブジェクト
53
+ * @param type A string specifying the type of format.
54
+ * フォーマットの種類を指定する文字列
55
+ * @returns A formatted date string.
56
+ * フォーマットされた日付文字列
57
+ */
58
+ static toStringFromDate(date: Date, type: 'datetime' | 'date' | 'time'): string {
59
+
60
+ const year = date.getFullYear().toString().padStart(4, '0');
61
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
62
+ const day = date.getDate().toString().padStart(2, '0');
63
+ const hour = date.getHours().toString().padStart(2, '0');
64
+ const minute = date.getMinutes().toString().padStart(2, '0');
65
+ const second = date.getSeconds().toString().padStart(2, '0');
66
+
67
+ switch (type) {
68
+ case 'datetime':
69
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
70
+ case 'date':
71
+ return `${year}-${month}-${day}`;
72
+ case 'time':
73
+ return `${hour}:${minute}:${second}`;
74
+ default:
75
+ throw new Error('Invalid type');
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Validates if the given value is in the format YYYY-MM-DD
81
+ * 与えられた値がYYYY-MM-DD形式であるかどうかを検証します
82
+ * @param value - The value to be validated, 検証する値
83
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD, 値がYYYY-MM-DD形式であるかどうか
84
+ */
85
+ static isYYYYMMDD(value: any) {
86
+ if (typeof value !== 'string') {
87
+ return false;
88
+ }
89
+
90
+ const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}$');
91
+ if (pattern.test(value) === false) {
92
+ return false;
93
+ }
94
+
95
+ return this.isErrorDateTime(value) === false;
96
+ }
97
+
98
+ /**
99
+ * Validates if the given value is in the format YYYY-MM-DD hh:mm:ss
100
+ * 与えられた値がYYYY-MM-DD hh:mm:ss形式であるかどうかを検証します
101
+ * @param value - The value to be validated, 検証する値
102
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm:ss, 値がYYYY-MM-DD hh:mm:ss形式であるかどうか
103
+ */
104
+ static isYYYYMMDDhhmiss(value: any) {
105
+ if (typeof value !== 'string') {
106
+ return false;
107
+ }
108
+
109
+ const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}$');
110
+ if (pattern.test(value) === false) {
111
+ return false;
112
+ }
113
+
114
+ return this.isErrorDateTime(value) === false;
115
+ }
116
+
117
+ /**
118
+ * Validates if the given value is in the format YYYY-MM-DD hh:mm:ss
119
+ * 与えられた値がYYYY-MM-DD hh:mm:ss形式であるかどうかを検証します
120
+ * @param value - The value to be validated, 検証する値
121
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm:ss, 値がYYYY-MM-DD hh:mm:ss形式であるかどうか
122
+ */
123
+ static isHHMM(value: any) {
124
+ if (typeof value !== 'string') {
125
+ return false;
126
+ }
127
+
128
+ const pattern = new RegExp('^(?:[01]\\d|2[0-3]):[0-5]\\d$');
129
+ return pattern.test(value);
130
+ }
131
+
132
+ /**
133
+ * Validates if the given value is in the format HH:MM:SS
134
+ * 与えられた値がHH:MM:SS形式であるかどうかを検証します
135
+ * @param value - The value to be validated, 検証する値
136
+ * @returns {boolean} - Whether the value is in the format HH:MM:SS, 値がHH:MM:SS形式であるかどうか
137
+ */
138
+ static isHHMMSS(value: any) {
139
+ if (typeof value !== 'string') {
140
+ return false;
141
+ }
142
+
143
+ const pattern = new RegExp('^(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$');
144
+ return pattern.test(value);
145
+ }
146
+ }