Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mongodb-js/mongodb-schema
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cfd2b85ab923e38511be1ec4ea462f9402231fe2
Choose a base ref
...
head repository: mongodb-js/mongodb-schema
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 01d70e23005db82b80e73773d1a11f6b53af1cb5
Choose a head ref

Commits on Dec 10, 2018

  1. Copy the full SHA
    78a2c19 View commit details
  2. 8.2.3

    durran committed Dec 10, 2018
    Copy the full SHA
    92a29ba View commit details

Commits on Dec 18, 2018

  1. chore: Update parseSchema and semanticTypes examples (#55)

    * chore: Update readme to use correct example
    
    * Update example parse schema
    lukakerr authored and rueckstiess committed Dec 18, 2018
    Copy the full SHA
    8db24ff View commit details

Commits on May 1, 2019

  1. Copy the full SHA
    7e754a1 View commit details
  2. 8.2.4

    durran committed May 1, 2019
    Copy the full SHA
    8a11d38 View commit details

Commits on Aug 15, 2019

  1. Copy the full SHA
    36e8316 View commit details
  2. 8.2.5

    durran committed Aug 15, 2019
    Copy the full SHA
    8688a06 View commit details

Commits on Jan 30, 2020

  1. [Security] Bump mixin-deep from 1.3.1 to 1.3.2 (#64)

    Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2. **This update includes a security fix.**
    - [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
    - [Commits](jonschlinkert/mixin-deep@1.3.1...1.3.2)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 30, 2020
    Copy the full SHA
    8cdd243 View commit details
  2. [Security] Bump extend from 3.0.1 to 3.0.2 (#61)

    Bumps [extend](https://github.com/justmoon/node-extend) from 3.0.1 to 3.0.2. **This update includes a security fix.**
    - [Release notes](https://github.com/justmoon/node-extend/releases)
    - [Changelog](https://github.com/justmoon/node-extend/blob/master/CHANGELOG.md)
    - [Commits](justmoon/node-extend@v3.0.1...v3.0.2)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 30, 2020
    Copy the full SHA
    c68a3f9 View commit details
  3. [Security] Bump eslint-utils from 1.3.1 to 1.4.3 (#60)

    Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.3. **This update includes security fixes.**
    - [Release notes](https://github.com/mysticatea/eslint-utils/releases)
    - [Commits](mysticatea/eslint-utils@v1.3.1...v1.4.3)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 30, 2020
    Copy the full SHA
    a68eacc View commit details
  4. [Security] Bump cached-path-relative from 1.0.1 to 1.0.2 (#58)

    Bumps [cached-path-relative](https://github.com/ashaffer/cached-path-relative) from 1.0.1 to 1.0.2. **This update includes security fixes.**
    - [Release notes](https://github.com/ashaffer/cached-path-relative/releases)
    - [Commits](https://github.com/ashaffer/cached-path-relative/commits)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 30, 2020
    Copy the full SHA
    1888f70 View commit details
  5. [Security] Bump tar from 4.4.1 to 4.4.13 (#63)

    Bumps [tar](https://github.com/npm/node-tar) from 4.4.1 to 4.4.13. **This update includes security fixes.**
    - [Release notes](https://github.com/npm/node-tar/releases)
    - [Changelog](https://github.com/npm/node-tar/blob/master/CHANGELOG.md)
    - [Commits](isaacs/node-tar@v4.4.1...v4.4.13)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 30, 2020
    Copy the full SHA
    b79a5d5 View commit details
  6. Copy the full SHA
    6081a27 View commit details
  7. Bump istanbul from 0.3.22 to 0.4.5 (#57)

    Bumps [istanbul](https://github.com/gotwarlost/istanbul) from 0.3.22 to 0.4.5.
    - [Release notes](https://github.com/gotwarlost/istanbul/releases)
    - [Changelog](https://github.com/gotwarlost/istanbul/blob/master/CHANGELOG.md)
    - [Commits](https://github.com/gotwarlost/istanbul/commits/v0.4.5)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 30, 2020
    Copy the full SHA
    afc9e73 View commit details

Commits on Jan 31, 2020

  1. chore(deps-dev): Bump eslint-config-mongodb-js from 3.0.1 to 5.0.3 (#72)

    Bumps [eslint-config-mongodb-js](https://github.com/mongodb-js/eslint-config) from 3.0.1 to 5.0.3.
    - [Release notes](https://github.com/mongodb-js/eslint-config/releases)
    - [Commits](https://github.com/mongodb-js/eslint-config/commits)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 31, 2020
    Copy the full SHA
    00666cf View commit details
  2. chore(deps): Bump js-yaml from 3.12.0 to 3.13.1 (#74)

    Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 3.12.0 to 3.13.1.
    - [Release notes](https://github.com/nodeca/js-yaml/releases)
    - [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
    - [Commits](nodeca/js-yaml@3.12.0...3.13.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jan 31, 2020
    Copy the full SHA
    6194cd3 View commit details
  3. Bump mongodb-collection-sample from 4.4.2 to 4.5.1 (#67)

    Bumps [mongodb-collection-sample](https://github.com/mongodb-js/mongodb-collection-sample) from 4.4.2 to 4.5.1.
    - [Release notes](https://github.com/mongodb-js/mongodb-collection-sample/releases)
    - [Commits](mongodb-js/collection-sample@v4.4.2...v4.5.1)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Jan 31, 2020
    Copy the full SHA
    8cbcd32 View commit details

Commits on Feb 3, 2020

  1. Copy the full SHA
    79fd908 View commit details
  2. chore(deps): Bump mongodb-extended-json from 1.10.0 to 1.11.0 (#75)

    Bumps [mongodb-extended-json](https://github.com/mongodb-js/extended-json) from 1.10.0 to 1.11.0.
    - [Release notes](https://github.com/mongodb-js/extended-json/releases)
    - [Commits](mongodb-js/extended-json@v1.10.0...v1.11.0)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 3, 2020
    Copy the full SHA
    e06e39a View commit details
  3. Bump mongodb-js-precommit from 2.0.0 to 2.2.0 (#71)

    Bumps [mongodb-js-precommit](https://github.com/mongodb-js/precommit) from 2.0.0 to 2.2.0.
    - [Release notes](https://github.com/mongodb-js/precommit/releases)
    - [Commits](https://github.com/mongodb-js/precommit/commits/v2.2.0)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 3, 2020
    Copy the full SHA
    2f41b46 View commit details
  4. build(deps): Bump ms from 0.7.3 to 2.1.2 (#66)

    Bumps [ms](https://github.com/zeit/ms) from 0.7.3 to 2.1.2.
    - [Release notes](https://github.com/zeit/ms/releases)
    - [Commits](vercel/ms@0.7.3...2.1.2)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 3, 2020
    Copy the full SHA
    ecdbdf0 View commit details
  5. build(deps): Bump stats-lite from 2.1.1 to 2.2.0 (#70)

    Bumps [stats-lite](https://github.com/brycebaril/node-stats-lite) from 2.1.1 to 2.2.0.
    - [Release notes](https://github.com/brycebaril/node-stats-lite/releases)
    - [Commits](brycebaril/node-stats-lite@v2.1.1...v2.2.0)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 3, 2020
    Copy the full SHA
    069b051 View commit details

Commits on Feb 4, 2020

  1. build(deps-dev): [Security] Bump bson from 0.5.7 to 1.0.5 (#77)

    Bumps [bson](https://github.com/mongodb/js-bson) from 0.5.7 to 1.0.5. **This update includes a security fix.**
    - [Release notes](https://github.com/mongodb/js-bson/releases)
    - [Changelog](https://github.com/mongodb/js-bson/blob/v1.0.5/HISTORY.md)
    - [Commits](mongodb/js-bson@V0.5.7...v1.0.5)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 4, 2020
    Copy the full SHA
    b6e367a View commit details
  2. build(deps): Bump mongodb-ns from 2.0.0 to 2.2.0 (#79)

    Bumps [mongodb-ns](https://github.com/mongodb-js/ns) from 2.0.0 to 2.2.0.
    - [Release notes](https://github.com/mongodb-js/ns/releases)
    - [Commits](mongodb-js/ns@v2.0.0...v2.2.0)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 4, 2020
    Copy the full SHA
    915ba85 View commit details
  3. Bump debug from 2.6.9 to 4.1.1 (#68)

    Bumps [debug](https://github.com/visionmedia/debug) from 2.6.9 to 4.1.1.
    - [Release notes](https://github.com/visionmedia/debug/releases)
    - [Commits](debug-js/debug@2.6.9...4.1.1)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 4, 2020
    Copy the full SHA
    8997b3e View commit details

Commits on Feb 10, 2020

  1. Bump mongodb-js-precommit from 2.2.0 to 2.2.1 (#82)

    Bumps [mongodb-js-precommit](https://github.com/mongodb-js/precommit) from 2.2.0 to 2.2.1.
    - [Release notes](https://github.com/mongodb-js/precommit/releases)
    - [Commits](mongodb-js/precommit@v2.2.0...v2.2.1)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    dependabot-preview[bot] authored Feb 10, 2020
    Copy the full SHA
    21a2fc7 View commit details

Commits on Feb 13, 2020

  1. Copy the full SHA
    17bbff4 View commit details

Commits on Feb 4, 2021

  1. Copy the full SHA
    39af582 View commit details

Commits on Feb 10, 2021

  1. Added promise support for library (#140)

    * Added promise support for library
    
    Based on this excellent SO answer:
    https://stackoverflow.com/a/36838115/3694288
    
    The objective is to make the library more available and easy to use.
    
    * Added linting check in package.json
    alexbjorlig authored Feb 10, 2021
    Copy the full SHA
    d73f838 View commit details
  2. Bump mocha from 3.5.3 to 8.2.1 (#124)

    Bumps [mocha](https://github.com/mochajs/mocha) from 3.5.3 to 8.2.1.
    - [Release notes](https://github.com/mochajs/mocha/releases)
    - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
    - [Commits](mochajs/mocha@v3.5.3...v8.2.1)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Feb 10, 2021
    Copy the full SHA
    beb4387 View commit details

Commits on Feb 12, 2021

  1. Copy the full SHA
    68a401b View commit details
  2. Copy the full SHA
    33e0f51 View commit details

Commits on Mar 9, 2021

  1. Reduce the usage of lodash (round 2) (#145)

    * Removed lodash from index.js
    
    * Removed lodash from stats.js
    
    * Removed lodash from stream.js
    
    Only function I could not re-write was defaults-deep.
    I moved the function to a utils folder, so we can remove it in the
    near future
    
    * Removed lodash from tests
    
    * fixed linting
    
    * Updated lodash 🚀
    
    I could not completly remove lodash, need help with 2 function calls:
    
        - stream.js
            --> _.get
            --> _.defaultsDeep
    
    * Attempt to fix travic ci failing build
    
    * Updated mocha - istanbul to modern API
    
    * Moving travis "back" to use npm ci
    
    Maybe this can solve the CI issue?
    
    * Fix CI error by using "normal" install
    
    * removed and re-installed node_modules
    
    * upgraded mocha
    
    * updating out-dated dependencies
    
    * Removed zuul
    
    It was depreceated and not maintained anymore:
    https://github.com/defunctzombie/zuul#readme
    
    * Fix pre-commit to match setup in compas
    
    This shoul help align the style used in:
    https://github.com/mongodb-js/compass
    
    * updated github workflow to look like compass
    
    * updated mognodb-js-precommit to latest
    
    * very small change from ssh --> https
    
    * fixed failing tests from upgrading BSON
    alexbjorlig authored Mar 9, 2021
    Copy the full SHA
    88b20c2 View commit details

Commits on Mar 15, 2021

  1. Bump mocha from 8.3.0 to 8.3.2 (#152)

    Bumps [mocha](https://github.com/mochajs/mocha) from 8.3.0 to 8.3.2.
    - [Release notes](https://github.com/mochajs/mocha/releases)
    - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
    - [Commits](mochajs/mocha@v8.3.0...v8.3.2)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Mar 15, 2021
    Copy the full SHA
    a1f3342 View commit details
  2. Bump cli-table from 0.3.4 to 0.3.5 (#151)

    Bumps [cli-table](https://github.com/Automattic/cli-table) from 0.3.4 to 0.3.5.
    - [Release notes](https://github.com/Automattic/cli-table/releases)
    - [Changelog](https://github.com/Automattic/cli-table/blob/master/History.md)
    - [Commits](Automattic/cli-table@v0.3.4...v0.3.5)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Mar 15, 2021
    Copy the full SHA
    983b2d1 View commit details
  3. Bump lodash from 4.17.20 to 4.17.21 (#149)

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.20...4.17.21)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Mar 15, 2021
    Copy the full SHA
    c4e8dba View commit details
  4. Update package-lock.json

    addaleax committed Mar 15, 2021
    Copy the full SHA
    f4147ea View commit details
  5. 9.0.0

    addaleax committed Mar 15, 2021
    Copy the full SHA
    01d70e2 View commit details
21 changes: 19 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"parserOptions": {
"ecmaVersion": 2019
},
"env": {
"mocha": true
"mocha": true,
"node": true,
"es6": true
},
"globals": {
"expect": true,
"sinon": true
},
"rules": {
"camelcase": 1,
"new-cap": 0,
"no-use-before-define": 0
},
"extends": "mongodb-js/node"
"extends": [
"mongodb-js/node",
"mongodb-js/browser"
]
}
22 changes: 22 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: unit tests

on: [push, pull_request]

jobs:
unitTest:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run check
- run: npm test
- run: npm run coverage
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -29,3 +29,8 @@ node_modules
# Release artifacts
.lone/
dist/

# Test output
.nyc_output
# Mac OS files on folder create/delete
.DS_Store
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -12,3 +12,5 @@ test/
*.log
coverage/
.eslintrc
.nyc_output
**/*.DS_Store
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .zuul.yml

This file was deleted.

17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ the collection in JSON format to stdout.

```
mongodb-schema mongodb://localhost:27017 mongodb.fanclub
```
```

Additional arguments change the number of samples (`--sample`), print additional statistics about the
schema analysis (`--stats`), switch to a different output format (`--format`), or let you suppress the
@@ -28,7 +28,7 @@ For more information, run

```
mongodb-schema --help
```
```

### API

@@ -55,19 +55,22 @@ below accordingly).
3. Create a new file `parse-schema.js` and paste in the following code:

```javascript
var parseSchema = require('mongodb-schema');
var connect = require('mongodb');
const parseSchema = require('mongodb-schema');
const MongoClient = require('mongodb').MongoClient;
const dbName = 'test';

connect('mongodb://localhost:27017/test', function(err, db) {
MongoClient.connect(`mongodb://localhost:27017/${dbName}`, { useNewUrlParser: true }, function(err, client) {
if (err) return console.error(err);

const db = client.db(dbName);

// here we are passing in a cursor as the first argument. You can
// also pass in a stream or an array of documents directly.
parseSchema(db.collection('data').find(), function(err, schema) {
if (err) return console.error(err);

console.log(JSON.stringify(schema, null, 2));
db.close();
client.close();
});
});
```
@@ -195,7 +198,7 @@ function emailDetector(value, path) {
return emailRegex.test(value);
};

parseSchema(db.collection('data').find(), {EmailAddress: emailDetector}, function(err, schema) {
parseSchema(db.collection('data').find(), { semanticTypes: { EmailAddress: emailDetector } }, function(err, schema) {
...
});
```
2 changes: 1 addition & 1 deletion bin/mongodb-schema
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ var bar = new ProgressBar('analyzing [:bar] :percent :etas ', {
clear: true
});

mongodb.connect(uri, function(err, conn) {
mongodb.connect(uri, {useUnifiedTopology: true}, function(err, conn) {
if (err) {
console.error('Failed to connect to MongoDB: ', err);
process.exit(1);
11 changes: 7 additions & 4 deletions examples/parse-schema.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/* eslint no-console: 0 */

var parseSchema = require('../');
var connect = require('mongodb');
const parseSchema = require('../');
const MongoClient = require('mongodb').MongoClient;
const dbName = 'mongodb';

connect('mongodb://localhost:27017/mongodb', function(err, db) {
MongoClient.connect(`mongodb://localhost:27017/${dbName}`, function(err, client) {
if (err) {
return console.error(err);
}

const db = client.db(dbName);

parseSchema(db.collection('fanclub').find().limit(100), function(err2, schema) {
if (err2) {
return console.error(err);
}

console.log(JSON.stringify(schema, null, 2));
db.close();
client.close();
});
});
79 changes: 45 additions & 34 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var stream = require('./stream');
var es = require('event-stream');
var _ = require('lodash');

// var debug = require('debug')('mongodb-schema:wrapper');

@@ -14,43 +13,55 @@ var _ = require('lodash');
* @param {Boolean} options.semanticTypes enable semantic type detection (default: false)
* @param {Boolean} options.storeValues enable storing of values (default: true)
*
* @param {Function} fn Callback which will be passed `(err, schema)`
* @param {Function} callback Callback which will be passed `(err, schema)`
* @return {Promise} You can await promise, or use callback if provided.
*/
module.exports = function(docs, options, fn) {
// shift parameters if no options are specified
if (_.isUndefined(options) || _.isFunction(options) && _.isUndefined(fn)) {
fn = options;
options = {};
}
module.exports = function(docs, options, callback) {
const promise = new Promise((resolve, reject) => {
// shift parameters if no options are specified
if (typeof options === 'undefined' || (typeof options === 'function' && typeof callback === 'undefined')) {
callback = options;
options = {};
}

var src;
// MongoDB Cursors
if (docs.stream && typeof docs.stream === 'function') {
src = docs.stream();
// Streams
} else if (docs.pipe && typeof docs.pipe === 'function') {
src = docs;
// Arrays
} else if (Array.isArray(docs)) {
src = es.readArray(docs);
} else {
reject(new Error(
'Unknown input type for `docs`. Must be an array, ' +
'stream or MongoDB Cursor.'
));
return;
}

var result;

src
.pipe(stream(options))
.on('data', function(data) {
result = data;
})
.on('error', function(err) {
reject(err);
})
.on('end', function() {
resolve(result);
});
});

var src;
// MongoDB Cursors
if (docs.stream && typeof docs.stream === 'function') {
src = docs.stream();
// Streams
} else if (docs.pipe && typeof docs.pipe === 'function') {
src = docs;
// Arrays
} else if (_.isArray(docs)) {
src = es.readArray(docs);
} else {
fn(new Error('Unknown input type for `docs`. Must be an array, '
+ 'stream or MongoDB Cursor.'));
return;
if (callback && typeof callback === 'function') {
promise.then(callback.bind(null, null), callback);
}

var result;

src.pipe(stream(options))
.on('data', function(data) {
result = data;
})
.on('error', function(err) {
fn(err);
})
.on('end', function() {
fn(null, result);
});
return promise;
};

module.exports.stream = stream;
5 changes: 0 additions & 5 deletions lib/semantic-types/geojson.js

This file was deleted.

3 changes: 1 addition & 2 deletions lib/semantic-types/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
module.exports = {
'Email': require('./email'),
'GeoJSON': require('./geojson')
'Email': require('./email')
};
54 changes: 29 additions & 25 deletions lib/stats.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var _ = require('lodash');
// var debug = require('debug')('mongodb-schema:stats');

var widthRecursive = function(schema) {
@@ -8,17 +7,21 @@ var widthRecursive = function(schema) {
}
if (schema.fields !== undefined) {
width += schema.fields.length;
width += _.sum(schema.fields.map(function(field) {
var doc = _.find(field.types, 'name', 'Document');

width += schema.fields.map(field => {
var doc = field.types.find(v => v.name === 'Document');
return widthRecursive(doc);
}));
width += _.sum(schema.fields.map(function(field) {
var arr = _.find(field.types, 'name', 'Array');
}).reduce((p, c) => p + c || 0, 0);


width += schema.fields.map(field => {
var arr = field.types.find(v => v.name === 'Array');
if (arr) {
var doc = _.find(arr.types, 'name', 'Document');
var doc = arr.types.find(v => v.name === 'Document');
return widthRecursive(doc);
}
}));
})
.reduce((p, c) => p + c || 0, 0);
}
return width;
};
@@ -30,18 +33,19 @@ var depthRecursive = function(schema) {
var maxChildDepth = 0;
if (schema.fields !== undefined && schema.fields.length > 0) {
maxChildDepth = 1 + Math.max(
_.max(schema.fields.map(function(field) {
var doc = _.find(field.types, 'name', 'Document');
Math.max(...schema.fields.map(field => {
var doc = field.types.find(v => v.name === 'Document');
return depthRecursive(doc);
})),
Math.max(...schema.fields.map(field => {
var arr = field.types.find(v => v.name === 'Array');
if (arr) {
var doc = arr.types.find(v => v.name === 'Document');
return depthRecursive(doc);
})),
_.max(schema.fields.map(function(field) {
var arr = _.find(field.types, 'name', 'Array');
if (arr) {
var doc = _.find(arr.types, 'name', 'Document');
return depthRecursive(doc);
}
return 0;
})));
}
return 0;
}))
);
}
return maxChildDepth;
};
@@ -55,21 +59,21 @@ var branchingFactors = function(schema) {
if (schema.fields !== undefined && schema.fields.length > 0) {
branchArray.push(schema.fields.length);
res = schema.fields.map(function(field) {
var doc = _.find(field.types, 'name', 'Document');
var doc = field.types.find(v => v.name === 'Document');
return branchingFactors(doc);
});
branchArray.push.apply(branchArray, _.flatten(res, true));
branchArray.push(...res.flat(Infinity));
res = schema.fields.map(function(field) {
var arr = _.find(field.types, 'name', 'Array');
var arr = field.types.find(v => v.name === 'Array');
if (arr) {
var doc = _.find(arr.types, 'name', 'Document');
var doc = arr.types.find(v => v.name === 'Document');
return branchingFactors(doc);
}
return [];
});
branchArray.push.apply(branchArray, _.flatten(res, true));
branchArray.push(...res.flat(Infinity));
}
return _.sortBy(branchArray).reverse();
return branchArray.sort().reverse();
};

module.exports = {
Loading