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

@asyncapi/parser

Package Overview
Dependencies
Maintainers
3
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/parser - npm Package Compare versions

Comparing version 0.25.0 to 0.25.1

2

lib/customValidators.js

@@ -119,3 +119,3 @@ const ParserError = require('./errors/parser-error');

operations.forEach(opName => {
const op = chnlObj[opName];
const op = chnlObj[String(opName)];
if (op) addDuplicateToMap(op, chnlName, opName);

@@ -122,0 +122,0 @@ });

@@ -1,2 +0,2 @@

const { createMapOfType, getMapKeyOfType, addExtensions } = require('../utils');
const { createMapOfType, getMapValueOfType, addExtensions } = require('../utils');
const Base = require('./base');

@@ -8,2 +8,3 @@ const Info = require('./info');

const Tag = require('./tag');
const xParserMessageName = 'x-parser-message-name';

@@ -70,3 +71,3 @@ const xParserSchemaId = 'x-parser-schema-id';

server(name) {
return getMapKeyOfType(this._json.servers, name, Server);
return getMapValueOfType(this._json.servers, name, Server);
}

@@ -101,3 +102,3 @@

channel(name) {
return getMapKeyOfType(this._json.channels, name, Channel, this);
return getMapValueOfType(this._json.channels, name, Channel, this);
}

@@ -205,3 +206,3 @@

if (m.name() === undefined) {
m.json()[xParserMessageName] = key;
m.json()[String(xParserMessageName)] = key;
}

@@ -221,3 +222,3 @@ }

for (const [parameterKey, parameterSchema] of Object.entries(channel.parameters())) {
parameterSchema.json()[xParserSchemaId] = parameterKey;
parameterSchema.json()[String(xParserSchemaId)] = parameterKey;
}

@@ -235,3 +236,3 @@ });

for (const [key, s] of Object.entries(doc.components().schemas())) {
s.json()[xParserSchemaId] = key;
s.json()[String(xParserSchemaId)] = key;
}

@@ -266,3 +267,3 @@ }

if (m.name() === undefined) {
m.json()[xParserMessageName] = `<anonymous-message-${number}>`;
m.json()[String(xParserMessageName)] = `<anonymous-message-${number}>`;
}

@@ -372,3 +373,3 @@ });

if (!schema.uid()) {
schema.json()[xParserSchemaId] = `<anonymous-schema-${++anonymousSchemaCounter}>`;
schema.json()[String(xParserSchemaId)] = `<anonymous-schema-${++anonymousSchemaCounter}>`;
}

@@ -375,0 +376,0 @@ };

@@ -20,3 +20,3 @@ const ParserError = require('../errors/parser-error');

if (!this._json) return;
return this._json[key];
return this._json[String(key)];
}

@@ -23,0 +23,0 @@ }

@@ -1,2 +0,2 @@

const { createMapOfType, getMapKeyOfType, addExtensions } = require('../utils');
const { createMapOfType, getMapValueOfType, getMapValueByKey, addExtensions } = require('../utils');
const Base = require('./base');

@@ -33,3 +33,3 @@ const ChannelParameter = require('./channel-parameter');

parameter(name) {
return getMapKeyOfType(this._json.parameters, name, ChannelParameter);
return getMapValueOfType(this._json.parameters, name, ChannelParameter);
}

@@ -86,3 +86,3 @@

binding(name) {
return this._json.bindings ? this._json.bindings[name] : null;
return getMapValueByKey(this._json.bindings, name);
}

@@ -89,0 +89,0 @@ }

@@ -1,2 +0,2 @@

const { getMapKeyOfType, createMapOfType, addExtensions } = require('../utils');
const { createMapOfType, getMapValueOfType, addExtensions } = require('../utils');
const Base = require('./base');

@@ -29,3 +29,3 @@ const Message = require('./message');

message(name) {
return getMapKeyOfType(this._json.messages, name, Message);
return getMapValueOfType(this._json.messages, name, Message);
}

@@ -44,3 +44,3 @@

schema(name) {
return getMapKeyOfType(this._json.schemas, name, Schema);
return getMapValueOfType(this._json.schemas, name, Schema);
}

@@ -59,3 +59,3 @@

securityScheme(name) {
return getMapKeyOfType(this._json.securitySchemes, name, SecurityScheme);
return getMapValueOfType(this._json.securitySchemes, name, SecurityScheme);
}

@@ -74,3 +74,3 @@

parameter(name) {
return getMapKeyOfType(this._json.parameters, name, ChannelParameter);
return getMapValueOfType(this._json.parameters, name, ChannelParameter);
}

@@ -89,3 +89,3 @@

correlationId(name) {
return getMapKeyOfType(this._json.correlationIds, name, CorrelationId);
return getMapValueOfType(this._json.correlationIds, name, CorrelationId);
}

@@ -104,3 +104,3 @@

operationTrait(name) {
return getMapKeyOfType(this._json.operationTraits, name, OperationTrait);
return getMapValueOfType(this._json.operationTraits, name, OperationTrait);
}

@@ -119,3 +119,3 @@

messageTrait(name) {
return getMapKeyOfType(this._json.messageTraits, name, MessageTrait);
return getMapValueOfType(this._json.messageTraits, name, MessageTrait);
}

@@ -122,0 +122,0 @@ }

@@ -1,2 +0,2 @@

const { getMapKeyOfType, addExtensions } = require('../utils');
const { getMapValueOfType, getMapValueByKey, addExtensions } = require('../utils');
const Base = require('./base');

@@ -29,3 +29,3 @@ const Tag = require('./tag');

if (!this._json.headers) return null;
return getMapKeyOfType(this._json.headers.properties, name, Schema);
return getMapValueOfType(this._json.headers.properties, name, Schema);
}

@@ -118,3 +118,3 @@

binding(name) {
return this._json.bindings ? this._json.bindings[name] : null;
return getMapValueByKey(this._json.bindings, name);
}

@@ -121,0 +121,0 @@

@@ -1,2 +0,2 @@

const { addExtensions } = require('../utils');
const { getMapValueByKey, addExtensions } = require('../utils');
const Base = require('./base');

@@ -69,3 +69,3 @@ const Tag = require('./tag');

binding(name) {
return this._json.bindings ? this._json.bindings[name] : null;
return getMapValueByKey(this._json.bindings, name);
}

@@ -72,0 +72,0 @@ }

@@ -33,6 +33,6 @@ const OperationTraitable = require('./operation-traitable');

message(index) {
if (!this._json.message) return null;
if (typeof index !== 'number' || !this._json.message) return null;
if (!this._json.message.oneOf) return new Message(this._json.message);
if (index > this._json.message.oneOf.length - 1) return null;
return new Message(this._json.message.oneOf[index]);
return new Message(this._json.message.oneOf[+index]);
}

@@ -39,0 +39,0 @@ }

@@ -235,8 +235,4 @@ const { createMapOfType, addExtensions } = require('../utils');

const result = {};
Object.keys(this._json.dependencies).forEach(k => {
if (!Array.isArray(this._json.dependencies[k])) {
result[k] = new Schema(this._json.dependencies[k]);
} else {
result[k] = this._json.dependencies[k];
}
Object.entries(this._json.dependencies).forEach(([key, value]) => {
result[String(key)] = !Array.isArray(value) ? new Schema(value) : value;
});

@@ -243,0 +239,0 @@ return result;

@@ -1,2 +0,2 @@

const { createMapOfType, getMapKeyOfType, addExtensions } = require('../utils');
const { createMapOfType, getMapValueOfType, getMapValueByKey, addExtensions } = require('../utils');
const Base = require('./base');

@@ -53,3 +53,3 @@ const ServerVariable = require('./server-variable');

variable(name) {
return getMapKeyOfType(this._json.variables, name, ServerVariable);
return getMapValueOfType(this._json.variables, name, ServerVariable);
}

@@ -84,3 +84,3 @@

binding(name) {
return this._json.bindings ? this._json.bindings[name] : null;
return getMapValueByKey(this._json.bindings, name);
}

@@ -87,0 +87,0 @@ }

@@ -158,9 +158,8 @@ const path = require('path');

for (const channelName in js.channels) {
const channel = js.channels[channelName];
const convert = OPERATIONS.map(async (opName) => {
const op = channel[opName];
const promisesArray = [];
Object.entries(js.channels).forEach(([channelName, channel]) => {
promisesArray.push(...OPERATIONS.map(async (opName) => {
const op = channel[String(opName)];
if (op) {
const messages = op.message ? (op.message.oneOf || [op.message]) : [];
const pathToPayload = `/channels/${ channelName }/${ opName }/message/payload`;
if (options.applyTraits) {

@@ -170,2 +169,3 @@ applyTraits(op);

}
const pathToPayload = `/channels/${channelName}/${opName}/message/payload`;
for (const m of messages) {

@@ -175,5 +175,5 @@ await validateAndConvertMessage(m, asyncapiYAMLorJSON, initialFormat, js, pathToPayload);

}
});
await Promise.all(convert);
}
}));
});
await Promise.all(promisesArray);
}

@@ -184,3 +184,3 @@

await PARSERS[schemaFormat]({
await PARSERS[String(schemaFormat)]({
schemaFormat,

@@ -215,3 +215,3 @@ message: msg,

parserModule.getMimeTypes().forEach((schemaFormat) => {
PARSERS[schemaFormat] = parserModule.parse;
PARSERS[String(schemaFormat)] = parserModule.parse;
});

@@ -224,3 +224,3 @@ }

for (const key in trait) {
js[key] = mergePatch(js[key], trait[key]);
js[String(key)] = mergePatch(js[String(key)], trait[String(key)]);
}

@@ -227,0 +227,0 @@ }

@@ -52,2 +52,4 @@ const YAML = require('js-yaml');

if (initialFormat === 'yaml') {
// disable eslint because loc is a Symbol
// eslint-disable-next-line security/detect-object-injection
info = node[loc];

@@ -72,10 +74,17 @@ } else if (initialFormat === 'json') {

const traverse = function (o, fn, scope = []) {
for (const i in o) {
fn.apply(this, [i, o[i], scope]);
if (o[i] !== null && typeof o[i] === 'object') {
traverse(o[i], fn, scope.concat(i));
Object.entries(o).forEach(([key,value]) => {
fn.apply(this, [key, value, scope]);
if (value !== null && typeof value === 'object') {
traverse(value, fn, scope.concat(key));
}
}
});
};
const getMapValue = (obj, key, Type) => {
if (typeof key !== 'string' || !obj) return null;
const v = obj[String(key)];
if (v === undefined) return null;
return Type ? new Type(v) : v;
};
utils.tilde = (str) => {

@@ -167,4 +176,4 @@ return str.replace(/[~\/]{1}/g, (m) => {

Object.keys(obj).forEach(key => {
result[key] = new Type(obj[key]);
Object.entries(obj).forEach(([key, value]) => {
result[String(key)] = new Type(value);
});

@@ -175,14 +184,16 @@

utils.getMapKeyOfType = (obj, key, Type) => {
if (!obj) return null;
if (!obj[key]) return null;
return new Type(obj[key]);
utils.getMapValueOfType = (obj, key, Type) => {
return getMapValue(obj, key, Type);
};
utils.getMapValueByKey = (obj, key) => {
return getMapValue(obj, key);
};
utils.addExtensions = (obj) => {
obj.prototype.extensions = function () {
const result = {};
Object.keys(this._json).forEach(key => {
Object.entries(this._json).forEach(([key, value]) => {
if ((/^x-[\w\d\.\-\_]+$/).test(key)) {
result[key] = this._json[key];
result[String(key)] = value;
}

@@ -194,3 +205,3 @@ });

obj.prototype.ext = function (name) {
return this._json[name];
return this._json[String(name)];
};

@@ -197,0 +208,0 @@

{
"name": "@asyncapi/parser",
"version": "0.25.0",
"version": "0.25.1",
"description": "JavaScript AsyncAPI parser.",

@@ -41,4 +41,5 @@ "main": "lib/index.js",

"conventional-changelog-conventionalcommits": "^4.2.3",
"eslint": "^6.8.0",
"eslint": "^7.0.0",
"eslint-plugin-mocha": "^7.0.1",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-sonarjs": "^0.5.0",

@@ -45,0 +46,0 @@ "jsdoc-to-markdown": "^5.0.0",

@@ -5,2 +5,3 @@ const { expect } = require('chai');

const path = require('path');
describe('AsyncAPIDocument', function() {

@@ -7,0 +8,0 @@ describe('assignUidToParameterSchemas()', function() {

@@ -1,2 +0,1 @@

/* eslint-disable sonarjs/no-duplicate-string */
const { EOL } = require('os');

@@ -3,0 +2,0 @@ const chai = require('chai');

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