@aesop-fables/triginta 0.8.6 → 0.9.0
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/lib/AwsServices.d.ts +4 -0
- package/lib/AwsServices.js +9 -0
- package/lib/Bootstrapping.d.ts +4 -2
- package/lib/Bootstrapping.js +31 -4
- package/lib/EventSource.d.ts +1 -0
- package/lib/ITrigintaRuntime.d.ts +12 -0
- package/lib/ITrigintaRuntime.js +2 -0
- package/lib/ITrigintaRuntimeFactory.d.ts +17 -0
- package/lib/ITrigintaRuntimeFactory.js +61 -0
- package/lib/TrigintaMiddleware.d.ts +20 -0
- package/lib/TrigintaMiddleware.js +49 -0
- package/lib/TrigintaServices.d.ts +5 -0
- package/lib/TrigintaServices.js +9 -0
- package/lib/http/HttpLambda.js +9 -29
- package/lib/http/HttpLambdaServices.d.ts +1 -3
- package/lib/http/HttpLambdaServices.js +6 -6
- package/lib/index.d.ts +14 -8
- package/lib/index.js +14 -8
- package/lib/logging/Levels.js +2 -2
- package/lib/s3/S3Lambda.js +22 -16
- package/lib/s3/S3LambdaServices.d.ts +0 -1
- package/lib/s3/S3LambdaServices.js +0 -1
- package/lib/sqs/ISqsFailureHandler.d.ts +16 -0
- package/lib/sqs/ISqsFailureHandler.js +20 -0
- package/lib/sqs/ISqsMessageHandler.d.ts +3 -4
- package/lib/sqs/SqsLambda.d.ts +4 -4
- package/lib/sqs/SqsLambda.js +48 -32
- package/lib/sqs/SqsLambdaServices.d.ts +4 -5
- package/lib/sqs/SqsLambdaServices.js +4 -5
- package/lib/sqs/invokeSqsHandler.d.ts +2 -2
- package/lib/sqs/invokeSqsHandler.js +1 -1
- package/lib/validation/ValidationMiddleware.js +2 -1
- package/package.json +4 -4
- package/lib/http/IRequestContext.d.ts +0 -4
- /package/lib/{http/IRequestContext.js → EventSource.js} +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AwsServices = void 0;
|
|
4
|
+
const Utils_1 = require("./Utils");
|
|
5
|
+
const keyFor = (0, Utils_1.createServiceNamespacer)('aws');
|
|
6
|
+
exports.AwsServices = {
|
|
7
|
+
Context: keyFor('context'),
|
|
8
|
+
Event: keyFor('event'),
|
|
9
|
+
};
|
package/lib/Bootstrapping.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { BootstrappedHttpLambdaContext } from './http/HttpLambda';
|
|
|
4
4
|
import { BootstrappedSqsLambdaContext } from './sqs/SqsLambda';
|
|
5
5
|
import { BootstrappedS3LambdaContext } from './s3/S3Lambda';
|
|
6
6
|
declare type Placeholder = object;
|
|
7
|
-
interface
|
|
7
|
+
interface AwsServiceCollection {
|
|
8
8
|
http: Placeholder;
|
|
9
9
|
s3: Placeholder;
|
|
10
10
|
sqs: Placeholder;
|
|
11
11
|
}
|
|
12
12
|
declare type ConfiguredServices<T> = {
|
|
13
|
-
[Property in keyof
|
|
13
|
+
[Property in keyof AwsServiceCollection]: T;
|
|
14
14
|
};
|
|
15
15
|
interface BootstrappedTrigintaApp extends BootstrappedHttpLambdaContext, BootstrappedSqsLambdaContext, BootstrappedS3LambdaContext {
|
|
16
16
|
containers: ConfiguredServices<IServiceContainer>;
|
|
@@ -30,5 +30,7 @@ export interface TrigintaOptions {
|
|
|
30
30
|
s3?: TrigintaS3Options;
|
|
31
31
|
sqs?: TrigintaSqsOptions;
|
|
32
32
|
}
|
|
33
|
+
export declare const useTriginta: IServiceModule;
|
|
34
|
+
export declare const useAwsServices: IServiceModule;
|
|
33
35
|
export declare function createTrigintaApp(options: TrigintaOptions): BootstrappedTrigintaApp;
|
|
34
36
|
export {};
|
package/lib/Bootstrapping.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTrigintaApp = void 0;
|
|
3
|
+
exports.createTrigintaApp = exports.useAwsServices = exports.useTriginta = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
5
|
const containr_1 = require("@aesop-fables/containr");
|
|
5
6
|
const http_1 = require("./http");
|
|
6
7
|
const HttpLambda_1 = require("./http/HttpLambda");
|
|
@@ -8,6 +9,24 @@ const localization_1 = require("./localization");
|
|
|
8
9
|
const validation_1 = require("./validation");
|
|
9
10
|
const SqsLambda_1 = require("./sqs/SqsLambda");
|
|
10
11
|
const S3Lambda_1 = require("./s3/S3Lambda");
|
|
12
|
+
const TrigintaServices_1 = require("./TrigintaServices");
|
|
13
|
+
const ITrigintaRuntimeFactory_1 = require("./ITrigintaRuntimeFactory");
|
|
14
|
+
const AwsServices_1 = require("./AwsServices");
|
|
15
|
+
exports.useTriginta = (0, containr_1.createServiceModule)((0, TrigintaServices_1.createCoreKey)('bootstrap'), (services) => {
|
|
16
|
+
services.autoResolve(TrigintaServices_1.TrigintaServices.RuntimeFactory, ITrigintaRuntimeFactory_1.TrigintaRuntimeFactory, containr_1.Scopes.Transient);
|
|
17
|
+
});
|
|
18
|
+
// The individual middlewares setup the runtime in the child container
|
|
19
|
+
// We're registering this here so that the defaults are in place
|
|
20
|
+
exports.useAwsServices = (0, containr_1.createServiceModule)((0, TrigintaServices_1.createCoreKey)('bootstrap'), (services) => {
|
|
21
|
+
services.factory(AwsServices_1.AwsServices.Context, (container) => {
|
|
22
|
+
const runtime = container.get(TrigintaServices_1.TrigintaServices.Runtime);
|
|
23
|
+
return runtime.context;
|
|
24
|
+
}, containr_1.Scopes.Transient);
|
|
25
|
+
services.factory(AwsServices_1.AwsServices.Event, (container) => {
|
|
26
|
+
const runtime = container.get(TrigintaServices_1.TrigintaServices.Runtime);
|
|
27
|
+
return runtime.event;
|
|
28
|
+
}, containr_1.Scopes.Transient);
|
|
29
|
+
});
|
|
11
30
|
function createTrigintaApp(options) {
|
|
12
31
|
const containers = {};
|
|
13
32
|
Object.keys(options).forEach((key) => {
|
|
@@ -18,14 +37,22 @@ function createTrigintaApp(options) {
|
|
|
18
37
|
let container;
|
|
19
38
|
switch (serviceKey) {
|
|
20
39
|
case 'http':
|
|
21
|
-
container = (0, containr_1.createContainer)([
|
|
40
|
+
container = (0, containr_1.createContainer)([
|
|
41
|
+
exports.useTriginta,
|
|
42
|
+
exports.useAwsServices,
|
|
43
|
+
HttpLambda_1.useTrigintaHttp,
|
|
44
|
+
http_1.useHttpServices,
|
|
45
|
+
localization_1.useLocalization,
|
|
46
|
+
validation_1.useHttpValidation,
|
|
47
|
+
...modules,
|
|
48
|
+
]);
|
|
22
49
|
break;
|
|
23
50
|
case 's3':
|
|
24
|
-
container = (0, containr_1.createContainer)([S3Lambda_1.useTrigintaS3, ...modules]);
|
|
51
|
+
container = (0, containr_1.createContainer)([exports.useTriginta, exports.useAwsServices, S3Lambda_1.useTrigintaS3, ...modules]);
|
|
25
52
|
break;
|
|
26
53
|
case 'sqs':
|
|
27
54
|
const { matchers = [] } = serviceOptions;
|
|
28
|
-
container = (0, containr_1.createContainer)([(0, SqsLambda_1.useTrigintaSqs)({ matchers }), ...modules]);
|
|
55
|
+
container = (0, containr_1.createContainer)([exports.useTriginta, exports.useAwsServices, (0, SqsLambda_1.useTrigintaSqs)({ matchers }), ...modules]);
|
|
29
56
|
break;
|
|
30
57
|
}
|
|
31
58
|
if (container) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type EventSource = 'sqs' | 's3' | 'http';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Disposable, IServiceContainer } from '@aesop-fables/containr';
|
|
2
|
+
import { EventSource } from './EventSource';
|
|
3
|
+
import { APIGatewayEventRequestContextV2, APIGatewayProxyEventV2, Context, S3Event, SQSEvent } from 'aws-lambda';
|
|
4
|
+
export interface ITrigintaRuntime<TEvent, TContext> extends Disposable {
|
|
5
|
+
container: IServiceContainer;
|
|
6
|
+
context: TContext;
|
|
7
|
+
event: TEvent;
|
|
8
|
+
source: EventSource;
|
|
9
|
+
}
|
|
10
|
+
export declare type ITrigintaHttpRuntime = ITrigintaRuntime<APIGatewayProxyEventV2, APIGatewayEventRequestContextV2>;
|
|
11
|
+
export declare type ITrigintaS3Runtime = ITrigintaRuntime<S3Event, Context>;
|
|
12
|
+
export declare type ITrigintaSqsRuntime = ITrigintaRuntime<SQSEvent, Context>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import middy from '@middy/core';
|
|
2
|
+
import { Context } from 'aws-lambda';
|
|
3
|
+
import { ITrigintaRuntime } from './ITrigintaRuntime';
|
|
4
|
+
import { IServiceContainer, IServiceModule } from '@aesop-fables/containr';
|
|
5
|
+
import { EventSource } from './EventSource';
|
|
6
|
+
export interface TrigintaRuntimeOptions {
|
|
7
|
+
overrides: IServiceModule[];
|
|
8
|
+
source: EventSource;
|
|
9
|
+
}
|
|
10
|
+
export interface ITrigintaRuntimeFactory {
|
|
11
|
+
createRuntime<TEvent, TContext extends Context>(request: middy.Request<TEvent, any, Error, TContext>, options: TrigintaRuntimeOptions): Promise<ITrigintaRuntime<TEvent, TContext>>;
|
|
12
|
+
}
|
|
13
|
+
export declare class TrigintaRuntimeFactory implements ITrigintaRuntimeFactory {
|
|
14
|
+
private readonly container;
|
|
15
|
+
constructor(container: IServiceContainer);
|
|
16
|
+
createRuntime<TEvent, TContext extends Context>(request: middy.Request<TEvent, any, Error, TContext>, options: TrigintaRuntimeOptions): Promise<ITrigintaRuntime<TEvent, TContext>>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TrigintaRuntimeFactory = void 0;
|
|
25
|
+
const containr_1 = require("@aesop-fables/containr");
|
|
26
|
+
const Utils_1 = require("./Utils");
|
|
27
|
+
const TrigintaServices_1 = require("./TrigintaServices");
|
|
28
|
+
const namespacer = (0, Utils_1.createServiceNamespacer)('runtime');
|
|
29
|
+
const factoryModule = namespacer('factory');
|
|
30
|
+
function embedRuntime(runtime) {
|
|
31
|
+
return (0, containr_1.createServiceModule)(namespacer('embedRuntime'), (services) => {
|
|
32
|
+
services.singleton(TrigintaServices_1.TrigintaServices.Runtime, runtime);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
let TrigintaRuntimeFactory = class TrigintaRuntimeFactory {
|
|
36
|
+
constructor(container) {
|
|
37
|
+
this.container = container;
|
|
38
|
+
}
|
|
39
|
+
createRuntime(request, options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const { context, event } = request;
|
|
42
|
+
const runtime = {
|
|
43
|
+
context,
|
|
44
|
+
event,
|
|
45
|
+
source: options.source,
|
|
46
|
+
};
|
|
47
|
+
const overrides = [embedRuntime(runtime), ...options.overrides];
|
|
48
|
+
const container = this.container.createChildContainer(factoryModule, overrides);
|
|
49
|
+
runtime.container = container;
|
|
50
|
+
runtime.dispose = () => {
|
|
51
|
+
container === null || container === void 0 ? void 0 : container.dispose();
|
|
52
|
+
};
|
|
53
|
+
return runtime;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
TrigintaRuntimeFactory = __decorate([
|
|
58
|
+
__param(0, (0, containr_1.injectContainer)()),
|
|
59
|
+
__metadata("design:paramtypes", [Object])
|
|
60
|
+
], TrigintaRuntimeFactory);
|
|
61
|
+
exports.TrigintaRuntimeFactory = TrigintaRuntimeFactory;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IServiceContainer, IServiceModule } from '@aesop-fables/containr';
|
|
2
|
+
import middy from '@middy/core';
|
|
3
|
+
import { Context } from 'aws-lambda';
|
|
4
|
+
import { ITrigintaRuntime } from './ITrigintaRuntime';
|
|
5
|
+
import { EventSource } from './EventSource';
|
|
6
|
+
export interface TrigintaMiddlewareOptions {
|
|
7
|
+
container: IServiceContainer;
|
|
8
|
+
overrides: IServiceModule[];
|
|
9
|
+
source: EventSource;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveTrigintaRuntime<TEvent, TContext extends Context = Context>(context: TContext): ITrigintaRuntime<TEvent, TContext>;
|
|
12
|
+
export declare function trigintaMiddlware<TEvent, TContext extends Context = Context>(options: TrigintaMiddlewareOptions): {
|
|
13
|
+
after: middy.MiddlewareFn<TEvent, any, Error, TContext>;
|
|
14
|
+
before: middy.MiddlewareFn<TEvent, any, Error, TContext>;
|
|
15
|
+
};
|
|
16
|
+
interface MiddyHandler<TEvent, TContext extends Context = Context> {
|
|
17
|
+
(event: TEvent, context: TContext): Promise<any>;
|
|
18
|
+
}
|
|
19
|
+
export declare function trigintafy<TEvent, TContext extends Context = Context>(handler: MiddyHandler<TEvent, TContext>, middlewareMetadata: any[], options: TrigintaMiddlewareOptions): middy.MiddyfiedHandler<TEvent, any, Error, Context & TContext>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
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.trigintafy = exports.trigintaMiddlware = exports.resolveTrigintaRuntime = void 0;
|
|
16
|
+
const core_1 = __importDefault(require("@middy/core"));
|
|
17
|
+
const Utils_1 = require("./Utils");
|
|
18
|
+
const TrigintaServices_1 = require("./TrigintaServices");
|
|
19
|
+
const runtimeContextKey = (0, Utils_1.createServiceNamespacer)('runtime')('context');
|
|
20
|
+
function resolveTrigintaRuntime(context) {
|
|
21
|
+
return context[runtimeContextKey];
|
|
22
|
+
}
|
|
23
|
+
exports.resolveTrigintaRuntime = resolveTrigintaRuntime;
|
|
24
|
+
function trigintaMiddlware(options) {
|
|
25
|
+
const before = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const factory = options.container.get(TrigintaServices_1.TrigintaServices.RuntimeFactory);
|
|
27
|
+
const runtime = yield factory.createRuntime(request, {
|
|
28
|
+
overrides: options.overrides,
|
|
29
|
+
source: options.source,
|
|
30
|
+
});
|
|
31
|
+
const context = request.context;
|
|
32
|
+
context[runtimeContextKey] = runtime;
|
|
33
|
+
});
|
|
34
|
+
const after = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
36
|
+
(_a = resolveTrigintaRuntime(request.context)) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
37
|
+
});
|
|
38
|
+
return { after, before };
|
|
39
|
+
}
|
|
40
|
+
exports.trigintaMiddlware = trigintaMiddlware;
|
|
41
|
+
function trigintafy(handler, middlewareMetadata, options) {
|
|
42
|
+
let midHandler = (0, core_1.default)(handler).use(trigintaMiddlware(options));
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
44
|
+
middlewareMetadata.forEach((midFunc) => {
|
|
45
|
+
midHandler = midHandler.use(midFunc());
|
|
46
|
+
});
|
|
47
|
+
return midHandler;
|
|
48
|
+
}
|
|
49
|
+
exports.trigintafy = trigintafy;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrigintaServices = exports.createCoreKey = void 0;
|
|
4
|
+
const Utils_1 = require("./Utils");
|
|
5
|
+
exports.createCoreKey = (0, Utils_1.createServiceNamespacer)('core');
|
|
6
|
+
exports.TrigintaServices = {
|
|
7
|
+
Runtime: (0, exports.createCoreKey)('runtime'),
|
|
8
|
+
RuntimeFactory: (0, exports.createCoreKey)('runtimeFactory'),
|
|
9
|
+
};
|
package/lib/http/HttpLambda.js
CHANGED
|
@@ -20,18 +20,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
-
};
|
|
26
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
24
|
exports.createBootstrappedHttpLambdaContext = exports.useTrigintaHttp = exports.HttpLambdaFactory = exports.HttpResponseGenerator = void 0;
|
|
28
25
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
29
26
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
30
27
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
31
28
|
const containr_1 = require("@aesop-fables/containr");
|
|
32
|
-
const core_1 = __importDefault(require("@middy/core"));
|
|
33
29
|
const Decorators_1 = require("../Decorators");
|
|
34
30
|
const HttpLambdaServices_1 = require("./HttpLambdaServices");
|
|
31
|
+
const TrigintaMiddleware_1 = require("../TrigintaMiddleware");
|
|
35
32
|
const LoggingRegistry_1 = require("../logging/LoggingRegistry");
|
|
36
33
|
const Levels_1 = require("../logging/Levels");
|
|
37
34
|
let HttpResponseGenerator = class HttpResponseGenerator {
|
|
@@ -84,7 +81,7 @@ let HttpLambdaFactory = class HttpLambdaFactory {
|
|
|
84
81
|
throw new Error('No route found for the specified endpoint');
|
|
85
82
|
}
|
|
86
83
|
const handler = (event, context) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const childContainer = context
|
|
84
|
+
const childContainer = (0, TrigintaMiddleware_1.resolveTrigintaRuntime)(context).container;
|
|
88
85
|
if (!childContainer) {
|
|
89
86
|
throw new Error('No container found in the context');
|
|
90
87
|
}
|
|
@@ -104,32 +101,15 @@ let HttpLambdaFactory = class HttpLambdaFactory {
|
|
|
104
101
|
});
|
|
105
102
|
const { container } = this;
|
|
106
103
|
const middlewareMetadata = (_a = (0, Decorators_1.getMiddleware)(newable)) !== null && _a !== void 0 ? _a : [];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const injectContextualServices = (0, containr_1.createServiceModule)('injectContextualServices', (services) => {
|
|
111
|
-
services.singleton(HttpLambdaServices_1.HttpLambdaServices.CurrentRoute, route);
|
|
112
|
-
services.singleton(HttpLambdaServices_1.HttpLambdaServices.CurrentEvent, request.event);
|
|
113
|
-
services.singleton(HttpLambdaServices_1.HttpLambdaServices.CurrentContext, request.context);
|
|
114
|
-
services.factory(HttpLambdaServices_1.HttpLambdaServices.RequestContext, (current) => {
|
|
115
|
-
return {
|
|
116
|
-
container: current,
|
|
117
|
-
};
|
|
118
|
-
}, containr_1.Scopes.Transient);
|
|
119
|
-
});
|
|
120
|
-
const childContainer = container.createChildContainer('httpLambda', [injectContextualServices]);
|
|
121
|
-
request.context['container'] = childContainer;
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
after(request) {
|
|
125
|
-
var _a;
|
|
126
|
-
(_a = request.context['container']) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
127
|
-
},
|
|
104
|
+
const httpRuntimeOverrides = (0, containr_1.createServiceModule)('httpRuntimeOverrides', (services) => {
|
|
105
|
+
services.singleton(HttpLambdaServices_1.HttpLambdaServices.CurrentRoute, route);
|
|
106
|
+
// TODO -- Register the AwsServices
|
|
128
107
|
});
|
|
129
|
-
|
|
130
|
-
|
|
108
|
+
return (0, TrigintaMiddleware_1.trigintafy)(handler, middlewareMetadata, {
|
|
109
|
+
container,
|
|
110
|
+
source: 'http',
|
|
111
|
+
overrides: [httpRuntimeOverrides],
|
|
131
112
|
});
|
|
132
|
-
return midHandler;
|
|
133
113
|
}
|
|
134
114
|
};
|
|
135
115
|
HttpLambdaFactory = __decorate([
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpLambdaServices = void 0;
|
|
4
|
+
const Utils_1 = require("../Utils");
|
|
5
|
+
const keyFor = (0, Utils_1.createServiceNamespacer)('http');
|
|
4
6
|
exports.HttpLambdaServices = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
HttpResponseGenerator: 'HttpResponseGenerator',
|
|
10
|
-
RequestContext: 'requestContext',
|
|
7
|
+
CurrentRoute: keyFor('currentRoute'),
|
|
8
|
+
HttpLambdaFactory: keyFor('httpLambdaFactory'),
|
|
9
|
+
HttpResponseGenerator: keyFor('httpResponseGenerator'),
|
|
10
|
+
RuntimeContext: keyFor('runtimeContext'),
|
|
11
11
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
|
+
export { default as RouteRegistry, IRouteRegistry } from './RouteRegistry';
|
|
2
|
+
export * from './AwsServices';
|
|
1
3
|
export * from './Bootstrapping';
|
|
4
|
+
export * from './Decorators';
|
|
2
5
|
export * from './IHandler';
|
|
6
|
+
export * from './ITrigintaRuntime';
|
|
7
|
+
export * from './ITrigintaRuntimeFactory';
|
|
8
|
+
export * from './http/IConfiguredRoute';
|
|
3
9
|
export * from './http/IHttpEndpoint';
|
|
4
|
-
export * from './Decorators';
|
|
5
10
|
export * from './http/HttpLambda';
|
|
6
11
|
export * from './http/HttpLambdaServices';
|
|
7
|
-
export
|
|
12
|
+
export * from './resolveEnvironmentSettings';
|
|
13
|
+
export * from './s3/IS3RecordHandler';
|
|
14
|
+
export * from './s3/S3Lambda';
|
|
15
|
+
export * from './s3/S3LambdaServices';
|
|
8
16
|
export * from './sqs/SqsLambda';
|
|
9
17
|
export * from './sqs/SqsLambdaServices';
|
|
10
18
|
export * from './sqs/ISqsMessageHandler';
|
|
19
|
+
export * from './sqs/ISqsFailureHandler';
|
|
11
20
|
export * from './sqs/RecordMatchers';
|
|
12
21
|
export * from './sqs/ISqsMessage';
|
|
13
22
|
export * from './sqs/MessagePublisher';
|
|
14
23
|
export * from './sqs/SqsSettings';
|
|
15
24
|
export * from './sqs/IQueue';
|
|
16
25
|
export * from './sqs/SqsPublisher';
|
|
17
|
-
export * from './http/IConfiguredRoute';
|
|
18
26
|
export * from './TrigintaConfig';
|
|
19
|
-
export * from './resolveEnvironmentSettings';
|
|
20
27
|
export * from './TrigintaHeaders';
|
|
21
|
-
export * from './
|
|
22
|
-
export * from './
|
|
23
|
-
export * from './s3/S3LambdaServices';
|
|
28
|
+
export * from './TrigintaMiddleware';
|
|
29
|
+
export * from './TrigintaServices';
|
|
24
30
|
export * as Localization from './localization';
|
|
25
31
|
export * as Validation from './validation';
|
|
26
32
|
export * as Logging from './logging';
|
|
@@ -32,7 +38,7 @@ import * as s3Utils from './s3/invokeS3Handler';
|
|
|
32
38
|
*/
|
|
33
39
|
export declare const TestUtils: {
|
|
34
40
|
invokeS3Handler(context: s3Utils.S3InvocationContext): Promise<void>;
|
|
35
|
-
invokeSqsHandler(context: sqsUtils.SqsInvocationContext): Promise<
|
|
41
|
+
invokeSqsHandler(context: sqsUtils.SqsInvocationContext): Promise<import("aws-lambda").SQSBatchResponse>;
|
|
36
42
|
parseRouteParams(route: string, path: string): import("aws-lambda").APIGatewayProxyEventPathParameters;
|
|
37
43
|
parsePathParameters(context: httpUtils.EventGenerationContext): Partial<import("aws-lambda").APIGatewayProxyEventV2>;
|
|
38
44
|
createApiGatewayEvent(context: httpUtils.EventGenerationContext): Partial<import("aws-lambda").APIGatewayProxyEventV2>;
|
package/lib/index.js
CHANGED
|
@@ -30,30 +30,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.TestUtils = exports.Logging = exports.Validation = exports.Localization = exports.RouteRegistry = void 0;
|
|
33
|
+
var RouteRegistry_1 = require("./RouteRegistry");
|
|
34
|
+
Object.defineProperty(exports, "RouteRegistry", { enumerable: true, get: function () { return __importDefault(RouteRegistry_1).default; } });
|
|
35
|
+
__exportStar(require("./AwsServices"), exports);
|
|
33
36
|
__exportStar(require("./Bootstrapping"), exports);
|
|
37
|
+
__exportStar(require("./Decorators"), exports);
|
|
34
38
|
__exportStar(require("./IHandler"), exports);
|
|
39
|
+
__exportStar(require("./ITrigintaRuntime"), exports);
|
|
40
|
+
__exportStar(require("./ITrigintaRuntimeFactory"), exports);
|
|
41
|
+
__exportStar(require("./http/IConfiguredRoute"), exports);
|
|
35
42
|
__exportStar(require("./http/IHttpEndpoint"), exports);
|
|
36
|
-
__exportStar(require("./Decorators"), exports);
|
|
37
43
|
__exportStar(require("./http/HttpLambda"), exports);
|
|
38
44
|
__exportStar(require("./http/HttpLambdaServices"), exports);
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
__exportStar(require("./resolveEnvironmentSettings"), exports);
|
|
46
|
+
__exportStar(require("./s3/IS3RecordHandler"), exports);
|
|
47
|
+
__exportStar(require("./s3/S3Lambda"), exports);
|
|
48
|
+
__exportStar(require("./s3/S3LambdaServices"), exports);
|
|
41
49
|
__exportStar(require("./sqs/SqsLambda"), exports);
|
|
42
50
|
__exportStar(require("./sqs/SqsLambdaServices"), exports);
|
|
43
51
|
__exportStar(require("./sqs/ISqsMessageHandler"), exports);
|
|
52
|
+
__exportStar(require("./sqs/ISqsFailureHandler"), exports);
|
|
44
53
|
__exportStar(require("./sqs/RecordMatchers"), exports);
|
|
45
54
|
__exportStar(require("./sqs/ISqsMessage"), exports);
|
|
46
55
|
__exportStar(require("./sqs/MessagePublisher"), exports);
|
|
47
56
|
__exportStar(require("./sqs/SqsSettings"), exports);
|
|
48
57
|
__exportStar(require("./sqs/IQueue"), exports);
|
|
49
58
|
__exportStar(require("./sqs/SqsPublisher"), exports);
|
|
50
|
-
__exportStar(require("./http/IConfiguredRoute"), exports);
|
|
51
59
|
__exportStar(require("./TrigintaConfig"), exports);
|
|
52
|
-
__exportStar(require("./resolveEnvironmentSettings"), exports);
|
|
53
60
|
__exportStar(require("./TrigintaHeaders"), exports);
|
|
54
|
-
__exportStar(require("./
|
|
55
|
-
__exportStar(require("./
|
|
56
|
-
__exportStar(require("./s3/S3LambdaServices"), exports);
|
|
61
|
+
__exportStar(require("./TrigintaMiddleware"), exports);
|
|
62
|
+
__exportStar(require("./TrigintaServices"), exports);
|
|
57
63
|
exports.Localization = __importStar(require("./localization"));
|
|
58
64
|
exports.Validation = __importStar(require("./validation"));
|
|
59
65
|
exports.Logging = __importStar(require("./logging"));
|
package/lib/logging/Levels.js
CHANGED
|
@@ -14,9 +14,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CurrentRecordLoggingLevel = exports.CurrentRequestLoggingLevel = void 0;
|
|
16
16
|
const containr_1 = require("@aesop-fables/containr");
|
|
17
|
-
const HttpLambdaServices_1 = require("../http/HttpLambdaServices");
|
|
18
17
|
const SqsLambdaServices_1 = require("../sqs/SqsLambdaServices");
|
|
19
18
|
const TrigintaHeaders_1 = require("../TrigintaHeaders");
|
|
19
|
+
const AwsServices_1 = require("../AwsServices");
|
|
20
20
|
let CurrentRequestLoggingLevel = class CurrentRequestLoggingLevel {
|
|
21
21
|
constructor(event) {
|
|
22
22
|
this.event = event;
|
|
@@ -26,7 +26,7 @@ let CurrentRequestLoggingLevel = class CurrentRequestLoggingLevel {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
CurrentRequestLoggingLevel = __decorate([
|
|
29
|
-
__param(0, (0, containr_1.inject)(
|
|
29
|
+
__param(0, (0, containr_1.inject)(AwsServices_1.AwsServices.Event)),
|
|
30
30
|
__metadata("design:paramtypes", [Object])
|
|
31
31
|
], CurrentRequestLoggingLevel);
|
|
32
32
|
exports.CurrentRequestLoggingLevel = CurrentRequestLoggingLevel;
|
package/lib/s3/S3Lambda.js
CHANGED
|
@@ -20,21 +20,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
-
};
|
|
26
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
24
|
exports.createBootstrappedS3LambdaContext = exports.S3LambdaFactory = exports.useTrigintaS3 = void 0;
|
|
28
25
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
29
26
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
30
27
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
31
28
|
const containr_1 = require("@aesop-fables/containr");
|
|
32
|
-
const core_1 = __importDefault(require("@middy/core"));
|
|
33
29
|
const Decorators_1 = require("../Decorators");
|
|
34
30
|
const S3LambdaServices_1 = require("./S3LambdaServices");
|
|
31
|
+
const AwsServices_1 = require("../AwsServices");
|
|
32
|
+
const TrigintaMiddleware_1 = require("../TrigintaMiddleware");
|
|
35
33
|
function embedS3Event(event) {
|
|
36
34
|
return (0, containr_1.createServiceModule)('@aesop-fables/triginta/s3/event', (services) => {
|
|
37
|
-
services.singleton(
|
|
35
|
+
services.singleton(AwsServices_1.AwsServices.Event, event);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function embedS3Context(context) {
|
|
39
|
+
return (0, containr_1.createServiceModule)('@aesop-fables/triginta/s3/context', (services) => {
|
|
40
|
+
services.singleton(AwsServices_1.AwsServices.Context, context);
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
43
|
function embedS3Record(record) {
|
|
@@ -50,16 +53,22 @@ let S3LambdaFactory = class S3LambdaFactory {
|
|
|
50
53
|
this.container = container;
|
|
51
54
|
}
|
|
52
55
|
createHandler(newable) {
|
|
53
|
-
const handler = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const handler = (event, context) => __awaiter(this, void 0, void 0, function* () {
|
|
54
57
|
for (let i = 0; i < event.Records.length; i++) {
|
|
58
|
+
const { container } = (0, TrigintaMiddleware_1.resolveTrigintaRuntime)(context);
|
|
59
|
+
if (!container) {
|
|
60
|
+
throw new Error('No container found in the context');
|
|
61
|
+
}
|
|
55
62
|
const record = event.Records[i];
|
|
56
|
-
const childContainer =
|
|
63
|
+
const childContainer = container.createChildContainer('s3Lambda', [
|
|
57
64
|
embedS3Event(event),
|
|
58
65
|
embedS3Record(record),
|
|
66
|
+
embedS3Context(context),
|
|
59
67
|
]);
|
|
60
68
|
try {
|
|
61
69
|
const handler = childContainer.resolve(newable);
|
|
62
70
|
yield handler.handle(record, event);
|
|
71
|
+
// TODO -- Add the failure handler
|
|
63
72
|
}
|
|
64
73
|
finally {
|
|
65
74
|
if (childContainer) {
|
|
@@ -73,15 +82,12 @@ let S3LambdaFactory = class S3LambdaFactory {
|
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
});
|
|
76
|
-
const middlewareMetadata = (0, Decorators_1.getMiddleware)(newable);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return midHandler;
|
|
83
|
-
}
|
|
84
|
-
return handler;
|
|
85
|
+
const middlewareMetadata = (0, Decorators_1.getMiddleware)(newable) || [];
|
|
86
|
+
return (0, TrigintaMiddleware_1.trigintafy)(handler, middlewareMetadata, {
|
|
87
|
+
container: this.container,
|
|
88
|
+
source: 's3',
|
|
89
|
+
overrides: [],
|
|
90
|
+
});
|
|
85
91
|
}
|
|
86
92
|
};
|
|
87
93
|
S3LambdaFactory = __decorate([
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SQSRecord } from 'aws-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the logic used to handle a failed SQS record.
|
|
4
|
+
*/
|
|
5
|
+
export interface ISqsRecordFailureHandler {
|
|
6
|
+
/**
|
|
7
|
+
* Called when an error occurs during the processing an SQSEvent.
|
|
8
|
+
* @param record The record that caused the error
|
|
9
|
+
* @param error The error that occurred
|
|
10
|
+
* @returns Whether or not to report the error (true to report; false to suppress).
|
|
11
|
+
*/
|
|
12
|
+
onError(record: SQSRecord, error: any): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
export declare class SqsRecordFailureHandler implements ISqsRecordFailureHandler {
|
|
15
|
+
onError(): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SqsRecordFailureHandler = void 0;
|
|
13
|
+
class SqsRecordFailureHandler {
|
|
14
|
+
onError() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return true;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.SqsRecordFailureHandler = SqsRecordFailureHandler;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SQSEvent, SQSRecord } from 'aws-lambda';
|
|
2
2
|
import { ISqsMessage } from './ISqsMessage';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
handle(message: Message, record: SQSRecord, event: SQSEvent): Promise<Output>;
|
|
3
|
+
export interface ISqsMessageHandler<Message extends ISqsMessage> {
|
|
4
|
+
handle(message: Message, record: SQSRecord, event: SQSEvent): Promise<void>;
|
|
6
5
|
}
|
package/lib/sqs/SqsLambda.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { IServiceContainer, IServiceModule, Newable } from '@aesop-fables/containr';
|
|
2
2
|
import { SQSHandler } from 'aws-lambda';
|
|
3
|
-
import { ISqsMessageHandler
|
|
3
|
+
import { ISqsMessageHandler } from './ISqsMessageHandler';
|
|
4
4
|
import { ISqsMessage } from './ISqsMessage';
|
|
5
5
|
import { ISqsRecordMatcher } from './RecordMatchers';
|
|
6
6
|
export interface BootstrappedSqsLambdaContext {
|
|
7
|
-
createSqsHandler<Message extends ISqsMessage
|
|
7
|
+
createSqsHandler<Message extends ISqsMessage>(newable: Newable<ISqsMessageHandler<Message>>): SQSHandler;
|
|
8
8
|
}
|
|
9
9
|
export interface ISqsLambdaFactory {
|
|
10
|
-
createHandler<Message extends ISqsMessage
|
|
10
|
+
createHandler<Message extends ISqsMessage>(newable: Newable<ISqsMessageHandler<Message>>): SQSHandler;
|
|
11
11
|
}
|
|
12
12
|
export declare class SqsLambdaFactory implements ISqsLambdaFactory {
|
|
13
13
|
private readonly container;
|
|
14
14
|
constructor(container: IServiceContainer);
|
|
15
|
-
createHandler<Message extends ISqsMessage
|
|
15
|
+
createHandler<Message extends ISqsMessage>(newable: Newable<ISqsMessageHandler<Message>>): SQSHandler;
|
|
16
16
|
}
|
|
17
17
|
export interface TrigintaLegacySqsOptions {
|
|
18
18
|
matchers?: ISqsRecordMatcher[];
|
package/lib/sqs/SqsLambda.js
CHANGED
|
@@ -20,25 +20,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
-
};
|
|
26
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
24
|
exports.createBootstrappedSqsLambdaContext = exports.useTrigintaSqs = exports.SqsLambdaFactory = void 0;
|
|
28
25
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
29
26
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
30
27
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
31
28
|
const containr_1 = require("@aesop-fables/containr");
|
|
32
|
-
const core_1 = __importDefault(require("@middy/core"));
|
|
33
29
|
const Decorators_1 = require("../Decorators");
|
|
34
30
|
const SqsLambdaServices_1 = require("./SqsLambdaServices");
|
|
35
31
|
const RecordMatchers_1 = require("./RecordMatchers");
|
|
36
32
|
const SqsPublisher_1 = require("./SqsPublisher");
|
|
37
33
|
const MessagePublisher_1 = require("./MessagePublisher");
|
|
38
34
|
const logging_1 = require("../logging");
|
|
35
|
+
const AwsServices_1 = require("../AwsServices");
|
|
36
|
+
const TrigintaMiddleware_1 = require("../TrigintaMiddleware");
|
|
37
|
+
const ISqsFailureHandler_1 = require("./ISqsFailureHandler");
|
|
39
38
|
function embedSqsEvent(event) {
|
|
40
39
|
return (0, containr_1.createServiceModule)('@aesop-fables/triginta/sqs/event', (services) => {
|
|
41
|
-
services.singleton(
|
|
40
|
+
services.singleton(AwsServices_1.AwsServices.Event, event);
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
43
|
function embedSqsRecord(record) {
|
|
@@ -48,7 +47,7 @@ function embedSqsRecord(record) {
|
|
|
48
47
|
}
|
|
49
48
|
function embedSqsContext(context) {
|
|
50
49
|
return (0, containr_1.createServiceModule)('@aesop-fables/triginta/sqs/context', (services) => {
|
|
51
|
-
services.singleton(
|
|
50
|
+
services.singleton(AwsServices_1.AwsServices.Context, context);
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
53
|
let SqsLambdaFactory = class SqsLambdaFactory {
|
|
@@ -57,40 +56,56 @@ let SqsLambdaFactory = class SqsLambdaFactory {
|
|
|
57
56
|
}
|
|
58
57
|
createHandler(newable) {
|
|
59
58
|
const handler = (event, context) => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const response = {
|
|
60
|
+
batchItemFailures: [],
|
|
61
|
+
};
|
|
60
62
|
for (let i = 0; i < event.Records.length; i++) {
|
|
61
63
|
const record = event.Records[i];
|
|
62
|
-
const childContainer = this.container.createChildContainer('sqsLambda', [
|
|
63
|
-
embedSqsEvent(event),
|
|
64
|
-
embedSqsRecord(record),
|
|
65
|
-
embedSqsContext(context),
|
|
66
|
-
]);
|
|
67
64
|
try {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
const { container } = (0, TrigintaMiddleware_1.resolveTrigintaRuntime)(context);
|
|
66
|
+
if (!container) {
|
|
67
|
+
throw new Error('No container found in the context');
|
|
68
|
+
}
|
|
69
|
+
const childContainer = container.createChildContainer('sqsLambda', [
|
|
70
|
+
embedSqsEvent(event),
|
|
71
|
+
embedSqsRecord(record),
|
|
72
|
+
embedSqsContext(context),
|
|
73
|
+
]);
|
|
74
|
+
try {
|
|
75
|
+
const innerHandler = childContainer.resolve(newable);
|
|
76
|
+
const deserializer = childContainer.get(SqsLambdaServices_1.SqsLambdaServices.MessageDeserializer);
|
|
77
|
+
const message = yield deserializer.deserializeMessage(record);
|
|
78
|
+
yield innerHandler.handle(message, record, event);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
if (childContainer) {
|
|
82
|
+
try {
|
|
83
|
+
childContainer.dispose();
|
|
84
|
+
}
|
|
85
|
+
catch (_a) {
|
|
86
|
+
// no-op
|
|
87
|
+
}
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
90
|
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
const failureHandler = this.container.get(SqsLambdaServices_1.SqsLambdaServices.FailureHandler);
|
|
93
|
+
const shouldReport = yield failureHandler.onError(record, e);
|
|
94
|
+
if (shouldReport) {
|
|
95
|
+
response.batchItemFailures.push({
|
|
96
|
+
itemIdentifier: record.messageId,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
83
100
|
}
|
|
101
|
+
return response;
|
|
102
|
+
});
|
|
103
|
+
const middlewareMetadata = (0, Decorators_1.getMiddleware)(newable) || [];
|
|
104
|
+
return (0, TrigintaMiddleware_1.trigintafy)(handler, middlewareMetadata, {
|
|
105
|
+
container: this.container,
|
|
106
|
+
source: 'sqs',
|
|
107
|
+
overrides: [],
|
|
84
108
|
});
|
|
85
|
-
const middlewareMetadata = (0, Decorators_1.getMiddleware)(newable);
|
|
86
|
-
if (middlewareMetadata) {
|
|
87
|
-
let midHandler = (0, core_1.default)(handler);
|
|
88
|
-
middlewareMetadata.forEach((midFunc) => {
|
|
89
|
-
midHandler = midHandler.use(midFunc());
|
|
90
|
-
});
|
|
91
|
-
return midHandler;
|
|
92
|
-
}
|
|
93
|
-
return handler;
|
|
94
109
|
}
|
|
95
110
|
};
|
|
96
111
|
SqsLambdaFactory = __decorate([
|
|
@@ -108,6 +123,7 @@ exports.useTrigintaSqs = (0, containr_1.createServiceModuleWithOptions)('trigint
|
|
|
108
123
|
services.autoResolve(SqsLambdaServices_1.SqsLambdaServices.DefaultRecordMatcher, RecordMatchers_1.DefaultSqsRecordMatcher, containr_1.Scopes.Transient);
|
|
109
124
|
services.autoResolve(SqsLambdaServices_1.SqsLambdaServices.MessageDeserializer, RecordMatchers_1.SqsMessageDeserializer, containr_1.Scopes.Transient);
|
|
110
125
|
services.autoResolve(SqsLambdaServices_1.SqsLambdaServices.SqsPublisher, SqsPublisher_1.SqsPublisher, containr_1.Scopes.Transient);
|
|
126
|
+
services.autoResolve(SqsLambdaServices_1.SqsLambdaServices.FailureHandler, ISqsFailureHandler_1.SqsRecordFailureHandler, containr_1.Scopes.Transient);
|
|
111
127
|
services.autoResolve(SqsLambdaServices_1.SqsLambdaServices.MessagePublisher, MessagePublisher_1.MessagePublisher, containr_1.Scopes.Transient);
|
|
112
128
|
services.include(new logging_1.LoggingRegistry(logging_1.CurrentRecordLoggingLevel));
|
|
113
129
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export declare const SqsLambdaServices: {
|
|
2
|
-
|
|
2
|
+
CurrentRecord: string;
|
|
3
3
|
DefaultRecordMatcher: string;
|
|
4
|
+
FailureHandler: string;
|
|
4
5
|
MessageDeserializer: string;
|
|
5
|
-
RecordMatchers: string;
|
|
6
6
|
MessagePublisher: string;
|
|
7
|
+
RecordMatchers: string;
|
|
8
|
+
SqsLambdaFactory: string;
|
|
7
9
|
SqsPublisher: string;
|
|
8
10
|
SqsSettings: string;
|
|
9
|
-
CurrentContext: string;
|
|
10
|
-
CurrentEvent: string;
|
|
11
|
-
CurrentRecord: string;
|
|
12
11
|
};
|
|
@@ -4,14 +4,13 @@ exports.SqsLambdaServices = void 0;
|
|
|
4
4
|
const Utils_1 = require("../Utils");
|
|
5
5
|
const namedService = (0, Utils_1.createServiceNamespacer)('sqs');
|
|
6
6
|
exports.SqsLambdaServices = {
|
|
7
|
-
|
|
7
|
+
CurrentRecord: namedService('SqsCurrentRecord'),
|
|
8
8
|
DefaultRecordMatcher: namedService('DefaultRecordMatcher'),
|
|
9
|
+
FailureHandler: namedService('FailureHandler'),
|
|
9
10
|
MessageDeserializer: namedService('MessageDeserializer'),
|
|
10
|
-
RecordMatchers: namedService('RecordMatchers'),
|
|
11
11
|
MessagePublisher: namedService('MessagePublisher'),
|
|
12
|
+
RecordMatchers: namedService('RecordMatchers'),
|
|
13
|
+
SqsLambdaFactory: namedService('SqsLambdaFactory'),
|
|
12
14
|
SqsPublisher: namedService('SqsPublisher'),
|
|
13
15
|
SqsSettings: namedService('SqsSettings'),
|
|
14
|
-
CurrentContext: namedService('SqsCurrentContext'),
|
|
15
|
-
CurrentEvent: namedService('SqsCurrentEvent'),
|
|
16
|
-
CurrentRecord: namedService('SqsCurrentRecord'),
|
|
17
16
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SQSEvent } from 'aws-lambda';
|
|
1
|
+
import { SQSBatchResponse, SQSEvent } from 'aws-lambda';
|
|
2
2
|
import { IServiceContainer } from '@aesop-fables/containr';
|
|
3
3
|
export interface SqsInvocationContext extends Partial<SQSEvent> {
|
|
4
4
|
handler: Function;
|
|
@@ -9,4 +9,4 @@ export interface SqsInvocationContext extends Partial<SQSEvent> {
|
|
|
9
9
|
* @param context
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare function invokeSqsHandler(context: SqsInvocationContext): Promise<
|
|
12
|
+
export declare function invokeSqsHandler(context: SqsInvocationContext): Promise<SQSBatchResponse>;
|
|
@@ -50,7 +50,7 @@ function invokeSqsHandler(context) {
|
|
|
50
50
|
throw new Error('Function not implemented.');
|
|
51
51
|
},
|
|
52
52
|
};
|
|
53
|
-
const response = yield configuredHandler(event, handlerContext);
|
|
53
|
+
const response = (yield configuredHandler(event, handlerContext));
|
|
54
54
|
return response;
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -11,12 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.validate = void 0;
|
|
13
13
|
const ValidationServices_1 = require("./ValidationServices");
|
|
14
|
+
const TrigintaMiddleware_1 = require("../TrigintaMiddleware");
|
|
14
15
|
function validate(rules) {
|
|
15
16
|
return () => {
|
|
16
17
|
return {
|
|
17
18
|
before(request) {
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const container = request.context
|
|
20
|
+
const { container } = (0, TrigintaMiddleware_1.resolveTrigintaRuntime)(request.context);
|
|
20
21
|
const validator = container.get(ValidationServices_1.ValidationServices.ValidatorFactory).create(rules);
|
|
21
22
|
const failureHandler = container.get(ValidationServices_1.ValidationServices.ValidationFailureHandler);
|
|
22
23
|
const model = request.event.body;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aesop-fables/triginta",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A lightweight framework that wraps the basic infrastructure usages of AWS Lambda (SQS, Kinesis, etc.).",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"exports": {
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "^5.59.11",
|
|
37
37
|
"@typescript-eslint/parser": "5.59.11",
|
|
38
38
|
"aws-sdk": "^2.1386.0",
|
|
39
|
-
"esbuild": "^0.
|
|
39
|
+
"esbuild": "^0.18.16",
|
|
40
40
|
"eslint": "8.42.0",
|
|
41
41
|
"eslint-config-prettier": "^8.5.0",
|
|
42
|
-
"eslint-plugin-jest": "27.2.
|
|
42
|
+
"eslint-plugin-jest": "27.2.3",
|
|
43
43
|
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
-
"jest": "29.
|
|
44
|
+
"jest": "29.6.1",
|
|
45
45
|
"jest-mock-extended": "^3.0.1",
|
|
46
46
|
"prettier": "^2.8.1",
|
|
47
47
|
"reflect-metadata": "^0.1.13",
|
|
File without changes
|