All Projects → anishkny → Integrify

anishkny / Integrify

Licence: mit
🤝 Enforce referential and data integrity in Cloud Firestore using triggers

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Integrify

React Firebase Starter
Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay
Stars: ✭ 4,366 (+5800%)
Mutual labels:  serverless, firebase-functions, firebase, firestore
Firestore Cloud Functions Typescript
Firebase cloud functions in typescript with Firestore. Using a social network as example
Stars: ✭ 171 (+131.08%)
Mutual labels:  firebase-functions, firebase, firestore
Combinefirebase
Combine wrapper on Google's iOS Firebase library.
Stars: ✭ 126 (+70.27%)
Mutual labels:  firebase-functions, firebase, firestore
Firebase Gcp Examples
🔥 Firebase app architectures, languages, tools & some GCP things! React w Next.js, Svelte w Sapper, Cloud Functions, Cloud Run.
Stars: ✭ 470 (+535.14%)
Mutual labels:  serverless, firebase-functions, firebase
Awesome Firebase
🔥 List of Firebase talks, tools, examples & articles! Translations in 🇬🇧 🇷🇺 Contributions welcome!
Stars: ✭ 448 (+505.41%)
Mutual labels:  serverless, firebase, firestore
Wild Workouts Go Ddd Example
Complete application to show how to apply DDD, Clean Architecture, and CQRS by practical refactoring of a Go project.
Stars: ✭ 756 (+921.62%)
Mutual labels:  serverless, firebase, firestore
Sapper Template Firebase
Starter Rollup template for Sapper apps with Firebase functions based on https://github.com/nhristov/sapper-template-rollup.
Stars: ✭ 29 (-60.81%)
Mutual labels:  firebase-functions, firebase
Firextensions
[DEPRECATED] 🔥 Unofficial Kotlin Extensions for the Firebase Android SDK.
Stars: ✭ 30 (-59.46%)
Mutual labels:  firebase, firestore
Nativescript Plugin Firebase
🔥 NativeScript plugin for Firebase
Stars: ✭ 990 (+1237.84%)
Mutual labels:  firebase, firestore
Firestorerecycleradaptersample
Sample Android project using FirestoreRecyclerAdapter
Stars: ✭ 43 (-41.89%)
Mutual labels:  firebase, firestore
Hoverboard
Conference website template
Stars: ✭ 935 (+1163.51%)
Mutual labels:  firebase, firestore
Moveit
🚀 NLW #4 | React+ TypeScript + NextJS + StyledComponents + Firebase + MongoDb +Axios
Stars: ✭ 39 (-47.3%)
Mutual labels:  serverless, firebase
Kotlin Firebase Group Chat
Group and OneonOne chat using firebase built in Kotlin similar to whatsapp.
Stars: ✭ 44 (-40.54%)
Mutual labels:  firebase-functions, firebase
Mock Cloud Firestore
Mock library for Cloud Firestore
Stars: ✭ 69 (-6.76%)
Mutual labels:  firebase, firestore
Travelmantics
Firestore & firebase storage MVVM sample
Stars: ✭ 28 (-62.16%)
Mutual labels:  firebase, firestore
Social Note
Social Note - Note-taking, sharing, time & location reminder
Stars: ✭ 38 (-48.65%)
Mutual labels:  firebase, firestore
Angular Universal Firebase
Angular Universal app using Firebase Cloud Functions
Stars: ✭ 14 (-81.08%)
Mutual labels:  firebase-functions, firebase
Paginate firestore
A flutter package to simplify pagination with firestore data 🗃
Stars: ✭ 40 (-45.95%)
Mutual labels:  firebase, firestore
Tiledesk Dashboard
The Tiledesk dashboard. Tiledesk is an Open Source Live Chat platform written in NodeJs, firebase and Angular.
Stars: ✭ 53 (-28.38%)
Mutual labels:  firebase, firestore
Ember Cloud Firestore Adapter
Unofficial Ember Data Adapter and Serializer for Cloud Firestore
Stars: ✭ 51 (-31.08%)
Mutual labels:  firebase, firestore

𝚒𝚗𝚝𝚎𝚐𝚛𝚒𝚏𝚢

Build Status Coverage Status Dependency Status Security npm package Mentioned in Awesome Firebase Firebase Open Source

🤝 Enforce referential and data integrity in Cloud Firestore using triggers

Introductory blog post

Usage

// index.js

const { integrify } = require('integrify');

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();

integrify({ config: { functions, db } });

// Automatically replicate attributes from source to target
module.exports.replicateMasterToDetail = integrify({
  rule: 'REPLICATE_ATTRIBUTES',
  source: {
    collection: 'master',
  },
  targets: [
    {
      collection: 'detail1',
      foreignKey: 'masterId',
      attributeMapping: {
        masterField1: 'detail1Field1',
        masterField2: 'detail1Field2',
      },
    },
    {
      collection: 'detail2',
      foreignKey: 'masterId',
      attributeMapping: {
        masterField1: 'detail2Field1',
        masterField3: 'detail2Field3',
      },

      // Optional:
      isCollectionGroup: true, // Replicate into collection group, see more below
    },
  ],

  // Optional:
  hooks: {
    pre: (change, context) => {
      // Code to execute before replicating attributes
      // See: https://firebase.google.com/docs/functions/firestore-events
    },
  },
});

// Automatically delete stale references
module.exports.deleteReferencesToMaster = integrify({
  rule: 'DELETE_REFERENCES',
  source: {
    collection: 'master',
  },
  targets: [
    {
      collection: 'detail1',
      foreignKey: 'masterId',

      // Optional:
      isCollectionGroup: true, // Delete from collection group, see more below
    },
  ],

  // Optional:
  hooks: {
    pre: (snap, context) => {
      // Code to execute before deleting references
      // See: https://firebase.google.com/docs/functions/firestore-events
    },
  },
});

// Automatically maintain count
module.exports.maintainFavoritesCount = integrify({
  rule: 'MAINTAIN_COUNT',
  source: {
    collection: 'favorites',
    foreignKey: 'articleId',
  },
  target: {
    collection: 'articles',
    attribute: 'favoritesCount',
  },
});

Deploy to Firebase by executing:

$ firebase deploy --only functions

Rules File

Alternately, rules can be specified in a file named integrify.rules.js.

// index.js

const { integrify } = require('integrify');

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();

integrify({ config: { functions, db } });

// Rules will be loaded from "integrify.rules.js"
module.exports = integrify();
// integrify.rules.js

module.exports = [
  {
    rule: 'REPLICATE_ATTRIBUTES',
    name: 'replicateMasterToDetail',
    // ...
  },
  // ...
];

Collection Groups (isCollectionGroup)

Firestore allows searching over multiple collections (a.k.a. collection group) with the same name at any level in the database. This is called a collection group query.

Integrify allows you to replicate tracked master attributes into (optionally) collection groups linked by a foreign key using the isCollectionGroup parameter (see above) in the REPLICATE_ATTRIBUTES rule. Similarly, you can delete references in a collection group (instead of just a collection) using the isCollectionGroup in the DELETE_REFERENCES rule.

Note: You need to first create the appropriate index to be able to use Collection Group Queries. The first time you attempt to use it, Firebase will throw an error message with a link which when clicked will prompt you to create the appropriate index. For example:

The query requires a COLLECTION_GROUP_ASC index for collection detail1 and field masterId. You can create it here: https://console.firebase.google.com/project/integrify-dev/database/firestore/indexes/single_field?create_exemption=ClNwcm9qZWNxxxxxx3RlcklkEAE

For more help, see here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].