Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Text<InputType, OutputType, FormatParams>

A simple text field. Can support full text search and have a configurable min/max length.

All html-like chars are escaped, so none of them are interpreted as HTML.

Params:

  • full_text_search - Boolean - whether or not the DB should create a full text search for this field
  • min_length - Number - the text should have at least this many characters
  • max_length - Number - the text shuld have at most this many characters

Type parameters

  • InputType

  • OutputType

  • FormatParams

Hierarchy

Index

Constructors

constructor

  • new Text(app: App, collection: Collection, name: string, required: boolean, display_hints: any): Text
  • Creates a new instance of a field

    Parameters

    • app: App
    • collection: Collection
    • name: string
    • required: boolean
    • display_hints: any

    Returns Text

Properties

collection

collection: Collection

The collection this field is attached to

display_hints

display_hints: any

The display hints specified for this field

handles_large_data

handles_large_data: boolean = false

Whether or not the field handles large data

todo:

see if there's any viability in storing this

name

name: string

the name of the field

required

required: boolean

Whether or not this field should always have a value. Creating a resource with a value missing for a required field will throw an error

Methods

decode

encode

  • encode(_: any, input: string): Promise<{ original: string; safe: string }>
  • Parameters

    • _: any
    • input: string

    Returns Promise<{ original: string; safe: string }>

filterToQuery

  • filterToQuery(context: Context, filter: any): Promise<any>
  • Generates a mongo query based on the filter value

    Parameters

    Returns Promise<any>

fullTextSearchEnabled

  • fullTextSearchEnabled(): Promise<boolean>
  • Whether or not the db should create a fulltext index on this field

    Returns Promise<boolean>

getAggregationStages

  • getAggregationStages(_: any, query_params: { filter: {} }): Promise<{}[]>

getAttachmentLoader

  • getAttachmentLoader(context: Context, omit_it: Boolean, attachment_params: ConstructorParameters<typeof ReferenceToCollection>[2]): AttachmentLoader | null
  • If the field supports attachments, it should return a properly configured AttachmentLoader. Not necessary for most basic fields.

    Parameters

    • context: Context
    • omit_it: Boolean
    • attachment_params: ConstructorParameters<typeof ReferenceToCollection>[2]

    Returns AttachmentLoader | null

getDefaultValue

getSpecification

  • getSpecification(): { display_hints: any; name: string; type: string }
  • Return a summary of this field

    Returns { display_hints: any; name: string; type: string }

    • display_hints: any
    • name: string
    • type: string

getValuePath

  • getValuePath(): Promise<string>
  • Value path is where inside a single record should the DB look for the field's value when filtering resources. Some fields use complex objects for storage and overwrite this method, and thanks to that they don't have to reimplement Field.getAggregationStages

    Returns Promise<string>

hasDefaultValue

  • hasDefaultValue(): boolean
  • Whether or not a field has a default value - that is, a value given to the field if no value is provided

    Returns boolean

init

  • init(_: App): Promise<void>
  • Runs when the app is being started. Hooks can be set up within this function

    Parameters

    Returns Promise<void>

isOldValueSensitive

  • Whether or not any of the methods of the field depend on the previous value of the field

    Parameters

    Returns boolean

setParams

  • Sets the params @ignore

    Parameters

    Returns void

Static fromDefinition

  • fromDefinition<T>(app: App, collection: Collection, definition: { display_hints?: any; name: string; params?: Parameters<InstanceType<FieldClass>["setParams"]>[0]; required?: undefined | false | true; type: T }): Field<any, any, any>
  • Create a new instance of Field based on the definition. **It's recommended to use FieldDefinitionHelper instead

    Type parameters

    Parameters

    • app: App
    • collection: Collection
    • definition: { display_hints?: any; name: string; params?: Parameters<InstanceType<FieldClass>["setParams"]>[0]; required?: undefined | false | true; type: T }
      • Optional display_hints?: any
      • name: string
      • Optional params?: Parameters<InstanceType<FieldClass>["setParams"]>[0]
      • Optional required?: undefined | false | true
      • type: T

    Returns Field<any, any, any>

Static invalid

Static valid

Generated using TypeDoc