Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
070eb559b9 | |||
d07e30d7fb | |||
2293ad69e1 | |||
0a150a8a09 | |||
b5f53b1f64 | |||
e5a02a014a | |||
9d12338630 | |||
3c75bfedfc | |||
d9e80caa6f | |||
e44b7875e6 | |||
52bad357fe | |||
3ffc38dac5 | |||
f35dd1e050 | |||
66eba9eef7 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarts3",
|
"name": "@pushrocks/smarts3",
|
||||||
"version": "1.0.2",
|
"version": "1.0.9",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smarts3",
|
"name": "@pushrocks/smarts3",
|
||||||
"version": "1.0.2",
|
"version": "1.0.9",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^9.0.3",
|
"@pushrocks/smartfile": "^9.0.3",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarts3",
|
"name": "@pushrocks/smarts3",
|
||||||
"version": "1.0.2",
|
"version": "1.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "create an s3 endpoint that maps to a local directory",
|
"description": "create an s3 endpoint that maps to a local directory",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -15,7 +15,6 @@
|
|||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^1.0.78",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.44",
|
||||||
"@pushrocks/smartbucket": "^1.0.44",
|
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^17.0.0",
|
"@types/node": "^17.0.0",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
@ -37,6 +36,7 @@
|
|||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/smartbucket": "^1.0.44",
|
||||||
"@pushrocks/smartfile": "^9.0.3",
|
"@pushrocks/smartfile": "^9.0.3",
|
||||||
"@types/s3rver": "^3.7.0",
|
"@types/s3rver": "^3.7.0",
|
||||||
"s3rver": "^3.7.1"
|
"s3rver": "^3.7.1"
|
||||||
|
11
test/test.ts
11
test/test.ts
@ -6,23 +6,16 @@ import * as smarts3 from '../ts/index';
|
|||||||
let testSmarts3Instance: smarts3.Smarts3;
|
let testSmarts3Instance: smarts3.Smarts3;
|
||||||
|
|
||||||
tap.test('should create a smarts3 instance and run it', async toolsArg => {
|
tap.test('should create a smarts3 instance and run it', async toolsArg => {
|
||||||
testSmarts3Instance = new smarts3.Smarts3({
|
testSmarts3Instance = await smarts3.Smarts3.createAndStart({
|
||||||
port: 3000,
|
port: 3000,
|
||||||
cleanSlate: true,
|
cleanSlate: true,
|
||||||
});
|
});
|
||||||
await testSmarts3Instance.start();
|
|
||||||
console.log(`Let the instance run for 2 seconds`);
|
console.log(`Let the instance run for 2 seconds`);
|
||||||
await toolsArg.delayFor(2000);
|
await toolsArg.delayFor(2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should be able to access buckets', async () => {
|
tap.test('should be able to access buckets', async () => {
|
||||||
const smartbucketInstance = new plugins.smartbucket.SmartBucket({
|
const smartbucketInstance = new plugins.smartbucket.SmartBucket(await testSmarts3Instance.getS3Descriptor());
|
||||||
endpoint: 'localhost',
|
|
||||||
port: 3000,
|
|
||||||
useSsl: false,
|
|
||||||
accessKey: 'S3RVER',
|
|
||||||
accessSecret: 'S3RVER'
|
|
||||||
});
|
|
||||||
const bucket = await smartbucketInstance.createBucket('testbucket');
|
const bucket = await smartbucketInstance.createBucket('testbucket');
|
||||||
const baseDirectory = await bucket.getBaseDirectory();
|
const baseDirectory = await bucket.getBaseDirectory();
|
||||||
await baseDirectory.fastStore('subdir/hello.txt', 'hi there!');
|
await baseDirectory.fastStore('subdir/hello.txt', 'hi there!');
|
||||||
|
25
ts/index.ts
25
ts/index.ts
@ -7,11 +7,23 @@ export interface ISmarts3ContructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Smarts3 {
|
export class Smarts3 {
|
||||||
|
// STATIC
|
||||||
|
public static async createAndStart(optionsArg: ConstructorParameters<typeof Smarts3>[0]) {
|
||||||
|
const smartS3Instance = new Smarts3(optionsArg);
|
||||||
|
await smartS3Instance.start();
|
||||||
|
return smartS3Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
public options: ISmarts3ContructorOptions;
|
public options: ISmarts3ContructorOptions;
|
||||||
public s3Instance: plugins.s3rver;
|
public s3Instance: plugins.s3rver;
|
||||||
|
|
||||||
constructor(optionsArg: ISmarts3ContructorOptions) {
|
constructor(optionsArg: ISmarts3ContructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
|
this.options = {
|
||||||
|
...this.options,
|
||||||
|
...optionsArg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
@ -24,13 +36,22 @@ export class Smarts3 {
|
|||||||
port: this.options.port || 3000,
|
port: this.options.port || 3000,
|
||||||
address: '0.0.0.0',
|
address: '0.0.0.0',
|
||||||
silent: false,
|
silent: false,
|
||||||
directory: paths.bucketsDir,
|
directory: paths.bucketsDir
|
||||||
allowMismatchedSignatures: true,
|
|
||||||
})
|
})
|
||||||
await this.s3Instance.run();
|
await this.s3Instance.run();
|
||||||
console.log('s3 server is running');
|
console.log('s3 server is running');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getS3Descriptor(): Promise<plugins.smartbucket.ISmartBucketConfig> {
|
||||||
|
return {
|
||||||
|
accessKey: 'S3RVER',
|
||||||
|
accessSecret: 'S3RVER',
|
||||||
|
endpoint: 'localhost',
|
||||||
|
port: this.options.port,
|
||||||
|
useSsl: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
await this.s3Instance.close();
|
await this.s3Instance.close();
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,12 @@ export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as samrtfile from '@pushrocks/smartfile';
|
import * as smartbucket from '@pushrocks/smartbucket';
|
||||||
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
samrtfile as smartfile
|
smartbucket,
|
||||||
|
smartfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// thirdparty scope
|
// thirdparty scope
|
||||||
|
Reference in New Issue
Block a user