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 types for Client.queryWithMetrics #628

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/types/Client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,24 @@ interface StreamApi
document: StreamFn<SubscriptionEventHandlers>
}

interface MetricsResponse<T = object> {
value: T
metrics: {
'x-compute-ops': number
'x-byte-read-ops': number
'x-byte-write-ops': number
'x-query-time': number
'x-txn-retries': number
}
}

export default class Client {
constructor(opts?: ClientConfig)
query<T = object>(expr: ExprArg, options?: QueryOptions): Promise<T>
query<T = object>(expr: ExprArg, options?: QueryOptions): Promise<T> | Promise<MetricsResponse<T>>
Copy link

@Akryum Akryum Mar 29, 2022

Choose a reason for hiding this comment

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

This is a breaking change for TypeScript projects :(

Copy link

Choose a reason for hiding this comment

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

Example:

image

error TS2322: Type 'boolean | MetricsResponse<boolean>' is not assignable to type 'boolean'.

queryWithMetrics<T = object>(
expr: ExprArg,
options?: QueryOptions
): Promise<MetricsResponse<T>>
paginate(expr: Expr, params?: object, options?: QueryOptions): PageHelper
ping(scope?: string, timeout?: number): Promise<string>
close(opts?: { force?: boolean }): Promise<void>
Expand Down