Repository for managing saved filter definitions.

FilterRepository provides methods to create, update, and delete Filter definitions. Filters are named, reusable query expressions that can be applied to limetypes to define subsets of objects (e.g., "My Active Deals", "High Priority Tickets").

Filters can be:

  • System-wide (available to all users)
  • User-specific (private to a single user when iduser is set)
  • Referenced in InFilterExpressions for advanced queries

The repository extends StateRepository, enabling:

  • Reactive subscriptions to filter changes
  • Automatic UI updates when filters are created or deleted
  • Integration with state decorators

Example

Basic usage

const repo = platform.get(PlatformServiceName.FilterRepository);

const filter: Filter = {
id: 'high_value_deals',
limetype: 'deal',
name: { 'en': 'High Value Deals' },
filter: {
op: Operator.AND,
exp: [
{ key: 'status', op: Operator.EQUALS, exp: 'active' },
{ key: 'value', op: Operator.GREATER_OR_EQUAL, exp: 100000 }
]
}
};

await repo.save(filter);

See

Hierarchy

Methods

  • Delete a filter from the database.

    Permanently removes the specified filter. This operation cannot be undone.

    Returns

    Promise that resolves when the filter is deleted

    Throws

    Error if deletion fails due to permissions or other issues

    Example

    const repo = platform.get(PlatformServiceName.FilterRepository);
    await repo.delete(filter);

    See

    • Filter for the filter structure
    • save to create or update a filter

    Parameters

    Returns Promise<void>

  • Save a filter definition to the database.

    Creates a new filter or updates an existing one. The filter will be stored persistently and become available for use in queries and filter expressions.

    If a filter with the same id already exists, it will be updated with the new values. Otherwise, a new filter is created.

    Returns

    Promise that resolves when the filter is saved

    Throws

    Error if save fails due to validation or permission issues

    Example

    const repo = platform.get(PlatformServiceName.FilterRepository);

    const filter: Filter = {
    id: 'my_deals',
    limetype: 'deal',
    name: { 'en': 'My Deals' },
    filter: { key: 'owner', op: Operator.EQUALS, exp: currentUserId }
    };

    await repo.save(filter);

    See

    Parameters

    Returns Promise<void>

  • Subscribe to state changes with optional transformation and filtering.

    The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.

    Returns

    Unsubscribe function - call this to stop receiving updates

    Remarks

    • Map functions are applied sequentially to transform the state
    • Filter functions must all return true for the callback to be invoked
    • Functions in map/filter arrays are bound to the component instance
    • Always store and call the unsubscribe function when component is destroyed

    Example

    // Basic subscription
    const unsubscribe = repository.subscribe((state) => {
    console.log('State updated:', state);
    });

    // With transformations
    const unsubscribe = repository.subscribe(
    (userName) => console.log('User:', userName),
    { map: [(state) => state.user?.name] }
    );

    Parameters

    • callback: ((...args: unknown[]) => void)

      Function called with state updates (after map/filter applied)

        • (...args: unknown[]): void
        • Parameters

          • Rest ...args: unknown[]

          Returns void

    • Optional options: StateOptions

      Optional transformations and filters for the subscription

    Returns (() => void)

      • (): void
      • Subscribe to state changes with optional transformation and filtering.

        The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.

        Returns

        Unsubscribe function - call this to stop receiving updates

        Remarks

        • Map functions are applied sequentially to transform the state
        • Filter functions must all return true for the callback to be invoked
        • Functions in map/filter arrays are bound to the component instance
        • Always store and call the unsubscribe function when component is destroyed

        Example

        // Basic subscription
        const unsubscribe = repository.subscribe((state) => {
        console.log('State updated:', state);
        });

        // With transformations
        const unsubscribe = repository.subscribe(
        (userName) => console.log('User:', userName),
        { map: [(state) => state.user?.name] }
        );

        Returns void