Class: GeneralTransitionEngImpl

base.GeneralTransitionEngImpl()

The General Transition Engine provides basic transitions for files and media while keeping the abstraction for managing and executing transtions which may be of varying complexity and asynchronicity.

Ideally, the most advanced transition engine will operate distributed ATMs or Petri nets with the web interface taking part a an active input driver from among many input drivers.

NOTE: all the base classes in /lib return the class and do not return an instance. Explore the applications and the reader will find that the descendant modules export instances. The classes provided by copious-transitions must be extended by an application.

Constructor

new GeneralTransitionEngImpl()

Source:

Methods

alt_store() → {boolean}

Returns true if the application override is configured to use alternate storage to the default storage provided here.

Source:
Returns:
Type
boolean

app_pack_data(blob_data)

Replaces the functionality of store_data if alt_store returns true.

In the application version of this method, the point is to return data that can be written into a file using the method store_data.

Parameters:
Name Type Description
blob_data object
Source:

(async) chunk_mover(`token`, `file_descriptor`, `target_path`, `cb`) → {string|function}

The map _uploader_managers stores a chunk manager per transition token. Elsewhere in this documentation, the transition object and its token is explained. One kind of transition is one that takes in data from the client, and its token will last as long as the data is being uploaded.

The chunk manager has the purpose of return a collection of chunks in preparation for writing to storage. In some applications, the chunk_mover may return false if the chunks cannot be a complete file. The expectation is that the chunk mover will be called again after adding more chunks, until the data can be stored as a complete object.

When the storage operation has been performed, the store_data method will return an identifier that identifies the data. This may be a hash of the data. Ultimately, this identifier will be returned by this method.

This method is called by chunks_complete.

Parameters:
Name Type Description
`token` string
`file_descriptor` object
`target_path` string
`cb` function
Source:
Returns:
Type
string | function

(async) chunks_complete(post_body, ttrans) → {object}

The post body must have the token field with the value being the transition token required by the request.

The previously prepared chunk manager will be accessed by mapping the token to the chunk manager in the _uploader_managers map.

The post body must have one of the following fields:

  • file_list - an array of file descriptors
  • file - a single descriptor

If the post body has the field file_list,which must be an array of file descriptors, then each descriptor will have at least one field name. The chunk manager will have a map, _chunkers, which maps the file name to the array of gathered chunks.

If the post body as a file field instead of a file_list field, the chunk manager will look for the one array where all the chunks being uploaded have been gathered for storage in just one file.

This method attempts to create a unique name for the file from the information that has been passed to it. Furthermore, it makes use of the transition class object's file_entry_id.

This method is often called by the application's session manager as a part of transition finalization.

Parameters:
Name Type Description
post_body object
ttrans object

the transition class object

Source:
Returns:
  • finalization_state - this object has fields "state" equal to "stored" if successful, "OK" equal to true, and a list of ids, which are all the file ids that have been finally stored.
Type
object

chunks_to_data(`blob_data`) → {Buffer}

Calls the node.js Buffer.concat method. Some application may do something else. Returns a buffer.

Parameters:
Name Type Description
`blob_data` Buffer
Source:
Returns:
Type
Buffer

(async) file_mover(`file_descriptor`, `target_path`, `trans_obj`, cb) → {Number}

A number of parameters are provided for applications needing more complexity than this method provides.

As a default, this method calls node.js mv.

Parameters:
Name Type Description
`file_descriptor` object
`target_path` string
`trans_obj` object
cb function
Source:
Returns:
Type
Number

files_coming_in_chunks(`post_body`, `token`)

Initializes a chunk manager that will receive a number of files identified in the requet body of an uploader type of transition. The chunk manager will be keyed (remembered) by its transition token.

The post body should have a field file_list which must be an array of file descriptors. Each descriptor will have at least one field name. The chunk manager will have a map, _chunkers, which maps the file name to an empty array. The empty array will later be filled with chunk data.

If the post body does not have a file_list field, the chunk manager will keep just one array where all the chunks being uploaded will be placed for future storage in just one file.

This method is often called by the application's session manager as a part of transition processing.

Parameters:
Name Type Description
`post_body` object

the POST request body from the client (or a message from the endpoint server)

`token` string

the chunk manager is always identified by the transtion token

Source:

get_import_key_function() → {string|boolean}

This method returns false. It should be overridden in applications using crytpo key processing.

Source:
Returns:
Type
string | boolean

initialize(conf, db)

At this level, this method just sets the configuration and the database referenc.

Parameters:
Name Type Description
conf object
db object
Source:

install(`statics_assets`, `dynamics_assets`, sessions)

This method sets back references to other lib component class instances. It also tends to the importation of crypto keys.

Parameters:
Name Type Description
`statics_assets` object
`dynamics_assets` object
sessions object
Source:

set_contractual_filters(`trans_processor`, `user_processor`, `mime_processor`)

This method sets back references to the contractual methods which provide the skeletal outline for handling client requests. The contractual class methods, especially those for transition processing, are generally the callers of the application's transition engine. But, the transition engine may call back to those classes if needed (depends on the application).

Parameters:
Name Type Description
`trans_processor` object
`user_processor` object
`mime_processor` object
Source:

set_ws(`web_sockets`)

Accepts a reference to the application supplied web socket server manager and sets the web_sockets field to it.

At times, the transition engine will use the web socket service to fire off messages to listening clients.

Parameters:
Name Type Description
`web_sockets` object

the reference to the application supplied web socket server manager.

Source:

(async) store_data(`file_descriptor`, `target_path`, `writeable_data`, id) → {string}

By default, this method calls the async writeFile method to store data. Some applications may need to route storage at this point.

Parameters:
Name Type Description
`file_descriptor` object
`target_path` string
`writeable_data` string
id string
Source:
Returns:
Type
string

(async) update_meta_descriptors(`post_body`, ids)

This method is provided for those applications using persistent storage use meta descriptors of files.

Parameters:
Name Type Description
`post_body` object
ids Array
Source:

(async) upload_chunk(`post_body`, `files`) → {object}

This method takes in the client's POST request body (or endpoint message) and the list of files associated with it. In some applications, the files map may be part of the request body. In other applications, the files map may be associated with a session token or session and might be cached between calls to the upload_chunk.

The post body must have the token field with the value being the transition token required by the request.

The previously prepared chunk manager will be accessed by mapping the token to the chunk manager in the _uploader_managers map.

The files parameter must alwasy be a map even if there is only one file in files. If there is just one file, this method will check to see if uploading has been prepared to manage just one file. If it has been prepared to upload more, it is possible to have just one file if it is the last file still gathering chunks from the client. Complete files may have already been finalized. (This is why there are differen field names for the single and multiple case.)

This method is often called by the application's session manager as a part of secondary transition processing.

Parameters:
Name Type Description
`post_body` object
`files` string
Source:
Returns:
  • state_of_result
Type
object

(async) upload_file(post_body, ttrans, files, req) → {object}

This method servers to upload a single file or multiple files in response one request, where all the files are complete upon arrival. (If chunking has occurred, it has been handled by standard HTTP mechanisms).

The function of this handler is fairly common code stacks. Other methods in the class are useful in situations where data undergoes intermediate treatment during data gathering or when data is coming in messages from the endpoint server. Usually, this method is used when uploading a file from disk and passing it through standard forms.

This method augments the placement of the file into an application directory by adding descriptors of the file into the DB (which is again defined by the application).

Parameters:
Name Type Description
post_body object
ttrans object
files Array
req object
Source:
Returns:
  • finalization_state
Type
object