Create a new subscriber with the given encryption configuration.
Encrypt configured fields before a new entity is inserted.
Encrypt configured fields before an existing entity is updated.
Decrypt configured fields after an entity is loaded from the database.
Optionalevent: LoadEvent<Record<string, unknown>>
A TypeORM
EntitySubscriberthat hooks into the entity lifecycle to encrypt and decrypt fields automatically. The set of fields to process is defined viaEncryptionConfig.fields— aMapkeyed by entity constructor name.This approach is useful when you want to keep your entity classes free from transformer configuration and centralise encryption policy.
Example