Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

NestedSubcollection

NestedSubcollection<Model, ParentModel, ParentIds>: function

Type parameters

  • Model

  • ParentModel

  • ParentIds: Array<string>

Type declaration

Subcollection

Subcollection<Model, ParentModel>: function

The subcollection function type.

Type parameters

  • Model

  • ParentModel

Type declaration

Functions

subcollection

  • subcollection<Model, ParentModel>(name: string, parentCollection: Collection<ParentModel>): Subcollection<Model, ParentModel>
  • subcollection<Model, SubcollectionModel, SubcollectionParentModel>(name: string, parentSubcollection: Subcollection<SubcollectionModel, SubcollectionParentModel>): NestedSubcollection<Model, SubcollectionModel, [string, string]>
  • subcollection<Model, SubcollectionModel, SubcollectionParentModel, SubcollectionIds>(name: string, parentSubcollection: NestedSubcollection<SubcollectionModel, SubcollectionParentModel, SubcollectionIds>): NestedSubcollection<Model, SubcollectionModel, [string, string, string]>
  • subcollection<Model, SubcollectionModel, SubcollectionParentModel, SubcollectionIds>(name: string, parentSubcollection: NestedSubcollection<SubcollectionModel, SubcollectionParentModel, SubcollectionIds>): NestedSubcollection<Model, SubcollectionModel, [string, string, string, string]>
  • subcollection<Model, SubcollectionModel, SubcollectionParentModel, SubcollectionIds>(name: string, parentSubcollection: NestedSubcollection<SubcollectionModel, SubcollectionParentModel, SubcollectionIds>): NestedSubcollection<Model, SubcollectionModel, [string, string, string, string, string]>
  • Creates a subcollection function which accepts parent document reference or id and returns the subcollection trasnformed into a collection object.

    import { subcollection, collection, ref, add } from 'typesaurus'
    
    type User = { name: string }
    type Order = { item: string }
    const users = collection<User>('users')
    const userOrders = subcollection<Order, User>('orders')
    
    const sashasOrders = userOrders('00sHm46UWKObv2W7XK9e')
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/orders' }
    // Also accepts reference:
    userOrders(ref(users, '00sHm46UWKObv2W7XK9e'))
    
    add(sashasOrders, { item: 'Snowboard boots' })

    The subcollection function can be passed as the parent collection to create nested subcollection:

    import { subcollection, collection, ref, add, Ref } from '.'
    
    type User = { name: string }
    type Post = { author: Ref<User>; text: string; date?: Date }
    type Comment = { author: Ref<User>; text: string; date?: Date }
    type Like = { author: Ref<User> }
    
    const users = collection<User>('users')
    const userPosts = subcollection<Post, User>('posts', users)
    // Generic types:
    // - Comment - the subcollection model
    // - Post - the parent model
    // - User - the grandparent model
    const postComments = subcollection<Comment, Post, User>('comments', userPosts)
    // Generic types:
    // - Like - the subcollection model
    // - Comment - the parent model
    // - Post - the grandparent model
    // - [string, string] - the ids type, a string for each level of nesting
    const commentLikes = subcollection<Like, Comment, Post, [string, string]>(
      'likes',
      postComments
    )
    
    // Using ids:
    
    const userId = '00sHm46UWKObv2W7XK9e'
    const postId = '2ZWn8t4w2F3LVz2azVCN'
    const commentId = 'UBHKjURqRZVpjvCwSKuO'
    
    userPosts(userId)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    postComments([userId, postId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    commentLikes([userId, postId, commentId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }
    
    // Or using refs:
    
    const user = ref(users, userId)
    userPosts(user)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    const post = ref(userPosts(user))
    postComments(post)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    const comment = ref(postComments(post))
    commentLikes(comment)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }

    Type parameters

    • Model

    • ParentModel

    Parameters

    • name: string

      The subcollection name

    • parentCollection: Collection<ParentModel>

      The parent collection, subcollection or nested subcollection

    Returns Subcollection<Model, ParentModel>

    Function which accepts parent document ref or id and returns collection object

  • Creates a subcollection function which accepts parent document reference or id and returns the subcollection trasnformed into a collection object.

    import { subcollection, collection, ref, add } from 'typesaurus'
    
    type User = { name: string }
    type Order = { item: string }
    const users = collection<User>('users')
    const userOrders = subcollection<Order, User>('orders')
    
    const sashasOrders = userOrders('00sHm46UWKObv2W7XK9e')
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/orders' }
    // Also accepts reference:
    userOrders(ref(users, '00sHm46UWKObv2W7XK9e'))
    
    add(sashasOrders, { item: 'Snowboard boots' })

    The subcollection function can be passed as the parent collection to create nested subcollection:

    import { subcollection, collection, ref, add, Ref } from '.'
    
    type User = { name: string }
    type Post = { author: Ref<User>; text: string; date?: Date }
    type Comment = { author: Ref<User>; text: string; date?: Date }
    type Like = { author: Ref<User> }
    
    const users = collection<User>('users')
    const userPosts = subcollection<Post, User>('posts', users)
    // Generic types:
    // - Comment - the subcollection model
    // - Post - the parent model
    // - User - the grandparent model
    const postComments = subcollection<Comment, Post, User>('comments', userPosts)
    // Generic types:
    // - Like - the subcollection model
    // - Comment - the parent model
    // - Post - the grandparent model
    // - [string, string] - the ids type, a string for each level of nesting
    const commentLikes = subcollection<Like, Comment, Post, [string, string]>(
      'likes',
      postComments
    )
    
    // Using ids:
    
    const userId = '00sHm46UWKObv2W7XK9e'
    const postId = '2ZWn8t4w2F3LVz2azVCN'
    const commentId = 'UBHKjURqRZVpjvCwSKuO'
    
    userPosts(userId)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    postComments([userId, postId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    commentLikes([userId, postId, commentId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }
    
    // Or using refs:
    
    const user = ref(users, userId)
    userPosts(user)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    const post = ref(userPosts(user))
    postComments(post)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    const comment = ref(postComments(post))
    commentLikes(comment)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }

    Type parameters

    • Model

    • SubcollectionModel

    • SubcollectionParentModel

    Parameters

    • name: string

      The subcollection name

    • parentSubcollection: Subcollection<SubcollectionModel, SubcollectionParentModel>

    Returns NestedSubcollection<Model, SubcollectionModel, [string, string]>

    Function which accepts parent document ref or id and returns collection object

  • Creates a subcollection function which accepts parent document reference or id and returns the subcollection trasnformed into a collection object.

    import { subcollection, collection, ref, add } from 'typesaurus'
    
    type User = { name: string }
    type Order = { item: string }
    const users = collection<User>('users')
    const userOrders = subcollection<Order, User>('orders')
    
    const sashasOrders = userOrders('00sHm46UWKObv2W7XK9e')
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/orders' }
    // Also accepts reference:
    userOrders(ref(users, '00sHm46UWKObv2W7XK9e'))
    
    add(sashasOrders, { item: 'Snowboard boots' })

    The subcollection function can be passed as the parent collection to create nested subcollection:

    import { subcollection, collection, ref, add, Ref } from '.'
    
    type User = { name: string }
    type Post = { author: Ref<User>; text: string; date?: Date }
    type Comment = { author: Ref<User>; text: string; date?: Date }
    type Like = { author: Ref<User> }
    
    const users = collection<User>('users')
    const userPosts = subcollection<Post, User>('posts', users)
    // Generic types:
    // - Comment - the subcollection model
    // - Post - the parent model
    // - User - the grandparent model
    const postComments = subcollection<Comment, Post, User>('comments', userPosts)
    // Generic types:
    // - Like - the subcollection model
    // - Comment - the parent model
    // - Post - the grandparent model
    // - [string, string] - the ids type, a string for each level of nesting
    const commentLikes = subcollection<Like, Comment, Post, [string, string]>(
      'likes',
      postComments
    )
    
    // Using ids:
    
    const userId = '00sHm46UWKObv2W7XK9e'
    const postId = '2ZWn8t4w2F3LVz2azVCN'
    const commentId = 'UBHKjURqRZVpjvCwSKuO'
    
    userPosts(userId)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    postComments([userId, postId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    commentLikes([userId, postId, commentId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }
    
    // Or using refs:
    
    const user = ref(users, userId)
    userPosts(user)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    const post = ref(userPosts(user))
    postComments(post)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    const comment = ref(postComments(post))
    commentLikes(comment)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }

    Type parameters

    • Model

    • SubcollectionModel

    • SubcollectionParentModel

    • SubcollectionIds: [string, string]

    Parameters

    • name: string

      The subcollection name

    • parentSubcollection: NestedSubcollection<SubcollectionModel, SubcollectionParentModel, SubcollectionIds>

    Returns NestedSubcollection<Model, SubcollectionModel, [string, string, string]>

    Function which accepts parent document ref or id and returns collection object

  • Creates a subcollection function which accepts parent document reference or id and returns the subcollection trasnformed into a collection object.

    import { subcollection, collection, ref, add } from 'typesaurus'
    
    type User = { name: string }
    type Order = { item: string }
    const users = collection<User>('users')
    const userOrders = subcollection<Order, User>('orders')
    
    const sashasOrders = userOrders('00sHm46UWKObv2W7XK9e')
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/orders' }
    // Also accepts reference:
    userOrders(ref(users, '00sHm46UWKObv2W7XK9e'))
    
    add(sashasOrders, { item: 'Snowboard boots' })

    The subcollection function can be passed as the parent collection to create nested subcollection:

    import { subcollection, collection, ref, add, Ref } from '.'
    
    type User = { name: string }
    type Post = { author: Ref<User>; text: string; date?: Date }
    type Comment = { author: Ref<User>; text: string; date?: Date }
    type Like = { author: Ref<User> }
    
    const users = collection<User>('users')
    const userPosts = subcollection<Post, User>('posts', users)
    // Generic types:
    // - Comment - the subcollection model
    // - Post - the parent model
    // - User - the grandparent model
    const postComments = subcollection<Comment, Post, User>('comments', userPosts)
    // Generic types:
    // - Like - the subcollection model
    // - Comment - the parent model
    // - Post - the grandparent model
    // - [string, string] - the ids type, a string for each level of nesting
    const commentLikes = subcollection<Like, Comment, Post, [string, string]>(
      'likes',
      postComments
    )
    
    // Using ids:
    
    const userId = '00sHm46UWKObv2W7XK9e'
    const postId = '2ZWn8t4w2F3LVz2azVCN'
    const commentId = 'UBHKjURqRZVpjvCwSKuO'
    
    userPosts(userId)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    postComments([userId, postId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    commentLikes([userId, postId, commentId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }
    
    // Or using refs:
    
    const user = ref(users, userId)
    userPosts(user)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    const post = ref(userPosts(user))
    postComments(post)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    const comment = ref(postComments(post))
    commentLikes(comment)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }

    Type parameters

    • Model

    • SubcollectionModel

    • SubcollectionParentModel

    • SubcollectionIds: [string, string, string]

    Parameters

    • name: string

      The subcollection name

    • parentSubcollection: NestedSubcollection<SubcollectionModel, SubcollectionParentModel, SubcollectionIds>

    Returns NestedSubcollection<Model, SubcollectionModel, [string, string, string, string]>

    Function which accepts parent document ref or id and returns collection object

  • Creates a subcollection function which accepts parent document reference or id and returns the subcollection trasnformed into a collection object.

    import { subcollection, collection, ref, add } from 'typesaurus'
    
    type User = { name: string }
    type Order = { item: string }
    const users = collection<User>('users')
    const userOrders = subcollection<Order, User>('orders')
    
    const sashasOrders = userOrders('00sHm46UWKObv2W7XK9e')
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/orders' }
    // Also accepts reference:
    userOrders(ref(users, '00sHm46UWKObv2W7XK9e'))
    
    add(sashasOrders, { item: 'Snowboard boots' })

    The subcollection function can be passed as the parent collection to create nested subcollection:

    import { subcollection, collection, ref, add, Ref } from '.'
    
    type User = { name: string }
    type Post = { author: Ref<User>; text: string; date?: Date }
    type Comment = { author: Ref<User>; text: string; date?: Date }
    type Like = { author: Ref<User> }
    
    const users = collection<User>('users')
    const userPosts = subcollection<Post, User>('posts', users)
    // Generic types:
    // - Comment - the subcollection model
    // - Post - the parent model
    // - User - the grandparent model
    const postComments = subcollection<Comment, Post, User>('comments', userPosts)
    // Generic types:
    // - Like - the subcollection model
    // - Comment - the parent model
    // - Post - the grandparent model
    // - [string, string] - the ids type, a string for each level of nesting
    const commentLikes = subcollection<Like, Comment, Post, [string, string]>(
      'likes',
      postComments
    )
    
    // Using ids:
    
    const userId = '00sHm46UWKObv2W7XK9e'
    const postId = '2ZWn8t4w2F3LVz2azVCN'
    const commentId = 'UBHKjURqRZVpjvCwSKuO'
    
    userPosts(userId)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    postComments([userId, postId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    commentLikes([userId, postId, commentId])
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }
    
    // Or using refs:
    
    const user = ref(users, userId)
    userPosts(user)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts' }
    
    const post = ref(userPosts(user))
    postComments(post)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments' }
    
    const comment = ref(postComments(post))
    commentLikes(comment)
    //=> { __type__: 'collection', path: 'users/00sHm46UWKObv2W7XK9e/posts/2ZWn8t4w2F3LVz2azVCN/comments/UBHKjURqRZVpjvCwSKuO/likes' }

    Type parameters

    • Model

    • SubcollectionModel

    • SubcollectionParentModel

    • SubcollectionIds: [string, string, string, string]

    Parameters

    • name: string

      The subcollection name

    • parentSubcollection: NestedSubcollection<SubcollectionModel, SubcollectionParentModel, SubcollectionIds>

    Returns NestedSubcollection<Model, SubcollectionModel, [string, string, string, string, string]>

    Function which accepts parent document ref or id and returns collection object

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