pg-mvc-service 1.0.8 → 1.0.9

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.
@@ -136,7 +136,8 @@ class AwsS3Client {
136
136
  }
137
137
  getText(path, fileName) {
138
138
  return __awaiter(this, void 0, void 0, function* () {
139
- var _a;
139
+ var _a, e_1, _b, _c;
140
+ var _d;
140
141
  try {
141
142
  const command = new client_s3_1.GetObjectCommand({
142
143
  Bucket: this.bucketName,
@@ -146,18 +147,39 @@ class AwsS3Client {
146
147
  if (res.Body === undefined) {
147
148
  throw new Error(`Failed to get text data. Response body is undefined.`);
148
149
  }
149
- if (((_a = res.ContentType) === null || _a === void 0 ? void 0 : _a.startsWith('text/')) === false) {
150
+ if (((_d = res.ContentType) === null || _d === void 0 ? void 0 : _d.startsWith('text/')) === false) {
150
151
  throw new Error(`Cannot get text data from non-text file. ContentType: ${res.ContentType}`);
151
152
  }
152
153
  // v3ではBodyがReadableStreamなので、変換が必要
153
- const stream = res.Body;
154
- const reader = stream.getReader();
155
154
  const chunks = [];
156
- while (true) {
157
- const { done, value } = yield reader.read();
158
- if (done)
159
- break;
160
- chunks.push(value);
155
+ if (res.Body && typeof res.Body === 'object' && 'getReader' in res.Body) {
156
+ // ReadableStreamの場合
157
+ const stream = res.Body;
158
+ const reader = stream.getReader();
159
+ while (true) {
160
+ const { done, value } = yield reader.read();
161
+ if (done)
162
+ break;
163
+ chunks.push(value);
164
+ }
165
+ }
166
+ else {
167
+ try {
168
+ // Node.js Readableの場合
169
+ for (var _e = true, _f = __asyncValues(res.Body), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
170
+ _c = _g.value;
171
+ _e = false;
172
+ const chunk = _c;
173
+ chunks.push(chunk);
174
+ }
175
+ }
176
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
177
+ finally {
178
+ try {
179
+ if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
180
+ }
181
+ finally { if (e_1) throw e_1.error; }
182
+ }
161
183
  }
162
184
  const buffer = Buffer.concat(chunks);
163
185
  return buffer.toString('utf-8');
@@ -183,7 +205,7 @@ class AwsS3Client {
183
205
  }
184
206
  getDataFronJson(path, fileName) {
185
207
  return __awaiter(this, void 0, void 0, function* () {
186
- var _a, e_1, _b, _c;
208
+ var _a, e_2, _b, _c;
187
209
  const command = new client_s3_1.GetObjectCommand({
188
210
  Bucket: this.bucketName,
189
211
  Key: this.makeKey(path, fileName),
@@ -205,12 +227,12 @@ class AwsS3Client {
205
227
  chunks.push(chunk);
206
228
  }
207
229
  }
208
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
230
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
209
231
  finally {
210
232
  try {
211
233
  if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
212
234
  }
213
- finally { if (e_1) throw e_1.error; }
235
+ finally { if (e_2) throw e_2.error; }
214
236
  }
215
237
  const buffer = Buffer.concat(chunks);
216
238
  const jsonString = buffer.toString('utf-8');
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.Base64Client = exports.AwsS3Client = exports.createSwagger = exports.BusinessLogicException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
3
+ exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.Base64Client = exports.AwsS3Client = exports.createSwagger = exports.UnprocessableException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
4
4
  var Service_1 = require("./Service");
5
5
  Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return Service_1.Service; } });
6
6
  var Exception_1 = require("./exceptions/Exception");
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "AuthException", { enumerable: true, get: functio
9
9
  Object.defineProperty(exports, "InputErrorException", { enumerable: true, get: function () { return Exception_1.InputErrorException; } });
10
10
  Object.defineProperty(exports, "ForbiddenException", { enumerable: true, get: function () { return Exception_1.ForbiddenException; } });
11
11
  Object.defineProperty(exports, "DbConflictException", { enumerable: true, get: function () { return Exception_1.DbConflictException; } });
12
- Object.defineProperty(exports, "BusinessLogicException", { enumerable: true, get: function () { return Exception_1.UnprocessableException; } });
12
+ Object.defineProperty(exports, "UnprocessableException", { enumerable: true, get: function () { return Exception_1.UnprocessableException; } });
13
13
  var Swagger_1 = require("./documents/Swagger");
14
14
  Object.defineProperty(exports, "createSwagger", { enumerable: true, get: function () { return Swagger_1.createSwagger; } });
15
15
  var AwsS3Client_1 = require("./clients/AwsS3Client");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -147,14 +147,22 @@ export class AwsS3Client {
147
147
  }
148
148
 
149
149
  // v3ではBodyがReadableStreamなので、変換が必要
150
- const stream = res.Body as ReadableStream;
151
- const reader = stream.getReader();
152
150
  const chunks: Uint8Array[] = [];
153
-
154
- while (true) {
155
- const { done, value } = await reader.read();
156
- if (done) break;
157
- chunks.push(value);
151
+ if (res.Body && typeof res.Body === 'object' && 'getReader' in res.Body) {
152
+ // ReadableStreamの場合
153
+ const stream = res.Body as ReadableStream;
154
+ const reader = stream.getReader();
155
+
156
+ while (true) {
157
+ const { done, value } = await reader.read();
158
+ if (done) break;
159
+ chunks.push(value);
160
+ }
161
+ } else {
162
+ // Node.js Readableの場合
163
+ for await (const chunk of res.Body as any) {
164
+ chunks.push(chunk);
165
+ }
158
166
  }
159
167
 
160
168
  const buffer = Buffer.concat(chunks);