Module: microdata-to-id-hash

A ONE internal module to optimize the calculation of ID hashes from microdata without going through a to-Javascript-object conversion.

Source:

Methods

(static) extractIdObject(microdata, expectedTypeopt) → {undefined|string}

Parameters:
Name Type Attributes Description
microdata string

The full microdata string

expectedType OneObjectTypeNames | Array.<OneObjectTypeNames> <optional>

An optional expected type or an array of expected type names. If it is not matched by the microdata leads to an Error when attempting to parse the microdata. Leaving this parameter undefined or setting it to '*' disables the type check.

This function takes a ONE object in microdata format, parses the type, and if it is a versioned object builds the ID object microdata by extracting the ID properties into a new string and adding the ID object attribute to the outer span.

Assumption (enforced in type-checks.js function ensureRecipeRuleObj): all ID properties are on the top level, never inside nested objects. Reminder: nested objects are part of the object, unlike included objects, which have their own recipe, and which even when included in imploded form don't influence the ID object of the parent, since they cannot be ID properties (disallowed through the mentioned type-checks.js function).

Source:
Returns:

Returns the ONE object microdata string of the ID object or undefined if the object is not a versioned object and no ID object can be built

Type: undefined | string

(async, static) calculateIdHashForStoredObj(hash, expectedTypeopt) → {Promise.<(undefined|SHA256Hash)>}

Parameters:
Name Type Attributes Default Description
hash SHA256Hash
expectedType OneVersionedObjectTypeNames | Array.<OneVersionedObjectTypeNames> | '*' <optional>
'*'

An optional expected type or an array of expected type names. If it is not matched by the microdata leads to an Error when attempting to parse the microdata. Leaving this parameter undefined or setting it to '*' disables the type check.

The function calculates the ID hash for a given hash. If the object is not a versioned object undefined is returned.

This method performs no validity checks on the microdata. It presumes that the microdata represents a valid ONE object.

However, if the header itself cannot be parsed an Error is thrown. An error is also thrown if for a detected opening tag no matching closing tag can be found, and an Error is thrown if there is an expectedType parameter and the type found in the header is not a match.

Source:
Returns:

Returns undefined if the hash points to an unversioned object, or the SHA-256 of the ID object of the object identified by the given hash if it is a versioned object.

Type: Promise.<(undefined|SHA256Hash)>