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

apis-builder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apis-builder - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

ajv.js

65

index.js

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

const inflection = require('path-proxy/node_modules/inflection')
const pathProxy = require('path-proxy')
const promisifyCall = require('promisify-call')
const ajv = require('./ajv')
const _ = require('lodash')

@@ -24,3 +25,2 @@ class Builder {

const properties = action.properties
const requiredProps = action.required

@@ -43,3 +43,2 @@ // HACKY special case for members bulk add and send MIME endpoints

err = new Error(`Invalid number of params in path (expected ${pathParams.length}, got ${this.params.length}).`)
return fn(err)

@@ -52,18 +51,5 @@ }

// check required payload properties
if (requiredProps && requiredProps.length > 0) {
if (!data) {
err = new Error('Missing parameters.')
} else {
for (let i = 0; i < requiredProps.length; i++) {
const prop = requiredProps[i]
if (typeof data[prop] === 'undefined') {
err = new Error(`Missing parameter '${prop}'`)
break
}
}
}
}
let schema = { properties }
if (action.required) { schema.required = action.required }
err = ajv(schema, data)
if (err) {

@@ -73,30 +59,7 @@ return fn(err)

// check payload property types
for (const key in properties) {
if (data && data[key]) {
const type = properties[key].type
let dataType = typeof data[key]
if (Array.isArray(data[key])) {
dataType = 'array'
}
if (Array.isArray(type)) {
if (type.indexOf(dataType) === -1) {
err = new Error(`Invalid parameter type. ${key} must be of type: ${type}.`)
break
}
} else if (dataType !== type) {
err = new Error(`Invalid parameter type. ${key} must be of type: ${type}.`)
break
}
}
this.client = this.base
if (typeof this.client[action.method.toLowerCase()] !== 'function') {
console.error(`WARNING: 'this.client.${action.method.toLowerCase()}' is not a function`)
return
}
if (err) {
return fn(err)
}
this.client = this.base
return this.client[action.method.toLowerCase()](requestPath, data, fn)

@@ -109,14 +72,6 @@ }

constructor.prototype[getName(actionName)] = promisifed
constructor.prototype[_.camelCase(actionName)] = promisifed
}
}
function getName (name) {
name = name.toLowerCase()
name = inflection.dasherize(name).replace(/-/g, '_')
name = inflection.camelize(name, true)
return name
}
function build (baseObj, resources) {

@@ -123,0 +78,0 @@ const b = new Builder(baseObj, resources)

{
"name": "apis-builder",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/_mocha test/ --bail"
"test": "mocha test"
},

@@ -12,3 +12,4 @@ "author": "leeqiang <leesumiir@gmail.com>",

"dependencies": {
"inflection": "^1.12.0",
"ajv": "^6.4.0",
"lodash": "^4.17.5",
"path-proxy": "^1.0.0",

@@ -15,0 +16,0 @@ "promisify-call": "^2.0.4"

@@ -22,6 +22,19 @@ /* global describe, before, it */

}, {
description: '测试2',
description: '测试3',
href: '/tests/{id}/hello/path',
method: 'POST',
title: 'say'
}, {
description: '测试4',
href: '/tests/{id}:a',
method: 'GET',
title: 'get-by-id'
}, {
description: '测试5: ajv',
href: '/tests/{_id}:ajv',
method: 'GET',
title: 'ajv',
properties: {
_otherId: { type: 'string', format: 'objectid' }
}
}]

@@ -51,2 +64,19 @@ }

})
it('should ok get by id', function (done) {
let sdk = new SDK()
expect(typeof sdk.tests('123').getById === 'function').toBe(true)
done()
})
it('should ok ajv', async function () {
let sdk = new SDK()
try {
await sdk.tests('123').ajv({
_otherId: '123'
})
} catch (err) {
expect(err.message.includes('_otherId')).toBe(true)
}
})
})

Sorry, the diff of this file is not supported yet

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