Socket
Socket
Sign inDemoInstall

@everestate/serverless-router

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everestate/serverless-router - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

10

lib/__tests__/ServerlessRouter.js

@@ -48,5 +48,11 @@ const ServerlessRouter = require('../ServerlessRouter');

const router = subj();
router.weekday.saturday(() => ({ saturday: true }));
router.weekday.saturday((...args) => ({ saturday: true, args }));
router.mismatch(() => ({ mismatched: true }));
expect(router.dispatch(new Date('2014-08-16'))).toEqual({ saturday: true });
expect(router.dispatch(new Date('2014-08-16'))).toEqual({
saturday: true,
args: [
{},
new Date('2014-08-16'),
],
});
expect(router.dispatch(new Date('2017-09-05'))).toEqual({ mismatched: true });

@@ -53,0 +59,0 @@ });

2

lib/ServerlessRouter.js

@@ -40,3 +40,3 @@ class ServerlessRouter {

if (route) {
return route.callback.apply(null, [...args, route.context || {}]);
return route.callback.apply(null, [route.context || {}, ...args]);
}

@@ -43,0 +43,0 @@ }

{
"name": "@everestate/serverless-router",
"version": "0.0.2",
"version": "0.1.0",
"description": "Fast, minimalist, pluggable, universal router.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -25,29 +25,28 @@ # @everestate/serverless-router

const router = new ServerlessRouter([ServerlessRouterWebPlugin]);
cosnt userService = require('../services/userService');
router.web
.get('/users/:userId/appointments', (event, context, callback) => {
const appointments = findAppointmentsByUserId(event.pathParameters.userId);
return callback(null, {
statusCode: '200',
body: JSON.stringify({ appointments }),
});
})
.post('/users/:userId/appointments', (event, context, callback) => {
const { userId } = event.pathParameters;
const appointment = createAppointment({ ...event.body, userId });
return callback(null, {
statusCode: '201',
body: JSON.stringify({ appointment }),
});
})
.delete('/users/:userId/appointments/:appointmentId', (event, context, callback) => {
const { appointmentId } = event.pathParameters;
deleteAppointmentById(appointmentId);
return callback(null, {
statusCode: '204',
body: '',
});
function dispatch(event) {
const router = new ServerlessRouter([ServerlessRouterWebPlugin]);
router.web
.get('/users/:id', () =>
userService.getUserById(event.pathParameters.id)) // returns promise
.delete('/users/:id', () =>
userService.deleteUserById(event.pathParameters.id)); // returns promise
router.mismatch(() => {
const { path, httpMethod } = event;
return Promise.reject(new Error(`Unknown route: ${httpMethod} ${path}`));
});
router.dispatch(event, context, callback);
return router.dispatch(event);
}
function myLambdaHandler(event, context, callback) {
return dispatch(event)
.then(result =>
callback(null, { statusCode: result.code, body: JSON.stringify({ payload: result.payload }) }))
.catch(error =>
callback(null, { statusCode: '500', body: JSON.stringify({ message: error.message }) }));
}
```

@@ -54,0 +53,0 @@

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