snap-shot-machine
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

snap-shot-machine

Encoder / decoder for taking a current snapshot of the firestore database

Installing

Using npm:

$ npm install snap-shot-machine

Using yarn:

$ yarn add snap-shot-machine

Methods

getPackedAndOrderedFile()

import { getPackedAndOrderedFile } from 'snap-shot-machine'

await getPackedAndOrderedFile ({
  collectionId: string,
  where: Array<{fieldPath: string, opStr: WhereFilterOp, value: unknown}>,
  select: Array<string>,
  orderBy: {
    comparator: (documentA: Array<unknown>, documentB: Array<unknown>) => number
    batchSize: number
  },
  destinationFilePath: string,
})

Saves an encoded file of the firestore database based on the query

  • collectionId - Which firestore collection to read from.
  • where - Which filters to apply.
     If no filters are required, provide an empty array.
  • select - Which fields to read from.  By default, undefined field values will not be encoded and not reconstructed through the decoder.
  • orderBy - How the encoded file should be ordered.  comparator assumes that the document will be reshaped into the shape designated by select. It is the user's responsibility to check that the values are not undefined and are of the expected type.  batchSize determines the size of each intermediate file. The batchSize may affect the performance when sorting the encoded file. Intermediate files will be saved at os.tmpdir()/merge-intermediates/ and will be removed once the process is complete.
  • destinationFilePath - Where the encoded file should be saved.

Decoder

import { Decoder } from 'snap-shot-machine'

const decoderStream = new Decoder()
fileReadStream.pipe(decodeStream)

A decoder stream which decodes the encoded file into streams of objects. The objects will resemble that of the firestore documents, but will only have fields/values that were specified. NOTE Decoder will throw an error if the encoded file and the decoder have different schema versions.

Readme

Keywords

none

Package Sidebar

Install

npm i snap-shot-machine

Weekly Downloads

3

Version

0.1.7

License

MIT

Unpacked Size

385 kB

Total Files

160

Last publish

Collaborators

  • sjeon