- 
                Notifications
    You must be signed in to change notification settings 
- Fork 17
[KZL-1098] proxify kuzzle to avoid mistyping error #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good one.
A remark though: the documentation you put in your PR description is very nice, but it should also be in a comment of the proxify file
        
          
                src/proxify.js
              
                Outdated
          
        
      | ...options | ||
| }); | ||
|  | ||
| const getPropertyNames = (obj) => { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nitpicking) coding-style consistency
| const getPropertyNames = (obj) => { | |
| const getPropertyNames = obj => { | 
        
          
                src/proxify.js
              
                Outdated
          
        
      | throw new Error(`${options.name}.${name} is not defined`); | ||
| } | ||
| if (options.deprecated.includes(name)) { | ||
| console.warn(`Warning: ${options.name}.${name} is deprecated`); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you must add some kind of flag to trigger that warning only once per deprecated property accessed, otherwise this can clog the console up pretty quickly
        
          
                src/proxify.js
              
                Outdated
          
        
      |  | ||
| const handler = { | ||
| get: (target, name) => { | ||
| if (options.sealGet && typeof name === 'string' && !properties.includes(name)) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should remove the typecheck made on name:
- it can only be a string or a symbol anyway, since this is a getter trap
- if I pass a non-existing symbol to your handler, I won't get any error even with sealGetactive, which does not seem to be the intended behavior
        
          
                src/proxify.js
              
                Outdated
          
        
      | throw new Error(`setting a not defined '${name}' properties in '${options.name}' object`) | ||
| } | ||
| if (options.deprecated.includes(name)) { | ||
| console.warn(`Warning: ${options.name}.${name} is deprecated`); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
…ascript into KZL-1098-proxify-kuzzle
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
| Codecov Report
 @@            Coverage Diff             @@
##            6-dev     #395      +/-   ##
==========================================
- Coverage   96.46%   96.44%   -0.03%     
==========================================
  Files          30       31       +1     
  Lines        1442     1489      +47     
==========================================
+ Hits         1391     1436      +45     
- Misses         51       53       +2
 Continue to review full report at Codecov. 
 | 
        
          
                src/proxify.js
              
                Outdated
          
        
      | const options = getOptions(opts); | ||
| const properties = ['inspect']; | ||
|  | ||
| const warnedDepreciation = new Set(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
        
          
                src/proxify.js
              
                Outdated
          
        
      | } | ||
|  | ||
| const options = getOptions(opts); | ||
| const properties = ['inspect']; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a Set too
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
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)
    
What does this PR do?
proxifyhelperCreate a helper that can throw error when get/set undeclared properties.
Some configuration:
name: the name of the proxified object for warningsseal: doesproxifythrow error on set undeclared properties?sealGet: doesproxifythrow error on get undeclared properties? this options is separated fromsealbecause getting undefined properties can be usefull for type checking for exampledeprecated: array of property names which produce a deprecate warning on get/setwarnDepreciationOnce: only warn once per deprecated propertyexposeApi: expose an api in the object to manipulate properties (described below)apiNamespace: in which namespace api is exposedproxyfy API
usage on kuzzle instance
kuzzle instance use
proxifylike this in the constructor:How should this be manually tested?
Kuzzleclassfoo