Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FileField

Takes a {@File} instance as input, stores it in the FS and then decodes to a URL.

Params:

  • get_default_file - ()=>Promise<File> - if no file is provided, then this file will be used in it's stead

Hierarchy

Index

Constructors

constructor

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

    Parameters

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

    Returns FileField

Properties

collection

collection: Collection

The collection this field is attached to

display_hints

display_hints: any

The display hints specified for this field

get_default_file

get_default_file: (context: Context) => Promise<File>

Type declaration

handles_large_data

handles_large_data: boolean = true

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(_: Context, file: File): Promise<{ filename: string; id: 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(context: Context, query_params: { filter?: undefined | {} }): Promise<QueryStage[]>
  • Creates parts of a Mongo Pipieline that will be used to filter the items when listing items of a collection

    Parameters

    • context: Context
    • query_params: { filter?: undefined | {} }
      • Optional filter?: undefined | {}

    Returns Promise<QueryStage[]>

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

getTypeName

  • getTypeName(): 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

hasIndex

  • hasIndex(): boolean | "text" | {}
  • Whether or not this field should have a dedicated index in the database

    Returns boolean | "text" | {}

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

isProperValue

  • isProperValue(_: Context, value: File): Promise<{ reason?: undefined | string; valid: boolean }>

setParams

  • setParams(params: { get_default_file: (context: Context) => Promise<File> }): 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