With this incredible Firestore toolkit, you can easily start coding in JavaScript using annotations with Firestore from Google Cloud.
Hi, my name is Andi. I work as a Lead iOS Engineer and Product Designer | Freelancing and Contract | Swift / iOS, macOS, GraphQL, Google Cloud and NodeJS for more than 13+ years 👋,
I actively maintain this toolkit. 🚀
I love to share this reliable and efficient Firestore toolkit with you. You can use it whenever you want for free to develop an incredible data layer.
You can contact me at any time contact@andireuter.com.
You can find me on
, or on
, or on
.
You have to paste this file .npmrc in the root folder of your code base. Because this NPM package is published to GitHub.
@andireuter:registry=https://npm.pkg.github.comnpm install @andireuter/js-domain-principlesdeno add @andireuter/js-domain-principlesA collection is also known as an entity. It contains a collection name and attributes to store data in Google Firestore.
You can declare the attributes with decorators to give it a purpose. Otherwise attributes without a decorator are being ignored.
@Collection({ name: "collection name" })
@EntityKey({ type: "string" })
@Attribute({
type: "[string|number|bool|object]",
object?: object, // Don't append that if type isn't "object".
optional: false
})
@ForeignKey({
collection: object,
optional: false
})Look at the example below, first an entity is declared for a collection in Google Firestore. It does not inherit from anything and should be declared as an object.
//
// RankingList.entity.ts
@Collection({ name: "RankingLists" })
class RankingList {
@EntityKey({ type: "string" })
id: string
@Attribute({
type: "number",
optional: false,
})
scores: number[]
@Attribute({
type: "object",
object: PlayingTime
optional: false,
})
game: PlayingTime
@Attribute({
type: "object",
object: Club
optional: false,
})
clubs: Club[]
@ForeignKey({
collection: Game,
optional: false,
})
game: Game
}Don't forget that every object property needs an initial value. Otherwise it gets undefined at run time. You can add a constructor or assign a value at definition.
You can directly access an instance of the Firestore context object, and hand over the collection as declared above or inherit from that same object to build a sophisticated custom context object yourself. Below you will find an example.
//
// RankingList.context.ts
class RankingListContext extends Firestore<RankingList> {
async insertRank(entity: RankingList): Promise<RankingList | undefined> {
return await this.insert(entity)
}
async changeRank(entity: RankingList): Promise<RankingList | undefined> {
return await this.changeById(entity)
}
async fetchRanks(): Promise<RankingList[] | undefined> {
return await this.fetch(RankingList)
}
}