serverless-simple-middleware 0.0.53 → 0.0.56

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 (51) hide show
  1. package/.prettierignore +2 -2
  2. package/README.md +4 -4
  3. package/dist/aws/config.d.ts +15 -15
  4. package/dist/aws/config.js +29 -29
  5. package/dist/aws/define.d.ts +21 -21
  6. package/dist/aws/define.js +8 -8
  7. package/dist/aws/index.d.ts +3 -3
  8. package/dist/aws/index.js +8 -8
  9. package/dist/aws/simple.d.ts +44 -44
  10. package/dist/aws/simple.js +659 -656
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +8 -8
  13. package/dist/middleware/aws.d.ts +25 -25
  14. package/dist/middleware/aws.js +128 -128
  15. package/dist/middleware/base.d.ts +54 -54
  16. package/dist/middleware/base.js +140 -140
  17. package/dist/middleware/build.d.ts +3 -3
  18. package/dist/middleware/build.js +234 -234
  19. package/dist/middleware/index.d.ts +12 -12
  20. package/dist/middleware/index.js +22 -22
  21. package/dist/middleware/logger.d.ts +18 -18
  22. package/dist/middleware/logger.js +71 -71
  23. package/dist/middleware/mysql.d.ts +44 -44
  24. package/dist/middleware/mysql.js +289 -289
  25. package/dist/middleware/trace.d.ts +86 -86
  26. package/dist/middleware/trace.js +255 -255
  27. package/dist/utils/index.d.ts +2 -2
  28. package/dist/utils/index.js +7 -7
  29. package/dist/utils/logger.d.ts +26 -26
  30. package/dist/utils/logger.js +73 -73
  31. package/dist/utils/misc.d.ts +1 -1
  32. package/dist/utils/misc.js +9 -9
  33. package/jest.config.js +7 -7
  34. package/package.json +61 -61
  35. package/src/aws/config.ts +46 -46
  36. package/src/aws/define.ts +29 -29
  37. package/src/aws/index.ts +3 -3
  38. package/src/aws/simple.ts +529 -531
  39. package/src/index.ts +3 -3
  40. package/src/middleware/aws.ts +78 -78
  41. package/src/middleware/base.ts +164 -164
  42. package/src/middleware/build.ts +173 -173
  43. package/src/middleware/index.ts +20 -20
  44. package/src/middleware/logger.ts +28 -28
  45. package/src/middleware/mysql.ts +210 -210
  46. package/src/middleware/trace.ts +269 -269
  47. package/src/utils/index.ts +2 -2
  48. package/src/utils/logger.ts +94 -94
  49. package/src/utils/misc.ts +11 -11
  50. package/tsconfig.json +15 -15
  51. package/tslint.json +12 -12
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './aws';
2
- export * from './middleware';
3
- export * from './utils';
1
+ export * from './aws';
2
+ export * from './middleware';
3
+ export * from './utils';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./aws"));
7
- __export(require("./middleware"));
8
- __export(require("./utils"));
1
+ "use strict";
2
+ function __export(m) {
3
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ __export(require("./aws"));
7
+ __export(require("./middleware"));
8
+ __export(require("./utils"));
@@ -1,25 +1,25 @@
1
- import { SimpleAWS, SimpleAWSConfig, SimpleAWSConfigLoadParam } from '../aws';
2
- import { HandlerAuxBase, HandlerPluginBase } from './base';
3
- declare type InitializerMapper = (aws: SimpleAWS, env: {}) => {
4
- [name: string]: () => Promise<boolean>;
5
- };
6
- export interface AWSPluginOptions {
7
- config?: SimpleAWSConfigLoadParam;
8
- mapper?: InitializerMapper;
9
- }
10
- export interface AWSPluginAux extends HandlerAuxBase {
11
- aws: SimpleAWS;
12
- awsConfig: SimpleAWSConfig;
13
- }
14
- export declare class AWSPlugin extends HandlerPluginBase<AWSPluginAux> {
15
- private options?;
16
- private aws?;
17
- private config;
18
- constructor(options?: AWSPluginOptions);
19
- create: () => Promise<{
20
- aws: SimpleAWS;
21
- awsConfig: SimpleAWSConfig;
22
- }>;
23
- }
24
- declare const build: (options?: AWSPluginOptions | undefined) => AWSPlugin;
25
- export default build;
1
+ import { SimpleAWS, SimpleAWSConfig, SimpleAWSConfigLoadParam } from '../aws';
2
+ import { HandlerAuxBase, HandlerPluginBase } from './base';
3
+ declare type InitializerMapper = (aws: SimpleAWS, env: {}) => {
4
+ [name: string]: () => Promise<boolean>;
5
+ };
6
+ export interface AWSPluginOptions {
7
+ config?: SimpleAWSConfigLoadParam;
8
+ mapper?: InitializerMapper;
9
+ }
10
+ export interface AWSPluginAux extends HandlerAuxBase {
11
+ aws: SimpleAWS;
12
+ awsConfig: SimpleAWSConfig;
13
+ }
14
+ export declare class AWSPlugin extends HandlerPluginBase<AWSPluginAux> {
15
+ private options?;
16
+ private aws?;
17
+ private config;
18
+ constructor(options?: AWSPluginOptions);
19
+ create: () => Promise<{
20
+ aws: SimpleAWS;
21
+ awsConfig: SimpleAWSConfig;
22
+ }>;
23
+ }
24
+ declare const build: (options?: AWSPluginOptions | undefined) => AWSPlugin;
25
+ export default build;
@@ -1,128 +1,128 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __assign = (this && this.__assign) || function () {
16
- __assign = Object.assign || function(t) {
17
- for (var s, i = 1, n = arguments.length; i < n; i++) {
18
- s = arguments[i];
19
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
- t[p] = s[p];
21
- }
22
- return t;
23
- };
24
- return __assign.apply(this, arguments);
25
- };
26
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var _this = this;
62
- Object.defineProperty(exports, "__esModule", { value: true });
63
- var aws_1 = require("../aws");
64
- var utils_1 = require("../utils");
65
- var base_1 = require("./base");
66
- var logger = utils_1.getLogger(__filename);
67
- var initialize = function (aws, mapper) { return __awaiter(_this, void 0, void 0, function () {
68
- var env, mapping, successes;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
71
- case 0:
72
- env = process.env;
73
- mapping = mapper(aws, env);
74
- return [4 /*yield*/, Promise.all(Object.keys(mapping).map(function (name) { return mapping[name](); }))];
75
- case 1:
76
- successes = _a.sent();
77
- return [2 /*return*/, Object.keys(mapping).reduce(function (result, name, index) {
78
- var _a;
79
- return (__assign({}, result, (_a = {}, _a[name] = successes[index], _a)));
80
- }, {})];
81
- }
82
- });
83
- }); };
84
- var AWSPlugin = /** @class */ (function (_super) {
85
- __extends(AWSPlugin, _super);
86
- function AWSPlugin(options) {
87
- var _this = _super.call(this) || this;
88
- _this.create = function () { return __awaiter(_this, void 0, void 0, function () {
89
- var _a, config, mapper, _b;
90
- return __generator(this, function (_c) {
91
- switch (_c.label) {
92
- case 0:
93
- if (!!this.aws) return [3 /*break*/, 4];
94
- _a = this.options || {
95
- config: undefined,
96
- mapper: undefined,
97
- }, config = _a.config, mapper = _a.mapper;
98
- if (!config) return [3 /*break*/, 2];
99
- logger.debug("Load aws config from " + config);
100
- _b = this;
101
- return [4 /*yield*/, aws_1.loadAWSConfig(config)];
102
- case 1:
103
- _b.config = _c.sent();
104
- _c.label = 2;
105
- case 2:
106
- this.aws = new aws_1.SimpleAWS(this.config);
107
- if (!mapper) return [3 /*break*/, 4];
108
- logger.debug("Initialize aws components with mapper.");
109
- return [4 /*yield*/, initialize(this.aws, mapper)];
110
- case 3:
111
- _c.sent();
112
- _c.label = 4;
113
- case 4: return [2 /*return*/, {
114
- aws: this.aws,
115
- awsConfig: this.config,
116
- }];
117
- }
118
- });
119
- }); };
120
- _this.options = options;
121
- _this.config = new aws_1.SimpleAWSConfig();
122
- return _this;
123
- }
124
- return AWSPlugin;
125
- }(base_1.HandlerPluginBase));
126
- exports.AWSPlugin = AWSPlugin;
127
- var build = function (options) { return new AWSPlugin(options); };
128
- exports.default = build;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var _this = this;
62
+ Object.defineProperty(exports, "__esModule", { value: true });
63
+ var aws_1 = require("../aws");
64
+ var utils_1 = require("../utils");
65
+ var base_1 = require("./base");
66
+ var logger = utils_1.getLogger(__filename);
67
+ var initialize = function (aws, mapper) { return __awaiter(_this, void 0, void 0, function () {
68
+ var env, mapping, successes;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0:
72
+ env = process.env;
73
+ mapping = mapper(aws, env);
74
+ return [4 /*yield*/, Promise.all(Object.keys(mapping).map(function (name) { return mapping[name](); }))];
75
+ case 1:
76
+ successes = _a.sent();
77
+ return [2 /*return*/, Object.keys(mapping).reduce(function (result, name, index) {
78
+ var _a;
79
+ return (__assign({}, result, (_a = {}, _a[name] = successes[index], _a)));
80
+ }, {})];
81
+ }
82
+ });
83
+ }); };
84
+ var AWSPlugin = /** @class */ (function (_super) {
85
+ __extends(AWSPlugin, _super);
86
+ function AWSPlugin(options) {
87
+ var _this = _super.call(this) || this;
88
+ _this.create = function () { return __awaiter(_this, void 0, void 0, function () {
89
+ var _a, config, mapper, _b;
90
+ return __generator(this, function (_c) {
91
+ switch (_c.label) {
92
+ case 0:
93
+ if (!!this.aws) return [3 /*break*/, 4];
94
+ _a = this.options || {
95
+ config: undefined,
96
+ mapper: undefined,
97
+ }, config = _a.config, mapper = _a.mapper;
98
+ if (!config) return [3 /*break*/, 2];
99
+ logger.debug("Load aws config from " + config);
100
+ _b = this;
101
+ return [4 /*yield*/, aws_1.loadAWSConfig(config)];
102
+ case 1:
103
+ _b.config = _c.sent();
104
+ _c.label = 2;
105
+ case 2:
106
+ this.aws = new aws_1.SimpleAWS(this.config);
107
+ if (!mapper) return [3 /*break*/, 4];
108
+ logger.debug("Initialize aws components with mapper.");
109
+ return [4 /*yield*/, initialize(this.aws, mapper)];
110
+ case 3:
111
+ _c.sent();
112
+ _c.label = 4;
113
+ case 4: return [2 /*return*/, {
114
+ aws: this.aws,
115
+ awsConfig: this.config,
116
+ }];
117
+ }
118
+ });
119
+ }); };
120
+ _this.options = options;
121
+ _this.config = new aws_1.SimpleAWSConfig();
122
+ return _this;
123
+ }
124
+ return AWSPlugin;
125
+ }(base_1.HandlerPluginBase));
126
+ exports.AWSPlugin = AWSPlugin;
127
+ var build = function (options) { return new AWSPlugin(options); };
128
+ exports.default = build;
@@ -1,54 +1,54 @@
1
- import * as awsTypes from 'aws-lambda';
2
- export interface RequestAuxBase {
3
- [pluginName: string]: any;
4
- }
5
- export declare class HandlerRequest {
6
- event: awsTypes.APIGatewayEvent;
7
- context: awsTypes.APIGatewayEventRequestContext;
8
- lastError: Error | string | undefined;
9
- private lazyBody?;
10
- constructor(event: any, context: any);
11
- readonly body: any;
12
- readonly path: {
13
- [key: string]: string;
14
- };
15
- readonly query: {
16
- [key: string]: string;
17
- };
18
- header(key: string): string | undefined;
19
- records<T, U>(selector?: (each: T) => U): T[] | U[];
20
- }
21
- export declare class HandlerResponse {
22
- callback: any;
23
- completed: boolean;
24
- result: any | Promise<any> | undefined;
25
- private corsHeaders;
26
- private cookies;
27
- private crossOrigin?;
28
- constructor(callback: any);
29
- ok(body?: {}, code?: number): any;
30
- fail(body?: {}, code?: number): any;
31
- addCookie(key: string, value: string, domain?: string, specifyCrossOrigin?: true, path?: string): void;
32
- setCrossOrigin: (origin?: string | undefined) => void;
33
- }
34
- export interface HandlerAuxBase {
35
- [key: string]: any;
36
- }
37
- export interface HandlerContext<A extends HandlerAuxBase> {
38
- request: HandlerRequest;
39
- response: HandlerResponse;
40
- aux: A;
41
- }
42
- export declare type Handler<A extends HandlerAuxBase> = (context: HandlerContext<A>) => any | Promise<any> | undefined;
43
- export interface HandlerPlugin<A extends HandlerAuxBase> {
44
- create: () => Promise<A> | A;
45
- begin: Handler<A>;
46
- end: Handler<A>;
47
- error: Handler<A>;
48
- }
49
- export declare class HandlerPluginBase<A extends HandlerAuxBase> implements HandlerPlugin<A> {
50
- create: () => A | Promise<A>;
51
- begin: (_: HandlerContext<A>) => void;
52
- end: (_: HandlerContext<A>) => void;
53
- error: (_: HandlerContext<A>) => void;
54
- }
1
+ import * as awsTypes from 'aws-lambda';
2
+ export interface RequestAuxBase {
3
+ [pluginName: string]: any;
4
+ }
5
+ export declare class HandlerRequest {
6
+ event: awsTypes.APIGatewayEvent;
7
+ context: awsTypes.APIGatewayEventRequestContext;
8
+ lastError: Error | string | undefined;
9
+ private lazyBody?;
10
+ constructor(event: any, context: any);
11
+ readonly body: any;
12
+ readonly path: {
13
+ [key: string]: string;
14
+ };
15
+ readonly query: {
16
+ [key: string]: string;
17
+ };
18
+ header(key: string): string | undefined;
19
+ records<T, U>(selector?: (each: T) => U): T[] | U[];
20
+ }
21
+ export declare class HandlerResponse {
22
+ callback: any;
23
+ completed: boolean;
24
+ result: any | Promise<any> | undefined;
25
+ private corsHeaders;
26
+ private cookies;
27
+ private crossOrigin?;
28
+ constructor(callback: any);
29
+ ok(body?: {}, code?: number): any;
30
+ fail(body?: {}, code?: number): any;
31
+ addCookie(key: string, value: string, domain?: string, specifyCrossOrigin?: true, path?: string): void;
32
+ setCrossOrigin: (origin?: string | undefined) => void;
33
+ }
34
+ export interface HandlerAuxBase {
35
+ [key: string]: any;
36
+ }
37
+ export interface HandlerContext<A extends HandlerAuxBase> {
38
+ request: HandlerRequest;
39
+ response: HandlerResponse;
40
+ aux: A;
41
+ }
42
+ export declare type Handler<A extends HandlerAuxBase> = (context: HandlerContext<A>) => any | Promise<any> | undefined;
43
+ export interface HandlerPlugin<A extends HandlerAuxBase> {
44
+ create: () => Promise<A> | A;
45
+ begin: Handler<A>;
46
+ end: Handler<A>;
47
+ error: Handler<A>;
48
+ }
49
+ export declare class HandlerPluginBase<A extends HandlerAuxBase> implements HandlerPlugin<A> {
50
+ create: () => A | Promise<A>;
51
+ begin: (_: HandlerContext<A>) => void;
52
+ end: (_: HandlerContext<A>) => void;
53
+ error: (_: HandlerContext<A>) => void;
54
+ }