Home Reference Source
import FenceBuilder from 'fence.js/src/lib/FenceBuilder.js'
public class | source

FenceBuilder

A FenceBuilder is used to create an extensible Fence.

An instance of FenceBuilder will have prototype methods that are created through the register() method. When the fork() method is called all of the instance's already registered methods will be transferred to a new instance of FenceBuilder that is then returned. This is what allows you to 'extend' a Fence as you can then continue to register() methods without mutating the original FenceBuilder's prototype.

These prototypical methods are called Invokable's. An Invokable is a named function reference that optionally includes some predefined arguments that can be used to make specific comparisons. *

Constructor Summary

Public Constructor
public

constructor(invokables: Array)

Member Summary

Private Members
private

Method Summary

Public Methods
public

Convert an instance of FenceBuilder to something that can be used to validate some value

public

fork(proto: *): FenceBuilder

Create a clone of a FenceBuilder instance so that it can be extended.

public

hydrate(invokables: String): FenceBuilder

Given a string representing a serialize'd FenceBuilder, attempt to recreate a list of Invokables by calling the named prototype references. If the serialize'd FenceBuilder includes a reference to an unavailable prototype method, an error is thrown.

public

register(name: String, fn: Function): FenceBuilder

Add a named function reference to the prototype of an instance of FenceBuilder

public

serialize(returnFull: *): String

Create a representation of an instance of FenceBuilder's Invokable function reference names and arguments that can be persisted then later used by hydrate() recreate an equivalent FenceBuilder

public

unregister(name: String): FenceBuilder

Remove a named function reference from the prototype of an instance of FenceBuilder

Public Constructors

public constructor(invokables: Array) source

Params:

NameTypeAttributeDescription
invokables Array

A set of already defined Invokable's

Private Members

private _invokables: * source

Public Methods

public build(): Fence source

Convert an instance of FenceBuilder to something that can be used to validate some value

Return:

Fence

an Object with a run() method that can be called with a value, will produce a list of Results

public fork(proto: *): FenceBuilder source

Create a clone of a FenceBuilder instance so that it can be extended.

Params:

NameTypeAttributeDescription
proto *

Return:

FenceBuilder

a reference to a new FenceBuilder

public hydrate(invokables: String): FenceBuilder source

Given a string representing a serialize'd FenceBuilder, attempt to recreate a list of Invokables by calling the named prototype references. If the serialize'd FenceBuilder includes a reference to an unavailable prototype method, an error is thrown.

Params:

NameTypeAttributeDescription
invokables String

A stringify'd JSON blob representing a FenceBuilder's Invokeable's

Return:

FenceBuilder

public register(name: String, fn: Function): FenceBuilder source

Add a named function reference to the prototype of an instance of FenceBuilder

Params:

NameTypeAttributeDescription
name String

A named function reference

fn Function

A reference to a validation function

Return:

FenceBuilder

The FenceBuilder instance being operated on, used for function chaining

public serialize(returnFull: *): String source

Create a representation of an instance of FenceBuilder's Invokable function reference names and arguments that can be persisted then later used by hydrate() recreate an equivalent FenceBuilder

Params:

NameTypeAttributeDescription
returnFull *

Return:

String

a stringified JSON blob that can be persisted

public unregister(name: String): FenceBuilder source

Remove a named function reference from the prototype of an instance of FenceBuilder

Params:

NameTypeAttributeDescription
name String

A named function reference

Return:

FenceBuilder

The FenceBuilder instance being operated on, used for function chaining