Skip to content

Commit

Permalink
Added support for newer Mongo drivers (renamed ObjectID -> ObjectId)
Browse files Browse the repository at this point in the history
- OkanjoApp.js: updated flattenData to support newer MongoDB drivers
- package.json: Bumped to 3.2.1
  • Loading branch information
kfitzgerald committed Mar 31, 2022
1 parent e7ac117 commit 30c9661
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion OkanjoApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class OkanjoApp extends EventEmitter {
} else {
output[key] = input[key]; // as-is
}
} else if (typeof input[key] === "object" && input[key] && input[key].constructor && input[key].constructor.name === "ObjectID") { // Object.create(null) is truthy, but .constructor is undefined
} else if (typeof input[key] === "object" && input[key] && input[key].constructor && (input[key].constructor.name === "ObjectID" || input[key].constructor.name === "ObjectId")) { // Object.create(null) is truthy, but .constructor is undefined
output[key] = input[key].toString();
} else if (typeof input[key] === 'object') {
// Make child objects flat too (always returns object so Object.keys is safe)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "okanjo-app",
"version": "3.2.0",
"version": "3.2.1",
"description": "Okanjo application framework",
"main": "OkanjoApp.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions test/app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ describe('OkanjoApp', function() {
function ObjectID(value = "ffffffffffffffffffffffff") {
this.value = value;
}
function ObjectId(value = "ffffffffffffffffffffffff") {
this.value = value;
}

ObjectID.prototype.toString = function() {
return this.value;
Expand All @@ -618,7 +621,8 @@ describe('OkanjoApp', function() {
},
d: new ObjectID(),
e: new Date(),
f: ctorLessObj
f: ctorLessObj,
g: new ObjectId(),
};

const expected = {
Expand All @@ -631,7 +635,8 @@ describe('OkanjoApp', function() {
c_c_b_c_b_b: undefined,
d: source.d.toString(),
e: source.e,
f_z: "asdf"
f_z: "asdf",
g: source.g.toString(),
};

OkanjoApp.flattenData(source).should.deepEqual(expected);
Expand Down

0 comments on commit 30c9661

Please sign in to comment.