@cybertools/mongo
v1.0.1
Published
MongoDB-aware serializers (ObjectId/Date/BigInt) and type guards for Cyberscope backends.
Readme
@cybertools/mongo
MongoDB-aware serializers (ObjectId/Date/BigInt) and type guards for Cyberscope backends.
mongodb is a peer dependency (^5.6.0 || ^6.0.0 || ^7.0.0) and must be installed by the app. It is never bundled, so instanceof ObjectId uses your copy of the driver.
Exports
| Export | Description |
| ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| serializeBackend(value, options?) | Converts ObjectId, Date and BigInt to strings and renames _id to id. |
| deserializeBackend(value, options?) | Reverses it: id to _id ObjectId, with dateFields, bigIntFields and transform. |
| serializeDb(resource, options?) | Encodes the bigInts.keys fields as { _cdt: 104, n, s }; Dates and ObjectIds pass through. |
| deserializeDb(resource) | Decodes { _cdt: 104, ... } objects back to BigInt. |
| bigIntDataType | The _cdt marker value (104). |
| isObject, isBigInt, isDate, isObjectId, isNumber | Type guards. |
| Transform, SerializeBackendOptions, DeserializeBackendOptions, SerializeDbOptions | Option types. |
Note: serializeBackend requires options.transform whenever options are passed.
