@aesop-fables/triginta 0.1.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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -0
  3. package/lib/AwsServices.d.ts +4 -0
  4. package/lib/AwsServices.js +9 -0
  5. package/lib/Bootstrapping.d.ts +36 -0
  6. package/lib/Bootstrapping.js +64 -0
  7. package/lib/Decorators.d.ts +14 -0
  8. package/lib/Decorators.js +53 -0
  9. package/lib/EventSource.d.ts +1 -0
  10. package/lib/EventSource.js +2 -0
  11. package/lib/IHandler.d.ts +6 -0
  12. package/lib/IHandler.js +3 -0
  13. package/lib/ITrigintaRuntime.d.ts +12 -0
  14. package/lib/ITrigintaRuntime.js +2 -0
  15. package/lib/ITrigintaRuntimeFactory.d.ts +17 -0
  16. package/lib/ITrigintaRuntimeFactory.js +61 -0
  17. package/lib/RouteRegistry.d.ts +12 -0
  18. package/lib/RouteRegistry.js +14 -0
  19. package/lib/TrigintaConfig.d.ts +6 -0
  20. package/lib/TrigintaConfig.js +2 -0
  21. package/lib/TrigintaHeaders.d.ts +3 -0
  22. package/lib/TrigintaHeaders.js +6 -0
  23. package/lib/TrigintaMiddleware.d.ts +20 -0
  24. package/lib/TrigintaMiddleware.js +49 -0
  25. package/lib/TrigintaServices.d.ts +5 -0
  26. package/lib/TrigintaServices.js +9 -0
  27. package/lib/Utils.d.ts +1 -0
  28. package/lib/Utils.js +9 -0
  29. package/lib/http/HttpCultureContext.d.ts +7 -0
  30. package/lib/http/HttpCultureContext.js +17 -0
  31. package/lib/http/HttpLambda.d.ts +29 -0
  32. package/lib/http/HttpLambda.js +144 -0
  33. package/lib/http/HttpLambdaServices.d.ts +6 -0
  34. package/lib/http/HttpLambdaServices.js +11 -0
  35. package/lib/http/IConfiguredRoute.d.ts +6 -0
  36. package/lib/http/IConfiguredRoute.js +2 -0
  37. package/lib/http/IHttpEndpoint.d.ts +6 -0
  38. package/lib/http/IHttpEndpoint.js +2 -0
  39. package/lib/http/index.d.ts +1 -0
  40. package/lib/http/index.js +9 -0
  41. package/lib/http/invokeHttpHandler.d.ts +21 -0
  42. package/lib/http/invokeHttpHandler.js +160 -0
  43. package/lib/index.d.ts +46 -0
  44. package/lib/index.js +72 -0
  45. package/lib/localization/ICultureContext.d.ts +3 -0
  46. package/lib/localization/ICultureContext.js +2 -0
  47. package/lib/localization/ILocalizationStorage.d.ts +6 -0
  48. package/lib/localization/ILocalizationStorage.js +2 -0
  49. package/lib/localization/IStringLocalizer.d.ts +4 -0
  50. package/lib/localization/IStringLocalizer.js +2 -0
  51. package/lib/localization/LocalizationServices.d.ts +5 -0
  52. package/lib/localization/LocalizationServices.js +8 -0
  53. package/lib/localization/LocalizationStorage.d.ts +4 -0
  54. package/lib/localization/LocalizationStorage.js +10 -0
  55. package/lib/localization/LocalizedString.d.ts +4 -0
  56. package/lib/localization/LocalizedString.js +2 -0
  57. package/lib/localization/StringLocalizer.d.ts +10 -0
  58. package/lib/localization/StringLocalizer.js +16 -0
  59. package/lib/localization/index.d.ts +8 -0
  60. package/lib/localization/index.js +32 -0
  61. package/lib/logging/ConsoleLogger.d.ts +10 -0
  62. package/lib/logging/ConsoleLogger.js +38 -0
  63. package/lib/logging/ILogger.d.ts +12 -0
  64. package/lib/logging/ILogger.js +18 -0
  65. package/lib/logging/ILoggerFactory.d.ts +7 -0
  66. package/lib/logging/ILoggerFactory.js +2 -0
  67. package/lib/logging/Levels.d.ts +14 -0
  68. package/lib/logging/Levels.js +46 -0
  69. package/lib/logging/LoggerFactory.d.ts +8 -0
  70. package/lib/logging/LoggerFactory.js +36 -0
  71. package/lib/logging/LoggingRegistry.d.ts +7 -0
  72. package/lib/logging/LoggingRegistry.js +22 -0
  73. package/lib/logging/LoggingServices.d.ts +5 -0
  74. package/lib/logging/LoggingServices.js +10 -0
  75. package/lib/logging/index.d.ts +7 -0
  76. package/lib/logging/index.js +23 -0
  77. package/lib/resolveEnvironmentSettings.d.ts +17 -0
  78. package/lib/resolveEnvironmentSettings.js +17 -0
  79. package/lib/s3/IS3RecordHandler.d.ts +4 -0
  80. package/lib/s3/IS3RecordHandler.js +2 -0
  81. package/lib/s3/S3Lambda.d.ts +16 -0
  82. package/lib/s3/S3Lambda.js +109 -0
  83. package/lib/s3/S3LambdaServices.d.ts +4 -0
  84. package/lib/s3/S3LambdaServices.js +9 -0
  85. package/lib/s3/invokeS3Handler.d.ts +12 -0
  86. package/lib/s3/invokeS3Handler.js +57 -0
  87. package/lib/sqs/IQueue.d.ts +8 -0
  88. package/lib/sqs/IQueue.js +16 -0
  89. package/lib/sqs/ISqsFailureHandler.d.ts +16 -0
  90. package/lib/sqs/ISqsFailureHandler.js +20 -0
  91. package/lib/sqs/ISqsMessage.d.ts +20 -0
  92. package/lib/sqs/ISqsMessage.js +36 -0
  93. package/lib/sqs/ISqsMessageHandler.d.ts +5 -0
  94. package/lib/sqs/ISqsMessageHandler.js +2 -0
  95. package/lib/sqs/MessagePublisher.d.ts +17 -0
  96. package/lib/sqs/MessagePublisher.js +70 -0
  97. package/lib/sqs/RecordMatchers.d.ts +31 -0
  98. package/lib/sqs/RecordMatchers.js +113 -0
  99. package/lib/sqs/SqsLambda.d.ts +25 -0
  100. package/lib/sqs/SqsLambda.js +146 -0
  101. package/lib/sqs/SqsLambdaServices.d.ts +11 -0
  102. package/lib/sqs/SqsLambdaServices.js +16 -0
  103. package/lib/sqs/SqsPublisher.d.ts +13 -0
  104. package/lib/sqs/SqsPublisher.js +55 -0
  105. package/lib/sqs/SqsSettings.d.ts +2 -0
  106. package/lib/sqs/SqsSettings.js +2 -0
  107. package/lib/sqs/invokeSqsHandler.d.ts +12 -0
  108. package/lib/sqs/invokeSqsHandler.js +57 -0
  109. package/lib/validation/ArrayContinuationRule.d.ts +9 -0
  110. package/lib/validation/ArrayContinuationRule.js +38 -0
  111. package/lib/validation/IConfiguredValidationRule.d.ts +5 -0
  112. package/lib/validation/IConfiguredValidationRule.js +2 -0
  113. package/lib/validation/IValidationFailureHandler.d.ts +15 -0
  114. package/lib/validation/IValidationFailureHandler.js +30 -0
  115. package/lib/validation/IValidationRule.d.ts +4 -0
  116. package/lib/validation/IValidationRule.js +2 -0
  117. package/lib/validation/IValidator.d.ts +4 -0
  118. package/lib/validation/IValidator.js +2 -0
  119. package/lib/validation/IValidatorFactory.d.ts +5 -0
  120. package/lib/validation/IValidatorFactory.js +2 -0
  121. package/lib/validation/RequiredRule.d.ts +5 -0
  122. package/lib/validation/RequiredRule.js +23 -0
  123. package/lib/validation/RuleParser.d.ts +11 -0
  124. package/lib/validation/RuleParser.js +36 -0
  125. package/lib/validation/ValidationContext.d.ts +19 -0
  126. package/lib/validation/ValidationContext.js +35 -0
  127. package/lib/validation/ValidationError.d.ts +4 -0
  128. package/lib/validation/ValidationError.js +11 -0
  129. package/lib/validation/ValidationKeys.d.ts +4 -0
  130. package/lib/validation/ValidationKeys.js +6 -0
  131. package/lib/validation/ValidationMessage.d.ts +7 -0
  132. package/lib/validation/ValidationMessage.js +13 -0
  133. package/lib/validation/ValidationMiddleware.d.ts +4 -0
  134. package/lib/validation/ValidationMiddleware.js +35 -0
  135. package/lib/validation/ValidationNotification.d.ts +22 -0
  136. package/lib/validation/ValidationNotification.js +86 -0
  137. package/lib/validation/ValidationServices.d.ts +5 -0
  138. package/lib/validation/ValidationServices.js +8 -0
  139. package/lib/validation/Validator.d.ts +12 -0
  140. package/lib/validation/Validator.js +46 -0
  141. package/lib/validation/ValidatorFactory.d.ts +9 -0
  142. package/lib/validation/ValidatorFactory.js +30 -0
  143. package/lib/validation/index.d.ts +17 -0
  144. package/lib/validation/index.js +43 -0
  145. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Aesop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @aesop-fables/triginta
2
+
3
+ `triginta` is a lightweight framework that wraps the basic infrastructure usages of AWS Lambda (SQS, Kinesis, etc.) and is entirely based on top of Middyjs.
4
+
5
+ ## Installation
6
+ ```
7
+ npm install @aesop-fables/triginta
8
+ ```
9
+ ```
10
+ yarn add @aesop-fables/triginta
11
+ ```
12
+
13
+ ## Docs
14
+
15
+ Docs are coming. In the meantime, we recommend you checkout the docs from middyjs and our example repo:
16
+ https://github.com/aesop-fables/triginta-example
17
+
18
+
19
+ ## Breaking Changes
20
+
21
+ ### v0.4.0
22
+
23
+ The `path` property of the `InvocationContext` (used in `invokeHttpHandler`) was renamed to `rawPath` to properly match the
24
+ expected API Gateway Event.
@@ -0,0 +1,4 @@
1
+ export declare const AwsServices: {
2
+ Context: string;
3
+ Event: string;
4
+ };
@@ -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
+ };
@@ -0,0 +1,36 @@
1
+ import { IServiceContainer, IServiceModule } from '@aesop-fables/containr';
2
+ import { ISqsRecordMatcher } from './sqs/RecordMatchers';
3
+ import { BootstrappedHttpLambdaContext } from './http/HttpLambda';
4
+ import { BootstrappedSqsLambdaContext } from './sqs/SqsLambda';
5
+ import { BootstrappedS3LambdaContext } from './s3/S3Lambda';
6
+ declare type Placeholder = object;
7
+ interface AwsServiceCollection {
8
+ http: Placeholder;
9
+ s3: Placeholder;
10
+ sqs: Placeholder;
11
+ }
12
+ declare type ConfiguredServices<T> = {
13
+ [Property in keyof AwsServiceCollection]: T;
14
+ };
15
+ interface BootstrappedTrigintaApp extends BootstrappedHttpLambdaContext, BootstrappedSqsLambdaContext, BootstrappedS3LambdaContext {
16
+ containers: ConfiguredServices<IServiceContainer>;
17
+ }
18
+ export interface AwsServiceOptions {
19
+ modules: IServiceModule[];
20
+ }
21
+ export interface TrigintaHttpOptions extends AwsServiceOptions {
22
+ }
23
+ export interface TrigintaS3Options extends AwsServiceOptions {
24
+ }
25
+ export interface TrigintaSqsOptions extends AwsServiceOptions {
26
+ matchers?: ISqsRecordMatcher[];
27
+ }
28
+ export interface TrigintaOptions {
29
+ http?: TrigintaHttpOptions;
30
+ s3?: TrigintaS3Options;
31
+ sqs?: TrigintaSqsOptions;
32
+ }
33
+ export declare const useTriginta: IServiceModule;
34
+ export declare const useAwsServices: IServiceModule;
35
+ export declare function createTrigintaApp(options: TrigintaOptions): BootstrappedTrigintaApp;
36
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTrigintaApp = exports.useAwsServices = exports.useTriginta = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const containr_1 = require("@aesop-fables/containr");
6
+ const http_1 = require("./http");
7
+ const HttpLambda_1 = require("./http/HttpLambda");
8
+ const localization_1 = require("./localization");
9
+ const validation_1 = require("./validation");
10
+ const SqsLambda_1 = require("./sqs/SqsLambda");
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
+ });
30
+ function createTrigintaApp(options) {
31
+ const containers = {};
32
+ Object.keys(options).forEach((key) => {
33
+ var _a, _b;
34
+ const serviceKey = key;
35
+ const serviceOptions = (_a = options[key]) !== null && _a !== void 0 ? _a : {};
36
+ const { modules = [] } = (_b = options[key]) !== null && _b !== void 0 ? _b : {};
37
+ let container;
38
+ switch (serviceKey) {
39
+ case 'http':
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
+ ]);
49
+ break;
50
+ case 's3':
51
+ container = (0, containr_1.createContainer)([exports.useTriginta, exports.useAwsServices, S3Lambda_1.useTrigintaS3, ...modules]);
52
+ break;
53
+ case 'sqs':
54
+ const { matchers = [] } = serviceOptions;
55
+ container = (0, containr_1.createContainer)([exports.useTriginta, exports.useAwsServices, (0, SqsLambda_1.useTrigintaSqs)({ matchers }), ...modules]);
56
+ break;
57
+ }
58
+ if (container) {
59
+ containers[serviceKey] = container;
60
+ }
61
+ });
62
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, (0, HttpLambda_1.createBootstrappedHttpLambdaContext)(containers.http)), (0, SqsLambda_1.createBootstrappedSqsLambdaContext)(containers.sqs)), (0, S3Lambda_1.createBootstrappedS3LambdaContext)(containers.s3)), { containers });
63
+ }
64
+ exports.createTrigintaApp = createTrigintaApp;
@@ -0,0 +1,14 @@
1
+ import { IConfiguredRoute } from './http/IConfiguredRoute';
2
+ export declare const endpointMetadataKey: unique symbol;
3
+ export declare function getRoute(target: Function): IConfiguredRoute | undefined;
4
+ export declare function httpGet(route: string): (target: Object) => void;
5
+ export declare function httpPut(route: string): (target: Object) => void;
6
+ export declare function httpDelete(route: string): (target: Object) => void;
7
+ export declare function httpPost(route: string): (target: Object) => void;
8
+ /**
9
+ * This is exposed internally for testing.
10
+ * There shouldn't be a need to export this publicly
11
+ */
12
+ export declare const middlewareMetadataKey: unique symbol;
13
+ export declare function useMiddleware(...args: any[]): (target: Object) => void;
14
+ export declare function getMiddleware(target: any): any[] | undefined;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getMiddleware = exports.useMiddleware = exports.middlewareMetadataKey = exports.httpPost = exports.httpDelete = exports.httpPut = exports.httpGet = exports.getRoute = exports.endpointMetadataKey = void 0;
7
+ const RouteRegistry_1 = __importDefault(require("./RouteRegistry"));
8
+ /* eslint-disable @typescript-eslint/ban-types */
9
+ exports.endpointMetadataKey = Symbol('@endpointMetadataKey');
10
+ function defineEndpointMetadata(method, route) {
11
+ return (target) => {
12
+ const params = { method, route, constructor: target };
13
+ Reflect.defineMetadata(exports.endpointMetadataKey, params, target);
14
+ RouteRegistry_1.default.register(params);
15
+ };
16
+ }
17
+ function getRoute(target) {
18
+ return Reflect.getMetadata(exports.endpointMetadataKey, target);
19
+ }
20
+ exports.getRoute = getRoute;
21
+ function httpGet(route) {
22
+ return defineEndpointMetadata('get', route);
23
+ }
24
+ exports.httpGet = httpGet;
25
+ function httpPut(route) {
26
+ return defineEndpointMetadata('put', route);
27
+ }
28
+ exports.httpPut = httpPut;
29
+ function httpDelete(route) {
30
+ return defineEndpointMetadata('delete', route);
31
+ }
32
+ exports.httpDelete = httpDelete;
33
+ function httpPost(route) {
34
+ return defineEndpointMetadata('post', route);
35
+ }
36
+ exports.httpPost = httpPost;
37
+ /**
38
+ * This is exposed internally for testing.
39
+ * There shouldn't be a need to export this publicly
40
+ */
41
+ exports.middlewareMetadataKey = Symbol('@middlewareMetadataKey');
42
+ function useMiddleware(...args) {
43
+ return (target) => {
44
+ let params = Reflect.getMetadata(exports.middlewareMetadataKey, target) || [];
45
+ params = params.concat(args);
46
+ Reflect.defineMetadata(exports.middlewareMetadataKey, params, target);
47
+ };
48
+ }
49
+ exports.useMiddleware = useMiddleware;
50
+ function getMiddleware(target) {
51
+ return Reflect.getMetadata(exports.middlewareMetadataKey, target);
52
+ }
53
+ exports.getMiddleware = getMiddleware;
@@ -0,0 +1 @@
1
+ export declare type EventSource = 'sqs' | 's3' | 'http';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface IEventHandler<Event = any, Return = void> {
2
+ handle(event: Event): Promise<Return>;
3
+ }
4
+ export interface IMessageHandler<Message, Event = any, Return = void> {
5
+ handle(message: Message, event: Event): Promise<Return>;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,12 @@
1
+ import { IConfiguredRoute } from './http/IConfiguredRoute';
2
+ export interface IRouteRegistry {
3
+ allRoutes(): IConfiguredRoute[];
4
+ register(route: IConfiguredRoute): void;
5
+ }
6
+ declare class RouteRegistry implements IRouteRegistry {
7
+ private readonly routes;
8
+ allRoutes(): IConfiguredRoute[];
9
+ register(route: IConfiguredRoute): void;
10
+ }
11
+ declare const _default: RouteRegistry;
12
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class RouteRegistry {
4
+ constructor() {
5
+ this.routes = [];
6
+ }
7
+ allRoutes() {
8
+ return this.routes;
9
+ }
10
+ register(route) {
11
+ this.routes.push(route);
12
+ }
13
+ }
14
+ exports.default = new RouteRegistry();
@@ -0,0 +1,6 @@
1
+ import { IServiceContainer } from '@aesop-fables/containr';
2
+ import { IRouteRegistry } from './RouteRegistry';
3
+ export declare type TrigintaConfig = {
4
+ container: IServiceContainer;
5
+ routes: IRouteRegistry;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare const TrigintaHeaders: {
2
+ LogLevel: string;
3
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrigintaHeaders = void 0;
4
+ exports.TrigintaHeaders = {
5
+ LogLevel: 'X-Log-Level',
6
+ };
@@ -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,5 @@
1
+ export declare const createCoreKey: (key: string) => string;
2
+ export declare const TrigintaServices: {
3
+ Runtime: string;
4
+ RuntimeFactory: string;
5
+ };
@@ -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/Utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function createServiceNamespacer(prefix: string): (key: string) => string;
package/lib/Utils.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createServiceNamespacer = void 0;
4
+ function createServiceNamespacer(prefix) {
5
+ return (key) => {
6
+ return `@aesop-fables/triginta/${prefix}/${key}`;
7
+ };
8
+ }
9
+ exports.createServiceNamespacer = createServiceNamespacer;
@@ -0,0 +1,7 @@
1
+ import { APIGatewayProxyEventV2 } from 'aws-lambda';
2
+ import { ICultureContext } from '../localization/ICultureContext';
3
+ export declare class HttpCultureContext implements ICultureContext {
4
+ private readonly event;
5
+ constructor(event: APIGatewayProxyEventV2);
6
+ detectCulture(): string;
7
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpCultureContext = void 0;
4
+ class HttpCultureContext {
5
+ constructor(event) {
6
+ this.event = event;
7
+ }
8
+ detectCulture() {
9
+ var _a;
10
+ const defaultCulture = 'en-US';
11
+ if (this.event.headers) {
12
+ return (_a = this.event.headers['Accept-Language']) !== null && _a !== void 0 ? _a : defaultCulture;
13
+ }
14
+ return defaultCulture;
15
+ }
16
+ }
17
+ exports.HttpCultureContext = HttpCultureContext;
@@ -0,0 +1,29 @@
1
+ import { IServiceContainer, Newable } from '@aesop-fables/containr';
2
+ import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2, Handler } from 'aws-lambda';
3
+ import { IHttpEndpoint, IHttpEventHandler } from './IHttpEndpoint';
4
+ import { IConfiguredRoute } from './IConfiguredRoute';
5
+ export declare type NonNoisyEvent = Omit<APIGatewayProxyEventV2, 'requestContext'>;
6
+ export interface BootstrappedHttpLambdaContext {
7
+ createHttpEventHandler<Output>(newable: Newable<IHttpEventHandler<Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
8
+ createHttpHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
9
+ }
10
+ export interface IHttpLambdaFactory {
11
+ createHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output> | IHttpEventHandler<Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
12
+ createEventHandler<Output>(newable: Newable<IHttpEventHandler<Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
13
+ }
14
+ export interface IHttpResponseGenerator {
15
+ generateResponse(response?: any): Promise<APIGatewayProxyStructuredResultV2>;
16
+ }
17
+ export declare class HttpResponseGenerator implements IHttpResponseGenerator {
18
+ private readonly configuredRoute;
19
+ constructor(configuredRoute: IConfiguredRoute);
20
+ generateResponse(response?: any): Promise<APIGatewayProxyStructuredResultV2>;
21
+ }
22
+ export declare class HttpLambdaFactory implements IHttpLambdaFactory {
23
+ private readonly container;
24
+ constructor(container: IServiceContainer);
25
+ createEventHandler<Output>(newable: Newable<IHttpEventHandler<Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
26
+ createHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output> | IHttpEventHandler<Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
27
+ }
28
+ export declare const useTrigintaHttp: import("@aesop-fables/containr").IServiceModule;
29
+ export declare function createBootstrappedHttpLambdaContext(container: IServiceContainer): BootstrappedHttpLambdaContext;