tigrisdata-archive / tigris-client-ts

TypeScript client for Tigris
https://www.tigrisdata.com/docs/sdkstools/typescript/
Apache License 2.0
15 stars 10 forks source link

feat: static type checking for query constructs #273

Closed adilansari closed 1 year ago

adilansari commented 1 year ago

Describe your changes

1. q in SearchQuery is optional ( closes #269 )

- const matchAll: SearchQuery<Student> = { q: "" };
+ const matchAll: SearchQuery<Student> = { };

2. Querying constructs are bound to schema fields ( closes #267 )

- searchFields?: Array<string>;
+ searchFields?: DocumentPaths<T>;

- includeFields?: Array<string>;
+ includeFields?: DocumentPaths<T>;

- excludeFields?: Array<string>;
+ excludeFields?: DocumentPaths<T>;

- export type FacetFieldOptions = {
-   [key: string]: FacetQueryOptions;
- };
+ export type FacetFieldOptions<T> = DocumentFields<T, FacetQueryOptions>;

- export type FacetFields = Array<string>;
+ export type FacetFields<T> = DocumentPaths<T>;

- export type ReadFields = {
-   include?: Array<string>;
-   exclude?: Array<string>;
-};
+ export type ReadFields<T> = {
+   include?: DocumentPaths<T>;
+   exclude?: DocumentPaths<T>;
+};

-export type SortField = {
-   field: string;
-   order: Order;
-};
+export type SortField<T> = {
+   field: Paths<T>;
+   order: "$asc" | "$desc";
+};

This enables autocompletion in IDE and enables static type checks at compile time. Introduces compile time checking for cases where a schema field is renamed.

How best to test these changes

Unit tests

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 98.85% and project coverage change: +0.34 :tada:

Comparison is base (3d27885) 89.50% compared to head (78db505) 89.85%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #273 +/- ## ========================================== + Coverage 89.50% 89.85% +0.34% ========================================== Files 29 29 Lines 5281 5146 -135 Branches 630 599 -31 ========================================== - Hits 4727 4624 -103 + Misses 553 521 -32 Partials 1 1 ``` | [Impacted Files](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata) | Coverage Δ | | |---|---|---| | [src/search/result.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL3NlYXJjaC9yZXN1bHQudHM=) | `99.44% <97.91%> (-0.56%)` | :arrow_down: | | [src/collection.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL2NvbGxlY3Rpb24udHM=) | `97.25% <100.00%> (ø)` | | | [src/error.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL2Vycm9yLnRz) | `75.72% <100.00%> (+3.34%)` | :arrow_up: | | [src/search/query.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL3NlYXJjaC9xdWVyeS50cw==) | `100.00% <100.00%> (ø)` | | | [src/search/search-index.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL3NlYXJjaC9zZWFyY2gtaW5kZXgudHM=) | `73.27% <100.00%> (+2.25%)` | :arrow_up: | | [src/search/types.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL3NlYXJjaC90eXBlcy50cw==) | `95.18% <100.00%> (+1.77%)` | :arrow_up: | | [src/types.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL3R5cGVzLnRz) | `90.71% <100.00%> (-0.08%)` | :arrow_down: | | [src/utility.ts](https://codecov.io/gh/tigrisdata/tigris-client-ts/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata#diff-c3JjL3V0aWxpdHkudHM=) | `96.77% <100.00%> (+2.00%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tigrisdata)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

ovaistariq commented 1 year ago

It is very cool to see this.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.0.0-beta.36 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

reviewpad[bot] commented 1 year ago

Reviewpad Report

:bangbang: Errors