Skip to content

feat: client modules, type definitions, performance tuning & error codes guides - #1150

Open
iam-mercy wants to merge 1 commit into
Stellar-split:mainfrom
iam-mercy:feat/1077-1080-client-modules-types-docs
Open

iam-mercy wants to merge 1 commit into
Stellar-split:mainfrom
iam-mercy:feat/1077-1080-client-modules-types-docs

Conversation

@iam-mercy

Copy link
Copy Markdown

What this fixes

  • Refactor client into modules #1079 Refactor client into modules: StellarSplitClient was a monolithic class containing thousands of lines across disparate domains (invoices, payments, disputes, admin actions, grouping, templates, and milestones), making maintenance, domain isolation, and modular consumption difficult.
  • Add type definitions improvements #1080 Add type definitions improvements: The TypeScript type definitions lacked generic parameters for metadata and lifecycle statuses, functional result utilities, status narrowing type guards, and branded types to prevent type confusion between plain strings/bigints and domain types (stroops, addresses, invoice IDs).
  • Create performance tuning guide #1078 Create performance tuning guide: Developers lacked documented guidance and empirical benchmarks for optimizing SDK performance across RPC connection pooling, request batching, multi-tier caching, circuit breaking, multi-endpoint load balancing, and Soroban storage TTL batching.
  • Add error code reference guide #1077 Add error code reference guide: SDK error codes and panic mappings lacked a centralized reference guide documenting root causes, recovery strategies, retryability classifications, and concrete code examples.

What changed

  1. Client Modularization (Refactor client into modules #1079):

    • Designed and created logical sub-modules under src/client/modules/:
      • InvoiceModule: Creation, cloning, updates, queries, cancellations, sync, snapshots, and verification.
      • PaymentModule: Payments, simulations, batch payments, receipt generation, refunds, and reconciliations.
      • DisputeModule: Dispute raising, arbiter voting, resolution, and evidence attachment.
      • AdminModule: Administrative freeze/unfreeze and timelocked actions.
      • GroupModule: Group creation, invoice attachment, release, and aggregation statistics.
      • TemplateModule: Template storage, template creation, and recurring invoice management.
      • MilestoneModule: Milestone completions, active milestone tracking, and funding round closure.
    • Attached module instances (invoices, payments, disputes, admin, groups, templates, milestones) to StellarSplitClient.
    • Maintained 100% backward compatibility for all existing methods on StellarSplitClient.
    • Re-exported modules and sub-clients in src/client/index.ts and src/index.ts.
  2. Type Definitions & Utilities (Add type definitions improvements #1080):

    • Made Invoice<TMetadata, TStatus> and CreateInvoiceParams<TMetadata> generic with backward-compatible defaults.
    • Added Result<T, E> discriminated union with ok(), err(), isOk(), isErr(), unwrapResult(), mapResult(), mapErr(), and matchResult().
    • Added PaginatedResponse<T> generic interface and constructor helper.
    • Added branded types: StroopAmount, StellarAddress, InvoiceId with safe conversion helpers (toStroops, toStellarAddress, toInvoiceId).
    • Added status-narrowed invoice types (PendingInvoice, ReleasedInvoice, etc.) and type guard functions (isPendingInvoice, isReleasedInvoice, isInvoiceStatus).
    • Added recursive type utilities: DeepPartial, DeepReadonly, RequireKeys, OptionalKeys, StrictOmit, RequireAtLeastOne, RequireOnlyOne.
  3. Performance Tuning Guide (Create performance tuning guide #1078):

    • Created docs/PERFORMANCE_TUNING.md documenting:
      • RPC connection pooling (rpcPoolSize) with 85% latency reduction benchmarks.
      • Request multiplexing & batching (setBatchingEnabled) with 93% network roundtrip reduction.
      • In-memory and optimistic caching (cache) with sub-millisecond reads.
      • Circuit breaker and adaptive throttling for outage protection.
      • Health-weighted multi-endpoint balancing (rpcEndpoints).
      • Soroban storage TTL batch bumps (bumpStorageTtlBatch) saving 62% in fees.
      • Real-time streaming (WebSocket/SSE) vs. Horizon polling with 97% lower lag.
      • Comprehensive performance decision matrix.
  4. Error Code Reference Guide (Add error code reference guide #1077):

    • Created docs/ERROR_CODES.md cataloging the complete SDK error taxonomy across invoice lifecycle, payments, network/RPC, access control, disputes, milestones, and batch operations.
    • Added root causes, recovery actions, and TypeScript code examples for every error code.
    • Implemented missing error classes in src/errors.ts: RoundNotEndedError, WrongMilestoneError, NothingToClaimError, InvoiceExpiredError, PayerNotWhitelistedError, ContributionCapExceededError, PaymentCooldownActiveError, ContractFrozenError, InvoiceFullyFundedError, and DelegateLimitReachedError.
    • Updated isRetryable() to distinguish transient retryable conditions (RPC 429/503, timeouts, cooldowns) from terminal contract errors.

Testing

  • Unit tests run via Vitest:
    • test/client.test.ts (68 passed)
    • test/retryPolicy.test.ts (31 passed)
    • test/network-environment.test.ts (11 passed)
    • test/clientModules.test.ts (12 passed)
    • test/typeImprovements.test.ts (16 passed)
    • test/errorCodes.test.ts (10 passed)
    • test/sdkExports.test.ts (3 passed)
    • Total: 7 test files, 151 tests passed, 0 failures.

Issues

closes #1080
closes #1079
closes #1078
closes #1077

…rformance and error code guides

- Refactor monolithic StellarSplitClient into logical sub-modules (InvoiceModule, PaymentModule, DisputeModule, AdminModule, GroupModule, TemplateModule, MilestoneModule) while preserving full backward-compatible API (Stellar-split#1079)
- Improve TypeScript type definitions with advanced generics, Result<T, E> discriminated union, PaginatedResponse<T>, branded types, status-narrowed invoices, and utility types (Stellar-split#1080)
- Add comprehensive performance tuning guide with optimization techniques, tradeoffs, code examples, and empirical benchmark measurements (Stellar-split#1078)
- Add complete error code reference guide with causes, recovery actions, and code examples for the full error taxonomy (Stellar-split#1077)
- Add full test coverage for modules, type definitions, and error taxonomy
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@iam-mercy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type definitions improvements Refactor client into modules Create performance tuning guide Add error code reference guide

1 participant