firestore_api_converter 0.1.0 copy "firestore_api_converter: ^0.1.0" to clipboard
firestore_api_converter: ^0.1.0 copied to clipboard

A pure-Dart converter to use encode and decode data for Firestore REST API.

Usage #

Encode an Map #

If you have an object, convert it to a map using any of the standard methods. Then encode that map to send it over Firestore REST API:

final map = {
  'null': null,
  'boolean': true,
  'integer': 123,
  'double': .5,
  'timestamp': DateTime.utc(2023, 9, 13, 17, 43, 11, 0, 2002),
  'string': 'abc',
  'array': [true, 'abc', 123],
  'map': {'boolean': true, 'string': 'abc', 'integer': 123},
};
final encoded = FirestoreApiConverter.toFirestore(map);
// {
//   "fields": {
//     "null": { "nullValue": null },
//     "boolean": { "booleanValue": true },
//     "integer": { "integerValue": "123" },
//     "double": { "doubleValue": 0.5 },
//     "timestamp": { "timestampValue": "2023-09-13T17:43:11.002Z" },
//     "string": { "stringValue": "abc" },
//     "array": {
//       "arrayValue": {
//         "values": [
//           { "booleanValue": true },
//           { "stringValue": "abc" },
//           { "integerValue": "123" }
//         ]
//       }
//     },
//     "map": {
//       "mapValue": {
//         "fields": {
//           "boolean": { "booleanValue": true },
//           "string": { "stringValue": "abc" },
//           "integer": { "integerValue": "123" }
//         }
//       }
//     }
//   }
// }

Decode a Document #

Decode a document received via Firestore REST API:

final decoded = FirestoreApiConverter.fromFirestore(encoded);

Type Support #

Full Support #

  • null
  • boolean
  • integer
  • double
  • timestamp
  • string
  • array
  • map

Not Yet Supported #

I do not have use cases to test those properly. If you have one, submit a PR. Before working on it, read a discussion corresponding issue linked above and suggest your idea of implementation.

4
likes
160
points
29
downloads

Publisher

verified publisherainkin.com

Weekly Downloads

A pure-Dart converter to use encode and decode data for Firestore REST API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT-0 (license)

More

Packages that depend on firestore_api_converter