Skip to content

AIDC Toolkit / Utility / Transformer

Abstract Class: Transformer

Defined in: transformer.ts:23

Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range defined by a callback function. In other words, the domain determines valid input values and, without a callback, the range of valid output values.

The concept is similar to format-preserving encryption, where input values within a specified domain (e.g., payment card numbers ranging from 8-19 digits) are transformed into values in the same domain, typically for storage in a database where the data type and length are already fixed and exfiltration of the data can have significant repercussions.

Two subclasses are supported directly by this class: IdentityTransformer (which operates based on a domain only) and EncryptionTransformer (which operates based on a domain and a tweak). If an application is expected to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the transformer object, an in-memory cache is available via the get() method. Properties in IdentityTransformer and EncryptionTransformer are read-only once constructed, so there is no issue with their shared use.

Extended by

Constructors

Constructor

new Transformer(domain): Transformer

Defined in: transformer.ts:40

Constructor.

Parameters

domain

Domain.

number | bigint

Returns

Transformer

Accessors

domain

Get Signature

get domain(): bigint

Defined in: transformer.ts:90

Get the domain.

Returns

bigint

Methods

get()

static get(domain, tweak?): Transformer

Defined in: transformer.ts:65

Get a transformer, constructing it if necessary. The type returned is IdentityTransformer if tweak is undefined, EncryptionTransformer if tweak is defined. Note that although an EncryptionTransformer with a zero tweak operates as an IdentityTransformer, EncryptionTransformer is still the type returned if a zero tweak is explicitly specified.

Parameters

domain

Domain.

number | bigint

tweak?

Tweak.

number | bigint

Returns

Transformer

Transformer.


doForward()

abstract protected doForward(value): bigint

Defined in: transformer.ts:124

Do the work of transforming a value forward.

Parameters

value

bigint

Value.

Returns

bigint

Transformed value.


forward()

Call Signature

forward(value): bigint

Defined in: transformer.ts:171

Transform a value forward.

Parameters
value

Value.

number | bigint

Returns

bigint

Transformed value.

Call Signature

forward<TOutput>(value, transformerCallback): TOutput

Defined in: transformer.ts:188

Transform a value forward and apply another transformation.

Type Parameters
TOutput

TOutput

Transformer callback output type.

Parameters
value

Value.

number | bigint

transformerCallback

IndexedCallback<bigint, TOutput>

Called with interim transformed value to transform it to its final value.

Returns

TOutput

Transformed value.

Call Signature

forward(values): Iterable<bigint>

Defined in: transformer.ts:200

Transform values forward.

Parameters
values

Iterable<number | bigint>

Values. If this is an instance of Sequence, the minimum and maximum values are validated prior to transformation. Otherwise, the individual values are validated at the time of each transformation.

Returns

Iterable<bigint>

Transformed values.

Call Signature

forward<TOutput>(values, transformerCallback): Iterable<TOutput>

Defined in: transformer.ts:218

Transform values forward and apply another transformation to each.

Type Parameters
TOutput

TOutput

Transformer callback output type.

Parameters
values

Iterable<number | bigint>

Values. If this is an instance of Sequence, the minimum and maximum values are validated prior to transformation. Otherwise, the individual values are validated at the time of each transformation.

transformerCallback

IndexedCallback<bigint, TOutput>

Called with each interim transformed value to transform it to its final value.

Returns

Iterable<TOutput>

Transformed values.

Call Signature

forward<TInput>(valueOrValues): TInput extends Iterable<number | bigint, any, any> ? Iterable<bigint, any, any> : bigint

Defined in: transformer.ts:221

Transform a value forward.

Type Parameters
TInput

TInput extends number | bigint | Iterable<number | bigint, any, any>

Parameters
valueOrValues

TInput extends Iterable<number | bigint, any, any> ? TInput<TInput> : number | bigint

Returns

TInput extends Iterable<number | bigint, any, any> ? Iterable<bigint, any, any> : bigint

Transformed value.

Call Signature

forward<TInput, TOutput>(valueOrValues, transformerCallback): TInput extends Iterable<number | bigint, any, any> ? Iterable<TOutput, any, any> : TOutput

Defined in: transformer.ts:224

Transform a value forward.

Type Parameters
TInput

TInput extends number | bigint | Iterable<number | bigint, any, any>

TOutput

TOutput

Parameters
valueOrValues

TInput extends Iterable<number | bigint, any, any> ? TInput<TInput> : number | bigint

transformerCallback

IndexedCallback<bigint, TOutput>

Returns

TInput extends Iterable<number | bigint, any, any> ? Iterable<TOutput, any, any> : TOutput

Transformed value.


doReverse()

abstract protected doReverse(transformedValue): bigint

Defined in: transformer.ts:263

Do the work of transforming a value in reverse.

Parameters

transformedValue

bigint

Transformed value.

Returns

bigint

Value.


reverse()

reverse(transformedValue): bigint

Defined in: transformer.ts:274

Transform a value in reverse.

Parameters

transformedValue

Transformed value.

number | bigint

Returns

bigint

Value.