This library is an implementation of the firebase repository pattern and some helpers to facilitate the work of developers using firebase. - (ts projects only)
npm i fire-repo
Only you need download the code and install the dependencies running the command npm install
.
The used libraries are:
-
📁
.github
: Contains the github actions configurations. -
📁
example
: Contains the example of usage from library.- ts
configuration.ts
: Example of configuration. - ts
index.ts
: Example of usage.
- ts
-
📁
helpers
: Contains the helpers of library.- ts
fire-file.helper.ts
: Helper to work with firebase files. - ts
fire-mapping.helper.ts
: Helper to mapping the firebase data. - ts
index.ts
: Export the helpers.
- ts
-
📁
models
: Contains the models of library- ts
base.model.ts
: Base model.
- ts
-
📁
repositories
: Contains the repositories of library- 📁
implementations
: Contains the implementations of repositories. - 📁
interfaces
: Contains the interfaces of library.- ts
index.ts
: Export the interfaces. - ts
read.interface.ts
: Interface to read data. - ts
write.interface.ts
: Interface to write data.
- ts
- 📁
types
: Contains the types of library.- ts
filter.type.ts
: Type to filter data. - ts
index.ts
: Export the types.
- ts
- 📁
-
📁
test
- 📁
helpers
: Contains the test of helpers. - 📁
repositories
: Contains the test of repositories
- 📁
For use the library in you project you need install the fire-repo library running the command npm i fire-repo
and import the library in your project.
import { FireRepository } from "fire-repo";
import { BaseModel } from "fire-repo";
Create your model extending the base model.
class User extends BaseModel {
name: string;
email: string;
}
Create your service class for work with the repository and manage the entity and data.
class UserService extends FireRepository<User> {
constructor() {
/**
* @param {initializeApp} firebaseConfiguration firebase configuration
* @param {string} collection firebase collection "/test"
*/
super(firebaseConfiguration, collection);
}
}
-
add
: Create a new entity. -
update
: Update an entity. -
deleteEntity
: Delete an entity. -
remove
: Applied the soft delete a entity. -
getAll
: Get all entities. -
getOne
: Get One entity. -
getDocId
: Get the document id. -
getCollection
: Get the collection.
-
fileUpload
: Upload a file to firebase storage. -
removeFile
: Remove a file from firebase storage. -
toEntityArray
: Convert an array of firebase data to an array of entities. -
getFormateadFirebaseData
: Format the retrieved data from firebase. (Date - timestamp)
If you want to contribute to the library you can create a branch in the repository and send a pull request. Remember create great unit tests and documentation updates.
Remember usage this structure:
feature/[name]
fix/[name]
bug/[name]
If you have an issue or a problem with the library you can report it in the issues