Home Reference Source
import {FieldMapperDelegate} from 'tilla/src/field.mapper.delegate.js'
public class | source

FieldMapperDelegate

FieldMapperDelegates provide the API for orchaestrating and arranging FieldMappers on a Transformer. They should typically be used through the util module

Constructor Summary

Public Constructor
public

constructor(sourceKey: string, permissionRanking: Array<string>)

Member Summary

Public Members
public
public
public
public
public
public

delegate: {}

public
public
public
public
public
Private Members
private

Method Summary

Public Methods
public

always(): *

Indicate the following action should be used for every permission level

public

asList(): *

Set the isList falg to be passed to the FieldMapper ie.

public

atOrAbove(permission: string): *

Indicate the following action should be used for this permission level and above

public

Build the permission API for the provided permission ranking on the FieldMapperDelegate instance

public

buildWith(builder: function(instance: Object, key: string, isList: boolean)): *

Assign a CustomFieldMapper to the current permission masking

public

Assigns a PassthroughFieldMapper to the current permission masking

public

restrictTo(permission: string): *

Indicate the following action should be used for this permission level and all others are set to null

public
public

subTransform(transformerKey: string | Transformer | function(): any, permissionLvl: string): *

Assign a SubtransformFieldMapper, indicated by @param transformerKey to the current permission masking.

public

transform(permission: string, instance: Object): Promise

Perform the field transformation at the provided permission level

public

when(permission: string): *

Indicate the following action should be used for the indicated permission level

Private Methods
private

Set all permission lvls to use the same field mapper if the always flag is set

private

_checkAndReset(fieldMapper: *)

Restrict transforming if needed.

private

Restrict access all fields except specified permission lvl and above

private

_restrictTo(fieldMapper: FieldMapper)

Restrict access all fields except specified permission lvl

Public Constructors

public constructor(sourceKey: string, permissionRanking: Array<string>) source

Params:

NameTypeAttributeDescription
sourceKey string
  • optional

the key on the source object.

permissionRanking Array<string>

a custom permission ranking to use to build the permission api.

Public Members

public [`${atOrAbove}${capitalize(permission)}`]: * source

public [`${restrictTo}${capitalize(permission)}`]: * source

public [`${when}${capitalize(permission)}`]: * source

public alwaysFlag: boolean source

public curPermissionLvl: * source

public delegate: {} source

public isList: boolean source

public permissionRanking: * source

public restrict: * source

public restrictAtOrAbove: * source

public sourceKey: * source

Private Members

private _defaultPermissionRanking: boolean source

Public Methods

public always(): * source

Indicate the following action should be used for every permission level

Return:

*

public asList(): * source

Set the isList falg to be passed to the FieldMapper ie. 1:M or M:M associations

Return:

*

public atOrAbove(permission: string): * source

Indicate the following action should be used for this permission level and above

Params:

NameTypeAttributeDescription
permission string

the permission level

Return:

*

public buildPermissionMethods() source

Build the permission API for the provided permission ranking on the FieldMapperDelegate instance

public buildWith(builder: function(instance: Object, key: string, isList: boolean)): * source

Assign a CustomFieldMapper to the current permission masking

Params:

NameTypeAttributeDescription
builder function(instance: Object, key: string, isList: boolean)

the builder function to use when building this field

Return:

*

public passthrough(): * source

Assigns a PassthroughFieldMapper to the current permission masking

Return:

*

public restrictTo(permission: string): * source

Indicate the following action should be used for this permission level and all others are set to null

Params:

NameTypeAttributeDescription
permission string

the permission level

Return:

*

public setPermissionRanking() source

public subTransform(transformerKey: string | Transformer | function(): any, permissionLvl: string): * source

Assign a SubtransformFieldMapper, indicated by @param transformerKey to the current permission masking.

Params:

NameTypeAttributeDescription
transformerKey string | Transformer | function(): any

the Transformer provider.

permissionLvl string
  • optional

If provided, the permission level is used to perform the subtransformation. By the default the parents permission level is used.

Return:

*

public transform(permission: string, instance: Object): Promise source

Perform the field transformation at the provided permission level

Params:

NameTypeAttributeDescription
permission string

The permission level to perform the transformation

instance Object

the source object

Return:

Promise

the transformed value

public when(permission: string): * source

Indicate the following action should be used for the indicated permission level

Params:

NameTypeAttributeDescription
permission string

the permission level

Return:

*

Private Methods

private _always() source

Set all permission lvls to use the same field mapper if the always flag is set

private _checkAndReset(fieldMapper: *) source

Restrict transforming if needed. This will go back and null out some lvls we just set if that is desired.

Params:

NameTypeAttributeDescription
fieldMapper *

private _restrictAtOrAbove(fieldMapper: FieldMapper) source

Restrict access all fields except specified permission lvl and above

Params:

NameTypeAttributeDescription
fieldMapper FieldMapper

the FieldMapper instance

private _restrictTo(fieldMapper: FieldMapper) source

Restrict access all fields except specified permission lvl

Params:

NameTypeAttributeDescription
fieldMapper FieldMapper

the FieldMapper instance