@adobe/data - v0.10.30
    Preparing search index...

    Interface Store<C, R, A, IX, PK, DFK>

    Store is the main interface for storing components, entities and resources.

    interface Store<
        C extends Components = {},
        R extends ResourceComponents = {},
        A extends ArchetypeComponents<StringKeyof<C>> = {},
        IX extends IndexDeclarations<C> = {},
        PK extends string = never,
        DFK extends string = never,
    > {
        archetypes: {
            -readonly [K in string]: ArchetypeOrRouter<
                HasPartitionKey<A[K][number], PK>,
                { [Col in string]: (C & OptionalComponents)[Col] },
                Archetype<
                    { [Col in string]: (C & OptionalComponents)[Col] },
                    Extract<A[K][number], DFK>,
                >,
                Extract<A[K][number], DFK>,
            >
        };
        compact: () => void;
        componentSchemas: { readonly [K in string]: Schema.Schema };
        delete: (entity: number) => undefined | number;
        indexes: { readonly [K in string | number | symbol]: Handle<C, IX[K]> };
        locate: (entity: number) => null | { archetype: Archetype; row: number };
        resources: { -readonly [K in string]: R[K] };
        undoable?: Undoable;
        update: (
            entity: number,
            values: EntityUpdateValues<C>,
        ) => undefined | number;
        userId?: string | number;
        count<Include extends string>(
            include: ReadonlySet<string> | readonly Include[],
            options?: EntitySelectOptions<
                C & OptionalComponents,
                Pick<C & RequiredComponents & OptionalComponents, Include>,
            >,
        ): number;
        ensureArchetype<const CC extends string>(
            components: readonly CC[] | ReadonlySet<CC>,
        ): HasPartitionKey<CC, PK> extends true
            ? Router<
                { [K in string]: (C & OptionalComponents)[K] },
                Extract<CC, DFK>,
            >
            : Archetype<
                { [K in string]: (C & OptionalComponents)[K] },
                Extract<CC, DFK>,
            >;
        ensureArchetype<const CC extends string>(
            components: readonly CC[] | ReadonlySet<CC>,
            partitionValues: { readonly [K in string]: (C & OptionalComponents)[K] },
        ): Archetype<
            { [K in string]: (C & OptionalComponents)[K] },
            Extract<CC, DFK>,
        >;
        extend<S extends Store.Schema<any, any, any, {}>>(
            schema: S,
        ): S extends Store.Schema<XC, XR, XA, XIX>
            ? Store<
                C & FromSchemas<XC>,
                R & FromSchemas<XR>,
                A & XA,
                IX & XIX,
                PK | PartitionKeysOf<XC>,
                DFK | DefaultFactoryKeys<XC>,
            >
            : never;
        fromData(data: unknown, scope?: PersistenceScope): void;
        get<K extends string>(entity: number, component: K): undefined | C[K];
        pruneToSchema(keep: ReadonlySet<string>): void;
        queryArchetypes<Include extends string>(
            include: ReadonlySet<string> | readonly Include[],
            options?: ArchetypeQueryOptions<C, PK>,
        ): readonly Archetype<
            Pick<C & OptionalComponents, Include>,
            Extract<Include, DFK>,
        >[];
        read<T>(
            entity: number,
            archetype: ReadonlyArchetype<T> | Archetype<T, never>,
        ): null | Readonly<T>;
        read<const K extends string | number | symbol>(
            entity: number,
            components: readonly K[],
        ): null | Readonly<Pick<EntityReadValues<C>, K>>;
        read(entity: number): null | EntityReadValues<C>;
        reconstructNonPersistentColumns(): void;
        reset(): void;
        select<Include extends string>(
            include: ReadonlySet<string> | readonly Include[],
            options?: EntitySelectOptions<
                C & OptionalComponents,
                Pick<C & RequiredComponents & OptionalComponents, Include>,
            >,
        ): readonly number[];
        toData(options?: ToDataOptions): unknown;
    }

    Type Parameters

    Hierarchy

    Index

    Properties

    archetypes: {
        -readonly [K in string]: ArchetypeOrRouter<
            HasPartitionKey<A[K][number], PK>,
            { [Col in string]: (C & OptionalComponents)[Col] },
            Archetype<
                { [Col in string]: (C & OptionalComponents)[Col] },
                Extract<A[K][number], DFK>,
            >,
            Extract<A[K][number], DFK>,
        >
    }
    compact: () => void
    componentSchemas: { readonly [K in string]: Schema.Schema }
    delete: (entity: number) => undefined | number

    Deletes the entity. Returns the entity that was swap-moved into the vacated row (a relocation side effect), or undefined when the deleted row was the last row. The return is optional info — callers that don't track relocations may ignore it.

    indexes: { readonly [K in string | number | symbol]: Handle<C, IX[K]> }

    Index handles keyed by user-chosen name. Returned handles are the same references at the Store layer and the Database layer; mutations to the store keep them in sync as a side effect of every insert/update/delete.

    locate: (entity: number) => null | { archetype: Archetype; row: number }
    resources: { -readonly [K in string]: R[K] }
    undoable?: Undoable

    This is used when a store is used to represent a transaction. For most stores, this is ignored if it is set.

    update: (entity: number, values: EntityUpdateValues<C>) => undefined | number

    Updates the entity. When the update migrates the entity to another archetype, its old archetype swap-moves a neighbor into the vacated row; that neighbor is returned (or undefined for an in-place update with no migration). The migrated entity's own relocation is observable via locate. The return is optional info — callers may ignore it.

    userId?: string | number

    The user on whose behalf the current transaction is running, set by the dispatcher for the duration of a transaction body and undefined otherwise. A store is the context a transaction operates on; there is no separate transaction-context type.

    Methods

    • Type Parameters

      Parameters

      • schema: S

      Returns S extends Store.Schema<XC, XR, XA, XIX>
          ? Store<
              C & FromSchemas<XC>,
              R & FromSchemas<XR>,
              A & XA,
              IX & XIX,
              PK | PartitionKeysOf<XC>,
              DFK | DefaultFactoryKeys<XC>,
          >
          : never

    • Restore from a snapshot. With no scope, performs a whole-database load (restores both persistent quadrants and resets the non-persistent ones). With a scope, restores only the in-scope persistent quadrant(s) and leaves every other quadrant untouched (see PersistenceScope).

      Parameters

      Returns void

    • Type Parameters

      • K extends string

      Parameters

      • entity: number
      • component: K

      Returns undefined | C[K]

    • Conform the store's DATA to a target schema: keep is the set of component + resource names to retain (the ECS built-ins are always kept). Every other component is stripped from every entity — an entity keeping at least one component migrates to its reduced archetype; an all-foreign entity (including a foreign resource singleton) is removed. Prunes data only: the emptied foreign archetypes and their unused schemas are shed on the next fromData, not by an in-place structural rebuild. Prefer Database.pruneToPluginSchema to derive keep from a plugin.

      Parameters

      • keep: ReadonlySet<string>

      Returns void

    • Read exactly the components of archetype. A membership GATE: returns null unless the entity is a superset of archetype. The result is narrowed to the archetype's own row — reading a component outside archetype off the result is a compile error (use a wider archetype, the component-list overload, or read(entity)).

      Type Parameters

      • T

      Parameters

      Returns null | Readonly<T>

    • Read a chosen subset of an entity's components.

      A pure PROJECTION, not a membership gate: returns null only when the entity does not exist. A requested component the entity does not have comes back absent — the field stays optional in the result, exactly as from the full read(entity).

      Prefer this over read(entity) when only a few fields are needed: it names the exact components touched, so db.derive can scope its recompute to just those fields instead of the whole entity. id is not a readable component (you already hold it); the element type is inferred as a literal union.

      Type Parameters

      • const K extends string | number | symbol

      Parameters

      • entity: number
      • components: readonly K[]

      Returns null | Readonly<Pick<EntityReadValues<C>, K>>

    • Parameters

      • entity: number

      Returns null | EntityReadValues<C>

    • Reconcile nonPersistent-schema columns after an external restore (e.g. a persistence layer that rebuilt the store from disk column-by-column): reset defaulted ones to their schema default and strip no-default ones (the entity migrates out of the component). Idempotent. fromData already applies this to its own loads; this is for callers that restore columns another way.

      Returns void

    • Wipe all entities and reset resources to plugin defaults. O(num_archetypes + num_resources).

      Returns void

    • Serialize the store to a plain snapshot. When copy is true the snapshot is detached from the live store (column/entity buffers are copied) so it remains valid after subsequent mutations; otherwise it references live buffers and is only valid until the next mutation. See Database.toData() for the bug this copy flag addresses for transient-bearing strategies.

      options.scope selects which persistent quadrants to emit; omit for all.

      Parameters

      Returns unknown