Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: rewrite project to typescript #1109

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@ module.exports = {
'mocha': true,
'es6': true
},
'extends': 'eslint:recommended',
'extends': ['eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
'parser': '@typescript-eslint/parser',
'plugins': ['@typescript-eslint'],
'parserOptions': {
'sourceType': 'module',
"ecmaVersion": 8
'ecmaVersion': 8
},
'rules': {
'no-console': ['error'],
'no-var': ['error'],
'no-empty-function': ['error'],
'comma-dangle': ['error', 'never'],
'prefer-const': ['error'],
'quotes': ['error', 'single'],
'comma-spacing': ['error', { before: false, after: true }],
'semi-spacing': ['warn', { before: false, after: true }],
'space-before-blocks': ['warn', 'always'],
'switch-colon-spacing': ['warn', { after: true, before: false }],
'keyword-spacing': ['warn', { before: true, after: true }],
'template-curly-spacing': ['error', 'never'],
'rest-spread-spacing': ['error', 'never'],
'no-multi-spaces': ['warn', { ignoreEOLComments: false }],
Comment on lines +17 to +30
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are applied for consistent code style. The most prominent one is "prefer-const" to avoid any other var on the codebase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use prettier and use the default configuration to enforce it. And configure husky


'indent': [
'error',
2,
Expand All @@ -23,19 +42,41 @@ module.exports = {
],
'linebreak-style': [
'error',
(process.platform === 'win32' ? 'windows' : 'unix') // all windows platforms are denoted by win32
'unix'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the default linebreak style as LF (unix-style), as this ternary configuration really broke on every text editor / IDE I use on WIndows.

],
'semi': ['error', 'never'],
'spaced-comment': ['error', 'always', {
'line': {
'markers': ['/'],
'exceptions': ['-', '+']
},
'block': {
'markers': ['!'],
'exceptions': ['*'],
'balanced': true
}
}]
},
'block': {
'markers': ['!'],
'exceptions': ['*'],
'balanced': true
}
}],
'@typescript-eslint/no-explicit-any': ['warn'],

'@typescript-eslint/prefer-optional-chain': ['warn'],
'@typescript-eslint/no-empty-function': ['warn'],
'@typescript-eslint/no-empty-interface': ['warn'],

'@typescript-eslint/no-array-constructor': ['off'],

'no-extra-parens': ['off'],
'@typescript-eslint/no-extra-parens': [
'error',
'all',
{
ignoreJSX: 'multi-line',
returnAssign: true,
conditionalAssign: true,
nestedBinaryExpressions: false,
enforceForArrowConditionals: false,
enforceForSequenceExpressions: false,
enforceForNewInMemberExpressions: false
}
]
}
}
10 changes: 5 additions & 5 deletions examples/bucket-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.


var Minio = require('minio')
const Minio = require('minio')

var s3Client = new Minio.Client({
const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
Expand All @@ -31,6 +31,6 @@ s3Client.bucketExists('my-bucketname', function(err, exists) {
return console.log(err)
}
if (exists) {
console.log("Bucket exists.")
console.log('Bucket exists.')
}
})
46 changes: 23 additions & 23 deletions examples/compose-object-test-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
// are dummy values, please replace them with original values.
const os = require('os')
const splitFile = require("split-file")
const splitFile = require('split-file')
const fs = require('fs')

var Minio = require("../dist/main/minio")
var Helpers = require("../dist/main/helpers")
const Minio = require('../dist/main/minio')
const Helpers = require('../dist/main/helpers')


var s3Client = new Minio.Client({
const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
Expand All @@ -35,43 +35,43 @@ const oneMB = 1024 * 1024

// Create a bucket prior to running: mc mb local/source-bucket
function sampleRunComposeObject() {
var tmpDir = os.tmpdir()
const tmpDir = os.tmpdir()


const bucketName = "source-bucket"
const bucketName = 'source-bucket'
// generate 100 MB buffer and write to a file.
var local100mbFileToBeSplitAndComposed = Buffer.alloc(100 * oneMB, 0)
const local100mbFileToBeSplitAndComposed = Buffer.alloc(100 * oneMB, 0)

const composedObjName = '_100-mb-file-to-test-compose'
const tmpSubDir = `${tmpDir}/compose`
var fileToSplit = `${tmpSubDir}/${composedObjName}`
let partObjNameList = []
const fileToSplit = `${tmpSubDir}/${composedObjName}`
const partObjNameList = []

fs.mkdir(tmpSubDir, { recursive: true }, function(err) {
if (err) {
console.log(err)
} else {
console.log("New Temp directory successfully created.")
console.log('New Temp directory successfully created.')
}
})


try {
fs.writeFileSync(fileToSplit, local100mbFileToBeSplitAndComposed)
console.log("Written 100 MB File ")
console.log('Written 100 MB File ')
// 100 MB split into 26 MB part size. ( just to test unequal parts ). But change as required.

splitFile.splitFileBySize(fileToSplit, (26 * oneMB))
splitFile.splitFileBySize(fileToSplit, 26 * oneMB)
.then((names) => {
console.log("Split and write 100 MB File(s) ", names)
console.log('Split and write 100 MB File(s) ', names)
const putPartRequests = names.map((partFileName) => {
const partObjName = partFileName.slice((tmpSubDir + "/").length)
const partObjName = partFileName.slice((tmpSubDir + '/').length)
partObjNameList.push(partObjName)
return s3Client.fPutObject(bucketName, partObjName, partFileName, {})
})

Promise.all(putPartRequests).then(() => {
console.log("Uploaded part Files: ", names)
console.log('Uploaded part Files: ', names)
const sourcePartObjList = partObjNameList.map((partObjName) => {
return new Helpers.CopySourceOptions({
Bucket: bucketName,
Expand All @@ -85,7 +85,7 @@ function sampleRunComposeObject() {
})

s3Client.composeObject(destObjConfig, sourcePartObjList).then(() => {
console.log("Composed to a single file: ", composedObjName)
console.log('Composed to a single file: ', composedObjName)

/** Begin Clean up ***/
// To verify that the parts are uploaded properly, comment the below code blocks and verify
Expand All @@ -94,7 +94,7 @@ function sampleRunComposeObject() {
})

Promise.all(sourcePartObjList).then(() => {
console.log("Removed source parts: ")
console.log('Removed source parts: ')

// Uncomment to remove the composed object itself. commented for verification.
/*
Expand All @@ -106,32 +106,32 @@ function sampleRunComposeObject() {
*/

}).catch(er => {
console.log("Error removing parts used in composing", er)
console.log('Error removing parts used in composing', er)
})

/** End Clean up **/

// Clean up generated parts locally
Helpers.removeDirAndFiles(tmpSubDir)
console.log("Clean up temp parts directory : ")
console.log('Clean up temp parts directory : ')

}).catch((e) => {
console.log("Error Composing parts into an object", e)
console.log('Error Composing parts into an object', e)
})

}).catch(e => {
console.log("Error Uploading parts ", e)
console.log('Error Uploading parts ', e)
})


})
.catch((e) => {
// this is a client error not related to compose object
console.log("Error Splitting files into parts ", e)
console.log('Error Splitting files into parts ', e)
})
} catch (err) {
// this is a client error not related to compose object
console.log("Error Creating local files ", err)
console.log('Error Creating local files ', err)
}


Expand Down
30 changes: 15 additions & 15 deletions examples/compose-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
// are dummy values, please replace them with original values.

var Minio = require("../dist/main/minio")
var Helpers = require("../dist/main/helpers")
const Minio = require('../dist/main/minio')
const Helpers = require('../dist/main/helpers')


var s3Client = new Minio.Client({
const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})

const bucketName = "source-bucket"
const bucketName = 'source-bucket'

const sourceList = [new Helpers.CopySourceOptions( {
Bucket: bucketName,
Object: "parta",
Object: 'parta'
// other options if any.
}),new Helpers.CopySourceOptions({
}), new Helpers.CopySourceOptions({
Bucket: bucketName,
Object: "partb",
Object: 'partb'
// other options if any.
// VersionID:""
}),new Helpers.CopySourceOptions({
}), new Helpers.CopySourceOptions({
Bucket: bucketName,
Object: "partc",
Object: 'partc'

}),new Helpers.CopySourceOptions({
}), new Helpers.CopySourceOptions({
Bucket: bucketName,
Object: "partd",
Object: 'partd'
})]

const destOption = new Helpers.CopyDestinationOptions({
Bucket: bucketName,
Object: "100MB.zip",
Object: '100MB.zip'
/** Other possible options */
/* Encryption:{
type:Helpers.ENCRYPTION_TYPES.KMS,
Expand All @@ -66,10 +66,10 @@ const destOption = new Helpers.CopyDestinationOptions({
})


const composePromise = s3Client.composeObject(destOption,sourceList)
const composePromise = s3Client.composeObject(destOption, sourceList)
composePromise.then((result) => {
console.log("ComposeObject Success..." , result)
console.log('ComposeObject Success...', result)
})
.catch((e)=>{
console.log("composeObject Promise Error",e)
console.log('composeObject Promise Error', e)
})
16 changes: 8 additions & 8 deletions examples/copy-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@
* limitations under the License.
*/

// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname,
// my-src-bucketname and my-src-objectname are dummy values, please replace
// them with original values.
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname,
// my-src-bucketname and my-src-objectname are dummy values, please replace
// them with original values.

var Minio = require('minio')
const Minio = require('minio')

var s3Client = new Minio.Client({
const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
})

var conds = new Minio.CopyConditions()
const conds = new Minio.CopyConditions()
conds.setMatchETag('bd891862ea3e22c93ed53a098218791d')

s3Client.copyObject('my-bucketname', 'my-objectname', '/my-src-bucketname/my-src-objectname', conds, function(e, data) {
if (e) {
return console.log(e)
}
console.log("Successfully copied the object:")
console.log("etag = " + data.etag + ", lastModified = " + data.lastModified)
console.log('Successfully copied the object:')
console.log('etag = ' + data.etag + ', lastModified = ' + data.lastModified)
})

8 changes: 4 additions & 4 deletions examples/fget-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
// are dummy values, please replace them with original values.

var Minio = require('minio')
const Minio = require('minio')

var s3Client = new Minio.Client({
const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY'
Expand All @@ -33,8 +33,8 @@ s3Client.fGetObject('my-bucketname', 'my-objectname', '/tmp/objfile', function(e
console.log('done')
})

//To get a specific version of an object
s3Client.fGetObject('my-bucketname', 'my-objectname', '/tmp/objfile', {versionId:"03fd1247-90d9-4b71-a27e-209d484a234b"}, function(e) {
// To get a specific version of an object
s3Client.fGetObject('my-bucketname', 'my-objectname', '/tmp/objfile', {versionId:'03fd1247-90d9-4b71-a27e-209d484a234b'}, function(e) {
if (e) {
return console.log(e)
}
Expand Down
Loading