Type Parameters

Hierarchy

  • CollectionCustomizer

Constructors

Properties

addField: ((name: string, definition: ComputedDefinition<S, N>) => CollectionCustomizer<S, N>)

Type declaration

    • (name: string, definition: ComputedDefinition<S, N>): CollectionCustomizer<S, N>
    • Add a new field on the collection.

      See

      Documentation Link

      Example

      .addField('fullName', {
      columnType: 'String',
      dependencies: ['firstName', 'lastName'],
      getValues: (records) => records.map(record => `${record.lastName} ${record.firstName}`),
      });

      Parameters

      • name: string

        the name of the field

      • definition: ComputedDefinition<S, N>

        The definition of the field

      Returns CollectionCustomizer<S, N>

name: string

Accessors

Methods

  • Add a new action on the collection.

    See

    Documentation Link

    Example

    .addAction('is live', {
    scope: 'Single',
    execute: async (context, resultBuilder) => {
    return resultBuilder.success('Is live!');
    },
    })

    Parameters

    • name: string

      the name of the action

    • definition: ActionDefinition<S, N>

      the definition of the action

    Returns CollectionCustomizer<S, N>

  • Create a new API chart

    See

    Documentation Link

    Example

    .addChart('numCustomers', (context, resultBuilder) => {
    return resultBuilder.distribution({
    tomatoes: 10,
    potatoes: 20,
    carrots: 30,
    });
    })

    Parameters

    • name: string

      name of the chart

    • definition: CollectionChartDefinition<S, N>

      definition of the chart

    Returns CollectionCustomizer<S, N>

  • Add a virtual collection into the related data of a record.

    See

    Documentation Link

    Example

    .addExternalRelation('states', {
    schema: { code: 'Number', name: 'String' },
    listRecords: ({ id }) => {
    return record.id == 34 ?
    [{ code: 'AL', name: 'Alabama' }, { code: 'AK', name: 'Alaska' }] :
    [{ code: 'AZ', name: 'Arizona' }, { code: 'TX', name: 'Texas' }];
    }
    })

    Parameters

    Returns CollectionCustomizer<S, N>

  • Add a new validator to the edition form of a given field

    See

    Documentation Link

    Example

    .addFieldValidation('firstName', 'LongerThan', 2);
    

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      The name of the field

    • operator: "Equal" | "NotEqual" | "LessThan" | "GreaterThan" | "Match" | "NotContains" | "NotIContains" | "LongerThan" | "ShorterThan" | "IncludesAll" | "IncludesNone" | "Today" | "Yesterday" | "PreviousMonth" | "PreviousQuarter" | "PreviousWeek" | "PreviousYear" | "PreviousMonthToDate" | "PreviousQuarterToDate" | "PreviousWeekToDate" | "PreviousXDaysToDate" | "PreviousXDays" | "PreviousYearToDate" | "Present" | "Blank" | "Missing" | "In" | "NotIn" | "StartsWith" | "EndsWith" | "Contains" | "IStartsWith" | "IEndsWith" | "IContains" | "Like" | "ILike" | "Before" | "After" | "AfterXHoursAgo" | "BeforeXHoursAgo" | "Future" | "Past"

      The validator that you wish to add

    • Optional value: unknown

      A configuration value that the validator may need

    Returns CollectionCustomizer<S, N>

  • Add a new hook handler to an action

    See

    Documentation Link

    Example

    .addHook('Before', 'List', async (context) => {
    // Do something before the list action
    });

    Type Parameters

    • P extends HookPosition

    • T extends "List" | "Create" | "Update" | "Delete" | "Aggregate"

    Parameters

    • position: P

      Either if the hook is executed before or after the action

    • type: T

      Type of action which should be hooked

    • handler: HookHandler<HooksContext<S, N>[P][T], void, TSchema, string>

      Callback that should be executed when the hook is triggered

    Returns CollectionCustomizer<S, N>

  • Add a many to many relation to the collection

    See

    Documentation Link

    Example

    dvds.addManyToManyRelation('rentalsOfThisDvd', 'rentals', 'dvdRentals', {
    originKey: 'dvdId',
    foreignKey: 'rentalId'
    })

    Type Parameters

    • Foreign extends string

    • Through extends string

    Parameters

    • name: string

      name of the new relation

    • foreignCollection: Foreign

      name of the targeted collection

    • throughCollection: Through

      name of the intermediary collection

    • options: {
          foreignKey: Extract<keyof S[Through]["plain"], string>;
          foreignKeyTarget?: Extract<keyof S[Foreign]["plain"], string>;
          originKey: Extract<keyof S[Through]["plain"], string>;
          originKeyTarget?: Extract<keyof S[N]["plain"], string>;
      }

      extra information about the relation

      • foreignKey: Extract<keyof S[Through]["plain"], string>
      • Optional foreignKeyTarget?: Extract<keyof S[Foreign]["plain"], string>
      • originKey: Extract<keyof S[Through]["plain"], string>
      • Optional originKeyTarget?: Extract<keyof S[N]["plain"], string>

    Returns CollectionCustomizer<S, N>

  • Add a many to one relation to the collection

    See

    Documentation Link

    Example

    books.addManyToOneRelation('myAuthor', 'persons', { foreignKey: 'authorId' })
    

    Type Parameters

    • T extends string

    Parameters

    • name: string

      name of the new relation

    • foreignCollection: T

      name of the targeted collection

    • options: {
          foreignKey: Extract<keyof S[N]["plain"], string>;
          foreignKeyTarget?: Extract<keyof S[T]["plain"], string>;
      }

      extra information about the relation

      • foreignKey: Extract<keyof S[N]["plain"], string>
      • Optional foreignKeyTarget?: Extract<keyof S[T]["plain"], string>

    Returns CollectionCustomizer<S, N>

  • Add a one to many relation to the collection

    See

    Documentation Link

    Example

    persons.addOneToManyRelation('writtenBooks', 'books', { originKey: 'authorId' })
    

    Type Parameters

    • T extends string

    Parameters

    • name: string

      name of the new relation

    • foreignCollection: T

      name of the targeted collection

    • options: {
          originKey: Extract<keyof S[T]["plain"], string>;
          originKeyTarget?: Extract<keyof S[N]["plain"], string>;
      }

      extra information about the relation

      • originKey: Extract<keyof S[T]["plain"], string>
      • Optional originKeyTarget?: Extract<keyof S[N]["plain"], string>

    Returns CollectionCustomizer<S, N>

  • Add a one to one relation to the collection

    See

    Documentation Link

    Example

    persons.addOneToOneRelation('bestFriend', 'persons', { originKey: 'bestFriendId' })
    

    Type Parameters

    • T extends string

    Parameters

    • name: string

      name of the new relation

    • foreignCollection: T

      name of the targeted collection

    • options: {
          originKey: Extract<keyof S[T]["plain"], string>;
          originKeyTarget?: Extract<keyof S[N]["plain"], string>;
      }

      extra information about the relation

      • originKey: Extract<keyof S[T]["plain"], string>
      • Optional originKeyTarget?: Extract<keyof S[N]["plain"], string>

    Returns CollectionCustomizer<S, N>

  • Add a new segment on the collection.

    See

    Documentation Link

    Example

    .addSegment(
    'Wrote more than 2 books',
    { field: 'booksCount', operator: 'GreaterThan', value: 2 }
    );

    Parameters

    • name: string

      the name of the segment

    • definition: SegmentDefinition<S, N>

      a function used to generate a condition tree or a condition tree

    Returns CollectionCustomizer<S, N>

  • Disable count in list view pagination for improved performance.

    Example

    .disableCount()
    

    Returns CollectionCustomizer<S, N>

  • Disable sorting on a specific field.

    See

    Documentation Link

    Example

    .disableFieldSorting('fullName');
    

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      the name of the field with sorting to be disabled

    Returns CollectionCustomizer<S, N>

  • Enable filtering on a specific field using emulation. As for all the emulation method, the field filtering will be done in-memory.

    See

    Documentation Link

    Example

    .emulateFieldFiltering('aField');
    

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      the name of the field to enable emulation on

    Returns CollectionCustomizer<S, N>

  • Enable filtering on a specific field with a specific operator using emulation. As for all the emulation method, the field filtering will be done in-memory.

    See

    Documentation Link

    Example

    .emulateFieldOperator('aField', 'In');
    

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      the name of the field to enable emulation on

    • operator: "Equal" | "NotEqual" | "LessThan" | "GreaterThan" | "Match" | "NotContains" | "NotIContains" | "LongerThan" | "ShorterThan" | "IncludesAll" | "IncludesNone" | "Today" | "Yesterday" | "PreviousMonth" | "PreviousQuarter" | "PreviousWeek" | "PreviousYear" | "PreviousMonthToDate" | "PreviousQuarterToDate" | "PreviousWeekToDate" | "PreviousXDaysToDate" | "PreviousXDays" | "PreviousYearToDate" | "Present" | "Blank" | "Missing" | "In" | "NotIn" | "StartsWith" | "EndsWith" | "Contains" | "IStartsWith" | "IEndsWith" | "IContains" | "Like" | "ILike" | "Before" | "After" | "AfterXHoursAgo" | "BeforeXHoursAgo" | "Future" | "Past"

      the operator to emulate

    Returns CollectionCustomizer<S, N>

  • Enable sorting on a specific field using emulation. As for all the emulation method, the field sorting will be done in-memory.

    See

    Documentation Link

    Example

    .emulateFieldSorting('fullName');
    

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      the name of the field to enable emulation on

    Returns CollectionCustomizer<S, N>

  • Import a field from a many to one or one to one relation.

    See

    Documentation Link

    Example

    .importField('authorName', { path: 'author:fullName' })
    

    Parameters

    • name: string

      the name of the field that will be created on the collection

    • options: {
          path: TFieldName<S, N>;
          readonly?: boolean;
      }

      options to import the field

      • path: TFieldName<S, N>
      • Optional readonly?: boolean

    Returns CollectionCustomizer<S, N>

  • Choose how binary data should be transported to the GUI. By default, all fields are transported as 'datauri', with the exception of primary and foreign keys.

    Using 'datauri' allows to use the FilePicker widget, while 'hex' is more suitable for short binary data (for instance binary uuids).

    Example

    .replaceFieldBinaryMode('avatar', 'datauri');
    

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      the name of the field

    • binaryMode: BinaryMode

      either 'datauri' or 'hex'

    Returns CollectionCustomizer<S, N>

  • Replace an implementation for a specific operator on a specific field. The operator replacement will be done by the datasource.

    See

    Documentation Link

    Example

    .replaceFieldOperator('fullName', 'Contains', (value) => {
    return {
    aggregator: 'Or',
    conditions: [{
    field: 'firstName',
    operator: 'Contains',
    value
    }, {
    field: 'lastName',
    operator: 'Contains',
    value
    }]
    }
    });

    Type Parameters

    • C extends string

    Parameters

    • name: C

      the name of the field to filter on

    • operator: "Equal" | "NotEqual" | "LessThan" | "GreaterThan" | "Match" | "NotContains" | "NotIContains" | "LongerThan" | "ShorterThan" | "IncludesAll" | "IncludesNone" | "Today" | "Yesterday" | "PreviousMonth" | "PreviousQuarter" | "PreviousWeek" | "PreviousYear" | "PreviousMonthToDate" | "PreviousQuarterToDate" | "PreviousWeekToDate" | "PreviousXDaysToDate" | "PreviousXDays" | "PreviousYearToDate" | "Present" | "Blank" | "Missing" | "In" | "NotIn" | "StartsWith" | "EndsWith" | "Contains" | "IStartsWith" | "IEndsWith" | "IContains" | "Like" | "ILike" | "Before" | "After" | "AfterXHoursAgo" | "BeforeXHoursAgo" | "Future" | "Past"

      the operator to replace

    • replacer: OperatorDefinition<S, N, C>

      the proposed implementation

    Returns CollectionCustomizer<S, N>

  • Replace an implementation for the sorting. The field sorting will be done by the datasource.

    See

    @Documentation Link

    Example

    .replaceFieldSorting(
    'fullName',
    [
    { field: 'firstName', ascending: true },
    { field: 'lastName', ascending: true },
    ]
    )

    Parameters

    • name: Extract<keyof S[N]["plain"], string>

      the name of the field to enable sort

    • equivalentSort: TSortClause<S, N>[]

      the sort equivalent

    Returns CollectionCustomizer<S, N>

  • Replace the write behavior of a field.

    See

    Documentation Link

    Example

    .replaceFieldWriting('fullName', fullName => {
    const [firstName, lastName] = fullName.split(' ');
    return { firstName, lastName };
    });

    Type Parameters

    • C extends string

    Parameters

    Returns CollectionCustomizer<S, N>

  • Replace the behavior of the search bar

    See

    Documentation Link

    Example

    .replaceSearch(async (searchString) => {
    return { field: 'name', operator: 'Contains', value: searchString };
    });

    Parameters

    Returns CollectionCustomizer<S, N>

  • Load a plugin on the collection.

    See

    Documentation Link

    Example

    import { createFileField } from '@forestadmin/plugin-s3';

    collection.use(createFileField, { fieldname: 'avatar' }),

    Type Parameters

    • Options

    Parameters

    • plugin: Plugin<Options>

      reference to the plugin function

    • Optional options: Options

      options to pass to the plugin

    Returns CollectionCustomizer<S, N>