serverless-simple-middleware 0.0.52 → 0.0.53
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/.prettierignore +2 -2
- package/README.md +4 -4
- package/dist/aws/config.d.ts +15 -15
- package/dist/aws/config.js +29 -29
- package/dist/aws/define.d.ts +21 -21
- package/dist/aws/define.js +8 -8
- package/dist/aws/index.d.ts +3 -3
- package/dist/aws/index.js +8 -8
- package/dist/aws/simple.d.ts +44 -42
- package/dist/aws/simple.js +656 -590
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -8
- package/dist/middleware/aws.d.ts +25 -25
- package/dist/middleware/aws.js +128 -128
- package/dist/middleware/base.d.ts +54 -54
- package/dist/middleware/base.js +140 -140
- package/dist/middleware/build.d.ts +3 -3
- package/dist/middleware/build.js +234 -234
- package/dist/middleware/index.d.ts +12 -12
- package/dist/middleware/index.js +22 -22
- package/dist/middleware/logger.d.ts +18 -18
- package/dist/middleware/logger.js +71 -71
- package/dist/middleware/mysql.d.ts +44 -44
- package/dist/middleware/mysql.js +289 -289
- package/dist/middleware/trace.d.ts +86 -86
- package/dist/middleware/trace.js +255 -255
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +7 -7
- package/dist/utils/logger.d.ts +26 -26
- package/dist/utils/logger.js +73 -73
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.js +9 -9
- package/jest.config.js +7 -7
- package/package.json +61 -60
- package/src/aws/config.ts +46 -46
- package/src/aws/define.ts +29 -29
- package/src/aws/index.ts +3 -3
- package/src/aws/simple.ts +531 -482
- package/src/index.ts +3 -3
- package/src/middleware/aws.ts +78 -78
- package/src/middleware/base.ts +164 -164
- package/src/middleware/build.ts +173 -173
- package/src/middleware/index.ts +20 -20
- package/src/middleware/logger.ts +28 -28
- package/src/middleware/mysql.ts +210 -210
- package/src/middleware/trace.ts +269 -269
- package/src/utils/index.ts +2 -2
- package/src/utils/logger.ts +94 -94
- package/src/utils/misc.ts +11 -11
- package/tsconfig.json +15 -15
- package/tslint.json +12 -12
package/dist/aws/simple.js
CHANGED
|
@@ -1,590 +1,656 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (_) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
var AWS = require("aws-sdk"); // tslint:disable-line
|
|
50
|
-
var fs = require("fs");
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
Key: key
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
.
|
|
299
|
-
.
|
|
300
|
-
.on('
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
case
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
case
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
case
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
case
|
|
519
|
-
|
|
520
|
-
return [4 /*yield*/, this.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
case
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
var AWS = require("aws-sdk"); // tslint:disable-line
|
|
50
|
+
var fs = require("fs");
|
|
51
|
+
var os = require("os");
|
|
52
|
+
var non_secure_1 = require("nanoid/non-secure");
|
|
53
|
+
var utils_1 = require("../utils");
|
|
54
|
+
var config_1 = require("./config");
|
|
55
|
+
var define_1 = require("./define");
|
|
56
|
+
var logger = utils_1.getLogger(__filename);
|
|
57
|
+
var SimpleAWS = /** @class */ (function () {
|
|
58
|
+
function SimpleAWS(config) {
|
|
59
|
+
var _this = this;
|
|
60
|
+
this.getQueueUrl = function (queueName) { return __awaiter(_this, void 0, void 0, function () {
|
|
61
|
+
var urlResult;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
if (this.queueUrls[queueName] !== undefined) {
|
|
66
|
+
return [2 /*return*/, this.queueUrls[queueName]];
|
|
67
|
+
}
|
|
68
|
+
return [4 /*yield*/, this.sqs
|
|
69
|
+
.getQueueUrl({
|
|
70
|
+
QueueName: queueName,
|
|
71
|
+
})
|
|
72
|
+
.promise()];
|
|
73
|
+
case 1:
|
|
74
|
+
urlResult = _a.sent();
|
|
75
|
+
logger.stupid("urlResult", urlResult);
|
|
76
|
+
if (!urlResult.QueueUrl) {
|
|
77
|
+
throw new Error("No queue url with name[" + queueName + "]");
|
|
78
|
+
}
|
|
79
|
+
return [2 /*return*/, (this.queueUrls[queueName] = urlResult.QueueUrl)];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); };
|
|
83
|
+
this.enqueue = function (queueName, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
84
|
+
var queueUrl, sendResult, attrResult;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
logger.debug("Send message[" + data.key + "] to queue.");
|
|
89
|
+
logger.stupid("data", data);
|
|
90
|
+
return [4 /*yield*/, this.getQueueUrl(queueName)];
|
|
91
|
+
case 1:
|
|
92
|
+
queueUrl = _a.sent();
|
|
93
|
+
return [4 /*yield*/, this.sqs
|
|
94
|
+
.sendMessage({
|
|
95
|
+
QueueUrl: queueUrl,
|
|
96
|
+
MessageBody: JSON.stringify(data),
|
|
97
|
+
DelaySeconds: 0,
|
|
98
|
+
})
|
|
99
|
+
.promise()];
|
|
100
|
+
case 2:
|
|
101
|
+
sendResult = _a.sent();
|
|
102
|
+
logger.stupid("sendResult", sendResult);
|
|
103
|
+
return [4 /*yield*/, this.sqs
|
|
104
|
+
.getQueueAttributes({
|
|
105
|
+
QueueUrl: queueUrl,
|
|
106
|
+
AttributeNames: ['ApproximateNumberOfMessages'],
|
|
107
|
+
})
|
|
108
|
+
.promise()];
|
|
109
|
+
case 3:
|
|
110
|
+
attrResult = _a.sent();
|
|
111
|
+
logger.stupid("attrResult", attrResult);
|
|
112
|
+
if (!attrResult.Attributes) {
|
|
113
|
+
return [2 /*return*/, 0];
|
|
114
|
+
}
|
|
115
|
+
return [2 /*return*/, +attrResult.Attributes.ApproximateNumberOfMessages];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}); };
|
|
119
|
+
this.dequeue = function (queueName, fetchSize, waitSeconds, visibilityTimeout) {
|
|
120
|
+
if (fetchSize === void 0) { fetchSize = 1; }
|
|
121
|
+
if (waitSeconds === void 0) { waitSeconds = 1; }
|
|
122
|
+
if (visibilityTimeout === void 0) { visibilityTimeout = 15; }
|
|
123
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
+
var queueUrl, receiveResult, data, _i, _a, each, message;
|
|
125
|
+
return __generator(this, function (_b) {
|
|
126
|
+
switch (_b.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
logger.debug("Receive message from queue[" + queueName + "].");
|
|
129
|
+
return [4 /*yield*/, this.getQueueUrl(queueName)];
|
|
130
|
+
case 1:
|
|
131
|
+
queueUrl = _b.sent();
|
|
132
|
+
return [4 /*yield*/, this.sqs
|
|
133
|
+
.receiveMessage({
|
|
134
|
+
QueueUrl: queueUrl,
|
|
135
|
+
MaxNumberOfMessages: fetchSize,
|
|
136
|
+
WaitTimeSeconds: waitSeconds,
|
|
137
|
+
VisibilityTimeout: visibilityTimeout,
|
|
138
|
+
})
|
|
139
|
+
.promise()];
|
|
140
|
+
case 2:
|
|
141
|
+
receiveResult = _b.sent();
|
|
142
|
+
logger.stupid("receiveResult", receiveResult);
|
|
143
|
+
if (receiveResult.Messages === undefined ||
|
|
144
|
+
receiveResult.Messages.length === 0) {
|
|
145
|
+
return [2 /*return*/, []];
|
|
146
|
+
}
|
|
147
|
+
data = [];
|
|
148
|
+
for (_i = 0, _a = receiveResult.Messages; _i < _a.length; _i++) {
|
|
149
|
+
each = _a[_i];
|
|
150
|
+
if (!each.ReceiptHandle) {
|
|
151
|
+
logger.warn("No receipt handler: " + JSON.stringify(each));
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
message = {
|
|
155
|
+
handle: each.ReceiptHandle,
|
|
156
|
+
body: each.Body ? JSON.parse(each.Body) : undefined,
|
|
157
|
+
};
|
|
158
|
+
data.push(message);
|
|
159
|
+
}
|
|
160
|
+
logger.verbose("Receive a message[" + JSON.stringify(data) + "] from queue");
|
|
161
|
+
return [2 /*return*/, data];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
this.dequeueAll = function (queueName, limitSize, visibilityTimeout) {
|
|
167
|
+
if (limitSize === void 0) { limitSize = Number.MAX_VALUE; }
|
|
168
|
+
if (visibilityTimeout === void 0) { visibilityTimeout = 15; }
|
|
169
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
170
|
+
var messages, maxFetchSize, eachOfMessages, _i, eachOfMessages_1, each;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
messages = [];
|
|
175
|
+
maxFetchSize = 10;
|
|
176
|
+
_a.label = 1;
|
|
177
|
+
case 1:
|
|
178
|
+
if (!(messages.length < limitSize)) return [3 /*break*/, 3];
|
|
179
|
+
return [4 /*yield*/, this.dequeue(queueName, Math.min(limitSize - messages.length, maxFetchSize), 0, visibilityTimeout)];
|
|
180
|
+
case 2:
|
|
181
|
+
eachOfMessages = _a.sent();
|
|
182
|
+
if (!eachOfMessages || eachOfMessages.length === 0) {
|
|
183
|
+
return [3 /*break*/, 3];
|
|
184
|
+
}
|
|
185
|
+
for (_i = 0, eachOfMessages_1 = eachOfMessages; _i < eachOfMessages_1.length; _i++) {
|
|
186
|
+
each = eachOfMessages_1[_i];
|
|
187
|
+
messages.push(each);
|
|
188
|
+
}
|
|
189
|
+
return [3 /*break*/, 1];
|
|
190
|
+
case 3:
|
|
191
|
+
logger.stupid("messages", messages);
|
|
192
|
+
return [2 /*return*/, messages];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
this.retainMessage = function (queueName, handle, seconds) { return __awaiter(_this, void 0, void 0, function () {
|
|
198
|
+
var _this = this;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
201
|
+
var _this = this;
|
|
202
|
+
return __generator(this, function (_a) {
|
|
203
|
+
logger.debug("Change visibilityTimeout of " + handle + " to " + seconds + "secs.");
|
|
204
|
+
this.getQueueUrl(queueName)
|
|
205
|
+
.then(function (queueUrl) {
|
|
206
|
+
_this.sqs.changeMessageVisibility({
|
|
207
|
+
QueueUrl: queueUrl,
|
|
208
|
+
ReceiptHandle: handle,
|
|
209
|
+
VisibilityTimeout: seconds,
|
|
210
|
+
}, function (err, changeResult) {
|
|
211
|
+
if (err) {
|
|
212
|
+
reject(err);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
logger.stupid("changeResult", changeResult);
|
|
216
|
+
resolve(handle);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
})
|
|
220
|
+
.catch(reject);
|
|
221
|
+
return [2 /*return*/];
|
|
222
|
+
});
|
|
223
|
+
}); })];
|
|
224
|
+
});
|
|
225
|
+
}); };
|
|
226
|
+
this.completeMessage = function (queueName, handle) { return __awaiter(_this, void 0, void 0, function () {
|
|
227
|
+
var queueUrl, deleteResult;
|
|
228
|
+
return __generator(this, function (_a) {
|
|
229
|
+
switch (_a.label) {
|
|
230
|
+
case 0:
|
|
231
|
+
logger.debug("Complete a message with handle[" + handle + "]");
|
|
232
|
+
return [4 /*yield*/, this.getQueueUrl(queueName)];
|
|
233
|
+
case 1:
|
|
234
|
+
queueUrl = _a.sent();
|
|
235
|
+
return [4 /*yield*/, this.sqs
|
|
236
|
+
.deleteMessage({
|
|
237
|
+
QueueUrl: queueUrl,
|
|
238
|
+
ReceiptHandle: handle,
|
|
239
|
+
})
|
|
240
|
+
.promise()];
|
|
241
|
+
case 2:
|
|
242
|
+
deleteResult = _a.sent();
|
|
243
|
+
logger.stupid("deleteResult", deleteResult);
|
|
244
|
+
return [2 /*return*/, handle];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}); };
|
|
248
|
+
this.completeMessages = function (queueName, handles) { return __awaiter(_this, void 0, void 0, function () {
|
|
249
|
+
var chunkSize, index, start, end, sublist, queueUrl, deletesResult;
|
|
250
|
+
return __generator(this, function (_a) {
|
|
251
|
+
switch (_a.label) {
|
|
252
|
+
case 0:
|
|
253
|
+
logger.debug("Complete a message with handle[" + handles + "]");
|
|
254
|
+
if (!handles) {
|
|
255
|
+
return [2 /*return*/, handles];
|
|
256
|
+
}
|
|
257
|
+
chunkSize = 10;
|
|
258
|
+
index = 0;
|
|
259
|
+
start = 0;
|
|
260
|
+
_a.label = 1;
|
|
261
|
+
case 1:
|
|
262
|
+
if (!(start < handles.length)) return [3 /*break*/, 5];
|
|
263
|
+
end = Math.min(start + chunkSize, handles.length);
|
|
264
|
+
sublist = handles.slice(start, end);
|
|
265
|
+
return [4 /*yield*/, this.getQueueUrl(queueName)];
|
|
266
|
+
case 2:
|
|
267
|
+
queueUrl = _a.sent();
|
|
268
|
+
return [4 /*yield*/, this.sqs
|
|
269
|
+
.deleteMessageBatch({
|
|
270
|
+
QueueUrl: queueUrl,
|
|
271
|
+
Entries: sublist.map(function (handle) { return ({
|
|
272
|
+
Id: (++index).toString(),
|
|
273
|
+
ReceiptHandle: handle,
|
|
274
|
+
}); }),
|
|
275
|
+
})
|
|
276
|
+
.promise()];
|
|
277
|
+
case 3:
|
|
278
|
+
deletesResult = _a.sent();
|
|
279
|
+
logger.stupid("deleteResult", deletesResult);
|
|
280
|
+
_a.label = 4;
|
|
281
|
+
case 4:
|
|
282
|
+
start += chunkSize;
|
|
283
|
+
return [3 /*break*/, 1];
|
|
284
|
+
case 5: return [2 /*return*/, handles];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}); };
|
|
288
|
+
this.download = function (bucket, key, localPath) { return __awaiter(_this, void 0, void 0, function () {
|
|
289
|
+
var stream;
|
|
290
|
+
return __generator(this, function (_a) {
|
|
291
|
+
logger.debug("Get a stream of item[" + key + "] from bucket[" + bucket + "]");
|
|
292
|
+
stream = this.s3
|
|
293
|
+
.getObject({ Bucket: bucket, Key: key })
|
|
294
|
+
.createReadStream();
|
|
295
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
296
|
+
return stream
|
|
297
|
+
.on('error', function (error) { return reject(error); })
|
|
298
|
+
.pipe(fs.createWriteStream(localPath))
|
|
299
|
+
.on('finish', function () { return resolve(localPath); })
|
|
300
|
+
.on('error', function (error) { return reject(error); });
|
|
301
|
+
})];
|
|
302
|
+
});
|
|
303
|
+
}); };
|
|
304
|
+
this.readFile = function (bucket, key) { return __awaiter(_this, void 0, void 0, function () {
|
|
305
|
+
var tempFile, content;
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0:
|
|
309
|
+
logger.debug("Read item[" + key + "] from bucket[" + bucket + "]");
|
|
310
|
+
tempFile = os.tmpdir() + "/" + non_secure_1.nanoid();
|
|
311
|
+
_a.label = 1;
|
|
312
|
+
case 1:
|
|
313
|
+
_a.trys.push([1, , 4, 5]);
|
|
314
|
+
return [4 /*yield*/, this.download(bucket, key, tempFile)];
|
|
315
|
+
case 2:
|
|
316
|
+
_a.sent();
|
|
317
|
+
return [4 /*yield*/, fs.promises.readFile(tempFile, {
|
|
318
|
+
encoding: 'utf-8',
|
|
319
|
+
})];
|
|
320
|
+
case 3:
|
|
321
|
+
content = _a.sent();
|
|
322
|
+
return [2 /*return*/, content];
|
|
323
|
+
case 4:
|
|
324
|
+
if (!fs.existsSync(tempFile)) {
|
|
325
|
+
fs.unlink(tempFile, function (error) {
|
|
326
|
+
if (!error) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
var msg = "Error during readFile: unlink " + tempFile + ": " + utils_1.stringifyError(error);
|
|
330
|
+
logger.error(msg);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return [7 /*endfinally*/];
|
|
334
|
+
case 5: return [2 /*return*/];
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}); };
|
|
338
|
+
this.upload = function (bucket, localPath, key) { return __awaiter(_this, void 0, void 0, function () {
|
|
339
|
+
var putResult;
|
|
340
|
+
return __generator(this, function (_a) {
|
|
341
|
+
switch (_a.label) {
|
|
342
|
+
case 0:
|
|
343
|
+
logger.debug("Upload item[" + key + "] into bucket[" + bucket + "]");
|
|
344
|
+
return [4 /*yield*/, this.s3
|
|
345
|
+
.upload({
|
|
346
|
+
Bucket: bucket,
|
|
347
|
+
Key: key,
|
|
348
|
+
Body: fs.createReadStream(localPath),
|
|
349
|
+
})
|
|
350
|
+
.promise()];
|
|
351
|
+
case 1:
|
|
352
|
+
putResult = _a.sent();
|
|
353
|
+
logger.stupid("putResult", putResult);
|
|
354
|
+
return [2 /*return*/, key];
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}); };
|
|
358
|
+
this.writeFile = function (bucket, key, content) { return __awaiter(_this, void 0, void 0, function () {
|
|
359
|
+
var tempFile;
|
|
360
|
+
return __generator(this, function (_a) {
|
|
361
|
+
switch (_a.label) {
|
|
362
|
+
case 0:
|
|
363
|
+
logger.debug("Write item[" + key + "] into bucket[" + bucket + "]");
|
|
364
|
+
tempFile = os.tmpdir() + "/" + non_secure_1.nanoid();
|
|
365
|
+
_a.label = 1;
|
|
366
|
+
case 1:
|
|
367
|
+
_a.trys.push([1, , 4, 5]);
|
|
368
|
+
return [4 /*yield*/, fs.promises.writeFile(tempFile, content, 'utf-8')];
|
|
369
|
+
case 2:
|
|
370
|
+
_a.sent();
|
|
371
|
+
return [4 /*yield*/, this.upload(bucket, tempFile, key)];
|
|
372
|
+
case 3:
|
|
373
|
+
_a.sent();
|
|
374
|
+
return [3 /*break*/, 5];
|
|
375
|
+
case 4:
|
|
376
|
+
if (!fs.existsSync(tempFile)) {
|
|
377
|
+
return [2 /*return*/];
|
|
378
|
+
}
|
|
379
|
+
fs.unlink(tempFile, function (error) {
|
|
380
|
+
if (!error) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
var msg = "Error during writeFile: unlink file " + tempFile + ": " + utils_1.stringifyError(error);
|
|
384
|
+
logger.error(msg);
|
|
385
|
+
});
|
|
386
|
+
return [7 /*endfinally*/];
|
|
387
|
+
case 5: return [2 /*return*/];
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}); };
|
|
391
|
+
this.getSignedUrl = function (bucketName, key, operation, params) {
|
|
392
|
+
if (operation === void 0) { operation = 'getObject'; }
|
|
393
|
+
return {
|
|
394
|
+
key: key,
|
|
395
|
+
url: _this.s3.getSignedUrl(operation, __assign({ Bucket: bucketName, Key: key, Expires: 60 * 10 }, (params || {}))),
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
this.getSignedCookie = function (keyPairId, privateKey, url, expires) {
|
|
399
|
+
var signer = new AWS.CloudFront.Signer(keyPairId, privateKey);
|
|
400
|
+
var policy = {
|
|
401
|
+
Statement: [
|
|
402
|
+
{
|
|
403
|
+
Resource: url,
|
|
404
|
+
Condition: {
|
|
405
|
+
DateLessThan: { 'AWS:EpochTime': expires },
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
};
|
|
410
|
+
var ret = signer.getSignedCookie({ policy: JSON.stringify(policy) });
|
|
411
|
+
return ret;
|
|
412
|
+
};
|
|
413
|
+
this.getAttachmentUrl = function (bucketName, key, fileName, params) {
|
|
414
|
+
return _this.getSignedUrl(bucketName, key, 'getObject', __assign({}, params, { ResponseContentDisposition: "attachment; filename=\"" + fileName + "\"" }));
|
|
415
|
+
};
|
|
416
|
+
this.getDynamoDbItem = function (tableName, key, defaultValue) { return __awaiter(_this, void 0, void 0, function () {
|
|
417
|
+
var getResult, item;
|
|
418
|
+
return __generator(this, function (_a) {
|
|
419
|
+
switch (_a.label) {
|
|
420
|
+
case 0:
|
|
421
|
+
logger.debug("Read an item with key[" + JSON.stringify(key) + "] from " + tableName + ".");
|
|
422
|
+
return [4 /*yield*/, this.dynamodb
|
|
423
|
+
.get({
|
|
424
|
+
TableName: tableName,
|
|
425
|
+
Key: key,
|
|
426
|
+
})
|
|
427
|
+
.promise()];
|
|
428
|
+
case 1:
|
|
429
|
+
getResult = _a.sent();
|
|
430
|
+
logger.stupid("getResult", getResult);
|
|
431
|
+
item = getResult !== undefined && getResult.Item !== undefined
|
|
432
|
+
? getResult.Item // Casts forcefully.
|
|
433
|
+
: defaultValue;
|
|
434
|
+
logger.stupid("item", item);
|
|
435
|
+
return [2 /*return*/, item];
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}); };
|
|
439
|
+
this.updateDynamoDbItem = function (tableName, key, columnValues) { return __awaiter(_this, void 0, void 0, function () {
|
|
440
|
+
var expressions, attributeValues, updateResult;
|
|
441
|
+
return __generator(this, function (_a) {
|
|
442
|
+
switch (_a.label) {
|
|
443
|
+
case 0:
|
|
444
|
+
logger.debug("Update an item with key[" + JSON.stringify(key) + "] to " + tableName);
|
|
445
|
+
logger.stupid("keyValues", columnValues);
|
|
446
|
+
expressions = Object.keys(columnValues)
|
|
447
|
+
.map(function (column) { return column + " = :" + column; })
|
|
448
|
+
.join(', ');
|
|
449
|
+
attributeValues = Object.keys(columnValues)
|
|
450
|
+
.map(function (column) { return [":" + column, columnValues[column]]; })
|
|
451
|
+
.reduce(function (obj, pair) {
|
|
452
|
+
var _a;
|
|
453
|
+
return (__assign({}, obj, (_a = {}, _a[pair[0]] = pair[1], _a)));
|
|
454
|
+
}, {});
|
|
455
|
+
logger.stupid("expressions", expressions);
|
|
456
|
+
logger.stupid("attributeValues", attributeValues);
|
|
457
|
+
return [4 /*yield*/, this.dynamodb
|
|
458
|
+
.update({
|
|
459
|
+
TableName: tableName,
|
|
460
|
+
Key: key,
|
|
461
|
+
UpdateExpression: "set " + expressions,
|
|
462
|
+
ExpressionAttributeValues: attributeValues,
|
|
463
|
+
})
|
|
464
|
+
.promise()];
|
|
465
|
+
case 1:
|
|
466
|
+
updateResult = _a.sent();
|
|
467
|
+
logger.stupid("updateResult", updateResult);
|
|
468
|
+
return [2 /*return*/, updateResult];
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}); };
|
|
472
|
+
// Setup
|
|
473
|
+
this.setupQueue = function (queueName) { return __awaiter(_this, void 0, void 0, function () {
|
|
474
|
+
var listResult, _i, _a, queueUrl, error_1, createResult;
|
|
475
|
+
return __generator(this, function (_b) {
|
|
476
|
+
switch (_b.label) {
|
|
477
|
+
case 0:
|
|
478
|
+
_b.trys.push([0, 2, , 3]);
|
|
479
|
+
return [4 /*yield*/, this.sqs
|
|
480
|
+
.listQueues({
|
|
481
|
+
QueueNamePrefix: queueName,
|
|
482
|
+
})
|
|
483
|
+
.promise()];
|
|
484
|
+
case 1:
|
|
485
|
+
listResult = _b.sent();
|
|
486
|
+
if (listResult.QueueUrls) {
|
|
487
|
+
for (_i = 0, _a = listResult.QueueUrls; _i < _a.length; _i++) {
|
|
488
|
+
queueUrl = _a[_i];
|
|
489
|
+
if (queueUrl.endsWith(queueName)) {
|
|
490
|
+
logger.debug("Queue[" + queueName + " => " + queueUrl + "] already exists.");
|
|
491
|
+
return [2 /*return*/, true];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return [3 /*break*/, 3];
|
|
496
|
+
case 2:
|
|
497
|
+
error_1 = _b.sent();
|
|
498
|
+
logger.debug("No Queue[" + queueName + "] exists due to " + error_1);
|
|
499
|
+
return [3 /*break*/, 3];
|
|
500
|
+
case 3:
|
|
501
|
+
logger.debug("Create a queue[" + queueName + "] newly.");
|
|
502
|
+
return [4 /*yield*/, this.sqs
|
|
503
|
+
.createQueue({
|
|
504
|
+
QueueName: queueName,
|
|
505
|
+
})
|
|
506
|
+
.promise()];
|
|
507
|
+
case 4:
|
|
508
|
+
createResult = _b.sent();
|
|
509
|
+
logger.stupid("createResult", createResult);
|
|
510
|
+
return [2 /*return*/, true];
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}); };
|
|
514
|
+
this.setupStorage = function (bucketName, cors) { return __awaiter(_this, void 0, void 0, function () {
|
|
515
|
+
var listResult, error_2, createResult, corsResult;
|
|
516
|
+
return __generator(this, function (_a) {
|
|
517
|
+
switch (_a.label) {
|
|
518
|
+
case 0:
|
|
519
|
+
_a.trys.push([0, 2, , 3]);
|
|
520
|
+
return [4 /*yield*/, this.s3.listBuckets().promise()];
|
|
521
|
+
case 1:
|
|
522
|
+
listResult = _a.sent();
|
|
523
|
+
if (listResult.Buckets &&
|
|
524
|
+
listResult.Buckets.map(function (each) { return each.Name; }).includes(bucketName)) {
|
|
525
|
+
logger.debug("Bucket[" + bucketName + "] already exists.");
|
|
526
|
+
return [2 /*return*/, true];
|
|
527
|
+
}
|
|
528
|
+
return [3 /*break*/, 3];
|
|
529
|
+
case 2:
|
|
530
|
+
error_2 = _a.sent();
|
|
531
|
+
logger.debug("No bucket[" + bucketName + "] exists due to " + error_2);
|
|
532
|
+
return [3 /*break*/, 3];
|
|
533
|
+
case 3:
|
|
534
|
+
logger.debug("Create a bucket[" + bucketName + "] newly.");
|
|
535
|
+
return [4 /*yield*/, this.s3
|
|
536
|
+
.createBucket({
|
|
537
|
+
Bucket: bucketName,
|
|
538
|
+
})
|
|
539
|
+
.promise()];
|
|
540
|
+
case 4:
|
|
541
|
+
createResult = _a.sent();
|
|
542
|
+
logger.stupid("createResult", createResult);
|
|
543
|
+
if (!cors) return [3 /*break*/, 6];
|
|
544
|
+
return [4 /*yield*/, this.s3
|
|
545
|
+
.putBucketCors({
|
|
546
|
+
Bucket: bucketName,
|
|
547
|
+
CORSConfiguration: {
|
|
548
|
+
CORSRules: [
|
|
549
|
+
{
|
|
550
|
+
AllowedHeaders: ['*'],
|
|
551
|
+
AllowedMethods: cors.methods,
|
|
552
|
+
AllowedOrigins: cors.origins,
|
|
553
|
+
},
|
|
554
|
+
],
|
|
555
|
+
},
|
|
556
|
+
})
|
|
557
|
+
.promise()];
|
|
558
|
+
case 5:
|
|
559
|
+
corsResult = _a.sent();
|
|
560
|
+
logger.stupid("corsResult", corsResult);
|
|
561
|
+
_a.label = 6;
|
|
562
|
+
case 6: return [2 /*return*/, true];
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}); };
|
|
566
|
+
this.setupDynamoDb = function (tableName, keyColumn) { return __awaiter(_this, void 0, void 0, function () {
|
|
567
|
+
var listResult, error_3, createResult;
|
|
568
|
+
return __generator(this, function (_a) {
|
|
569
|
+
switch (_a.label) {
|
|
570
|
+
case 0:
|
|
571
|
+
_a.trys.push([0, 2, , 3]);
|
|
572
|
+
return [4 /*yield*/, this.dynamodbAdmin.listTables().promise()];
|
|
573
|
+
case 1:
|
|
574
|
+
listResult = _a.sent();
|
|
575
|
+
if (listResult.TableNames && listResult.TableNames.includes(tableName)) {
|
|
576
|
+
logger.debug("Table[" + tableName + "] already exists.");
|
|
577
|
+
return [2 /*return*/, true];
|
|
578
|
+
}
|
|
579
|
+
return [3 /*break*/, 3];
|
|
580
|
+
case 2:
|
|
581
|
+
error_3 = _a.sent();
|
|
582
|
+
logger.debug("No table[" + tableName + "] exists due to " + error_3);
|
|
583
|
+
return [3 /*break*/, 3];
|
|
584
|
+
case 3:
|
|
585
|
+
logger.debug("Create a table[" + tableName + "] newly.");
|
|
586
|
+
return [4 /*yield*/, this.dynamodbAdmin
|
|
587
|
+
.createTable({
|
|
588
|
+
TableName: tableName,
|
|
589
|
+
KeySchema: [{ AttributeName: keyColumn, KeyType: 'HASH' }],
|
|
590
|
+
AttributeDefinitions: [
|
|
591
|
+
{ AttributeName: keyColumn, AttributeType: 'S' },
|
|
592
|
+
],
|
|
593
|
+
ProvisionedThroughput: {
|
|
594
|
+
ReadCapacityUnits: 30,
|
|
595
|
+
WriteCapacityUnits: 10,
|
|
596
|
+
},
|
|
597
|
+
})
|
|
598
|
+
.promise()];
|
|
599
|
+
case 4:
|
|
600
|
+
createResult = _a.sent();
|
|
601
|
+
logger.stupid("createResult", createResult);
|
|
602
|
+
return [2 /*return*/, true];
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
}); };
|
|
606
|
+
this.config = config || new config_1.SimpleAWSConfig();
|
|
607
|
+
/**
|
|
608
|
+
* The simple cache for { queueName: queueUrl }.
|
|
609
|
+
* It can help in the only case of launching this project as offline.
|
|
610
|
+
* @type { { [queueName: string]: string } }
|
|
611
|
+
*/
|
|
612
|
+
this.queueUrls = {};
|
|
613
|
+
}
|
|
614
|
+
Object.defineProperty(SimpleAWS.prototype, "s3", {
|
|
615
|
+
get: function () {
|
|
616
|
+
if (this.lazyS3 === undefined) {
|
|
617
|
+
this.lazyS3 = new AWS.S3(this.config.get(define_1.AWSComponent.s3));
|
|
618
|
+
}
|
|
619
|
+
return this.lazyS3;
|
|
620
|
+
},
|
|
621
|
+
enumerable: true,
|
|
622
|
+
configurable: true
|
|
623
|
+
});
|
|
624
|
+
Object.defineProperty(SimpleAWS.prototype, "sqs", {
|
|
625
|
+
get: function () {
|
|
626
|
+
if (this.lazySqs === undefined) {
|
|
627
|
+
this.lazySqs = new AWS.SQS(this.config.get(define_1.AWSComponent.sqs));
|
|
628
|
+
}
|
|
629
|
+
return this.lazySqs;
|
|
630
|
+
},
|
|
631
|
+
enumerable: true,
|
|
632
|
+
configurable: true
|
|
633
|
+
});
|
|
634
|
+
Object.defineProperty(SimpleAWS.prototype, "dynamodb", {
|
|
635
|
+
get: function () {
|
|
636
|
+
if (this.lazyDynamodb === undefined) {
|
|
637
|
+
this.lazyDynamodb = new AWS.DynamoDB.DocumentClient(this.config.get(define_1.AWSComponent.dynamodb));
|
|
638
|
+
}
|
|
639
|
+
return this.lazyDynamodb;
|
|
640
|
+
},
|
|
641
|
+
enumerable: true,
|
|
642
|
+
configurable: true
|
|
643
|
+
});
|
|
644
|
+
Object.defineProperty(SimpleAWS.prototype, "dynamodbAdmin", {
|
|
645
|
+
get: function () {
|
|
646
|
+
if (this.lazyDynamodbAdmin === undefined) {
|
|
647
|
+
this.lazyDynamodbAdmin = new AWS.DynamoDB(this.config.get(define_1.AWSComponent.dynamodb));
|
|
648
|
+
}
|
|
649
|
+
return this.lazyDynamodbAdmin;
|
|
650
|
+
},
|
|
651
|
+
enumerable: true,
|
|
652
|
+
configurable: true
|
|
653
|
+
});
|
|
654
|
+
return SimpleAWS;
|
|
655
|
+
}());
|
|
656
|
+
exports.SimpleAWS = SimpleAWS;
|