How to use ember-cloud-firestore-adapter - 10 common examples

To help you get started, we’ve selected a few ember-cloud-firestore-adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikkopaderes / ember-cloud-firestore-adapter / tests / dummy / app / adapters / application.js View on Github external
import CloudFirestoreAdapter from 'ember-cloud-firestore-adapter/adapters/cloud-firestore';

export default CloudFirestoreAdapter.extend();
github mikkopaderes / ember-cloud-firestore-adapter / addon-test-support / mocks / cloud-firestore.js View on Github external
export default function mockCloudFirestore(owner, fixtureData) {
  initializeInstanceInitializer(owner);

  const mockFirebase = new MockFirebase();

  const mockFirebasePojo = {
    _data: fixtureData,
    initializeApp: mockFirebase.initializeApp,
    firestore: mockFirebase.firestore,
  };
  const firebaseService = Service.extend(mockFirebasePojo);

  owner.register('service:firebase', firebaseService);

  return owner.lookup('service:firebase', { as: 'firebase' });
}
github mikkopaderes / ember-cloud-firestore-adapter / tests / helpers / module-for-acceptance.js View on Github external
beforeEach() {
      this.application = startApp();

      const owner = this.application.__container__.owner;

      mockFirebase(owner, getFixtureData());

      if (options.beforeEach) {
        return options.beforeEach.apply(this, arguments);
      }
    },
github mikkopaderes / ember-cloud-firestore-adapter / addon / serializers / cloud-firestore.js View on Github external
extractRelationship(relationshipModelName, relationshipHash) {
    if (isDocumentReference(relationshipHash)) {
      const path = buildPathFromRef(relationshipHash);
      const pathNodes = path.split('/');
      const belongsToId = pathNodes[pathNodes.length - 1];

      return { id: belongsToId, type: relationshipModelName };
    }

    return null;
  },
github mikkopaderes / ember-cloud-firestore-adapter / addon / adapters / cloud-firestore.js View on Github external
init(...args) {
    this._super(...args);

    if (this.firestoreSettings) {
      const db = this.firebase.firestore();

      db.settings(this.firestoreSettings);
    }

    this.set('realtimeTracker', new RealtimeTracker());
  },
github mikkopaderes / ember-cloud-firestore-adapter / addon / adapters / cloud-firestore.js View on Github external
return new Promise((resolve, reject) => {
      const db = this.firebase.firestore();
      const collectionRef = db.collection(buildCollectionName(type.modelName));
      const unsubscribe = collectionRef.onSnapshot((querySnapshot) => {
        if (this.getAdapterOptionConfig(snapshotRecordArray, 'isRealtime') && !this.isFastBoot) {
          this.realtimeTracker.trackFindAllChanges(type.modelName, collectionRef, store);
        }

        const requests = querySnapshot.docs.map(docSnapshot => (
          this.findRecord(store, type, docSnapshot.id, snapshotRecordArray)
        ));

        Promise.all(requests).then(records => resolve(records)).catch(error => (
          reject(new Error(error.message))
        ));

        unsubscribe();
      }, error => reject(new Error(error.message)));
    });
github mikkopaderes / ember-cloud-firestore-adapter / addon / serializers / cloud-firestore.js View on Github external
if (
          Object.prototype.hasOwnProperty.call(resourceHash, name)
          && isDocumentReference(resourceHash[name])
        ) {
          const path = buildPathFromRef(resourceHash[name]);

          links[name] = path;
        }
      } else {
        const cardinality = modelClass.determineRelationshipType(descriptor, this.store);
        let hasManyPath;

        if (cardinality === 'manyToOne') {
          hasManyPath = buildCollectionName(descriptor.type);
        } else {
          const collectionName = buildCollectionName(modelClass.modelName);
          const docId = resourceHash.id;

          hasManyPath = `${collectionName}/${docId}/${name}`;
        }

        links[name] = hasManyPath;
      }
    });
github mikkopaderes / ember-cloud-firestore-adapter / addon / adapters / cloud-firestore.js View on Github external
buildHasManyCollectionRef(store, snapshot, url, relationship) {
    const db = this.firebase.firestore();
    const cardinality = snapshot.type.determineRelationshipType(relationship, store);
    let collectionRef;

    if (cardinality === 'manyToOne') {
      const inverse = snapshot.type.inverseFor(relationship.key, store);
      const collectionName = buildCollectionName(snapshot.modelName);
      const reference = db.collection(collectionName).doc(snapshot.id);

      collectionRef = db.collection(url).where(inverse.name, '==', reference);
    } else if (Object.prototype.hasOwnProperty.call(relationship.options, 'buildReference')) {
      collectionRef = relationship.options.buildReference(db, snapshot.record);
    } else {
      collectionRef = buildRefFromPath(db, url);
    }

    return this.buildQuery(collectionRef, relationship.options, snapshot.record);
  },
github mikkopaderes / ember-cloud-firestore-adapter / addon / serializers / cloud-firestore.js View on Github external
modelClass.eachRelationship((name, descriptor) => {
      if (descriptor.kind === 'belongsTo') {
        if (
          Object.prototype.hasOwnProperty.call(resourceHash, name)
          && isDocumentReference(resourceHash[name])
        ) {
          const path = buildPathFromRef(resourceHash[name]);

          links[name] = path;
        }
      } else {
        const cardinality = modelClass.determineRelationshipType(descriptor, this.store);
        let hasManyPath;

        if (cardinality === 'manyToOne') {
          hasManyPath = buildCollectionName(descriptor.type);
        } else {
          const collectionName = buildCollectionName(modelClass.modelName);
          const docId = resourceHash.id;

          hasManyPath = `${collectionName}/${docId}/${name}`;
        }

        links[name] = hasManyPath;
      }
    });
github mikkopaderes / ember-cloud-firestore-adapter / addon / adapters / cloud-firestore.js View on Github external
generateIdForRecord(store, type) {
    const db = this.firebase.firestore();
    const collectionName = buildCollectionName(type);

    return db.collection(collectionName).doc().id;
  },