Registry / database / firestore-rest-serdes

firestore-rest-serdes

JSON →
library1.0.5jsnpmunverified

A lightweight serializer/deserializer for converting between plain JSON objects and Firestore REST API's Document format. Version 1.0.5, stable, no dependencies. Essential for backend functions needing to trigger Firestore security rules via REST with user ID tokens, which the Admin SDK cannot do. Unlike the official Firebase SDK, this module is minimal and framework-agnostic, focusing solely on field conversion.

npm install firestore-rest-serdes
INSTALL
IMPORT
SIG · FIRESTORE-REST-SER
F
firestore-rest-serdes
databasejavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

serialize
✓ import { serialize } from 'firestore-rest-serdes'
✗ const serialize = require('firestore-rest-serdes').serialize
ESM imports work; CJS require also supported.
deserialize
✓ import { deserialize } from 'firestore-rest-serdes'
✗ import serdes from 'firestore-rest-serdes'
Default import does not exist; use named imports.
serialize, deserialize
✓ const { serialize, deserialize } = require('firestore-rest-serdes')
CommonJS destructuring works in Node.js.

Shows basic serialization and deserialization between plain JSON and Firestore REST Document fields.

import { serialize, deserialize } from 'firestore-rest-serdes'; const plainObj = { hello: 'world', zero: 0 }; const serialized = serialize(plainObj); console.log(serialized); // Output: { hello: { stringValue: 'world' }, zero: { integerValue: '0' } } const firestoreFields = { hello: { stringValue: 'world' }, zero: { integerValue: '0' } }; const deserialized = deserialize(firestoreFields); console.log(deserialized); // Output: { hello: 'world', zero: 0 }
Debug
Known issues
gotchaThe serializer only converts primitive types (string, number, boolean, null) and arrays/objects. MapValue and arrayValue are handled, but timestamp, bytes, reference, geoPoint, and latlng are not serialized correctly and will be omitted or throw.
fix
Manually handle unsupported types using Firestore REST API types before serialization.
affects: <1.1.0
gotchaThe deserializer expects Firestore field objects with value type keys (e.g., stringValue, integerValue). It does not support the full Document proto (e.g., createTime, updateTime). Passing the entire Document object will cause unexpected behavior.
fix
Extract the fields property from a Document before calling deserialize.
affects: >=1.0.0
gotchaNumbers are always serialized as integerValue (for integers) or doubleValue (for floats). There is no support for the Firestore integerValue string format for large integers beyond JavaScript safe integer range.
fix
Use BigInt or string for numbers outside Number.MAX_SAFE_INTEGER, but they will be serialized as doubleValue.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: serialize is not defined
Forgot to import or destructure the function correctly when using ESM.
fix
Use 'import { serialize } from 'firestore-rest-serdes'
TypeError: serialize is not a function
Attempted to default-import the module (e.g., import serdes from 'firestore-rest-serdes')
fix
Use named imports: import { serialize, deserialize } from 'firestore-rest-serdes'
Error: Unknown value type: object at field 'foo'
Attempted to serialize a Date object, which is not a supported type.
fix
Convert Date objects to strings or timestamps before serialization.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
firestore-rest-serdes — npm install firestore-rest-serdes · libregistry