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

Constructors

Properties

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

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, ...string[]]>;
            unsharded: Record<string, [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: ((...args: [string, ...unknown[]]) => any);
            encode: ((...args: [any, ...unknown[]]) => string);
        }>;
    }
  • 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, ...string[]]>;
            unsharded: Record<string, [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: ((...args: [string, ...unknown[]]) => any);
            encode: ((...args: [any, ...unknown[]]) => string);
        }>;
    }

    Current Config object.

    • 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, ...string[]]>;
          unsharded: Record<string, [string, ...string[]]>;
      }
      • sharded: Record<string, [string, ...string[]]>
      • unsharded: Record<string, [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: ((...args: [string, ...unknown[]]) => any);
          encode: ((...args: [any, ...unknown[]]) => string);
      }>
  • set config(value): 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, ...string[]]>;
              unsharded: Record<string, [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: ((...args: [string, ...unknown[]]) => any);
              encode: ((...args: [any, ...unknown[]]) => string);
          }>;
      }

      Config object.

      • 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, ...string[]]>;
            unsharded: Record<string, [string, ...string[]]>;
        }
        • sharded: Record<string, [string, ...string[]]>
        • unsharded: Record<string, [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: ((...args: [string, ...unknown[]]) => any);
            encode: ((...args: [any, ...unknown[]]) => string);
        }>

    Returns void

Methods

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

    Type Parameters

    Parameters

    Returns undefined | string

    Encoded generated property value.

    Error if property is not a Config generatedProperties key.

  • Find an index token in a Config object based on the index hashKey and rangeKey.

    Parameters

    • hashKeyToken: string

      Index hash key.

    • rangeKeyToken: string

      Index range key.

    • OptionalsuppressError: boolean

      Suppress error if no match found.

    Returns undefined | string

    Index token if found.

    Error if no match found and suppressError is not true.

  • Protected

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

    Parameters

    Returns Promise<QueryResult<C>>

    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.