Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ src/core/security/Role.js
src/utils/interfaces.js
src/core/searchResult/SearchResultBase.js
src/core/searchResult/Document.js
src/core/searchResult/Profile.js
src/core/searchResult/Role.js
src/core/searchResult/Specifications.js
src/core/searchResult/User.js
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ src/core/security/Role.js
src/utils/interfaces.js
src/core/searchResult/SearchResultBase.js
src/core/searchResult/Document.js
src/core/searchResult/Profile.js
src/core/searchResult/Role.js
src/core/searchResult/Specifications.js
src/core/searchResult/User.js
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SearchResultBase } from './src/core/searchResult/SearchResultBase';
import { DocumentSearchResult } from './src/core/searchResult/Document';
import { ProfileSearchResult } from './src/core/searchResult/Profile';
import { RoleSearchResult } from './src/core/searchResult/Role';
import { SpecificationSearchResult } from './src/core/searchResult/Specifications';
import { SpecificationsSearchResult } from './src/core/searchResult/Specifications';
import { UserSearchResult } from './src/core/searchResult/User';

const exported = {
Expand All @@ -32,7 +32,7 @@ const exported = {
DocumentSearchResult,
ProfileSearchResult,
RoleSearchResult,
SpecificationSearchResult,
SpecificationsSearchResult,
UserSearchResult
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export class AuthController extends BaseController {
*/
_id: string;
/**
* Expiration date in UNIX micro-timestamp format (-1 if the token never expires)
* Expiration date in Epoch-millis format (-1 if the token never expires)
*/
expiresAt: number;
/**
Expand Down
29 changes: 0 additions & 29 deletions src/core/searchResult/Profile.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/core/searchResult/Profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Profile } from '../security/Profile';
import { SearchResultBase } from './SearchResultBase';

export class ProfileSearchResult extends SearchResultBase<Profile> {
constructor (kuzzle, request, options, response) {
super(kuzzle, request, options, response);

this._searchAction = 'searchProfiles';
this._scrollAction = 'scrollProfiles';
this.hits = response.hits.map(hit => (
new Profile(this._kuzzle, hit._id, hit._source)
));
}

next () {
return super.next()
.then((nextSearchResult: ProfileSearchResult) => {
if (! nextSearchResult) {
return null;
}

nextSearchResult.hits = nextSearchResult._response.hits.map(hit => (
new Profile(nextSearchResult._kuzzle, hit._id, hit._source)
));

return nextSearchResult;
});
}
}
18 changes: 10 additions & 8 deletions src/core/searchResult/Role.js → src/core/searchResult/Role.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const { Role } = require('../security/Role');
const { SearchResultBase } = require('./SearchResultBase');
import { Role } from '../security/Role';
import { SearchResultBase } from './SearchResultBase';

class RoleSearchResult extends SearchResultBase {
export class RoleSearchResult extends SearchResultBase<Role> {

constructor (kuzzle, query, options, response) {
super(kuzzle, query, options, response);

this._searchAction = 'searchRoles';
this._scrollAction = null; // scrollRoles action does not exists in Kuzzle API.

this.hits = this._response.hits.map(hit => new Role(this._kuzzle, hit._id, hit._source.controllers));
this.hits = this._response.hits.map(hit => (
new Role(this._kuzzle, hit._id, hit._source.controllers)
));
}

next () {
Expand All @@ -20,16 +22,16 @@ class RoleSearchResult extends SearchResultBase {
}

return super.next()
.then(nextSearchResult => {
.then((nextSearchResult: RoleSearchResult) => {
if (! nextSearchResult) {
return null;
}

nextSearchResult.hits = nextSearchResult._response.hits.map(hit => new Role(nextSearchResult._kuzzle, hit._id, hit._source.controllers));
nextSearchResult.hits = nextSearchResult._response.hits.map(hit => (
new Role(nextSearchResult._kuzzle, hit._id, hit._source.controllers)
));

return nextSearchResult;
});
}
}

module.exports = { RoleSearchResult };
30 changes: 15 additions & 15 deletions src/core/searchResult/SearchResultBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,10 @@ export class SearchResultBase<T> implements SearchResult<T> {

public fetched: number;

/**
*
* @param {Kuzzle} kuzzle
* @param {object} request
* @param {object} options
* @param {object} response
*/
constructor (
kuzzle: Kuzzle,
request: KuzzleRequest = {},
options: any = {},
options: JSONObject = {},
response: any = {}
) {
Reflect.defineProperty(this, '_kuzzle', {
Expand All @@ -80,10 +73,18 @@ export class SearchResultBase<T> implements SearchResult<T> {
Reflect.defineProperty(this, '_response', {
value: response
});

this._controller = request.controller;
this._searchAction = 'search';
this._scrollAction = 'scroll';
Reflect.defineProperty(this, '_controller', {
value: request.controller,
writable: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these writable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in the SpecificationSearchResult class we overload the controller with collection

});
Reflect.defineProperty(this, '_searchAction', {
value: 'search',
writable: true
});
Reflect.defineProperty(this, '_scrollAction', {
value: 'scroll',
writable: true
});

this.aggregations = response.aggregations;
this.hits = response.hits || [];
Expand Down Expand Up @@ -166,7 +167,7 @@ export class SearchResultBase<T> implements SearchResult<T> {
return Promise.reject(new Error('Unable to retrieve next results from search: missing scrollId, from/sort, or from/size params'));
}

_get (object, path) {
protected _get (object, path) {
if (!object) {
return object;
}
Expand All @@ -179,15 +180,14 @@ export class SearchResultBase<T> implements SearchResult<T> {
return this._get(object[key], path);
}

_buildNextSearchResult (response) {
protected _buildNextSearchResult (response) {
const Constructor: any = this.constructor;

const nextSearchResult = new Constructor(this._kuzzle, this._request, this._options, response.result);
nextSearchResult.fetched += this.fetched;

return nextSearchResult;
}

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { SearchResultBase } = require('./SearchResultBase');
import { SearchResultBase } from './SearchResultBase';
import { JSONObject } from '../../utils/interfaces';

class SpecificationsSearchResult extends SearchResultBase {
export class SpecificationsSearchResult extends SearchResultBase<JSONObject> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know I should have created a proper Specification interface but I'm lazy to do it since I doubt someone is using this and we need a refactor of this module.
The JSONObject type works like a POJO


constructor (kuzzle, query, options, response) {
super(kuzzle, query, options, response);
Expand All @@ -10,5 +11,3 @@ class SpecificationsSearchResult extends SearchResultBase {
this._scrollAction = 'scrollSpecifications';
}
}

module.exports = { SpecificationsSearchResult };
27 changes: 0 additions & 27 deletions src/core/searchResult/User.js

This file was deleted.

30 changes: 30 additions & 0 deletions src/core/searchResult/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { SearchResultBase } from './SearchResultBase';
import { User } from '../security/User';

export class UserSearchResult extends SearchResultBase<User> {

constructor (kuzzle, query, options, response) {
super(kuzzle, query, options, response);

this._searchAction = 'searchUsers';
this._scrollAction = 'scrollUsers';
this.hits = this._response.hits.map(hit => (
new User(this._kuzzle, hit._id, hit._source)
));
}

next () {
return super.next()
.then((nextSearchResult: UserSearchResult) => {
if (! nextSearchResult) {
return null;
}

nextSearchResult.hits = nextSearchResult._response.hits.map(hit => (
new User(nextSearchResult._kuzzle, hit._id, hit._source)
));

return nextSearchResult;
});
}
}
3 changes: 0 additions & 3 deletions src/core/security/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,3 @@ export class Profile {
options);
}
}

module.exports = { Profile };

14 changes: 13 additions & 1 deletion src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface KuzzleRequest extends JSONObject {
jwt?: string;
volatile?: JSONObject;
body?: JSONObject;
[key: string]: any;
}

/**
Expand Down Expand Up @@ -88,8 +89,14 @@ export interface ProfilePolicy {
* @see https://docs.kuzzle.io/core/2/guides/essentials/security#defining-roles
*/
export interface RoleRightsDefinition {
/**
* API controller name
*/
[key: string]: {
actions: {
/**
* API action name
*/
[key: string]: boolean
}
}
Expand All @@ -112,7 +119,7 @@ export interface ApiKey {
*/
userId: string;
/**
* Expiration date in UNIX micro-timestamp format (-1 if the token never expires)
* Expiration date in Epoch-millis format (-1 if the token never expires)
*/
expiresAt: number;
/**
Expand Down Expand Up @@ -178,6 +185,11 @@ export interface Document {

/**
* Document retrieved from a search
*
* @property _id
* @property _version
* @property _source
* @property _score
*/
export interface DocumentHit extends Document {
/**
Expand Down