pg-mvc-service 2.1.0 → 2.1.1
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/dist/PoolManager.d.ts +7 -0
- package/dist/PoolManager.d.ts.map +1 -0
- package/dist/Service.d.ts +82 -0
- package/dist/Service.d.ts.map +1 -0
- package/dist/Utils/DateTimeUtil.d.ts +58 -0
- package/dist/Utils/DateTimeUtil.d.ts.map +1 -0
- package/dist/Utils/NumberUtil.d.ts +10 -0
- package/dist/Utils/NumberUtil.d.ts.map +1 -0
- package/dist/Utils/StringUtil.d.ts +16 -0
- package/dist/Utils/StringUtil.d.ts.map +1 -0
- package/dist/clients/AwsS3Client.d.ts +35 -0
- package/dist/clients/AwsS3Client.d.ts.map +1 -0
- package/dist/clients/Base64Client.d.ts +31 -0
- package/dist/clients/Base64Client.d.ts.map +1 -0
- package/dist/clients/EncryptClient.d.ts +18 -0
- package/dist/clients/EncryptClient.d.ts.map +1 -0
- package/dist/clients/StringClient.d.ts +6 -0
- package/dist/clients/StringClient.d.ts.map +1 -0
- package/dist/cron/BaseCron.d.ts +35 -0
- package/dist/cron/BaseCron.d.ts.map +1 -0
- package/dist/cron/CronExecuter.d.ts +2 -0
- package/dist/cron/CronExecuter.d.ts.map +1 -0
- package/dist/cron/CronType.d.ts +6 -0
- package/dist/cron/CronType.d.ts.map +1 -0
- package/dist/documents/Swagger.d.ts +10 -0
- package/dist/documents/Swagger.d.ts.map +1 -0
- package/dist/exceptions/Exception.d.ts +31 -0
- package/dist/exceptions/Exception.d.ts.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +2 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/models/ExpressionClient.d.ts +12 -0
- package/dist/models/ExpressionClient.d.ts.map +1 -0
- package/dist/models/MigrateDatabase.d.ts +19 -0
- package/dist/models/MigrateDatabase.d.ts.map +1 -0
- package/dist/models/MigrateRollback.d.ts +18 -0
- package/dist/models/MigrateRollback.d.ts.map +1 -0
- package/dist/models/MigrateTable.d.ts +13 -0
- package/dist/models/MigrateTable.d.ts.map +1 -0
- package/dist/models/SqlUtils/SelectExpression.d.ts +31 -0
- package/dist/models/SqlUtils/SelectExpression.d.ts.map +1 -0
- package/dist/models/SqlUtils/UpdateExpression.d.ts +8 -0
- package/dist/models/SqlUtils/UpdateExpression.d.ts.map +1 -0
- package/dist/models/SqlUtils/ValidateValueUtil.d.ts +19 -0
- package/dist/models/SqlUtils/ValidateValueUtil.d.ts.map +1 -0
- package/dist/models/SqlUtils/WhereExpression.d.ts +30 -0
- package/dist/models/SqlUtils/WhereExpression.d.ts.map +1 -0
- package/dist/models/TableDoc.d.ts +3 -0
- package/dist/models/TableDoc.d.ts.map +1 -0
- package/dist/models/TableModel.d.ts +196 -0
- package/dist/models/TableModel.d.ts.map +1 -0
- package/dist/models/Type.d.ts +64 -0
- package/dist/models/Type.d.ts.map +1 -0
- package/dist/models/Utils/MessageUtil.d.ts +7 -0
- package/dist/models/Utils/MessageUtil.d.ts.map +1 -0
- package/dist/models/ValidateClient.d.ts +27 -0
- package/dist/models/ValidateClient.d.ts.map +1 -0
- package/dist/reqestResponse/ReqResType.d.ts +113 -0
- package/dist/reqestResponse/ReqResType.d.ts.map +1 -0
- package/dist/reqestResponse/RequestType.d.ts +247 -0
- package/dist/reqestResponse/RequestType.d.ts.map +1 -0
- package/dist/reqestResponse/ResponseType.d.ts +85 -0
- package/dist/reqestResponse/ResponseType.d.ts.map +1 -0
- package/package.json +7 -1
- package/index.d.ts +0 -192
- package/src/PoolManager.ts +0 -48
- package/src/Service.ts +0 -307
- package/src/Utils/DateTimeUtil.ts +0 -146
- package/src/Utils/NumberUtil.ts +0 -23
- package/src/Utils/StringUtil.ts +0 -33
- package/src/clients/AwsS3Client.ts +0 -310
- package/src/clients/Base64Client.ts +0 -305
- package/src/clients/EncryptClient.ts +0 -100
- package/src/clients/StringClient.ts +0 -19
- package/src/cron/BaseCron.ts +0 -122
- package/src/cron/CronExecuter.ts +0 -34
- package/src/cron/CronType.ts +0 -25
- package/src/documents/Swagger.ts +0 -106
- package/src/exceptions/Exception.ts +0 -72
- package/src/models/ExpressionClient.ts +0 -72
- package/src/models/MigrateDatabase.ts +0 -135
- package/src/models/MigrateRollback.ts +0 -151
- package/src/models/MigrateTable.ts +0 -56
- package/src/models/SqlUtils/SelectExpression.ts +0 -102
- package/src/models/SqlUtils/UpdateExpression.ts +0 -29
- package/src/models/SqlUtils/ValidateValueUtil.ts +0 -354
- package/src/models/SqlUtils/WhereExpression.ts +0 -455
- package/src/models/TableDoc.ts +0 -372
- package/src/models/TableModel.ts +0 -749
- package/src/models/Type.ts +0 -62
- package/src/models/Utils/MessageUtil.ts +0 -60
- package/src/models/ValidateClient.ts +0 -182
- package/src/reqestResponse/ReqResType.ts +0 -241
- package/src/reqestResponse/RequestType.ts +0 -1619
- package/src/reqestResponse/ResponseType.ts +0 -549
- package/tsconfig.json +0 -14
package/src/Service.ts
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { Request, Response } from 'express';
|
|
3
|
-
import { Hono, Context } from 'hono' // Context を追加
|
|
4
|
-
import { Pool, type PoolClient } from 'pg';
|
|
5
|
-
import { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException, NotFoundException } from './exceptions/Exception';
|
|
6
|
-
import { RequestType } from './reqestResponse/RequestType';
|
|
7
|
-
import { ResponseType } from './reqestResponse/ResponseType';
|
|
8
|
-
import { AwsS3Client } from './clients/AwsS3Client';
|
|
9
|
-
import { Base64Client } from './clients/Base64Client';
|
|
10
|
-
import { StringClient } from './clients/StringClient';
|
|
11
|
-
import { EncryptClient } from './clients/EncryptClient';
|
|
12
|
-
import PoolManager from './PoolManager';
|
|
13
|
-
|
|
14
|
-
type TStatusCode = 200 | 201 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 503;
|
|
15
|
-
|
|
16
|
-
export type MethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
17
|
-
export interface IError {
|
|
18
|
-
status: TStatusCode,
|
|
19
|
-
code: string;
|
|
20
|
-
description: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export class Service {
|
|
25
|
-
protected readonly module: 'express' | 'hono' = 'express';
|
|
26
|
-
protected readonly method: MethodType = 'GET';
|
|
27
|
-
get Method(): MethodType { return this.method; }
|
|
28
|
-
protected readonly endpoint: string = '';
|
|
29
|
-
get Endpoint(): string { return this.endpoint + this.request.paramPath; }
|
|
30
|
-
protected readonly apiCode: string = '';
|
|
31
|
-
get ApiCode(): string { return this.apiCode; }
|
|
32
|
-
protected readonly summary: string = '';
|
|
33
|
-
get Summary(): string { return `${this.ApiCode !== '' ? this.apiCode + ': ' : ''}${this.summary}`; }
|
|
34
|
-
protected readonly apiUserAvailable: string = '';
|
|
35
|
-
get ApiUserAvailable(): string { return this.apiUserAvailable; }
|
|
36
|
-
protected readonly request: RequestType = new RequestType();
|
|
37
|
-
get Request(): RequestType { return this.request }; // swaggerで必要なので、ここだけ宣言
|
|
38
|
-
get AuthToken(): string { return this.request.Authorization ?? ''; }
|
|
39
|
-
protected readonly response: ResponseType = new ResponseType();
|
|
40
|
-
get Response(): ResponseType { return this.response }; // swaggerで必要なので、ここだけ宣言
|
|
41
|
-
protected readonly tags: Array<string> = [];
|
|
42
|
-
get Tags(): Array<string> { return this.tags; }
|
|
43
|
-
protected readonly errorList: Array<IError> = [];
|
|
44
|
-
get ErrorList(): Array<IError> {
|
|
45
|
-
return [...this.errorList, {
|
|
46
|
-
status: 500,
|
|
47
|
-
code: '',
|
|
48
|
-
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
49
|
-
}];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected readonly req?: Request;
|
|
53
|
-
protected readonly res?: Response;
|
|
54
|
-
protected readonly c?: Context;
|
|
55
|
-
protected setResponse(status: TStatusCode, data: any) {
|
|
56
|
-
if (this.module === 'express') {
|
|
57
|
-
this.res?.status(status).json(data);
|
|
58
|
-
} else {
|
|
59
|
-
this.c?.json(data, status)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
constructor(request: Request, response: Response);
|
|
64
|
-
constructor(c: Context);
|
|
65
|
-
constructor(param1: Request | Context, param2?: Response) {
|
|
66
|
-
if (param2 !== undefined) {
|
|
67
|
-
// Express の場合: (request, response)
|
|
68
|
-
this.module = 'express';
|
|
69
|
-
this.req = param1 as Request;
|
|
70
|
-
this.res = param2;
|
|
71
|
-
} else {
|
|
72
|
-
// Hono の場合: (c)
|
|
73
|
-
this.module = 'hono';
|
|
74
|
-
this.c = param1 as Context;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public async inintialize(): Promise<void> {
|
|
79
|
-
if (this.module === "express") {
|
|
80
|
-
await this.request.setRequest(this.module, this.req as Request);
|
|
81
|
-
} else {
|
|
82
|
-
await this.request.setRequest(this.module, this.c as Context);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
await this.checkMaintenance();
|
|
86
|
-
await this.middleware();
|
|
87
|
-
}
|
|
88
|
-
// Context<{ Bindings: Bindings }>
|
|
89
|
-
|
|
90
|
-
protected dbUser?: string = process.env.DB_USER;
|
|
91
|
-
protected dbHost?: string = process.env.DB_HOST;
|
|
92
|
-
protected dbName?: string = process.env.DB_DATABASE;
|
|
93
|
-
protected dbPassword?: string = process.env.DB_PASSWORD;
|
|
94
|
-
protected dbPort?: string | number = process.env.DB_PORT;
|
|
95
|
-
protected dbIsSslConnect: boolean = process.env.DB_IS_SSL === 'true';
|
|
96
|
-
private setPool(): Pool {
|
|
97
|
-
if (this.dbUser === undefined) {
|
|
98
|
-
throw new Error("Database user is not configured");
|
|
99
|
-
}
|
|
100
|
-
if (this.dbHost === undefined) {
|
|
101
|
-
throw new Error("Database host is not configured");
|
|
102
|
-
}
|
|
103
|
-
if (this.dbName === undefined) {
|
|
104
|
-
throw new Error("Database name is not configured");
|
|
105
|
-
}
|
|
106
|
-
if (this.dbPassword === undefined) {
|
|
107
|
-
throw new Error("Database password is not configured");
|
|
108
|
-
}
|
|
109
|
-
if (this.dbPort === undefined) {
|
|
110
|
-
throw new Error("Database port is not configured");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
return PoolManager.getPool(this.dbUser, this.dbHost, this.dbName, this.dbPassword, this.dbPort, this.dbIsSslConnect);
|
|
115
|
-
} catch (ex) {
|
|
116
|
-
throw new Error("Failed to connect to the database. Please check the connection settings.");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
protected async checkMaintenance(): Promise<void> { }
|
|
120
|
-
protected async middleware(): Promise<void>{ }
|
|
121
|
-
|
|
122
|
-
public resSuccess(): void {
|
|
123
|
-
this.setResponse(200, this.response.ResponseData);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
protected async outputErrorLog(ex: any): Promise<void>{ }
|
|
127
|
-
public handleException(ex: any): void {
|
|
128
|
-
// To avoid slowing down the response, make this asynchronous
|
|
129
|
-
this.outputErrorLog(ex).catch((ex) => {
|
|
130
|
-
console.error(ex);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
if (ex instanceof AuthException) {
|
|
134
|
-
this.setResponse(401, {
|
|
135
|
-
message : "Authentication expired. Please login again."
|
|
136
|
-
});
|
|
137
|
-
return;
|
|
138
|
-
} else if (ex instanceof ForbiddenException) {
|
|
139
|
-
this.setResponse(403, {
|
|
140
|
-
message : 'Forbidden error'
|
|
141
|
-
});
|
|
142
|
-
return;
|
|
143
|
-
} else if (ex instanceof InputErrorException) {
|
|
144
|
-
this.setResponse(400, {
|
|
145
|
-
errorCode : `${this.apiCode}-${ex.ErrorId}`,
|
|
146
|
-
errorMessage : ex.message
|
|
147
|
-
});
|
|
148
|
-
return;
|
|
149
|
-
} else if (ex instanceof DbConflictException) {
|
|
150
|
-
this.setResponse(409, {
|
|
151
|
-
errorCode : `${this.apiCode}-${ex.ErrorId}`,
|
|
152
|
-
errorMessage : ex.message
|
|
153
|
-
});
|
|
154
|
-
return;
|
|
155
|
-
} else if (ex instanceof UnprocessableException) {
|
|
156
|
-
this.setResponse(422, {
|
|
157
|
-
errorCode : `${this.apiCode}-${ex.ErrorId}`,
|
|
158
|
-
errorMessage : ex.message
|
|
159
|
-
});
|
|
160
|
-
return;
|
|
161
|
-
} else if (ex instanceof MaintenanceException) {
|
|
162
|
-
this.setResponse(503, {
|
|
163
|
-
errorMessage : ex.message
|
|
164
|
-
});
|
|
165
|
-
return;
|
|
166
|
-
} else if (ex instanceof NotFoundException) {
|
|
167
|
-
this.setResponse(404, {
|
|
168
|
-
errorCode : `${this.apiCode}-${ex.ErrorId}`,
|
|
169
|
-
errorMessage : ex.message
|
|
170
|
-
});
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
this.setResponse(500, {
|
|
175
|
-
message : 'Internal server error'
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private pool?: Pool;
|
|
182
|
-
protected get Pool(): Pool {
|
|
183
|
-
if (this.pool === undefined) {
|
|
184
|
-
this.pool = this.setPool();
|
|
185
|
-
this.pool.query(`SET TIME ZONE '${process.env.TZ ?? 'Asia/Tokyo'}';`);
|
|
186
|
-
}
|
|
187
|
-
return this.pool;
|
|
188
|
-
}
|
|
189
|
-
private client?: PoolClient;
|
|
190
|
-
private isExecuteRollback: boolean = false;
|
|
191
|
-
protected get Client(): PoolClient {
|
|
192
|
-
if (this.client === undefined) {
|
|
193
|
-
throw new Error("Please call this.PoolClient after using the startConnect method.");
|
|
194
|
-
}
|
|
195
|
-
return this.client;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
public async startConnect(): Promise<void> {
|
|
199
|
-
this.client = await this.Pool.connect();
|
|
200
|
-
await this.Client.query('BEGIN');
|
|
201
|
-
this.isExecuteRollback = true;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public async commit(): Promise<void> {
|
|
205
|
-
await this.Client.query('COMMIT');
|
|
206
|
-
this.isExecuteRollback = false;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
public async rollback(): Promise<void> {
|
|
210
|
-
if (this.isExecuteRollback) {
|
|
211
|
-
await this.Client.query('ROLLBACK');
|
|
212
|
-
}
|
|
213
|
-
this.isExecuteRollback = false;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public async release(): Promise<void> {
|
|
217
|
-
await this.rollback();
|
|
218
|
-
if (this.client !== undefined) {
|
|
219
|
-
await this.client.release();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private s3Client?: AwsS3Client;
|
|
224
|
-
get S3Client(): AwsS3Client {
|
|
225
|
-
if (this.s3Client === undefined) {
|
|
226
|
-
this.s3Client = new AwsS3Client({
|
|
227
|
-
bucketName: process.env.S3_BUCKET_NAME,
|
|
228
|
-
region: process.env.S3_REGION,
|
|
229
|
-
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
|
230
|
-
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
return this.s3Client;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
private base64Client? : Base64Client;
|
|
237
|
-
get Base64Client(): Base64Client {
|
|
238
|
-
if (this.base64Client === undefined) {
|
|
239
|
-
this.base64Client = new Base64Client();
|
|
240
|
-
}
|
|
241
|
-
return this.base64Client;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
private stringClient? : StringClient;
|
|
245
|
-
get StringClient(): StringClient {
|
|
246
|
-
if (this.stringClient === undefined) {
|
|
247
|
-
this.stringClient = new StringClient();
|
|
248
|
-
}
|
|
249
|
-
return this.stringClient;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
private encryptClient?: EncryptClient;
|
|
253
|
-
get EncryptClient(): EncryptClient {
|
|
254
|
-
if (this.encryptClient === undefined) {
|
|
255
|
-
this.encryptClient = new EncryptClient({
|
|
256
|
-
secretKeyHex: process.env.SECRET_KEY_HEX,
|
|
257
|
-
hmacKeyBase64: process.env.HMAC_KEY_BASE64
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return this.encryptClient;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
public async requestApi<TRequest=Record<string, any>, TResponse={[key: string]: any}>(
|
|
265
|
-
method: MethodType, url: string, params: TRequest, header: {[key: string]: any}): Promise<AxiosResponse<TResponse>> {
|
|
266
|
-
|
|
267
|
-
// GET,DELETEのparamをURLクエリに
|
|
268
|
-
if (method === 'GET' || method === 'DELETE') {
|
|
269
|
-
for (const [key, value] of Object.entries(params as Record<string, any>)) {
|
|
270
|
-
if (value === undefined || value === null) {
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (Array.isArray(value)) {
|
|
275
|
-
for (const arrayValue of value) {
|
|
276
|
-
url += url.includes('?') ? '&' : '?';
|
|
277
|
-
url += `${key}=${arrayValue.toString()}`;
|
|
278
|
-
}
|
|
279
|
-
} else {
|
|
280
|
-
url += url.includes('?') ? '&' : '?';
|
|
281
|
-
url += `${key}=${value.toString()}`;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
switch (method) {
|
|
288
|
-
case 'GET':
|
|
289
|
-
return await axios.get(url, header === undefined ? {} : { headers: header });
|
|
290
|
-
case 'POST':
|
|
291
|
-
return await axios.post(url, params, header === undefined ? {} : { headers: header });
|
|
292
|
-
case 'PUT':
|
|
293
|
-
return await axios.put(url, params, header === undefined ? {} : { headers: header });
|
|
294
|
-
case 'DELETE':
|
|
295
|
-
return await axios.delete(url, header === undefined ? {} : { headers: header });
|
|
296
|
-
case 'PATCH':
|
|
297
|
-
return await axios.patch(url, params, header === undefined ? {} : { headers: header });
|
|
298
|
-
}
|
|
299
|
-
} catch (ex) {
|
|
300
|
-
let response = (ex as any).response as AxiosResponse<TResponse>;
|
|
301
|
-
if (response && [400, 401, 403, 404, 409, 422].includes(response.status)) {
|
|
302
|
-
return response;
|
|
303
|
-
}
|
|
304
|
-
throw ex;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
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
|
-
}
|
package/src/Utils/NumberUtil.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export default class NumberUtil {
|
|
2
|
-
/**
|
|
3
|
-
* Checks if the given value is a number.
|
|
4
|
-
* 与えられた値が数値であるかどうかを確認します。
|
|
5
|
-
* @param value - The value to be checked. ���認する値。
|
|
6
|
-
* @returns {boolean} - Whether the value is a number. ��が数値であるかどうか。
|
|
7
|
-
*/
|
|
8
|
-
static isNumber(value: any) {
|
|
9
|
-
if (value == null) {
|
|
10
|
-
return false;
|
|
11
|
-
} else if (value instanceof Date) {
|
|
12
|
-
return false;
|
|
13
|
-
} else if (value instanceof Array) {
|
|
14
|
-
return false;
|
|
15
|
-
} else if (typeof(value) == 'string') {
|
|
16
|
-
if (value == "") {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return isNaN(Number(value)) == false;
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/Utils/StringUtil.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export default class StringUtil {
|
|
2
|
-
/**
|
|
3
|
-
* Validates if the given value is a valid UUID
|
|
4
|
-
* 与えられた値が有効なUUIDであるかどうかを検証します
|
|
5
|
-
* @param value - The value to be validated, 検証する値
|
|
6
|
-
* @returns {boolean} - Whether the value is a valid UUID, 値が有効なUUIDであるかどうか
|
|
7
|
-
*/
|
|
8
|
-
static isUUID(value: any) {
|
|
9
|
-
if (typeof value !== 'string') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const pattern = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$');
|
|
14
|
-
return pattern.test(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 小文字スネークからキャピタルケースに変換
|
|
19
|
-
* @param {string} value スネーク文字列
|
|
20
|
-
* @returns キャピタル文字列
|
|
21
|
-
*/
|
|
22
|
-
static formatFromSnakeToCamel(value: string) {
|
|
23
|
-
const regex = /_[a-z]/g;
|
|
24
|
-
let capital = value.replace(regex,
|
|
25
|
-
function(matchChar) {
|
|
26
|
-
return String.fromCharCode(matchChar.charCodeAt(1) - 0x20);
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
// "_1"や"_@"のパターンを考慮して、_を省く(この使い方はあまりないと思いますが...)
|
|
31
|
-
return capital.replaceAll("_", "");
|
|
32
|
-
}
|
|
33
|
-
}
|