New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

routesmith

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

routesmith - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

8

autorouter.js

@@ -12,10 +12,10 @@ const express = require('express');

console.log(pathBase + route.path);
if (route.middleware && route.middleware.length > 0 && route.data.id) {
if (route.middleware && route.middleware.length > 0 && route.id) {
for (let i = 0; i < route.middleware.length; i++) {
autoRouter.router.use(pathBase + route.path + '/:' + route.data.id, route.middleware[i]);
autoRouter.router.use(pathBase + route.path + '/:' + route.id, route.middleware[i]);
}
}
autoRouter.router.use(pathBase + route.path, require('./default')(route));
if (route.children && route.data.id) {
let newPathBase = pathBase + route.path + '/:' + route.data.id + '/';
if (route.children && route.id) {
let newPathBase = pathBase + route.path + '/:' + route.id + '/';
autoRouter.CreateRoutes(route.children, newPathBase);

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

@@ -7,11 +7,9 @@

router.post('/', controller.create);
router.get('/', controller.getAll);
if (obj.data) {
router.get('/:' + obj.data.id, controller.get);
router.put('/:' + obj.data.id, controller.update);
router.delete('/:' + obj.data.id, controller.remove);
}
router.post('/', controller.create);
router.get('/', controller.getAll);
router.get('/:' + obj.id, controller.get);
router.put('/:' + obj.id, controller.update);
router.delete('/:' + obj.id, controller.remove);
return router;
};
module.exports = [
{
path:'users',
controller:<controller object goes here>,
middleware:[
<middleware objects go here>
],
data:{
id:'userID',
model:'Users',
required:[
'name',
'email',
'password'
],
optional:[
'description',
'phone',
'address'
],
public:[
'name',
'description',
'email',
'phone',
'address'
],
req:[
{
name:'organizationID',
hierarchy:[
'org',
'id'
]
}
]
},
id:'userID',
controller:require('routesmith-sequelize')(data),
middleware:[],
children:[
{
path:'posts',
controller:<controller object goes here>,
middleware:[
<middleware objects go here>
],
data:{
id:'postID',
belongsTo:'userID',
model:'Posts',
required:[
'content'
],
optional:[],
public:[
'id',
'content',
'userID'
]
}
controller:{},
middleware:[]
}

@@ -60,0 +13,0 @@ ]

{
"name": "routesmith",
"version": "1.0.3",
"version": "1.0.4",
"description": "A simple, lightweight routing solution for Express.",

@@ -22,3 +22,3 @@ "main": "autorouter.js",

"author": "Kurnett",
"license": "ISC"
"license": "MIT"
}

@@ -9,2 +9,8 @@ #RouteSmith

##Packages
[RouteSmith-Sequelize](https://www.npmjs.com/package/routesmith-sequelize) allows developers to easily create controllers to go along with RouteSmith's routes.
```bash
$ npm install --save routesmith-sequelize
```
##Usage

@@ -22,2 +28,9 @@ ```bash

####Path
The `path` field determines the URL of the endpoints to be generated.
####ID
The `id` field determines the name to be used for the URL parameter (e.g. `/users/:userID`).
####Controllers

@@ -29,22 +42,2 @@ Controllers are expected to be objects with `create`, `get`, `getAll`, `update`, and `remove` methods, corresponding to basic CRUD operations.

####Data
The `data` object contains several pieces of information. However, most of the values it contains are not checked by RouteSmith - rather, they are passed into the controller for use later on. This feature will be moved to a separate, but complementary, controller-automation package in the near future.
The `id` field determines the label for parameters in the route's URL. For example, for a route with the `path` `users`, the ID`id:'userID'` would create the following routes:
```bash
/users
/users/:userID
```
The `model` field allows you to define which model will be passed into the controller when the route is accessed, allowing you to find the correct model should the route interact with a database.
The `required` array dictates what values are required in the body of the request. RouteSmith does not validate this - rather, the list is passed to the controller.
The `optional` array dictates what values are optional in the body of the request. RouteSmith does not validate this - rather, the list is passed to the controller.
The `public` array dictates what values are publicly visible in the response to a GET request. RouteSmith does not validate this - rather, the list is passed to the controller.
The `req` array allows developers to define values to look for in the request object, typically added by middleware prior to the route being reached. For example, a global middleware function might retrieve user data and attach it to the request object for future use. The `req` array can then define a new name for the object and the hierarchy through the request object that is needed to retrieve the proper value (for nested values - i.e. `req.user.id`).
####Children

@@ -60,2 +53,3 @@ The `children` array contains a list of other routes to be created under the original route.

path:'users',
id:'userID',
controller:<controller object goes here>,

@@ -65,53 +59,10 @@ middleware:[

],
data:{
id:'userID',
model:'Users',
required:[
'name',
'email',
'password'
],
optional:[
'description',
'phone',
'address'
],
public:[
'name',
'description',
'email',
'phone',
'address'
],
req:[
{
name:'organizationID',
hierarchy:[
'org',
'id'
]
}
]
},
children:[
{
path:'posts',
id:'postID',
controller:<controller object goes here>,
middleware:[
<middleware objects go here>
],
data:{
id:'postID',
belongsTo:'userID',
model:'Posts',
required:[
'content'
],
optional:[],
public:[
'id',
'content',
'userID'
]
}
]
}

@@ -122,2 +73,19 @@ ]

```
If we wished to simplify the route structure further, we could strip out unnecessary data (for example, if we had no middleware to apply).
```bash
const routes = [
{
path:'users',
id:'userID',
controller:<controller object goes here>
children:[
{
path:'posts',
id:'postID',
controller:<controller object goes here>
}
]
}
]
```
Based on this structure, we would have the following routes:

@@ -124,0 +92,0 @@ ```bash

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