Skip to content

Conversation

Aschen
Copy link
Contributor

@Aschen Aschen commented Apr 23, 2019

What does this PR do?

I'm not sure if this is a new feature or an enhancement

This PR intend to unify the way we add/use controllers with the SDK. In this way we can have the same API when using our core controllers (document, collection, etc.) and custom controllers made by users.

All existing controllers are now inheriting from the BaseController class and they are added to the SDK with Kuzzle.useController instead of been manually instantiated.

Example of custom controller

class TaxiController extends BaseController {
  constructor (kuzzle) {
    super(kuzzle, 'my-plugin/taxi');
  }

  startDuty (driver) {
    return this.query({ driver, action: 'startDuty' });
  }
}

kuzzle.useController(TaxiController, 'taxi');

kuzzle.taxi.startDuty('Martin');

I know this look like a breaking change but since we never documented this feature by now it is not really one.

Documentation kuzzleio/documentation#284

How should this be manually tested?

  • Step 1 : Run unit tests

@codecov-io
Copy link

codecov-io commented Apr 23, 2019

Codecov Report

Merging #388 into 6-dev will increase coverage by <.01%.
The diff coverage is 99.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##            6-dev     #388      +/-   ##
==========================================
+ Coverage   96.65%   96.65%   +<.01%     
==========================================
  Files          30       30              
  Lines        1435     1437       +2     
==========================================
+ Hits         1387     1389       +2     
  Misses         48       48
Impacted Files Coverage Δ
src/controllers/index.js 97.29% <100%> (ø) ⬆️
src/controllers/bulk.js 100% <100%> (ø) ⬆️
src/Kuzzle.js 95.45% <100%> (+0.04%) ⬆️
src/controllers/server.js 100% <100%> (ø) ⬆️
src/controllers/collection.js 94.8% <100%> (ø) ⬆️
src/controllers/realtime/index.js 100% <100%> (ø) ⬆️
src/controllers/memoryStorage.js 96.25% <100%> (ø) ⬆️
src/controllers/base.js 100% <100%> (ø) ⬆️
src/controllers/auth.js 93.02% <100%> (ø) ⬆️
src/controllers/security/index.js 99.58% <100%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9aba3cc...f5eb3cd. Read the comment docs.

Copy link
Contributor

@scottinet scottinet left a comment

Choose a reason for hiding this comment

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

I like the idea (and this looks more like an enhancement than a new feature to me), but I disagree with the actions exposure being implicit.

I would prefer that you add an init function (possibly returning a promise?) that explicitly declares what actions can be performed for that registering controller.
Or any other method of your choice, as long as it's explicit. :)

@Aschen
Copy link
Contributor Author

Aschen commented Apr 25, 2019

@scottinet I didn't understand what you mean by explicitly declare what actions can be performed for that registering controller. Since the controller is a class, is not the SDK responsibility to allow or disallow method calling. If we weren't in JS, we would have the private keyword but..

I could wrap the controller class with a Proxy or something but I didn't really see the point here.

@scottinet
Copy link
Contributor

scottinet commented Apr 25, 2019

@Aschen > You have a point.
Just to explain myself: we had to make actions exposure explicit in Kuzzle's controllers to prevent internal methods from being leaked to the API. And I erroneously thought that we had possibly the same problem here, while it's obvious that the context is different.

@scottinet scottinet merged commit f1a8140 into 6-dev Apr 25, 2019
@scottinet scottinet deleted the change-use-controller-api branch April 25, 2019 07:38
Aschen added a commit to kuzzleio/documentation that referenced this pull request Apr 26, 2019
Add a page about how to extend the JS SDK with custom controllers.  
https://deploy-preview-284--kuzzle-doc-v2.netlify.com/sdk-reference/js/6/extend-sdk/

Also document:
 - BaseController class
 - Kuzzle.useController method

See kuzzleio/sdk-javascript#388
This was referenced Apr 29, 2019
Aschen pushed a commit that referenced this pull request Apr 29, 2019
# [6.1.1](https://github.com/kuzzleio/sdk-javascript/releases/tag/6.1.1) (2019-04-29)


#### Bug fixes

- [ [#384](#384) ] [fix] search API: "sort" and "search_after" must be in the requests body   ([scottinet](https://github.com/scottinet))

#### Enhancements

- [ [#388](#388) ] Use BaseController class for controllers   ([Aschen](https://github.com/Aschen))
- [ [#385](#385) ] Add Realtime.createRestrictedUser method   ([Aschen](https://github.com/Aschen))

#### Others

- [ [#387](#387) ] SearchResult.next returns a new instance   ([Aschen](https://github.com/Aschen))
---
alexandrebouthinon pushed a commit to kuzzleio/documentation that referenced this pull request Apr 29, 2019
* Add documentation page about mappings (#271)

Adds a documentation essentials page about mappings:

dynamic mapping policy
collection metadata
properties types definitions
Also update SDKs

See kuzzleio/kuzzle#1257

* Embedded protocols (#286)

Documentation for embedded protocols, notably for MQTT.

* Extending the JS SDK with controllers (#284)

Add a page about how to extend the JS SDK with custom controllers.  
https://deploy-preview-284--kuzzle-doc-v2.netlify.com/sdk-reference/js/6/extend-sdk/

Also document:
 - BaseController class
 - Kuzzle.useController method

See kuzzleio/sdk-javascript#388

* [KZL-907] Getting started dev plugin (#276)

## What does this PR do?

This PR responds to this [ticket](https://jira.kaliop.net/browse/KZL-907).
Also, it increases the readability of documentation's plugin part.

### How should this be manually tested?

[Netify](https://deploy-preview-276--kuzzle-doc-v2.netlify.com/plugins/1/essentials/introduction/)

### Other changes

- Re-arrange plugin documentation path
- Update dead link in boilerplate repository

### Boyscout

Prettier

* Release 2.1.1
@Aschen Aschen mentioned this pull request Jun 14, 2019
Aschen added a commit that referenced this pull request Jun 14, 2019
Release 6.1.2

Bug fixes

    [ #398 ] Fix bulk return (Aschen)
    [ #394 ] Add default values for from/size to document:search (Aschen)
    [ #384 ] Fix search API: "sort" and "search_after" must be in the requests body (scottinet)

Enhancements

    [ #390 ] Add authenticated property on Kuzzle object (Aschen)
    [ #395 ] Proxify kuzzle to avoid mistyping error (thomasarbona)
    [ #389 ] Remove usage of _meta (Aschen)
    [ #391 ] Add isConnected (Aschen)
    [ #388 ] Use BaseController class for controllers (Aschen)
    [ #385 ] Add Security.createRestrictedUser method (Aschen)

Others

    [ #400 ] Fix large document search using scroll (stafyniaksacha)
    [ #387 ] SearchResult.next returns a new instance (Aschen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants