Interface IndexedStorage<T>

A storage solution that allows for more complex queries than a key/value storage and allows setting indexes on specific keys.

interface IndexedStorage<T> {
    create: (<TType>(type: TType, value: CreateTypeObject<T[TType]>) => Promise<TypeObject<T[TType]>>);
    createIndex: (<TType>(type: TType, key: StringKey<T[TType]>) => Promise<void>);
    defineType: (<TType>(type: TType, description: T[TType]) => Promise<void>);
    delete: (<TType>(type: TType, id: string) => Promise<void>);
    entries: (<TType>(type: TType) => AsyncIterableIterator<TypeObject<T[TType]>>);
    find: (<TType>(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)
    }) => Promise<TypeObject<T[TType]>[]>);
    findIds: (<TType>(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)
    }) => Promise<string[]>);
    get: (<TType>(type: TType, id: string) => Promise<undefined | TypeObject<T[TType]>>);
    has: (<TType>(type: TType, id: string) => Promise<boolean>);
    set: (<TType>(type: TType, value: TypeObject<T[TType]>) => Promise<void>);
    setField: (<TType, TKey>(type: TType, id: string, key: TKey, value: ValueType<T[TType][TKey]>) => Promise<void>);
}

Type Parameters

Implemented by

Properties

create: (<TType>(type: TType, value: CreateTypeObject<T[TType]>) => Promise<TypeObject<T[TType]>>)

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

Type declaration

createIndex: (<TType>(type: TType, key: StringKey<T[TType]>) => Promise<void>)

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 declaration

    • <TType>(type, key): Promise<void>
    • 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>

defineType: (<TType>(type: TType, description: T[TType]) => Promise<void>)

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 declaration

    • <TType>(type, description): Promise<void>
    • 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>

delete: (<TType>(type: TType, id: string) => Promise<void>)

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

Type declaration

    • <TType>(type, id): Promise<void>
    • 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>

entries: (<TType>(type: TType) => AsyncIterableIterator<TypeObject<T[TType]>>)

Returns an iterator over all objects of the given type.

Type declaration

find: (<TType>(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)
}) => Promise<TypeObject<T[TType]>[]>)

Finds all objects matching a specific IndexedQuery.

Type declaration

    • <TType>(type, query): Promise<TypeObject<T[TType]>[]>
    • 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.

findIds: (<TType>(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)
}) => Promise<string[]>)

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

Type declaration

    • <TType>(type, query): Promise<string[]>
    • 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.

get: (<TType>(type: TType, id: string) => Promise<undefined | TypeObject<T[TType]>>)

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

Type declaration

    • <TType>(type, id): Promise<undefined | TypeObject<T[TType]>>
    • 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.

has: (<TType>(type: TType, id: string) => Promise<boolean>)

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

Type declaration

    • <TType>(type, id): Promise<boolean>
    • 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.

set: (<TType>(type: TType, value: TypeObject<T[TType]>) => Promise<void>)

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

Type declaration

    • <TType>(type, value): Promise<void>
    • Type Parameters

      • TType extends string

      Parameters

      Returns Promise<void>

setField: (<TType, TKey>(type: TType, id: string, key: TKey, value: ValueType<T[TType][TKey]>) => Promise<void>)

Sets the value of one specific field in an object.

Type declaration

    • <TType, TKey>(type, id, key, value): Promise<void>
    • 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>