@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
#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
createHttpClient({ url: "http://localhost:3000" });
// Use with config object
createHttpClient({
url: {
host: "api.example.com",
port: 443,
username: "user",
password: "secret",
},
});
| 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.
