Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4ef2085
wip
Yoann-Abbes Nov 15, 2019
1c9af67
wip
Yoann-Abbes Nov 15, 2019
86e632f
wip
Yoann-Abbes Nov 15, 2019
553ebda
wip
Yoann-Abbes Nov 15, 2019
b93c0f1
wip
Yoann-Abbes Nov 15, 2019
35be008
wip
Yoann-Abbes Nov 15, 2019
e0d5b4f
wip
Yoann-Abbes Nov 15, 2019
b9b80ee
wip
Yoann-Abbes Nov 15, 2019
e9e94ab
[ci skip] wip
Yoann-Abbes Nov 15, 2019
c79dd3e
[ci skip] wip
Yoann-Abbes Nov 15, 2019
cec592e
[ci skip] wip
Yoann-Abbes Nov 15, 2019
1538d93
[ci skip] wip
Yoann-Abbes Nov 15, 2019
8c2ae9e
[ci skip] wip
Yoann-Abbes Nov 15, 2019
c366238
[ci skip] wip
Yoann-Abbes Nov 15, 2019
d27e6ba
[ci skip] wip
Yoann-Abbes Nov 15, 2019
68d1808
revert change
Yoann-Abbes Nov 15, 2019
18fe729
fix tests
Yoann-Abbes Nov 15, 2019
9911237
Merge branch '7-dev' into handle-double-routes
Yoann-Abbes Nov 21, 2019
71d66a9
fix tests
Yoann-Abbes Nov 21, 2019
6e64216
doc
Yoann-Abbes Nov 21, 2019
6114798
@Aschen requested changes
Yoann-Abbes Nov 22, 2019
036a87f
add mgetUsers
Yoann-Abbes Jan 9, 2020
2f06b02
doc
Yoann-Abbes Jan 9, 2020
448b528
fix
Yoann-Abbes Jan 9, 2020
2819638
Update doc/7/controllers/security/m-get-users/index.md
Yoann-Abbes Jan 9, 2020
9c70403
Update doc/7/controllers/security/m-get-users/index.md
Yoann-Abbes Jan 9, 2020
9b5c9f1
Merge branch '7-dev' into handle-double-routes
Feb 1, 2020
0fb2dfb
Merge branch 'handle-double-routes' of github.com:kuzzleio/sdk-javasc…
Feb 1, 2020
d242e9e
hook snippet doc
Yoann-Abbes Feb 5, 2020
cbd2eac
hook snippet doc
Yoann-Abbes Feb 5, 2020
6aba5d4
getAllStats snipper hook
Yoann-Abbes Feb 5, 2020
22ab7a5
adapt doc snippets getAllStats and getLastStats
Yoann-Abbes Feb 5, 2020
f1238dc
test
Yoann-Abbes Feb 7, 2020
20d686c
fix document search GET behavior
Yoann-Abbes Feb 7, 2020
391c5c1
revert
Yoann-Abbes Feb 7, 2020
c6e1640
Merge branch '7-dev' into handle-double-routes
Yoann-Abbes Feb 13, 2020
7f5c5ef
Update doc/7/controllers/security/m-get-users/index.md
Yoann-Abbes Feb 13, 2020
08fdc81
Update doc/7/controllers/security/m-get-users/index.md
Yoann-Abbes Feb 13, 2020
c84e46c
@scottinet requested changes
Yoann-Abbes Feb 13, 2020
e6c8f01
revert search chabges
Yoann-Abbes Feb 13, 2020
ada96e4
doc
Yoann-Abbes Feb 13, 2020
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
7 changes: 7 additions & 0 deletions doc/7/controllers/document/m-get/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Gets multiple documents.
mGet(index, collection, ids, [options]);
```


| Argument | Type | Description |
| ------------ | --------------- | --------------- |
| `index` | <pre>string</pre> | Index name |
Expand All @@ -29,6 +30,12 @@ Additional query options
| Options | Type<br/>(default) | Description |
| ---------- | ---------------------- | ---------------------------------------------------------------------------- |
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `verb` | <pre>string</pre> | (HTTP only) Forces the verb of the route |

#### verb

When instantiated with a HTTP protocol object, the SDK uses the GET API by default for this API route.
You can set the `verb` option to `POST` to force the SDK to use the POST API instead.

## Resolves

Expand Down
43 changes: 43 additions & 0 deletions doc/7/controllers/security/m-get-users/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
code: true
type: page
title: mGetUsers
description: Gets multiple security users
---

# mGetUsers

Gets multiple security users.

<br />

```js
mGetUsers(kuids, [options]);
```

<br />

| Property | Type | Description |
|--- |--- |--- |
| `ids` | <pre>string[]</pre> | User identifiers |
| `options` | <pre>object</pre> | Query options |

### options

| Property | Type | Description |
| --- | --- | --- |
| `queuable` | <pre>boolean</pre> | If true, queues the request during downtime, until connected to Kuzzle again |
| `verb` | <pre>string</pre> | (HTTP only) Forces the verb of the API route |

#### verb

When instantiated with a HTTP protocol object, the SDK uses the GET API by default for this API route.
You can set the `verb` option to `POST` to force the SDK to use the POST API instead.

## Resolves

An array of retrieved [`User`](/sdk/js/7/core-classes/user/introduction) objects.

## Usage

<<< ./snippets/m-get-users.js
22 changes: 22 additions & 0 deletions doc/7/controllers/security/m-get-users/snippets/m-get-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
try {
const response = await kuzzle.security.mGetUsers([
'user1',
'user2',
'user3'
]);

console.log(response);
/*
[ User {
_id: 'user1',
profileIds: ['profile1'],
User {
_id: 'user2',
profileIds: ['profile2'],
User {
_id: 'user3',
profileIds: ['profile3'] ]
*/
} catch (e) {
console.error(e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: security#mGetUsers
description: mget users
hooks:
before: |
for i in 1 2 3; do
curl -H "Content-type: application/json" -d '{
"content": {
"profileIds": ["default"],
"fullname": "user'${i}'"
},
"credentials": {
"local": {
"username": "user'${i}'",
"password": "bar"
}
}
}' kuzzle:7512/users/user${i}/_create
done
after: |
for i in 1 2 3; do
curl -XDELETE kuzzle:7512/users/user${i}
done
template: default
expected: '^ _id: ''user3'',$'
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ hooks:
before:
after:
template: default
expected: ongoingRequests
expected: ongoingRequests
2 changes: 1 addition & 1 deletion src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class Kuzzle extends KuzzleEventEmitter {
Discarded request: ${JSON.stringify(request)}`));
}

return this.protocol.query(request);
return this.protocol.query(request, options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class AuthController extends BaseController {
action: 'login'
};

return this.query(request, {queuable: false})
return this.query(request, {queuable: false, verb: 'POST'})
.then(response => {
try {
this._authenticationToken = new Jwt(response.result.jwt);
Expand Down
7 changes: 6 additions & 1 deletion src/controllers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ class DocumentController extends BaseController {
const request = {
index,
collection,
body: {ids},
action: 'mGet'
};

if (options.verb === 'POST') {
request.body = {ids};
}
else {
request.ids = ids.join();
}
return this.query(request, options)
.then(response => response.result);
}
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,22 @@ class SecurityController extends BaseController {
.then(response => response.result.hits.map(hit => new Profile(this.kuzzle, hit._id , hit._source.policies)));
}

mGetUsers (ids, options = {}) {
const request = {
action: 'mGetUsers'
};

if (options.verb === 'POST') {
request.body = { ids };
}
else {
request.ids = ids.join();
}

return this.query(request, options)
.then(response => response.result.hits.map(hit => new User(this.kuzzle, hit._id, hit._source)));
}

mGetRoles (ids, options = {}) {
return this.query({
action: 'mGetRoles',
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/abstract/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AbstractWrapper extends KuzzleEventEmitter {
this.clear();
}

query (request) {
query (request, options) {
if (!this.isReady()) {
this.emit('discarded', request);
return Promise.reject(new Error(`Unable to execute request: not connected to a Kuzzle server.
Expand Down Expand Up @@ -109,7 +109,7 @@ Discarded request: ${JSON.stringify(request)}`));
pending.resolve(response);
});

this.send(request);
this.send(request, options);

return pending.promise;
}
Expand Down
18 changes: 7 additions & 11 deletions src/protocols/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class HttpWrapper extends KuzzleAbstractProtocol {
* @param {Object} data
* @returns {Promise<any>}
*/
send (data) {
send (data, options = {}) {
const
payload = {
action: undefined,
Expand Down Expand Up @@ -183,7 +183,7 @@ class HttpWrapper extends KuzzleAbstractProtocol {
}

const
method = route.verb,
method = options.verb || route.verb,
regex = /\/:([^/]*)/;

let
Expand Down Expand Up @@ -331,7 +331,7 @@ class HttpWrapper extends KuzzleAbstractProtocol {
function getCorrectRoute (routes) {
let
shortestRoute = routes[0],
postRoute,
getRoute,
minLength = routes[0].url.length,
sameLength = true;

Expand All @@ -345,19 +345,15 @@ function getCorrectRoute (routes) {
minLength = route.url.length;
}

if (route.verb === 'POST') {
postRoute = route;
if (route.verb === 'GET') {
getRoute = route;
}
}

if (sameLength) {
// with same URL size, we keep the POST route
return postRoute;
}

// with same URL size, we keep the GET route
// with differents URL sizes, we keep the shortest because URL params
// will be in the query string
return shortestRoute;
return sameLength ? getRoute : shortestRoute;
}

module.exports = HttpWrapper;
2 changes: 1 addition & 1 deletion test/controllers/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe('Auth Controller', () => {
strategy: 'strategy',
expiresIn: 'expiresIn',
body: credentials
}, {queuable: false});
}, {queuable: false, verb: 'POST'});

should(res).be.equal(jwt);
});
Expand Down
36 changes: 27 additions & 9 deletions test/controllers/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,16 @@ describe('Document Controller', () => {
});

describe('mGet', () => {
it('should call document/mGet query and return a Promise which resolves the list of documents', () => {
const result = {
hits: [
{_id: 'document1', _version: 1, _source: {foo: 'bar'}},
{_id: 'document2', _version: 3, _source: {foo: 'baz'}}
],
total: 2
};
const result = {
hits: [
{ _id: 'document1', _version: 1, _source: { foo: 'bar' } },
{ _id: 'document2', _version: 3, _source: { foo: 'baz' } }
],
total: 2
};
it('should call document/mGet POST query and return a Promise which resolves the list of documents', () => {
kuzzle.query.resolves({result});

options.verb = 'POST';
return kuzzle.document.mGet('index', 'collection', ['document1', 'document2'], options)
.then(res => {
should(kuzzle.query)
Expand All @@ -274,6 +274,24 @@ describe('Document Controller', () => {
should(res).be.equal(result);
});
});
it('should call document/mGet GET query and return a Promise which resolves the list of documents', () => {
kuzzle.query.resolves({ result });
options.verb = undefined;
return kuzzle.document.mGet('index', 'collection', ['document1', 'document2'], options)
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
controller: 'document',
action: 'mGet',
index: 'index',
collection: 'collection',
ids: 'document1,document2'
}, options);

should(res).be.equal(result);
});
});
});

describe('mReplace', () => {
Expand Down
15 changes: 13 additions & 2 deletions test/protocol/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,12 @@ describe('HTTP networking module', () => {
{ verb: 'POST', url: '/:index/:collection/:_id/_create' }
]
},
mGet: {
http: [
{ verb: 'GET', url: '/:index/:collection/_mGet' },
{ verb: 'POST', url: '/:index/:collection/_mGet' }
]
},
subscribe: {},
list: {
http: [ { verb: 'GET', url: '/:index/_list' } ]
Expand All @@ -722,9 +728,14 @@ describe('HTTP networking module', () => {
should(routes.foo.list.url).be.eql('/:index/_list');
should(routes.foo.list.verb).be.eql('GET');

// with same URL size, we keep the POST route
// with same URL size, we keep the GET route
should(routes.foo.login.url).be.eql('/_login/:strategy');
should(routes.foo.login.verb).be.eql('POST');
should(routes.foo.login.verb).be.eql('GET');

// with same URL size, we keep the GET route
should(routes.foo.mGet.url).be.eql('/:index/:collection/_mGet');
should(routes.foo.mGet.verb).be.eql('GET');


// with differents URL sizes, we keep the shortest because URL params
// will be in the query string
Expand Down