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

hyped

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyped - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

spec/parameters.spec.js

3

CHANGELOG.md

@@ -0,1 +1,4 @@

### 0.0.12
Add support for query parameter definition.
### 0.0.11

@@ -2,0 +5,0 @@

2

package.json
{
"name": "hyped",
"version": "0.0.11",
"version": "0.0.12",
"description": "Hypermedia response generation engine",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -20,2 +20,3 @@ ## hyped

```
// resource
{

@@ -26,3 +27,3 @@ [resourceName]: the resource name (must be unique)

[actionName]: {
method: the http verb/method
method: the http method
url: the URL for this action

@@ -35,2 +36,3 @@ include: property names array to include in the rendered response

links: provides alternate/compatible urls for activating this action
parameters: provide metadata to describe available query parameters for this action
}

@@ -49,3 +51,3 @@ },

// an embed section looks like this:
// embed
{

@@ -59,6 +61,13 @@ [propertyName]: {

// a link section looks like this:
// links
{
[actionName]: url|generator
}
// parameters
{
parameterName: {
[ range|choice|list|validate|invalidate ]: specification
}
}
```

@@ -115,2 +124,16 @@

</dd>
<dt><h3>parameters</h3></dt>
<dd>A hash of parameter names and metadata about each parameter. Each parameter should specify what "type" it is along with a specification that the client can use to validate possible parameter values. Any of the specifications can be a generator function to allow for dynamic specification.</dd>
<dt>choice</dt>
<dd>An array of valid choices where the consumer is expected to provide a single value.</dd>
<dt>multi</dt>
<dd>An array of valid choices where the consumer can provide multiple values.</dd>
<dt>range</dt>
<dd>A two-element array consisting of a lower and upper bound for the parameter value.</dd>
<dt>validate</dt>
<dd>A regular expression used to determine if a parameter value is valid.</dd>
<dt>invalidate</dt>
<dd>A regular expression used to detect invalid parameter values.</dd>
<dt>required</dt>
<dd>A boolean indicating that this parameter is required.</dd>
</dl>

@@ -271,4 +294,4 @@

"_links": {
"self": { "href": "/user/leroyJenkins", "verb": "GET" },
"insult": { "href": "/user/leroyJenkins/{insult}", "verb": "POST", "templated": true }
"self": { "href": "/user/leroyJenkins", "method": "GET" },
"insult": { "href": "/user/leroyJenkins/{insult}", "method": "POST", "templated": true }
}

@@ -435,3 +458,3 @@ }

#### Methods
HAL does not include the HTTP verb/method used for an link"s `href`. Our version does include this information in the link using the `verb` property. As in our URL example from above:
HAL does not include the HTTP method used for an link"s `href`. Our version does include this information in the link using the `method` property. As in our URL example from above:

@@ -442,3 +465,3 @@ ```javascript

"_links": {
"self": { "href": "/user/leroyJenkins", "verb": "GET" }
"self": { "href": "/user/leroyJenkins", "method": "GET" }
}

@@ -448,2 +471,33 @@ }

#### Parameters
While the `links` property allows you to provide actions with the parameters already attached to the URL, there will be times when defining every possible combination of parameters as a specific action won't make sense.
In those cases, we believe hypermedia should include metadata about the available parameters. This at least reduces the amount of implementation details exposed to API consumers.
```javascript
{
"_links": {
"self": {
"href": "/thing/100",
"method": "GET",
"parameters": {
"arg1": {
"range": [ 0, 100 ]
},
"arg2": {
"choice": [ 4, 8, 15, 16, 23, 42 ]
},
"arg3": {
"multi": [ "a", "b", "c", "d" ]
},
"arg4": {
"validate": "/^starts with.*/",
"invalidate": "/.*ends with$"
}
}
}
}
}
```
## Contributing

@@ -450,0 +504,0 @@ The tests are a bit of a contrived mess at the moment but do exercise the features and known use cases. If submitting a PR, please do the following:

@@ -185,2 +185,11 @@ var _ = require( "lodash" );

if( hasPermission && canRender ) {
var parameters = _.reduce( action.parameters, function( acc, val, key ) {
if( _.isFunction( val ) ) {
acc[ key ] = val( item, requestContext );
} else {
acc[ key ] = val;
}
return acc;
}, {} );
function genLink( rel, template, method ) {

@@ -205,2 +214,5 @@ var href = [ url.create( template, item, resource.name ) ];

}
if( !_.isEmpty( parameters ) ) {
links[ rel ].parameters = parameters;
}
}

@@ -207,0 +219,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