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

p-odm

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-odm - npm Package Compare versions

Comparing version 3.0.10 to 3.1.0

155

lib/index.js

@@ -16,33 +16,4 @@ 'use strict';

var Validator = require('jsonschema');
var schema = new (require('jsonschema').Environment)();
function Environment() {
this.schemas = {};
return this;
}
Environment.prototype.addSchema = function (schema, urn) {
var ourUrn = urn;
if (!schema) {
return null;
}
if (!urn) {
ourUrn = schema.id;
}
if (ourUrn) {
this.schemas[ourUrn] = schema;
}
return this.schemas[ourUrn];
};
Environment.prototype.validate = function (instance, schema) {
var v = new Validator();
v.setSchemas(this.schemas);
return v.validate(instance, schema);
};
var schema = new Environment();
// lazy connector

@@ -274,4 +245,2 @@ var _collections = {};

callback(null, array);
// clean resources

@@ -281,2 +250,4 @@ if (!cursor.isClosed()) {

}
return callback(null, array);
});

@@ -445,15 +416,10 @@ });

graph: function (filename, schemas, callback) {
var header =
'digraph g {\n' +
'graph [rankdir = "LR"];\n' +
'node [fontsize = "10" shape = "ellipse"];\n' +
'edge [];\n';
subgraph: function (name, options, schemas) {
var records = '';
var references = '';
var subgraph = {
label: name,
records: '',
references: ''
};
// each reference must have a unique id
var refNum = 0;
// iterate through all collections in schemas

@@ -464,5 +430,5 @@ schemas.forEach(function (schema) {

// add table to record
records += '"' + collectionName + '" [\n';
subgraph.records += '"' + collectionName + '" [\n';
// begin fields
records += ' label = "<f0> ' + collectionName;
subgraph.records += ' label = "<f0> ' + collectionName;
var fieldNumber = 0;

@@ -473,2 +439,3 @@

var type;
var items;

@@ -486,6 +453,6 @@ for (propertyName in schema.properties) {

if (property.$ref === 'MongoDb#ObjectId') {
if (property.description) {
refNum++;
if (property.title) {
options.refNum++;
// add references
references += '"' + collectionName + '":f' + fieldNumber + ' -> "' + property.description + '":f0 [id = ' + refNum + '];\n';
subgraph.references += '"' + collectionName + '":f' + fieldNumber + ' -> "' + property.title + '":f0 [id = ' + options.refNum + '];\n';
}

@@ -496,13 +463,13 @@ }

if (property.type === 'array') {
var items = property.items;
type = property.items.type + '[]';
items = property.items;
type = items.type + '[]';
if (items.$ref) {
type = property.items.$ref + '[]';
type = items.$ref + '[]';
// only ObjectId props are dbrefs
if (items.$ref === 'MongoDb#ObjectId') {
if (items.description) {
refNum++;
if (items.title) {
options.refNum++;
// add references
references += '"' + collectionName + '":f' + fieldNumber + ' -> "' + items.description + '":f0 [id = ' + refNum + '];\n';
subgraph.references += '"' + collectionName + '":f' + fieldNumber + ' -> "' + items.title + '":f0 [id = ' + options.refNum + '];\n';
}

@@ -513,8 +480,51 @@ }

if (Array.isArray(property.type)) {
if (property.type.length === 2 && (property.type[0] === 'null' || property.type[1] === 'null')) {
// null or something
var prop;
if (property.type[0] === 'null') {
prop = property.type[1];
type = '?' + prop;
} else {
prop = property.type[0];
type = '?' + prop;
}
}
if (prop.$ref) {
type = '?' + prop.$ref;
// only ObjectId props are dbrefs
if (prop.$ref === 'MongoDb#ObjectId') {
if (prop.title) {
options.refNum++;
// add references
subgraph.references += '"' + collectionName + '":f' + fieldNumber + ' -> "' + prop.title + '":f0 [id = ' + options.refNum + '];\n';
}
}
}
if (prop.type === 'array') {
items = prop.items;
type = '?' + items.type + '[]';
if (items.$ref) {
type = items.$ref + '[]';
// only ObjectId props are dbrefs
if (items.$ref === 'MongoDb#ObjectId') {
if (items.title) {
options.refNum++;
// add references
subgraph.references += '"' + collectionName + '":f' + fieldNumber + ' -> "' + items.title + '":f0 [id = ' + options.refNum + '];\n';
}
}
}
}
}
// add fields to record
records += '| <f' + fieldNumber + '> ' + propertyName + ':' + type;
subgraph.records += '| <f' + fieldNumber + '> ' + propertyName + ':\\{' + type + '\\}\\l';
}
}
records += '"\n' +
subgraph.records += '"\n' +
' shape = "record"\n' +

@@ -524,5 +534,36 @@ '];\n';

fs.writeFile(filename, header + records + references + '}', callback);
return subgraph;
},
graph: function (filename, schemas, callback) {
var graph =
'digraph g {\n' +
'rankdir = "LR";\n' +
'node [fontsize = "10" shape = "ellipse"];\n' +
'edge [];\n';
// each reference must have a unique id
var options = {
refNum: 0
};
var references = '';
var cluster;
for (cluster in schemas) {
if (schemas.hasOwnProperty(cluster)) {
var subgraph = ODM.subgraph(cluster, options, schemas[cluster]);
graph += 'subgraph cluster_' + cluster + ' {\n' +
'overlap=false;\n' +
'label="' + cluster + '"\n';
graph += subgraph.records + '}\n';
references += subgraph.references;
}
}
fs.writeFile(filename, graph + references + '}\n', callback);
},
/**

@@ -529,0 +570,0 @@ * Helper functions to work with arrays

@@ -8,3 +8,3 @@ {

],
"version": "3.0.10",
"version": "3.1.0",
"engines": {

@@ -15,3 +15,3 @@ "node": ">=0.4.12"

"mongodb": "1.0.2",
"jsonschema": "0.0.6"
"jsonschema": "0.1.0"
},

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