Node repository related functions.
Example
var repoLib = require('/lib/xp/repo');
Methods
(static) create(params) → {object}
Creates a repository œ
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object | JSON with the parameters. Properties
|
Returns:
Repository created as JSON.
- Type
- object
Examples
// Creates a repository with default configuration
var result1 = repoLib.create({
id: 'test-repo'
});
log.info('Repository created with id ' + result1.id);
// Creates a repository with specific settings
var result2 = repoLib.create({
id: 'test-repo2',
rootPermissions: [
{
"principal": "role:admin",
"allow": [
"READ",
"CREATE",
"MODIFY",
"DELETE",
"PUBLISH",
"READ_PERMISSIONS",
"WRITE_PERMISSIONS"
],
"deny": []
}
],
rootChildOrder: "_timestamp DESC"
});
log.info('Repository created with id ' + result2.id);
// First repository created.
var expected1 = {
"id": "test-repo",
"branches": [
"master"
],
settings: {}
};
(static) createBranch(params) → {object}
Creates a branch
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
params |
object | JSON with the parameters. Properties
|
Returns:
The branch (as JSON).
- Type
- object
Example
// Creates a branch
try {
var result = repoLib.createBranch({
branchId: 'test-branch',
repoId: 'my-repo'
});
log.info('Branch [' + result.id + '] created');
} catch (e) {
if (e.code == 'branchAlreadyExists') {
log.error('Branch [features-branch] already exist');
} else {
log.error('Unexpected error: ' + e.message);
}
}
(static) delete(id) → {boolean}
Deletes a repository
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Repository ID. |
Returns:
true if deleted, false otherwise.
- Type
- boolean
Example
// Retrieves a repository
var result = repoLib.delete('test-repo');
if (result) {
log.info('Repository deleted');
} else {
log.info('Repository was not found');
}
(static) deleteBranch(params) → {object}
Deletes a branch
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
params |
object | JSON with the parameters. Properties
|
Returns:
The branch (as JSON).
- Type
- object
Example
// Deletes a branch
try {
var result = repoLib.deleteBranch({
branchId: 'test-branch',
repoId: 'my-repo'
});
log.info('Branch [' + result.id + '] deleted');
} catch (e) {
if (e.code == 'branchNotFound') {
log.error('Branch [test-branch] does not exist');
} else {
log.error('Unexpected error: ' + e.message);
}
}
(static) get(id) → {object}
Retrieves a repository
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Repository ID. |
Returns:
The repository (as JSON).
- Type
- object
Examples
// Retrieves a repository
var result = repoLib.get('test-repo');
if (result) {
log.info('Repository found');
} else {
log.info('Repository was not found');
}
// Repository retrieved.
var expected = {
"id": "test-repo",
"branches": [
"master"
],
settings: {}
};
(static) list() → {object}
Retrieves the list of repositories
Returns:
The repositories (as JSON array).
- Type
- object
Examples
// Retrieves the list of repositories
var result = repoLib.list();
log.info(result.length + ' repositories found');
// Repositories retrieved.
var expected = [{
"id": "test-repo",
"branches": [
"master"
],
settings: {}
}, {
"id": "another-repo",
"branches": [
"master"
],
settings: {}
}];
(static) refresh(paramsnullable)
Refresh the data for the given index-type in the current repository.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
<nullable> |
JSON with the parameters. Properties
|
Examples
// Refresh all for default repository
repoLib.refresh();
// Refresh storage for default repository
repoLib.refresh({mode: 'storage'});
// Refresh search for 'system-repo' repository
repoLib.refresh({
mode: 'search',
repo: 'system-repo'
});
Type Definitions
IndexDefinition
Type:
- object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
settings |
object |
<optional> |
Index definition settings. |
mapping |
object |
<optional> |
Index definition settings. |