Options
All
  • Public
  • Public/Protected
  • All
Menu

A set of sub-conditions to operate against a model, optionally scoped to a specific field, combined with the given operator (one of and, or, or not).

member

groupId Used to distinguish between GroupCondition instances for debugging and troublehsooting.

member

model A metadata object that tells GroupCondition what to query and how.

member

field The field on the model that the sub-conditions apply to.

member

operator How to group child conditions together.

member

operands The child conditions.

Hierarchy

  • GroupCondition

Index

Constructors

constructor

Properties

field

field: string | undefined

If populated, this group specifices a condition on a relationship.

If field does not point to a related model, that's an error. It could indicate that the GroupCondition was instantiated with bad data, or that the model metadata is incorrect.

groupId

groupId: string = getGroupId()

isOptimized

isOptimized: boolean

Whether this GroupCondition is the result of an optimize call.

This is used to guard against infinitely fetch -> optimize -> fetch recursion.

model

model: ModelMeta<any>

The ModelMeta of the model to query and/or filter against. Expected to contain:

{
    builder: ModelConstructor,
    schema: SchemaModel,
    pkField: string[]
}

operands

operands: UntypedCondition[]

operator

operator: GroupOperator

relationshipType

relationshipType: string | undefined

If a field is given, whether the relationship is a HAS_ONE, 'HAS_MANY, orBELONGS_TO`.

TODO: Remove this and replace with derivation using ModelRelationship.from(this.model, this.field).relationship;

Methods

copy

fetch

  • fetch(storage: StorageAdapter, breadcrumb?: string[], negate?: boolean): Promise<Record<string, any>[]>
  • Fetches matching records from a given storage adapter using legacy predicates (for now).

    Parameters

    • storage: StorageAdapter

      The storage adapter this predicate will query against.

    • Default value breadcrumb: string[] = []

      For debugging/troubleshooting. A list of the groupId's this GroupdCondition.fetch is nested within.

    • Default value negate: boolean = false

      Whether to match on the NOT of this.

    Returns Promise<Record<string, any>[]>

    An Promise of any[] from storage matching the child conditions.

matches

  • matches(item: Record<string, any>, ignoreFieldName?: boolean): Promise<boolean>
  • Determines whether a single item matches the conditions of this. When checking the target item's properties, each property will be await'd to ensure lazy-loading is respected where applicable.

    Parameters

    • item: Record<string, any>

      The item to match against.

    • Default value ignoreFieldName: boolean = false

      Tells match() that the field name has already been dereferenced. (Used for iterating over children on HAS_MANY checks.)

    Returns Promise<boolean>

    A boolean (promise): true if matched, false otherwise.

optimized

  • Returns a version of the predicate tree with unnecessary logical groups condensed and merged together. This is intended to create a dense tree with leaf nodes (FieldCondition's) aggregated under as few group conditions as possible for the most efficient fetching possible -- it allows fetch().

    E.g. a grouping like this:

    and:
        and:
            id:
                eq: "abc"
        and:
            name:
                eq: "xyz"

    Will become this:

    and:
        id:
            eq: "abc"
        name:
            eq: "xyz"

    This allows fetch() to pass both the id and name conditions to the adapter together, which can then decide what index to use based on both fields together.

    Parameters

    • Default value preserveNode: boolean = true

      Whether to preserve the current node and to explicitly not eliminate it during optimization. Used internally to preserve the root node and children of not groups. not groups will always have a single child, so there's nothing to optimize below a not (for now), and it makes the query logic simpler later.

    Returns UntypedCondition

toAST

  • toAST(): object

toJSON

  • toJSON(): this & object

toStoragePredicate

  • toStoragePredicate<T>(): StoragePredicate<T>

withFieldConditionsOnly

  • Creates a new GroupCondition that contains only the local field conditions, omitting related model conditions. That resulting GroupCondition can be used to produce predicates that are compatible with the storage adapters and Cloud storage.

    Parameters

    • negate: boolean

      Whether the condition tree should be negated according to De Morgan's law.

    Returns GroupCondition