Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@elastic.io/maester-client

Package Overview
Dependencies
Maintainers
15
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elastic.io/maester-client - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

spec-integration-temp/objects.spec.ts

2

dist/package.json
{
"name": "@elastic.io/maester-client",
"version": "1.0.0",
"version": "1.1.0",
"description": "The official object-storage client for sailor-nodejs.",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -0,0 +0,0 @@ import { AxiosInstance } from 'axios';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import BucketRepository from './bucket';

@@ -0,0 +0,0 @@ "use strict";

export * from './client';
export * from './bucket';
export * from './object';

@@ -0,0 +0,0 @@ "use strict";

@@ -8,2 +8,3 @@ /// <reference types="node" />

export declare type ObjectMetadata = Record<string, any>;
export declare type QueriableField = Record<string, any>;
export interface ObjectData {

@@ -23,6 +24,23 @@ data: string | Buffer | Readable;

}
export interface ObjectQueryRequest {
[key: string]: string;
}
export interface GetObjectQueryResponse {
objectId: string;
contentType: string;
createdAt: string;
metadata: ObjectMetadata;
queriableFields: QueriableField;
}
interface ObjectField {
Meta: string;
Query: string;
}
interface ObjectFields {
[key: string]: ObjectField;
}
export interface CreateObjectParams {
contentType?: string;
bucket?: string;
metadata?: ObjectMetadata;
objectFields?: ObjectFields;
}

@@ -46,2 +64,6 @@ export interface CreateObjectResponseData {

}
export interface PutObjectParams {
id?: string;
objectFields?: ObjectFields;
}
export default class ObjectRepository {

@@ -56,3 +78,7 @@ private readonly client;

createWriteStream(params?: CreateObjectParams): Writable;
getObjectQuery(query: ObjectQueryRequest, responseType?: ResponseType): Promise<GetObjectQueryResponse[]>;
updateObjectQuery(data: PlainOrArray<string | Buffer | Readable | ObjectData>, params?: PutObjectParams): Promise<void>;
delete(id: string): Promise<void>;
deleteQuery(queryFields: ObjectQueryRequest): Promise<void>;
}
export {};

@@ -77,3 +77,3 @@ "use strict";

create(data, params) {
const { bucket, metadata } = params !== null && params !== void 0 ? params : {};
const { metadata } = params !== null && params !== void 0 ? params : {};
const dataArray = Array.isArray(data) ? data : [data];

@@ -87,5 +87,2 @@ const formData = new form_data_1.default();

}
if (bucket) {
formData.append('bucket', bucket);
}
if (metadata) {

@@ -99,2 +96,10 @@ for (const [key, value] of Object.entries(metadata)) {

};
if (params === null || params === void 0 ? void 0 : params.objectFields) {
Object.entries(params.objectFields).forEach(e => {
if (e[1].Query)
headers[`X-Query-${e[0]}`] = e[1].Query;
if (e[1].Meta)
headers[`X-Meta-${e[0]}`] = e[1].Meta;
});
}
return this.client.post('/objects', formData, { headers })

@@ -110,6 +115,44 @@ .then((res) => Array.isArray(res.data)

}
getObjectQuery(query, responseType) {
const queryString = Object.entries(query)
.map(e => `query[${encodeURIComponent(e[0])}]=${encodeURIComponent(e[1])}`)
.reduce((q1, q2) => `${q1}&${q2}`);
return this.client.get(`/objects?${queryString}`, { responseType })
.then(res => res.data);
}
async updateObjectQuery(data, params) {
const { id } = params !== null && params !== void 0 ? params : {};
const dataArray = Array.isArray(data) ? data : [data];
const formData = new form_data_1.default();
for (const item of dataArray) {
const [data, contentType] = isObjectData(item)
? [item.data, item.contentType]
: [item, exports.DEFAULT_CONTENT_TYPE];
formData.append('data', data, { contentType });
}
const headers = {
'content-type': 'application/octet-stream'
};
if (params === null || params === void 0 ? void 0 : params.objectFields) {
Object.entries(params.objectFields).forEach(e => {
if (e[1].Query)
headers[`X-Query-${e[0]}`] = e[1].Query;
if (e[1].Meta)
headers[`X-Meta-${e[0]}`] = e[1].Meta;
});
}
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return this.client.put(`/objects/${id}`, data, { headers })
.then(res => res.data);
}
delete(id) {
return this.client.delete(`/objects/${id}`);
}
deleteQuery(queryFields) {
const queryString = Object.entries(queryFields)
.map(e => `query[${encodeURIComponent(e[0])}]=${encodeURIComponent(e[1])}`)
.reduce((q1, q2) => `${q1}&${q2}`);
return this.client.delete(`/objects?${queryString}`);
}
}
exports.default = ObjectRepository;
{
"name": "@elastic.io/maester-client",
"version": "1.0.0",
"version": "1.1.0",
"description": "The official object-storage client for sailor-nodejs.",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -96,2 +96,13 @@ # Maester Client

Get object query:
```
const query = {
'x-query-foo': 'fooQuery',
'x-query-bar': 'barQuery',
};
const response = await this.client.objects.getObjectQuery(query);
```
Create read stream example:

@@ -111,17 +122,24 @@

Create object with metadata:
Create object with queryable parameters:
```
const response = await client.objects.create(data, {
metadata: {
key: 'value'
const params = {
objectFields: {
key1: {
Meta: 'someMeta',
Query: 'someQuery',
}
});
}
}
const response = await client.objects.create(data, params);
```
Create object and add it to a bucket:
Create object with metadata:
```
const response = await client.objects.create(data, {
bucket: 'bucket-id'
metadata: {
key: 'value'
}
});

@@ -168,2 +186,16 @@ ```

Update object query:
```
const data = 'hello world';
const objectFields = {
foo: { Query: 'fooQuery', Meta: 'fooMeta' },
bar: { Query: 'barQuery', Meta: 'barMeta' }
};
const params = { id: 'some', objectFields };
const object = await this.client.objects.updateObjectQuery(data, params);
```
Delete object:

@@ -174,1 +206,12 @@

```
Delete object query:
```
const query = {
foo: 'a',
bar: 'b'
};
await client.objects.delete(query);
```

@@ -207,2 +207,28 @@ import nock from 'nock';

describe('get objects query', function () {
it('should get objects', async function () {
const query = {
foo: 'a',
bar: 'b'
};
const data = 'test123';
const response = randomCreateObjectResponse(data);
const contentType = 'text/plain';
const contentLength = data.length;
const scope = nock(this.client.baseUri, this.options)
.defaultReplyHeaders({
'content-type': contentType,
'content-length': contentLength.toString()
})
.get('/objects?query[foo]=a&query[bar]=b')
.reply(200, response);
const object = await this.client.objects.getObjectQuery(query);
expect(scope.isDone()).to.be.true;
expect(object).to.deep.equal(response);
});
});
describe('create object', function () {

@@ -250,20 +276,2 @@ it('should create object from text', async function () {

it('should create object and attach it bucket', async function () {
const data = 'test123';
const bucket = randomObjectId();
const response = randomCreateObjectResponse(data);
const scope = nock(this.client.baseUri, this.options)
.matchHeader('content-type', /multipart\/form-data/)
.post('/objects', body =>
matchFormData(body, 'data', data, response.contentType) &&
matchFormData(body, 'bucket', bucket))
.reply(201, response);
const object = await this.client.objects.create(data, { bucket });
expect(scope.isDone()).to.be.true;
expect(object).to.deep.equal(transformResponse(response));
});
it('should create object and override content type', async function () {

@@ -377,2 +385,27 @@ const data = 'test123';

describe('update object', function () {
it('should update object from text', async function () {
const data = 'test123';
const response = randomCreateObjectResponse(data);
const objectFields = {
foo: { Query: 'fooQuery', Meta: 'fooMeta' },
bar: { Query: 'barQuery', Meta: 'barMeta' }
};
const params = { id: 'some', objectFields };
const scope = nock(this.client.baseUri, this.options)
.matchHeader('x-query-foo', /fooQuery/)
.matchHeader('x-query-bar', /barQuery/)
.matchHeader('x-meta-foo', /fooMeta/)
.matchHeader('x-meta-bar', /barMeta/)
.put(`/objects/${params.id}`)
.reply(200, response);
const object = await this.client.objects.updateObjectQuery(data, params);
expect(scope.isDone()).to.be.true;
expect(object).to.deep.equal(response);
});
});
it('should delete objects', async function () {

@@ -389,2 +422,19 @@ const id = randomObjectId();

});
describe('delete objects query', function () {
it('should delete objects', async function () {
const query = {
foo: 'a',
bar: 'b'
};
const scope = nock(this.client.baseUri, this.options)
.delete('/objects?query[foo]=a&query[bar]=b')
.reply(200);
const object = await this.client.objects.deleteQuery(query);
expect(scope.isDone()).to.be.true;
expect(object.status).to.equal(200);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc