Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Transform<TStoredValue, TRuntimeValue>

A Transform can be passed in the definition of a schema field to create a mapping between what is stored in the database, and what is stored in the model. For example, you might store an array of strings in Cosmos DB, but represent it as a Set in the application. This could be handled like so:

schema.field('favoriteColors', asType<string[]>, {
  type: 'array',
  uniqueValues: true,
  transform: new Transform(
    storeValue => new Set(storeValue),
    appValue => Array.from(appValue),
  ),
});

This is pased in the ISchemaField.

Type parameters

  • TStoredValue

  • TRuntimeValue

Hierarchy

  • Transform

Index

Constructors

Properties

Constructors

constructor

  • new Transform<TStoredValue, TRuntimeValue>(deserialize: (storedValue: TStoredValue) => TRuntimeValue, serialize: (applicationValue: TRuntimeValue) => TStoredValue): Transform<TStoredValue, TRuntimeValue>
  • Type parameters

    • TStoredValue

    • TRuntimeValue

    Parameters

    • deserialize: (storedValue: TStoredValue) => TRuntimeValue

      Function to transform from the database value to the runtime value

        • (storedValue: TStoredValue): TRuntimeValue
        • Parameters

          • storedValue: TStoredValue

          Returns TRuntimeValue

    • serialize: (applicationValue: TRuntimeValue) => TStoredValue

      Function to transform from the runtime value back to the database value

        • (applicationValue: TRuntimeValue): TStoredValue
        • Parameters

          • applicationValue: TRuntimeValue

          Returns TStoredValue

    Returns Transform<TStoredValue, TRuntimeValue>

Properties

deserialize

deserialize: (storedValue: TStoredValue) => TRuntimeValue

Type declaration

    • (storedValue: TStoredValue): TRuntimeValue
    • Parameters

      • storedValue: TStoredValue

      Returns TRuntimeValue

serialize

serialize: (applicationValue: TRuntimeValue) => TStoredValue

Type declaration

    • (applicationValue: TRuntimeValue): TStoredValue
    • Parameters

      • applicationValue: TRuntimeValue

      Returns TStoredValue

Generated using TypeDoc