@aesop-fables/triginta 0.5.0 → 0.7.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 (85) hide show
  1. package/lib/Decorators.d.ts +1 -1
  2. package/lib/RouteRegistry.d.ts +1 -1
  3. package/lib/http/HttpCultureContext.d.ts +7 -0
  4. package/lib/http/HttpCultureContext.js +17 -0
  5. package/lib/{HttpLambda.js → http/HttpLambda.js} +57 -44
  6. package/lib/{HttpLambdaServices.d.ts → http/HttpLambdaServices.d.ts} +2 -0
  7. package/lib/{HttpLambdaServices.js → http/HttpLambdaServices.js} +2 -0
  8. package/lib/{IHttpEndpoint.d.ts → http/IHttpEndpoint.d.ts} +1 -1
  9. package/lib/http/IRequestContext.d.ts +4 -0
  10. package/lib/http/index.d.ts +1 -0
  11. package/lib/http/index.js +15 -0
  12. package/lib/index.d.ts +13 -9
  13. package/lib/index.js +14 -10
  14. package/lib/localization/ICultureContext.d.ts +3 -0
  15. package/lib/localization/ICultureContext.js +2 -0
  16. package/lib/localization/ILocalizationStorage.d.ts +6 -0
  17. package/lib/localization/ILocalizationStorage.js +2 -0
  18. package/lib/localization/IStringLocalizer.d.ts +4 -0
  19. package/lib/localization/IStringLocalizer.js +2 -0
  20. package/lib/localization/LocalizationServices.d.ts +5 -0
  21. package/lib/localization/LocalizationServices.js +8 -0
  22. package/lib/localization/LocalizationStorage.d.ts +4 -0
  23. package/lib/localization/LocalizationStorage.js +10 -0
  24. package/lib/localization/LocalizedString.d.ts +4 -0
  25. package/lib/localization/LocalizedString.js +2 -0
  26. package/lib/localization/StringLocalizer.d.ts +10 -0
  27. package/lib/localization/StringLocalizer.js +16 -0
  28. package/lib/localization/index.d.ts +8 -0
  29. package/lib/localization/index.js +32 -0
  30. package/lib/sqs/ISqsMessage.d.ts +16 -0
  31. package/lib/sqs/ISqsMessage.js +30 -0
  32. package/lib/{ISqsMessageHandler.d.ts → sqs/ISqsMessageHandler.d.ts} +2 -1
  33. package/lib/sqs/ISqsMessageHandler.js +2 -0
  34. package/lib/sqs/RecordMatchers.d.ts +31 -0
  35. package/lib/sqs/RecordMatchers.js +113 -0
  36. package/lib/sqs/SqsLambda.d.ts +29 -0
  37. package/lib/{SqsLambda.js → sqs/SqsLambda.js} +29 -18
  38. package/lib/sqs/SqsLambdaServices.d.ts +6 -0
  39. package/lib/{SqsLambdaServices.js → sqs/SqsLambdaServices.js} +3 -0
  40. package/lib/validation/IConfiguredValidationRule.d.ts +5 -0
  41. package/lib/validation/IConfiguredValidationRule.js +2 -0
  42. package/lib/validation/IValidationFailureHandler.d.ts +15 -0
  43. package/lib/validation/IValidationFailureHandler.js +30 -0
  44. package/lib/validation/IValidationRule.d.ts +4 -0
  45. package/lib/validation/IValidationRule.js +2 -0
  46. package/lib/validation/IValidator.d.ts +4 -0
  47. package/lib/validation/IValidator.js +2 -0
  48. package/lib/validation/IValidatorFactory.d.ts +5 -0
  49. package/lib/validation/IValidatorFactory.js +2 -0
  50. package/lib/validation/RequiredRule.d.ts +5 -0
  51. package/lib/validation/RequiredRule.js +23 -0
  52. package/lib/validation/RuleParser.d.ts +10 -0
  53. package/lib/validation/RuleParser.js +29 -0
  54. package/lib/validation/ValidationContext.d.ts +19 -0
  55. package/lib/validation/ValidationContext.js +35 -0
  56. package/lib/validation/ValidationError.d.ts +4 -0
  57. package/lib/validation/ValidationError.js +11 -0
  58. package/lib/validation/ValidationKeys.d.ts +4 -0
  59. package/lib/validation/ValidationKeys.js +6 -0
  60. package/lib/validation/ValidationMessage.d.ts +7 -0
  61. package/lib/validation/ValidationMessage.js +13 -0
  62. package/lib/validation/ValidationMiddleware.d.ts +4 -0
  63. package/lib/validation/ValidationMiddleware.js +34 -0
  64. package/lib/validation/ValidationNotification.d.ts +11 -0
  65. package/lib/validation/ValidationNotification.js +56 -0
  66. package/lib/validation/ValidationServices.d.ts +5 -0
  67. package/lib/validation/ValidationServices.js +8 -0
  68. package/lib/validation/Validator.d.ts +12 -0
  69. package/lib/validation/Validator.js +48 -0
  70. package/lib/validation/ValidatorFactory.d.ts +9 -0
  71. package/lib/validation/ValidatorFactory.js +31 -0
  72. package/lib/validation/index.d.ts +17 -0
  73. package/lib/validation/index.js +43 -0
  74. package/package.json +9 -6
  75. package/lib/SqsLambda.d.ts +0 -19
  76. package/lib/SqsLambdaServices.d.ts +0 -3
  77. /package/lib/{HttpLambda.d.ts → http/HttpLambda.d.ts} +0 -0
  78. /package/lib/{IConfiguredRoute.d.ts → http/IConfiguredRoute.d.ts} +0 -0
  79. /package/lib/{IConfiguredRoute.js → http/IConfiguredRoute.js} +0 -0
  80. /package/lib/{IHttpEndpoint.js → http/IHttpEndpoint.js} +0 -0
  81. /package/lib/{ISqsMessageHandler.js → http/IRequestContext.js} +0 -0
  82. /package/lib/{invokeHttpHandler.d.ts → http/invokeHttpHandler.d.ts} +0 -0
  83. /package/lib/{invokeHttpHandler.js → http/invokeHttpHandler.js} +0 -0
  84. /package/lib/{invokeSqsHandler.d.ts → sqs/invokeSqsHandler.d.ts} +0 -0
  85. /package/lib/{invokeSqsHandler.js → sqs/invokeSqsHandler.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { IConfiguredRoute } from './IConfiguredRoute';
1
+ import { IConfiguredRoute } from './http/IConfiguredRoute';
2
2
  export declare const endpointMetadataKey: unique symbol;
3
3
  export declare function getRoute(target: Function): IConfiguredRoute | undefined;
4
4
  export declare function httpGet(route: string): (target: Object) => void;
@@ -1,4 +1,4 @@
1
- import { IConfiguredRoute } from './IConfiguredRoute';
1
+ import { IConfiguredRoute } from './http/IConfiguredRoute';
2
2
  export interface IRouteRegistry {
3
3
  allRoutes(): IConfiguredRoute[];
4
4
  register(route: IConfiguredRoute): void;
@@ -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;
@@ -30,8 +30,11 @@ exports.HttpLambda = exports.useTrigintaHttp = exports.HttpLambdaFactory = expor
30
30
  /* eslint-disable @typescript-eslint/no-unused-vars */
31
31
  const containr_1 = require("@aesop-fables/containr");
32
32
  const core_1 = __importDefault(require("@middy/core"));
33
- const Decorators_1 = require("./Decorators");
33
+ const Decorators_1 = require("../Decorators");
34
34
  const HttpLambdaServices_1 = require("./HttpLambdaServices");
35
+ const _1 = require(".");
36
+ const localization_1 = require("../localization");
37
+ const validation_1 = require("../validation");
35
38
  let HttpResponseGenerator = class HttpResponseGenerator {
36
39
  constructor(configuredRoute) {
37
40
  this.configuredRoute = configuredRoute;
@@ -76,53 +79,57 @@ class HttpLambdaFactory {
76
79
  return this.createHandler(newable);
77
80
  }
78
81
  createHandler(newable) {
79
- const handler = (event) => __awaiter(this, void 0, void 0, function* () {
80
- const route = (0, Decorators_1.getRoute)(newable);
81
- if (!route) {
82
- throw new Error('No route found for the specified endpoint');
82
+ var _a;
83
+ const route = (0, Decorators_1.getRoute)(newable);
84
+ if (!route) {
85
+ throw new Error('No route found for the specified endpoint');
86
+ }
87
+ const handler = (event, context) => __awaiter(this, void 0, void 0, function* () {
88
+ const childContainer = context['container'];
89
+ if (!childContainer) {
90
+ throw new Error('No container found in the context');
83
91
  }
84
- const injectConfiguredRoute = {
85
- name: 'injectConfiguredRoute',
86
- configureServices(services) {
87
- services.register(HttpLambdaServices_1.HttpLambdaServices.CurrentRoute, route);
88
- },
89
- };
90
- const childContainer = this.container.createChildContainer('httpLambda', [injectConfiguredRoute]);
91
92
  const responseGenerator = childContainer.get(HttpLambdaServices_1.HttpLambdaServices.HttpResponseGenerator);
92
- try {
93
- const handler = this.container.resolve(newable);
94
- const { body: request } = event;
95
- let response;
96
- if (route.method !== 'get') {
97
- const endpoint = handler;
98
- response = (yield endpoint.handle(request, event));
99
- }
100
- else {
101
- const eventHandler = handler;
102
- response = (yield eventHandler.handle(event));
103
- }
104
- return responseGenerator.generateResponse(response);
93
+ const handler = childContainer.resolve(newable);
94
+ const { body: request } = event;
95
+ let response;
96
+ if (route.method !== 'get') {
97
+ const endpoint = handler;
98
+ response = (yield endpoint.handle(request, event));
105
99
  }
106
- finally {
107
- if (childContainer) {
108
- try {
109
- childContainer.dispose();
110
- }
111
- catch (_a) {
112
- // no-op
113
- }
114
- }
100
+ else {
101
+ const eventHandler = handler;
102
+ response = (yield eventHandler.handle(event));
115
103
  }
104
+ return responseGenerator.generateResponse(response);
116
105
  });
117
- const middlewareMetadata = (0, Decorators_1.getMiddleware)(newable);
118
- if (middlewareMetadata) {
119
- let midHandler = (0, core_1.default)(handler);
120
- middlewareMetadata.forEach((midFunc) => {
121
- midHandler = midHandler.use(midFunc());
122
- });
123
- return midHandler;
124
- }
125
- return handler;
106
+ const { container } = this;
107
+ const middlewareMetadata = (_a = (0, Decorators_1.getMiddleware)(newable)) !== null && _a !== void 0 ? _a : [];
108
+ let midHandler = (0, core_1.default)(handler).use({
109
+ before(request) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const injectContextualServices = (0, containr_1.createServiceModule)('injectContextualServices', (services) => {
112
+ services.register(HttpLambdaServices_1.HttpLambdaServices.CurrentRoute, route);
113
+ services.register(HttpLambdaServices_1.HttpLambdaServices.CurrentEvent, request.event);
114
+ services.register(HttpLambdaServices_1.HttpLambdaServices.RequestContext, (current) => {
115
+ return {
116
+ container: current,
117
+ };
118
+ });
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
+ },
128
+ });
129
+ middlewareMetadata.forEach((midFunc) => {
130
+ midHandler = midHandler.use(midFunc());
131
+ });
132
+ return midHandler;
126
133
  }
127
134
  }
128
135
  exports.HttpLambdaFactory = HttpLambdaFactory;
@@ -133,7 +140,13 @@ exports.useTrigintaHttp = (0, containr_1.createServiceModule)('triginta/http', (
133
140
  let _currentContainer;
134
141
  class HttpLambda {
135
142
  static initialize(modules = []) {
136
- const container = (0, containr_1.createContainer)([exports.useTrigintaHttp, ...modules]);
143
+ const container = (0, containr_1.createContainer)([
144
+ exports.useTrigintaHttp,
145
+ _1.useHttpServices,
146
+ localization_1.useLocalization,
147
+ validation_1.useHttpValidation,
148
+ ...modules,
149
+ ]);
137
150
  _currentContainer = container;
138
151
  return {
139
152
  createHttpEventLambda(newable) {
@@ -1,5 +1,7 @@
1
1
  export declare const HttpLambdaServices: {
2
2
  CurrentRoute: string;
3
+ CurrentEvent: string;
3
4
  HttpLambdaFactory: string;
4
5
  HttpResponseGenerator: string;
6
+ RequestContext: string;
5
7
  };
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpLambdaServices = void 0;
4
4
  exports.HttpLambdaServices = {
5
5
  CurrentRoute: 'currentRoute',
6
+ CurrentEvent: 'currentEvent',
6
7
  HttpLambdaFactory: 'HttpLambdaFactory',
7
8
  HttpResponseGenerator: 'HttpResponseGenerator',
9
+ RequestContext: 'requestContext',
8
10
  };
@@ -1,5 +1,5 @@
1
1
  import { APIGatewayProxyEventV2 } from 'aws-lambda';
2
- import { IEventHandler, IMessageHandler } from './IHandler';
2
+ import { IEventHandler, IMessageHandler } from '../IHandler';
3
3
  export interface IHttpEventHandler<Output = void> extends IEventHandler<APIGatewayProxyEventV2, Output> {
4
4
  }
5
5
  export interface IHttpEndpoint<Input, Output> extends IMessageHandler<Input, APIGatewayProxyEventV2, Output> {
@@ -0,0 +1,4 @@
1
+ import { IServiceContainer } from '@aesop-fables/containr';
2
+ export interface IRequestContext {
3
+ container: IServiceContainer;
4
+ }
@@ -0,0 +1 @@
1
+ export declare const useHttpServices: import("@aesop-fables/containr").IServiceModule;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useHttpServices = void 0;
4
+ const containr_1 = require("@aesop-fables/containr");
5
+ const localization_1 = require("../localization");
6
+ const HttpCultureContext_1 = require("./HttpCultureContext");
7
+ const HttpLambdaServices_1 = require("./HttpLambdaServices");
8
+ exports.useHttpServices = (0, containr_1.createServiceModule)('useHttpServices', (services) => {
9
+ services.use(localization_1.LocalizationServices.CultureContext, HttpCultureContext_1.HttpCultureContext);
10
+ services.register(HttpLambdaServices_1.HttpLambdaServices.RequestContext, (container) => {
11
+ return {
12
+ container,
13
+ };
14
+ });
15
+ });
package/lib/index.d.ts CHANGED
@@ -1,16 +1,20 @@
1
1
  export * from './IHandler';
2
- export * from './IHttpEndpoint';
2
+ export * from './http/IHttpEndpoint';
3
3
  export * from './Decorators';
4
- export * from './HttpLambda';
5
- export * from './HttpLambdaServices';
4
+ export * from './http/HttpLambda';
5
+ export * from './http/HttpLambdaServices';
6
6
  export { default as RouteRegistry, IRouteRegistry } from './RouteRegistry';
7
- export * from './SqsLambda';
8
- export * from './SqsLambdaServices';
9
- export * from './ISqsMessageHandler';
10
- export * from './IConfiguredRoute';
7
+ export * from './sqs/SqsLambda';
8
+ export * from './sqs/SqsLambdaServices';
9
+ export * from './sqs/ISqsMessageHandler';
10
+ export * from './sqs/RecordMatchers';
11
+ export * from './sqs/ISqsMessage';
12
+ export * from './http/IConfiguredRoute';
11
13
  export * from './TrigintaConfig';
12
- import * as httpUtils from './invokeHttpHandler';
13
- import * as sqsUtils from './invokeSqsHandler';
14
+ export * as Localization from './localization';
15
+ export * as Validation from './validation';
16
+ import * as httpUtils from './http/invokeHttpHandler';
17
+ import * as sqsUtils from './sqs/invokeSqsHandler';
14
18
  /**
15
19
  * Provides helper functions for invoking lambdas in unit/integration tests.
16
20
  */
package/lib/index.js CHANGED
@@ -29,21 +29,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.TestUtils = exports.RouteRegistry = void 0;
32
+ exports.TestUtils = exports.Validation = exports.Localization = exports.RouteRegistry = void 0;
33
33
  __exportStar(require("./IHandler"), exports);
34
- __exportStar(require("./IHttpEndpoint"), exports);
34
+ __exportStar(require("./http/IHttpEndpoint"), exports);
35
35
  __exportStar(require("./Decorators"), exports);
36
- __exportStar(require("./HttpLambda"), exports);
37
- __exportStar(require("./HttpLambdaServices"), exports);
36
+ __exportStar(require("./http/HttpLambda"), exports);
37
+ __exportStar(require("./http/HttpLambdaServices"), exports);
38
38
  var RouteRegistry_1 = require("./RouteRegistry");
39
39
  Object.defineProperty(exports, "RouteRegistry", { enumerable: true, get: function () { return __importDefault(RouteRegistry_1).default; } });
40
- __exportStar(require("./SqsLambda"), exports);
41
- __exportStar(require("./SqsLambdaServices"), exports);
42
- __exportStar(require("./ISqsMessageHandler"), exports);
43
- __exportStar(require("./IConfiguredRoute"), exports);
40
+ __exportStar(require("./sqs/SqsLambda"), exports);
41
+ __exportStar(require("./sqs/SqsLambdaServices"), exports);
42
+ __exportStar(require("./sqs/ISqsMessageHandler"), exports);
43
+ __exportStar(require("./sqs/RecordMatchers"), exports);
44
+ __exportStar(require("./sqs/ISqsMessage"), exports);
45
+ __exportStar(require("./http/IConfiguredRoute"), exports);
44
46
  __exportStar(require("./TrigintaConfig"), exports);
45
- const httpUtils = __importStar(require("./invokeHttpHandler"));
46
- const sqsUtils = __importStar(require("./invokeSqsHandler"));
47
+ exports.Localization = __importStar(require("./localization"));
48
+ exports.Validation = __importStar(require("./validation"));
49
+ const httpUtils = __importStar(require("./http/invokeHttpHandler"));
50
+ const sqsUtils = __importStar(require("./sqs/invokeSqsHandler"));
47
51
  /**
48
52
  * Provides helper functions for invoking lambdas in unit/integration tests.
49
53
  */
@@ -0,0 +1,3 @@
1
+ export interface ICultureContext {
2
+ detectCulture(): string;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface ILocalizationStorage {
2
+ lookupCulture(cultureCode: string): ILocalizedStringStorage;
3
+ }
4
+ export interface ILocalizedStringStorage {
5
+ [key: string]: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { LocalizedString } from './LocalizedString';
2
+ export interface IStringLocalizer {
3
+ resolve(value: LocalizedString): string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export declare const LocalizationServices: {
2
+ CultureContext: string;
3
+ LocalizationStorage: string;
4
+ StringLocalizer: string;
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalizationServices = void 0;
4
+ exports.LocalizationServices = {
5
+ CultureContext: 'cultureContext',
6
+ LocalizationStorage: 'localizationStorage',
7
+ StringLocalizer: 'stringLocalizer',
8
+ };
@@ -0,0 +1,4 @@
1
+ import { ILocalizationStorage, ILocalizedStringStorage } from './ILocalizationStorage';
2
+ export declare class LocalizationStorage implements ILocalizationStorage {
3
+ lookupCulture(): ILocalizedStringStorage;
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalizationStorage = void 0;
4
+ // TODO -- Build this out more
5
+ class LocalizationStorage {
6
+ lookupCulture() {
7
+ return {};
8
+ }
9
+ }
10
+ exports.LocalizationStorage = LocalizationStorage;
@@ -0,0 +1,4 @@
1
+ export interface LocalizedString {
2
+ key: string;
3
+ defaultValue?: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { ICultureContext } from './ICultureContext';
2
+ import { ILocalizationStorage } from './ILocalizationStorage';
3
+ import { IStringLocalizer } from './IStringLocalizer';
4
+ import { LocalizedString } from './LocalizedString';
5
+ export declare class StringLocalizer implements IStringLocalizer {
6
+ private readonly storage;
7
+ private readonly cultureContext;
8
+ constructor(storage: ILocalizationStorage, cultureContext: ICultureContext);
9
+ resolve(value: LocalizedString): string;
10
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringLocalizer = void 0;
4
+ class StringLocalizer {
5
+ constructor(storage, cultureContext) {
6
+ this.storage = storage;
7
+ this.cultureContext = cultureContext;
8
+ }
9
+ resolve(value) {
10
+ var _a, _b;
11
+ const culture = this.cultureContext.detectCulture();
12
+ const store = this.storage.lookupCulture(culture);
13
+ return (_b = (_a = store[value.key]) !== null && _a !== void 0 ? _a : value.defaultValue) !== null && _b !== void 0 ? _b : value.key;
14
+ }
15
+ }
16
+ exports.StringLocalizer = StringLocalizer;
@@ -0,0 +1,8 @@
1
+ export * from './ICultureContext';
2
+ export * from './ILocalizationStorage';
3
+ export * from './IStringLocalizer';
4
+ export * from './LocalizationServices';
5
+ export * from './LocalizationStorage';
6
+ export * from './LocalizedString';
7
+ export * from './StringLocalizer';
8
+ export declare const useLocalization: import("@aesop-fables/containr").IServiceModule;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.useLocalization = void 0;
18
+ const containr_1 = require("@aesop-fables/containr");
19
+ const LocalizationServices_1 = require("./LocalizationServices");
20
+ const LocalizationStorage_1 = require("./LocalizationStorage");
21
+ const StringLocalizer_1 = require("./StringLocalizer");
22
+ __exportStar(require("./ICultureContext"), exports);
23
+ __exportStar(require("./ILocalizationStorage"), exports);
24
+ __exportStar(require("./IStringLocalizer"), exports);
25
+ __exportStar(require("./LocalizationServices"), exports);
26
+ __exportStar(require("./LocalizationStorage"), exports);
27
+ __exportStar(require("./LocalizedString"), exports);
28
+ __exportStar(require("./StringLocalizer"), exports);
29
+ exports.useLocalization = (0, containr_1.createServiceModule)('useLocalization', (services) => {
30
+ services.use(LocalizationServices_1.LocalizationServices.LocalizationStorage, LocalizationStorage_1.LocalizationStorage);
31
+ services.use(LocalizationServices_1.LocalizationServices.StringLocalizer, StringLocalizer_1.StringLocalizer);
32
+ });
@@ -0,0 +1,16 @@
1
+ import { SQSMessageAttributes } from 'aws-lambda';
2
+ export interface ISqsMessage {
3
+ type: string;
4
+ getAttributes(): SQSMessageAttributes;
5
+ getBody(): string;
6
+ }
7
+ export declare const TrigintaMessageHeaders: {
8
+ MessageType: string;
9
+ };
10
+ export declare abstract class BaseSqsMessage implements ISqsMessage {
11
+ readonly type: string;
12
+ constructor(type: string);
13
+ getAttributes(): SQSMessageAttributes;
14
+ getData(): any;
15
+ getBody(): string;
16
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSqsMessage = exports.TrigintaMessageHeaders = void 0;
4
+ exports.TrigintaMessageHeaders = {
5
+ MessageType: 'X-Message-Type',
6
+ };
7
+ class BaseSqsMessage {
8
+ constructor(type) {
9
+ this.type = type;
10
+ }
11
+ getAttributes() {
12
+ const attributes = {
13
+ [exports.TrigintaMessageHeaders.MessageType]: {
14
+ dataType: 'String',
15
+ stringValue: this.type,
16
+ },
17
+ };
18
+ return attributes;
19
+ }
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ getData() {
22
+ return undefined;
23
+ }
24
+ getBody() {
25
+ var _a;
26
+ const data = (_a = this.getData()) !== null && _a !== void 0 ? _a : {};
27
+ return JSON.stringify(data);
28
+ }
29
+ }
30
+ exports.BaseSqsMessage = BaseSqsMessage;
@@ -1,5 +1,6 @@
1
1
  import { SQSBatchResponse, SQSEvent, SQSRecord } from 'aws-lambda';
2
+ import { ISqsMessage } from './ISqsMessage';
2
3
  export declare type SqsOutput = SQSBatchResponse | void;
3
- export interface ISqsMessageHandler<Message, Output extends SqsOutput = void> {
4
+ export interface ISqsMessageHandler<Message extends ISqsMessage, Output extends SqsOutput = void> {
4
5
  handle(message: Message, record: SQSRecord, event: SQSEvent): Promise<Output>;
5
6
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import { SQSMessageAttributes, SQSRecord } from 'aws-lambda';
2
+ import { ISqsMessage } from './ISqsMessage';
3
+ export interface ISqsRecordMatcher {
4
+ matches(record: SQSRecord): boolean;
5
+ deserializeMessage<Message extends ISqsMessage>(record: SQSRecord): Promise<Message>;
6
+ }
7
+ export declare function retrieveMessageType(messageAttributes: SQSMessageAttributes): string;
8
+ export declare class DefaultSqsRecordMatcher implements ISqsRecordMatcher {
9
+ matches(): boolean;
10
+ deserializeMessage<Message extends ISqsMessage>(record: SQSRecord): Promise<Message>;
11
+ }
12
+ export interface ISqsMessageDeserializer {
13
+ deserializeMessage<Message extends ISqsMessage>(record: SQSRecord): Promise<Message>;
14
+ }
15
+ export declare class SqsMessageDeserializer implements ISqsMessageDeserializer {
16
+ private readonly matchers;
17
+ private readonly defaultMatcher;
18
+ constructor(matchers: ISqsRecordMatcher[], defaultMatcher: ISqsRecordMatcher);
19
+ deserializeMessage<Message extends ISqsMessage>(record: SQSRecord): Promise<Message>;
20
+ }
21
+ export declare type MessageConfigAttributes<Message> = {
22
+ [Property in keyof Message]: string;
23
+ };
24
+ export declare type MessageFactory<Message, Body> = (attributes: Partial<MessageConfigAttributes<Message>>, body: Body) => Promise<Message>;
25
+ export declare type MessageConfig<Message, Options> = {
26
+ type: string;
27
+ attributes: Partial<MessageConfigAttributes<Message>>;
28
+ constructUsing: MessageFactory<Message, Options>;
29
+ };
30
+ export declare type MessageExpression<Message extends ISqsMessage> = Omit<Message, 'getAttributes' | 'getBody' | 'getData'>;
31
+ export declare function createMatcher<Message extends ISqsMessage, Options>(configuration: MessageConfig<MessageExpression<Message>, Options>): ISqsRecordMatcher;