@yopdev/dev-server 1.5.0-alpha.6 → 1.7.0-alpha.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.
@@ -1,5 +1,4 @@
1
- import { SQSEvent } from 'aws-lambda';
2
- import { MessageAttributeValue } from '@aws-sdk/client-sqs';
1
+ import { SNSMessageAttributes, SQSEvent } from 'aws-lambda';
3
2
  import { Service } from './services';
4
3
  export declare const newEventsProxy: (name: string, config: {
5
4
  handlers: EventHandler[];
@@ -8,5 +7,5 @@ export declare const newEventsProxy: (name: string, config: {
8
7
  export type EventHandler = {
9
8
  name: string;
10
9
  handler: (event: SQSEvent) => Promise<unknown>;
11
- matcher: (subject: string, attributes: Record<string, MessageAttributeValue>) => boolean;
10
+ matcher: (subject: string, attributes: SNSMessageAttributes) => boolean;
12
11
  };
@@ -94,8 +94,10 @@ var EventsProxy = /** @class */ (function () {
94
94
  return;
95
95
  }
96
96
  var body = (0, assert_1.assertNotUndefined)(message.Body, 'body is not present');
97
- var subject = JSON.parse(body).Subject;
98
- var handlers = _this.handlers.filter(function (handler) { var _a; return handler.matcher(subject, (_a = message.MessageAttributes) !== null && _a !== void 0 ? _a : {}); });
97
+ var json = JSON.parse(body);
98
+ var attributes = json.MessageAttributes;
99
+ var subject = json.Subject;
100
+ var handlers = _this.handlers.filter(function (handler) { return handler.matcher(subject, attributes); });
99
101
  if (handlers.length === 0) {
100
102
  _this.LOGGER.warn('no handlers found for message %o', message);
101
103
  }
@@ -13,6 +13,7 @@ export { all as allOf, oneThenOther } from './factories';
13
13
  export { lazy, promised } from './deferred';
14
14
  export { Lifecycle, Service } from './services';
15
15
  export { DevServerConfig } from './config';
16
+ export { Route } from './lambda-http-proxy';
16
17
  declare global {
17
18
  interface Promise<T> {
18
19
  tap(onfulfilled?: (value: T) => void, onrejected?: (reason: unknown) => void): Promise<T>;
@@ -5,9 +5,9 @@ export declare const newLambdaHttpProxy: (name: string, config: {
5
5
  settings: HttpSettings;
6
6
  routes: Route[];
7
7
  }, callback?: Callback<string>) => Service<string>;
8
- type Route = {
8
+ export type Route = {
9
9
  method: RegExp;
10
10
  path: RegExp;
11
+ weight: number;
11
12
  handler: (event: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult>;
12
13
  };
13
- export {};
@@ -75,7 +75,7 @@ var LambdaHttpProxy = /** @class */ (function () {
75
75
  var _a;
76
76
  return ((_a = _this.routes.filter(function (r) { return request.method.match(r.method); })
77
77
  .filter(function (r) { return request.url.match(r.path); })
78
- .sort(function (r1, r2) { return r2.path.source.length - r1.path.source.length; })
78
+ .sort(function (r1, r2) { return r2.weight - r1.weight; })
79
79
  .map(function (r) { return _this.handler(r.handler); })
80
80
  .find(function () { return true; })) !== null && _a !== void 0 ? _a : _this.fallback)(request, body, response);
81
81
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yopdev/dev-server",
3
- "version": "1.5.0-alpha.6",
3
+ "version": "1.7.0-alpha.0",
4
4
  "scripts": {
5
5
  "compile": "tsc",
6
6
  "pretest": "npm run compile",