AIDC Toolkit / Utility / Transformer
Abstract Class: Transformer ​
Defined in: transformer.ts:53
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:70
Constructor.
Parameters ​
domain ​
Domain.
number | bigint
Returns ​
Transformer
Accessors ​
domain ​
Get Signature ​
get domain():
bigint
Defined in: transformer.ts:120
Get the domain.
Returns ​
bigint
Methods ​
get() ​
staticget(domain,tweak?):Transformer
Defined in: transformer.ts:95
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
IdentityTransformer if tweak is undefined, EncryptionTransformer if tweak is defined.
doForward() ​
abstractprotecteddoForward(value):bigint
Defined in: transformer.ts:154
Do the work of transforming a value forward.
Parameters ​
value ​
bigint
Value.
Returns ​
bigint
Transformed value.
forward() ​
Call Signature ​
forward<
TTransformerInput>(valueOrValues):TransformerOutput<TTransformerInput,bigint>
Defined in: transformer.ts:205
Transform value(s) forward.
Type Parameters ​
TTransformerInput ​
TTransformerInput extends TransformerInput<number | bigint>
Value(s) input type.
Parameters ​
valueOrValues ​
TTransformerInput
Value(s). If this is an instance of Sequence, the minimum and maximum values are validated prior to transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
Returns ​
TransformerOutput<TTransformerInput, bigint>
Transformed value(s).
Call Signature ​
forward<
TTransformerInput,TOutput>(valueOrValues,transformerCallback):TransformerOutput<TTransformerInput,TOutput>
Defined in: transformer.ts:226
Transform value(s) forward, optionally applying a transformation.
Type Parameters ​
TTransformerInput ​
TTransformerInput extends TransformerInput<number | bigint>
Value(s) input type.
TOutput ​
TOutput
Transformation callback output type.
Parameters ​
valueOrValues ​
TTransformerInput
Value(s). If this is an instance of Sequence, the minimum and maximum values are validated prior to transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
transformerCallback ​
IndexedCallback<bigint, TOutput>
Called after each value is transformed to convert it to its final value.
Returns ​
TransformerOutput<TTransformerInput, TOutput>
Transformed value(s).
doReverse() ​
abstractprotecteddoReverse(transformedValue):bigint
Defined in: transformer.ts:267
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:278
Transform a value in reverse.
Parameters ​
transformedValue ​
Transformed value.
number | bigint
Returns ​
bigint
Value.