Skip to content
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

Merged
merged 35 commits into from Jan 8, 2024
Merged

Conversation

rolljee
Copy link
Contributor

@rolljee rolljee commented Sep 6, 2023

What does this PR do ?

  • Add Typescript support to Elasticsearch.js file

@kuzzle
Copy link
Contributor

kuzzle commented Sep 6, 2023

Executed Checks

✔️ Branch Merge Check

✔️ Changelog Tag Check

✔️ PR Body Check

Generated by 🚫 dangerJS against 733d3f9

};

export interface JSONObject {
[key: string]: JSONObject | any;
Copy link
Member

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 ?

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 found it weird that kuzzle use types from it's sdk, it should be the other way around

Copy link
Member

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

Comment on lines 2529 to 2535
}: {
refresh?: string;
timeout?: number;
userId?: string;
injectKuzzleMeta?: boolean;
limits?: boolean;
source?: boolean;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right

@rolljee rolljee marked this pull request as draft September 7, 2023 08:45
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",
Copy link
Member

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

@rolljee rolljee marked this pull request as ready for review September 25, 2023 09:12
@sonarcloud
Copy link

sonarcloud bot commented Oct 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@alexandrebouthinon alexandrebouthinon left a 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


class ElasticsearchMock extends Elasticsearch {
class ElasticsearchMock extends ElasticSearch {
Copy link
Member

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

@rolljee rolljee linked an issue Nov 23, 2023 that may be closed by this pull request
Copy link

sonarcloud bot commented Dec 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rolljee rolljee merged commit 6907e43 into 2-dev Jan 8, 2024
25 checks passed
@rolljee rolljee deleted the feat/elasticsearch-typescript branch January 8, 2024 13:33
Copy link
Member

@sebtiz13 sebtiz13 left a 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.

Copy link
Member

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

Comment on lines +21 to +23
export interface JSONObject {
[key: string]: any;
}
Copy link
Member

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) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let documents = hits.hits.map((h: JSONObject) => ({
let documents = hits.hits.map((h: KDocument<KDocumentContentGeneric>) => ({

Why not use KDocument type instead of JSONObject ?

Comment on lines +98 to +103
public _client: StorageClient;
public _scope: scopeEnum;
public _indexPrefix: string;
public _esWrapper: ESWrapper;
public _esVersion: any;
public _translator: QueryTranslator;
Copy link
Member

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

Comment on lines +35 to +42
export type KRequestParams = {
refresh?: boolean | "wait_for";
timeout?: string;
userId?: string;
injectKuzzleMeta?: boolean;
limits?: boolean;
source?: boolean;
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 = {},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}: KRequestParams = {},
}: Exclude<KRequestParams, "retryOnConflict"> & { limits?: boolean; source?: boolean; } = {},

Comment on lines +2566 to +2571
{
refresh = undefined,
retryOnConflict = 0,
timeout = undefined,
userId = null,
} = {},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{
refresh = undefined,
retryOnConflict = 0,
timeout = undefined,
userId = null,
} = {},
{
refresh = undefined,
retryOnConflict = 0,
timeout = undefined,
userId = null,
}: Exclude<KRequestParams, "injectKuzzleMeta"> = {},

Comment on lines +2662 to +2672
{
refresh,
retryOnConflict = 0,
timeout,
userId = null,
}: {
refresh?: boolean | "wait_for";
retryOnConflict?: number;
timeout?: string;
userId?: string;
} = {},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{
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

Comment on lines +2771 to +2779
{
refresh,
timeout,
userId = null,
}: {
refresh?: boolean | "wait_for";
timeout?: string;
userId?: string;
} = {},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{
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

Comment on lines +2864 to +2869
{
refresh,
}: {
refresh?: boolean | "wait_for";
timeout?: number;
} = {},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{
refresh,
}: {
refresh?: boolean | "wait_for";
timeout?: number;
} = {},
{
refresh,
}: Pick<KRequestParams, "refresh" | "timeout"> = {},

With new KRequestParams type we can compose type like it, to DRY

@kuzzle
Copy link
Contributor

kuzzle commented Jan 16, 2024

🎉 This PR is included in version 2.29.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kuzzle
Copy link
Contributor

kuzzle commented Feb 1, 2024

🎉 This PR is included in version 2.29.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kuzzle kuzzle added the released This issue/pull request has been released. label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:enhancements released on @beta released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Elasticsearch.js to Typescript to prepare futur work on ES8
6 participants