@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

    Constructors

    Properties

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

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

    Accessors

    • get config(): {
          entities: Record<
              string,
              {
                  defaultLimit: number;
                  defaultPageSize: number;
                  shardBumps: { charBits: number; chars: number; timestamp: number }[];
                  timestampProperty: string;
                  uniqueProperty: string;
              },
          >;
          generatedKeyDelimiter: string;
          generatedProperties: {
              sharded: Record<string, string[]>;
              unsharded: Record<string, string[]>;
          };
          generatedValueDelimiter: string;
          hashKey: string;
          indexes: Record<
              string,
              { hashKey: string; projections?: string[]; rangeKey: string },
          >;
          propertyTranscodes: Record<string, string>;
          rangeKey: string;
          shardKeyDelimiter: string;
          throttle: number;
          transcodes: Record<string, { decode: unknown; encode: unknown }>;
      }

      Get the current EntityManager Config object.

      Returns {
          entities: Record<
              string,
              {
                  defaultLimit: number;
                  defaultPageSize: number;
                  shardBumps: { charBits: number; chars: number; timestamp: number }[];
                  timestampProperty: string;
                  uniqueProperty: string;
              },
          >;
          generatedKeyDelimiter: string;
          generatedProperties: {
              sharded: Record<string, string[]>;
              unsharded: Record<string, string[]>;
          };
          generatedValueDelimiter: string;
          hashKey: string;
          indexes: Record<
              string,
              { hashKey: string; projections?: string[]; rangeKey: string },
          >;
          propertyTranscodes: Record<string, string>;
          rangeKey: string;
          shardKeyDelimiter: string;
          throttle: number;
          transcodes: Record<string, { decode: unknown; encode: unknown }>;
      }

      Current Config object.

    • set config(
          value: {
              entities: Record<
                  string,
                  {
                      defaultLimit: number;
                      defaultPageSize: number;
                      shardBumps: { charBits: number; chars: number; timestamp: number }[];
                      timestampProperty: string;
                      uniqueProperty: string;
                  },
              >;
              generatedKeyDelimiter: string;
              generatedProperties: {
                  sharded: Record<string, string[]>;
                  unsharded: Record<string, string[]>;
              };
              generatedValueDelimiter: string;
              hashKey: string;
              indexes: Record<
                  string,
                  { hashKey: string; projections?: string[]; rangeKey: string },
              >;
              propertyTranscodes: Record<string, string>;
              rangeKey: string;
              shardKeyDelimiter: string;
              throttle: number;
              transcodes: Record<string, { decode: unknown; encode: unknown }>;
          },
      ): void

      Set the current EntityManager Config object.

      Parameters

      • value: {
            entities: Record<
                string,
                {
                    defaultLimit: number;
                    defaultPageSize: number;
                    shardBumps: { charBits: number; chars: number; timestamp: number }[];
                    timestampProperty: string;
                    uniqueProperty: string;
                },
            >;
            generatedKeyDelimiter: string;
            generatedProperties: {
                sharded: Record<string, string[]>;
                unsharded: Record<string, string[]>;
            };
            generatedValueDelimiter: string;
            hashKey: string;
            indexes: Record<
                string,
                { hashKey: string; projections?: string[]; rangeKey: string },
            >;
            propertyTranscodes: Record<string, string>;
            rangeKey: string;
            shardKeyDelimiter: string;
            throttle: number;
            transcodes: Record<string, { decode: unknown; encode: unknown }>;
        }

        Config object.

      Returns void

    Methods

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

    • Protected

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

      Type Parameters

      • ET extends string
      • 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.