@amag-ch/sap_cap_common_objectstore
Version:
NodeJS library to communicate with an objectstore
86 lines (75 loc) • 2.07 kB
JavaScript
const { Readable } = require('node:stream')
module.exports = class Client {
/**
* Initialise.
*
* @returns {Promise<void>}
*/
init () {
return this
}
/**
* List all files in store.
*
* @returns {Promise<[{filename: string, modifiedAt: Date, contentLength: integer}]>}
*/
list = async () => {
throw new Error('Not implemented')
}
/**
* Read metadata from file.
*
* @param {string} filename
* @returns {Promise<{modifiedAt: Date, contentLength: integer}>}
*/
head = async (filename) => {
throw new Error('Not implemented')
}
/**
* Read file.
*
* @param {string} filename
* @returns {Promise<ReadableStream>}
*/
get = async (filename) => {
throw new Error('Not implemented')
}
/**
* Put new file to store.
*
* @param {string} filename
* @param {string|Readable|Blob|ReadableStream<any>|Uint8Array|Buffer} content
* @param {{contentType?: string}} options
* @returns {Promise<void>}
*/
put = async (filename, content, { contentType }={}) => {
throw new Error('Not implemented')
}
/**
* Delete file in store.
*
* @param {string} filename
* @returns {Promise<void>}
*/
delete = async (filename) => {
throw new Error('Not implemented')
}
/**
* Create client.
*
* @param {Object} credentials
* @returns {Promise<Client>}
*/
static create = async (options) => {
// remove for security reasons (otherwise it's shown in log)
delete options?.credentials?.uri
let client
if (options?.kind === 'local-objectstore')
client = new (require('./LocalClient'))(options?.credentials)
else if (options?.credentials?.bucket)
client = new (require('./S3Client'))(options?.credentials)
else
throw new Error('Application not bound to an objectstore')
return client.init()
}
}