Skip to content
This repository was archived by the owner on Dec 27, 2025. It is now read-only.

BREAKING: Convert getter methods to properties for cleaner API#65

Merged
lambdalisue merged 1 commit intomainfrom
feat/flatten-getter
Dec 23, 2025
Merged

BREAKING: Convert getter methods to properties for cleaner API#65
lambdalisue merged 1 commit intomainfrom
feat/flatten-getter

Conversation

@lambdalisue
Copy link
Member

Summary

  • Convert HTTP response body accessors (text(), json(), arrayBuffer(), blob(), raw()) from methods to properties
  • Convert GraphQL response accessors (data(), raw()) from methods to properties
  • Convert ConnectRPC response accessors (data(), raw()) from methods to properties
  • Update all tests and documentation examples to use property syntax
  • Change json property to return unknown instead of generic type

Why

The method syntax response.json() was unnecessary for simple accessors that just return cached values. Converting to properties (response.json) provides:

  1. Cleaner API: Simpler syntax without parentheses for property access
  2. Consistency: Aligns with standard JavaScript/TypeScript patterns (e.g., arr.length not arr.length())
  3. Same behavior: Getters preserve lazy evaluation and caching semantics
  4. Type safety: The json property returning unknown forces explicit type assertions, improving type safety

This is a breaking change but improves the developer experience and code readability across all client packages.

Migration Guide

// Before
const user = response.json<User>();
const text = response.text();
const data = response.data<T>();

// After
const user = response.json as User | null;
const text = response.text;
const data = response.data as T | null;

Test Plan

  • All unit tests pass with updated property syntax
  • Integration tests pass for HTTP, GraphQL, and ConnectRPC clients
  • Type checking passes (deno task check)
  • Documentation examples updated and verified
  • deno task verify passes (format, lint, type-check, tests)

…ent-connectrpc): convert getter methods to properties

Response body accessor methods are now properties for cleaner API:
- HTTP: text(), json(), arrayBuffer(), blob() → getter properties
- HTTP: raw() → readonly property
- GraphQL: data(), raw() → readonly properties
- ConnectRPC: data(), raw() → readonly properties

The json property returns 'unknown' instead of generic T, requiring
explicit type assertions where needed. This change eliminates unnecessary
function call syntax while preserving the same lazy evaluation behavior.

Migration:
- response.json<User>() → response.json as User | null
- response.text() → response.text
- response.data<T>() → response.data as T | null
- All other accessors: remove () parentheses
@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 93.65079% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/probitas-client-http/response.ts 84.61% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@lambdalisue lambdalisue merged commit f4de00c into main Dec 23, 2025
3 checks passed
@lambdalisue lambdalisue deleted the feat/flatten-getter branch December 23, 2025 06:07
lambdalisue added a commit to probitas-test/probitas-test.github.io that referenced this pull request Dec 23, 2025
Updated code examples to reflect the breaking change in probitas-client
where response body accessors changed from methods to properties.

Changed accessor calls:
- res.json() → res.json (HTTP client)
- res.data() → res.data (gRPC/GraphQL clients)

This aligns with probitas-client PR #65 which converted getter methods
to properties for cleaner API. The json property now returns 'unknown'
requiring explicit type assertions where needed.

Ref: probitas-test/probitas-client#65
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant