AdonisJS API
    Preparing search index...

    A wrapper class that allows optional values to be passed to transformers without causing errors when the value is undefined.

    The Maybe wrapper is typically used with the whenLoaded method to handle relationships that may or may not be loaded.

    class UserTransformer extends BaseTransformer<User> {
    toObject() {
    return {
    id: this.resource.id,
    profile: this.whenLoaded(this.resource.profile) // Returns Maybe<Profile>
    }
    }
    }

    Type Parameters

    • T
    Index
    • Creates a new Maybe wrapper for a value

      Type Parameters

      • T

      Parameters

      • value: T

        The value to wrap, which may be undefined

        const maybeUser = new Maybe(userData)
        const maybeUndefined = new Maybe(undefined)

      Returns Maybe<T>

    value: T

    The wrapped value, which may be undefined