Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection

Creates a collection. All collections are automatically served via the REST API, with permissions set by the Policies

Hierarchy

  • Collection

Index

Creating a collection

constructor

  • Create a new app. This is not the most elegant way to create a collection, it's better to use Collection.fromDefinition

    category

    Creating a collection

    Parameters

    Returns Collection

Static fromDefinition

  • Use a "definition object" to describe the shape and behavior of the collection.

    Example:

    import {
      App,
      Collection,
      FieldTypes,
      FieldDefinitionHelper as field,
      Policies,
    } from "sealious";
    
    const app = new App();
    
    Collection.fromDefinition(
     app,
     {
     name: "seals",
     fields: [
       field("name", FieldTypes.Text),
       field("age", FieldTypes.Int, { min: 0 }),
     ],
     policy: {
       show: Policies.Public,
       delete: Policies.Noone,
     },
    });

    Parameters

    • app: App

      the collection read from definition will be attached to this app

    • definition: CollectionDefinition

      the definition of the appliaction, containing the fields and policies

    Returns Collection

Other

app

app: App

the app

calculated_fields

calculated_fields: {}

stores the calculated fields of the collection

Type declaration

definition

the collection definition

display_hints

display_hints: any

An arbitrary value that can be use by front-ends to e.g. format forms for given collection in a specific way

Readonly fields

fields: {}

Stores all the fields in the given collection. Does not store values of those fields.

This is a read-only property. If you want to change fields in an existing collection, use Collection.addField

Type declaration

  • [field_name: string]: Field

human_readable_name

human_readable_name: string | null

Used while creating a REST API documentation for your app

name

name: string

The name of the collection. This is used as the part of it's URL in the REST API

named_filters

named_filters: {}

stores the special filtes attached to this collection

Type declaration

policy

policy: {}

stores Policies for some of the possible ActionNames. If no policy is specified for a given action, the policy under the default key is used.

Type declaration

summary

summary: string | null
todo

find out what that is

addField

  • Adds a field to collection. It's usually not necessary, because you can add all the necessary fields while creating the collection.

    Parameters

    Returns void

addSpecialFilters

  • addSpecialFilters(named_filters: {}): void
  • Add special filters to the collection

    Parameters

    • named_filters: {}

      the filters to add

    Returns void

checkIfActionIsAllowed

  • Throws if a given ActionName is not allowed to be performed on a given Item under given context

    Parameters

    • context: Context

      the context

    • action_name: ActionName

      the action name

    • Optional item: Item

      the item (pass undefined if checking actions like create as then there's no item to check on)

    Returns Promise<void>

getAggregationStages

  • getAggregationStages(context: Context, action_name: ActionName, query_params: { filter?: undefined | {}; search?: undefined | {} }, ids?: string[], named_filters?: string[]): Promise<QueryStage[]>
  • Gets the aggregation stages that filter the resources based on Policies, filters, search params and named filters. Returns a mongo pipeline. This is done in order to avoid having to manually check each item returned from the database

    todo

    check if removing the ids arg breaks anything

    Parameters

    • context: Context

      the context

    • action_name: ActionName
    • query_params: { filter?: undefined | {}; search?: undefined | {} }

      query params - e.g. parsed from a REST GET request

      • Optional filter?: undefined | {}

        the filter object that can contain filter values for any of the fields in the collection

      • Optional search?: undefined | {}

        the search string

    • Default value ids: string[] = []

      deprecated

    • Default value named_filters: string[] = []

      names of any named filters that should be applied to the query

    Returns Promise<QueryStage[]>

getNamedFilter

  • Return a named filter from the collection

    Parameters

    • filter_name: string

      the name of the filter

    Returns SpecialFilter

getPolicy

getResourceRepresentation

  • getResourceRepresentation(context: Context, db_document: any, format: any, calculate?: boolean | values<boolean>): Promise<Item>
  • Takes a db entry of an item and formats it so it can be presented to the user

    Parameters

    • context: Context

      the context

    • db_document: any

      the raw db entry

    • format: any

      the formats for some/all/none of the fields

    • Optional calculate: boolean | values<boolean>

      whether or not to compute some/all of the fields

    Returns Promise<Item>

getSpecification

  • getSpecification(summary: any): { display_hints: any; fields: {}; human_readable_name: null | string; name: string; summary: any }
  • Return the specification of the collection to be returned when generating the docs for the REST API

    internal;

    Parameters

    • summary: any

      the human-readable description of the collection

    Returns { display_hints: any; fields: {}; human_readable_name: null | string; name: string; summary: any }

    • display_hints: any
    • fields: {}
      • [field: string]: { display_hints: any; name: string; required?: undefined | false | true; type: string }
        • display_hints: any
        • name: string
        • Optional required?: undefined | false | true
        • type: string
    • human_readable_name: null | string
    • name: string
    • summary: any

setPolicy

  • setPolicy(strategy_definition: Partial<{}>): void
  • Set a policy for given actions

    Parameters

    • strategy_definition: Partial<{}>

      an object that maps a given ActionName to a Policy. Not all action names have to be mapped to a policy. default policy can be provided and it will be used when performing an action with an unspecified policy.

    Returns void

Generated using TypeDoc