@karmaniverous/entity-manager
    Preparing search index...

    Class EntityManager<CC, CF>

    The EntityManager class applies a configuration-driven sharded data model & query strategy to NoSql data.

    While the query method is public, normally it should not be called directly. The query method is used by a platform-specific QueryBuilder.query method to provide a fluent query API.

    Type Parameters

    • CC extends BaseConfigMap

      ConfigMap that defines the configuration's EntityMap, key properties, and TranscodeRegistry. If omitted, defaults to BaseConfigMap.

    • CF = unknown

      Values-first config literal type captured at construction time (phantom generic; type-only). This is used by downstream adapters to infer index-token unions (ITS) and per-index page key shapes.

    Index
    logger: Pick<Console, "debug" | "error">

    Logger object (defaults to console, must support debug & error methods).

    • Update generated properties, hash key, and range key on an EntityItem object.

      Type Parameters

      • ET extends string | number | symbol

      Parameters

      • entityToken: ET

        Entity token (narrows types by token).

      • item: EntityItemPartial<CC, ET>

        Single item to update with generated keys/properties.

      • Optionaloverwrite: boolean

        Overwrite existing keys/properties (default false).

      Returns EntityRecord<CC, ET>

      EntityRecord object with updated properties.

      Error if entityToken is invalid.

    • Update generated properties, hash key, and range key on an array of EntityItem objects.

      Type Parameters

      • ET extends string | number | symbol

      Parameters

      • entityToken: ET

        Entity token (narrows types by token).

      • item: Partial<EntityItem<CC, ET>>[]

        Items to update with generated keys/properties.

      • Optionaloverwrite: boolean

        Overwrite existing keys/properties (default false).

      Returns EntityRecord<CC, ET>[]

      Array of EntityRecord objects with updated properties.

      Error if entityToken is invalid.

    • Encode a generated property value. Returns a string or undefined if atomicity requirement of sharded properties not met.

      Parameters

      Returns string | undefined

      Encoded generated property value.

      Error if property is not a Config generatedProperties key.

    • Find an index token based on the configured hash and range key tokens.

      Parameters

      • hashKeyToken: CC["HashKey"] | CC["ShardedKeys"]

        Index hash key token (global hashKey or a sharded generated key).

      • rangeKeyToken: CC["RangeKey"] | CC["UnshardedKeys"] | CC["TranscodedProperties"]

        Index range key token (global rangeKey, unsharded generated key, or a transcodable scalar).

      • OptionalsuppressError: false

        When false (default), throws if no match; when true, returns undefined instead.

      Returns IndexTokensOf<CF>

      A configured index token (narrowed to the CF.indexes key union) or undefined when allowed.

      Error if no match is found and suppressError is not true.

    • Find an index token based on the configured hash and range key tokens.

      Parameters

      • hashKeyToken: CC["HashKey"] | CC["ShardedKeys"]

        Index hash key token (global hashKey or a sharded generated key).

      • rangeKeyToken: CC["RangeKey"] | CC["UnshardedKeys"] | CC["TranscodedProperties"]

        Index range key token (global rangeKey, unsharded generated key, or a transcodable scalar).

      • suppressError: true

        When false (default), throws if no match; when true, returns undefined instead.

      Returns IndexTokensOf<CF> | undefined

      A configured index token (narrowed to the CF.indexes key union) or undefined when allowed.

      Error if no match is found and suppressError is not true.

    • Convert one or more EntityItem objects into an array of EntityKey values.

      Type Parameters

      • ET extends string | number | symbol

      Parameters

      • entityToken: ET

        Entity token (narrows types by token).

      • item: EntityItemPartial<CC, ET>

        Single item to derive primary keys for.

      • Optionaloverwrite: boolean

        Overwrite existing keys on the item before deriving (default false).

      Returns EntityKey<CC>[]

      Array of EntityKey values derived from item.

      Error if entityToken is invalid.

    • Convert an array of EntityItem objects into EntityKey values.

      Type Parameters

      • ET extends string | number | symbol

      Parameters

      • entityToken: ET

        Entity token (narrows types by token).

      • items: Partial<EntityItem<CC, ET>>[]

        Array of items to derive primary keys for.

      • Optionaloverwrite: boolean

        Overwrite existing keys on each item before deriving (default false).

      Returns EntityKey<CC>[]

      Array of EntityKey values derived from all items.

      Error if entityToken is invalid.

    • Protected

      Query a database entity across shards in a provider-generic fashion.

      Type Parameters

      • ET extends string | number | symbol
      • ITS extends string
      • CF = unknown
      • K = unknown

      Parameters

      Returns Promise<QueryResult<CC, ET, ITS, K>>

      QueryResult object.

      The provided shardQueryMap performs the actual query of individual data pages on individual index/shard combinations.

      Individual shard query results will be combined, deduped by Config uniqueProperty value, and sorted by sortOrder.

      In queries on sharded data, expect the leading and trailing edges of returned data pages to interleave somewhat with preceding & following pages.

      Unsharded query results should sort & page as expected.

      Normally this method should not be called directly! It is used by a platform-specific QueryBuilder.query method to provide a fluent query API.

      Error if options pageKeyMap pageKeyMap keys do not match shardQueryMap keys.