Type Alias ConfigEntity<EntityToken, M, HashKey, RangeKey, T>Protected

ConfigEntity<EntityToken, M, HashKey, RangeKey, T>: {
    defaultLimit?: number;
    defaultPageSize?: number;
    elementTranscodes?: ([TranscodableProperties<M[EntityToken], T>] extends [never]
        ? never
        : {
            [P in TranscodableProperties<M[EntityToken], T>]?: PropertiesOfType<T, M[EntityToken][P]>
        }) | ([TranscodableProperties<M[EntityToken], T>] extends [never]
        ? Record<string, never>
        : never);
    indexes?: Record<string, (
        | TranscodableProperties<M[EntityToken], T>
        | PropertiesOfType<M[EntityToken], never>
        | HashKey
        | RangeKey)[]>;
    shardBumps?: ShardBump[];
    timestampProperty: PropertiesOfType<M[EntityToken], number>;
    uniqueProperty: PropertiesOfType<M[EntityToken], number | string>;
} & ([PropertiesOfType<M[EntityToken], never>] extends [never]
    ? {
        generated?: ConfigEntityGenerated<EntityToken, M, T>;
    }
    : {
        generated: ConfigEntityGenerated<EntityToken, M, T>;
    })

Returns a Config entity type.

Type Parameters

  • EntityToken extends keyof Exactify<M>

    The Entity token.

  • M extends EntityMap

    The EntityMap.

  • HashKey extends string

    The property used across the configuration to store an Entity's sharded hash key. Should be configured as the table hash key. Must not conflict with any Entity property.

  • RangeKey extends string

    The property used across the configuration to store an Entity's range key. Should be configured as the table range key. Must not conflict with any Entity property.

  • T extends TranscodeMap

    The TranscodeMap identifying transcodable property types. Only Entity properties of these types can be components of an index or a generated property.

Type declaration

  • OptionaldefaultLimit?: number

    The default maximum number of records to return from a query.

    10

    Can be overridden at QueryOptions.limit.

    In cross-shard queries, the actual number of records returned is heavily influenced by query pageSize and the number of shards queried. Actual results may significantly exceed this limit.

  • OptionaldefaultPageSize?: number

    The default maximum number of records to return per data page on an individual shard query.

    10

    Shard queries will be repeated internally until either the shard is exhausted or the number of records returned exceeds the query limit.

    Can be overridden at QueryOptions.pageSize.

  • OptionalelementTranscodes?: ([TranscodableProperties<M[EntityToken], T>] extends [never]
        ? never
        : {
            [P in TranscodableProperties<M[EntityToken], T>]?: PropertiesOfType<T, M[EntityToken][P]>
        }) | ([TranscodableProperties<M[EntityToken], T>] extends [never]
        ? Record<string, never>
        : never)

    This object assigns transcodes to Entity generated property & ungenerated index elements.

    These transcodes are used to encode and decode generated property values & pageKeys.

    The keys of this object must be transcodable properties of the Entity.

    The values of this object must be one of the keys of the Config T type parameter (the config's TranscodeMap).

    The types of the related Entity and TranscodeMap properties should match.

    If any entity generated property element or ungenerated index element is not included here, the Config object will fail to parse.

    // Default transcodable types.
    interface DefaultTranscodeMap extends TranscodeMap {
    string: string;
    number: number;
    boolean: boolean;
    bigint: bigint;
    }

    interface MyEntityMap extends EntityMap {
    user: {
    created: number;
    data?: Json; // Not a Stringifiable type
    userId: string;
    };
    }

    // T type param defaults to DefaultTranscodeMap.
    const config: Config<MyEntityMap> = {
    entities: {
    user: {
    ...,
    types: { // All Stringafiable properties required!
    created: 'number',
    userId: 'string',
    // 'data' not allowed: not a Stringifiable type
    }
    }
    },
    ...
    };
  • Optionalindexes?: Record<string, (
        | TranscodableProperties<M[EntityToken], T>
        | PropertiesOfType<M[EntityToken], never>
        | HashKey
        | RangeKey)[]>

    Indexes defined for the Entity. Should reflect the underlying database table indexes.

    Each key is the name of an index, and each value is a non-empty array of Entity property names that define the index.

    Related property types must be align with the Config T type parameter. Note tha all generated property types are transcodable by definition.

  • OptionalshardBumps?: ShardBump[]

    An array of ShardBump objects representing the Entity's sharding strategy.

    If omitted, or if configured without a zero-timestamp ShardBump, this array will be initialized with the following ShardBump as its first member:

    { timestamp: 0, charBits: 0, chars: 1 }
    

    Members must be unique by timestamp.

    chars must increase monotonically with timestamp

    Array will be sorted in ascending order by timestamp on initialization.

    Future ShardBumps can be changed as required, but past ShardBumps should not be modified or data integrity will be compromised!

  • timestampProperty: PropertiesOfType<M[EntityToken], number>

    Identifies the Entity property used as the timestamp for shard key calculations.

    This property must be of type number. Its value should not change over the life of the record. A created timestamp is ideal.

    Once in production, this configuration property should not be changed or data integrity will be compromised!

  • uniqueProperty: PropertiesOfType<M[EntityToken], number | string>

    Identifies the Entity used as the basis for both shard key calculations and the table's range key.

    This property must be of type string or number. Its value should be a unique record identifier and should not change over the life of the record.

    Once in production, this configuration property should not be changed or data integrity will be compromised!

generated is optional if E has no properties of type never.