Syncher
The main class for the syncher package. The Syncher is a singleton class per Hyperty/URL and it is the owner of all created Data Sync Objects according to the Reporter - Observer pattern. Main functionality is to create reporters and to subscribe to existing ones.
Constructor Summary
Public Constructor | ||
public |
constructor(owner: HypertyURL, bus: MiniBus, config: JSON) Constructor that should be used by the Hyperty owner |
Member Summary
Public Members | ||
public get |
observers: Object<URL, DataObjectObserver> All owned observers, the ones that were created by a local subscription |
|
public get |
owner: HypertyURL The owner of the Syncher and all created reporters. |
|
public get |
reporters: Object<URL, DataObjectReporter> All owned reporters, the ones that were created by a create |
Method Summary
Public Methods | ||
public |
create(schema: SchemaURL, observers: HypertyURL[], initialData: JSON, store: boolean, p2p: boolean, name: string, identity: MessageBodyIdentity, input: SyncMetadata): Promise<DataObjectReporter> Request a DataObjectReporter creation. |
|
public |
onNotification(callback: function(event: MsgEvent)) Setup the callback to process create and delete events of remove Reporter objects. |
|
public |
onObserversResume(callback: Function): Object<URL, DataObjectObserver> Callback system to trigger the resumed observers |
|
public |
onReportersResume(callback: Function): Object<URL, DataObjectReporter> Callback system to trigger the resumed reporters |
|
public |
Request a read action on the reporter object |
|
public |
resumeObservers(criteria: criteria): Promise<DataObjectObserver> Request a subscription to an existent reporter object. |
|
public |
resumeReporters(criteria: Object): Promise<DataObjectReporter>[] Request a DataObjectReporter creation. |
|
public |
subscribe(schema: SchemaURL, objURL: ObjectURL, store: Boolean, p2p: Boolean, mutual: Boolean, identity: MessageBodyIdentity): Promise<DataObjectObserver> Request a subscription to an existent reporter object. |
Public Constructors
public constructor(owner: HypertyURL, bus: MiniBus, config: JSON) source
Constructor that should be used by the Hyperty owner
Params:
Name | Type | Attribute | Description |
owner | HypertyURL | Hyperty URL owner. An URL allocated by the runtime that uniquely identifies the Hyperty. |
|
bus | MiniBus | An instance of the MiniBus provided in the sandbox. When an object (Reporter or Observed) is created, the SyncherManager will add a listener in the MiniBus to receive/send Messages of that object. |
|
config | JSON | Configuration data. The only required field for now is the runtimeURL. |
Public Members
public get observers: Object<URL, DataObjectObserver> source
All owned observers, the ones that were created by a local subscription
public get reporters: Object<URL, DataObjectReporter> source
All owned reporters, the ones that were created by a create
Public Methods
public create(schema: SchemaURL, observers: HypertyURL[], initialData: JSON, store: boolean, p2p: boolean, name: string, identity: MessageBodyIdentity, input: SyncMetadata): Promise<DataObjectReporter> source
Request a DataObjectReporter creation. The URL will be be requested by the allocation mechanism.
Params:
Name | Type | Attribute | Description |
schema | SchemaURL | Hyperty Catalogue URL address that can be used to retrieve the JSON-Schema describing the Data Object schema |
|
observers | HypertyURL[] | List of hyperties that are pre-authorized for subscription |
|
initialData | JSON | Initial data of the reporter |
|
store | boolean | (Optional) if true, object will be stored by the runtime |
|
p2p | boolean | (Optional) if true, data synchronisation stream will use p2p connection as much as possible |
|
name | string | (Optional) the name of the dataobject |
|
identity | MessageBodyIdentity | (optional) identity data to be added to identity the user reporter. To be used for legacy identities. |
|
input | SyncMetadata | (optional) all metadata required to sunc the Data Object. |
Return:
Promise<DataObjectReporter> | Return Promise to a new Reporter. The reporter can be accepted or rejected by the PEP |
public onNotification(callback: function(event: MsgEvent)) source
Setup the callback to process create and delete events of remove Reporter objects. This is releated to the messagens sent by create to the observers Hyperty array.
Params:
Name | Type | Attribute | Description |
callback | function(event: MsgEvent) |
public onObserversResume(callback: Function): Object<URL, DataObjectObserver> source
Callback system to trigger the resumed observers
Params:
Name | Type | Attribute | Description |
callback | Function | function callback which will be invoked |
public onReportersResume(callback: Function): Object<URL, DataObjectReporter> source
Callback system to trigger the resumed reporters
Params:
Name | Type | Attribute | Description |
callback | Function | function callback which will be invoked |
public read(objURL: ObjectURL): Promise<Object> source
Request a read action on the reporter object
Params:
Name | Type | Attribute | Description |
objURL | ObjectURL | URL of the reporter object to be read |
public resumeObservers(criteria: criteria): Promise<DataObjectObserver> source
Request a subscription to an existent reporter object.
Params:
Name | Type | Attribute | Description |
criteria | criteria | Information to discovery the observer object |
Return:
Promise<DataObjectObserver> | Return Promise to a new observer. It's associated with the reporter. |
public resumeReporters(criteria: Object): Promise<DataObjectReporter>[] source
Request a DataObjectReporter creation. The URL will be be requested by the allocation mechanism.
Params:
Name | Type | Attribute | Description |
criteria | Object | (optional) identity data to be added to identity the user reporter. To be used for legacy identities. |
Return:
Promise<DataObjectReporter>[] | Return a promise with a list of DataObjectReporter to be resumed; |
public subscribe(schema: SchemaURL, objURL: ObjectURL, store: Boolean, p2p: Boolean, mutual: Boolean, identity: MessageBodyIdentity): Promise<DataObjectObserver> source
Request a subscription to an existent reporter object.
Params:
Name | Type | Attribute | Description |
schema | SchemaURL | Hyperty Catalogue URL address that can be used to retrieve the JSON-Schema describing the Data Object schema |
|
objURL | ObjectURL | Address of the existent reporter object to be observed |
|
store | Boolean |
|
Save the subscription on the Syncher Manager for further resume (Default is false) |
p2p | Boolean |
|
Info about if should use p2p connection (Default is false) |
mutual | Boolean |
|
Info about if messages of this object should be encrypted (Default is true) |
identity | MessageBodyIdentity | (optional) identity data to be added to identity the user reporter. To be used for legacy identities. |
Return:
Promise<DataObjectObserver> | Return Promise to a new observer. It's associated with the reporter. |