Store

Class representing an S3 store.

Constructor

new Store(params)

Interact with an object in an S3 bucket.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeAttributesDefaultDescription
credentialsCredentials

the AWS credentials to use for the connection

prefixstring

define a path prefix

typestring

the class / type of the item being operated on - must match: ^[a-z,A-Z][a-z,A-Z,0-9,_]+$

idstring

the id of the item being operated on - must match: ^[a-z,A-Z][a-z,A-Z,0-9,_]+$

splaynumber<optional>
1

the number of characters (from the start of the identifer) when converting the id to a path

Since
  • 1.17.0

Classes

Store

Methods

(async) copy(params)

Copy a file into the item from another part of the storage. This capability is specifically to support using different locations in the bucket for working data and repository data where the repository data might contain versioned copies of the working data.

This method is an event emitter. Listen to events using the store handle.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDefaultDescription
sourceString

the source file to be copied - this must be a full path to the file inside the bucket

targetString

the target location to copy the source file to; this is relative to the object path

registerFileBooleantrue

whether the file should be registered in ro-crate-metadata.json. The file will be registered in the hasPart property of the root dataset if there isn't already an entry for the file.

versionBooleanfalse

whether the file should be versioned. If true, the existing file will be copied to ${file}.v${date as ISO String}.{ext} before the new version is uploaded to the target name

batchArray.<Transfer>

an array of objects defining content to put into the store where the params are as for the single case. Uploads will be run 5 at a time.

Since
  • 1.18.0
Example

Listening to events

const store = new Store({})
store.on("copy", (msg) => console.log(msg));
// where msg = { msg: 'Copied batch 1/1 (1/1 files)', date: date as ISO String }

(async) createObject() → {Boolean}

Create the object in the storage.

Since
  • 1.17.0
Returns:
Type: 
Boolean

(async) delete(params)

Remove a file or files from an item in the storage. Files will also be removed from the hasPart property of the root dataset.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeAttributesDescription
targetString | Array.<String><optional>

the target name for the file or array of target files; this will be set relative to the item path

prefixString<optional>

file prefix; this will be set relative to the item path

(async) exists() → {Boolean}

Check whether the object exists in the storage.

Since
  • 1.17.0
Returns:
Type: 
Boolean

(async) fileExists(params) → {Boolean}

Check whether the path exists in the storage.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
pathString

the path of the file to check - this is relative to the item root

Since
  • 1.17.0
Returns:
Type: 
Boolean

(async) get(params)

Get a file from the item on the storage.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
localPathString

the local path where you want to download the file to

targetString

the file on the storage, relative to the item path, that you want to download

(async) getJSON(params)

Get a JSON file from the item on the storage.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
localPathString

the local path where you want to download the file to

targetString

the file on the storage, relative to the item path, that you want to download

(async) getObjectIdentifier() → {Object}

Get the object identifier.

Since
  • 1.17.0
Returns:
Type: 
Object

(async) getObjectInventory() → {Object}

Get the object inventory file.

Since
  • 1.17.0
Returns:
Type: 
Object

getObjectPath() → {String}

Get the path of the object in the storage.

Since
  • 1.17.0
Returns:
Type: 
String

(async) getPresignedUrl(params)

Get a presigned link to the file.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
targetString

the file on the storage, relative to the item path, that you want the url for

downloadString

get link that can be used to trigger a direct file download

(async) hashTarget(params) → {String}

Calculate the SHA512 hash of a file in storage

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
targetString

the file on the storage, relative to the item path, that is to be hashed

Returns:
  • the hash of the file or undefined
Type: 
String

(async) listFileVersions(params) → {Array}

Get file versions.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
targetString

the file whose versions to retrieve

Returns:
  • versions of the specified file ordered newest to oldest. The file as named (ie without a version string will be the first - newest - entry)
Type: 
Array

(async) listResources() → {Array.<String>}

Recursively walk and list all of the files for the item.

Returns:
  • a list of files
Type: 
Array.<String>

(async) put(params)

Put a file or batch of files into the item on the storage.

This method is an event emitter. Listen to events using the store handle.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDefaultDescription
localPathString

the path to the file locally that you want to upload to the item folder

jsonString

a JSON object to store in the file directly

contentString

some content to store in the file directly

targetString

the target name for the file; this will be set relative to the item path

registerFileBooleantrue

whether the file should be registered in ro-crate-metadata.json. The file will be registered in the hasPart property of the root dataset if there isn't already an entry for the file.

versionBooleanfalse

whether the file should be versioned. If true, the existing file will be copied to ${file}.v${date as ISO String}.{ext} before the new version is uploaded to the target name

mimetypeString

the mimetype of the file. If not defined, the library will try to determine it.

batchArray.<Transfer>

an array of objects defining content to put into the store where the params are as for the single case. Uploads will be run 5 at a time.

Example

Listening to events

const store = new Store({})
store.on("put", (msg) => console.log(msg));
// where msg = { msg: 'Uploaded batch 1/1 (1/1 files)', date: date as ISO String }

(async) registerFilesInCrateMetadata(filesopt)

Register a set of files in ro-crate-metadata.json. If no files are defined the method will register all files that are not special files. This includes the ro-crate-metadata file (or any version of it).

Parameters:
NameTypeAttributesDescription
filesArray.<String><optional>

if provided, the array of file names to be registered, relative to the root of the object.

Since
  • 1.18.0

(async) removeObject()

Delete the object in the storage.

Since
  • 1.17.0

resolvePath() → {String}

Resolve the full path of a file in the storage

Parameters:
NameTypeDescription
params.pathString

the path to the file relative to the object root that it to be resolved

Since
  • 1.17.0
Returns:
  • the full path to a file
Type: 
String

(async) stat(params) → {Boolean}

Return the file stat.

Parameters:
NameTypeDescription
paramsObject
Properties
NameTypeDescription
pathString

the path of the file to stat- this is relative to the item root

Returns:
Type: 
Boolean