new Project(projectId, storage, mainLogger, gmeConfig)
This project uses a common storage to connect to the database on the server via web-sockets. It can run under both nodeJS and in the browser.
Parameters:
Name | Type | Description |
---|---|---|
projectId |
string | Id of project to be opened. |
storage |
object | Storage connected to the server and database. |
mainLogger |
object | Logger instance. |
gmeConfig |
GmeConfig |
- Source:
Extends
Members
gmeConfig :GmeConfig
Type:
- Inherited From:
- Source:
logger :GmeLogger
Type:
- Inherited From:
- Source:
projectId :string
Unique ID of project, built up by the ownerId and projectName.
Type:
- Inherited From:
- Source:
Example
'guest+TestProject', 'organization+TestProject2'
Methods
createBranch(branchName, newHash, callbackopt) → {external:Promise}
Creates a new branch with head pointing to the provided commit hash.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
branchName |
string | Name of branch to create. |
||||||||||
newHash |
module:Storage~CommitHash | New commit hash for branch head. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitResult result.
On error the promise will be rejected with Error error.
- Type
- external:Promise
createTag(tagName, commitHash, callbackopt) → {external:Promise}
Creates a new tag pointing to the provided commit hash.
Parameters:
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
tagName |
string | Name of tag to create. |
|||||||
commitHash |
module:Storage~CommitHash | Commit hash tag will point to. |
|||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with nothing.
On error the promise will be rejected with Error error.
- Type
- external:Promise
deleteBranch(branchName, oldHash, callbackopt) → {external:Promise}
Deletes the branch.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
branchName |
string | Name of branch to create. |
||||||||||
oldHash |
module:Storage~CommitHash | Previous commit hash for branch head. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitResult result.
On error the promise will be rejected with Error error.
- Type
- external:Promise
deleteTag(tagName, callbackopt) → {external:Promise}
Deletes the given tag.
Parameters:
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
tagName |
string | Name of tag to delete. |
|||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with nothing.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getBranchHash(branchName, callbackopt) → {external:Promise}
Retrieves the commit hash for the head of the branch.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
branchName |
string | Name of branch. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitHash commitHash.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getBranches(callbackopt) → {external:Promise}
Retrieves all branches and their current heads within the project.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
Object.<string, module:Storage~CommitHash> branches.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getCommitObject(branchNameOrCommitHash, callbackopt) → {external:Promise}
Retrieves the commit-object at the provided branch or commit-hash.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
branchNameOrCommitHash |
string | Name of branch or a commit-hash. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Inherited From:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitObject commitObject.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getCommits(before, number, callbackopt) → {external:Promise}
Retrieves and array of the latest (sorted by timestamp) commits for the project.
If timestamp is given it will get number of commits strictly before before.
If commit hash is specified that commit will be included too.
N.B. due to slight time differences on different machines, ancestors may be returned before
their descendants. Unless looking for 'headless' commits 'getHistory' is the preferred method.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
before |
number | module:Storage~CommitHash | Timestamp or commitHash to load history from. |
||||||||||
number |
number | Number of commits to load. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
Array.<module:Storage~CommitObject> commits.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getCommonAncestorCommit(commitA, commitB, callbackopt) → {external:Promise}
Retrieves the common ancestor of two commits. If no ancestor exists it will result in an error.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
commitA |
module:Storage~CommitHash | Commit hash. |
||||||||||
commitB |
module:Storage~CommitHash | Commit hash. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitHash commitHash.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getHistory(start, number, callbackopt) → {external:Promise}
Retrieves an array of commits starting from a branch(es) and/or commitHash(es).
The result is ordered by the rules (applied in order)
1. Descendants are always returned before their ancestors.
2. By their timestamp.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
start |
string | module:Storage~CommitHash | Array.<string> | Array.<module:Storage~CommitHash> | Branch name, commit hash or array of these. |
||||||||||
number |
number | Number of commits to load. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
Array.<module:Storage~CommitObject> commits.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getProjectInfo(callbackopt) → {external:Promise}
Retrieves the metadata of the project.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
{object} projectInfo.
On error the promise will be rejected with Error error.
- Type
- external:Promise
Example
{
_id: 'guest+example',
owner: 'guest',
name: 'example',
info: {
createdAt: '2016-12-02T17:52:25.029Z',
viewedAt: '2017-01-30T22:45:15.269Z',
modifiedAt: '2017-01-20T00:15:34.593Z',
creator: 'guest',
viewer: 'guest',
modifier': 'guest'
},
hooks: {
ConstraintCheckerHook': {
url: 'http://127.0.0.1:8080/ConstraintCheckerHook',
description': 'Checks if there are any meta violations in the project',
events: ['COMMIT'],
active: true,
createdAt: '2017-01-19T23:22:46.834Z',
updatedAt: '2017-01-19T23:22:46.834Z'
}
},
rights: {
read: true,
write: true,
delete: true
},
branches: {
b1: '#998067142c7ff8067cd0c04a0ec4ef80d865606c',
master: '#36df6f8c17b2ccf4e35a2a75b1e0adb928f82a61'
}
}
getRootHash(branchNameOrCommitHash, callbackopt) → {external:Promise}
Retrieves the root hash at the provided branch or commit-hash.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
branchNameOrCommitHash |
string | Name of branch or a commit-hash. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Inherited From:
- Source:
Returns:
On success the promise will be resolved with
module:Core~ObjectHash rootHash.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getTags(callbackopt) → {external:Promise}
Retrieves all tags and their commits hashes within the project.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
Object.<string, module:Storage~CommitHash> tags.
On error the promise will be rejected with Error error.
- Type
- external:Promise
getUserId() → {string}
Return the identity of the current user of this project.
- Overrides:
- Source:
Returns:
the userId
- Type
- string
makeCommit(branchName, parents, rootHash, coreObjects, msg, callbackopt) → {external:Promise}
Makes a commit to data base. Based on the root hash and commit message a new module:Storage.CommitObject (with returned hash) is generated and insert together with the core objects to the database on the server.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
branchName |
string | Name of branch to update (none if null). |
|||||||||||
parents |
Array.<module:Storage~CommitHash> | Parent commit hashes. |
|||||||||||
rootHash |
module:Core~ObjectHash | Hash of root object. |
|||||||||||
coreObjects |
module:Core~DataObject | Core objects associated with the commit. |
|||||||||||
msg |
string | 'n/a' | Commit message. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitResult result.
On error the promise will be rejected with {Error} error.
- Type
- external:Promise
Examples
var persisted = core.persist(rootNode);
project.makeCommit('master', ['#thePreviousCommitHash'], persisted.rootHash, persisted.objects, 'new commit')
.then(function (result) {
// result = {
// status: 'SYNCED',
// hash: '#thisCommitHash'
// }
})
.catch(function (error) {
// error.message = 'Not authorized to read project: guest+project'
});
project.makeCommit('master', ['#notPreviousCommitHash'], persisted.rootHash, persisted.objects, 'new commit')
.then(function (result) {
// result = {
// status: 'FORKED',
// hash: '#thisCommitHash'
// }
})...
project.makeCommit(null, ['#anExistingCommitHash'], persisted.rootHash, persisted.objects, 'new commit')
.then(function (result) {
// result = {
// hash: '#thisCommitHash'
// }
})...
project.makeCommit('master', ['#aPreviousCommitHash'], previousRootHash, {}, 'adding a commit to master')
.then(function (result) {
// result = {
// status: 'SYNCED',
// hash: '#thisCommitHash'
// }
})...
sendDocumentOperation(data)
Send operation made, and optionally selection, on document at docId.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object |
Properties
|
sendDocumentSelection(data)
Send selection on document at docId. (Will only be transmitted if client is Synchronized.)
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
object |
Properties
|
setBranchHash(branchName, newHash, oldHash, callbackopt) → {external:Promise}
Updates the head of the branch.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
branchName |
string | Name of branch to update. |
||||||||||
newHash |
module:Storage~CommitHash | New commit hash for branch head. |
||||||||||
oldHash |
module:Storage~CommitHash | Current state of the branch head inside the database. |
||||||||||
callback |
function |
<optional> |
If provided no promise will be returned. Properties
|
- Overrides:
- Source:
Returns:
On success the promise will be resolved with
module:Storage~CommitResult result.
On error the promise will be rejected with Error error.
- Type
- external:Promise
unwatchDocument(data, callbackopt) → {Promise}
Stop watching the document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object |
Properties
|
|||||||||||||||||||||
callback |
function |
<optional> |
Properties
|
Returns:
- Type
- Promise
watchDocument(data, atOperation, atSelection, callbackopt) → {Promise}
Start watching the document at the provided context.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object |
Properties
|
|||||||||||||||||||||||||
atOperation |
function | Triggered when other clients' operations were applied Properties
|
|||||||||||||||||||||||||
atSelection |
function | Triggered when other clients send their selection info Properties
|
|||||||||||||||||||||||||
callback |
function |
<optional> |
Properties
|
Returns:
- Type
- Promise