Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

firex-store

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firex-store - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

lib/service/helpers/index.d.ts

4

lib/find.d.ts
import { FindCriteriaOptions } from './options';
import { FirestoreRef } from './types';
import { FirestoreRef, NullOr } from './types';
interface Criteria<T, U> {

@@ -7,3 +7,3 @@ ref: T;

}
export declare const findFirestore: <T = any>({ ref, options }: Criteria<FirestoreRef, T>) => Promise<T>;
export declare const findFirestore: <T = any>({ ref, options }: Criteria<FirestoreRef, T>) => Promise<NullOr<T>>;
export {};

@@ -1,2 +0,2 @@

import { FireMutation } from '../types';
import { CallMutation, NullOr } from '../types';
import { Unsubscribe } from 'firebase';

@@ -6,3 +6,3 @@ import { SubscribeCriteriaOptions, FindCriteriaOptions } from '../options';

ref: U;
fireMutation: FireMutation;
callMutation: CallMutation;
}

@@ -13,7 +13,7 @@ interface FindCriteria<T, U> extends FindCriteriaOptions<T> {

export declare class FirestoreService {
static subscribe<T = any>({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }: SubscribeCriteria<T, firebase.firestore.DocumentReference>): Unsubscribe;
static subscribeAll<T = any>({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }: SubscribeCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Unsubscribe;
static find<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.DocumentReference>): Promise<T | any>;
static findAll<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Promise<T[] | any | any[]>;
static subscribe<T = any>({ ref, callMutation, mapper, errorHandler, onCompleted, afterMutationCalled }: SubscribeCriteria<T, firebase.firestore.DocumentReference>): Unsubscribe;
static subscribeAll<T = any>({ ref, callMutation, mapper, errorHandler, onCompleted, afterMutationCalled }: SubscribeCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Unsubscribe;
static find<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.DocumentReference>): Promise<NullOr<T | any>>;
static findAll<T = any>({ ref, mapper, errorHandler, onCompleted }: FindCriteria<T, firebase.firestore.CollectionReference | firebase.firestore.Query>): Promise<NullOr<T[] | any | any[]>>;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const helpers_1 = require("./helpers");
class FirestoreService {
static subscribe({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }) {
static subscribe({ ref, callMutation, mapper, errorHandler, onCompleted, afterMutationCalled }) {
return ref.onSnapshot((doc) => {

@@ -10,5 +10,5 @@ if (!doc.exists) {

}
const data = utils_1.mapToIfDefined(doc, mapper);
const data = helpers_1.mapToIfDefined(doc, mapper);
const payload = { data, isLast: true };
fireMutation('added', payload);
callMutation('added', payload);
if (afterMutationCalled) {

@@ -24,3 +24,3 @@ afterMutationCalled(payload);

}
static subscribeAll({ ref, fireMutation, mapper, errorHandler, onCompleted, afterMutationCalled }) {
static subscribeAll({ ref, callMutation, mapper, errorHandler, onCompleted, afterMutationCalled }) {
return ref.onSnapshot((snapshot) => {

@@ -32,5 +32,5 @@ const length = snapshot.docChanges().length;

}
const data = utils_1.mapToIfDefined(change.doc, mapper);
const data = helpers_1.mapToIfDefined(change.doc, mapper);
const payload = { data, isLast: length === index + 1 };
fireMutation(change.type, payload);
callMutation(change.type, payload);
if (afterMutationCalled) {

@@ -50,9 +50,3 @@ afterMutationCalled(payload);

.get()
.then((doc) => {
if (!doc.exists) {
return;
}
const payload = utils_1.mapToIfDefined(doc, mapper);
return payload;
})
.then((doc) => (!doc.exists ? null : helpers_1.mapToIfDefined(doc, mapper)))
.catch((error) => errorHandler ? errorHandler(error) : console.error(error));

@@ -67,9 +61,9 @@ if (onCompleted) {

.get()
.then((snapshot) => snapshot.docs.map((doc) => {
if (!doc.exists) {
return;
}
const payload = utils_1.mapToIfDefined(doc, mapper);
return payload;
}))
.then((snapshot) => snapshot.empty
? []
: snapshot.docs.map((doc) => !doc.exists ? null : helpers_1.mapToIfDefined(doc, mapper)))
.then((documentResults) => {
const resultWithoutNull = documentResults.filter((it) => it !== null);
return resultWithoutNull.length > 0 ? resultWithoutNull : null;
})
.catch((error) => errorHandler ? errorHandler(error) : console.error(error));

@@ -76,0 +70,0 @@ if (onCompleted) {

@@ -6,3 +6,3 @@ "use strict";

const is_document_ref_1 = require("./is-document-ref");
const fire_mutation_1 = require("./fire-mutation");
const call_mutation_1 = require("./call-mutation");
const subscribeFirestoreCollection = ({ state, commit, ref, options }) => {

@@ -12,6 +12,6 @@ if (state[configurations_1.FIREX_COLLECTION_UNSUBSCRIBER]) {

}
const mutation = (changeType, payload) => fire_mutation_1.fireMutation({ mutationType: 'collection', changeType, commit, payload });
const mutation = (changeType, payload) => call_mutation_1.callMutation({ mutationType: 'collection', changeType, commit, payload });
const unsubscriber = service_1.FirestoreService.subscribeAll({
ref,
fireMutation: mutation,
callMutation: mutation,
...options

@@ -25,6 +25,6 @@ });

}
const mutation = (changeType, payload) => fire_mutation_1.fireMutation({ mutationType: 'document', changeType, commit, payload });
const mutation = (changeType, payload) => call_mutation_1.callMutation({ mutationType: 'document', changeType, commit, payload });
const unsubscriber = service_1.FirestoreService.subscribe({
ref,
fireMutation: mutation,
callMutation: mutation,
...options

@@ -31,0 +31,0 @@ });

export * from './error-handler.type';
export * from './fire-mutation.type';
export * from './call-mutation.type';
export * from './mapper.type';

@@ -8,1 +8,2 @@ export * from './mutation-type.type';

export * from './subscribe-hooks.type';
export * from './null-or.type';
{
"name": "firex-store",
"version": "0.5.0",
"version": "0.6.0",
"description": "subscribe firebase data to vuex",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -42,3 +42,3 @@ # firex-store

- you must initailize firebase
- You have to initailize firebase

@@ -66,3 +66,3 @@ ```javascript

Ex. subscribe collection
Ex. Subscribe collection

@@ -94,3 +94,3 @@ ```javascript

Ex. subscribe collection
Ex. Subscribe collection

@@ -118,3 +118,3 @@ ```javascript

Ex. subscribe collection
Ex. Subscribe collection

@@ -144,3 +144,3 @@ ```javascript

Ex. subscribe collection
Ex. Subscribe collection

@@ -198,3 +198,3 @@ ```javascript

Ex. unsubscribe collection
Ex. Unsubscribe collection

@@ -289,4 +289,6 @@ #### part1. Add `firestoreUnsubscribeActions` in actions

EX. call in Store Action, to fetch collection
- Return `null` if data not found
EX. Call in Store Action, to fetch collection
```javascript

@@ -328,3 +330,3 @@ export default {

- If it defined, call it when completed
- this method called after mutation called
- This method called after mutation called

@@ -331,0 +333,0 @@ Ex.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc