15.18.0 • Published 3 months ago

@getcircuit/patcher v15.18.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

@getcircuit/patcher

This package contains the methods necessary for resolving and applying patches to a document or collection.

Note: Currently, this package only implements the browser version of the patcher.

Usage

Creating a Patcher instance

The main export is the createPatcher function. It takes a firestore instance, a patches collection reference and an actor and returns a patcher object.

With a patcher, one can patch documents in multiple ways:

const patcher = createPatcher({
  firestore,
  patchesCollectionRef: firestore.collection('../../some/collection'),
  actor: 'user',
})

// patcher.addDocument(...)
// patcher.modifyDocument(...)
// patcher.moveDocument(...)
// patcher.deleteDocument(...)
// patcher.duplicateDocument(...)

Adding a document via patches

When we talk about adding a document via patches, we're actually talking about registering that a document was added to a collection. This means that patcher.addDocument doesn't create a new document in the database, but rather registers that a document was added by creating an added patch pointing to the document.

const docRef = firestore.collection('some-collection').doc('some-document')
await docRef.set({ title: 'Some title' })

// an `added` patch is created pointing to the newly created document
await patcher.addDocument({ documentRef: docRef })

Modifying a document via patches

When we talk about modifying a document via patches, we're actually talking about registering that a document was modified. This means that patcher.modifyDocument doesn't modify a document in the database, but rather registers that a document was modified by creating a modified patch pointing to the document.

Note: if there's already a modified patch pointing to the document, the new patch will be merged with the existing one.

const docRef = firestore.collection('some-collection').doc('some-document')
await docRef.set({ title: 'Some title' })

// a `modified` patch is created pointing to the modified document
await patcher.modifyDocument({
  documentRef: docRef,
  changes: {
    title: 'Some new title',
  },
})

// later on...
// the existing `modified` patch is merged with the new one
await patcher.modifyDocument({
  documentRef: docRef,
  changes: {
    description: 'Some description',
  },
})

Deleting a document via patches

When we talk about deleting a document via patches, we're actually talking about registering that a document was deleted. This means that patcher.deleteDocument doesn't delete a document in the database, but rather registers that a document was deleted by creating a deleted patch pointing to the document.

const docRef = firestore.collection('some-collection').doc('some-document')
await docRef.set({ title: 'Some title' })

// a `deleted` patch is created pointing to the deleted document
await patcher.deleteDocument({ documentRef: docRef })

Moving a document via patches

When we talk about moving a document via patches, we're actually talking about registering that a document was moved from one collection to another. This means that patcher.moveDocument doesn't move a document in the database, but rather registers that a document was moved by creating a moved patch pointing to the document.

const docRef = firestore.collection('some-collection').doc('some-document')

// a `moved` patch is created pointing to the moved document
await patcher.moveDocument({
  documentRef: docRef,
  destinationCollectionRef: firestore.collection('some-other-collection'),
})

Duplicating a document via patches

When we talk about duplicating a document via patches, we're actually talking about registering that a document was duplicated. This means that patcher.duplicateDocument doesn't duplicate a document in the database, but rather registers that a document was duplicated by creating a duplicated patch pointing to the document.

Note: the duplicateDocument method also takes account any existing modified patches pointing to the document being dulplicated.

const docRef = firestore.collection('some-collection').doc('some-document')

// a `duplicated` patch is created pointing to the duplicated document
await patcher.duplicateDocument({
  documentRef: docRef,
  destinationCollectionRef: firestore.collection('some-other-collection'),
})

Loading patches reactively

The package exports a signals entrypoint that contains the high-level API for patching documents and collections.

import {
  usePatchContext,
  providePatchContext,
  resolvePatchesFromCollection,
  createPatchedDocumentSnap,
  createPatchedCollectionDocumentSnaps,
  createUserAffectedDocumentIdsByAction,
} from '@getcircuit/patcher/signals'

Low-level internal utilities

The main exported module contains the low-level patching utilities to resolve and apply patches.

import {
  resolveDocumentPatches,
  resolvePatchList,
  applyPatchesToCollectionDocuments,
  queryPatches,
} from '@getcircuit/patcher'
15.18.0

3 months ago

15.17.15

4 months ago

15.17.14

4 months ago

15.17.13

4 months ago

15.17.12

4 months ago

15.17.11

4 months ago

15.17.10

4 months ago

15.17.9

4 months ago

15.17.8

4 months ago

15.17.7

4 months ago

15.17.6

4 months ago

15.17.5

4 months ago

15.17.4

4 months ago

15.17.3

4 months ago

15.17.2

4 months ago

15.17.1

4 months ago

15.18.0-leo.0

4 months ago

15.17.0

4 months ago

15.16.2-leo.0

4 months ago

15.16.1

4 months ago

15.16.0

4 months ago

15.15.2

4 months ago

15.15.1

4 months ago

15.15.0

4 months ago

15.14.0

4 months ago

15.13.6

4 months ago

15.13.5

4 months ago

15.13.4

4 months ago

15.13.3

5 months ago

15.13.2

5 months ago

15.13.1

5 months ago

15.13.0

5 months ago

15.12.12

5 months ago

15.12.11

5 months ago

15.12.10

5 months ago

15.12.6

5 months ago

15.12.5

5 months ago

15.12.2

5 months ago

15.12.1

5 months ago

15.12.0

5 months ago

15.11.4-potato.0

5 months ago

15.12.0-slct.0

5 months ago

15.11.1

5 months ago

15.10.2

5 months ago

15.11.0-leo.0

5 months ago

15.8.2

5 months ago

15.8.1

5 months ago

15.9.0-sd.0

5 months ago

15.6.14

5 months ago

15.6.14-luxon.0

5 months ago

15.7.0-select.0

5 months ago

15.6.12

5 months ago

15.6.11

5 months ago

15.6.9-potato.1

5 months ago

15.6.9-potato.0

5 months ago

15.7.0-pow.0

5 months ago

15.6.8-potato.0

5 months ago

15.6.8-intl.0

5 months ago

15.6.8-pow.0

5 months ago

15.6.7

5 months ago

15.6.6

5 months ago

15.6.5-pow.0

5 months ago

15.6.4

5 months ago

15.6.3

5 months ago

15.6.2-pow.0

5 months ago

15.6.1

5 months ago

15.6.0

5 months ago

15.6.0-pow.0

6 months ago

15.4.0

6 months ago

15.1.1

6 months ago

15.2.0-pow.0

6 months ago

15.0.2

6 months ago

15.1.0-dws.0

6 months ago

15.0.0

6 months ago

14.67.6

7 months ago

14.67.5

7 months ago

14.67.1

7 months ago

14.66.0

7 months ago

14.65.4

7 months ago

14.65.3

7 months ago

14.64.1

7 months ago

14.62.10

7 months ago

14.62.8

7 months ago

14.62.0

8 months ago

14.60.0

8 months ago

14.60.0-ttp.0

8 months ago

14.59.1

8 months ago

14.60.0-pow.0

8 months ago

14.57.8

8 months ago

14.57.4

8 months ago

14.57.3

8 months ago

14.57.2

8 months ago

14.55.0

8 months ago

14.54.3

8 months ago

14.54.2

8 months ago

14.52.3

8 months ago

14.50.0

8 months ago

14.49.0-zoning.0

8 months ago

14.45.3

8 months ago

14.45.1-pow.0

8 months ago

14.45.0

8 months ago

14.44.0

9 months ago

14.43.0

9 months ago

14.42.1

9 months ago

14.39.8

9 months ago

14.39.3

9 months ago

14.39.2-potato.0

9 months ago

14.39.2

9 months ago

14.39.0-potato.0

9 months ago

14.39.0

9 months ago

14.36.0-alpha.0

9 months ago

14.35.0

9 months ago

14.34.2

9 months ago

14.33.1

9 months ago

14.32.1

9 months ago

14.32.0

9 months ago

14.31.0

9 months ago

14.30.0

9 months ago

14.29.0-potato.0

9 months ago

14.29.0

9 months ago

14.27.2

9 months ago

14.27.1

9 months ago

14.26.2

9 months ago

14.26.1

9 months ago

14.26.0

9 months ago

14.25.0

10 months ago

14.23.0

10 months ago

14.21.0-tll.0

10 months ago

14.20.0

10 months ago

14.20.0-btn.0

10 months ago

14.19.2

10 months ago

14.19.0-react18.0

10 months ago

14.18.0-react18.0

10 months ago

14.16.0-react18.0

10 months ago

14.15.2

10 months ago

14.9.3-alpha.0

11 months ago

14.13.0-pow.0

11 months ago

14.12.0-yam.0

11 months ago

14.11.0

11 months ago

14.9.3

11 months ago

14.5.0

11 months ago

14.4.0-alpha.0

11 months ago

14.3.0-alpha.7

11 months ago

14.3.0-alpha.6

11 months ago

14.2.6-pow.0

11 months ago

14.3.0-yam.1.0

11 months ago

14.2.4

11 months ago

14.3.0-read-only.0

11 months ago

14.2.0

12 months ago

14.1.5-wow.0

12 months ago

14.1.4

12 months ago

14.0.1

12 months ago

14.0.0

12 months ago

13.13.1

12 months ago

13.14.0-pow.0

12 months ago

13.12.0-pow.0

12 months ago

13.10.0

12 months ago

13.9.3

12 months ago

13.9.0

12 months ago

13.5.0-yam.1.0

1 year ago

13.5.0-yam.0

1 year ago

13.4.0

1 year ago

13.4.0-yam.0

1 year ago

13.3.0

1 year ago

13.0.0

1 year ago

12.18.0-pow.0

1 year ago

12.17.4

1 year ago

12.17.0

1 year ago

12.16.2

1 year ago

12.17.0-pow.0

1 year ago

12.15.0-yam.1

1 year ago

12.15.0-yam.0

1 year ago

12.15.0-pow.0

1 year ago

12.12.0-leo.0

1 year ago

12.12.0-pim.0

1 year ago

12.7.0-yam.1

1 year ago

12.9.0-rows.0

1 year ago

12.7.0-yam.0

1 year ago

12.7.0-rows.0

1 year ago

12.5.0-rows.0

1 year ago

12.4.2

1 year ago

12.5.0-row.0

1 year ago

12.4.0

1 year ago

12.4.0-row.0

1 year ago

12.3.0

1 year ago

12.3.0-clx.0

1 year ago

12.2.11

1 year ago

12.2.10

1 year ago

12.2.9

1 year ago

12.2.8

1 year ago

12.3.0-cll.0

1 year ago

12.2.7

1 year ago

12.3.0-ico.0

1 year ago

12.2.5

1 year ago

12.2.5-kiwi.0

1 year ago

12.3.0-cells.0

1 year ago

12.2.4

1 year ago

12.3.0-cell.0

1 year ago

12.2.0

1 year ago

12.1.0-cell.0

1 year ago

12.0.1

1 year ago

12.0.0

1 year ago

11.0.0

1 year ago

10.2.0

1 year ago

10.2.0-kiwi.0

1 year ago

10.1.4

1 year ago

10.1.3

1 year ago

10.1.0

1 year ago

10.0.0

1 year ago

9.0.1-kiwi.1

1 year ago

9.0.1-kiwi.0

1 year ago

8.6.1-kiwi.0

1 year ago

9.1.0-badge.0

1 year ago

9.0.0

1 year ago

8.2.0-input.0

1 year ago

8.1.1

1 year ago

8.2.0-yam.0

1 year ago

8.1.0-yam.0

1 year ago

8.0.4

1 year ago

8.0.1

1 year ago

8.0.0

1 year ago

7.2.0

1 year ago

8.0.0-kiwi.0

1 year ago

7.2.0-yam.0

1 year ago

7.2.0-alpha.0

1 year ago

7.1.0

1 year ago

7.1.0-alpha.0

1 year ago

7.1.0-kiwi.1

1 year ago

7.1.0-kiwi.0

1 year ago

7.1.0-gamma.0

1 year ago

7.1.0-inputs.0

1 year ago

8.0.0-input.0

1 year ago

7.0.0

1 year ago

7.0.0-kiwi.6

1 year ago

7.0.0-kiwi.5

1 year ago

7.0.0-kiwi.4

1 year ago

7.0.0-kiwi.3

1 year ago

7.0.0-kiwi.2

1 year ago

7.0.0-kiwi.1

1 year ago

6.3.0-input.0

1 year ago

7.0.0-kiwi.0

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

0.3.0

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.7-input.0

1 year ago

0.2.6

1 year ago

0.2.5-input.0

1 year ago

0.2.4

1 year ago

0.2.4-yam.8.6.0

1 year ago

0.2.4-yam.8.5.0

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.2-yam.8.2.0

1 year ago

0.2.2-yam.8.1.0

1 year ago

0.2.1

1 year ago

0.2.1-yam.8.0

1 year ago

0.2.0

1 year ago

0.1.2-yam.7.7.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.1.0-patcher.0

1 year ago

0.0.2-patcher.6

1 year ago

0.0.2-patcher.5

1 year ago

0.0.2-patcher.4

1 year ago

0.0.2-patcher.3

1 year ago

0.0.2-patcher.2

1 year ago

0.0.2-patcher.1

1 year ago

0.0.2-patcher.0

1 year ago