pg-mvc-service 2.1.0 → 2.1.2

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 (98) hide show
  1. package/dist/PoolManager.d.ts +7 -0
  2. package/dist/PoolManager.d.ts.map +1 -0
  3. package/dist/Service.d.ts +79 -0
  4. package/dist/Service.d.ts.map +1 -0
  5. package/dist/Service.js +0 -8
  6. package/dist/Utils/DateTimeUtil.d.ts +58 -0
  7. package/dist/Utils/DateTimeUtil.d.ts.map +1 -0
  8. package/dist/Utils/NumberUtil.d.ts +10 -0
  9. package/dist/Utils/NumberUtil.d.ts.map +1 -0
  10. package/dist/Utils/StringUtil.d.ts +16 -0
  11. package/dist/Utils/StringUtil.d.ts.map +1 -0
  12. package/dist/clients/AwsS3Client.d.ts +34 -0
  13. package/dist/clients/AwsS3Client.d.ts.map +1 -0
  14. package/dist/clients/AwsS3Client.js +13 -28
  15. package/dist/clients/EncryptClient.d.ts +18 -0
  16. package/dist/clients/EncryptClient.d.ts.map +1 -0
  17. package/dist/clients/StringClient.d.ts +6 -0
  18. package/dist/clients/StringClient.d.ts.map +1 -0
  19. package/dist/cron/BaseCron.d.ts +32 -0
  20. package/dist/cron/BaseCron.d.ts.map +1 -0
  21. package/dist/cron/BaseCron.js +0 -7
  22. package/dist/cron/CronExecuter.d.ts +2 -0
  23. package/dist/cron/CronExecuter.d.ts.map +1 -0
  24. package/dist/cron/CronType.d.ts +6 -0
  25. package/dist/cron/CronType.d.ts.map +1 -0
  26. package/dist/documents/Swagger.d.ts +10 -0
  27. package/dist/documents/Swagger.d.ts.map +1 -0
  28. package/dist/exceptions/Exception.d.ts +31 -0
  29. package/dist/exceptions/Exception.d.ts.map +1 -0
  30. package/{src/index.ts → dist/index.d.ts} +3 -7
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +1 -3
  33. package/dist/models/ExpressionClient.d.ts +12 -0
  34. package/dist/models/ExpressionClient.d.ts.map +1 -0
  35. package/dist/models/MigrateDatabase.d.ts +19 -0
  36. package/dist/models/MigrateDatabase.d.ts.map +1 -0
  37. package/dist/models/MigrateRollback.d.ts +18 -0
  38. package/dist/models/MigrateRollback.d.ts.map +1 -0
  39. package/dist/models/MigrateTable.d.ts +13 -0
  40. package/dist/models/MigrateTable.d.ts.map +1 -0
  41. package/dist/models/SqlUtils/SelectExpression.d.ts +31 -0
  42. package/dist/models/SqlUtils/SelectExpression.d.ts.map +1 -0
  43. package/dist/models/SqlUtils/UpdateExpression.d.ts +8 -0
  44. package/dist/models/SqlUtils/UpdateExpression.d.ts.map +1 -0
  45. package/dist/models/SqlUtils/ValidateValueUtil.d.ts +19 -0
  46. package/dist/models/SqlUtils/ValidateValueUtil.d.ts.map +1 -0
  47. package/dist/models/SqlUtils/WhereExpression.d.ts +30 -0
  48. package/dist/models/SqlUtils/WhereExpression.d.ts.map +1 -0
  49. package/dist/models/TableDoc.d.ts +3 -0
  50. package/dist/models/TableDoc.d.ts.map +1 -0
  51. package/dist/models/TableModel.d.ts +196 -0
  52. package/dist/models/TableModel.d.ts.map +1 -0
  53. package/dist/models/Type.d.ts +64 -0
  54. package/dist/models/Type.d.ts.map +1 -0
  55. package/dist/models/Utils/MessageUtil.d.ts +7 -0
  56. package/dist/models/Utils/MessageUtil.d.ts.map +1 -0
  57. package/dist/models/ValidateClient.d.ts +27 -0
  58. package/dist/models/ValidateClient.d.ts.map +1 -0
  59. package/dist/reqestResponse/ReqResType.d.ts +113 -0
  60. package/dist/reqestResponse/ReqResType.d.ts.map +1 -0
  61. package/dist/reqestResponse/RequestType.d.ts +247 -0
  62. package/dist/reqestResponse/RequestType.d.ts.map +1 -0
  63. package/dist/reqestResponse/ResponseType.d.ts +85 -0
  64. package/dist/reqestResponse/ResponseType.d.ts.map +1 -0
  65. package/package.json +7 -2
  66. package/dist/clients/Base64Client.js +0 -292
  67. package/index.d.ts +0 -192
  68. package/src/PoolManager.ts +0 -48
  69. package/src/Service.ts +0 -307
  70. package/src/Utils/DateTimeUtil.ts +0 -146
  71. package/src/Utils/NumberUtil.ts +0 -23
  72. package/src/Utils/StringUtil.ts +0 -33
  73. package/src/clients/AwsS3Client.ts +0 -310
  74. package/src/clients/Base64Client.ts +0 -305
  75. package/src/clients/EncryptClient.ts +0 -100
  76. package/src/clients/StringClient.ts +0 -19
  77. package/src/cron/BaseCron.ts +0 -122
  78. package/src/cron/CronExecuter.ts +0 -34
  79. package/src/cron/CronType.ts +0 -25
  80. package/src/documents/Swagger.ts +0 -106
  81. package/src/exceptions/Exception.ts +0 -72
  82. package/src/models/ExpressionClient.ts +0 -72
  83. package/src/models/MigrateDatabase.ts +0 -135
  84. package/src/models/MigrateRollback.ts +0 -151
  85. package/src/models/MigrateTable.ts +0 -56
  86. package/src/models/SqlUtils/SelectExpression.ts +0 -102
  87. package/src/models/SqlUtils/UpdateExpression.ts +0 -29
  88. package/src/models/SqlUtils/ValidateValueUtil.ts +0 -354
  89. package/src/models/SqlUtils/WhereExpression.ts +0 -455
  90. package/src/models/TableDoc.ts +0 -372
  91. package/src/models/TableModel.ts +0 -749
  92. package/src/models/Type.ts +0 -62
  93. package/src/models/Utils/MessageUtil.ts +0 -60
  94. package/src/models/ValidateClient.ts +0 -182
  95. package/src/reqestResponse/ReqResType.ts +0 -241
  96. package/src/reqestResponse/RequestType.ts +0 -1619
  97. package/src/reqestResponse/ResponseType.ts +0 -549
  98. package/tsconfig.json +0 -14
@@ -0,0 +1,247 @@
1
+ import { Request } from 'express';
2
+ import ReqResType, { EnumType, NumberType, PrimitiveType, StringType } from "./ReqResType";
3
+ import { IError } from '../Service';
4
+ import { Context } from 'hono';
5
+ export interface ErrorMessageType {
6
+ REQUIRED: string;
7
+ UNNECESSARY: string;
8
+ INVALID_OBJECT: string;
9
+ INVALID_ARRAY: string;
10
+ INVALID_NUMBER: string;
11
+ INVALID_NUMBER_MIN: string;
12
+ INVALID_NUMBER_MAX: string;
13
+ INVALID_BOOL: string;
14
+ INVALID_STRING: string;
15
+ INVALID_STRING_MAX_LENGTH: string;
16
+ INVALID_STRING_REG_EXP: string;
17
+ INVALID_UUID: string;
18
+ INVALID_MAIL: string;
19
+ INVALID_HTTPS: string;
20
+ INVALID_DATE: string;
21
+ INVALID_TIME: string;
22
+ INVALID_DATETIME: string;
23
+ INVALID_BASE64: string;
24
+ INVALID_ENUM: string;
25
+ INVALID_MAP_NUMBER: string;
26
+ INVALID_MAP_STRING: string;
27
+ INVALID_MAP_BOOL: string;
28
+ }
29
+ export declare class RequestType extends ReqResType {
30
+ private readonly ERROR_MESSAGE_ENGLISH;
31
+ private readonly ERROR_MESSAGE_JAPAN;
32
+ protected readonly ERROR_MESSAGE: ErrorMessageType;
33
+ protected paramProperties: Array<(PrimitiveType | StringType | NumberType | EnumType) & {
34
+ key: string;
35
+ }>;
36
+ get paramPath(): string;
37
+ private params?;
38
+ get Params(): {
39
+ [key: string]: any;
40
+ };
41
+ private data?;
42
+ get Data(): {
43
+ [key: string]: any;
44
+ };
45
+ private headers?;
46
+ get Headers(): IncomingHttpHeaders;
47
+ get Authorization(): string | null;
48
+ setRequest(module: 'express' | 'hono', request: Request | Context): Promise<void>;
49
+ private createErrorMessage;
50
+ /**
51
+ * Generates an error message based on the provided code, keys, and value.
52
+ * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
53
+ * @param {string} code - The error code. エラーコード
54
+ * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
55
+ * @param {any} value - The value that caused the error. エラーを引き起こした値
56
+ * @returns {string} The generated error message. 生成されたエラーメッセージ
57
+ */
58
+ private throwInputError;
59
+ /**
60
+ * Sets the values of the request body to the class properties.
61
+ * リクエストボディの値をクラスのプロパティにセットします。
62
+ *
63
+ * Note: This method is implemented as a separate method rather than in the constructor.
64
+ * This is because if executed in the constructor, the properties of the inheriting class
65
+ * are not yet initialized, and the values cannot be set correctly.
66
+ * 注意: このメソッドはコンストラクタではなく別メソッドとして実装されています。
67
+ * これは、コンストラクタ内で実行すると継承先のクラスのプロパティが
68
+ * まだ初期化されていないため、正しく値をセットできないためです。
69
+ *
70
+ * @param {Object} body - Request body object, リクエストボディオブジェクト
71
+ * @throws {InputErrorException} Thrown when the input value is invalid, 入力値が不正な場合にスローされます
72
+ */
73
+ private createBody;
74
+ /**
75
+ * Sets the value for an enum type based on the specified keys.
76
+ * 指定されたキーに基づいて列挙型の値を設定します。
77
+ * @param {Array<string | number>} keys - Path to the target (array of strings or index numbers)
78
+ * 処理対象のパス(文字列またはインデックス番号の配列)
79
+ * @param {any} value - Value to be set
80
+ * 設定する値
81
+ * @throws {InputErrorException} Thrown when the type does not match
82
+ * 型が一致しない場合にスローされます
83
+ */
84
+ private setEnum;
85
+ /**
86
+ * Recursively processes array type values.
87
+ * Validates each element of the array and converts it to the appropriate type.
88
+ * 配列型の値を再帰的に処理します。
89
+ * 配列の各要素を検証し、適切な型に変換します。
90
+ *
91
+ * @param {Array<string | number>} keys - Current processing path (array of strings or index numbers)
92
+ * 現在の処理パス(文字列またはインデックス番号の配列)
93
+ * @param {any[]} values - Array to be processed
94
+ * 処理対象の配列
95
+ * @throws {InputErrorException} Thrown when the type of an array element is invalid
96
+ * 配列要素の型が不正な場合にスローされます
97
+ */
98
+ private setArray;
99
+ /**
100
+ * Set the value of the request body to the specified path.
101
+ * Automatically create intermediate objects or arrays as needed.
102
+ * リクエストボディの値を指定されたパスに設定します。
103
+ * 必要に応じて中間のオブジェクトや配列を自動的に作成します。
104
+ * @param {Array<string | number>} keys - Path to the destination (array of strings or index numbers)
105
+ * 設定先へのパス(文字列またはインデックス番号の配列)
106
+ * @param {any} value - Value to be set
107
+ * 設定する値
108
+ */
109
+ private changeBody;
110
+ /**
111
+ * Process object type values recursively.
112
+ * Validate object properties and convert them to appropriate types.
113
+ * オブジェクト型の値を再帰的に処理します。
114
+ * オブジェクトのプロパティを検証し、適切な型に変換します。
115
+ * @param {Array<string | number>} keys - Current processing path (array of strings or index numbers)
116
+ * 現在の処理パス(文字列またはインデックス番号の配列)
117
+ * @param {object} values - Object to be processed
118
+ * 処理対象のオブジェクト
119
+ * @throws {InputErrorException} Thrown when the property type is invalid
120
+ * プロパティの型が不正な場合にスローされます
121
+ */
122
+ private setObject;
123
+ /**
124
+ * Convert the input value based on the specified type.
125
+ * Throws an exception if type conversion fails.
126
+ * 指定された型に基づいて入力値を変換します。
127
+ * 型変換に失敗した場合は例外をスローします。
128
+ *
129
+ * @param {string} property - The type to convert to (e.g., 'number', 'boolean', 'string', 'date', 'time', 'datetime')
130
+ * 変換する型(例: 'number', 'boolean', 'string', 'date', 'time', 'datetime')
131
+ * @param {any} value - The value to convert
132
+ * 変換する値
133
+ * @param {Array<string | number>} keys - The path to the target (array of strings or index numbers)
134
+ * 処理対象のパス(文字列またはインデックス番号の配列)
135
+ * @returns {any} The converted value, 変換された値
136
+ * @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
137
+ */
138
+ private convertValue;
139
+ /**
140
+ * Convert the input value to the specified type.
141
+ * Throws an exception if type conversion fails.
142
+ * 入力値を指定された型に変換します。
143
+ * 型変換に失敗した場合は例外をスローします。
144
+ * @param {Array<string | number>} keys - Path to the target (array of strings or index numbers)
145
+ * 処理対象のパス(文字列またはインデックス番号の配列)
146
+ * @param {any} value - Value to be converted
147
+ * 変換する値
148
+ * @throws {InputErrorException} Thrown when type conversion fails
149
+ * 型変換に失敗した場合にスローされます
150
+ */
151
+ private convertInput;
152
+ /**
153
+ * Generates a Swagger YAML definition from the request body.
154
+ * リクエストボディからSwaggerのYAML定義を生成します。
155
+ * @returns {string} Swagger format YAML definition
156
+ * Swagger形式のYAML定義
157
+ */
158
+ createSwagger(method: string): string;
159
+ /**
160
+ * Generates Swagger properties from object type properties
161
+ * オブジェクト型のプロパティからSwaggerのプロパティを生成
162
+ * @param {Array.<string|number>} keys - Path to the properties
163
+ * プロパティへのパス
164
+ * @returns {string} Swagger format property definition
165
+ * Swagger形式のプロパティ定義
166
+ */
167
+ private makeSwaggerProperyFromObject;
168
+ /**
169
+ * Generates Swagger properties from array type properties
170
+ * 配列型のプロパティからSwaggerのプロパティを生成
171
+ * @param {Array.<string|number>} keys - Path to the properties
172
+ * プロパティへのパス
173
+ * @returns {string} Swagger format property definition
174
+ * Swagger形式のプロパティ定義
175
+ */
176
+ private makeSwaggerPropertyFromArray;
177
+ getInputErrorList(method: string): Array<IError>;
178
+ private getErrorObject;
179
+ private getErrorArray;
180
+ private getError;
181
+ }
182
+ export interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
183
+ accept?: string | undefined;
184
+ "accept-language"?: string | undefined;
185
+ "accept-patch"?: string | undefined;
186
+ "accept-ranges"?: string | undefined;
187
+ "access-control-allow-credentials"?: string | undefined;
188
+ "access-control-allow-headers"?: string | undefined;
189
+ "access-control-allow-methods"?: string | undefined;
190
+ "access-control-allow-origin"?: string | undefined;
191
+ "access-control-expose-headers"?: string | undefined;
192
+ "access-control-max-age"?: string | undefined;
193
+ "access-control-request-headers"?: string | undefined;
194
+ "access-control-request-method"?: string | undefined;
195
+ age?: string | undefined;
196
+ allow?: string | undefined;
197
+ "alt-svc"?: string | undefined;
198
+ authorization?: string | undefined;
199
+ "cache-control"?: string | undefined;
200
+ connection?: string | undefined;
201
+ "content-disposition"?: string | undefined;
202
+ "content-encoding"?: string | undefined;
203
+ "content-language"?: string | undefined;
204
+ "content-length"?: string | undefined;
205
+ "content-location"?: string | undefined;
206
+ "content-range"?: string | undefined;
207
+ "content-type"?: string | undefined;
208
+ cookie?: string | undefined;
209
+ date?: string | undefined;
210
+ etag?: string | undefined;
211
+ expect?: string | undefined;
212
+ expires?: string | undefined;
213
+ forwarded?: string | undefined;
214
+ from?: string | undefined;
215
+ host?: string | undefined;
216
+ "if-match"?: string | undefined;
217
+ "if-modified-since"?: string | undefined;
218
+ "if-none-match"?: string | undefined;
219
+ "if-unmodified-since"?: string | undefined;
220
+ "last-modified"?: string | undefined;
221
+ location?: string | undefined;
222
+ origin?: string | undefined;
223
+ pragma?: string | undefined;
224
+ "proxy-authenticate"?: string | undefined;
225
+ "proxy-authorization"?: string | undefined;
226
+ "public-key-pins"?: string | undefined;
227
+ range?: string | undefined;
228
+ referer?: string | undefined;
229
+ "retry-after"?: string | undefined;
230
+ "sec-websocket-accept"?: string | undefined;
231
+ "sec-websocket-extensions"?: string | undefined;
232
+ "sec-websocket-key"?: string | undefined;
233
+ "sec-websocket-protocol"?: string | undefined;
234
+ "sec-websocket-version"?: string | undefined;
235
+ "set-cookie"?: string[] | undefined;
236
+ "strict-transport-security"?: string | undefined;
237
+ tk?: string | undefined;
238
+ trailer?: string | undefined;
239
+ "transfer-encoding"?: string | undefined;
240
+ upgrade?: string | undefined;
241
+ "user-agent"?: string | undefined;
242
+ vary?: string | undefined;
243
+ via?: string | undefined;
244
+ warning?: string | undefined;
245
+ "www-authenticate"?: string | undefined;
246
+ }
247
+ //# sourceMappingURL=RequestType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestType.d.ts","sourceRoot":"","sources":["../../src/reqestResponse/RequestType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,UAAU,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAgB,UAAU,EAAE,MAAM,cAAc,CAAC;AAIzG,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,yBAAyB,EAAE,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GAAG,SAAS,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C"}
@@ -0,0 +1,85 @@
1
+ import ReqResType from "./ReqResType";
2
+ import { IError } from "../Service";
3
+ export declare class ResponseType extends ReqResType {
4
+ /**
5
+ * Property to store response data
6
+ * レスポンスデータを格納するためのプロパティ
7
+ */
8
+ Data: {
9
+ [key: string]: any;
10
+ };
11
+ /**
12
+ * Convert and retrieve data according to the type definition
13
+ * 型定義に従ってデータを変換して取得
14
+ * @returns {Object.<string, any>} Converted data, 変換されたデータ
15
+ */
16
+ get ResponseData(): {
17
+ [key: string]: any;
18
+ };
19
+ /**
20
+ * Retrieve object type data
21
+ * オブジェクト型のデータを取得
22
+ * @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
23
+ * @returns {Object.<string, any>} Retrieved object data, 取得されたオブジェクトデータ
24
+ */
25
+ private getObject;
26
+ /**
27
+ * Retrieve array type data
28
+ * 配列型のデータを取得
29
+ * @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
30
+ * @returns {Array<any> | undefined} Retrieved array data, 取得された配列データ
31
+ */
32
+ private getArray;
33
+ /**
34
+ * Retrieve array type data
35
+ * 配列型のデータを取得
36
+ * @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
37
+ * @returns {Array<any> | undefined} Retrieved array data, 取得された配列データ
38
+ */
39
+ private getMap;
40
+ /**
41
+ * Retrieve data based on the provided keys
42
+ * 指定されたキーに基づいてデータを取得
43
+ * @param {Array.<string|number>} keys - Path to the data, データへのパス
44
+ * @returns {any} Retrieved data, 取得されたデータ
45
+ */
46
+ private getData;
47
+ /**
48
+ * Retrieve value based on the provided keys
49
+ * 指定されたキーに基づいて値を取得
50
+ * @param {Array.<string|number>} keys - Path to the value, 値へのパス
51
+ * @returns {string | number | boolean | null | undefined} Retrieved value, 取得された値
52
+ */
53
+ private getValue;
54
+ /**
55
+ * Generates Swagger response definition
56
+ * Swaggerのレスポンス定義を生成します
57
+ * @returns {string} Swagger format response definition
58
+ * Swagger形式のレスポンス定義
59
+ */
60
+ createSwagger(errorList: Array<IError>, apiCode: string): string;
61
+ /**
62
+ * Generates Swagger properties from object type properties
63
+ * オブジェクト型のプロパティからSwaggerのプロパティを生成
64
+ * @param {Array.<string|number>} keys - Path to the properties
65
+ * プロパティへのパス
66
+ * @returns {string} Swagger format property definition
67
+ * Swagger形式のプロパティ定義
68
+ */
69
+ private makeSwaggerProperyFromObject;
70
+ /**
71
+ * Generates Swagger properties from array type properties
72
+ * 配列型のプロパティからSwaggerのプロパティを生成
73
+ * @param {Array.<string|number>} keys - Path to the properties, プロパティへのパス
74
+ * @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
75
+ */
76
+ private makeSwaggerPropertyFromArray;
77
+ /**
78
+ * Generates Swagger properties from array type properties
79
+ * 配列型のプロパティからSwaggerのプロパティを生成
80
+ * @param {Array.<string|number>} keys - Path to the properties, プロパティへのパス
81
+ * @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
82
+ */
83
+ private makeSwaggerPropertyFromDictionary;
84
+ }
85
+ //# sourceMappingURL=ResponseType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponseType.d.ts","sourceRoot":"","sources":["../../src/reqestResponse/ResponseType.ts"],"names":[],"mappings":"AAEA,OAAO,UAA4B,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpC,qBAAa,YAAa,SAAQ,UAAU;IAExC;;;OAGG;IACI,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAM;IAEvC;;;;OAIG;IACH,IAAI,YAAY,IAAI;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAoCvC;IAED;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IA2CjB;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAoCZ;;;;;GAKD;IACH,OAAO,CAAC,MAAM;IAqDd;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAef;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAmIhB;;;;;OAKG;IACI,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IA6EvE;;;;;;;OAOG;IACH,OAAO,CAAC,4BAA4B;IAqCpC;;;;;OAKG;IACH,OAAO,CAAC,4BAA4B;IAgChC;;;;;GAKD;IACH,OAAO,CAAC,iCAAiC;CAU5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -14,6 +14,12 @@
14
14
  "author": "Sho Nakadaira",
15
15
  "type": "commonjs",
16
16
  "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist/**/*",
20
+ "README.md",
21
+ "package.json"
22
+ ],
17
23
  "scripts": {
18
24
  "build": "rm -rf dist/* && tsc",
19
25
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -34,7 +40,6 @@
34
40
  "hono": "4.11.2",
35
41
  "node-cron": "4.2.1",
36
42
  "pdf-lib": "1.17.1",
37
- "sharp": "0.34.1",
38
43
  "type-utils-n-daira": "1.0.11"
39
44
  }
40
45
  }
@@ -1,292 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Base64Client = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const pdf_lib_1 = require("pdf-lib");
18
- const sharp_1 = __importDefault(require("sharp"));
19
- const type_utils_n_daira_1 = require("type-utils-n-daira");
20
- class Base64Client {
21
- constructor() {
22
- this.PREFIX_JPEG_DATA = '/9j/';
23
- this.PREFIX_PNG_DATA = 'iVBORw0KGgo';
24
- }
25
- // public encode(text: string): string {
26
- // return Buffer.from(text).toString('base64');
27
- // }
28
- tryDecode(base64) {
29
- try {
30
- // Data URLのパターンをチェック
31
- if (base64.startsWith('data:')) {
32
- const matches = base64.match(/^data:([A-Za-z-+/]+);base64,(.+)$/);
33
- if (!matches || matches.length !== 3) {
34
- return false;
35
- }
36
- // base64部分のみを取得
37
- base64 = matches[2];
38
- }
39
- if (base64.length % 4 !== 0) {
40
- return false;
41
- }
42
- const regex = /^[A-Za-z0-9+/]*={0,2}$/;
43
- if (!regex.test(base64)) {
44
- return false;
45
- }
46
- return Buffer.from(base64, 'base64');
47
- }
48
- catch (_a) {
49
- return false;
50
- }
51
- }
52
- getMimeType(data) {
53
- try {
54
- let buffer;
55
- if (typeof data === 'string') {
56
- // Data URLのパターンをチェック
57
- if (data.startsWith('data:')) {
58
- const matches = data.match(/^data:([A-Za-z-+/]+);base64,(.+)$/);
59
- if (!matches || matches.length !== 3) {
60
- throw new Error('Invalid Data URL format');
61
- }
62
- // base64部分のみを取得
63
- data = matches[2];
64
- }
65
- buffer = this.tryDecode(data);
66
- }
67
- else {
68
- buffer = data;
69
- }
70
- if (buffer === false) {
71
- throw new Error('Cannot getMineType because the input is not in base64 format.');
72
- }
73
- const header = buffer.subarray(0, 4);
74
- if (header[0] === 0x25 && header[1] === 0x50 && header[2] === 0x44 && header[3] === 0x46) {
75
- return 'application/pdf';
76
- }
77
- else if (header[0] === 0x89 && header[1] === 0x50 && header[2] === 0x4E && header[3] === 0x47) {
78
- return 'image/png';
79
- }
80
- else if (header[0] === 0xFF && header[1] === 0xD8) {
81
- return 'image/jpeg';
82
- }
83
- else if (header[0] === 0x47 && header[1] === 0x49 && header[2] === 0x46 && header[3] === 0x38) {
84
- return 'image/gif';
85
- }
86
- throw new Error('Cannot getMimeType because the file type is not PDF, PNG, JPEG, or GIF.');
87
- }
88
- catch (_a) {
89
- throw new Error('Cannot getMineType because the input is not in base64 format.');
90
- }
91
- }
92
- mergeToPdfBase64(datas) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const mergedPdf = yield pdf_lib_1.PDFDocument.create();
95
- for (const data of datas) {
96
- const buffer = this.tryDecode(data);
97
- if (buffer === false) {
98
- throw new Error('Cannot mergeToPdf because the input is not in base64 format.');
99
- }
100
- const fileType = this.getMimeType(buffer);
101
- if (fileType === 'application/pdf') {
102
- const pdfDoc = yield pdf_lib_1.PDFDocument.load(buffer);
103
- const pages = yield mergedPdf.copyPages(pdfDoc, pdfDoc.getPageIndices());
104
- pages.forEach(page => mergedPdf.addPage(page));
105
- }
106
- else {
107
- // convert from image to pdf
108
- const imagePdf = yield this.convertImageToPdf(buffer);
109
- const pdfDoc = yield pdf_lib_1.PDFDocument.load(imagePdf);
110
- const pages = yield mergedPdf.copyPages(pdfDoc, pdfDoc.getPageIndices());
111
- pages.forEach(page => mergedPdf.addPage(page));
112
- }
113
- }
114
- // 結合したPDFをBase64に変換
115
- const mergedPdfBytes = yield mergedPdf.save();
116
- return Buffer.from(mergedPdfBytes).toString('base64');
117
- });
118
- }
119
- convertImageToPdf(imageBuffer) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const fileType = this.getMimeType(imageBuffer);
122
- let optimizedImage;
123
- if (fileType === 'image/gif') {
124
- // gifの場合はpngに変換して処理
125
- optimizedImage = yield (0, sharp_1.default)(imageBuffer)
126
- .png()
127
- .toBuffer();
128
- }
129
- else {
130
- optimizedImage = yield (0, sharp_1.default)(imageBuffer).toBuffer();
131
- }
132
- // 新しいPDFドキュメントを作成
133
- const pdfDoc = yield pdf_lib_1.PDFDocument.create();
134
- const page = pdfDoc.addPage();
135
- // 画像をPDFに埋め込み
136
- let image;
137
- if (fileType === 'image/jpeg') {
138
- image = yield pdfDoc.embedJpg(optimizedImage);
139
- }
140
- else {
141
- image = yield pdfDoc.embedPng(optimizedImage);
142
- }
143
- const { width, height } = image.scale(1);
144
- // ページサイズを画像に合わせる
145
- page.setSize(width, height);
146
- // 画像を描画
147
- page.drawImage(image, {
148
- x: 0,
149
- y: 0,
150
- width,
151
- height,
152
- });
153
- // PDFをバッファに変換
154
- const pdfBytes = yield pdfDoc.save();
155
- return Buffer.from(pdfBytes);
156
- });
157
- }
158
- isJpeg(value) {
159
- if (type_utils_n_daira_1.ValidateStringUtil.isBase64(value) === false) {
160
- return false;
161
- }
162
- if (value.startsWith('data:')) {
163
- if (value.startsWith('data:image/jpeg,') === false && value.startsWith('data:image/jpg,') === false) {
164
- return false;
165
- }
166
- const valueParts = value.split(',');
167
- if (valueParts.length !== 2) {
168
- return false;
169
- }
170
- return valueParts[1].startsWith(this.PREFIX_JPEG_DATA);
171
- }
172
- return value.startsWith(this.PREFIX_JPEG_DATA);
173
- }
174
- isPng(value) {
175
- if (type_utils_n_daira_1.ValidateStringUtil.isBase64(value) === false) {
176
- return false;
177
- }
178
- if (value.startsWith('data:')) {
179
- if (value.startsWith('data:image/png,') === false) {
180
- return false;
181
- }
182
- const valueParts = value.split(',');
183
- if (valueParts.length !== 2) {
184
- return false;
185
- }
186
- return valueParts[1].startsWith(this.PREFIX_PNG_DATA);
187
- }
188
- return value.startsWith(this.PREFIX_PNG_DATA);
189
- }
190
- tryConvertToPng(base64Value) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- if (type_utils_n_daira_1.ValidateStringUtil.isBase64(base64Value) === false) {
193
- return false;
194
- }
195
- const base64Data = base64Value.startsWith('data:') ? base64Value.split(',')[1] : base64Value;
196
- if (this.isPng(base64Data)) {
197
- return base64Data;
198
- }
199
- else if (this.isJpeg(base64Data)) {
200
- const buffer = Buffer.from(base64Data, 'base64');
201
- try {
202
- const pngBuffer = yield (0, sharp_1.default)(buffer)
203
- .ensureAlpha().png().toBuffer();
204
- return pngBuffer.toString('base64');
205
- }
206
- catch (e) {
207
- return false;
208
- }
209
- }
210
- return false;
211
- });
212
- }
213
- resizeImage(base64Data, toSize) {
214
- return __awaiter(this, void 0, void 0, function* () {
215
- if (type_utils_n_daira_1.ValidateStringUtil.isBase64(base64Data) === false) {
216
- throw new Error("The specified data is not in base64 format");
217
- }
218
- const imageBuffer = Buffer.from(base64Data, 'base64');
219
- const metadata = yield (0, sharp_1.default)(imageBuffer).metadata();
220
- const { width, height, format } = metadata;
221
- if (width === undefined || height === undefined) {
222
- throw new Error("Failed to retrieve image dimensions");
223
- }
224
- let rate = 1;
225
- if ('rate' in toSize) {
226
- rate = toSize.rate;
227
- }
228
- else if ('w' in toSize && 'h' in toSize && 'func' in toSize) {
229
- const wRate = toSize.w / width;
230
- const hRate = toSize.h / height;
231
- switch (toSize.func) {
232
- case 'max':
233
- rate = Math.max(wRate, hRate);
234
- break;
235
- case 'min':
236
- rate = Math.min(wRate, hRate);
237
- break;
238
- }
239
- }
240
- else if ('w' in toSize) {
241
- rate = toSize.w / width;
242
- }
243
- else if ('h' in toSize) {
244
- rate = toSize.h / height;
245
- }
246
- // 画像は1倍より大きくできないので
247
- if (rate >= 1 || rate <= 0) {
248
- return base64Data;
249
- }
250
- let resizedImage;
251
- // フォーマットに応じて処理を分岐
252
- const targetWidth = Math.round(width * rate);
253
- const targetHeight = Math.round(height * rate);
254
- if (format === 'png') {
255
- resizedImage = yield (0, sharp_1.default)(imageBuffer)
256
- .resize(targetWidth, targetHeight, {
257
- fit: 'inside',
258
- withoutEnlargement: true
259
- })
260
- .png({ quality: 90 })
261
- .toBuffer();
262
- }
263
- else {
264
- // JPEG、その他のフォーマット
265
- resizedImage = yield (0, sharp_1.default)(imageBuffer)
266
- .resize(targetWidth, targetHeight, {
267
- fit: 'inside',
268
- withoutEnlargement: true
269
- })
270
- .jpeg({ quality: 90 })
271
- .toBuffer();
272
- }
273
- return resizedImage.toString('base64');
274
- });
275
- }
276
- fetchImageAsBase64(imageUrl) {
277
- return __awaiter(this, void 0, void 0, function* () {
278
- const res = yield axios_1.default.get(imageUrl, {
279
- responseType: 'arraybuffer' // これを追加
280
- });
281
- // Content-Typeをチェック
282
- const contentType = res.headers['content-type'];
283
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('image/'))) {
284
- throw new Error(`Invalid content type: ${contentType}. Expected image/*`);
285
- }
286
- // ArrayBufferをBufferに変換してBase64にエンコード
287
- const buffer = Buffer.from(res.data);
288
- return buffer.toString('base64');
289
- });
290
- }
291
- }
292
- exports.Base64Client = Base64Client;