Module: util/object

Helper functions for (ONE) objects. Most of them are only useful for ONE objects, except for createReadonlyTrackingObj() which works for any Javascript object.

Source:

Members

(static, constant) MICRODATA_START :'<div itemscope itemtype="//refin.io/'

A string constant containing the string any ONE microdata object would start with.

Type:
  • '<div itemscope itemtype="//refin.io/'
Source:

(static, constant) ID_OBJECT_ATTR :'data-id-object="true"'

ID objects have an attribute data-id-object="true" in their outer span tag. This replaces the beginning of the outer span tag to make ONE ID object microdata from mere ONE object data. The purpose of the (never written, purely virtual!) attribute is to make ID objects and ID hashes different from the hash of an ordinary ONE object that happens to have only the properties that also are ID properties, so that no (concrete) ONE object's SHA-256 is the same as its ID hash.

A normal object:

<span itemScope itemType="//refin.io/MyType">...</span>

An ID object (purely virtual):

<div data-id-object="true" itemScope itemType="//refin.io/MyType">...</span>

Type:
  • 'data-id-object="true"'
Source:

(static, constant) ID_OBJ_MICRODATA_START :'<div itemscope itemtype="//refin.io/'

A string constant containing the string any ONE microdata object would start with.

Type:
  • '<div itemscope itemtype="//refin.io/'
Source:

Methods

(static) isIdObjMicrodata(html) → {boolean}

Parameters:
Name Type Description
html string

A helper function that takes a ONE object microdata string and returns true if the microdata represents an ID object, false otherwise.

Source:
Returns:

Type: boolean

(async, static) calculateHashOfObj(obj) → {Promise.<SHA256Hash>}

Parameters:
Name Type Description
obj OneObjectTypes

A ONE object in Javascript object format (if it was microdata format one could calculate the hash directly).

Given a ONE object in JS object notation, this function converts the object to microdata format and then calculates and returns the crypto-hash over that string.

Source:
Returns:

Returns a promise that resolves with the SHA-256 hash

Type: Promise.<SHA256Hash>

(async, static) calculateIdHashOfObj(obj) → {Promise.<SHA256IdHash>}

Parameters:
Name Type Description
obj OneVersionedObjectTypes | OneIdObjectTypes

A versioned ONE object or an ID object for such an object

This function takes a ONE object in Javascript object representation, converts it into an ID object (i.e. it only has fields defined as ID fields in object-recipes.js for the given type of ONE object), converts that into a microdata string, and then calculates the crypto-hash of that string.

Source:
Returns:

ID hash of the given versioned ONE object

Type: Promise.<SHA256IdHash>

(static) getTypeFromMicrodata(microdata) → {string|'BLOB'}

Parameters:
Name Type Description
microdata string

A ONE microdata object, or the part of it at the beginning. Only the full opening tag up to and including its ">" closing character are needed and used.

This function extracts the ONE object type name string from the "itemtype" attribute of the span tag surrounding ONE object data in its microdata HTML string representation. The function does not check if the type has a known recipe in the current runtime! That is why the return type only is string and not the much stronger OneObjectTypeNames.

Source:
Returns:

The type string of the given microdata object, the type string plus " [ID]" if it is an ID object, or 'BLOB' if the given string does not look like ONE object microdata

Type: string | 'BLOB'

(static) createReadonlyTrackingObj(obj, includeMutableReferencesopt) → {object}

Parameters:
Name Type Attributes Default Description
obj object

An object whose top-level enumerable properties will be made available through a new read-only object

includeMutableReferences boolean <optional>
false

Only the basic types number, boolean and string can be tracked read-only, because objects are reference values. By default, we leave them out of the tracking object because we cannot guarantee the read-only status.

Creates a read-only object tracking the top-level properties of another object. The use case is if you need an object that is read-write in one context but read-only in another. This is not possible, but we can create an object with no setters and with getters that deliver the values of the respective property of the original object, as a real-time and read-only copy of the object.

Source:
Returns:

A read-only object whose top-level properties track the values of the top-level properties of the given object

Type: object