Constructor
new BucketActions(bucket, region)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
bucket |
Object
|
S3 Bucket name. |
region |
Object
|
S3 Region name. |
Example
const actions = new Actions('s3-is-not-a-db', 'us-east-1');
Methods
(async) batch(keyName, actions) → {Promise|Error}
Execute a batch operation in sequential order. Use "Pessimistic Locking" for data integrity.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
actions |
Array.<Promise>
|
Array of promised Actions. |
Returns:
- Type:
-
Promise|Error
Example
const keyName = 'file.json';
const operations = [];
// Fetch the object.
operations.push(() => {
return actions.fetch(keyName);
});
// Update existing data.
operations.push(data => {
return actions.write(keyName, {...data, foo: 'bar'}));
});
actions.batch(keyName, operations)
.catch(function(err) {
console.warn(err.message);
});
(async) delete(keyName) → {Promise.<(Object|Error)>}
Delete object.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
Returns:
- Type:
-
Promise.<(Object|Error)>
Example
actions.prefix = 'path/to/object';
await actions.delete('keyName');
(async) exists(keyName) → {Promise.<(Object|Boolean|Error)>}
Check object exists.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
Returns:
- Type:
-
Promise.<(Object|Boolean|Error)>
Example
actions.prefix = 'path/to/object';
const exists = await actions.exists('keyName');
(async) fetch(keyName) → {Promise.<(Object|Error)>}
Fetch object.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
Returns:
- Type:
-
Promise.<(Object|Error)>
Example
actions.prefix = 'path/to/object';
const data = await actions.fetch('keyName');
(async) isLocked(keyName) → {Promise.<(Boolean|Error)>}
Check object lock exists.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
Returns:
- Type:
-
Promise.<(Boolean|Error)>
Example
actions.prefix = 'path/to/object';
const result = await actions.isLocked('keyName');
isValidData(obj) → {Boolean}
Check object keys match Model fields.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object
|
Data as object. |
Returns:
- Type:
-
Boolean
Example
const result = actions.isValidData({foo: true, bar: false});
(async) list() → {Promise.<(Object|Error)>}
List objects.
- Source:
Returns:
- Type:
-
Promise.<(Object|Error)>
Example
actions.prefix = 'path/to/objects';
const objects = await actions.list();
// ['foo.ext', 'bar.ext', 'biz.ext', 'baz.ext']
(async) lockObject(keyName) → {Promise.<(undefined|Error)>}
Create object lock.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
Returns:
- Type:
-
Promise.<(undefined|Error)>
Example
actions.prefix = 'path/to/object';
await actions.lockObject('keyName');
(async) rename(oldKeyName, newKeyName) → {Promise.<(Object|Error)>}
Rename object.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
oldKeyName |
String
|
Old Object as string. |
newKeyName |
String
|
New object as string. |
Returns:
- Type:
-
Promise.<(Object|Error)>
Example
actions.prefix = 'path/to/object';
await actions.rename('keyName1', 'keyName2');
(async) unlockObject(keyName) → {Promise.<(undefined|Error)>}
Remove object lock.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
keyName |
String
|
Object name. |
Returns:
- Type:
-
Promise.<(undefined|Error)>
Example
actions.prefix = 'path/to/object';
await actions.unlockObject('keyName');
(async) write(keyName, data, contentType) → {Promise.<(Object|Error)>}
Write object.
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
keyName |
String
|
Object name. |
|
data |
String
|
Buffer
|
Object data. |
|
contentType |
String
|
text/plain |
Object content type (default: 'text/plain') |
Returns:
- Type:
-
Promise.<(Object|Error)>
Example
actions.prefix = 'path/to/object';
await actions.write('keyName', 'foo');
..
await actions.write('keyName', {foo1: 'bar'});
..
await actions.write('keyName', <Buffer>, 'image/jpeg; charset=utf-8');