Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aesop-fables/triginta

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aesop-fables/triginta - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

1

lib/Decorators.js

@@ -13,3 +13,2 @@ "use strict";

const params = { method, route, constructor: target };
console.log('wtf', params);
Reflect.defineMetadata(exports.endpointMetadataKey, params, target);

@@ -16,0 +15,0 @@ RouteRegistry_1.default.register(params);

3

lib/HttpLambda.d.ts
import { IServiceContainer, IServiceModule, Newable } from '@aesop-fables/containr';
import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2, Handler } from 'aws-lambda';
import { IHttpEndpoint, IHttpEventHandler } from './IHttpEndpoint';
import { IConfiguredRoute } from './IConfiguredRoute';
export declare type NonNoisyEvent = Omit<APIGatewayProxyEventV2, 'requestContext'>;

@@ -17,2 +18,4 @@ export interface BootstrappedHttpLambdaContext {

export declare class HttpResponseGenerator implements IHttpResponseGenerator {
private readonly configuredRoute;
constructor(configuredRoute: IConfiguredRoute);
generateResponse(response?: any): Promise<APIGatewayProxyStructuredResultV2>;

@@ -19,0 +22,0 @@ }

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -23,17 +35,37 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

const HttpLambdaServices_1 = require("./HttpLambdaServices");
class HttpResponseGenerator {
let HttpResponseGenerator = class HttpResponseGenerator {
constructor(configuredRoute) {
this.configuredRoute = configuredRoute;
}
generateResponse(response) {
return __awaiter(this, void 0, void 0, function* () {
let proxyResponse = response;
if (typeof (proxyResponse === null || proxyResponse === void 0 ? void 0 : proxyResponse.statusCode) === 'undefined') {
// TODO -- Is 200 always correct here?
proxyResponse = {
const proxyResponse = response;
if (typeof (proxyResponse === null || proxyResponse === void 0 ? void 0 : proxyResponse.statusCode) !== 'undefined') {
return proxyResponse;
}
// TODO -- We should use the event to make this a little smarter
const body = response ? JSON.stringify(response) : undefined;
if (this.configuredRoute.method === 'get') {
return {
statusCode: 200,
body: response ? JSON.stringify(response) : undefined,
body,
};
}
return proxyResponse;
if (typeof response === 'undefined') {
return {
statusCode: 204,
body: undefined,
};
}
return {
statusCode: 200,
body,
};
});
}
}
};
HttpResponseGenerator = __decorate([
__param(0, (0, containr_1.inject)(HttpLambdaServices_1.HttpLambdaServices.CurrentRoute)),
__metadata("design:paramtypes", [Object])
], HttpResponseGenerator);
exports.HttpResponseGenerator = HttpResponseGenerator;

@@ -49,4 +81,13 @@ class HttpLambdaFactory {

const handler = (event) => __awaiter(this, void 0, void 0, function* () {
const childContainer = this.container.createChildContainer('httpLambda');
// TODO -- Containr doens't have a way to inject itself YET so we'll just pull the dependency out of the container directly
const route = (0, Decorators_1.getRoute)(newable);
if (!route) {
throw new Error('No route found for the specified endpoint');
}
const injectConfiguredRoute = {
name: 'injectConfiguredRoute',
configureServices(services) {
services.register(HttpLambdaServices_1.HttpLambdaServices.CurrentRoute, route);
},
};
const childContainer = this.container.createChildContainer('httpLambda', [injectConfiguredRoute]);
const responseGenerator = childContainer.get(HttpLambdaServices_1.HttpLambdaServices.HttpResponseGenerator);

@@ -57,6 +98,2 @@ try {

let response;
const route = (0, Decorators_1.getRoute)(newable);
if (!route) {
throw new Error('No route found for the specified endpoint');
}
if (route.method !== 'get') {

@@ -63,0 +100,0 @@ const endpoint = handler;

export declare const HttpLambdaServices: {
CurrentRoute: string;
HttpLambdaFactory: string;
HttpResponseGenerator: string;
};

@@ -5,4 +5,5 @@ "use strict";

exports.HttpLambdaServices = {
CurrentRoute: 'currentRoute',
HttpLambdaFactory: 'HttpLambdaFactory',
HttpResponseGenerator: 'HttpResponseGenerator',
};

@@ -0,5 +1,6 @@

export declare type HttpMethod = 'get' | 'post' | 'delete' | 'put' | 'options';
export interface IConfiguredRoute {
constructor: Function;
method: string;
method: HttpMethod;
route: string;
}
{
"name": "@aesop-fables/triginta",
"version": "0.4.1",
"version": "0.4.2",
"description": "A lightweight framework that wraps the basic infrastructure usages of AWS Lambda (SQS, Kinesis, etc.).",

@@ -19,3 +19,3 @@ "type": "commonjs",

"lint:fix": "eslint src --fix --ext .js,.ts",
"test": "jest --config jest.config.js",
"test": "jest --config jest.config.js --runInBand",
"test:watch": "jest --config jest.config.js --watch",

@@ -28,3 +28,3 @@ "prepublishOnly": "npm test && npm run lint",

"devDependencies": {
"@aesop-fables/containr": "^0.2.3",
"@aesop-fables/containr": "^0.2.4",
"@middy/core": "^4.2.7",

@@ -31,0 +31,0 @@ "@middy/http-error-handler": "^4.2.3",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc