Options
All
  • Public
  • Public/Protected
  • All
Menu

🦕 Typesaurus

TypeScript-first ORM for Firestore.

Why?

  • Designed with TypeScript's type inference in mind
  • Universal code (browser & Node.js)
  • Functional API
  • Maximum type-safety
  • Autocomplete
  • Say goodbye to any!
  • Say goodbye to exceptions!

Installation

The library is available as an npm package. To install the package run:

npm install typesaurus --save
# or with yarn
yarn add typesaurus

Get started

Add data

import { collection, add, set, update } from 'typesaurus'

type User = { name: string }
const users = collection<User>('users')

// Add a document to a collection with auto-generated id
add(users, { name: 'Sasha' })
//=> Promise<Doc<User>>

// Set or overwrite a document with given id
set(users, '42', { name: 'Sasha' })
//=> Promise<Doc<User>>

// Update a document with given id
update(users, '42', { name: 'Sasha' })
//=> Promise<void>

Read data

import { collection, get, all, query, where } from 'typesaurus'

type User = { name: string }
const users = collection<User>('users')

// Get a document with given id
get(users, '42')
//=> Promise<Doc<User> | undefined>

// Get all documents in a collection
all(users)
//=> Promise<Doc<User>[]>

// Query collection
query(users, [where('name', '===', 'Sasha')])
//=> Promise<Doc<User>[]>

Remove data

import { collection, remove } from 'typesaurus'

type User = { name: string }
const users = collection<User>('users')

// Remove a document with given id
remove(users, '42')
//=> Promise<void>

API Reference

Query data

  • all - Returns all documents in a collection.
  • get - Retrieves a document from a collection.
  • query - Queries passed collection using query objects (order, where, limit).

Query helpers:

  • order - Creates order query object with given field, ordering method and pagination cursors.
  • limit - Creates a limit query object. It's used to paginate queries.
  • where - Creates where query with array-contains filter operation.
  • untypedWhereArrayContains - Creates where query with array-contains filter operation.

Pagination helpers:

  • endAt - Ends the query results on the given value.
  • endBefore - Ends the query results before the given value.
  • startAfter - Start the query results after the given value.
  • startAt - Start the query results on the given value.

Real-time:

  • onAll - Subscribes to all documents in a collection.
  • onGet - Subscribes to the diven document.
  • onQuery - Subscribes to a collection query built using query objects (order, where, limit).

Operations

  • add - Adds a new document with a random id to a collection.
  • set - Sets a document to the given data.
  • update - Updates a document.
  • remove - Removes a document.

Operation helpers:

  • field - Creates a field object. It's used to update nested maps.

Constructors

  • collection - Creates a collection object.
  • subcollection - Creates a subcollection function which accepts parent document reference and returns the subcollection transformed into a collection object.
  • group - Creates a collection group object.
  • doc - Creates a document object.
  • ref - Creates reference object to a document in given collection with given id.

Transactions and batched writes

Changelog

See the changelog.

License

MIT © Sasha Koss

Index

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc