@probitas/client
Core utilities and types for Probitas client libraries.
This package provides shared types, error classes, and utilities used across all `@probitas/*` client packages.
Features
- Common Options: Shared configuration types like
CommonOptionsandRetryOptions - Error Hierarchy: Base error classes (
ClientError,ConnectionError,TimeoutError,AbortError)
Installation
deno add jsr:@probitas/client
Usage
This package is typically used as a dependency by other client packages. End users rarely need to import from it directly.
import type { CommonOptions, RetryOptions } from "@probitas/client";
import { ClientError, ConnectionError, TimeoutError } from "@probitas/client";
// Use CommonOptions for timeout and abort signal support
async function fetchData(options?: CommonOptions) {
// Implementation with timeout and signal handling
}
// Catch and handle errors
try {
await fetchData({ timeout: 5000 });
} catch (error) {
if (error instanceof TimeoutError) {
console.log(`Timed out after ${error.timeoutMs}ms`);
} else if (error instanceof ConnectionError) {
console.log("Failed to connect");
}
}
Related Packages
| Package | Description |
|---|---|
| `@probitas/client-http` | HTTP client |
| `@probitas/client-graphql` | GraphQL client |
| `@probitas/client-grpc` | gRPC client |
| `@probitas/client-connectrpc` | ConnectRPC client |
| `@probitas/client-sql-postgres` | PostgreSQL client |
| `@probitas/client-sql-mysql` | MySQL client |
| `@probitas/client-sql-sqlite` | SQLite client |
| `@probitas/client-sql-duckdb` | DuckDB client |
| `@probitas/client-deno-kv` | Deno KV client |
| `@probitas/client-redis` | Redis client |
| `@probitas/client-mongodb` | MongoDB client |
| `@probitas/client-rabbitmq` | RabbitMQ client |
| `@probitas/client-sqs` | AWS SQS client |
Links
Installation
deno add jsr:@probitas/clientClasses
#AbortError
class AbortError extends ClientErrorClientErrorError thrown when an operation is aborted via AbortSignal.
Constructor
new AbortError(message: string, options?: ErrorOptions)Properties
- readonly
namestring - readonly
kind"abort"
#ClientError
class ClientError extends ErrorErrorBase error class for all client errors.
The kind property is typed as string to allow client-specific packages
to define their own error kinds without modifying this core package.
Subclasses can narrow the type using literal types with as const.
Constructor
new ClientError(message: string, _: unknown, options?: ErrorOptions)Properties
- readonly
namestring - readonly
kindstring
#ConnectionError
class ConnectionError extends ClientErrorClientErrorError thrown when a connection cannot be established.
Constructor
new ConnectionError(message: string, options?: ErrorOptions)Properties
- readonly
namestring - readonly
kind"connection"
#TimeoutError
class TimeoutError extends ClientErrorClientErrorError thrown when an operation times out.
Constructor
new TimeoutError(message: string, timeoutMs: number, options?: ErrorOptions)Properties
- readonly
namestring - readonly
kind"timeout" - readonly
timeoutMsnumber
Interfaces
#ClientResult
interface ClientResultBase interface for all client result types.
All client operation results (responses, query results, etc.) extend this interface,
providing a consistent structure across all Probitas clients. The kind property
serves as a discriminator for type-safe switch statements.
This mirrors the design of ClientError where kind is used instead of type
for consistency across the framework.
Examples
import type { ClientResult } from "@probitas/client";
interface HttpResponse extends ClientResult {
readonly kind: "http";
readonly status: number;
}
interface SqlQueryResult extends ClientResult {
readonly kind: "sql";
readonly rowCount: number;
}
type MyResult = HttpResponse | SqlQueryResult;
function handleResult(result: MyResult) {
// Check if request reached the server
if (!result.processed) {
console.error("Network failure:", result.error);
return;
}
// Check if operation succeeded
if (!result.ok) {
console.error("Operation failed:", result.error);
return;
}
// Type narrowing by kind
switch (result.kind) {
case "http":
console.log(`HTTP ${result.status} in ${result.duration}ms`);
break;
case "sql":
console.log(`${result.rowCount} rows in ${result.duration}ms`);
break;
}
}
| Name | Description |
|---|---|
kind | Result kind discriminator. |
processed | Whether the operation was processed by the server. |
ok | Whether the operation succeeded. |
error | Error that occurred during the operation (null if successful). |
duration | Operation duration in milliseconds. |
Properties
- readonly
kindstringResult kind discriminator.
The
kindproperty is typed asstringto allow client-specific packages to define their own result kinds without modifying this core package. Subinterfaces can narrow the type using literal types withas const. - readonly
processedbooleanWhether the operation was processed by the server.
true: Server received and processed the request (success or error response)false: Request failed before reaching the server (network error, timeout, etc.)
Use this to distinguish between "server returned an error" and "couldn't reach server".
- readonly
okbooleanWhether the operation succeeded.
For HTTP responses, this corresponds to status 200-299. For database operations, this indicates successful execution. Always
falsewhenprocessedisfalse. - readonly
errorError | nullError that occurred during the operation (null if successful).
Contains the error when
okisfalse. The specific error type depends on the client kind (e.g., HttpError, GraphqlError, SqlError). - readonly
durationnumberOperation duration in milliseconds.
Measured from operation start to completion, useful for performance analysis and timeout monitoring.
#CommonConnectionConfig
interface CommonConnectionConfigCommon connection configuration shared across all network clients.
This interface provides a unified way to configure connection parameters for all network-based clients. Each client extends this with service-specific options while maintaining a consistent base.
Examples
Use with string URL
import { createHttpClient } from "@probitas/client-http";
const client = createHttpClient({ url: "http://localhost:3000" });
await client[Symbol.asyncDispose]();
Use with config object
import { createHttpClient } from "@probitas/client-http";
const client = createHttpClient({
url: {
host: "api.example.com",
port: 443,
username: "user",
password: "secret",
},
});
await client[Symbol.asyncDispose]();
| Name | Description |
|---|---|
host | Hostname or IP address. |
port | Port number. |
username | Username for authentication. |
password | Password for authentication. |
Properties
- readonly
host?stringHostname or IP address.
- readonly
port?numberPort number. Each service has its own default.
- readonly
username?stringUsername for authentication.
- readonly
password?stringPassword for authentication.
#CommonOptions
interface CommonOptionsCommon options shared across all clients.
| Name | Description |
|---|---|
timeout | Timeout in milliseconds. |
signal | AbortSignal for cancellation. |
retry | Retry configuration. |
Properties
- readonly
timeout?numberTimeout in milliseconds.
- readonly
signal?AbortSignalAbortSignal for cancellation.
Retry configuration.
#RetryOptions
interface RetryOptionsRetry configuration options.
| Name | Description |
|---|---|
maxAttempts | Maximum number of attempts (1 = no retry). |
backoff | Backoff strategy. |
initialDelay | Initial delay in milliseconds. |
maxDelay | Maximum delay in milliseconds. |
retryOn | Function to determine if the error should trigger a retry. |
Properties
- readonly
maxAttempts?numberMaximum number of attempts (1 = no retry).
- readonly
backoff?"linear" | "exponential"Backoff strategy.
- readonly
initialDelay?numberInitial delay in milliseconds.
- readonly
maxDelay?numberMaximum delay in milliseconds.
- readonly
retryOn?(error: Error) => unknownFunction to determine if the error should trigger a retry.
