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

@architect/parser

Package Overview
Dependencies
Maintainers
4
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/parser - npm Package Compare versions

Comparing version 2.1.1-RC.0 to 2.1.1-RC.1

2

package.json
{
"name": "@architect/parser",
"version": "2.1.1-RC.0",
"version": "2.1.1-RC.1",
"description": "Architect Parser accepts plaintext, JSON, or YAML .arc manifests and returns a plain JavaScript Object",

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

@@ -6,3 +6,3 @@ let Ajv = require('./ajv-6.10.2')

* @param {object} arc
* @returns {boolean|array} returns either 'false' or an array of errors
* @returns {boolean|string} returns either 'false' or a string of errors
*/

@@ -12,3 +12,55 @@ module.exports = function validate(arc) {

let valid = defn.validate(schema, arc)
return valid? false : defn.errors
let isValid = valid && !defn.errors
let isInvalid = !valid && defn.errors
if (isValid) {
return false
}
else if (isInvalid) {
let message = ['Architect schema validation error']
let unknownErrors = 0
let findPragma = /\w+(?=\[)/
let findPosition = /(?<=[\[])\d+(?=[\]])/
let pragmas = {
app: 'app name',
aws: 'setting',
events: 'event',
http: 'route',
indexes: 'index or key',
macros: 'macro',
queues: 'event',
scheduled: 'event',
static: 'setting',
tables: 'table or key',
ws: 'route',
}
for (let error of defn.errors) {
try {
// Suss out the pragma and position of the offending statement
let pragma = error.dataPath.match(findPragma)[0]
let position = error.dataPath.match(findPosition)[0]
let offender = arc[pragma][position]
// Depending on what the user did we may get strings, arrays, or objects
if (Array.isArray(offender)) {
offender = offender.join(' ')
}
else if (offender instanceof Object) {
offender = Object.keys(offender)[position]
}
let msg = ` @${pragma} invalid ${pragmas[pragma]}: "${offender}"`
if (!message.includes(msg)) message.push(msg)
}
catch (err) {
++unknownErrors
}
}
if (message.length > 2) message[0] += 's'
if (unknownErrors) message.push(` ${unknownErrors} unknown validation error${unknownErrors > 1 ? 's' : ''}`)
return message.join('\n')
}
// Shouldn't be possible but jic ajv does something funky
else throw Error('Invalid error reporting state')
}
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