The main module for CRDTs:
- Read and write CRDT objects
- Generate CRDT metadata
- merge CRDTs
- how to resolve references
Methods
(static) storeVersionedObjectCRDT(obj, objBase) → {Promise.<VersionedObjectResult.<T>>}
Parameters:
Name | Type | Description |
---|---|---|
obj |
T | |
objBase |
SHA256Hash.<T> |
This stores a new version for a crdt based data type.
Functionality:
- A diff is calculated between ob and objBase.
- The metadata is updated based on the changes. The details depend on the CRDT implementation. For a set a list of add / remove objects might be generated, or for a LWWRegister the current time might be recorded for the new value ...
- This metadata is then merged into the latest version generating a new version for the versioned object.
The interface differs from the normal storeVersionedObject only by one additional parameter: objBase. For most CRDTs we need to calculate the changes that have happened since the last version. So you have to specify on which version you based your new object on. We can't just use the latest version that is stored, because other changes might have arrived via chum in the meantime.
Returns:
Type: Promise.<VersionedObjectResult.<T>>
(static) storeVersionedObjectCRDTMergeOnly(metadata) → {Promise.<VersionedObjectResult.<T>>}
Parameters:
Name | Type | Description |
---|---|---|
metadata |
CRDTMetaData.<T.$type$> |
Generate a new version of the versioned object by merging the passed information. The data is referenced by the metadata object, so effectively you pass in metadata and data.
Returns:
Type: Promise.<VersionedObjectResult.<T>>
(async, inner) generateCrdtMetaData(obj, objBaseHash) → {Promise.<unknown>}
Parameters:
Name | Type | Description |
---|---|---|
obj |
T | The new version of the object that shall be written |
objBaseHash |
SHA256Hash.<T> | The base object. It is used to see what changes were made in the original object. |
This generates / updates metadata for all crdt variables.
This function diffs the obj against the base object in order to see what data was added / removed from the object. Then it computes new metadata that then can be merged into the versioned object with the mergeCRDTData call.
Note: This call does not write anything at the moment. It just gets the base version, compares it to the new version and returns the metadata that reflects this diff.
Returns:
- This
Type: Promise.<unknown>
(static) generateCrdtMetadataForRule(rule, obj, objBaseopt, metadataBaseopt, crdtConfigopt) → {Promise.<(undefined|{itemprop:string, metaDataPart: *})>}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rule |
RecipeRule | ||
obj |
Record.<string, any> | ||
objBase |
Record.<string, any> |
<optional> |
|
metadataBase |
Record.<string, any> |
<optional> |
|
crdtConfig |
Recipe.crdtConfig |
<optional> |
Generate the metadata for the given rule. If case, it is recursive for unversioned reference objects.
Returns:
Type: Promise.<(undefined|{itemprop:string, metaDataPart: *})>
(async, inner) mergeCRDTData(obj, metadata, source) → {Promise.<VersionedObjectResult.<T>>}
Parameters:
Name | Type | Description |
---|---|---|
obj |
T | |
metadata |
CRDTMetaData.<T.$type$> | |
source |
"local" | "remote" |
Merges an object with CRDT Annotations into a versioned object
This will generate a new version of the versioned object (if necessary).
Returns:
Type: Promise.<VersionedObjectResult.<T>>
(static) mergeCRDTDataForRule(objLatestVersion, metadataLatestVersion, objToMerge, metadataToMerge, rule, crdtConfig) → {Promise.<(undefined|{itemprop:string, data: *, metadata: *})>}
Parameters:
Name | Type | Description |
---|---|---|
objLatestVersion |
Record.<string, any> | undefined | |
metadataLatestVersion |
Record.<string, any> | undefined | |
objToMerge |
Record.<string, any> | undefined | |
metadataToMerge |
Record.<string, any> | undefined | |
rule |
RecipeRule | |
crdtConfig |
Recipe.crdtConfig |
Merge CRDT data for given rule. If case, it is recursive for unversioned referenced objects.
Returns:
Type: Promise.<(undefined|{itemprop:string, data: *, metadata: *})>
(async, inner) getCrdtAndMetaObjectByIdHash(idHash) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
idHash |
SHA256IdHash.<T> |
Loads the latest data and metadata object for the versioned object.
Returns:
Type: Object
(async, inner) getCrdtAndMetaObject(hash) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
hash |
SHA256Hash.<T> | The hash of a specific object version for which to load data and metadata. |
Loads the latest data and metadata object for the versioned object.
Returns:
Type: Object
(static) getCrdtMetaObjectWithType(hash, type) → {Promise.<OneUnversionedObjectTypes>}
Parameters:
Name | Type | Description |
---|---|---|
hash |
SHA256Hash.<T> | |
type |
OneCrdtObjectTypeNames |
Obtain the meta-object of a certain type for the passed object hash.
Returns:
Type: Promise.<OneUnversionedObjectTypes>
(static) getCrdtMetaObject(hash, type) → {Promise.<OneCrdtMetaObjectTypes>}
Parameters:
Name | Type | Description |
---|---|---|
hash |
SHA256Hash.<T> | |
type |
OneCrdtObjectTypeNames |
Obtain the meta-object for the passed object hash.
Returns:
Type: Promise.<OneCrdtMetaObjectTypes>
(static) getCrdtMetaObjectAsMicrodata(hash, type) → {Promise.<{microdata:string, hash:SHA256Hash.<OneCrdtMetaObjectTypes>}>}
Parameters:
Name | Type | Description |
---|---|---|
hash |
SHA256Hash.<T> | |
type |
OneCrdtObjectTypeNames |
Obtain the meta-object for the passed object hash.
Returns:
Type: Promise.<{microdata:string, hash:SHA256Hash.<OneCrdtMetaObjectTypes>}>
(async, inner) storeCrdtAndMetaObject(metadata) → {Promise.<VersionedObjectResult.<T>>}
Parameters:
Name | Type | Description |
---|---|---|
metadata |
CRDTMetaData.<T.$type$> |
Stores a new version of the data and metadata.
The data is not part of the interface because we expect the data object already be written to disk - but without being recorded in the version map. This can be achieved with the call storeVersionedObjectOmitVersionMap.
Returns:
Type: Promise.<VersionedObjectResult.<T>>
(async, inner) generateMetadataForListRule(rule, objBaseChild, objChild, metadataBaseChild, crdtConfig) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
rule |
RecipeRule | |
objBaseChild |
unknown | |
objChild |
unknown | |
metadataBaseChild |
unknown | |
crdtConfig |
Recipe.crdtConfig |
Generate the metadata object for the given list rule.
Returns:
Type: Object
(async, inner) generateMetadataForRuleWithReferenceToObj(rule, objBaseChild, objChild, metadataBaseChild, crdtConfig) → {Promise.<{itemprop: string, metaDataPart: unknown}>}
Parameters:
Name | Type | Description |
---|---|---|
rule |
RecipeRule | |
objBaseChild |
unknown | |
objChild |
unknown | |
metadataBaseChild |
unknown | |
crdtConfig |
Recipe.crdtConfig |
Generate the metadata object for the given rule with a 'referenceToObject' property. The metadata generation will go recursively if:
- the referenced object is unversioned
- the referenced object has only one single type
- the referenced object has a concrete type ('*' - not accepted; it is handled with CRDT-Register algorithm)
Returns:
Type: Promise.<{itemprop: string, metaDataPart: unknown}>
(async, inner) mergeCRDTDataForListRule(rule, objLatestVersionChildHash, metadataLatestVersionChild, objToMergeChild, metadataToMergeChild, crdtConfig) → {Promise.<{itemprop:string, data: *, metadata: *}>}
Parameters:
Name | Type | Description |
---|---|---|
rule |
RecipeRule | |
objLatestVersionChildHash |
unknown | |
metadataLatestVersionChild |
unknown | |
objToMergeChild |
unknown | |
metadataToMergeChild |
unknown | |
crdtConfig |
Recipe.crdtConfig |
Merge CRDT data for list rule.
Returns:
Type: Promise.<{itemprop:string, data: *, metadata: *}>
(async, inner) mergeCRDTDataForRuleWithReferenceToObj(rule, objLatestVersionChild, metadataLatestVersionChild, metadataToMergeChild, objToMergeChild, crdtConfig) → {Promise.<{itemprop: string, data: unknown, metadata: unknown}>}
Parameters:
Name | Type | Description |
---|---|---|
rule |
RecipeRule | |
objLatestVersionChild |
unknown | |
metadataLatestVersionChild |
unknown | |
metadataToMergeChild |
unknown | |
objToMergeChild |
unknown | |
crdtConfig |
Recipe.crdtConfig |
Merge CRDT data for the given rule with a 'referenceToObject' property. The data is merging is done recursively if:
- the referenced object is unversioned
- the referenced object has only one single type
- the referenced object has a concrete type ('*' - not accepted; it is handled with CRDT-Register algorithm)
Returns:
Type: Promise.<{itemprop: string, data: unknown, metadata: unknown}>