This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isArray, isObject, mapValues } from 'lodash-es' | |
import type { Document } from 'mongodb' | |
const mapValuesDeep = <T>(obj: T, cb: any): unknown => { | |
if (isArray(obj)) { | |
return obj.map(innerObj => mapValuesDeep(innerObj, cb)) | |
} else if (isObject(obj)) { | |
if (!('toHexString' in obj || 'getDay' in obj)) { | |
return mapValues(obj, val => mapValuesDeep(val, cb)) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$'); | |
function check_serializability(value, id, path) { | |
const type = typeof value; | |
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'undefined') { | |
// primitives are fine | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ObjectId = require('bson-objectid') | |
function check_serializability(value, id, path) { | |
const type = typeof value; | |
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'undefined') { | |
// primitives are fine | |
return; | |
} |