-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from elasticio/first-version
first version
- Loading branch information
Showing
16 changed files
with
3,793 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"extends": [ | ||
"standard-with-typescript", | ||
"plugin:mocha/recommended" | ||
], | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"plugins": [ | ||
"mocha" | ||
], | ||
"rules": { | ||
"semi": "off", | ||
"@typescript-eslint/space-before-function-paren": "off", | ||
"@typescript-eslint/no-unused-expressions": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/strict-boolean-expressions": "off", | ||
"@typescript-eslint/promise-function-async": "off", | ||
"@typescript-eslint/return-await": "off", | ||
"@typescript-eslint/member-delimiter-style": [ | ||
"error", | ||
{ | ||
"multiline": { | ||
"delimiter": "semi", | ||
"requireLast": true | ||
}, | ||
"singleline": { | ||
"delimiter": "semi", | ||
"requireLast": false | ||
} | ||
} | ||
], | ||
"@typescript-eslint/indent": [ | ||
"error", | ||
4, | ||
{ | ||
"SwitchCase": 1, | ||
"FunctionDeclaration": { | ||
"parameters": "first" | ||
}, | ||
"FunctionExpression": { | ||
"parameters": "first" | ||
} | ||
} | ||
], | ||
"max-len": [ | ||
"warn", | ||
120, | ||
4, | ||
{ | ||
"ignoreUrls": true, | ||
"ignoreTemplateLiterals": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
/dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea | ||
/src | ||
/dist/spec | ||
.eslintignore | ||
.eslintrc.json | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
save-exact=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,170 @@ | ||
# maester-client | ||
Client library for object storage | ||
# Maester Client | ||
|
||
The official object-storage client for elasticio-sailor-nodejs. | ||
|
||
## Usage | ||
|
||
### Create client | ||
``` | ||
const Client = require('@elasticio/maester-client'); | ||
const client = new Client('http://maester.local:3002', 'my-token'); | ||
``` | ||
|
||
### Buckets API | ||
|
||
Get bucket: | ||
|
||
``` | ||
const bucket = await client.buckets.get(id); | ||
``` | ||
|
||
List buckets: | ||
|
||
``` | ||
const buckets = await client.buckets.list({ | ||
page: { | ||
number: 1, | ||
size: 25 | ||
} | ||
}); | ||
``` | ||
|
||
List buckets by external ID: | ||
|
||
``` | ||
const buckets = await client.buckets.list({ | ||
externalId: 'my-external-id' | ||
}); | ||
``` | ||
|
||
Create bucket: | ||
|
||
``` | ||
const bucket = await client.buckets.create({ | ||
objects: ['object-1', 'object-2', ..., 'object-N'], | ||
extrenalId: 'my-external-id | ||
}); | ||
``` | ||
|
||
Update bucket: | ||
|
||
``` | ||
const bucket = await client.buckets.update(id, { | ||
closed: true | ||
}); | ||
``` | ||
|
||
Delete bucket: | ||
|
||
``` | ||
await client.buckets.delete(id); | ||
``` | ||
|
||
### Objects API | ||
|
||
Get object: | ||
|
||
``` | ||
const object = await client.objects.get(id); | ||
console.log(object.data); | ||
``` | ||
|
||
Object's property `data` has value of type `string`, `object`, `Buffer` or `Stream`. | ||
|
||
Get object as JSON: | ||
|
||
``` | ||
const object = await client.objects.getJSON(id); | ||
console.log(object.data); | ||
``` | ||
|
||
Get object as buffer: | ||
|
||
``` | ||
const object = await client.objects.getBuffer(id); | ||
console.log(object.data.toString()) | ||
``` | ||
|
||
Get object as stream: | ||
|
||
``` | ||
const object = await client.objects.getStream(id); | ||
object.data.pipe(...) | ||
``` | ||
|
||
Create read stream example: | ||
|
||
``` | ||
client.objects.createReadStream(id).pipe(fs.createWriteStream('/foo/bar.jpg')); | ||
``` | ||
|
||
Create object: | ||
|
||
``` | ||
const response = await client.objects.create(data); | ||
``` | ||
|
||
Where `data` can be `string`, `Buffer`, `Stream` or array of these values. | ||
|
||
Create object with metadata: | ||
|
||
``` | ||
const response = await client.objects.create(data, { | ||
metadata: { | ||
key: 'value' | ||
} | ||
}); | ||
``` | ||
|
||
Create object and add it to a bucket: | ||
|
||
``` | ||
const response = await client.objects.create(data, { | ||
bucket: 'bucket-id' | ||
}); | ||
``` | ||
|
||
Create object and override its content type: | ||
|
||
``` | ||
const response = await client.objects.create({ | ||
data: 'hello world', | ||
contentType: 'text/plain' | ||
}); | ||
``` | ||
|
||
Create multiple objects at once: | ||
|
||
``` | ||
const data = [ | ||
{ | ||
data: 'hello world' | ||
}, | ||
{ | ||
data: JSON.stringify(json), | ||
contentType: 'application/json' | ||
}, | ||
fs.createReadStream('/foo/bar.jpg'), | ||
Buffer.allocUnsafe(1024) | ||
]; | ||
const response = await client.objects.create(data, { | ||
bucket: 'bucket-id', | ||
metadata: { | ||
description: 'my stuff' | ||
} | ||
}); | ||
``` | ||
|
||
Writable stream example: | ||
|
||
``` | ||
fs.createReadStream('/foo/bar.jpg').pipe(client.objects.createWriteStream()); | ||
``` | ||
|
||
Delete object: | ||
|
||
``` | ||
await client.objects.delete(id); | ||
``` |
Oops, something went wrong.