Interface LoginStorage<T>

A IndexedStorage where the defineType function takes an extra parameter to indicate if the type corresponds to a login method. This is useful for storages that want to add extra requirements based on the data being edited.

In practice, we use this because we want to require accounts to have at least 1 login method.

Type Parameters

Hierarchy

Implemented by

Properties

defineType: (<TType>(type, description, isLogin) => Promise<void>)

Type declaration

    • <TType>(type, description, isLogin): Promise<void>
    • Defines a type in the storage, just like in an IndexedStorage, but additionally it needs to be indicated if the type corresponds to a login method or not.

      Type Parameters

      • TType extends string

      Parameters

      • type: TType

        Type to define.

      • description: T[TType]

        Description of the type.

      • isLogin: boolean

        Whether this type corresponds to a login method or not.

      Returns Promise<void>

Methods

  • Creates an object of the given type. The storage will generate an identifier for the newly created object.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type to create.

    • value: CreateTypeObject<T[TType]>

      The value to set for the created object.

    Returns Promise<TypeObject<T[TType]>>

    A representation of the newly created object, including its new identifier.

  • Creates an index on a key of the given type, to allow for better queries involving those keys. Similar to IndexedStorage.defineType these calls need to happen first.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type to create an index on.

    • key: StringKey<T[TType]>

      The key of that type to create an index on.

    Returns Promise<void>

  • Deletes the given object. This will also delete all objects that reference that object if the corresponding key is not optional.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type of the object to delete.

    • id: string

      The identifier of the object.

    Returns Promise<void>

  • Returns an iterator over all objects of the given type.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type to iterate over.

    Returns AsyncIterableIterator<TypeObject<T[TType]>>

  • Finds all objects matching a specific IndexedQuery.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type of objects to find.

    • query: {
          [K in string | number | symbol]?: ValueType<T[TType][K]> | (T[TType][K] extends `id:${U}`
              ? ({ [K in "id" | keyof T[U]]?: ValueType<T[U][K]> | (T[U][K] extends `id:${infer U}` ? { [K in "id" | keyof T[U]]?: ValueType<T[U][K]> | (T[U][K] extends `id:${infer U}` ? { [K in "id" | keyof T[U]]?: ValueType<...> | ... 1 more ... | undefined; } : never) | undefined; } : never) | undefined; })
              : never)
      }

      The query to execute.

    Returns Promise<TypeObject<T[TType]>[]>

    A list of objects matching the query.

  • Similar to IndexedStorage.find, but only returns the identifiers of the found objects.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type of objects to find.

    • query: {
          [K in string | number | symbol]?: ValueType<T[TType][K]> | (T[TType][K] extends `id:${U}`
              ? ({ [K in "id" | keyof T[U]]?: ValueType<T[U][K]> | (T[U][K] extends `id:${infer U}` ? { [K in "id" | keyof T[U]]?: ValueType<T[U][K]> | (T[U][K] extends `id:${infer U}` ? { [K in "id" | keyof T[U]]?: ValueType<...> | ... 1 more ... | undefined; } : never) | undefined; } : never) | undefined; })
              : never)
      }

      The query to execute.

    Returns Promise<string[]>

    A list of identifiers of the matching objects.

  • Returns the object of the given type with the given identifier.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type of object to get.

    • id: string

      The identifier of that object.

    Returns Promise<undefined | TypeObject<T[TType]>>

    A representation of the object, or undefined if there is no object of that type with that identifier.

  • Returns true if the object of the given type with the given identifier exists.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type of object to get.

    • id: string

      The identifier of that object.

    Returns Promise<boolean>

    Whether this object exists.

  • Sets the value of a specific object. The identifier in the object is used to identify the object.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type of the object to set.

    • value: TypeObject<T[TType]>

      The new value for the object.

    Returns Promise<void>

  • Sets the value of one specific field in an object.

    Type Parameters

    • TType extends string

    • TKey extends string

    Parameters

    • type: TType

      The type of the object to update.

    • id: string

      The identifier of the object to update.

    • key: TKey

      The key to update.

    • value: ValueType<T[TType][TKey]>

      The new value for the given key.

    Returns Promise<void>