Class WrappedIndexedStorage<T>

An IndexedStorage that makes use of 2 KeyValueStorages to implement the interface. Due to being limited by key/value storages, there are some restrictions on the allowed type definitions:

  • There needs to be exactly 1 type with no references to other types.
  • All other types need to have exactly 1 reference to another type.
  • Types can't reference each other to create a cycle of references.

All of the above to create a tree-like structure of references. Such a tree is then stored in one of the storages. The other storage is used to store all indexes that are used to find the correct tree object when solving queries.

Type Parameters

Implements

Constructors

Properties

logger: Logger = ...

Accessors

  • get rootType(): string
  • The root type for this storage. Use this instead of rootTypeVar to prevent having to check for undefined. This value will always be defined if the type definitions have been validated.

    Returns string

Methods

  • Informs the storage of the definition of a specific type. A definition is a key/value object with the values being a valid ValueTypeDescription. Generally, this call needs to happen for every type of this storage, and before any calls are made to interact with the data.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType

      The type to define.

    • description: T[TType]

      A description of the values stored in objects of that type.

    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>

  • 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 string | number | symbol]?: (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 string | number | symbol]?: (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.

  • Finds the IDs of all root objects that contain objects of the given type matching the given query by making use of the indexes applicable to the keys in the query. This function only looks at the keys in the query with primitive values, object values in the query referencing parent objects are not considered. Similarly, only indexes are used, keys without index are also ignored.

    If an array of root IDs is provided as input, the result will be an intersection of this array and the found identifiers.

    If the result is an empty array, it means that there is no valid identifier matching the query, while an undefined result means there is no index matching any of the query keys, so a result can't be determined.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType
    • match: {
          [K in string | number | symbol]?: ValueType<T[TType][K]> | (T[TType][K] extends `id:${U}`
              ? {
                  [K in string | number | symbol]?: (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)
      }
    • OptionalrootIds: string[]

    Returns Promise<undefined | string[]>

  • Returns the sequence of virtual keys that need to be accessed to reach the given type, starting from the root.

    Parameters

    • type: string

    Returns `**${string}**`[]

  • 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.

  • Finds all objects of the given type matching the query. The rootIds array can be used to restrict the IDs of root objects to look at, which is relevant for the recursive calls the function does.

    Will throw an error if there is no index that can be used to solve the query.

    Type Parameters

    • TType extends string

    Parameters

    • type: TType
    • query: {
          [K in string | number | symbol]?: ValueType<T[TType][K]> | (T[TType][K] extends `id:${U}`
              ? {
                  [K in string | number | symbol]?: (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)
      }
    • OptionalrootIds: string[]

    Returns Promise<VirtualObject[]>

  • Updates the index for a specific key of an object of the given type.

    Parameters

    • type: string
    • key: string
    • value: string
    • rootId: string
    • add: boolean

    Returns Promise<void>

  • Makes sure the defined types fulfill all the requirements necessary for types on this storage. Will throw an error if this is not the case. This should be called before doing any data interactions. Stores success in a variable so future calls are instantaneous.

    Parameters

    • type: string

    Returns void