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

docworks-jsdoc2spec

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docworks-jsdoc2spec - npm Package Compare versions

Comparing version 1.6.0 to 1.6.2

15

dist/docworks-plugins.js

@@ -7,3 +7,3 @@ "use strict";

exports.default = handlePlugins;
function handlePlugins(plugins, pluginFunction, doclet) {
function handlePlugins(plugins, pluginFunction, doclet, element) {
var extra = {};

@@ -14,7 +14,14 @@ if (plugins) {

}).forEach(function (plugin) {
var extraValue = plugin[pluginFunction](doclet);
if (extraValue) extra[plugin.extendDocworksKey] = extraValue;
var pluginResult = plugin[pluginFunction](doclet, element);
if (pluginResult) {
var extraValue = pluginResult.extraValue,
newElement = pluginResult.element;
if (extraValue) extra[plugin.extendDocworksKey] = extraValue;
element = newElement || element;
}
});
}
return extra;
element.extra = extra;
return element;
}

@@ -42,6 +42,6 @@ 'use strict';

var extra = (0, _docworksPlugins2.default)(plugins, 'extendDocworksMessage', message);
return (0, _docworksModel.Message)(message.name, [], members, messages.map(function (mes) {
var messageElement = (0, _docworksModel.Message)(message.name, [], members, messages.map(function (mes) {
return (0, _jsdocHandlerShared.handleMeta)(mes.meta);
}), (0, _jsdocHandlerShared.handleDoc)(message, plugins), extra);
}), (0, _jsdocHandlerShared.handleDoc)(message, plugins));
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksMessage', message, messageElement);
}

@@ -48,0 +48,0 @@ };

@@ -59,6 +59,6 @@ 'use strict';

// todo handle name params
var extra = (0, _docworksPlugins2.default)(plugins, kind === 'Operation' ? 'extendDocworksOperation' : 'extendDocworksCallback', func);
return (0, _docworksModel.Operation)(func.name, [], [], params, ret, funcs.map(function (func) {
var operation = (0, _docworksModel.Operation)(func.name, [], [], params, ret, funcs.map(function (func) {
return (0, _jsdocHandlerShared.handleMeta)(func.meta);
}), (0, _jsdocHandlerShared.handleDoc)(func, plugins), extra);
}), (0, _jsdocHandlerShared.handleDoc)(func, plugins));
return (0, _docworksPlugins2.default)(plugins, kind === 'Operation' ? 'extendDocworksOperation' : 'extendDocworksCallback', func, operation);
}

@@ -65,0 +65,0 @@ };

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

@@ -27,73 +27,79 @@ exports.default = handleProperties;

var extractMembers = function extractMembers(find, onError, plugins) {
return function (member) {
// handle read property
var location = (0, _jsdocHandlerShared.handleMeta)(member.meta);
var context = (0, _jsdocHandlerShared.typeContext)('Property', member.name, '', member.memberof, location);
var extra = (0, _docworksPlugins2.default)(plugins, 'extendDocworksProperty', member);
var defaultValue = member.defaultvalue;
if (member.type) return (0, _docworksModel.Property)(member.name, [], true, false, (0, _jsdocHandlerShared.handleType)(member.type, find, onError, context), defaultValue, [location], (0, _jsdocHandlerShared.handleDoc)(member, plugins), extra);
return function (member) {
// handle read property
var location = (0, _jsdocHandlerShared.handleMeta)(member.meta);
var context = (0, _jsdocHandlerShared.typeContext)('Property', member.name, '', member.memberof, location);
var defaultValue = member.defaultvalue;
if (member.type) {
var _property = (0, _docworksModel.Property)(member.name, [], true, false, (0, _jsdocHandlerShared.handleType)(member.type, find, onError, context), defaultValue, [location], (0, _jsdocHandlerShared.handleDoc)(member, plugins));
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksProperty', member, _property);
}
// handle write property
if (member.params && member.params.length > 0) return (0, _docworksModel.Property)(member.name, [], false, true, (0, _jsdocHandlerShared.handleType)(member.params[0].type, find, onError, context), defaultValue, [location], (0, _jsdocHandlerShared.handleDoc)(member, plugins), extra);
// handle write property
if (member.params && member.params.length > 0) {
var _property2 = (0, _docworksModel.Property)(member.name, [], false, true, (0, _jsdocHandlerShared.handleType)(member.params[0].type, find, onError, context), defaultValue, [location], (0, _jsdocHandlerShared.handleDoc)(member, plugins));
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksProperty', member, _property2);
}
onError((0, _docworksModel.JsDocError)('Property ' + member.name + ' is missing a type annotation', [location]));
return (0, _docworksModel.Property)(member.name, [], false, false, _docworksModel.Void, defaultValue, [location], (0, _jsdocHandlerShared.handleDoc)(member, plugins), extra);
};
onError((0, _docworksModel.JsDocError)('Property ' + member.name + ' is missing a type annotation', [location]));
var property = (0, _docworksModel.Property)(member.name, [], false, false, _docworksModel.Void, defaultValue, [location], (0, _jsdocHandlerShared.handleDoc)(member, plugins));
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksProperty', member, property);
};
};
var groupByName = function groupByName(groups, property) {
if (!property) return groups;
if (groups[property.name]) groups[property.name].push(property);else groups[property.name] = [property];
return groups;
if (!property) return groups;
if (groups[property.name]) groups[property.name].push(property);else groups[property.name] = [property];
return groups;
};
var mergeProperties = function mergeProperties(service, onError) {
return function (properties) {
var _ref;
return function (properties) {
var _ref;
var prop1 = properties[0];
if (properties.length === 1) {
if (prop1.set && !prop1.get) onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' is a write only property', prop1.locations));
var prop1 = properties[0];
if (properties.length === 1) {
if (prop1.set && !prop1.get) onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' is a write only property', prop1.locations));
return prop1;
}
if (properties.length === 2) {
return prop1;
}
if (properties.length === 2) {
var prop2 = properties[1];
var extra = Object.assign({}, prop1.extra, prop2.extra);
var _locations = prop1.locations.concat(prop2.locations);
if ((0, _lodash2.default)(prop1.type, prop2.type) && prop1.get !== prop2.get && prop1.set !== prop2.set) {
var docs = prop1.get ? prop1.docs : prop2.docs;
return (0, _docworksModel.Property)(prop1.name, [], true, true, prop1.type, prop1.defaultValue, _locations, docs, extra);
}
var prop2 = properties[1];
var extra = Object.assign({}, prop1.extra, prop2.extra);
var _locations = prop1.locations.concat(prop2.locations);
if ((0, _lodash2.default)(prop1.type, prop2.type) && prop1.get !== prop2.get && prop1.set !== prop2.set) {
var docs = prop1.get ? prop1.docs : prop2.docs;
return (0, _docworksModel.Property)(prop1.name, [], true, true, prop1.type, prop1.defaultValue, _locations, docs, extra);
}
if (!(0, _lodash2.default)(prop1.type, prop2.type) && prop1.get !== prop2.get && prop1.set !== prop2.set) {
onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' has mismatching types for get (' + prop1.type + ') and set (' + prop2.type + ')', _locations));
var _docs = prop1.get ? prop1.docs : prop2.docs;
return (0, _docworksModel.Property)(prop1.name, [], true, true, prop1.type, prop1.defaultValue, _locations, _docs, extra);
}
if (!(0, _lodash2.default)(prop1.type, prop2.type) && prop1.get !== prop2.get && prop1.set !== prop2.set) {
onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' has mismatching types for get (' + prop1.type + ') and set (' + prop2.type + ')', _locations));
var _docs = prop1.get ? prop1.docs : prop2.docs;
return (0, _docworksModel.Property)(prop1.name, [], true, true, prop1.type, prop1.defaultValue, _locations, _docs, extra);
}
onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' is defined two or more times', _locations));
return (0, _docworksModel.Property)(prop1.name, [], true, true, prop1.type, prop1.defaultValue, _locations, prop1.docs, prop1.extra);
}
var locations = (_ref = []).concat.apply(_ref, _toConsumableArray(properties.map(function (_) {
return _.locations;
})));
onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' is defined two or more times', locations));
return prop1;
};
onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' is defined two or more times', _locations));
return (0, _docworksModel.Property)(prop1.name, [], true, true, prop1.type, prop1.defaultValue, _locations, prop1.docs, prop1.extra);
}
var locations = (_ref = []).concat.apply(_ref, _toConsumableArray(properties.map(function (_) {
return _.locations;
})));
onError((0, _docworksModel.JsDocError)('Property ' + prop1.name + ' is defined two or more times', locations));
return prop1;
};
};
function handleProperties(find, service, onError, plugins) {
var members = find({ kind: 'member', memberof: service.longname });
if (!members) return [];
var members = find({ kind: 'member', memberof: service.longname });
if (!members) return [];
members = members.filter(function (_) {
return !_.mixed;
});
members = members.filter(function (_) {
return !_.mixed;
});
var groups = members.map(extractMembers(find, onError, plugins)).reduce(groupByName, {});
return Object.keys(groups).map(function (group) {
return groups[group];
}).map(mergeProperties(service, onError));
var groups = members.map(extractMembers(find, onError, plugins)).reduce(groupByName, {});
return Object.keys(groups).map(function (group) {
return groups[group];
}).map(mergeProperties(service, onError));
}

@@ -106,10 +106,12 @@ 'use strict';

var examples = rawExamples.map(function (ex) {
var exExtra = (0, _docworksPlugins2.default)(plugins, 'extendDocworksDocsExample', ex);
var found = void 0;
var example = void 0;
if (found = exampleCaption.exec(ex)) {
return (0, _docworksModel.Example)(found[1], found[2].trim(), exExtra);
} else return (0, _docworksModel.Example)(undefined, ex, exExtra);
example = (0, _docworksModel.Example)(found[1], found[2].trim());
} else example = (0, _docworksModel.Example)(undefined, ex);
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksDocsExample', ex, example);
});
var extra = (0, _docworksPlugins2.default)(plugins, 'extendDocworksDocs', doclet);
return (0, _docworksModel.Docs)(doclet.summary, doclet.description || doclet.classdesc, doclet.see ? doclet.see : [], examples, extra);
var docs = (0, _docworksModel.Docs)(doclet.summary, doclet.description || doclet.classdesc, doclet.see ? doclet.see : [], examples);
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksDocs', doclet, docs);
}

@@ -71,5 +71,5 @@ 'use strict';

var docs = (0, _jsdocHandlerShared.handleDoc)(serviceDoclet, plugins);
var extra = (0, _docworksPlugins2.default)(plugins, 'extendDocworksService', serviceDoclet);
return (0, _docworksModel.Service)(serviceDoclet.name, serviceDoclet.memberof, mixes, [], properties, operations, callbacks, messages, location, docs, extra);
var service = (0, _docworksModel.Service)(serviceDoclet.name, serviceDoclet.memberof, mixes, [], properties, operations, callbacks, messages, location, docs);
return (0, _docworksPlugins2.default)(plugins, 'extendDocworksService', serviceDoclet, service);
};
}
export default function handlePlugins(plugins, pluginFunction, doclet) {
export default function handlePlugins(plugins, pluginFunction, doclet, element) {
let extra = {};

@@ -8,8 +8,13 @@ if (plugins) {

.forEach(plugin => {
let extraValue = plugin[pluginFunction](doclet);
if (extraValue)
extra[plugin.extendDocworksKey] = extraValue;
const pluginResult = plugin[pluginFunction](doclet, element);
if (pluginResult) {
let {extraValue, element: newElement} = pluginResult;
if (extraValue)
extra[plugin.extendDocworksKey] = extraValue;
element = newElement || element;
}
})
}
return extra;
element.extra = extra;
return element;
}

@@ -32,4 +32,4 @@ import {handleMeta, handleType, typeContext, handleDoc} from './jsdoc-handler-shared';

let extra = handlePlugins(plugins, 'extendDocworksMessage', message);
return Message(message.name, [], members, messages.map(mes => handleMeta(mes.meta)), handleDoc(message, plugins), extra);
const messageElement = Message(message.name, [], members, messages.map(mes => handleMeta(mes.meta)), handleDoc(message, plugins));
return handlePlugins(plugins, 'extendDocworksMessage', message, messageElement);
}

@@ -36,0 +36,0 @@ };

@@ -59,4 +59,4 @@ import {handleMeta, handleType, typeContext, handleDoc} from './jsdoc-handler-shared';

// todo handle name params
let extra = handlePlugins(plugins, (kind==='Operation')?'extendDocworksOperation':'extendDocworksCallback', func);
return Operation(func.name, [], [], params, ret, funcs.map(func => handleMeta(func.meta)), handleDoc(func, plugins), extra);
const operation = Operation(func.name, [], [], params, ret, funcs.map(func => handleMeta(func.meta)), handleDoc(func, plugins));
return handlePlugins(plugins, (kind==='Operation')?'extendDocworksOperation':'extendDocworksCallback', func, operation);
}

@@ -63,0 +63,0 @@ };

@@ -9,72 +9,75 @@ import {Property, Void, JsDocError} from 'docworks-model';

const extractMembers = (find, onError, plugins) => (member) => {
// handle read property
let location = handleMeta(member.meta);
let context = typeContext('Property', member.name, '', member.memberof, location);
let extra = handlePlugins(plugins, 'extendDocworksProperty', member);
let defaultValue = member.defaultvalue;
if (member.type)
return Property(member.name, [], true, false, handleType(member.type, find, onError, context), defaultValue, [location], handleDoc(member, plugins), extra);
// handle read property
let location = handleMeta(member.meta);
let context = typeContext('Property', member.name, '', member.memberof, location);
let defaultValue = member.defaultvalue;
if (member.type) {
let property = Property(member.name, [], true, false, handleType(member.type, find, onError, context), defaultValue, [location], handleDoc(member, plugins));
return handlePlugins(plugins, 'extendDocworksProperty', member, property);
}
// handle write property
if (member.params && member.params.length > 0)
return Property(member.name, [], false, true, handleType(member.params[0].type, find, onError, context), defaultValue, [location], handleDoc(member, plugins), extra);
// handle write property
if (member.params && member.params.length > 0) {
let property = Property(member.name, [], false, true, handleType(member.params[0].type, find, onError, context), defaultValue, [location], handleDoc(member, plugins));
return handlePlugins(plugins, 'extendDocworksProperty', member, property);
}
onError(JsDocError(`Property ${member.name} is missing a type annotation`, [location]));
return Property(member.name, [], false, false, Void, defaultValue, [location], handleDoc(member, plugins), extra);
onError(JsDocError(`Property ${member.name} is missing a type annotation`, [location]));
let property = Property(member.name, [], false, false, Void, defaultValue, [location], handleDoc(member, plugins));
return handlePlugins(plugins, 'extendDocworksProperty', member, property);
};
const groupByName = (groups, property) => {
if (!property)
return groups;
if (groups[property.name])
groups[property.name].push(property);
else
groups[property.name] = [property];
if (!property)
return groups;
if (groups[property.name])
groups[property.name].push(property);
else
groups[property.name] = [property];
return groups;
};
const mergeProperties = (service, onError) => (properties) => {
let prop1 = properties[0];
if (properties.length === 1) {
if (prop1.set && !prop1.get)
onError(JsDocError(
`Property ${prop1.name} is a write only property`,
prop1.locations));
let prop1 = properties[0];
if (properties.length === 1) {
if (prop1.set && !prop1.get)
onError(JsDocError(
`Property ${prop1.name} is a write only property`,
prop1.locations));
return prop1;
return prop1;
}
if (properties.length === 2) {
let prop2 = properties[1];
let extra = Object.assign({}, prop1.extra, prop2.extra);
let locations = prop1.locations.concat(prop2.locations);
if (isEqual(prop1.type, prop2.type) &&
prop1.get !== prop2.get &&
prop1.set !== prop2.set) {
let docs = prop1.get?prop1.docs:prop2.docs;
return Property(prop1.name, [], true, true, prop1.type, prop1.defaultValue, locations, docs, extra);
}
if (properties.length === 2) {
let prop2 = properties[1];
let extra = Object.assign({}, prop1.extra, prop2.extra);
let locations = prop1.locations.concat(prop2.locations);
if (isEqual(prop1.type, prop2.type) &&
prop1.get !== prop2.get &&
prop1.set !== prop2.set) {
let docs = prop1.get?prop1.docs:prop2.docs;
return Property(prop1.name, [], true, true, prop1.type, prop1.defaultValue, locations, docs, extra);
}
if (!isEqual(prop1.type, prop2.type) &&
prop1.get !== prop2.get &&
prop1.set !== prop2.set) {
onError(JsDocError(
`Property ${prop1.name} has mismatching types for get (${prop1.type}) and set (${prop2.type})`,
locations));
let docs = prop1.get?prop1.docs:prop2.docs;
return Property(prop1.name, [], true, true, prop1.type, prop1.defaultValue, locations, docs, extra)
}
if (!isEqual(prop1.type, prop2.type) &&
prop1.get !== prop2.get &&
prop1.set !== prop2.set) {
onError(JsDocError(
`Property ${prop1.name} has mismatching types for get (${prop1.type}) and set (${prop2.type})`,
locations));
let docs = prop1.get?prop1.docs:prop2.docs;
return Property(prop1.name, [], true, true, prop1.type, prop1.defaultValue, locations, docs, extra)
}
onError(JsDocError(
`Property ${prop1.name} is defined two or more times`,
locations));
return Property(prop1.name, [], true, true, prop1.type, prop1.defaultValue, locations, prop1.docs, prop1.extra)
onError(JsDocError(
`Property ${prop1.name} is defined two or more times`,
locations));
return Property(prop1.name, [], true, true, prop1.type, prop1.defaultValue, locations, prop1.docs, prop1.extra)
}
let locations = [].concat(...properties.map(_ => _.locations));
onError(JsDocError(
`Property ${prop1.name} is defined two or more times`,
locations));
return prop1;
}
let locations = [].concat(...properties.map(_ => _.locations));
onError(JsDocError(
`Property ${prop1.name} is defined two or more times`,
locations));
return prop1;
};

@@ -84,5 +87,5 @@

export default function handleProperties(find, service, onError, plugins) {
let members = find({kind: 'member', memberof: service.longname});
if(!members)
return [];
let members = find({kind: 'member', memberof: service.longname});
if(!members)
return [];

@@ -93,7 +96,7 @@

let groups = members.map(extractMembers(find, onError, plugins))
.reduce(groupByName, {});
return Object.keys(groups)
.map((group) => groups[group])
.map(mergeProperties(service, onError));
.reduce(groupByName, {});
return Object.keys(groups)
.map((group) => groups[group])
.map(mergeProperties(service, onError));
}

@@ -96,12 +96,14 @@ import {Void, Location, JsDocError, GeneticType, Docs, Example} from 'docworks-model';

let examples = rawExamples.map((ex) => {
let exExtra = handlePlugins(plugins, 'extendDocworksDocsExample', ex);
let found;
let example;
if (found = exampleCaption.exec(ex)) {
return Example(found[1], found[2].trim(), exExtra)
example = Example(found[1], found[2].trim())
}
else
return Example(undefined, ex, exExtra);
example = Example(undefined, ex);
return handlePlugins(plugins, 'extendDocworksDocsExample', ex, example);
});
let extra = handlePlugins(plugins, 'extendDocworksDocs', doclet);
return Docs(doclet.summary, doclet.description || doclet.classdesc, doclet.see?doclet.see:[], examples, extra);
const docs = Docs(doclet.summary, doclet.description || doclet.classdesc, doclet.see?doclet.see:[], examples);
return handlePlugins(plugins, 'extendDocworksDocs', doclet, docs);
}

@@ -46,6 +46,6 @@ import helper from 'jsdoc/util/templateHelper';

let docs = handleDoc(serviceDoclet, plugins);
let extra = handlePlugins(plugins, 'extendDocworksService', serviceDoclet);
return Service(serviceDoclet.name, serviceDoclet.memberof, mixes, [], properties, operations, callbacks, messages, location, docs, extra);
let service = Service(serviceDoclet.name, serviceDoclet.memberof, mixes, [], properties, operations, callbacks, messages, location, docs);
return handlePlugins(plugins, 'extendDocworksService', serviceDoclet, service);
}
}
{
"name": "docworks-jsdoc2spec",
"version": "1.6.0",
"version": "1.6.2",
"description": "extractor for jsdoc apis to api spec",

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

@@ -0,26 +1,29 @@

import {Example, Docs} from 'docworks-model';
exports.extendDocworksKey = 'pluginGenerated';
exports.extendDocworksService = function(doclet) {
return 'service plugin visited'
exports.extendDocworksService = function(doclet, service) {
return {extraValue: 'service plugin visited'}
};
exports.extendDocworksProperty = function(doclet) {
return 'property plugin visited'
exports.extendDocworksProperty = function(doclet, property) {
return {extraValue: 'property plugin visited'}
};
exports.extendDocworksOperation = function(doclet) {
return 'operation plugin visited'
exports.extendDocworksOperation = function(doclet, operation) {
return {extraValue: 'operation plugin visited'}
};
exports.extendDocworksMessage = function(doclet) {
return 'message plugin visited'
exports.extendDocworksMessage = function(doclet, message) {
return {extraValue: 'message plugin visited'}
};
exports.extendDocworksDocs = function(doclet) {
return 'docs plugin visited'
exports.extendDocworksDocs = function(doclet, docs) {
const newDocs = Docs('plugin updated summary', docs.description, docs.links, docs.examples);
return {extraValue: 'docs plugin visited', element: newDocs}
};
exports.extendDocworksDocsExample = function(doclet) {
return 'example plugin visited'
exports.extendDocworksDocsExample = function(doclet, example) {
const newExample = Example(example.title, 'plugin updated body');
return {extraValue: 'example plugin visited', element: newExample}
};

@@ -22,4 +22,5 @@ import runJsDoc from '../lib/jsdoc-runner';

docs: {
summary: 'plugin updated summary',
examples: [
{title: 'name', body: 'the example', extra: {pluginGenerated: 'example plugin visited'}}],
{title: 'name', body: 'plugin updated body', extra: {pluginGenerated: 'example plugin visited'}}],
extra: {pluginGenerated: 'docs plugin visited'}}}

@@ -32,3 +33,3 @@ ],

examples: [
{title: 'name', body: 'the example', extra: {pluginGenerated: 'example plugin visited'}}],
{title: 'name', body: 'plugin updated body', extra: {pluginGenerated: 'example plugin visited'}}],
extra: {pluginGenerated: 'docs plugin visited'}}}

@@ -41,3 +42,3 @@ ],

examples: [
{title: 'name', body: 'the example', extra: {pluginGenerated: 'example plugin visited'}}],
{title: 'name', body: 'plugin updated body', extra: {pluginGenerated: 'example plugin visited'}}],
extra: {pluginGenerated: 'docs plugin visited'}}}

@@ -48,3 +49,3 @@ ],

examples: [
{title: 'name', body: 'the example', extra: {pluginGenerated: 'example plugin visited'}}],
{title: 'name', body: 'plugin updated body', extra: {pluginGenerated: 'example plugin visited'}}],
extra: {pluginGenerated: 'docs plugin visited'}}

@@ -51,0 +52,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