Compare commits

..

6 Commits

Author SHA1 Message Date
fbac742db2 1.0.11 2019-10-16 15:21:02 +02:00
3456459456 fix(core): update 2019-10-16 15:21:02 +02:00
c4374da42a 1.0.10 2019-10-15 20:00:00 +02:00
7ba61904ee fix(core): update 2019-10-15 20:00:00 +02:00
f5da38592e 1.0.9 2019-10-15 19:23:06 +02:00
caf0566020 fix(core): update 2019-10-15 19:23:06 +02:00
8 changed files with 167 additions and 11 deletions

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

20
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,20 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone"
}
}
}
}
]
}

30
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.8",
"version": "1.0.11",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -313,6 +313,17 @@
"luxon": "^1.16.0"
}
},
"@pushrocks/streamfunction": {
"version": "1.0.24",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fstreamfunction/-/streamfunction-1.0.24.tgz",
"integrity": "sha512-zGxL1/i5+k+udB0kq+zP6FOXSBsSKbNeNcRratslqtOYDszIPgrMiei05Er/Lpp/hEJKCexcfu3Zi2jQnBgiXQ==",
"requires": {
"@types/from2": "^2.3.0",
"@types/through2": "^2.0.34",
"from2": "^2.3.0",
"through2": "^3.0.1"
}
},
"@pushrocks/tapbundle": {
"version": "3.0.13",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2ftapbundle/-/tapbundle-3.0.13.tgz",
@ -381,6 +392,14 @@
"form-data": "*"
}
},
"@types/from2": {
"version": "2.3.0",
"resolved": "https://verdaccio.lossless.one/@types%2ffrom2/-/from2-2.3.0.tgz",
"integrity": "sha512-WIURl4GQOp6wqa/suhVjtMh9Lgb7nnOsykAPYvwInDLbwu/hCLQcBvF57zQdEterX5sZtKQIHrSFZijvd6FDjA==",
"requires": {
"@types/node": "*"
}
},
"@types/fs-extra": {
"version": "8.0.0",
"resolved": "https://verdaccio.lossless.one/@types%2ffs-extra/-/fs-extra-8.0.0.tgz",
@ -864,6 +883,15 @@
"mime-types": "^2.1.12"
}
},
"from2": {
"version": "2.3.0",
"resolved": "https://verdaccio.lossless.one/from2/-/from2-2.3.0.tgz",
"integrity": "sha1-i/tVAr3kpNNs/e6gB/zKIdfjgq8=",
"requires": {
"inherits": "^2.0.1",
"readable-stream": "^2.0.0"
}
},
"fs-extra": {
"version": "8.1.0",
"resolved": "https://verdaccio.lossless.one/fs-extra/-/fs-extra-8.1.0.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.8",
"version": "1.0.11",
"description": "simple cloud independent object storage",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -21,10 +21,11 @@
"dependencies": {
"@pushrocks/qenv": "^4.0.6",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/streamfunction": "^1.0.24",
"@types/minio": "^7.0.3",
"minio": "^7.0.12"
},
"private": true,
"private": false,
"files": [
"ts/**/*",
"ts_web/**/*",

View File

@ -6,6 +6,7 @@ import * as smartbucket from '../ts/index';
const testQenv = new Qenv('./', './.nogit/');
let testSmartbucket: smartbucket.SmartBucket;
let myBucket: smartbucket.Bucket;
tap.test('should create a valid smartbucket', async () => {
testSmartbucket = new smartbucket.SmartBucket({
@ -15,7 +16,7 @@ tap.test('should create a valid smartbucket', async () => {
});
});
tap.skip.test('should create a bucket', async () => {
tap.skip.test('should create testbucket', async () => {
await testSmartbucket.createBucket('smartbucket');
});
@ -23,4 +24,24 @@ tap.skip.test('should remove testbucket', async () => {
await testSmartbucket.removeBucket('pushrocks-smartbucket');
});
tap.test('should get a bucket', async () => {
myBucket = await testSmartbucket.getBucketByName('smartbucket');
expect(myBucket).to.be.instanceOf(smartbucket.Bucket);
expect(myBucket.name).to.equal('smartbucket');
});
tap.test('should store data in bucket', async () => {
await myBucket.store('hithere/socool.txt', 'hi there!');
});
tap.test('should get data in bucket', async () => {
const fileString = await myBucket.get('hithere/socool.txt');
console.log(fileString);
});
tap.test('should delete data in bucket', async () => {
await myBucket.remove('hithere/socool.txt');
});
tap.start();

View File

@ -2,7 +2,7 @@ import * as plugins from './smartbucket.plugins';
import { SmartBucket } from './smartbucket.classes.smartbucket';
export class Bucket {
public static async createFromName(smartbucketRef: SmartBucket, bucketNameArg: string) {
public static async getBucketByName(smartbucketRef: SmartBucket, bucketNameArg: string) {
const buckets = await smartbucketRef.minioClient.listBuckets();
const foundBucket = buckets.find(bucket => {
return bucket.name === bucketNameArg;
@ -12,13 +12,68 @@ export class Bucket {
console.log(`bucket with name ${bucketNameArg} exists.`)
console.log(`Taking this as base for new Bucket instance`);
return new this(smartbucketRef, bucketNameArg);
} else {
return null;
}
}
public static async createBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
await smartbucketRef.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
return new Bucket(smartbucketRef, bucketName);
}
public static async removeBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
await smartbucketRef.minioClient.removeBucket(bucketName).catch(e => console.log(e));
}
public smartbucketRef: SmartBucket;
public name: string;
constructor(smartbucketRef: SmartBucket, bucketName: string) {
this.smartbucketRef = smartbucketRef;
this.name = bucketName;
}
/**
* store file
*/
public async store(pathArg: string, fileContent: string) {
const streamIntake = new plugins.streamfunction.Intake();
const putPromise = this.smartbucketRef.minioClient.putObject(this.name, pathArg, streamIntake.getReadable()).catch(e => console.log(e));
streamIntake.pushData(fileContent);
streamIntake.signalEnd();
await putPromise;
}
/**
* get file
*/
public async get(pathArg: string) {
const done = plugins.smartpromise.defer();
const fileStream = await this.smartbucketRef.minioClient.getObject(this.name, pathArg).catch(e => console.log(e));
let completeFile: string = '';
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(async (chunk) => {
const chunkString = chunk.toString();
completeFile += chunkString;
return chunk;
}, async (cb) => {
done.resolve();
return Buffer.from('');
});
if (!fileStream) {
return null;
}
fileStream.pipe(duplexStream);
await done.promise;
return completeFile;
}
/**
* removeObject
*/
public async remove (pathArg: string) {
await this.smartbucketRef.minioClient.removeObject(this.name, pathArg);
}
}

View File

@ -26,15 +26,16 @@ export class SmartBucket {
});
}
public async createBucket(bucketName: string) {
await this.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
public async createBucket(bucketNameArg: string) {
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
return bucket;
}
public async removeBucket(bucketName: string) {
await this.minioClient.removeBucket(bucketName).catch(e => console.log(e));
await Bucket.removeBucketByName(this, bucketName);
}
public async getBucket(bucketName: string) {
return Bucket.getFromName(this, bucketName);
public async getBucketByName(bucketName: string) {
return Bucket.getBucketByName(this, bucketName);
}
}

View File

@ -1,6 +1,7 @@
import * as smartpromise from '@pushrocks/smartpromise';
import * as streamfunction from '@pushrocks/streamfunction';
export { smartpromise };
export { smartpromise, streamfunction };
// third party scope
import * as minio from 'minio';