-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add typescript to elasticsearch service #2473
Conversation
lib/types/storage/Elasticsearch.ts
Outdated
}; | ||
|
||
export interface JSONObject { | ||
[key: string]: JSONObject | any; |
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.
This union are always resolved to any
because, any include JSONObject.
Also why not use JSONObject
type from kuzzle-sdk
package ?
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.
I found it weird that kuzzle use types from it's sdk, it should be the other way around
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.
Yes, maybe we should merge SDK JS in this repo to facilitate evolutions or generate a types package from the core and use it in SDK to avoid duplicated types in both packages
lib/service/storage/elasticsearch.ts
Outdated
}: { | ||
refresh?: string; | ||
timeout?: number; | ||
userId?: string; | ||
injectKuzzleMeta?: boolean; | ||
limits?: boolean; | ||
source?: boolean; |
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.
Maybe define an interface with the requests options in lib/types/storage/ElasticSearch.ts
and import it to use in methods parameters, it's more clear and lighter to read.
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 are right
package.json
Outdated
@@ -37,7 +37,7 @@ | |||
"test:lint:ts": "eslint --max-warnings=0 ./lib --ext .ts --config .eslintc-ts.json", | |||
"test:lint": "npm run test:lint:js && npm run test:lint:ts", | |||
"test:unit:coverage": "DEBUG= nyc --reporter=text-summary --reporter=lcov mocha --exit", | |||
"test:unit": "DEBUG= npx --node-arg=--trace-warnings mocha --exit", | |||
"test:unit": "DEBUG= npx mocha --exit", |
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.
Normally npx
are useless in npm scripts
Kudos, SonarCloud Quality Gate passed!
|
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.
It seems your local Prettier/ESLint vscode configuration broke the code formatting on the functional tests
test/mocks/elasticsearch.mock.js
Outdated
|
||
class ElasticsearchMock extends Elasticsearch { | ||
class ElasticsearchMock extends ElasticSearch { |
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.
I don't know if it's a good idea to update the Elasticsearch class name spelling
Kudos, SonarCloud Quality Gate passed!
|
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.
Globaly can improve types, also why alternatively use JSONObject
and Record<string, any>
it's practically identical in result.
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.
Nit: Maybe your editor have bad configuration because final new line is generally required on projects
export interface JSONObject { | ||
[key: string]: any; | ||
} |
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.
Why recreate JSONObject type here, instead of use the interface provided by kuzzle-sdk
?
} | ||
|
||
let documents = hits.hits.map((h) => ({ _id: h._id, _source: h._source })); | ||
let documents = hits.hits.map((h: JSONObject) => ({ |
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.
let documents = hits.hits.map((h: JSONObject) => ({ | |
let documents = hits.hits.map((h: KDocument<KDocumentContentGeneric>) => ({ |
Why not use KDocument type instead of JSONObject ?
public _client: StorageClient; | ||
public _scope: scopeEnum; | ||
public _indexPrefix: string; | ||
public _esWrapper: ESWrapper; | ||
public _esVersion: any; | ||
public _translator: QueryTranslator; |
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.
Generally the properties prefixed by an underscore are in private or protected
export type KRequestParams = { | ||
refresh?: boolean | "wait_for"; | ||
timeout?: string; | ||
userId?: string; | ||
injectKuzzleMeta?: boolean; | ||
limits?: boolean; | ||
source?: boolean; | ||
}; |
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.
export type KRequestParams = { | |
refresh?: boolean | "wait_for"; | |
timeout?: string; | |
userId?: string; | |
injectKuzzleMeta?: boolean; | |
limits?: boolean; | |
source?: boolean; | |
}; | |
interface KRequestParams { | |
userId?: string; | |
refresh?: boolean | "wait_for"; | |
injectKuzzleMeta?: boolean; | |
retryOnConflict?: number; | |
timeout?: string; | |
} |
It's better to use this interface to easily compose the params types in methods
{ | ||
refresh, | ||
timeout, | ||
userId = null, | ||
injectKuzzleMeta = true, | ||
limits = true, | ||
source = true, | ||
} = {}, | ||
}: KRequestParams = {}, |
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.
}: KRequestParams = {}, | |
}: Exclude<KRequestParams, "retryOnConflict"> & { limits?: boolean; source?: boolean; } = {}, |
{ | ||
refresh = undefined, | ||
retryOnConflict = 0, | ||
timeout = undefined, | ||
userId = null, | ||
} = {}, |
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.
{ | |
refresh = undefined, | |
retryOnConflict = 0, | |
timeout = undefined, | |
userId = null, | |
} = {}, | |
{ | |
refresh = undefined, | |
retryOnConflict = 0, | |
timeout = undefined, | |
userId = null, | |
}: Exclude<KRequestParams, "injectKuzzleMeta"> = {}, |
{ | ||
refresh, | ||
retryOnConflict = 0, | ||
timeout, | ||
userId = null, | ||
}: { | ||
refresh?: boolean | "wait_for"; | ||
retryOnConflict?: number; | ||
timeout?: string; | ||
userId?: string; | ||
} = {}, |
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.
{ | |
refresh, | |
retryOnConflict = 0, | |
timeout, | |
userId = null, | |
}: { | |
refresh?: boolean | "wait_for"; | |
retryOnConflict?: number; | |
timeout?: string; | |
userId?: string; | |
} = {}, | |
{ | |
refresh, | |
retryOnConflict = 0, | |
timeout, | |
userId = null, | |
}: Exclude<KRequestParams, "injectKuzzleMeta"> = {}, |
With new KRequestParams
type we can compose type like it, to DRY
{ | ||
refresh, | ||
timeout, | ||
userId = null, | ||
}: { | ||
refresh?: boolean | "wait_for"; | ||
timeout?: string; | ||
userId?: string; | ||
} = {}, |
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.
{ | |
refresh, | |
timeout, | |
userId = null, | |
}: { | |
refresh?: boolean | "wait_for"; | |
timeout?: string; | |
userId?: string; | |
} = {}, | |
{ | |
refresh, | |
timeout, | |
userId = null, | |
}: Exclude<KRequestParams, "injectKuzzleMeta" | "retryOnConflict"> = {}, |
With new KRequestParams
type we can compose type like it, to DRY
{ | ||
refresh, | ||
}: { | ||
refresh?: boolean | "wait_for"; | ||
timeout?: number; | ||
} = {}, |
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.
{ | |
refresh, | |
}: { | |
refresh?: boolean | "wait_for"; | |
timeout?: number; | |
} = {}, | |
{ | |
refresh, | |
}: Pick<KRequestParams, "refresh" | "timeout"> = {}, |
With new KRequestParams
type we can compose type like it, to DRY
🎉 This PR is included in version 2.29.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 2.29.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What does this PR do ?