Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 13 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
- next
branches-ignore:
- 'generated'
- 'codegen/**'
- 'integrated/**'
- 'stl-preview-head/**'
- 'stl-preview-base/**'

jobs:
lint:
timeout-minutes: 10
name: lint
runs-on: ubuntu-latest
runs-on: ${{ github.repository == 'stainless-sdks/modern-treasury-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}

steps:
- uses: actions/checkout@v4

Expand All @@ -21,7 +23,7 @@ jobs:
distribution: temurin
java-version: |
8
17
21
cache: gradle

- name: Set up Gradle
Expand All @@ -30,8 +32,9 @@ jobs:
- name: Run lints
run: ./scripts/lint
test:
timeout-minutes: 10
name: test
runs-on: ubuntu-latest
runs-on: ${{ github.repository == 'stainless-sdks/modern-treasury-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v4

Expand All @@ -41,7 +44,7 @@ jobs:
distribution: temurin
java-version: |
8
17
21
cache: gradle

- name: Set up Gradle
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "6.2.0"
".": "7.0.0"
}
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Changelog

## 7.0.0 (2025-05-08)

Full Changelog: [v6.2.0...v7.0.0](https://github.com/Modern-Treasury/modern-treasury-java/compare/v6.2.0...v7.0.0)

### ⚠ BREAKING CHANGES

* **client:** extract auto pagination to shared classes
* **client:** **Migration:** - If you were referencing the `AutoPager` class on a specific `*Page` or `*PageAsync` type, then you should instead reference the shared `AutoPager` and `AutoPagerAsync` types, under the `core` package
- `AutoPagerAsync` now has different usage. You can call `.subscribe(...)` on the returned object instead to get called back each page item. You can also call `onCompleteFuture()` to get a future that completes when all items have been processed. Finally, you can call `.close()` on the returned object to stop auto-paginating early
- If you were referencing `getNextPage` or `getNextPageParams`:
- Swap to `nextPage()` and `nextPageParams()`
- Note that these both now return non-optional types (use `hasNextPage()` before calling these, since they will throw if it's impossible to get another page)

### Features

* **api:** only send idempotency headers on PUT / POST requests ([b6af4eb](https://github.com/Modern-Treasury/modern-treasury-java/commit/b6af4ebca72513731d994db5ba84609b10d7aa0c))
* **client:** allow providing some params positionally ([c31350d](https://github.com/Modern-Treasury/modern-treasury-java/commit/c31350de1a83577bd8939f56f8099f59c2180ca6))
* **client:** extract auto pagination to shared classes ([578b033](https://github.com/Modern-Treasury/modern-treasury-java/commit/578b033749fbe2aa9e7afc36a493d1543f92d7ed))


### Bug Fixes

* **client:** add missing convenience methods ([ac3f059](https://github.com/Modern-Treasury/modern-treasury-java/commit/ac3f05909d3c136609f25520e6412353dc518f52))
* **internal:** format ([897821c](https://github.com/Modern-Treasury/modern-treasury-java/commit/897821ce9b3d209dc7609cde4a827c0a08400f02))


### Chores

* **ci:** add timeout thresholds for CI jobs ([0622aaf](https://github.com/Modern-Treasury/modern-treasury-java/commit/0622aafaa9c6b587110cebfa76b7400989d7b2b2))
* **ci:** only use depot for staging repos ([62b7483](https://github.com/Modern-Treasury/modern-treasury-java/commit/62b7483bf16ff40e2934931ee3d150bb4a8ea0ed))
* **ci:** run on more branches and use depot runners ([0daa6f8](https://github.com/Modern-Treasury/modern-treasury-java/commit/0daa6f89440339d9a527d9c5b56c3e8d97a8e3ef))
* **internal:** java 17 -> 21 on ci ([6511256](https://github.com/Modern-Treasury/modern-treasury-java/commit/65112564512234ff8fc9c4db0e049bb92d50a46c))
* **internal:** remove flaky `-Xbackend-threads=0` option ([aa64e9e](https://github.com/Modern-Treasury/modern-treasury-java/commit/aa64e9e8fb65e307b16a5af1154cb17e4e5f1a45))
* **internal:** update java toolchain ([6cd2213](https://github.com/Modern-Treasury/modern-treasury-java/commit/6cd2213a29baa1889b2a7caf19a7bb6d1a5a8664))
* **internal:** use `byteInputStream()` in tests ([ac3f059](https://github.com/Modern-Treasury/modern-treasury-java/commit/ac3f05909d3c136609f25520e6412353dc518f52))

## 6.2.0 (2025-04-16)

Full Changelog: [v6.1.0...v6.2.0](https://github.com/Modern-Treasury/modern-treasury-java/compare/v6.1.0...v6.2.0)
Expand Down
92 changes: 69 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.moderntreasury.api/modern-treasury-java)](https://central.sonatype.com/artifact/com.moderntreasury.api/modern-treasury-java/6.2.0)
[![javadoc](https://javadoc.io/badge2/com.moderntreasury.api/modern-treasury-java/6.2.0/javadoc.svg)](https://javadoc.io/doc/com.moderntreasury.api/modern-treasury-java/6.2.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.moderntreasury.api/modern-treasury-java)](https://central.sonatype.com/artifact/com.moderntreasury.api/modern-treasury-java/7.0.0)
[![javadoc](https://javadoc.io/badge2/com.moderntreasury.api/modern-treasury-java/7.0.0/javadoc.svg)](https://javadoc.io/doc/com.moderntreasury.api/modern-treasury-java/7.0.0)

<!-- x-release-please-end -->

Expand All @@ -13,7 +13,7 @@ The Modern Treasury Java SDK is similar to the Modern Treasury Kotlin SDK but wi

<!-- x-release-please-start-version -->

The REST API documentation can be found on [docs.moderntreasury.com](https://docs.moderntreasury.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.moderntreasury.api/modern-treasury-java/6.2.0).
The REST API documentation can be found on [docs.moderntreasury.com](https://docs.moderntreasury.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.moderntreasury.api/modern-treasury-java/7.0.0).

<!-- x-release-please-end -->

Expand All @@ -24,7 +24,7 @@ The REST API documentation can be found on [docs.moderntreasury.com](https://doc
### Gradle

```kotlin
implementation("com.moderntreasury:modern-treasury-java:6.2.0")
implementation("com.moderntreasury:modern-treasury-java:7.0.0")
```

### Maven
Expand All @@ -33,7 +33,7 @@ implementation("com.moderntreasury:modern-treasury-java:6.2.0")
<dependency>
<groupId>com.moderntreasury</groupId>
<artifactId>modern-treasury-java</artifactId>
<version>6.2.0</version>
<version>7.0.0</version>
</dependency>
```

Expand Down Expand Up @@ -286,53 +286,101 @@ The SDK throws custom unchecked exception types:

## Pagination

For methods that return a paginated list of results, this library provides convenient ways access the results either one page at a time, or item-by-item across all pages.
The SDK defines methods that return a paginated lists of results. It provides convenient ways to access the results either one page at a time or item-by-item across all pages.

### Auto-pagination

To iterate through all results across all pages, you can use `autoPager`, which automatically handles fetching more pages for you:
To iterate through all results across all pages, use the `autoPager()` method, which automatically fetches more pages as needed.

### Synchronous
When using the synchronous client, the method returns an [`Iterable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html)

```java
import com.moderntreasury.api.models.Counterparty;
import com.moderntreasury.api.models.CounterpartyListPage;

// As an Iterable:
CounterpartyListPage page = client.counterparties().list(params);
CounterpartyListPage page = client.counterparties().list();

// Process as an Iterable
for (Counterparty counterparty : page.autoPager()) {
System.out.println(counterparty);
};
}

// As a Stream:
client.counterparties().list(params).autoPager().stream()
// Process as a Stream
page.autoPager()
.stream()
.limit(50)
.forEach(counterparty -> System.out.println(counterparty));
```

### Asynchronous
When using the asynchronous client, the method returns an [`AsyncStreamResponse`](modern-treasury-java-core/src/main/kotlin/com/moderntreasury/api/core/http/AsyncStreamResponse.kt):

```java
// Using forEach, which returns CompletableFuture<Void>:
asyncClient.counterparties().list(params).autoPager()
.forEach(counterparty -> System.out.println(counterparty), executor);
import com.moderntreasury.api.core.http.AsyncStreamResponse;
import com.moderntreasury.api.models.Counterparty;
import com.moderntreasury.api.models.CounterpartyListPageAsync;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

CompletableFuture<CounterpartyListPageAsync> pageFuture = client.async().counterparties().list();

pageFuture.thenRun(page -> page.autoPager().subscribe(counterparty -> {
System.out.println(counterparty);
}));

// If you need to handle errors or completion of the stream
pageFuture.thenRun(page -> page.autoPager().subscribe(new AsyncStreamResponse.Handler<>() {
@Override
public void onNext(Counterparty counterparty) {
System.out.println(counterparty);
}

@Override
public void onComplete(Optional<Throwable> error) {
if (error.isPresent()) {
System.out.println("Something went wrong!");
throw new RuntimeException(error.get());
} else {
System.out.println("No more!");
}
}
}));

// Or use futures
pageFuture.thenRun(page -> page.autoPager()
.subscribe(counterparty -> {
System.out.println(counterparty);
})
.onCompleteFuture()
.whenComplete((unused, error) -> {
if (error != null) {
System.out.println("Something went wrong!");
throw new RuntimeException(error);
} else {
System.out.println("No more!");
}
}));
```

### Manual pagination

If none of the above helpers meet your needs, you can also manually request pages one-by-one. A page of results has a `data()` method to fetch the list of objects, as well as top-level `response` and other methods to fetch top-level data about the page. It also has methods `hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination.
To access individual page items and manually request the next page, use the `items()`,
`hasNextPage()`, and `nextPage()` methods:

```java
import com.moderntreasury.api.models.Counterparty;
import com.moderntreasury.api.models.CounterpartyListPage;

CounterpartyListPage page = client.counterparties().list(params);
while (page != null) {
CounterpartyListPage page = client.counterparties().list();
while (true) {
for (Counterparty counterparty : page.items()) {
System.out.println(counterparty);
}

page = page.getNextPage().orElse(null);
if (!page.hasNextPage()) {
break;
}

page = page.nextPage();
}
```

Expand Down Expand Up @@ -399,7 +447,6 @@ To set a custom timeout, configure the method call using the `timeout` method:

```java
import com.moderntreasury.api.models.Counterparty;
import com.moderntreasury.api.models.CounterpartyCreateParams;

Counterparty counterparty = client.counterparties().create(
params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()
Expand Down Expand Up @@ -631,7 +678,6 @@ Or configure the method call to validate the response using the `responseValidat

```java
import com.moderntreasury.api.models.Counterparty;
import com.moderntreasury.api.models.CounterpartyCreateParams;

Counterparty counterparty = client.counterparties().create(
params, RequestOptions.builder().responseValidation(true).build()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

allprojects {
group = "com.moderntreasury"
version = "6.2.0" // x-release-please-version
version = "7.0.0" // x-release-please-version
}

subprojects {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/modern-treasury.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ configure<SpotlessExtension> {

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}

sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/modern-treasury.kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ kotlin {
// Suppress deprecation warnings because we may still reference and test deprecated members.
// TODO: Replace with `-Xsuppress-warning=DEPRECATION` once we use Kotlin compiler 2.1.0+.
"-nowarn",
// Use as many threads as there are CPU cores on the machine for compilation.
"-Xbackend-threads=0",
)
jvmTarget.set(JvmTarget.JVM_1_8)
languageVersion.set(KotlinVersion.KOTLIN_1_8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional
import java.util.concurrent.Executor
import kotlin.jvm.optionals.getOrNull

class ModernTreasuryOkHttpClient private constructor() {
Expand Down Expand Up @@ -49,6 +50,10 @@ class ModernTreasuryOkHttpClient private constructor() {

fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }

fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
clientOptions.streamHandlerExecutor(streamHandlerExecutor)
}

fun clock(clock: Clock) = apply { clientOptions.clock(clock) }

fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional
import java.util.concurrent.Executor
import kotlin.jvm.optionals.getOrNull

class ModernTreasuryOkHttpClientAsync private constructor() {
Expand Down Expand Up @@ -50,6 +51,10 @@ class ModernTreasuryOkHttpClientAsync private constructor() {

fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }

fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
clientOptions.streamHandlerExecutor(streamHandlerExecutor)
}

fun clock(clock: Clock) = apply { clientOptions.clock(clock) }

fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// File generated from our OpenAPI spec by Stainless.

package com.moderntreasury.api.core

import java.util.stream.Stream
import java.util.stream.StreamSupport

class AutoPager<T> private constructor(private val firstPage: Page<T>) : Iterable<T> {

companion object {

fun <T> from(firstPage: Page<T>): AutoPager<T> = AutoPager(firstPage)
}

override fun iterator(): Iterator<T> =
generateSequence(firstPage) { if (it.hasNextPage()) it.nextPage() else null }
.flatMap { it.items() }
.iterator()

fun stream(): Stream<T> = StreamSupport.stream(spliterator(), false)
}
Loading