Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

COMPASS-3933: Upgrade to bson@4 #91

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 0 additions & 174 deletions .jsfmtrc

This file was deleted.

18 changes: 8 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
sudo: false
dist: trusty
language: node_js
node_js:
- 5
- 6
- 7
- node

- 12.4.0
before_install:
- npm install -g npm@latest
install:
- npm ci
script:
- npm run ci
- npm run check
- npm test

cache:
directories:
- node_modules
cache: npm
75 changes: 3 additions & 72 deletions lib/deserialize.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,11 @@
var types = require('./types');
var strict = require('./modes/strict');
var isObject = types.isObject;
var async = require('async');
var raf = require('raf');

const { EJSON } = require('bson');
/**
* Cast values from extended json objects to their BSON or JS types.
*
* @param {Any} data - A value which might be esjon encoded.
* @return {Any}
* @api private
*/
module.exports = function deserialize(data) {
if (Array.isArray(data)) {
return data.map(deserialize);
}
if (!isObject(data)) {
return data;
}

var keys = Object.keys(data);
if (keys.length === 0) {
return data;
}

var caster = strict.deserialize[keys[0]];
if (!caster) {
return keys.reduce(function(schema, key) {
schema[key] = deserialize(data[key]);
return schema;
}, {});
}

return caster(data);
module.exports = function(data) {
return EJSON.deserialize(data, { legacy: true, relaxed: false });
};

function deserializeAsync(data, fn) {
if (Array.isArray(data) === true) {
async.series(data.map(function(doc) {
return function(cb) {
raf(function() {
deserializeAsync(doc, cb);
});
};
}), fn);
} else if (isObject(data) === false) {
fn(null, data);
} else {
var keys = Object.keys(data);
if (keys.length === 0) {
fn(null, data);
} else {
var caster = strict.deserialize[keys[0]];
if (caster) {
fn(null, caster.call(null, data));
} else {
var res = {};
async.series(keys.map(function(key) {
return function(cb) {
deserializeAsync(data[key], function(err, d) {
if (err) {
return cb(err);
}
res[key] = d;
cb();
});
};
}), function(err) {
if (err) {
return fn(err);
}
fn(null, res);
});
}
}
}
}

module.exports.async = deserializeAsync;
Loading