diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9051fdd2..42805473 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,24 @@ name: CI on: push: - branches: - - main + branches-ignore: + - 'generated' + - 'codegen/**' + - 'integrated/**' + - 'stl-preview-head/**' + - 'stl-preview-base/**' pull_request: - branches: - - main - - next + branches-ignore: + - 'stl-preview-head/**' + - 'stl-preview-base/**' jobs: lint: - timeout-minutes: 10 + timeout-minutes: 15 name: lint - runs-on: ubuntu-latest + runs-on: ${{ github.repository == 'stainless-sdks/braintrust-sdk-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + steps: - uses: actions/checkout@v4 @@ -22,7 +28,7 @@ jobs: distribution: temurin java-version: | 8 - 17 + 21 cache: gradle - name: Set up Gradle @@ -30,10 +36,36 @@ jobs: - name: Run lints run: ./scripts/lint + + build: + timeout-minutes: 15 + name: build + runs-on: ${{ github.repository == 'stainless-sdks/braintrust-sdk-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + + steps: + - uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: | + 8 + 21 + cache: gradle + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build SDK + run: ./scripts/build + test: - timeout-minutes: 10 + timeout-minutes: 15 name: test - runs-on: ubuntu-latest + runs-on: ${{ github.repository == 'stainless-sdks/braintrust-sdk-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - uses: actions/checkout@v4 @@ -43,7 +75,7 @@ jobs: distribution: temurin java-version: | 8 - 17 + 21 cache: gradle - name: Set up Gradle diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml index bab4aea6..d914ae66 100755 --- a/.github/workflows/publish-sonatype.yml +++ b/.github/workflows/publish-sonatype.yml @@ -17,12 +17,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: | 8 - 17 + 21 cache: gradle - name: Set up Gradle diff --git a/.gitignore b/.gitignore index 4e81838d..b1346e6d 100755 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ .gradle .idea .kotlin -build +build/ codegen.log kls_database.db diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6d78745c..091cfb12 100755 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.9.0" + ".": "0.10.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 91f6c416..2e43a77b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 110 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/manugoyal%2Fbraintrust-sdk-f0d64ce0e0efde75f9c171f7f3c3d4a72f00a77abb3bc5a7d65b7be1e715689b.yml openapi_spec_hash: a027e48cc6aea2fab3cbdd38f4081119 -config_hash: 1ea10787f4def6c54a53f0e6f776f0a5 +config_hash: dca6e2cafd0764aa5fa3e78987e8b07c diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d47d1d9..3e8d2bf3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,103 @@ # Changelog +## 0.10.0 (2025-12-03) + +Full Changelog: [v0.9.0...v0.10.0](https://github.com/braintrustdata/braintrust-java/compare/v0.9.0...v0.10.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 + +* add retryable exception ([ad8114f](https://github.com/braintrustdata/braintrust-java/commit/ad8114f1410bdf0b8de7d97803ee1567256beb11)) +* **client:** add `{QueryParams,Headers}#put(String, JsonValue)` methods ([0d82daf](https://github.com/braintrustdata/braintrust-java/commit/0d82dafca840d9bab25d431f90bf624161f657d5)) +* **client:** add a `withOptions` method ([1da1cfa](https://github.com/braintrustdata/braintrust-java/commit/1da1cfac2d57ac0c4619888357cad8bd8ad8b55a)) +* **client:** add https config options ([0ae6f5d](https://github.com/braintrustdata/braintrust-java/commit/0ae6f5d5c5d0236d95f801afe0f648021c9f4c27)) +* **client:** allow configuring env via system properties ([bbca12c](https://github.com/braintrustdata/braintrust-java/commit/bbca12cb7c4c9a3b4914c31c1e3767ee944c9f6b)) +* **client:** allow providing some params positionally ([5d14bd0](https://github.com/braintrustdata/braintrust-java/commit/5d14bd085513672de3d1c064e2db919b5f0bffa2)) +* **client:** ensure compat with proguard ([cf76b62](https://github.com/braintrustdata/braintrust-java/commit/cf76b62a5d08699560aada21ebbe26d809a2a87e)) +* **client:** expose sleeper option ([0cf2fec](https://github.com/braintrustdata/braintrust-java/commit/0cf2fec7e371018483fa266379d854fc0a461c05)) +* **client:** extract auto pagination to shared classes ([42ec597](https://github.com/braintrustdata/braintrust-java/commit/42ec597072a9392a0a8fadf99bdf228960a66e37)) +* **client:** implement per-endpoint base URL support ([4610a9c](https://github.com/braintrustdata/braintrust-java/commit/4610a9cfca70a2b0567c952044434739beb591cd)) + + +### Bug Fixes + +* **ci:** release-doctor — report correct token name ([755910d](https://github.com/braintrustdata/braintrust-java/commit/755910da108b3010293d0d84bfc0e2696796448a)) +* **ci:** use java-version 21 for publish step ([f69d0fe](https://github.com/braintrustdata/braintrust-java/commit/f69d0fed4cf2ae0119e0bcf84503782208de89a0)) +* **client:** accidental mutability of some classes ([641c2dc](https://github.com/braintrustdata/braintrust-java/commit/641c2dc41ddbc04b225e944033fedb5f2efa7d02)) +* **client:** bump max requests per host to max requests (5 -> 64) ([e817e93](https://github.com/braintrustdata/braintrust-java/commit/e817e93b721d4bdbc4fcbf50c5e6dd019e1d6d1d)) +* **client:** cancel okhttp call when future cancelled ([4e9004a](https://github.com/braintrustdata/braintrust-java/commit/4e9004a568ad7c4309f30995df9bb7514d12ded7)) +* **client:** deserialization of empty objects ([599e59c](https://github.com/braintrustdata/braintrust-java/commit/599e59c37526f17fb2813776f35bf10ed7d176f9)) +* **client:** don't close client on `withOptions` usage when original is gc'd ([76d0366](https://github.com/braintrustdata/braintrust-java/commit/76d0366cca717ebf63a425cd6674b933b31519c9)) +* **client:** ensure error handling always occurs ([7f3b3e0](https://github.com/braintrustdata/braintrust-java/commit/7f3b3e052acb0e5053e3d470b9a67e226252e488)) +* **client:** ensure single timer is created per client ([0cf2fec](https://github.com/braintrustdata/braintrust-java/commit/0cf2fec7e371018483fa266379d854fc0a461c05)) +* **client:** incorrect `getPackageVersion` impl ([48913a4](https://github.com/braintrustdata/braintrust-java/commit/48913a4f26fae541609b186470f5e4d21a5892b3)) +* **client:** multi-value header serialization ([84f72e2](https://github.com/braintrustdata/braintrust-java/commit/84f72e20dea2803431834f698337574545c1ab29)) +* **client:** r8 support ([4796a86](https://github.com/braintrustdata/braintrust-java/commit/4796a86bef99bc10c8db95c0f8eae469542dbdcb)) +* **client:** remove `@MustBeClosed` for future returning methods ([fd77b27](https://github.com/braintrustdata/braintrust-java/commit/fd77b2799b7c290451a1fdc2cb3bde9970c8ccc8)) +* fix casing issue ([89a22c7](https://github.com/braintrustdata/braintrust-java/commit/89a22c7ada67d638f3c3a95b9b5dc83a57d6436c)) +* update singularization rules ([ed3c3b2](https://github.com/braintrustdata/braintrust-java/commit/ed3c3b22c536f4fdc470eca6ed3129af7e4176c7)) + + +### Performance Improvements + +* **internal:** make formatting faster ([12585ed](https://github.com/braintrustdata/braintrust-java/commit/12585ed0aa09ac429ba618d7efb82d18c556bdc0)) + + +### Chores + +* **ci:** add build job ([72ca2fc](https://github.com/braintrustdata/braintrust-java/commit/72ca2fc6ecb8aeca739eb3c7e2c8364bf9b13431)) +* **ci:** bump `actions/setup-java` to v4 ([a5b0e85](https://github.com/braintrustdata/braintrust-java/commit/a5b0e85efaf25619a2f027bc6ba26fded780c78d)) +* **ci:** enable for pull requests ([40d994c](https://github.com/braintrustdata/braintrust-java/commit/40d994c4a4deb433bb789f085a77a3e98bab9357)) +* **ci:** ensure docs generation always succeeds ([067e7c8](https://github.com/braintrustdata/braintrust-java/commit/067e7c85b66f03fe03432bd8f56f5b9f752568d4)) +* **ci:** only run for pushes and fork pull requests ([ed7f8d9](https://github.com/braintrustdata/braintrust-java/commit/ed7f8d9b135466d13af8d2a504446d9116e87df4)) +* **ci:** only use depot for staging repos ([e4dbfbc](https://github.com/braintrustdata/braintrust-java/commit/e4dbfbc0c747acdef7625c3a9f5c8a90411ad8c5)) +* **ci:** reduce log noise ([57adf59](https://github.com/braintrustdata/braintrust-java/commit/57adf598e9d61a5d2358cedb6153fdeb1cc4d1ff)) +* **client:** refactor closing / shutdown ([d72b3c9](https://github.com/braintrustdata/braintrust-java/commit/d72b3c9e7b16775bfad37b6041b1fc2ba8fc4de7)) +* **docs:** grammar improvements ([bac039c](https://github.com/braintrustdata/braintrust-java/commit/bac039cbe2257071de867bd0111c9c1979dedc25)) +* **example:** fix run example comment ([3f434c4](https://github.com/braintrustdata/braintrust-java/commit/3f434c47346d6a3eeee86bc55fa516d9f4e73d49)) +* improve formatter performance ([7e03e85](https://github.com/braintrustdata/braintrust-java/commit/7e03e8533c820200ddfe9d4d39ba0d9bc533f4b8)) +* improve formatter performance ([b6e41d0](https://github.com/braintrustdata/braintrust-java/commit/b6e41d05764a88105cee99bd26d17eb60f80352b)) +* increase max gradle JVM heap to 8GB ([e88d096](https://github.com/braintrustdata/braintrust-java/commit/e88d096c45bf5a8b192aa25290bcefa1b98105c6)) +* **internal:** add async lock helper ([62dce85](https://github.com/braintrustdata/braintrust-java/commit/62dce854fa19a3c1a53f881e95f4d625f7cbaa54)) +* **internal:** allow running specific example from cli ([ff998ed](https://github.com/braintrustdata/braintrust-java/commit/ff998ed099c02f1340558bd274685a7d6273873c)) +* **internal:** bump ci test timeout ([c823880](https://github.com/braintrustdata/braintrust-java/commit/c8238804faed172d1a6ab5678287e840631b4bd2)) +* **internal:** codegen related update ([cd321c9](https://github.com/braintrustdata/braintrust-java/commit/cd321c953fd40a9ad9b4acd2c6394ed08afc78eb)) +* **internal:** codegen related update ([2ed652b](https://github.com/braintrustdata/braintrust-java/commit/2ed652b7ce471d4a551e391a14c97bf5a10e4a2b)) +* **internal:** codegen related update ([1e2fa56](https://github.com/braintrustdata/braintrust-java/commit/1e2fa560ec11e9e31e2d2328cd8dffa027c20f4a)) +* **internal:** codegen related update ([f28bc60](https://github.com/braintrustdata/braintrust-java/commit/f28bc603c8009ea98477ede33c8a87ea12b8bb93)) +* **internal:** dynamically determine included projects ([9fcff68](https://github.com/braintrustdata/braintrust-java/commit/9fcff686b6ca947d06f80eeaff88174ac4aa6bda)) +* **internal:** java 17 -> 21 on ci ([ce64b45](https://github.com/braintrustdata/braintrust-java/commit/ce64b45664323ae4d427aadae817c2178be94b5a)) +* **internal:** reduce proguard ci logging ([4d23bb8](https://github.com/braintrustdata/braintrust-java/commit/4d23bb89a38926be3620b70f048526ce30a05742)) +* **internal:** refactor delegating from client to options ([8b05411](https://github.com/braintrustdata/braintrust-java/commit/8b054110bd40910f22f52ec943cedc2e6dc5ecb8)) +* **internal:** remove flaky `-Xbackend-threads=0` option ([3b5c63c](https://github.com/braintrustdata/braintrust-java/commit/3b5c63c53cf8b742f151bbb8429322b36ac84a6a)) +* **internal:** remove unnecessary `[...]` in `[@see](https://github.com/see)` ([bbd6ab6](https://github.com/braintrustdata/braintrust-java/commit/bbd6ab68df9cdce2607548f7c8b2e6a288ed94a8)) +* **internal:** support passing arguments to test script ([26ca502](https://github.com/braintrustdata/braintrust-java/commit/26ca502a788e989316c314a8a204a9d5531d7942)) +* **internal:** support running formatters directly ([1bfd53a](https://github.com/braintrustdata/braintrust-java/commit/1bfd53a5fe245df0acb8ebc0b39b88ff146e8961)) +* **internal:** update comment in script ([fb33197](https://github.com/braintrustdata/braintrust-java/commit/fb331975009e27f40c13e448d90ec23b0f090669)) +* **internal:** update java toolchain ([f9f4254](https://github.com/braintrustdata/braintrust-java/commit/f9f4254689cae85a734c79c0cf25f283163b6382)) +* remove memory upper bound from publishing step ([d8ca7a9](https://github.com/braintrustdata/braintrust-java/commit/d8ca7a9e64d50078c399d9d7552a3d2c14df8a40)) +* update @stainless-api/prism-cli to v5.15.0 ([7138c31](https://github.com/braintrustdata/braintrust-java/commit/7138c31970ba385cf1548e63af3746c61872a256)) + + +### Documentation + +* fix missing readme comment ([d1346c2](https://github.com/braintrustdata/braintrust-java/commit/d1346c2f1c8be9157d5e77d7db8a20b746b933e3)) +* more code comments ([cba7926](https://github.com/braintrustdata/braintrust-java/commit/cba79267f1c5e2a82b728fec6e44709d9387bd92)) +* remove `$` for better copy-pasteabality ([c162005](https://github.com/braintrustdata/braintrust-java/commit/c162005e4957239975573760d8e07cdb0e0b851f)) + + +### Refactors + +* **internal:** minor `ClientOptionsTest` change ([1dc2b4d](https://github.com/braintrustdata/braintrust-java/commit/1dc2b4d4f57bab9408f18407c877569540a6e7f0)) + ## 0.9.0 (2025-04-23) Full Changelog: [v0.8.0...v0.9.0](https://github.com/braintrustdata/braintrust-java/compare/v0.8.0...v0.9.0) diff --git a/README.md b/README.md index f494ee60..11fa79f2 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ NOTE: This repo is a Java client for the Braintrust REST API. If you wish to tra -[![Maven Central](https://img.shields.io/maven-central/v/com.braintrustdata.api/braintrust-java)](https://central.sonatype.com/artifact/com.braintrustdata.api/braintrust-java/0.9.0) -[![javadoc](https://javadoc.io/badge2/com.braintrustdata.api/braintrust-java/0.9.0/javadoc.svg)](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.9.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.braintrustdata.api/braintrust-java)](https://central.sonatype.com/artifact/com.braintrustdata.api/braintrust-java/0.10.0) +[![javadoc](https://javadoc.io/badge2/com.braintrustdata.api/braintrust-java/0.10.0/javadoc.svg)](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.10.0) @@ -17,7 +17,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.9.0). +The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.10.0). @@ -28,7 +28,7 @@ The REST API documentation can be found on [www.braintrustdata.com](https://www. ### Gradle ```kotlin -implementation("com.braintrustdata.api:braintrust-java:0.9.0") +implementation("com.braintrustdata.api:braintrust-java:0.10.0") ``` ### Maven @@ -37,7 +37,7 @@ implementation("com.braintrustdata.api:braintrust-java:0.9.0") com.braintrustdata.api braintrust-java - 0.9.0 + 0.10.0 ``` @@ -55,7 +55,8 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; import com.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectCreateParams; -// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables +// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties +// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClient client = BraintrustOkHttpClient.fromEnv(); ProjectCreateParams params = ProjectCreateParams.builder() @@ -66,13 +67,14 @@ Project project = client.projects().create(params); ## Client configuration -Configure the client using environment variables: +Configure the client using system properties or environment variables: ```java import com.braintrustdata.api.client.BraintrustClient; import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; -// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables +// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties +// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClient client = BraintrustOkHttpClient.fromEnv(); ``` @@ -94,7 +96,8 @@ import com.braintrustdata.api.client.BraintrustClient; import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; BraintrustClient client = BraintrustOkHttpClient.builder() - // Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables + // Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties + // Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables .fromEnv() .apiKey("My API Key") .build(); @@ -102,15 +105,32 @@ BraintrustClient client = BraintrustOkHttpClient.builder() See this table for the available options: -| Setter | Environment variable | Required | Default value | -| --------- | --------------------- | -------- | ------------------------------ | -| `apiKey` | `BRAINTRUST_API_KEY` | false | - | -| `baseUrl` | `BRAINTRUST_BASE_URL` | true | `"https://api.braintrust.dev"` | +| Setter | System property | Environment variable | Required | Default value | +| --------- | -------------------- | --------------------- | -------- | ------------------------------ | +| `apiKey` | `braintrust.apiKey` | `BRAINTRUST_API_KEY` | false | - | +| `baseUrl` | `braintrust.baseUrl` | `BRAINTRUST_BASE_URL` | true | `"https://api.braintrust.dev"` | + +System properties take precedence over environment variables. > [!TIP] > Don't create more than one client in the same application. Each client has a connection pool and > thread pools, which are more efficient to share between requests. +### Modifying configuration + +To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()` on any client or service: + +```java +import com.braintrustdata.api.client.BraintrustClient; + +BraintrustClient clientWithOptions = client.withOptions(optionsBuilder -> { + optionsBuilder.baseUrl("https://example.com"); + optionsBuilder.maxRetries(42); +}); +``` + +The `withOptions()` method does not affect the original client or service. + ## Requests and responses To send a request to the Braintrust API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class. @@ -136,7 +156,8 @@ import com.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectCreateParams; import java.util.concurrent.CompletableFuture; -// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables +// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties +// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClient client = BraintrustOkHttpClient.fromEnv(); ProjectCreateParams params = ProjectCreateParams.builder() @@ -154,7 +175,8 @@ import com.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectCreateParams; import java.util.concurrent.CompletableFuture; -// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables +// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties +// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables BraintrustClientAsync client = BraintrustOkHttpClientAsync.fromEnv(); ProjectCreateParams params = ProjectCreateParams.builder() @@ -213,59 +235,109 @@ The SDK throws custom unchecked exception types: - [`BraintrustIoException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustIoException.kt): I/O networking errors. +- [`BraintrustRetryableException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt): Generic error indicating a failure that could be retried by the client. + - [`BraintrustInvalidDataException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustInvalidDataException.kt): Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response. - [`BraintrustException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustException.kt): Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class. ## 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.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectListPage; -// As an Iterable: -ProjectListPage page = client.projects().list(params); +ProjectListPage page = client.projects().list(); + +// Process as an Iterable for (Project project : page.autoPager()) { System.out.println(project); -}; +} -// As a Stream: -client.projects().list(params).autoPager().stream() +// Process as a Stream +page.autoPager() + .stream() .limit(50) .forEach(project -> System.out.println(project)); ``` -### Asynchronous +When using the asynchronous client, the method returns an [`AsyncStreamResponse`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt): ```java -// Using forEach, which returns CompletableFuture: -asyncClient.projects().list(params).autoPager() - .forEach(project -> System.out.println(project), executor); +import com.braintrustdata.api.core.http.AsyncStreamResponse; +import com.braintrustdata.api.models.Project; +import com.braintrustdata.api.models.ProjectListPageAsync; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +CompletableFuture pageFuture = client.async().projects().list(); + +pageFuture.thenRun(page -> page.autoPager().subscribe(project -> { + System.out.println(project); +})); + +// If you need to handle errors or completion of the stream +pageFuture.thenRun(page -> page.autoPager().subscribe(new AsyncStreamResponse.Handler<>() { + @Override + public void onNext(Project project) { + System.out.println(project); + } + + @Override + public void onComplete(Optional 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(project -> { + System.out.println(project); + }) + .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.braintrustdata.api.models.Project; import com.braintrustdata.api.models.ProjectListPage; -ProjectListPage page = client.projects().list(params); -while (page != null) { - for (Project project : page.objects()) { +ProjectListPage page = client.projects().list(); +while (true) { + for (Project project : page.items()) { System.out.println(project); } - page = page.getNextPage().orElse(null); + if (!page.hasNextPage()) { + break; + } + + page = page.nextPage(); } ``` @@ -276,15 +348,21 @@ The SDK uses the standard [OkHttp logging interceptor](https://github.com/square Enable logging by setting the `BRAINTRUST_LOG` environment variable to `info`: ```sh -$ export BRAINTRUST_LOG=info +export BRAINTRUST_LOG=info ``` Or to `debug` for more verbose logging: ```sh -$ export BRAINTRUST_LOG=debug +export BRAINTRUST_LOG=debug ``` +## ProGuard and R8 + +Although the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `braintrust-java-core` is published with a [configuration file](braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage). + +ProGuard and R8 should automatically detect and use the published rules, but you can also manually copy the keep rules if necessary. + ## Jackson The SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default. @@ -300,7 +378,7 @@ If the SDK threw an exception, but you're _certain_ the version is compatible, t ### Retries -The SDK automatically retries 2 times by default, with a short exponential backoff. +The SDK automatically retries 2 times by default, with a short exponential backoff between requests. Only the following error types are retried: @@ -310,7 +388,7 @@ Only the following error types are retried: - 429 Rate Limit - 5xx Internal -The API may also explicitly instruct the SDK to retry or not retry a response. +The API may also explicitly instruct the SDK to retry or not retry a request. To set a custom number of retries, configure the client using the `maxRetries` method: @@ -332,7 +410,6 @@ To set a custom timeout, configure the method call using the `timeout` method: ```java import com.braintrustdata.api.models.Project; -import com.braintrustdata.api.models.ProjectCreateParams; Project project = client.projects().create( params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build() @@ -372,6 +449,27 @@ BraintrustClient client = BraintrustOkHttpClient.builder() .build(); ``` +### HTTPS + +> [!NOTE] +> Most applications should not call these methods, and instead use the system defaults. The defaults include +> special optimizations that can be lost if the implementations are modified. + +To configure how HTTPS connections are secured, configure the client using the `sslSocketFactory`, `trustManager`, and `hostnameVerifier` methods: + +```java +import com.braintrustdata.api.client.BraintrustClient; +import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient; + +BraintrustClient client = BraintrustOkHttpClient.builder() + .fromEnv() + // If `sslSocketFactory` is set, then `trustManager` must be set, and vice versa. + .sslSocketFactory(yourSSLSocketFactory) + .trustManager(yourTrustManager) + .hostnameVerifier(yourHostnameVerifier) + .build(); +``` + ### Custom HTTP client The SDK consists of three artifacts: @@ -580,7 +678,6 @@ Or configure the method call to validate the response using the `responseValidat ```java import com.braintrustdata.api.models.Project; -import com.braintrustdata.api.models.ProjectCreateParams; Project project = client.projects().create( params, RequestOptions.builder().responseValidation(true).build() diff --git a/SECURITY.md b/SECURITY.md index 0923aae0..a7f4f3b4 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -16,11 +16,11 @@ before making any information public. ## Reporting Non-SDK Related Security Issues If you encounter security issues that are not directly related to SDKs but pertain to the services -or products provided by Braintrust please follow the respective company's security reporting guidelines. +or products provided by Braintrust, please follow the respective company's security reporting guidelines. ### Braintrust Terms and Policies -Please contact info@braintrustdata.com for any questions or concerns regarding security of our services. +Please contact info@braintrustdata.com for any questions or concerns regarding the security of our services. --- diff --git a/bin/check-release-environment b/bin/check-release-environment index cc9c2cd7..3a6a7b4a 100755 --- a/bin/check-release-environment +++ b/bin/check-release-environment @@ -3,19 +3,19 @@ errors=() if [ -z "${SONATYPE_USERNAME}" ]; then - errors+=("The BRAINTRUST_SONATYPE_USERNAME secret has not been set. Please set it in either this repository's secrets or your organization secrets") + errors+=("The SONATYPE_USERNAME secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi if [ -z "${SONATYPE_PASSWORD}" ]; then - errors+=("The BRAINTRUST_SONATYPE_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") + errors+=("The SONATYPE_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi if [ -z "${GPG_SIGNING_KEY}" ]; then - errors+=("The BRAINTRUST_SONATYPE_GPG_SIGNING_KEY secret has not been set. Please set it in either this repository's secrets or your organization secrets") + errors+=("The GPG_SIGNING_KEY secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi if [ -z "${GPG_SIGNING_PASSWORD}" ]; then - errors+=("The BRAINTRUST_SONATYPE_GPG_SIGNING_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") + errors+=("The GPG_SIGNING_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi lenErrors=${#errors[@]} diff --git a/braintrust-java-client-okhttp/build.gradle.kts b/braintrust-java-client-okhttp/build.gradle.kts index 8408ea37..16bbfd8e 100755 --- a/braintrust-java-client-okhttp/build.gradle.kts +++ b/braintrust-java-client-okhttp/build.gradle.kts @@ -11,4 +11,5 @@ dependencies { testImplementation(kotlin("test")) testImplementation("org.assertj:assertj-core:3.25.3") + testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2") } diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt index aa4f40a4..e91ce488 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt @@ -5,23 +5,40 @@ package com.braintrustdata.api.client.okhttp import com.braintrustdata.api.client.BraintrustClient import com.braintrustdata.api.client.BraintrustClientImpl import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.Sleeper import com.braintrustdata.api.core.Timeout +import com.braintrustdata.api.core.http.AsyncStreamResponse import com.braintrustdata.api.core.http.Headers +import com.braintrustdata.api.core.http.HttpClient import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.jsonMapper import com.fasterxml.jackson.databind.json.JsonMapper import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor +import javax.net.ssl.HostnameVerifier +import javax.net.ssl.SSLSocketFactory +import javax.net.ssl.X509TrustManager import kotlin.jvm.optionals.getOrNull +/** + * A class that allows building an instance of [BraintrustClient] with [OkHttpClient] as the + * underlying [HttpClient]. + */ class BraintrustOkHttpClient private constructor() { companion object { - /** Returns a mutable builder for constructing an instance of [BraintrustOkHttpClient]. */ + /** Returns a mutable builder for constructing an instance of [BraintrustClient]. */ @JvmStatic fun builder() = Builder() + /** + * Returns a client configured using system properties and environment variables. + * + * @see ClientOptions.Builder.fromEnv + */ @JvmStatic fun fromEnv(): BraintrustClient = builder().fromEnv().build() } @@ -29,10 +46,63 @@ class BraintrustOkHttpClient private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() - private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null + private var sslSocketFactory: SSLSocketFactory? = null + private var trustManager: X509TrustManager? = null + private var hostnameVerifier: HostnameVerifier? = null + + fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } - fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) } + /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ + fun proxy(proxy: Optional) = proxy(proxy.getOrNull()) + + /** + * The socket factory used to secure HTTPS connections. + * + * If this is set, then [trustManager] must also be set. + * + * If unset, then the system default is used. Most applications should not call this method, + * and instead use the system default. The default include special optimizations that can be + * lost if the implementation is modified. + */ + fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply { + this.sslSocketFactory = sslSocketFactory + } + + /** Alias for calling [Builder.sslSocketFactory] with `sslSocketFactory.orElse(null)`. */ + fun sslSocketFactory(sslSocketFactory: Optional) = + sslSocketFactory(sslSocketFactory.getOrNull()) + + /** + * The trust manager used to secure HTTPS connections. + * + * If this is set, then [sslSocketFactory] must also be set. + * + * If unset, then the system default is used. Most applications should not call this method, + * and instead use the system default. The default include special optimizations that can be + * lost if the implementation is modified. + */ + fun trustManager(trustManager: X509TrustManager?) = apply { + this.trustManager = trustManager + } + + /** Alias for calling [Builder.trustManager] with `trustManager.orElse(null)`. */ + fun trustManager(trustManager: Optional) = + trustManager(trustManager.getOrNull()) + + /** + * The verifier used to confirm that response certificates apply to requested hostnames for + * HTTPS connections. + * + * If unset, then a default hostname verifier is used. + */ + fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply { + this.hostnameVerifier = hostnameVerifier + } + + /** Alias for calling [Builder.hostnameVerifier] with `hostnameVerifier.orElse(null)`. */ + fun hostnameVerifier(hostnameVerifier: Optional) = + hostnameVerifier(hostnameVerifier.getOrNull()) /** * Whether to throw an exception if any of the Jackson versions detected at runtime are @@ -45,10 +115,104 @@ class BraintrustOkHttpClient private constructor() { clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility) } + /** + * The Jackson JSON mapper to use for serializing and deserializing JSON. + * + * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient + * and rarely needs to be overridden. + */ fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + /** + * The executor to use for running [AsyncStreamResponse.Handler] callbacks. + * + * Defaults to a dedicated cached thread pool. + * + * This class takes ownership of the executor and shuts it down, if possible, when closed. + */ + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + clientOptions.streamHandlerExecutor(streamHandlerExecutor) + } + + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) } + + /** + * The clock to use for operations that require timing, like retries. + * + * This is primarily useful for using a fake clock in tests. + * + * Defaults to [Clock.systemUTC]. + */ fun clock(clock: Clock) = apply { clientOptions.clock(clock) } + /** + * The base URL to use for every request. + * + * Defaults to the production environment: `https://api.braintrust.dev`. + */ + fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) } + + /** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */ + fun baseUrl(baseUrl: Optional) = baseUrl(baseUrl.getOrNull()) + + /** + * Whether to call `validate` on every response before returning it. + * + * Defaults to false, which means the shape of the response will not be validated upfront. + * Instead, validation will only occur for the parts of the response that are accessed. + */ + fun responseValidation(responseValidation: Boolean) = apply { + clientOptions.responseValidation(responseValidation) + } + + /** + * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding + * retries. + * + * Defaults to [Timeout.default]. + */ + fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) } + + /** + * Sets the maximum time allowed for a complete HTTP call, not including retries. + * + * See [Timeout.request] for more details. + * + * For fine-grained control, pass a [Timeout] object. + */ + fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) } + + /** + * The maximum number of times to retry failed requests, with a short exponential backoff + * between requests. + * + * Only the following error types are retried: + * - Connection errors (for example, due to a network connectivity problem) + * - 408 Request Timeout + * - 409 Conflict + * - 429 Rate Limit + * - 5xx Internal + * + * The API may also explicitly instruct the SDK to retry or not retry a request. + * + * Defaults to 2. + */ + fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) } + + fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) } + + /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */ + fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull()) + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } fun headers(headers: Map>) = apply { @@ -129,33 +293,11 @@ class BraintrustOkHttpClient private constructor() { clientOptions.removeAllQueryParams(keys) } - fun timeout(timeout: Timeout) = apply { - clientOptions.timeout(timeout) - this.timeout = timeout - } - /** - * Sets the maximum time allowed for a complete HTTP call, not including retries. - * - * See [Timeout.request] for more details. + * Updates configuration using system properties and environment variables. * - * For fine-grained control, pass a [Timeout] object. + * @see ClientOptions.Builder.fromEnv */ - fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build()) - - fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) } - - fun proxy(proxy: Proxy) = apply { this.proxy = proxy } - - fun responseValidation(responseValidation: Boolean) = apply { - clientOptions.responseValidation(responseValidation) - } - - fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) } - - /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */ - fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull()) - fun fromEnv() = apply { clientOptions.fromEnv() } /** @@ -168,9 +310,11 @@ class BraintrustOkHttpClient private constructor() { clientOptions .httpClient( OkHttpClient.builder() - .baseUrl(clientOptions.baseUrl()) - .timeout(timeout) + .timeout(clientOptions.timeout()) .proxy(proxy) + .sslSocketFactory(sslSocketFactory) + .trustManager(trustManager) + .hostnameVerifier(hostnameVerifier) .build() ) .build() diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt index c0d37976..ae462cb7 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt @@ -5,25 +5,40 @@ package com.braintrustdata.api.client.okhttp import com.braintrustdata.api.client.BraintrustClientAsync import com.braintrustdata.api.client.BraintrustClientAsyncImpl import com.braintrustdata.api.core.ClientOptions +import com.braintrustdata.api.core.Sleeper import com.braintrustdata.api.core.Timeout +import com.braintrustdata.api.core.http.AsyncStreamResponse import com.braintrustdata.api.core.http.Headers +import com.braintrustdata.api.core.http.HttpClient import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.jsonMapper import com.fasterxml.jackson.databind.json.JsonMapper import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor +import javax.net.ssl.HostnameVerifier +import javax.net.ssl.SSLSocketFactory +import javax.net.ssl.X509TrustManager import kotlin.jvm.optionals.getOrNull +/** + * A class that allows building an instance of [BraintrustClientAsync] with [OkHttpClient] as the + * underlying [HttpClient]. + */ class BraintrustOkHttpClientAsync private constructor() { companion object { - /** - * Returns a mutable builder for constructing an instance of [BraintrustOkHttpClientAsync]. - */ + /** Returns a mutable builder for constructing an instance of [BraintrustClientAsync]. */ @JvmStatic fun builder() = Builder() + /** + * Returns a client configured using system properties and environment variables. + * + * @see ClientOptions.Builder.fromEnv + */ @JvmStatic fun fromEnv(): BraintrustClientAsync = builder().fromEnv().build() } @@ -31,10 +46,63 @@ class BraintrustOkHttpClientAsync private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() - private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null + private var sslSocketFactory: SSLSocketFactory? = null + private var trustManager: X509TrustManager? = null + private var hostnameVerifier: HostnameVerifier? = null + + fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } + + /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ + fun proxy(proxy: Optional) = proxy(proxy.getOrNull()) + + /** + * The socket factory used to secure HTTPS connections. + * + * If this is set, then [trustManager] must also be set. + * + * If unset, then the system default is used. Most applications should not call this method, + * and instead use the system default. The default include special optimizations that can be + * lost if the implementation is modified. + */ + fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply { + this.sslSocketFactory = sslSocketFactory + } + + /** Alias for calling [Builder.sslSocketFactory] with `sslSocketFactory.orElse(null)`. */ + fun sslSocketFactory(sslSocketFactory: Optional) = + sslSocketFactory(sslSocketFactory.getOrNull()) + + /** + * The trust manager used to secure HTTPS connections. + * + * If this is set, then [sslSocketFactory] must also be set. + * + * If unset, then the system default is used. Most applications should not call this method, + * and instead use the system default. The default include special optimizations that can be + * lost if the implementation is modified. + */ + fun trustManager(trustManager: X509TrustManager?) = apply { + this.trustManager = trustManager + } + + /** Alias for calling [Builder.trustManager] with `trustManager.orElse(null)`. */ + fun trustManager(trustManager: Optional) = + trustManager(trustManager.getOrNull()) + + /** + * The verifier used to confirm that response certificates apply to requested hostnames for + * HTTPS connections. + * + * If unset, then a default hostname verifier is used. + */ + fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply { + this.hostnameVerifier = hostnameVerifier + } - fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) } + /** Alias for calling [Builder.hostnameVerifier] with `hostnameVerifier.orElse(null)`. */ + fun hostnameVerifier(hostnameVerifier: Optional) = + hostnameVerifier(hostnameVerifier.getOrNull()) /** * Whether to throw an exception if any of the Jackson versions detected at runtime are @@ -47,10 +115,104 @@ class BraintrustOkHttpClientAsync private constructor() { clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility) } + /** + * The Jackson JSON mapper to use for serializing and deserializing JSON. + * + * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient + * and rarely needs to be overridden. + */ fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + /** + * The executor to use for running [AsyncStreamResponse.Handler] callbacks. + * + * Defaults to a dedicated cached thread pool. + * + * This class takes ownership of the executor and shuts it down, if possible, when closed. + */ + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + clientOptions.streamHandlerExecutor(streamHandlerExecutor) + } + + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) } + + /** + * The clock to use for operations that require timing, like retries. + * + * This is primarily useful for using a fake clock in tests. + * + * Defaults to [Clock.systemUTC]. + */ fun clock(clock: Clock) = apply { clientOptions.clock(clock) } + /** + * The base URL to use for every request. + * + * Defaults to the production environment: `https://api.braintrust.dev`. + */ + fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) } + + /** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */ + fun baseUrl(baseUrl: Optional) = baseUrl(baseUrl.getOrNull()) + + /** + * Whether to call `validate` on every response before returning it. + * + * Defaults to false, which means the shape of the response will not be validated upfront. + * Instead, validation will only occur for the parts of the response that are accessed. + */ + fun responseValidation(responseValidation: Boolean) = apply { + clientOptions.responseValidation(responseValidation) + } + + /** + * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding + * retries. + * + * Defaults to [Timeout.default]. + */ + fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) } + + /** + * Sets the maximum time allowed for a complete HTTP call, not including retries. + * + * See [Timeout.request] for more details. + * + * For fine-grained control, pass a [Timeout] object. + */ + fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) } + + /** + * The maximum number of times to retry failed requests, with a short exponential backoff + * between requests. + * + * Only the following error types are retried: + * - Connection errors (for example, due to a network connectivity problem) + * - 408 Request Timeout + * - 409 Conflict + * - 429 Rate Limit + * - 5xx Internal + * + * The API may also explicitly instruct the SDK to retry or not retry a request. + * + * Defaults to 2. + */ + fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) } + + fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) } + + /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */ + fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull()) + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } fun headers(headers: Map>) = apply { @@ -131,33 +293,11 @@ class BraintrustOkHttpClientAsync private constructor() { clientOptions.removeAllQueryParams(keys) } - fun timeout(timeout: Timeout) = apply { - clientOptions.timeout(timeout) - this.timeout = timeout - } - /** - * Sets the maximum time allowed for a complete HTTP call, not including retries. - * - * See [Timeout.request] for more details. + * Updates configuration using system properties and environment variables. * - * For fine-grained control, pass a [Timeout] object. + * @see ClientOptions.Builder.fromEnv */ - fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build()) - - fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) } - - fun proxy(proxy: Proxy) = apply { this.proxy = proxy } - - fun responseValidation(responseValidation: Boolean) = apply { - clientOptions.responseValidation(responseValidation) - } - - fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) } - - /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */ - fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull()) - fun fromEnv() = apply { clientOptions.fromEnv() } /** @@ -170,9 +310,11 @@ class BraintrustOkHttpClientAsync private constructor() { clientOptions .httpClient( OkHttpClient.builder() - .baseUrl(clientOptions.baseUrl()) - .timeout(timeout) + .timeout(clientOptions.timeout()) .proxy(proxy) + .sslSocketFactory(sslSocketFactory) + .trustManager(trustManager) + .hostnameVerifier(hostnameVerifier) .build() ) .build() diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt index 49a5df68..2ffdf3d7 100755 --- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt +++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt @@ -2,7 +2,6 @@ package com.braintrustdata.api.client.okhttp import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.Timeout -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.HttpClient import com.braintrustdata.api.core.http.HttpMethod @@ -14,10 +13,13 @@ import java.io.IOException import java.io.InputStream import java.net.Proxy import java.time.Duration +import java.util.concurrent.CancellationException import java.util.concurrent.CompletableFuture +import javax.net.ssl.HostnameVerifier +import javax.net.ssl.SSLSocketFactory +import javax.net.ssl.X509TrustManager import okhttp3.Call import okhttp3.Callback -import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType @@ -29,8 +31,7 @@ import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink class OkHttpClient -private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) : - HttpClient { +private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient { override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse { val call = newCall(request, requestOptions) @@ -50,20 +51,25 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val ): CompletableFuture { val future = CompletableFuture() - request.body?.run { future.whenComplete { _, _ -> close() } } - - newCall(request, requestOptions) - .enqueue( - object : Callback { - override fun onResponse(call: Call, response: Response) { - future.complete(response.toResponse()) - } + val call = newCall(request, requestOptions) + call.enqueue( + object : Callback { + override fun onResponse(call: Call, response: Response) { + future.complete(response.toResponse()) + } - override fun onFailure(call: Call, e: IOException) { - future.completeExceptionally(BraintrustIoException("Request failed", e)) - } + override fun onFailure(call: Call, e: IOException) { + future.completeExceptionally(BraintrustIoException("Request failed", e)) } - ) + } + ) + + future.whenComplete { _, e -> + if (e is CancellationException) { + call.cancel() + } + request.body?.close() + } return future } @@ -109,19 +115,19 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val val builder = Request.Builder().url(toUrl()).method(method.name, body) headers.names().forEach { name -> - headers.values(name).forEach { builder.header(name, it) } + headers.values(name).forEach { builder.addHeader(name, it) } } if ( !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 ) { - builder.header( + builder.addHeader( "X-Stainless-Read-Timeout", Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), ) } if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { - builder.header( + builder.addHeader( "X-Stainless-Timeout", Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), ) @@ -140,11 +146,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val } private fun HttpRequest.toUrl(): String { - url?.let { - return it - } - - val builder = baseUrl.newBuilder() + val builder = baseUrl.toHttpUrl().newBuilder() pathSegments.forEach(builder::addPathSegment) queryParams.keys().forEach { key -> queryParams.values(key).forEach { builder.addQueryParameter(key, it) } @@ -194,11 +196,11 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val class Builder internal constructor() { - private var baseUrl: HttpUrl? = null private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null - - fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() } + private var sslSocketFactory: SSLSocketFactory? = null + private var trustManager: X509TrustManager? = null + private var hostnameVerifier: HostnameVerifier? = null fun timeout(timeout: Timeout) = apply { this.timeout = timeout } @@ -206,6 +208,18 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } + fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply { + this.sslSocketFactory = sslSocketFactory + } + + fun trustManager(trustManager: X509TrustManager?) = apply { + this.trustManager = trustManager + } + + fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply { + this.hostnameVerifier = hostnameVerifier + } + fun build(): OkHttpClient = OkHttpClient( okhttp3.OkHttpClient.Builder() @@ -214,8 +228,25 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val .writeTimeout(timeout.write()) .callTimeout(timeout.request()) .proxy(proxy) - .build(), - checkRequired("baseUrl", baseUrl), + .apply { + val sslSocketFactory = sslSocketFactory + val trustManager = trustManager + if (sslSocketFactory != null && trustManager != null) { + sslSocketFactory(sslSocketFactory, trustManager) + } else { + check((sslSocketFactory != null) == (trustManager != null)) { + "Both or none of `sslSocketFactory` and `trustManager` must be set, but only one was set" + } + } + + hostnameVerifier?.let(::hostnameVerifier) + } + .build() + .apply { + // We usually make all our requests to the same host so it makes sense to + // raise the per-host limit to the overall limit. + dispatcher.maxRequestsPerHost = dispatcher.maxRequests + } ) } } diff --git a/braintrust-java-client-okhttp/src/test/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClientTest.kt b/braintrust-java-client-okhttp/src/test/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClientTest.kt new file mode 100644 index 00000000..ed9f0458 --- /dev/null +++ b/braintrust-java-client-okhttp/src/test/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClientTest.kt @@ -0,0 +1,44 @@ +package com.braintrustdata.api.client.okhttp + +import com.braintrustdata.api.core.http.HttpMethod +import com.braintrustdata.api.core.http.HttpRequest +import com.github.tomakehurst.wiremock.client.WireMock.* +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.ResourceLock + +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class OkHttpClientTest { + + private lateinit var baseUrl: String + private lateinit var httpClient: OkHttpClient + + @BeforeEach + fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) { + baseUrl = wmRuntimeInfo.httpBaseUrl + httpClient = OkHttpClient.builder().build() + } + + @Test + fun executeAsync_whenFutureCancelled_cancelsUnderlyingCall() { + stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) + val responseFuture = + httpClient.executeAsync( + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build() + ) + val call = httpClient.okHttpClient.dispatcher.runningCalls().single() + + responseFuture.cancel(false) + + // Should have cancelled the underlying call + assertThat(call.isCanceled()).isTrue() + } +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt index bc327480..7881923e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.client +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.services.blocking.AclService import com.braintrustdata.api.services.blocking.AiSecretService import com.braintrustdata.api.services.blocking.ApiKeyService @@ -21,6 +22,7 @@ import com.braintrustdata.api.services.blocking.SpanIframeService import com.braintrustdata.api.services.blocking.TopLevelService import com.braintrustdata.api.services.blocking.UserService import com.braintrustdata.api.services.blocking.ViewService +import java.util.function.Consumer /** * A client for interacting with the Braintrust REST API synchronously. You can also switch to @@ -51,6 +53,13 @@ interface BraintrustClient { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): BraintrustClient + fun topLevel(): TopLevelService fun projects(): ProjectService @@ -105,6 +114,13 @@ interface BraintrustClient { /** A view of [BraintrustClient] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): BraintrustClient.WithRawResponse + fun topLevel(): TopLevelService.WithRawResponse fun projects(): ProjectService.WithRawResponse diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt index 24ed3368..c6edb032 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.client +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.services.async.AclServiceAsync import com.braintrustdata.api.services.async.AiSecretServiceAsync import com.braintrustdata.api.services.async.ApiKeyServiceAsync @@ -21,6 +22,7 @@ import com.braintrustdata.api.services.async.SpanIframeServiceAsync import com.braintrustdata.api.services.async.TopLevelServiceAsync import com.braintrustdata.api.services.async.UserServiceAsync import com.braintrustdata.api.services.async.ViewServiceAsync +import java.util.function.Consumer /** * A client for interacting with the Braintrust REST API asynchronously. You can also switch to @@ -51,6 +53,13 @@ interface BraintrustClientAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): BraintrustClientAsync + fun topLevel(): TopLevelServiceAsync fun projects(): ProjectServiceAsync @@ -107,6 +116,15 @@ interface BraintrustClientAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): BraintrustClientAsync.WithRawResponse + fun topLevel(): TopLevelServiceAsync.WithRawResponse fun projects(): ProjectServiceAsync.WithRawResponse diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt index e945466b..2d94732b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt @@ -42,6 +42,7 @@ import com.braintrustdata.api.services.async.UserServiceAsync import com.braintrustdata.api.services.async.UserServiceAsyncImpl import com.braintrustdata.api.services.async.ViewServiceAsync import com.braintrustdata.api.services.async.ViewServiceAsyncImpl +import java.util.function.Consumer class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : BraintrustClientAsync { @@ -130,6 +131,9 @@ class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : Brai override fun withRawResponse(): BraintrustClientAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): BraintrustClientAsync = + BraintrustClientAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun topLevel(): TopLevelServiceAsync = topLevel override fun projects(): ProjectServiceAsync = projects @@ -168,7 +172,7 @@ class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : Brai override fun evals(): EvalServiceAsync = evals - override fun close() = clientOptions.httpClient.close() + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BraintrustClientAsync.WithRawResponse { @@ -249,6 +253,13 @@ class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : Brai EvalServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + override fun withOptions( + modifier: Consumer + ): BraintrustClientAsync.WithRawResponse = + BraintrustClientAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + override fun topLevel(): TopLevelServiceAsync.WithRawResponse = topLevel override fun projects(): ProjectServiceAsync.WithRawResponse = projects diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt index 3eecd3cb..c205ae48 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt @@ -42,6 +42,7 @@ import com.braintrustdata.api.services.blocking.UserService import com.braintrustdata.api.services.blocking.UserServiceImpl import com.braintrustdata.api.services.blocking.ViewService import com.braintrustdata.api.services.blocking.ViewServiceImpl +import java.util.function.Consumer class BraintrustClientImpl(private val clientOptions: ClientOptions) : BraintrustClient { @@ -118,6 +119,9 @@ class BraintrustClientImpl(private val clientOptions: ClientOptions) : Braintrus override fun withRawResponse(): BraintrustClient.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): BraintrustClient = + BraintrustClientImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun topLevel(): TopLevelService = topLevel override fun projects(): ProjectService = projects @@ -156,7 +160,7 @@ class BraintrustClientImpl(private val clientOptions: ClientOptions) : Braintrus override fun evals(): EvalService = evals - override fun close() = clientOptions.httpClient.close() + override fun close() = clientOptions.close() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BraintrustClient.WithRawResponse { @@ -237,6 +241,13 @@ class BraintrustClientImpl(private val clientOptions: ClientOptions) : Braintrus EvalServiceImpl.WithRawResponseImpl(clientOptions) } + override fun withOptions( + modifier: Consumer + ): BraintrustClient.WithRawResponse = + BraintrustClientImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + override fun topLevel(): TopLevelService.WithRawResponse = topLevel override fun projects(): ProjectService.WithRawResponse = projects diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPager.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPager.kt new file mode 100644 index 00000000..d208a9f8 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPager.kt @@ -0,0 +1,21 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class AutoPager private constructor(private val firstPage: Page) : Iterable { + + companion object { + + fun from(firstPage: Page): AutoPager = AutoPager(firstPage) + } + + override fun iterator(): Iterator = + generateSequence(firstPage) { if (it.hasNextPage()) it.nextPage() else null } + .flatMap { it.items() } + .iterator() + + fun stream(): Stream = StreamSupport.stream(spliterator(), false) +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPagerAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPagerAsync.kt new file mode 100644 index 00000000..7ff270b1 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPagerAsync.kt @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +import com.braintrustdata.api.core.http.AsyncStreamResponse +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.CompletionException +import java.util.concurrent.Executor +import java.util.concurrent.atomic.AtomicReference + +class AutoPagerAsync +private constructor(private val firstPage: PageAsync, private val defaultExecutor: Executor) : + AsyncStreamResponse { + + companion object { + + fun from(firstPage: PageAsync, defaultExecutor: Executor): AutoPagerAsync = + AutoPagerAsync(firstPage, defaultExecutor) + } + + private val onCompleteFuture = CompletableFuture() + private val state = AtomicReference(State.NEW) + + override fun subscribe(handler: AsyncStreamResponse.Handler): AsyncStreamResponse = + subscribe(handler, defaultExecutor) + + override fun subscribe( + handler: AsyncStreamResponse.Handler, + executor: Executor, + ): AsyncStreamResponse = apply { + // TODO(JDK): Use `compareAndExchange` once targeting JDK 9. + check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) { + if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once" + else "Cannot subscribe after the response is closed" + } + + fun PageAsync.handle(): CompletableFuture { + if (state.get() == State.CLOSED) { + return CompletableFuture.completedFuture(null) + } + + items().forEach { handler.onNext(it) } + return if (hasNextPage()) nextPage().thenCompose { it.handle() } + else CompletableFuture.completedFuture(null) + } + + executor.execute { + firstPage.handle().whenComplete { _, error -> + val actualError = + if (error is CompletionException && error.cause != null) error.cause else error + try { + handler.onComplete(Optional.ofNullable(actualError)) + } finally { + try { + if (actualError == null) { + onCompleteFuture.complete(null) + } else { + onCompleteFuture.completeExceptionally(actualError) + } + } finally { + close() + } + } + } + } + } + + override fun onCompleteFuture(): CompletableFuture = onCompleteFuture + + override fun close() { + val previousState = state.getAndSet(State.CLOSED) + if (previousState == State.CLOSED) { + return + } + + // When the stream is closed, we should always consider it closed. If it closed due + // to an error, then we will have already completed the future earlier, and this + // will be a no-op. + onCompleteFuture.complete(null) + } +} + +private enum class State { + NEW, + SUBSCRIBED, + CLOSED, +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt index 7b05d4da..254bc88e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt @@ -5,6 +5,9 @@ package com.braintrustdata.api.core import com.fasterxml.jackson.core.Version import com.fasterxml.jackson.core.util.VersionUtil +fun checkRequired(name: String, condition: Boolean) = + check(condition) { "`$name` is required, but was not set" } + fun checkRequired(name: String, value: T?): T = checkNotNull(value) { "`$name` is required, but was not set" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt index 9841ea6e..e77958a6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.core +import com.braintrustdata.api.core.http.AsyncStreamResponse import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.HttpClient import com.braintrustdata.api.core.http.PhantomReachableClosingHttpClient @@ -9,21 +10,102 @@ import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.http.RetryingHttpClient import com.fasterxml.jackson.databind.json.JsonMapper import java.time.Clock +import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors +import java.util.concurrent.ThreadFactory +import java.util.concurrent.atomic.AtomicLong import kotlin.jvm.optionals.getOrNull +/** A class representing the SDK client configuration. */ class ClientOptions private constructor( private val originalHttpClient: HttpClient, + /** + * The HTTP client to use in the SDK. + * + * Use the one published in `braintrust-java-client-okhttp` or implement your own. + * + * This class takes ownership of the client and closes it when closed. + */ @get:JvmName("httpClient") val httpClient: HttpClient, + /** + * Whether to throw an exception if any of the Jackson versions detected at runtime are + * incompatible with the SDK's minimum supported Jackson version (2.13.4). + * + * Defaults to true. Use extreme caution when disabling this option. There is no guarantee that + * the SDK will work correctly when using an incompatible Jackson version. + */ @get:JvmName("checkJacksonVersionCompatibility") val checkJacksonVersionCompatibility: Boolean, + /** + * The Jackson JSON mapper to use for serializing and deserializing JSON. + * + * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient and + * rarely needs to be overridden. + */ @get:JvmName("jsonMapper") val jsonMapper: JsonMapper, + /** + * The executor to use for running [AsyncStreamResponse.Handler] callbacks. + * + * Defaults to a dedicated cached thread pool. + * + * This class takes ownership of the executor and shuts it down, if possible, when closed. + */ + @get:JvmName("streamHandlerExecutor") val streamHandlerExecutor: Executor, + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + @get:JvmName("sleeper") val sleeper: Sleeper, + /** + * The clock to use for operations that require timing, like retries. + * + * This is primarily useful for using a fake clock in tests. + * + * Defaults to [Clock.systemUTC]. + */ @get:JvmName("clock") val clock: Clock, - @get:JvmName("baseUrl") val baseUrl: String, + private val baseUrl: String?, + /** Headers to send with the request. */ @get:JvmName("headers") val headers: Headers, + /** Query params to send with the request. */ @get:JvmName("queryParams") val queryParams: QueryParams, + /** + * Whether to call `validate` on every response before returning it. + * + * Defaults to false, which means the shape of the response will not be validated upfront. + * Instead, validation will only occur for the parts of the response that are accessed. + */ @get:JvmName("responseValidation") val responseValidation: Boolean, + /** + * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding + * retries. + * + * Defaults to [Timeout.default]. + */ @get:JvmName("timeout") val timeout: Timeout, + /** + * The maximum number of times to retry failed requests, with a short exponential backoff + * between requests. + * + * Only the following error types are retried: + * - Connection errors (for example, due to a network connectivity problem) + * - 408 Request Timeout + * - 409 Conflict + * - 429 Rate Limit + * - 5xx Internal + * + * The API may also explicitly instruct the SDK to retry or not retry a request. + * + * Defaults to 2. + */ @get:JvmName("maxRetries") val maxRetries: Int, private val apiKey: String?, ) { @@ -34,6 +116,13 @@ private constructor( } } + /** + * The base URL to use for every request. + * + * Defaults to the production environment: `https://api.braintrust.dev`. + */ + fun baseUrl(): String = baseUrl ?: PRODUCTION_URL + fun apiKey(): Optional = Optional.ofNullable(apiKey) fun toBuilder() = Builder().from(this) @@ -52,6 +141,11 @@ private constructor( */ @JvmStatic fun builder() = Builder() + /** + * Returns options configured using system properties and environment variables. + * + * @see Builder.fromEnv + */ @JvmStatic fun fromEnv(): ClientOptions = builder().fromEnv().build() } @@ -61,8 +155,10 @@ private constructor( private var httpClient: HttpClient? = null private var checkJacksonVersionCompatibility: Boolean = true private var jsonMapper: JsonMapper = jsonMapper() + private var streamHandlerExecutor: Executor? = null + private var sleeper: Sleeper? = null private var clock: Clock = Clock.systemUTC() - private var baseUrl: String = PRODUCTION_URL + private var baseUrl: String? = null private var headers: Headers.Builder = Headers.builder() private var queryParams: QueryParams.Builder = QueryParams.builder() private var responseValidation: Boolean = false @@ -75,6 +171,8 @@ private constructor( httpClient = clientOptions.originalHttpClient checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility jsonMapper = clientOptions.jsonMapper + streamHandlerExecutor = clientOptions.streamHandlerExecutor + sleeper = clientOptions.sleeper clock = clientOptions.clock baseUrl = clientOptions.baseUrl headers = clientOptions.headers.toBuilder() @@ -85,24 +183,122 @@ private constructor( apiKey = clientOptions.apiKey } - fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } + /** + * The HTTP client to use in the SDK. + * + * Use the one published in `braintrust-java-client-okhttp` or implement your own. + * + * This class takes ownership of the client and closes it when closed. + */ + fun httpClient(httpClient: HttpClient) = apply { + this.httpClient = PhantomReachableClosingHttpClient(httpClient) + } + /** + * Whether to throw an exception if any of the Jackson versions detected at runtime are + * incompatible with the SDK's minimum supported Jackson version (2.13.4). + * + * Defaults to true. Use extreme caution when disabling this option. There is no guarantee + * that the SDK will work correctly when using an incompatible Jackson version. + */ fun checkJacksonVersionCompatibility(checkJacksonVersionCompatibility: Boolean) = apply { this.checkJacksonVersionCompatibility = checkJacksonVersionCompatibility } + /** + * The Jackson JSON mapper to use for serializing and deserializing JSON. + * + * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient + * and rarely needs to be overridden. + */ fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper } + /** + * The executor to use for running [AsyncStreamResponse.Handler] callbacks. + * + * Defaults to a dedicated cached thread pool. + * + * This class takes ownership of the executor and shuts it down, if possible, when closed. + */ + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = + if (streamHandlerExecutor is ExecutorService) + PhantomReachableExecutorService(streamHandlerExecutor) + else streamHandlerExecutor + } + + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { this.sleeper = PhantomReachableSleeper(sleeper) } + + /** + * The clock to use for operations that require timing, like retries. + * + * This is primarily useful for using a fake clock in tests. + * + * Defaults to [Clock.systemUTC]. + */ fun clock(clock: Clock) = apply { this.clock = clock } - fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl } + /** + * The base URL to use for every request. + * + * Defaults to the production environment: `https://api.braintrust.dev`. + */ + fun baseUrl(baseUrl: String?) = apply { this.baseUrl = baseUrl } + + /** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */ + fun baseUrl(baseUrl: Optional) = baseUrl(baseUrl.getOrNull()) + /** + * Whether to call `validate` on every response before returning it. + * + * Defaults to false, which means the shape of the response will not be validated upfront. + * Instead, validation will only occur for the parts of the response that are accessed. + */ fun responseValidation(responseValidation: Boolean) = apply { this.responseValidation = responseValidation } + /** + * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding + * retries. + * + * Defaults to [Timeout.default]. + */ fun timeout(timeout: Timeout) = apply { this.timeout = timeout } + /** + * Sets the maximum time allowed for a complete HTTP call, not including retries. + * + * See [Timeout.request] for more details. + * + * For fine-grained control, pass a [Timeout] object. + */ + fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build()) + + /** + * The maximum number of times to retry failed requests, with a short exponential backoff + * between requests. + * + * Only the following error types are retried: + * - Connection errors (for example, due to a network connectivity problem) + * - 408 Request Timeout + * - 409 Conflict + * - 429 Rate Limit + * - 5xx Internal + * + * The API may also explicitly instruct the SDK to retry or not retry a request. + * + * Defaults to 2. + */ fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries } fun apiKey(apiKey: String?) = apply { this.apiKey = apiKey } @@ -190,11 +386,26 @@ private constructor( fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } - fun baseUrl(): String = baseUrl + fun timeout(): Timeout = timeout + /** + * Updates configuration using system properties and environment variables. + * + * See this table for the available options: + * + * |Setter |System property |Environment variable |Required|Default value | + * |---------|--------------------|---------------------|--------|------------------------------| + * |`apiKey` |`braintrust.apiKey` |`BRAINTRUST_API_KEY` |false |- | + * |`baseUrl`|`braintrust.baseUrl`|`BRAINTRUST_BASE_URL`|true |`"https://api.braintrust.dev"`| + * + * System properties take precedence over environment variables. + */ fun fromEnv() = apply { - System.getenv("BRAINTRUST_BASE_URL")?.let { baseUrl(it) } - System.getenv("BRAINTRUST_API_KEY")?.let { apiKey(it) } + (System.getProperty("braintrust.baseUrl") ?: System.getenv("BRAINTRUST_BASE_URL")) + ?.let { baseUrl(it) } + (System.getProperty("braintrust.apiKey") ?: System.getenv("BRAINTRUST_API_KEY"))?.let { + apiKey(it) + } } /** @@ -211,6 +422,25 @@ private constructor( */ fun build(): ClientOptions { val httpClient = checkRequired("httpClient", httpClient) + val streamHandlerExecutor = + streamHandlerExecutor + ?: PhantomReachableExecutorService( + Executors.newCachedThreadPool( + object : ThreadFactory { + + private val threadFactory: ThreadFactory = + Executors.defaultThreadFactory() + private val count = AtomicLong(0) + + override fun newThread(runnable: Runnable): Thread = + threadFactory.newThread(runnable).also { + it.name = + "braintrust-stream-handler-thread-${count.getAndIncrement()}" + } + } + ) + ) + val sleeper = sleeper ?: PhantomReachableSleeper(DefaultSleeper()) val headers = Headers.builder() val queryParams = QueryParams.builder() @@ -231,15 +461,16 @@ private constructor( return ClientOptions( httpClient, - PhantomReachableClosingHttpClient( - RetryingHttpClient.builder() - .httpClient(httpClient) - .clock(clock) - .maxRetries(maxRetries) - .build() - ), + RetryingHttpClient.builder() + .httpClient(httpClient) + .sleeper(sleeper) + .clock(clock) + .maxRetries(maxRetries) + .build(), checkJacksonVersionCompatibility, jsonMapper, + streamHandlerExecutor, + sleeper, clock, baseUrl, headers.build(), @@ -251,4 +482,20 @@ private constructor( ) } } + + /** + * Closes these client options, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because the client options are + * long-lived and usually should not be synchronously closed via try-with-resources. + * + * It's also usually not necessary to call this method at all. the default client automatically + * releases threads and connections if they remain idle, but if you are writing an application + * that needs to aggressively release unused resources, then you may call this method. + */ + fun close() { + httpClient.close() + (streamHandlerExecutor as? ExecutorService)?.shutdown() + sleeper.close() + } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/DefaultSleeper.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/DefaultSleeper.kt new file mode 100644 index 00000000..32ece057 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/DefaultSleeper.kt @@ -0,0 +1,28 @@ +package com.braintrustdata.api.core + +import java.time.Duration +import java.util.Timer +import java.util.TimerTask +import java.util.concurrent.CompletableFuture + +class DefaultSleeper : Sleeper { + + private val timer = Timer("DefaultSleeper", true) + + override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) + + override fun sleepAsync(duration: Duration): CompletableFuture { + val future = CompletableFuture() + timer.schedule( + object : TimerTask() { + override fun run() { + future.complete(null) + } + }, + duration.toMillis(), + ) + return future + } + + override fun close() = timer.cancel() +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Page.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Page.kt new file mode 100644 index 00000000..5d5afd20 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Page.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +/** + * An interface representing a single page, with items of type [T], from a paginated endpoint + * response. + * + * Implementations of this interface are expected to request additional pages synchronously. For + * asynchronous pagination, see the [PageAsync] interface. + */ +interface Page { + + /** + * Returns whether there's another page after this one. + * + * The method generally doesn't make requests so the result depends entirely on the data in this + * page. If a significant amount of time has passed between requesting this page and calling + * this method, then the result could be stale. + */ + fun hasNextPage(): Boolean + + /** + * Returns the page after this one by making another request. + * + * @throws IllegalStateException if it's impossible to get the next page. This exception is + * avoidable by calling [hasNextPage] first. + */ + fun nextPage(): Page + + /** Returns the items in this page. */ + fun items(): List +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PageAsync.kt new file mode 100644 index 00000000..10b3b47a --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PageAsync.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +import java.util.concurrent.CompletableFuture + +/** + * An interface representing a single page, with items of type [T], from a paginated endpoint + * response. + * + * Implementations of this interface are expected to request additional pages asynchronously. For + * synchronous pagination, see the [Page] interface. + */ +interface PageAsync { + + /** + * Returns whether there's another page after this one. + * + * The method generally doesn't make requests so the result depends entirely on the data in this + * page. If a significant amount of time has passed between requesting this page and calling + * this method, then the result could be stale. + */ + fun hasNextPage(): Boolean + + /** + * Returns the page after this one by making another request. + * + * @throws IllegalStateException if it's impossible to get the next page. This exception is + * avoidable by calling [hasNextPage] first. + */ + fun nextPage(): CompletableFuture> + + /** Returns the items in this page. */ + fun items(): List +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableExecutorService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableExecutorService.kt new file mode 100644 index 00000000..0538d523 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableExecutorService.kt @@ -0,0 +1,58 @@ +package com.braintrustdata.api.core + +import java.util.concurrent.Callable +import java.util.concurrent.ExecutorService +import java.util.concurrent.Future +import java.util.concurrent.TimeUnit + +/** + * A delegating wrapper around an [ExecutorService] that shuts it down once it's only phantom + * reachable. + * + * This class ensures the [ExecutorService] is shut down even if the user forgets to do it. + */ +internal class PhantomReachableExecutorService(private val executorService: ExecutorService) : + ExecutorService { + init { + closeWhenPhantomReachable(this) { executorService.shutdown() } + } + + override fun execute(command: Runnable) = executorService.execute(command) + + override fun shutdown() = executorService.shutdown() + + override fun shutdownNow(): MutableList = executorService.shutdownNow() + + override fun isShutdown(): Boolean = executorService.isShutdown + + override fun isTerminated(): Boolean = executorService.isTerminated + + override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean = + executorService.awaitTermination(timeout, unit) + + override fun submit(task: Callable): Future = executorService.submit(task) + + override fun submit(task: Runnable, result: T): Future = + executorService.submit(task, result) + + override fun submit(task: Runnable): Future<*> = executorService.submit(task) + + override fun invokeAll( + tasks: MutableCollection> + ): MutableList> = executorService.invokeAll(tasks) + + override fun invokeAll( + tasks: MutableCollection>, + timeout: Long, + unit: TimeUnit, + ): MutableList> = executorService.invokeAll(tasks, timeout, unit) + + override fun invokeAny(tasks: MutableCollection>): T = + executorService.invokeAny(tasks) + + override fun invokeAny( + tasks: MutableCollection>, + timeout: Long, + unit: TimeUnit, + ): T = executorService.invokeAny(tasks, timeout, unit) +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableSleeper.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableSleeper.kt new file mode 100644 index 00000000..8c293f53 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableSleeper.kt @@ -0,0 +1,23 @@ +package com.braintrustdata.api.core + +import java.time.Duration +import java.util.concurrent.CompletableFuture + +/** + * A delegating wrapper around a [Sleeper] that closes it once it's only phantom reachable. + * + * This class ensures the [Sleeper] is closed even if the user forgets to do it. + */ +internal class PhantomReachableSleeper(private val sleeper: Sleeper) : Sleeper { + + init { + closeWhenPhantomReachable(this, sleeper) + } + + override fun sleep(duration: Duration) = sleeper.sleep(duration) + + override fun sleepAsync(duration: Duration): CompletableFuture = + sleeper.sleepAsync(duration) + + override fun close() = sleeper.close() +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Properties.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Properties.kt index a0924603..5130de1b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Properties.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Properties.kt @@ -2,7 +2,7 @@ package com.braintrustdata.api.core -import java.util.Properties +import com.braintrustdata.api.client.BraintrustClient fun getOsArch(): String { val osArch = System.getProperty("os.arch") @@ -16,7 +16,7 @@ fun getOsArch(): String { "x86_64" -> "x64" "arm" -> "arm" "aarch64" -> "arm64" - else -> "other:${osArch}" + else -> "other:$osArch" } } @@ -30,13 +30,13 @@ fun getOsName(): String { osName.startsWith("Linux") -> "Linux" osName.startsWith("Mac OS") -> "MacOS" osName.startsWith("Windows") -> "Windows" - else -> "Other:${osName}" + else -> "Other:$osName" } } fun getOsVersion(): String = System.getProperty("os.version", "unknown") fun getPackageVersion(): String = - Properties::class.java.`package`.implementationVersion ?: "unknown" + BraintrustClient::class.java.`package`.implementationVersion ?: "unknown" fun getJavaVersion(): String = System.getProperty("java.version", "unknown") diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Sleeper.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Sleeper.kt new file mode 100644 index 00000000..856b4009 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Sleeper.kt @@ -0,0 +1,21 @@ +package com.braintrustdata.api.core + +import java.time.Duration +import java.util.concurrent.CompletableFuture + +/** + * An interface for delaying execution for a specified amount of time. + * + * Useful for testing and cleaning up resources. + */ +interface Sleeper : AutoCloseable { + + /** Synchronously pauses execution for the given [duration]. */ + fun sleep(duration: Duration) + + /** Asynchronously pauses execution for the given [duration]. */ + fun sleepAsync(duration: Duration): CompletableFuture + + /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */ + override fun close() +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt index 06ee42fa..b2320ac8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt @@ -157,10 +157,14 @@ private constructor( return true } - return /* spotless:off */ other is Timeout && connect == other.connect && read == other.read && write == other.write && request == other.request /* spotless:on */ + return other is Timeout && + connect == other.connect && + read == other.read && + write == other.write && + request == other.request } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(connect, read, write, request) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(connect, read, write, request) override fun toString() = "Timeout{connect=$connect, read=$read, write=$write, request=$request}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt index 6f9fb155..a1657ff3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt @@ -5,6 +5,8 @@ package com.braintrustdata.api.core import com.braintrustdata.api.errors.BraintrustInvalidDataException import java.util.Collections import java.util.SortedMap +import java.util.concurrent.CompletableFuture +import java.util.concurrent.locks.Lock @JvmSynthetic internal fun T?.getOrThrow(name: String): T = @@ -90,3 +92,24 @@ internal fun Any?.contentToString(): String { } internal interface Enum + +/** + * Executes the given [action] while holding the lock, returning a [CompletableFuture] with the + * result. + * + * @param action The asynchronous action to execute while holding the lock + * @return A [CompletableFuture] that completes with the result of the action + */ +@JvmSynthetic +internal fun Lock.withLockAsync(action: () -> CompletableFuture): CompletableFuture { + lock() + val future = + try { + action() + } catch (e: Throwable) { + unlock() + throw e + } + future.whenComplete { _, _ -> unlock() } + return future +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt index f3b14814..67559b98 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt @@ -19,7 +19,7 @@ import com.braintrustdata.api.errors.UnprocessableEntityException import com.fasterxml.jackson.databind.json.JsonMapper @JvmSynthetic -internal fun errorHandler(jsonMapper: JsonMapper): Handler { +internal fun errorBodyHandler(jsonMapper: JsonMapper): Handler { val handler = jsonHandler(jsonMapper) return object : Handler { @@ -33,52 +33,52 @@ internal fun errorHandler(jsonMapper: JsonMapper): Handler { } @JvmSynthetic -internal fun Handler.withErrorHandler(errorHandler: Handler): Handler = - object : Handler { - override fun handle(response: HttpResponse): T = +internal fun errorHandler(errorBodyHandler: Handler): Handler = + object : Handler { + override fun handle(response: HttpResponse): HttpResponse = when (val statusCode = response.statusCode()) { - in 200..299 -> this@withErrorHandler.handle(response) + in 200..299 -> response 400 -> throw BadRequestException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 401 -> throw UnauthorizedException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 403 -> throw PermissionDeniedException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 404 -> throw NotFoundException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 422 -> throw UnprocessableEntityException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 429 -> throw RateLimitException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() in 500..599 -> throw InternalServerException.builder() .statusCode(statusCode) .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() else -> throw UnexpectedStatusCodeException.builder() .statusCode(statusCode) .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt new file mode 100644 index 00000000..93dff9ec --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt @@ -0,0 +1,157 @@ +package com.braintrustdata.api.core.http + +import com.braintrustdata.api.core.http.AsyncStreamResponse.Handler +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.concurrent.atomic.AtomicReference + +/** + * A class providing access to an API response as an asynchronous stream of chunks of type [T], + * where each chunk can be individually processed as soon as it arrives instead of waiting on the + * full response. + */ +interface AsyncStreamResponse { + + /** + * Registers [handler] to be called for events of this stream. + * + * [handler]'s methods will be called in the client's configured or default thread pool. + * + * @throws IllegalStateException if [subscribe] has already been called. + */ + fun subscribe(handler: Handler): AsyncStreamResponse + + /** + * Registers [handler] to be called for events of this stream. + * + * [handler]'s methods will be called in the given [executor]. + * + * @throws IllegalStateException if [subscribe] has already been called. + */ + fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse + + /** + * Returns a future that completes when a stream is fully consumed, errors, or gets closed + * early. + */ + fun onCompleteFuture(): CompletableFuture + + /** + * Closes this resource, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because this response should not be + * synchronously closed via try-with-resources. + */ + fun close() + + /** A class for handling streaming events. */ + fun interface Handler { + + /** Called whenever a chunk is received. */ + fun onNext(value: T) + + /** + * Called when a stream is fully consumed, errors, or gets closed early. + * + * [onNext] will not be called once this method is called. + * + * @param error Non-empty if the stream completed due to an error. + */ + fun onComplete(error: Optional) {} + } +} + +@JvmSynthetic +internal fun CompletableFuture>.toAsync(streamHandlerExecutor: Executor) = + PhantomReachableClosingAsyncStreamResponse( + object : AsyncStreamResponse { + + private val onCompleteFuture = CompletableFuture() + private val state = AtomicReference(State.NEW) + + init { + this@toAsync.whenComplete { _, error -> + // If an error occurs from the original future, then we should resolve the + // `onCompleteFuture` even if `subscribe` has not been called. + error?.let(onCompleteFuture::completeExceptionally) + } + } + + override fun subscribe(handler: Handler): AsyncStreamResponse = + subscribe(handler, streamHandlerExecutor) + + override fun subscribe( + handler: Handler, + executor: Executor, + ): AsyncStreamResponse = apply { + // TODO(JDK): Use `compareAndExchange` once targeting JDK 9. + check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) { + if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once" + else "Cannot subscribe after the response is closed" + } + + this@toAsync.whenCompleteAsync( + { streamResponse, futureError -> + if (state.get() == State.CLOSED) { + // Avoid doing any work if `close` was called before the future + // completed. + return@whenCompleteAsync + } + + if (futureError != null) { + // An error occurred before we started passing chunks to the handler. + handler.onComplete(Optional.of(futureError)) + return@whenCompleteAsync + } + + var streamError: Throwable? = null + try { + streamResponse.stream().forEach(handler::onNext) + } catch (e: Throwable) { + streamError = e + } + + try { + handler.onComplete(Optional.ofNullable(streamError)) + } finally { + try { + // Notify completion via the `onCompleteFuture` as well. This is in + // a separate `try-finally` block so that we still complete the + // future if `handler.onComplete` throws. + if (streamError == null) { + onCompleteFuture.complete(null) + } else { + onCompleteFuture.completeExceptionally(streamError) + } + } finally { + close() + } + } + }, + executor, + ) + } + + override fun onCompleteFuture(): CompletableFuture = onCompleteFuture + + override fun close() { + val previousState = state.getAndSet(State.CLOSED) + if (previousState == State.CLOSED) { + return + } + + this@toAsync.whenComplete { streamResponse, error -> streamResponse?.close() } + // When the stream is closed, we should always consider it closed. If it closed due + // to an error, then we will have already completed the future earlier, and this + // will be a no-op. + onCompleteFuture.complete(null) + } + } + ) + +private enum class State { + NEW, + SUBSCRIBED, + CLOSED, +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt index 6d37e804..774088ec 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt @@ -1,5 +1,15 @@ +// File generated from our OpenAPI spec by Stainless. + package com.braintrustdata.api.core.http +import com.braintrustdata.api.core.JsonArray +import com.braintrustdata.api.core.JsonBoolean +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonNull +import com.braintrustdata.api.core.JsonNumber +import com.braintrustdata.api.core.JsonObject +import com.braintrustdata.api.core.JsonString +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.toImmutable import java.util.TreeMap @@ -28,6 +38,19 @@ private constructor( TreeMap(String.CASE_INSENSITIVE_ORDER) private var size: Int = 0 + fun put(name: String, value: JsonValue): Builder = apply { + when (value) { + is JsonMissing, + is JsonNull -> {} + is JsonBoolean -> put(name, value.value.toString()) + is JsonNumber -> put(name, value.value.toString()) + is JsonString -> put(name, value.value) + is JsonArray -> value.values.forEach { put(name, it) } + is JsonObject -> + value.values.forEach { (nestedName, value) -> put("$name.$nestedName", value) } + } + } + fun put(name: String, value: String) = apply { map.getOrPut(name) { mutableListOf() }.add(value) size++ @@ -41,15 +64,6 @@ private constructor( headers.names().forEach { put(it, headers.values(it)) } } - fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size } - - fun removeAll(names: Set) = apply { names.forEach(::remove) } - - fun clear() = apply { - map.clear() - size = 0 - } - fun replace(name: String, value: String) = apply { remove(name) put(name, value) @@ -68,6 +82,15 @@ private constructor( headers.names().forEach { replace(it, headers.values(it)) } } + fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size } + + fun removeAll(names: Set) = apply { names.forEach(::remove) } + + fun clear() = apply { + map.clear() + size = 0 + } + fun build() = Headers( map.mapValuesTo(TreeMap(String.CASE_INSENSITIVE_ORDER)) { (_, values) -> diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt index 1105f7d4..f3c2522c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt @@ -6,7 +6,7 @@ import com.braintrustdata.api.core.toImmutable class HttpRequest private constructor( @get:JvmName("method") val method: HttpMethod, - @get:JvmName("url") val url: String?, + @get:JvmName("baseUrl") val baseUrl: String, @get:JvmName("pathSegments") val pathSegments: List, @get:JvmName("headers") val headers: Headers, @get:JvmName("queryParams") val queryParams: QueryParams, @@ -16,7 +16,7 @@ private constructor( fun toBuilder(): Builder = Builder().from(this) override fun toString(): String = - "HttpRequest{method=$method, url=$url, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}" + "HttpRequest{method=$method, baseUrl=$baseUrl, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}" companion object { @JvmStatic fun builder() = Builder() @@ -25,7 +25,7 @@ private constructor( class Builder internal constructor() { private var method: HttpMethod? = null - private var url: String? = null + private var baseUrl: String? = null private var pathSegments: MutableList = mutableListOf() private var headers: Headers.Builder = Headers.builder() private var queryParams: QueryParams.Builder = QueryParams.builder() @@ -34,7 +34,7 @@ private constructor( @JvmSynthetic internal fun from(request: HttpRequest) = apply { method = request.method - url = request.url + baseUrl = request.baseUrl pathSegments = request.pathSegments.toMutableList() headers = request.headers.toBuilder() queryParams = request.queryParams.toBuilder() @@ -43,7 +43,7 @@ private constructor( fun method(method: HttpMethod) = apply { this.method = method } - fun url(url: String) = apply { this.url = url } + fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl } fun addPathSegment(pathSegment: String) = apply { pathSegments.add(pathSegment) } @@ -136,7 +136,7 @@ private constructor( fun build(): HttpRequest = HttpRequest( checkRequired("method", method), - url, + checkRequired("baseUrl", baseUrl), pathSegments.toImmutable(), headers.build(), queryParams.build(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt new file mode 100644 index 00000000..6d826dd4 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt @@ -0,0 +1,56 @@ +package com.braintrustdata.api.core.http + +import com.braintrustdata.api.core.closeWhenPhantomReachable +import com.braintrustdata.api.core.http.AsyncStreamResponse.Handler +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor + +/** + * A delegating wrapper around an `AsyncStreamResponse` that closes it once it's only phantom + * reachable. + * + * This class ensures the `AsyncStreamResponse` is closed even if the user forgets to close it. + */ +internal class PhantomReachableClosingAsyncStreamResponse( + private val asyncStreamResponse: AsyncStreamResponse +) : AsyncStreamResponse { + + /** + * An object used for keeping `asyncStreamResponse` open while the object is still reachable. + */ + private val reachabilityTracker = Object() + + init { + closeWhenPhantomReachable(reachabilityTracker, asyncStreamResponse::close) + } + + override fun subscribe(handler: Handler): AsyncStreamResponse = apply { + asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker)) + } + + override fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse = + apply { + asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker), executor) + } + + override fun onCompleteFuture(): CompletableFuture = + asyncStreamResponse.onCompleteFuture() + + override fun close() = asyncStreamResponse.close() +} + +/** + * A wrapper around a `Handler` that also references a `reachabilityTracker` object. + * + * Referencing the `reachabilityTracker` object prevents it from getting reclaimed while the handler + * is still reachable. + */ +private class TrackedHandler( + private val handler: Handler, + private val reachabilityTracker: Any, +) : Handler { + override fun onNext(value: T) = handler.onNext(value) + + override fun onComplete(error: Optional) = handler.onComplete(error) +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingStreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingStreamResponse.kt new file mode 100644 index 00000000..9c79ceb6 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingStreamResponse.kt @@ -0,0 +1,21 @@ +package com.braintrustdata.api.core.http + +import com.braintrustdata.api.core.closeWhenPhantomReachable +import java.util.stream.Stream + +/** + * A delegating wrapper around a `StreamResponse` that closes it once it's only phantom reachable. + * + * This class ensures the `StreamResponse` is closed even if the user forgets to close it. + */ +internal class PhantomReachableClosingStreamResponse( + private val streamResponse: StreamResponse +) : StreamResponse { + init { + closeWhenPhantomReachable(this, streamResponse) + } + + override fun stream(): Stream = streamResponse.stream() + + override fun close() = streamResponse.close() +} diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt index 03c719df..60103d82 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt @@ -2,6 +2,14 @@ package com.braintrustdata.api.core.http +import com.braintrustdata.api.core.JsonArray +import com.braintrustdata.api.core.JsonBoolean +import com.braintrustdata.api.core.JsonMissing +import com.braintrustdata.api.core.JsonNull +import com.braintrustdata.api.core.JsonNumber +import com.braintrustdata.api.core.JsonObject +import com.braintrustdata.api.core.JsonString +import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.toImmutable class QueryParams @@ -28,6 +36,39 @@ private constructor( private val map: MutableMap> = mutableMapOf() private var size: Int = 0 + fun put(key: String, value: JsonValue): Builder = apply { + when (value) { + is JsonMissing, + is JsonNull -> {} + is JsonBoolean -> put(key, value.value.toString()) + is JsonNumber -> put(key, value.value.toString()) + is JsonString -> put(key, value.value) + is JsonArray -> + put( + key, + value.values + .asSequence() + .mapNotNull { + when (it) { + is JsonMissing, + is JsonNull -> null + is JsonBoolean -> it.value.toString() + is JsonNumber -> it.value.toString() + is JsonString -> it.value + is JsonArray, + is JsonObject -> + throw IllegalArgumentException( + "Cannot comma separate non-primitives in query params" + ) + } + } + .joinToString(","), + ) + is JsonObject -> + value.values.forEach { (nestedKey, value) -> put("$key[$nestedKey]", value) } + } + } + fun put(key: String, value: String) = apply { map.getOrPut(key) { mutableListOf() }.add(value) size++ diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt index 830c55cc..5bdca25d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt @@ -1,8 +1,11 @@ package com.braintrustdata.api.core.http +import com.braintrustdata.api.core.DefaultSleeper import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.Sleeper import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.errors.BraintrustIoException +import com.braintrustdata.api.errors.BraintrustRetryableException import java.io.IOException import java.time.Clock import java.time.Duration @@ -10,8 +13,6 @@ import java.time.OffsetDateTime import java.time.format.DateTimeFormatter import java.time.format.DateTimeParseException import java.time.temporal.ChronoUnit -import java.util.Timer -import java.util.TimerTask import java.util.UUID import java.util.concurrent.CompletableFuture import java.util.concurrent.ThreadLocalRandom @@ -129,7 +130,10 @@ private constructor( return executeWithRetries(modifiedRequest, requestOptions) } - override fun close() = httpClient.close() + override fun close() { + httpClient.close() + sleeper.close() + } private fun isRetryable(request: HttpRequest): Boolean = // Some requests, such as when a request body is being streamed, cannot be retried because @@ -176,9 +180,10 @@ private constructor( } private fun shouldRetry(throwable: Throwable): Boolean = - // Only retry IOException and BraintrustIoException, other exceptions are not intended to be - // retried. - throwable is IOException || throwable is BraintrustIoException + // Only retry known retryable exceptions, other exceptions are not intended to be retried. + throwable is IOException || + throwable is BraintrustIoException || + throwable is BraintrustRetryableException private fun getRetryBackoffDuration(retries: Int, response: HttpResponse?): Duration { // About the Retry-After header: @@ -233,33 +238,14 @@ private constructor( class Builder internal constructor() { private var httpClient: HttpClient? = null - private var sleeper: Sleeper = - object : Sleeper { - - private val timer = Timer("RetryingHttpClient", true) - - override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) - - override fun sleepAsync(duration: Duration): CompletableFuture { - val future = CompletableFuture() - timer.schedule( - object : TimerTask() { - override fun run() { - future.complete(null) - } - }, - duration.toMillis(), - ) - return future - } - } + private var sleeper: Sleeper? = null private var clock: Clock = Clock.systemUTC() private var maxRetries: Int = 2 private var idempotencyHeader: String? = null fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } - @JvmSynthetic internal fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } + fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } fun clock(clock: Clock) = apply { this.clock = clock } @@ -270,17 +256,10 @@ private constructor( fun build(): HttpClient = RetryingHttpClient( checkRequired("httpClient", httpClient), - sleeper, + sleeper ?: DefaultSleeper(), clock, maxRetries, idempotencyHeader, ) } - - internal interface Sleeper { - - fun sleep(duration: Duration) - - fun sleepAsync(duration: Duration): CompletableFuture - } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/StreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/StreamResponse.kt new file mode 100644 index 00000000..3903400b --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/StreamResponse.kt @@ -0,0 +1,19 @@ +package com.braintrustdata.api.core.http + +import java.util.stream.Stream + +interface StreamResponse : AutoCloseable { + + fun stream(): Stream + + /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */ + override fun close() +} + +@JvmSynthetic +internal fun StreamResponse.map(transform: (T) -> R): StreamResponse = + object : StreamResponse { + override fun stream(): Stream = this@map.stream().map(transform) + + override fun close() = this@map.close() + } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt new file mode 100644 index 00000000..e70380e9 --- /dev/null +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt @@ -0,0 +1,15 @@ +package com.braintrustdata.api.errors + +/** + * Exception that indicates a transient error that can be retried. + * + * When this exception is thrown during an HTTP request, the SDK will automatically retry the + * request up to the maximum number of retries. + * + * @param message A descriptive error message + * @param cause The underlying cause of this exception, if any + */ +class BraintrustRetryableException +@JvmOverloads +constructor(message: String? = null, cause: Throwable? = null) : + BraintrustException(message, cause) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt index f5ad5a1b..a47ab007 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class AISecret +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -507,12 +508,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -524,12 +523,31 @@ private constructor( return true } - return /* spotless:off */ other is AISecret && id == other.id && name == other.name && orgId == other.orgId && created == other.created && metadata == other.metadata && previewSecret == other.previewSecret && type == other.type && updatedAt == other.updatedAt && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AISecret && + id == other.id && + name == other.name && + orgId == other.orgId && + created == other.created && + metadata == other.metadata && + previewSecret == other.previewSecret && + type == other.type && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, orgId, created, metadata, previewSecret, type, updatedAt, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + orgId, + created, + metadata, + previewSecret, + type, + updatedAt, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt index 34941085..9175b110 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt @@ -29,6 +29,7 @@ import kotlin.jvm.optionals.getOrNull * ACL, as part of a direct permission grant or as part of a role. */ class Acl +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _objectOrgId: JsonField, @@ -553,12 +554,35 @@ private constructor( return true } - return /* spotless:off */ other is Acl && id == other.id && _objectOrgId == other._objectOrgId && objectId == other.objectId && objectType == other.objectType && created == other.created && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Acl && + id == other.id && + _objectOrgId == other._objectOrgId && + objectId == other.objectId && + objectType == other.objectType && + created == other.created && + groupId == other.groupId && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + roleId == other.roleId && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _objectOrgId, objectId, objectType, created, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _objectOrgId, + objectId, + objectType, + created, + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt index 3276e25a..d8471677 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt @@ -79,8 +79,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -318,6 +320,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val addAcls: JsonField>, private val removeAcls: JsonField>, @@ -560,12 +563,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && addAcls == other.addAcls && removeAcls == other.removeAcls && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + addAcls == other.addAcls && + removeAcls == other.removeAcls && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addAcls, removeAcls, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(addAcls, removeAcls, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -584,6 +590,7 @@ private constructor( * ACL, as part of a direct permission grant or as part of a role. */ class AddAcl + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -1004,12 +1011,29 @@ private constructor( return true } - return /* spotless:off */ other is AddAcl && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddAcl && + objectId == other.objectId && + objectType == other.objectType && + groupId == other.groupId && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + roleId == other.roleId && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1028,6 +1052,7 @@ private constructor( * ACL, as part of a direct permission grant or as part of a role. */ class RemoveAcl + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -1448,12 +1473,29 @@ private constructor( return true } - return /* spotless:off */ other is RemoveAcl && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RemoveAcl && + objectId == other.objectId && + objectType == other.objectType && + groupId == other.groupId && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + roleId == other.roleId && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1466,10 +1508,13 @@ private constructor( return true } - return /* spotless:off */ other is AclBatchUpdateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AclBatchUpdateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "AclBatchUpdateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt index 901575b1..a7429202 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class AclBatchUpdateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val addedAcls: JsonField>, private val removedAcls: JsonField>, @@ -266,12 +267,13 @@ private constructor( return true } - return /* spotless:off */ other is AclBatchUpdateResponse && addedAcls == other.addedAcls && removedAcls == other.removedAcls && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AclBatchUpdateResponse && + addedAcls == other.addedAcls && + removedAcls == other.removedAcls && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(addedAcls, removedAcls, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt index 88196664..93d86eaf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt @@ -140,8 +140,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -452,6 +454,7 @@ private constructor( * ACL, as part of a direct permission grant or as part of a role. */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -872,13 +875,30 @@ private constructor( return true } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + objectId == other.objectId && + objectType == other.objectType && + groupId == other.groupId && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + roleId == other.roleId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -890,10 +910,13 @@ private constructor( return true } - return /* spotless:off */ other is AclCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AclCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "AclCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt index 9b05873d..1e13b46a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete an acl object by its id */ class AclDeleteParams private constructor( - private val aclId: String, + private val aclId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Acl id */ - fun aclId(): String = aclId + fun aclId(): Optional = Optional.ofNullable(aclId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [AclDeleteParams]. - * - * The following fields are required: - * ```java - * .aclId() - * ``` - */ + @JvmStatic fun none(): AclDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [AclDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Acl id */ - fun aclId(aclId: String) = apply { this.aclId = aclId } + fun aclId(aclId: String?) = apply { this.aclId = aclId } + + /** Alias for calling [Builder.aclId] with `aclId.orElse(null)`. */ + fun aclId(aclId: Optional) = aclId(aclId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [AclDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .aclId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): AclDeleteParams = AclDeleteParams( - checkRequired("aclId", aclId), + aclId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> aclId + 0 -> aclId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is AclDeleteParams && aclId == other.aclId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is AclDeleteParams && + aclId == other.aclId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(aclId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "AclDeleteParams{aclId=$aclId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt index 05969c71..4241a5ff 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt @@ -137,8 +137,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -453,6 +455,7 @@ private constructor( * ACL, as part of a direct permission grant or as part of a role. */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -873,13 +876,30 @@ private constructor( return true } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + objectId == other.objectId && + objectType == other.objectType && + groupId == other.groupId && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + roleId == other.roleId && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + objectId, + objectType, + groupId, + permission, + restrictObjectType, + roleId, + userId, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -891,10 +911,13 @@ private constructor( return true } - return /* spotless:off */ other is AclFindAndDeleteParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AclFindAndDeleteParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "AclFindAndDeleteParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt index fd5ac29d..8938e4ed 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt @@ -2,48 +2,42 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.AclService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [AclService.list] */ +/** @see AclService.list */ class AclListPage private constructor( private val service: AclService, private val params: AclListParams, private val response: AclListPageResponse, -) { +) : Page { /** * Delegates to [AclListPageResponse], but gracefully handles missing data. * - * @see [AclListPageResponse.objects] + * @see AclListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): AclListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): AclListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): AclListParams = params @@ -112,34 +106,18 @@ private constructor( ) } - class AutoPager(private val firstPage: AclListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AclListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is AclListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "AclListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt index 20160da8..def7bff5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt @@ -2,52 +2,45 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.AclServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [AclServiceAsync.list] */ +/** @see AclServiceAsync.list */ class AclListPageAsync private constructor( private val service: AclServiceAsync, + private val streamHandlerExecutor: Executor, private val params: AclListParams, private val response: AclListPageResponse, -) { +) : PageAsync { /** * Delegates to [AclListPageResponse], but gracefully handles missing data. * - * @see [AclListPageResponse.objects] + * @see AclListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): AclListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): AclListParams = params @@ -65,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -76,18 +70,24 @@ private constructor( class Builder internal constructor() { private var service: AclServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: AclListParams? = null private var response: AclListPageResponse? = null @JvmSynthetic internal fun from(aclListPageAsync: AclListPageAsync) = apply { service = aclListPageAsync.service + streamHandlerExecutor = aclListPageAsync.streamHandlerExecutor params = aclListPageAsync.params response = aclListPageAsync.response } fun service(service: AclServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: AclListParams) = apply { this.params = params } @@ -102,6 +102,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -111,47 +112,26 @@ private constructor( fun build(): AclListPageAsync = AclListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: AclListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Acl) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AclListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is AclListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "AclListPageAsync{service=$service, params=$params, response=$response}" + "AclListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt index 63b51fd2..b1cc5192 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class AclListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is AclListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AclListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt index 238ae30f..d0fefc9b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt @@ -7,6 +7,7 @@ import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -60,8 +61,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -346,10 +349,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -362,7 +365,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -379,10 +382,28 @@ private constructor( return true } - return /* spotless:off */ other is AclListParams && objectId == other.objectId && objectType == other.objectType && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AclListParams && + objectId == other.objectId && + objectType == other.objectType && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objectId, objectType, endingBefore, ids, limit, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + objectId, + objectType, + endingBefore, + ids, + limit, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "AclListParams{objectId=$objectId, objectType=$objectType, endingBefore=$endingBefore, ids=$ids, limit=$limit, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt index 727accde..d70f1270 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt @@ -179,7 +179,7 @@ class AclObjectType @JsonCreator private constructor(private val value: JsonFiel return true } - return /* spotless:off */ other is AclObjectType && value == other.value /* spotless:on */ + return other is AclObjectType && value == other.value } override fun hashCode() = value.hashCode() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt index ab43fccb..553c84c3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an acl object by its id */ class AclRetrieveParams private constructor( - private val aclId: String, + private val aclId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Acl id */ - fun aclId(): String = aclId + fun aclId(): Optional = Optional.ofNullable(aclId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [AclRetrieveParams]. - * - * The following fields are required: - * ```java - * .aclId() - * ``` - */ + @JvmStatic fun none(): AclRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [AclRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Acl id */ - fun aclId(aclId: String) = apply { this.aclId = aclId } + fun aclId(aclId: String?) = apply { this.aclId = aclId } + + /** Alias for calling [Builder.aclId] with `aclId.orElse(null)`. */ + fun aclId(aclId: Optional) = aclId(aclId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [AclRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .aclId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): AclRetrieveParams = - AclRetrieveParams( - checkRequired("aclId", aclId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + AclRetrieveParams(aclId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> aclId + 0 -> aclId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is AclRetrieveParams && aclId == other.aclId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AclRetrieveParams && + aclId == other.aclId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(aclId, additionalHeaders, additionalQueryParams) override fun toString() = "AclRetrieveParams{aclId=$aclId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt index 6a4e98f4..0fa8596a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt @@ -108,8 +108,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -372,6 +374,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val metadata: JsonField, @@ -672,12 +675,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && metadata == other.metadata && orgName == other.orgName && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + metadata == other.metadata && + orgName == other.orgName && + secret == other.secret && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, metadata, orgName, secret, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, metadata, orgName, secret, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -774,12 +783,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -791,10 +798,13 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AiSecretCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "AiSecretCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt index c0e7a074..61a67496 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete an ai_secret object by its id */ class AiSecretDeleteParams private constructor( - private val aiSecretId: String, + private val aiSecretId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** AiSecret id */ - fun aiSecretId(): String = aiSecretId + fun aiSecretId(): Optional = Optional.ofNullable(aiSecretId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [AiSecretDeleteParams]. - * - * The following fields are required: - * ```java - * .aiSecretId() - * ``` - */ + @JvmStatic fun none(): AiSecretDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [AiSecretDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** AiSecret id */ - fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId } + fun aiSecretId(aiSecretId: String?) = apply { this.aiSecretId = aiSecretId } + + /** Alias for calling [Builder.aiSecretId] with `aiSecretId.orElse(null)`. */ + fun aiSecretId(aiSecretId: Optional) = aiSecretId(aiSecretId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [AiSecretDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .aiSecretId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): AiSecretDeleteParams = AiSecretDeleteParams( - checkRequired("aiSecretId", aiSecretId), + aiSecretId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> aiSecretId + 0 -> aiSecretId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretDeleteParams && aiSecretId == other.aiSecretId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is AiSecretDeleteParams && + aiSecretId == other.aiSecretId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "AiSecretDeleteParams{aiSecretId=$aiSecretId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt index 83d28e3b..7e4aa36a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt @@ -62,8 +62,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -278,6 +280,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val orgName: JsonField, @@ -462,12 +465,13 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + orgName == other.orgName && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -480,10 +484,13 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretFindAndDeleteParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AiSecretFindAndDeleteParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "AiSecretFindAndDeleteParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt index 021f2341..b3de4d4f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.AiSecretService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [AiSecretService.list] */ +/** @see AiSecretService.list */ class AiSecretListPage private constructor( private val service: AiSecretService, private val params: AiSecretListParams, private val response: AiSecretListPageResponse, -) { +) : Page { /** * Delegates to [AiSecretListPageResponse], but gracefully handles missing data. * - * @see [AiSecretListPageResponse.objects] + * @see AiSecretListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): AiSecretListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): AiSecretListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): AiSecretListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: AiSecretListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AiSecretListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is AiSecretListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "AiSecretListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt index 597dd9cd..535d9386 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.AiSecretServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [AiSecretServiceAsync.list] */ +/** @see AiSecretServiceAsync.list */ class AiSecretListPageAsync private constructor( private val service: AiSecretServiceAsync, + private val streamHandlerExecutor: Executor, private val params: AiSecretListParams, private val response: AiSecretListPageResponse, -) { +) : PageAsync { /** * Delegates to [AiSecretListPageResponse], but gracefully handles missing data. * - * @see [AiSecretListPageResponse.objects] + * @see AiSecretListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): AiSecretListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): AiSecretListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: AiSecretServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: AiSecretListParams? = null private var response: AiSecretListPageResponse? = null @JvmSynthetic internal fun from(aiSecretListPageAsync: AiSecretListPageAsync) = apply { service = aiSecretListPageAsync.service + streamHandlerExecutor = aiSecretListPageAsync.streamHandlerExecutor params = aiSecretListPageAsync.params response = aiSecretListPageAsync.response } fun service(service: AiSecretServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: AiSecretListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): AiSecretListPageAsync = AiSecretListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: AiSecretListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (AISecret) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is AiSecretListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is AiSecretListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "AiSecretListPageAsync{service=$service, params=$params, response=$response}" + "AiSecretListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt index 57a8dde7..5d469b49 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class AiSecretListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AiSecretListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt index dd7ef4bd..d57cd54f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -62,8 +63,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -363,10 +366,10 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretType && string == other.string && strings == other.strings /* spotless:on */ + return other is AiSecretType && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -379,7 +382,8 @@ private constructor( @JvmStatic fun ofString(string: String) = AiSecretType(string = string) - @JvmStatic fun ofStrings(strings: List) = AiSecretType(strings = strings) + @JvmStatic + fun ofStrings(strings: List) = AiSecretType(strings = strings.toImmutable()) } /** @@ -428,10 +432,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -444,7 +448,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -461,10 +465,30 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretListParams && aiSecretName == other.aiSecretName && aiSecretType == other.aiSecretType && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AiSecretListParams && + aiSecretName == other.aiSecretName && + aiSecretType == other.aiSecretType && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretName, aiSecretType, endingBefore, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + aiSecretName, + aiSecretType, + endingBefore, + ids, + limit, + orgName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "AiSecretListParams{aiSecretName=$aiSecretName, aiSecretType=$aiSecretType, endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt index af588655..b73cb945 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt @@ -108,8 +108,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -372,6 +374,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val metadata: JsonField, @@ -672,12 +675,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && metadata == other.metadata && orgName == other.orgName && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + metadata == other.metadata && + orgName == other.orgName && + secret == other.secret && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, metadata, orgName, secret, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, metadata, orgName, secret, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -774,12 +783,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -791,10 +798,13 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AiSecretReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "AiSecretReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt index 551f4d43..c52011db 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an ai_secret object by its id */ class AiSecretRetrieveParams private constructor( - private val aiSecretId: String, + private val aiSecretId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** AiSecret id */ - fun aiSecretId(): String = aiSecretId + fun aiSecretId(): Optional = Optional.ofNullable(aiSecretId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [AiSecretRetrieveParams]. - * - * The following fields are required: - * ```java - * .aiSecretId() - * ``` - */ + @JvmStatic fun none(): AiSecretRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [AiSecretRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** AiSecret id */ - fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId } + fun aiSecretId(aiSecretId: String?) = apply { this.aiSecretId = aiSecretId } + + /** Alias for calling [Builder.aiSecretId] with `aiSecretId.orElse(null)`. */ + fun aiSecretId(aiSecretId: Optional) = aiSecretId(aiSecretId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [AiSecretRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .aiSecretId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): AiSecretRetrieveParams = AiSecretRetrieveParams( - checkRequired("aiSecretId", aiSecretId), + aiSecretId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> aiSecretId + 0 -> aiSecretId ?: "" else -> "" } @@ -188,10 +182,14 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretRetrieveParams && aiSecretId == other.aiSecretId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AiSecretRetrieveParams && + aiSecretId == other.aiSecretId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams) override fun toString() = "AiSecretRetrieveParams{aiSecretId=$aiSecretId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt index 4db720cf..6bd772e6 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable @@ -28,14 +27,14 @@ import kotlin.jvm.optionals.getOrNull */ class AiSecretUpdateParams private constructor( - private val aiSecretId: String, + private val aiSecretId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** AiSecret id */ - fun aiSecretId(): String = aiSecretId + fun aiSecretId(): Optional = Optional.ofNullable(aiSecretId) /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -93,22 +92,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [AiSecretUpdateParams]. - * - * The following fields are required: - * ```java - * .aiSecretId() - * ``` - */ + @JvmStatic fun none(): AiSecretUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [AiSecretUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -129,7 +125,10 @@ private constructor( } /** AiSecret id */ - fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId } + fun aiSecretId(aiSecretId: String?) = apply { this.aiSecretId = aiSecretId } + + /** Alias for calling [Builder.aiSecretId] with `aiSecretId.orElse(null)`. */ + fun aiSecretId(aiSecretId: Optional) = aiSecretId(aiSecretId.getOrNull()) /** * Sets the entire request body. @@ -318,17 +317,10 @@ private constructor( * Returns an immutable instance of [AiSecretUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .aiSecretId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): AiSecretUpdateParams = AiSecretUpdateParams( - checkRequired("aiSecretId", aiSecretId), + aiSecretId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -339,7 +331,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> aiSecretId + 0 -> aiSecretId ?: "" else -> "" } @@ -348,6 +340,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val metadata: JsonField, private val name: JsonField, @@ -581,12 +574,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && metadata == other.metadata && name == other.name && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + metadata == other.metadata && + name == other.name && + secret == other.secret && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, name, secret, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(metadata, name, secret, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -683,12 +681,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -700,10 +696,15 @@ private constructor( return true } - return /* spotless:off */ other is AiSecretUpdateParams && aiSecretId == other.aiSecretId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is AiSecretUpdateParams && + aiSecretId == other.aiSecretId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(aiSecretId, body, additionalHeaders, additionalQueryParams) override fun toString() = "AiSecretUpdateParams{aiSecretId=$aiSecretId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt index 17e11b99..4d05c260 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ApiKey +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -346,12 +347,19 @@ private constructor( return true } - return /* spotless:off */ other is ApiKey && id == other.id && name == other.name && previewName == other.previewName && created == other.created && orgId == other.orgId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ApiKey && + id == other.id && + name == other.name && + previewName == other.previewName && + created == other.created && + orgId == other.orgId && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, previewName, created, orgId, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, name, previewName, created, orgId, userId, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt index 236d29be..5d6c5394 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt @@ -65,8 +65,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -281,6 +283,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val orgName: JsonField, @@ -465,12 +468,13 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + orgName == other.orgName && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -483,10 +487,13 @@ private constructor( return true } - return /* spotless:off */ other is ApiKeyCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ApiKeyCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ApiKeyCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt index 908060c2..f3add49a 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete an api_key object by its id */ class ApiKeyDeleteParams private constructor( - private val apiKeyId: String, + private val apiKeyId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** ApiKey id */ - fun apiKeyId(): String = apiKeyId + fun apiKeyId(): Optional = Optional.ofNullable(apiKeyId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ApiKeyDeleteParams]. - * - * The following fields are required: - * ```java - * .apiKeyId() - * ``` - */ + @JvmStatic fun none(): ApiKeyDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ApiKeyDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** ApiKey id */ - fun apiKeyId(apiKeyId: String) = apply { this.apiKeyId = apiKeyId } + fun apiKeyId(apiKeyId: String?) = apply { this.apiKeyId = apiKeyId } + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [ApiKeyDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .apiKeyId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ApiKeyDeleteParams = ApiKeyDeleteParams( - checkRequired("apiKeyId", apiKeyId), + apiKeyId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> apiKeyId + 0 -> apiKeyId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is ApiKeyDeleteParams && apiKeyId == other.apiKeyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is ApiKeyDeleteParams && + apiKeyId == other.apiKeyId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "ApiKeyDeleteParams{apiKeyId=$apiKeyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt index 0aeea56f..230a76da 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ApiKeyService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [ApiKeyService.list] */ +/** @see ApiKeyService.list */ class ApiKeyListPage private constructor( private val service: ApiKeyService, private val params: ApiKeyListParams, private val response: ApiKeyListPageResponse, -) { +) : Page { /** * Delegates to [ApiKeyListPageResponse], but gracefully handles missing data. * - * @see [ApiKeyListPageResponse.objects] + * @see ApiKeyListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ApiKeyListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ApiKeyListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ApiKeyListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: ApiKeyListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ApiKeyListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ApiKeyListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ApiKeyListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt index 5bc2cbe9..4cb580a2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt @@ -2,53 +2,46 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ApiKeyServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [ApiKeyServiceAsync.list] */ +/** @see ApiKeyServiceAsync.list */ class ApiKeyListPageAsync private constructor( private val service: ApiKeyServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ApiKeyListParams, private val response: ApiKeyListPageResponse, -) { +) : PageAsync { /** * Delegates to [ApiKeyListPageResponse], but gracefully handles missing data. * - * @see [ApiKeyListPageResponse.objects] + * @see ApiKeyListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ApiKeyListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ApiKeyListParams = params @@ -66,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +71,24 @@ private constructor( class Builder internal constructor() { private var service: ApiKeyServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ApiKeyListParams? = null private var response: ApiKeyListPageResponse? = null @JvmSynthetic internal fun from(apiKeyListPageAsync: ApiKeyListPageAsync) = apply { service = apiKeyListPageAsync.service + streamHandlerExecutor = apiKeyListPageAsync.streamHandlerExecutor params = apiKeyListPageAsync.params response = apiKeyListPageAsync.response } fun service(service: ApiKeyServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ApiKeyListParams) = apply { this.params = params } @@ -103,6 +103,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +113,26 @@ private constructor( fun build(): ApiKeyListPageAsync = ApiKeyListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: ApiKeyListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (ApiKey) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ApiKeyListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ApiKeyListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "ApiKeyListPageAsync{service=$service, params=$params, response=$response}" + "ApiKeyListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt index 9c42308a..367f30ff 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ApiKeyListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is ApiKeyListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ApiKeyListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt index a1fcb296..8615dda7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -59,8 +60,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -337,10 +340,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -353,7 +356,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -370,10 +373,28 @@ private constructor( return true } - return /* spotless:off */ other is ApiKeyListParams && apiKeyName == other.apiKeyName && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ApiKeyListParams && + apiKeyName == other.apiKeyName && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeyName, endingBefore, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + apiKeyName, + endingBefore, + ids, + limit, + orgName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ApiKeyListParams{apiKeyName=$apiKeyName, endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt index de3cb891..4a7aa490 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an api_key object by its id */ class ApiKeyRetrieveParams private constructor( - private val apiKeyId: String, + private val apiKeyId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** ApiKey id */ - fun apiKeyId(): String = apiKeyId + fun apiKeyId(): Optional = Optional.ofNullable(apiKeyId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ApiKeyRetrieveParams]. - * - * The following fields are required: - * ```java - * .apiKeyId() - * ``` - */ + @JvmStatic fun none(): ApiKeyRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ApiKeyRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** ApiKey id */ - fun apiKeyId(apiKeyId: String) = apply { this.apiKeyId = apiKeyId } + fun apiKeyId(apiKeyId: String?) = apply { this.apiKeyId = apiKeyId } + + /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */ + fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [ApiKeyRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .apiKeyId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ApiKeyRetrieveParams = - ApiKeyRetrieveParams( - checkRequired("apiKeyId", apiKeyId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + ApiKeyRetrieveParams(apiKeyId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> apiKeyId + 0 -> apiKeyId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is ApiKeyRetrieveParams && apiKeyId == other.apiKeyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ApiKeyRetrieveParams && + apiKeyId == other.apiKeyId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams) override fun toString() = "ApiKeyRetrieveParams{apiKeyId=$apiKeyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt index d7fb8bd9..eb663486 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ChatCompletionContentPartImage +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val imageUrl: JsonField, private val type: JsonField, @@ -191,6 +192,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class ImageUrl + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val url: JsonField, private val detail: JsonField, @@ -483,7 +485,7 @@ private constructor( return true } - return /* spotless:off */ other is Detail && value == other.value /* spotless:on */ + return other is Detail && value == other.value } override fun hashCode() = value.hashCode() @@ -496,12 +498,13 @@ private constructor( return true } - return /* spotless:off */ other is ImageUrl && url == other.url && detail == other.detail && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ImageUrl && + url == other.url && + detail == other.detail && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(url, detail, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -622,7 +625,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -635,12 +638,13 @@ private constructor( return true } - return /* spotless:off */ other is ChatCompletionContentPartImage && imageUrl == other.imageUrl && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ChatCompletionContentPartImage && + imageUrl == other.imageUrl && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(imageUrl, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt index 7452ab93..dfeea28c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ChatCompletionContentPartText +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val text: JsonField, @@ -298,7 +299,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -311,12 +312,13 @@ private constructor( return true } - return /* spotless:off */ other is ChatCompletionContentPartText && type == other.type && text == other.text && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ChatCompletionContentPartText && + type == other.type && + text == other.text && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, text, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt index fdd8a4d7..3f9bc106 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt @@ -18,6 +18,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ChatCompletionMessageToolCall +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val function: JsonField, @@ -221,6 +222,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val arguments: JsonField, private val name: JsonField, @@ -398,12 +400,13 @@ private constructor( return true } - return /* spotless:off */ other is Function && arguments == other.arguments && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + arguments == other.arguments && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(arguments, name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -524,7 +527,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -537,12 +540,14 @@ private constructor( return true } - return /* spotless:off */ other is ChatCompletionMessageToolCall && id == other.id && function == other.function && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ChatCompletionMessageToolCall && + id == other.id && + function == other.function && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, function, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt index d547c7a0..b21ccf20 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt @@ -30,6 +30,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class CodeBundle +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bundleId: JsonField, private val location: JsonField, @@ -363,10 +364,10 @@ private constructor( return true } - return /* spotless:off */ other is Location && experiment == other.experiment && function == other.function /* spotless:on */ + return other is Location && experiment == other.experiment && function == other.function } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experiment, function) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(experiment, function) override fun toString(): String = when { @@ -454,6 +455,7 @@ private constructor( } class Experiment + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val evalName: JsonField, private val position: JsonField, @@ -760,10 +762,10 @@ private constructor( return true } - return /* spotless:off */ other is Position && type == other.type && scorer == other.scorer /* spotless:on */ + return other is Position && type == other.type && scorer == other.scorer } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(type, scorer) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(type, scorer) override fun toString(): String = when { @@ -853,6 +855,7 @@ private constructor( } class Type + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -1120,7 +1123,7 @@ private constructor( return true } - return /* spotless:off */ other is InnerType && value == other.value /* spotless:on */ + return other is InnerType && value == other.value } override fun hashCode() = value.hashCode() @@ -1133,12 +1136,12 @@ private constructor( return true } - return /* spotless:off */ other is Type && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Type && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1147,6 +1150,7 @@ private constructor( } class Scorer + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val index: JsonField, private val type: JsonField, @@ -1451,7 +1455,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1464,12 +1468,15 @@ private constructor( return true } - return /* spotless:off */ other is Scorer && index == other.index && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scorer && + index == other.index && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(index, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(index, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1594,7 +1601,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1607,12 +1614,16 @@ private constructor( return true } - return /* spotless:off */ other is Experiment && evalName == other.evalName && position == other.position && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Experiment && + evalName == other.evalName && + position == other.position && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(evalName, position, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(evalName, position, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1621,6 +1632,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val index: JsonField, private val type: JsonField, @@ -1913,7 +1925,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1926,12 +1938,13 @@ private constructor( return true } - return /* spotless:off */ other is Function && index == other.index && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + index == other.index && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(index, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1941,6 +1954,7 @@ private constructor( } class RuntimeContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -2234,7 +2248,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -2247,12 +2261,13 @@ private constructor( return true } - return /* spotless:off */ other is RuntimeContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RuntimeContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2265,12 +2280,17 @@ private constructor( return true } - return /* spotless:off */ other is CodeBundle && bundleId == other.bundleId && location == other.location && runtimeContext == other.runtimeContext && preview == other.preview && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CodeBundle && + bundleId == other.bundleId && + location == other.location && + runtimeContext == other.runtimeContext && + preview == other.preview && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bundleId, location, runtimeContext, preview, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(bundleId, location, runtimeContext, preview, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt index 2cbb41ce..951173c8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class CreateApiKeyOutput +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val key: JsonField, @@ -381,12 +382,20 @@ private constructor( return true } - return /* spotless:off */ other is CreateApiKeyOutput && id == other.id && key == other.key && name == other.name && previewName == other.previewName && created == other.created && orgId == other.orgId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CreateApiKeyOutput && + id == other.id && + key == other.key && + name == other.name && + previewName == other.previewName && + created == other.created && + orgId == other.orgId && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, key, name, previewName, created, orgId, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, key, name, previewName, created, orgId, userId, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt index e258e247..fb130110 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt @@ -18,6 +18,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class CrossObjectInsertResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val dataset: JsonField, private val experiment: JsonField, @@ -322,12 +323,10 @@ private constructor( return true } - return /* spotless:off */ other is Dataset && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Dataset && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -424,12 +423,10 @@ private constructor( return true } - return /* spotless:off */ other is Experiment && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Experiment && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -526,12 +523,10 @@ private constructor( return true } - return /* spotless:off */ other is ProjectLogs && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectLogs && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -543,12 +538,16 @@ private constructor( return true } - return /* spotless:off */ other is CrossObjectInsertResponse && dataset == other.dataset && experiment == other.experiment && projectLogs == other.projectLogs && additionalProperties == other.additionalProperties /* spotless:on */ + return other is CrossObjectInsertResponse && + dataset == other.dataset && + experiment == other.experiment && + projectLogs == other.projectLogs && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(dataset, experiment, projectLogs, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(dataset, experiment, projectLogs, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt index e499cfa4..e2485a60 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt @@ -17,6 +17,7 @@ import java.util.Objects /** Summary of a dataset's data */ class DataSummary +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val totalRecords: JsonField, private val additionalProperties: MutableMap, @@ -164,12 +165,12 @@ private constructor( return true } - return /* spotless:off */ other is DataSummary && totalRecords == other.totalRecords && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DataSummary && + totalRecords == other.totalRecords && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(totalRecords, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt index 66fafea8..e7e950c6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class Dataset +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -512,12 +513,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -529,12 +528,31 @@ private constructor( return true } - return /* spotless:off */ other is Dataset && id == other.id && name == other.name && projectId == other.projectId && created == other.created && deletedAt == other.deletedAt && description == other.description && metadata == other.metadata && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Dataset && + id == other.id && + name == other.name && + projectId == other.projectId && + created == other.created && + deletedAt == other.deletedAt && + description == other.description && + metadata == other.metadata && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, projectId, created, deletedAt, description, metadata, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + projectId, + created, + deletedAt, + description, + metadata, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt index b082caaa..23585870 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt @@ -94,8 +94,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -338,6 +340,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -604,12 +607,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + description == other.description && + metadata == other.metadata && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, description, metadata, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, projectId, description, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -707,12 +715,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -724,10 +730,13 @@ private constructor( return true } - return /* spotless:off */ other is DatasetCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt index c4238c34..bd822a26 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a dataset object by its id */ class DatasetDeleteParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [DatasetDeleteParams]. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - */ + @JvmStatic fun none(): DatasetDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [DatasetDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [DatasetDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): DatasetDeleteParams = DatasetDeleteParams( - checkRequired("datasetId", datasetId), + datasetId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetDeleteParams && datasetId == other.datasetId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is DatasetDeleteParams && + datasetId == other.datasetId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(datasetId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "DatasetDeleteParams{datasetId=$datasetId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt index e3b2abfa..783c2948 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class DatasetEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _xactId: JsonField, @@ -624,6 +625,7 @@ private constructor( * must be strings */ class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val additionalProperties: MutableMap, @@ -753,12 +755,12 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && + model == other.model && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -771,12 +773,41 @@ private constructor( return true } - return /* spotless:off */ other is DatasetEvent && id == other.id && _xactId == other._xactId && created == other.created && datasetId == other.datasetId && projectId == other.projectId && rootSpanId == other.rootSpanId && spanId == other.spanId && expected == other.expected && input == other.input && isRoot == other.isRoot && metadata == other.metadata && origin == other.origin && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DatasetEvent && + id == other.id && + _xactId == other._xactId && + created == other.created && + datasetId == other.datasetId && + projectId == other.projectId && + rootSpanId == other.rootSpanId && + spanId == other.spanId && + expected == other.expected && + input == other.input && + isRoot == other.isRoot && + metadata == other.metadata && + origin == other.origin && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _xactId, created, datasetId, projectId, rootSpanId, spanId, expected, input, isRoot, metadata, origin, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _xactId, + created, + datasetId, + projectId, + rootSpanId, + spanId, + expected, + input, + isRoot, + metadata, + origin, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt index e313cd08..d0ac1c86 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt @@ -19,19 +19,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Log feedback for a set of dataset events */ class DatasetFeedbackParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) /** * A list of dataset feedback items @@ -50,8 +51,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -63,7 +66,6 @@ private constructor( * * The following fields are required: * ```java - * .datasetId() * .feedback() * ``` */ @@ -87,7 +89,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** * Sets the entire request body. @@ -243,7 +248,6 @@ private constructor( * * The following fields are required: * ```java - * .datasetId() * .feedback() * ``` * @@ -251,7 +255,7 @@ private constructor( */ fun build(): DatasetFeedbackParams = DatasetFeedbackParams( - checkRequired("datasetId", datasetId), + datasetId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -262,7 +266,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -271,6 +275,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val feedback: JsonField>, private val additionalProperties: MutableMap, @@ -435,12 +440,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + feedback == other.feedback && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -453,10 +458,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetFeedbackParams && datasetId == other.datasetId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetFeedbackParams && + datasetId == other.datasetId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetFeedbackParams{datasetId=$datasetId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt index ac9b82f8..38306f2a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects @@ -17,7 +16,7 @@ import kotlin.jvm.optionals.getOrNull */ class DatasetFetchParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val limit: Long?, private val maxRootSpanId: String?, private val maxXactId: String?, @@ -27,7 +26,7 @@ private constructor( ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) /** * limit the number of traces fetched @@ -81,22 +80,19 @@ private constructor( */ fun version(): Optional = Optional.ofNullable(version) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [DatasetFetchParams]. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - */ + @JvmStatic fun none(): DatasetFetchParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [DatasetFetchParams]. */ @JvmStatic fun builder() = Builder() } @@ -123,7 +119,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** * limit the number of traces fetched @@ -300,17 +299,10 @@ private constructor( * Returns an immutable instance of [DatasetFetchParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): DatasetFetchParams = DatasetFetchParams( - checkRequired("datasetId", datasetId), + datasetId, limit, maxRootSpanId, maxXactId, @@ -322,7 +314,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -344,10 +336,26 @@ private constructor( return true } - return /* spotless:off */ other is DatasetFetchParams && datasetId == other.datasetId && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetFetchParams && + datasetId == other.datasetId && + limit == other.limit && + maxRootSpanId == other.maxRootSpanId && + maxXactId == other.maxXactId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, limit, maxRootSpanId, maxXactId, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + datasetId, + limit, + maxRootSpanId, + maxXactId, + version, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "DatasetFetchParams{datasetId=$datasetId, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt index 6dd48c3a..955438aa 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class DatasetFetchPostParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) /** * An opaque string to be used as a cursor for the next page of results, in order from latest to @@ -148,22 +147,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [DatasetFetchPostParams]. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - */ + @JvmStatic fun none(): DatasetFetchPostParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [DatasetFetchPostParams]. */ @JvmStatic fun builder() = Builder() } @@ -184,7 +180,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** * Sets the entire request body. @@ -450,17 +449,10 @@ private constructor( * Returns an immutable instance of [DatasetFetchPostParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): DatasetFetchPostParams = DatasetFetchPostParams( - checkRequired("datasetId", datasetId), + datasetId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -471,7 +463,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -480,6 +472,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cursor: JsonField, private val limit: JsonField, @@ -866,12 +859,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + cursor == other.cursor && + limit == other.limit && + maxRootSpanId == other.maxRootSpanId && + maxXactId == other.maxXactId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -884,10 +883,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetFetchPostParams && datasetId == other.datasetId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetFetchPostParams && + datasetId == other.datasetId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetFetchPostParams{datasetId=$datasetId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt index 9156ab3c..b9537932 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetInsertParams.kt @@ -19,19 +19,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Insert a set of events into the dataset */ class DatasetInsertParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) /** * A list of dataset events to insert @@ -50,8 +51,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -63,7 +66,6 @@ private constructor( * * The following fields are required: * ```java - * .datasetId() * .events() * ``` */ @@ -87,7 +89,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** * Sets the entire request body. @@ -241,7 +246,6 @@ private constructor( * * The following fields are required: * ```java - * .datasetId() * .events() * ``` * @@ -249,7 +253,7 @@ private constructor( */ fun build(): DatasetInsertParams = DatasetInsertParams( - checkRequired("datasetId", datasetId), + datasetId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -260,7 +264,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -269,6 +273,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val additionalProperties: MutableMap, @@ -433,12 +438,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + events == other.events && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -450,10 +455,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetInsertParams && datasetId == other.datasetId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetInsertParams && + datasetId == other.datasetId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetInsertParams{datasetId=$datasetId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt index 9e96f20b..6c7094af 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.DatasetService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [DatasetService.list] */ +/** @see DatasetService.list */ class DatasetListPage private constructor( private val service: DatasetService, private val params: DatasetListParams, private val response: DatasetListPageResponse, -) { +) : Page { /** * Delegates to [DatasetListPageResponse], but gracefully handles missing data. * - * @see [DatasetListPageResponse.objects] + * @see DatasetListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): DatasetListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): DatasetListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): DatasetListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: DatasetListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is DatasetListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is DatasetListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "DatasetListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt index c7e230c8..b198e6a7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.DatasetServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [DatasetServiceAsync.list] */ +/** @see DatasetServiceAsync.list */ class DatasetListPageAsync private constructor( private val service: DatasetServiceAsync, + private val streamHandlerExecutor: Executor, private val params: DatasetListParams, private val response: DatasetListPageResponse, -) { +) : PageAsync { /** * Delegates to [DatasetListPageResponse], but gracefully handles missing data. * - * @see [DatasetListPageResponse.objects] + * @see DatasetListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): DatasetListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): DatasetListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: DatasetServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: DatasetListParams? = null private var response: DatasetListPageResponse? = null @JvmSynthetic internal fun from(datasetListPageAsync: DatasetListPageAsync) = apply { service = datasetListPageAsync.service + streamHandlerExecutor = datasetListPageAsync.streamHandlerExecutor params = datasetListPageAsync.params response = datasetListPageAsync.response } fun service(service: DatasetServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: DatasetListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): DatasetListPageAsync = DatasetListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: DatasetListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Dataset) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is DatasetListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is DatasetListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "DatasetListPageAsync{service=$service, params=$params, response=$response}" + "DatasetListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt index 303e25f0..cd29a6ab 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class DatasetListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is DatasetListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DatasetListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt index 5928e94b..cee6532b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -67,8 +68,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -365,10 +368,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -381,7 +384,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -398,10 +401,32 @@ private constructor( return true } - return /* spotless:off */ other is DatasetListParams && datasetName == other.datasetName && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && projectId == other.projectId && projectName == other.projectName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetListParams && + datasetName == other.datasetName && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectId == other.projectId && + projectName == other.projectName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetName, endingBefore, ids, limit, orgName, projectId, projectName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + datasetName, + endingBefore, + ids, + limit, + orgName, + projectId, + projectName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "DatasetListParams{datasetName=$datasetName, endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, projectId=$projectId, projectName=$projectName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt index 27bc2e38..2673f27c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a dataset object by its id */ class DatasetRetrieveParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [DatasetRetrieveParams]. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - */ + @JvmStatic fun none(): DatasetRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [DatasetRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [DatasetRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): DatasetRetrieveParams = DatasetRetrieveParams( - checkRequired("datasetId", datasetId), + datasetId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -188,10 +182,13 @@ private constructor( return true } - return /* spotless:off */ other is DatasetRetrieveParams && datasetId == other.datasetId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetRetrieveParams && + datasetId == other.datasetId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(datasetId, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetRetrieveParams{datasetId=$datasetId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt index 998d598b..daf714c8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetSummarizeParams.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects @@ -13,34 +12,31 @@ import kotlin.jvm.optionals.getOrNull /** Summarize dataset */ class DatasetSummarizeParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val summarizeData: Boolean?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) /** Whether to summarize the data. If false (or omitted), only the metadata will be returned. */ fun summarizeData(): Optional = Optional.ofNullable(summarizeData) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [DatasetSummarizeParams]. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - */ + @JvmStatic fun none(): DatasetSummarizeParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [DatasetSummarizeParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +57,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** * Whether to summarize the data. If false (or omitted), only the metadata will be returned. @@ -181,17 +180,10 @@ private constructor( * Returns an immutable instance of [DatasetSummarizeParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): DatasetSummarizeParams = DatasetSummarizeParams( - checkRequired("datasetId", datasetId), + datasetId, summarizeData, additionalHeaders.build(), additionalQueryParams.build(), @@ -200,7 +192,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -219,10 +211,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetSummarizeParams && datasetId == other.datasetId && summarizeData == other.summarizeData && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetSummarizeParams && + datasetId == other.datasetId && + summarizeData == other.summarizeData && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, summarizeData, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(datasetId, summarizeData, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetSummarizeParams{datasetId=$datasetId, summarizeData=$summarizeData, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt index 53ef6810..0e747c50 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable @@ -28,14 +27,14 @@ import kotlin.jvm.optionals.getOrNull */ class DatasetUpdateParams private constructor( - private val datasetId: String, + private val datasetId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Dataset id */ - fun datasetId(): String = datasetId + fun datasetId(): Optional = Optional.ofNullable(datasetId) /** * Textual description of the dataset @@ -84,22 +83,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [DatasetUpdateParams]. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - */ + @JvmStatic fun none(): DatasetUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [DatasetUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -120,7 +116,10 @@ private constructor( } /** Dataset id */ - fun datasetId(datasetId: String) = apply { this.datasetId = datasetId } + fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId } + + /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */ + fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull()) /** * Sets the entire request body. @@ -298,17 +297,10 @@ private constructor( * Returns an immutable instance of [DatasetUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .datasetId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): DatasetUpdateParams = DatasetUpdateParams( - checkRequired("datasetId", datasetId), + datasetId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -319,7 +311,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> datasetId + 0 -> datasetId ?: "" else -> "" } @@ -328,6 +320,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val description: JsonField, private val metadata: JsonField, @@ -540,12 +533,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + description == other.description && + metadata == other.metadata && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, metadata, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(description, metadata, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -643,12 +640,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -660,10 +655,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetUpdateParams && datasetId == other.datasetId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is DatasetUpdateParams && + datasetId == other.datasetId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) override fun toString() = "DatasetUpdateParams{datasetId=$datasetId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt index 6eed845c..354ddd66 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVar.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class EnvVar +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -473,7 +474,7 @@ private constructor( return true } - return /* spotless:off */ other is ObjectType && value == other.value /* spotless:on */ + return other is ObjectType && value == other.value } override fun hashCode() = value.hashCode() @@ -486,12 +487,19 @@ private constructor( return true } - return /* spotless:off */ other is EnvVar && id == other.id && name == other.name && objectId == other.objectId && objectType == other.objectType && created == other.created && used == other.used && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EnvVar && + id == other.id && + name == other.name && + objectId == other.objectId && + objectType == other.objectType && + created == other.created && + used == other.used && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, objectId, objectType, created, used, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, name, objectId, objectType, created, used, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt index 95f3d594..df2d5196 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarCreateParams.kt @@ -94,8 +94,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -335,6 +337,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val objectId: JsonField, @@ -598,12 +601,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + objectId == other.objectId && + objectType == other.objectType && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, value, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, objectId, objectType, value, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -739,7 +747,7 @@ private constructor( return true } - return /* spotless:off */ other is ObjectType && value == other.value /* spotless:on */ + return other is ObjectType && value == other.value } override fun hashCode() = value.hashCode() @@ -752,10 +760,13 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EnvVarCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "EnvVarCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt index 9547d21a..12fb3736 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete an env_var object by its id */ class EnvVarDeleteParams private constructor( - private val envVarId: String, + private val envVarId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** EnvVar id */ - fun envVarId(): String = envVarId + fun envVarId(): Optional = Optional.ofNullable(envVarId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [EnvVarDeleteParams]. - * - * The following fields are required: - * ```java - * .envVarId() - * ``` - */ + @JvmStatic fun none(): EnvVarDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [EnvVarDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** EnvVar id */ - fun envVarId(envVarId: String) = apply { this.envVarId = envVarId } + fun envVarId(envVarId: String?) = apply { this.envVarId = envVarId } + + /** Alias for calling [Builder.envVarId] with `envVarId.orElse(null)`. */ + fun envVarId(envVarId: Optional) = envVarId(envVarId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [EnvVarDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .envVarId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): EnvVarDeleteParams = EnvVarDeleteParams( - checkRequired("envVarId", envVarId), + envVarId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> envVarId + 0 -> envVarId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarDeleteParams && envVarId == other.envVarId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is EnvVarDeleteParams && + envVarId == other.envVarId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(envVarId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(envVarId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "EnvVarDeleteParams{envVarId=$envVarId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt index 420b7e23..8bdc76be 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -43,8 +44,10 @@ private constructor( /** The type of the object the environment variable is scoped for */ fun objectType(): Optional = Optional.ofNullable(objectType) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -298,10 +301,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -314,7 +317,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -331,10 +334,26 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarListParams && envVarName == other.envVarName && ids == other.ids && limit == other.limit && objectId == other.objectId && objectType == other.objectType && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EnvVarListParams && + envVarName == other.envVarName && + ids == other.ids && + limit == other.limit && + objectId == other.objectId && + objectType == other.objectType && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(envVarName, ids, limit, objectId, objectType, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + envVarName, + ids, + limit, + objectId, + objectType, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "EnvVarListParams{envVarName=$envVarName, ids=$ids, limit=$limit, objectId=$objectId, objectType=$objectType, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt index 5b96d587..395976a1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarListResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class EnvVarListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarListResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is EnvVarListResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt index db76bd2a..11f78ac3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarObjectType.kt @@ -132,7 +132,7 @@ class EnvVarObjectType @JsonCreator private constructor(private val value: JsonF return true } - return /* spotless:off */ other is EnvVarObjectType && value == other.value /* spotless:on */ + return other is EnvVarObjectType && value == other.value } override fun hashCode() = value.hashCode() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt index 10e7bda1..96dd3de5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarReplaceParams.kt @@ -94,8 +94,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -335,6 +337,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val objectId: JsonField, @@ -598,12 +601,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + objectId == other.objectId && + objectType == other.objectType && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, value, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, objectId, objectType, value, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -739,7 +747,7 @@ private constructor( return true } - return /* spotless:off */ other is ObjectType && value == other.value /* spotless:on */ + return other is ObjectType && value == other.value } override fun hashCode() = value.hashCode() @@ -752,10 +760,13 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EnvVarReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "EnvVarReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt index 00b5ca97..2f008ae3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an env_var object by its id */ class EnvVarRetrieveParams private constructor( - private val envVarId: String, + private val envVarId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** EnvVar id */ - fun envVarId(): String = envVarId + fun envVarId(): Optional = Optional.ofNullable(envVarId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [EnvVarRetrieveParams]. - * - * The following fields are required: - * ```java - * .envVarId() - * ``` - */ + @JvmStatic fun none(): EnvVarRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [EnvVarRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** EnvVar id */ - fun envVarId(envVarId: String) = apply { this.envVarId = envVarId } + fun envVarId(envVarId: String?) = apply { this.envVarId = envVarId } + + /** Alias for calling [Builder.envVarId] with `envVarId.orElse(null)`. */ + fun envVarId(envVarId: Optional) = envVarId(envVarId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [EnvVarRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .envVarId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): EnvVarRetrieveParams = - EnvVarRetrieveParams( - checkRequired("envVarId", envVarId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + EnvVarRetrieveParams(envVarId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> envVarId + 0 -> envVarId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarRetrieveParams && envVarId == other.envVarId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EnvVarRetrieveParams && + envVarId == other.envVarId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(envVarId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(envVarId, additionalHeaders, additionalQueryParams) override fun toString() = "EnvVarRetrieveParams{envVarId=$envVarId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt index 0283dad1..39a55172 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EnvVarUpdateParams.kt @@ -27,14 +27,14 @@ import kotlin.jvm.optionals.getOrNull */ class EnvVarUpdateParams private constructor( - private val envVarId: String, + private val envVarId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** EnvVar id */ - fun envVarId(): String = envVarId + fun envVarId(): Optional = Optional.ofNullable(envVarId) /** * The name of the environment variable @@ -68,8 +68,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -81,7 +83,6 @@ private constructor( * * The following fields are required: * ```java - * .envVarId() * .name() * ``` */ @@ -105,7 +106,10 @@ private constructor( } /** EnvVar id */ - fun envVarId(envVarId: String) = apply { this.envVarId = envVarId } + fun envVarId(envVarId: String?) = apply { this.envVarId = envVarId } + + /** Alias for calling [Builder.envVarId] with `envVarId.orElse(null)`. */ + fun envVarId(envVarId: Optional) = envVarId(envVarId.getOrNull()) /** * Sets the entire request body. @@ -266,7 +270,6 @@ private constructor( * * The following fields are required: * ```java - * .envVarId() * .name() * ``` * @@ -274,7 +277,7 @@ private constructor( */ fun build(): EnvVarUpdateParams = EnvVarUpdateParams( - checkRequired("envVarId", envVarId), + envVarId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -285,7 +288,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> envVarId + 0 -> envVarId ?: "" else -> "" } @@ -294,6 +297,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val value: JsonField, @@ -472,12 +476,13 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, value, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -490,10 +495,15 @@ private constructor( return true } - return /* spotless:off */ other is EnvVarUpdateParams && envVarId == other.envVarId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EnvVarUpdateParams && + envVarId == other.envVarId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(envVarId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(envVarId, body, additionalHeaders, additionalQueryParams) override fun toString() = "EnvVarUpdateParams{envVarId=$envVarId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt index 0583e3ba..3ad43206 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/EvalCreateParams.kt @@ -304,8 +304,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -853,6 +855,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField, private val projectId: JsonField, @@ -1767,12 +1770,47 @@ private constructor( return true } - return /* spotless:off */ other is Body && data == other.data && projectId == other.projectId && scores == other.scores && task == other.task && baseExperimentId == other.baseExperimentId && baseExperimentName == other.baseExperimentName && experimentName == other.experimentName && gitMetadataSettings == other.gitMetadataSettings && isPublic == other.isPublic && maxConcurrency == other.maxConcurrency && metadata == other.metadata && parent == other.parent && repoInfo == other.repoInfo && stream == other.stream && timeout == other.timeout && trialCount == other.trialCount && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + data == other.data && + projectId == other.projectId && + scores == other.scores && + task == other.task && + baseExperimentId == other.baseExperimentId && + baseExperimentName == other.baseExperimentName && + experimentName == other.experimentName && + gitMetadataSettings == other.gitMetadataSettings && + isPublic == other.isPublic && + maxConcurrency == other.maxConcurrency && + metadata == other.metadata && + parent == other.parent && + repoInfo == other.repoInfo && + stream == other.stream && + timeout == other.timeout && + trialCount == other.trialCount && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, projectId, scores, task, baseExperimentId, baseExperimentName, experimentName, gitMetadataSettings, isPublic, maxConcurrency, metadata, parent, repoInfo, stream, timeout, trialCount, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + data, + projectId, + scores, + task, + baseExperimentId, + baseExperimentName, + experimentName, + gitMetadataSettings, + isPublic, + maxConcurrency, + metadata, + parent, + repoInfo, + stream, + timeout, + trialCount, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1886,10 +1924,13 @@ private constructor( return true } - return /* spotless:off */ other is Data && datasetId == other.datasetId && projectDatasetName == other.projectDatasetName && datasetRows == other.datasetRows /* spotless:on */ + return other is Data && + datasetId == other.datasetId && + projectDatasetName == other.projectDatasetName && + datasetRows == other.datasetRows } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, projectDatasetName, datasetRows) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(datasetId, projectDatasetName, datasetRows) override fun toString(): String = when { @@ -1993,6 +2034,7 @@ private constructor( /** Dataset id */ class DatasetId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val datasetId: JsonField, private val _internalBtql: JsonField<_InternalBtql>, @@ -2280,12 +2322,11 @@ private constructor( return true } - return /* spotless:off */ other is _InternalBtql && additionalProperties == other.additionalProperties /* spotless:on */ + return other is _InternalBtql && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2298,12 +2339,15 @@ private constructor( return true } - return /* spotless:off */ other is DatasetId && datasetId == other.datasetId && _internalBtql == other._internalBtql && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DatasetId && + datasetId == other.datasetId && + _internalBtql == other._internalBtql && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(datasetId, _internalBtql, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(datasetId, _internalBtql, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2313,6 +2357,7 @@ private constructor( /** Project and dataset name */ class ProjectDatasetName + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val datasetName: JsonField, private val projectName: JsonField, @@ -2643,12 +2688,11 @@ private constructor( return true } - return /* spotless:off */ other is _InternalBtql && additionalProperties == other.additionalProperties /* spotless:on */ + return other is _InternalBtql && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2661,12 +2705,16 @@ private constructor( return true } - return /* spotless:off */ other is ProjectDatasetName && datasetName == other.datasetName && projectName == other.projectName && _internalBtql == other._internalBtql && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectDatasetName && + datasetName == other.datasetName && + projectName == other.projectName && + _internalBtql == other._internalBtql && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(datasetName, projectName, _internalBtql, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(datasetName, projectName, _internalBtql, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2676,6 +2724,7 @@ private constructor( /** Dataset rows */ class DatasetRows + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField>, private val additionalProperties: MutableMap, @@ -2839,12 +2888,12 @@ private constructor( return true } - return /* spotless:off */ other is DatasetRows && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + return other is DatasetRows && + data == other.data && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3007,10 +3056,24 @@ private constructor( return true } - return /* spotless:off */ other is Score && functionId == other.functionId && projectSlug == other.projectSlug && globalFunction == other.globalFunction && promptSessionId == other.promptSessionId && inlineCode == other.inlineCode && inlinePrompt == other.inlinePrompt /* spotless:on */ + return other is Score && + functionId == other.functionId && + projectSlug == other.projectSlug && + globalFunction == other.globalFunction && + promptSessionId == other.promptSessionId && + inlineCode == other.inlineCode && + inlinePrompt == other.inlinePrompt } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionId, projectSlug, globalFunction, promptSessionId, inlineCode, inlinePrompt) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + functionId, + projectSlug, + globalFunction, + promptSessionId, + inlineCode, + inlinePrompt, + ) override fun toString(): String = when { @@ -3151,6 +3214,7 @@ private constructor( /** Function id */ class FunctionId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val functionId: JsonField, private val version: JsonField, @@ -3344,12 +3408,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionId && functionId == other.functionId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionId && + functionId == other.functionId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(functionId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(functionId, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3359,6 +3426,7 @@ private constructor( /** Project name and slug */ class ProjectSlug + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val projectName: JsonField, private val slug: JsonField, @@ -3589,12 +3657,16 @@ private constructor( return true } - return /* spotless:off */ other is ProjectSlug && projectName == other.projectName && slug == other.slug && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectSlug && + projectName == other.projectName && + slug == other.slug && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(projectName, slug, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(projectName, slug, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3604,6 +3676,7 @@ private constructor( /** Global function name */ class GlobalFunction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val globalFunction: JsonField, private val additionalProperties: MutableMap, @@ -3765,12 +3838,12 @@ private constructor( return true } - return /* spotless:off */ other is GlobalFunction && globalFunction == other.globalFunction && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GlobalFunction && + globalFunction == other.globalFunction && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(globalFunction, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3780,6 +3853,7 @@ private constructor( /** Prompt session id */ class PromptSessionId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val promptSessionFunctionId: JsonField, private val promptSessionId: JsonField, @@ -4020,12 +4094,21 @@ private constructor( return true } - return /* spotless:off */ other is PromptSessionId && promptSessionFunctionId == other.promptSessionFunctionId && promptSessionId == other.promptSessionId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PromptSessionId && + promptSessionFunctionId == other.promptSessionFunctionId && + promptSessionId == other.promptSessionId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(promptSessionFunctionId, promptSessionId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + promptSessionFunctionId, + promptSessionId, + version, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -4035,6 +4118,7 @@ private constructor( /** Inline code function */ class InlineCode + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val code: JsonField, private val inlineContext: JsonField, @@ -4260,6 +4344,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) class InlineContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -4570,7 +4655,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -4583,12 +4668,15 @@ private constructor( return true } - return /* spotless:off */ other is InlineContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InlineContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(runtime, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4601,12 +4689,16 @@ private constructor( return true } - return /* spotless:off */ other is InlineCode && code == other.code && inlineContext == other.inlineContext && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InlineCode && + code == other.code && + inlineContext == other.inlineContext && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, inlineContext, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(code, inlineContext, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4616,6 +4708,7 @@ private constructor( /** Inline prompt definition */ class InlinePrompt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val inlinePrompt: JsonField, private val name: JsonField, @@ -4814,12 +4907,15 @@ private constructor( return true } - return /* spotless:off */ other is InlinePrompt && inlinePrompt == other.inlinePrompt && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InlinePrompt && + inlinePrompt == other.inlinePrompt && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(inlinePrompt, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(inlinePrompt, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4982,10 +5078,24 @@ private constructor( return true } - return /* spotless:off */ other is Task && functionId == other.functionId && projectSlug == other.projectSlug && globalFunction == other.globalFunction && promptSessionId == other.promptSessionId && inlineCode == other.inlineCode && inlinePrompt == other.inlinePrompt /* spotless:on */ + return other is Task && + functionId == other.functionId && + projectSlug == other.projectSlug && + globalFunction == other.globalFunction && + promptSessionId == other.promptSessionId && + inlineCode == other.inlineCode && + inlinePrompt == other.inlinePrompt } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionId, projectSlug, globalFunction, promptSessionId, inlineCode, inlinePrompt) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + functionId, + projectSlug, + globalFunction, + promptSessionId, + inlineCode, + inlinePrompt, + ) override fun toString(): String = when { @@ -5124,6 +5234,7 @@ private constructor( /** Function id */ class FunctionId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val functionId: JsonField, private val version: JsonField, @@ -5317,12 +5428,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionId && functionId == other.functionId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionId && + functionId == other.functionId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(functionId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(functionId, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5332,6 +5446,7 @@ private constructor( /** Project name and slug */ class ProjectSlug + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val projectName: JsonField, private val slug: JsonField, @@ -5562,12 +5677,16 @@ private constructor( return true } - return /* spotless:off */ other is ProjectSlug && projectName == other.projectName && slug == other.slug && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectSlug && + projectName == other.projectName && + slug == other.slug && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(projectName, slug, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(projectName, slug, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5577,6 +5696,7 @@ private constructor( /** Global function name */ class GlobalFunction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val globalFunction: JsonField, private val additionalProperties: MutableMap, @@ -5738,12 +5858,12 @@ private constructor( return true } - return /* spotless:off */ other is GlobalFunction && globalFunction == other.globalFunction && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GlobalFunction && + globalFunction == other.globalFunction && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(globalFunction, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -5753,6 +5873,7 @@ private constructor( /** Prompt session id */ class PromptSessionId + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val promptSessionFunctionId: JsonField, private val promptSessionId: JsonField, @@ -5993,12 +6114,21 @@ private constructor( return true } - return /* spotless:off */ other is PromptSessionId && promptSessionFunctionId == other.promptSessionFunctionId && promptSessionId == other.promptSessionId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PromptSessionId && + promptSessionFunctionId == other.promptSessionFunctionId && + promptSessionId == other.promptSessionId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(promptSessionFunctionId, promptSessionId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + promptSessionFunctionId, + promptSessionId, + version, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -6008,6 +6138,7 @@ private constructor( /** Inline code function */ class InlineCode + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val code: JsonField, private val inlineContext: JsonField, @@ -6233,6 +6364,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) class InlineContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -6543,7 +6675,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -6556,12 +6688,15 @@ private constructor( return true } - return /* spotless:off */ other is InlineContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InlineContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(runtime, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -6574,12 +6709,16 @@ private constructor( return true } - return /* spotless:off */ other is InlineCode && code == other.code && inlineContext == other.inlineContext && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InlineCode && + code == other.code && + inlineContext == other.inlineContext && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, inlineContext, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(code, inlineContext, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -6589,6 +6728,7 @@ private constructor( /** Inline prompt definition */ class InlinePrompt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val inlinePrompt: JsonField, private val name: JsonField, @@ -6787,12 +6927,15 @@ private constructor( return true } - return /* spotless:off */ other is InlinePrompt && inlinePrompt == other.inlinePrompt && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InlinePrompt && + inlinePrompt == other.inlinePrompt && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(inlinePrompt, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(inlinePrompt, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -6806,6 +6949,7 @@ private constructor( * fields allowed in org-level settings. */ class GitMetadataSettings + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val collect: JsonField, private val fields: JsonField>, @@ -7119,7 +7263,7 @@ private constructor( return true } - return /* spotless:off */ other is Collect && value == other.value /* spotless:on */ + return other is Collect && value == other.value } override fun hashCode() = value.hashCode() @@ -7290,7 +7434,7 @@ private constructor( return true } - return /* spotless:off */ other is Field && value == other.value /* spotless:on */ + return other is Field && value == other.value } override fun hashCode() = value.hashCode() @@ -7303,12 +7447,13 @@ private constructor( return true } - return /* spotless:off */ other is GitMetadataSettings && collect == other.collect && fields == other.fields && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GitMetadataSettings && + collect == other.collect && + fields == other.fields && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(collect, fields, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -7409,12 +7554,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -7507,10 +7650,12 @@ private constructor( return true } - return /* spotless:off */ other is Parent && spanParentStruct == other.spanParentStruct && string == other.string /* spotless:on */ + return other is Parent && + spanParentStruct == other.spanParentStruct && + string == other.string } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanParentStruct, string) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(spanParentStruct, string) override fun toString(): String = when { @@ -7603,6 +7748,7 @@ private constructor( /** Span parent properties */ class SpanParentStruct + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -8010,7 +8156,7 @@ private constructor( return true } - return /* spotless:off */ other is ObjectType && value == other.value /* spotless:on */ + return other is ObjectType && value == other.value } override fun hashCode() = value.hashCode() @@ -8116,12 +8262,11 @@ private constructor( return true } - return /* spotless:off */ other is PropagatedEvent && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PropagatedEvent && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -8131,6 +8276,7 @@ private constructor( /** Identifiers for the row to to log a subspan under */ class RowIds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val rootSpanId: JsonField, @@ -8365,12 +8511,16 @@ private constructor( return true } - return /* spotless:off */ other is RowIds && id == other.id && rootSpanId == other.rootSpanId && spanId == other.spanId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RowIds && + id == other.id && + rootSpanId == other.rootSpanId && + spanId == other.spanId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, rootSpanId, spanId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, rootSpanId, spanId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -8383,12 +8533,17 @@ private constructor( return true } - return /* spotless:off */ other is SpanParentStruct && objectId == other.objectId && objectType == other.objectType && propagatedEvent == other.propagatedEvent && rowIds == other.rowIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SpanParentStruct && + objectId == other.objectId && + objectType == other.objectType && + propagatedEvent == other.propagatedEvent && + rowIds == other.rowIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, propagatedEvent, rowIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(objectId, objectType, propagatedEvent, rowIds, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -8402,10 +8557,13 @@ private constructor( return true } - return /* spotless:off */ other is EvalCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is EvalCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "EvalCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt index e756f680..9753c326 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Experiment.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class Experiment +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -767,12 +768,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -784,12 +783,43 @@ private constructor( return true } - return /* spotless:off */ other is Experiment && id == other.id && name == other.name && projectId == other.projectId && public_ == other.public_ && baseExpId == other.baseExpId && commit == other.commit && created == other.created && datasetId == other.datasetId && datasetVersion == other.datasetVersion && deletedAt == other.deletedAt && description == other.description && metadata == other.metadata && repoInfo == other.repoInfo && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Experiment && + id == other.id && + name == other.name && + projectId == other.projectId && + public_ == other.public_ && + baseExpId == other.baseExpId && + commit == other.commit && + created == other.created && + datasetId == other.datasetId && + datasetVersion == other.datasetVersion && + deletedAt == other.deletedAt && + description == other.description && + metadata == other.metadata && + repoInfo == other.repoInfo && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, projectId, public_, baseExpId, commit, created, datasetId, datasetVersion, deletedAt, description, metadata, repoInfo, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + projectId, + public_, + baseExpId, + commit, + created, + datasetId, + datasetVersion, + deletedAt, + description, + metadata, + repoInfo, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt index f1387ce7..1566b32d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentCreateParams.kt @@ -188,8 +188,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -553,6 +555,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val projectId: JsonField, private val baseExpId: JsonField, @@ -1102,12 +1105,35 @@ private constructor( return true } - return /* spotless:off */ other is Body && projectId == other.projectId && baseExpId == other.baseExpId && datasetId == other.datasetId && datasetVersion == other.datasetVersion && description == other.description && ensureNew == other.ensureNew && metadata == other.metadata && name == other.name && public_ == other.public_ && repoInfo == other.repoInfo && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + projectId == other.projectId && + baseExpId == other.baseExpId && + datasetId == other.datasetId && + datasetVersion == other.datasetVersion && + description == other.description && + ensureNew == other.ensureNew && + metadata == other.metadata && + name == other.name && + public_ == other.public_ && + repoInfo == other.repoInfo && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(projectId, baseExpId, datasetId, datasetVersion, description, ensureNew, metadata, name, public_, repoInfo, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + projectId, + baseExpId, + datasetId, + datasetVersion, + description, + ensureNew, + metadata, + name, + public_, + repoInfo, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1205,12 +1231,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1222,10 +1246,13 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ExperimentCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt index 82be2d53..20855f56 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete an experiment object by its id */ class ExperimentDeleteParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ExperimentDeleteParams]. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - */ + @JvmStatic fun none(): ExperimentDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ExperimentDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -62,7 +60,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -188,17 +189,10 @@ private constructor( * Returns an immutable instance of [ExperimentDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ExperimentDeleteParams = ExperimentDeleteParams( - checkRequired("experimentId", experimentId), + experimentId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -210,7 +204,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -223,10 +217,20 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentDeleteParams && experimentId == other.experimentId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is ExperimentDeleteParams && + experimentId == other.experimentId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + experimentId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "ExperimentDeleteParams{experimentId=$experimentId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt index 8190a183..a62525d4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentEvent.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ExperimentEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _xactId: JsonField, @@ -923,6 +924,7 @@ private constructor( * location in code which produced the experiment event */ class Context + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonField, private val callerFunctionname: JsonField, @@ -1168,12 +1170,16 @@ private constructor( return true } - return /* spotless:off */ other is Context && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Context && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1189,6 +1195,7 @@ private constructor( * must be strings */ class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val additionalProperties: MutableMap, @@ -1318,12 +1325,12 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && + model == other.model && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1337,6 +1344,7 @@ private constructor( * event was produced */ class Metrics + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonValue, private val callerFunctionname: JsonValue, @@ -1747,12 +1755,31 @@ private constructor( return true } - return /* spotless:off */ other is Metrics && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && completionTokens == other.completionTokens && end == other.end && promptTokens == other.promptTokens && start == other.start && tokens == other.tokens && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metrics && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + completionTokens == other.completionTokens && + end == other.end && + promptTokens == other.promptTokens && + start == other.start && + tokens == other.tokens && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, completionTokens, end, promptTokens, start, tokens, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1858,12 +1885,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1875,12 +1900,55 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentEvent && id == other.id && _xactId == other._xactId && created == other.created && experimentId == other.experimentId && projectId == other.projectId && rootSpanId == other.rootSpanId && spanId == other.spanId && context == other.context && error == other.error && expected == other.expected && input == other.input && isRoot == other.isRoot && metadata == other.metadata && metrics == other.metrics && origin == other.origin && output == other.output && scores == other.scores && spanAttributes == other.spanAttributes && spanParents == other.spanParents && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExperimentEvent && + id == other.id && + _xactId == other._xactId && + created == other.created && + experimentId == other.experimentId && + projectId == other.projectId && + rootSpanId == other.rootSpanId && + spanId == other.spanId && + context == other.context && + error == other.error && + expected == other.expected && + input == other.input && + isRoot == other.isRoot && + metadata == other.metadata && + metrics == other.metrics && + origin == other.origin && + output == other.output && + scores == other.scores && + spanAttributes == other.spanAttributes && + spanParents == other.spanParents && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _xactId, created, experimentId, projectId, rootSpanId, spanId, context, error, expected, input, isRoot, metadata, metrics, origin, output, scores, spanAttributes, spanParents, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _xactId, + created, + experimentId, + projectId, + rootSpanId, + spanId, + context, + error, + expected, + input, + isRoot, + metadata, + metrics, + origin, + output, + scores, + spanAttributes, + spanParents, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt index 5c621452..391a2223 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFeedbackParams.kt @@ -19,19 +19,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Log feedback for a set of experiment events */ class ExperimentFeedbackParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) /** * A list of experiment feedback items @@ -50,8 +51,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -63,7 +66,6 @@ private constructor( * * The following fields are required: * ```java - * .experimentId() * .feedback() * ``` */ @@ -87,7 +89,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) /** * Sets the entire request body. @@ -243,7 +248,6 @@ private constructor( * * The following fields are required: * ```java - * .experimentId() * .feedback() * ``` * @@ -251,7 +255,7 @@ private constructor( */ fun build(): ExperimentFeedbackParams = ExperimentFeedbackParams( - checkRequired("experimentId", experimentId), + experimentId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -262,7 +266,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -271,6 +275,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val feedback: JsonField>, private val additionalProperties: MutableMap, @@ -435,12 +440,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + feedback == other.feedback && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -453,10 +458,15 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentFeedbackParams && experimentId == other.experimentId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentFeedbackParams && + experimentId == other.experimentId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ExperimentFeedbackParams{experimentId=$experimentId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt index c96284e4..15a35318 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchParams.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects @@ -17,7 +16,7 @@ import kotlin.jvm.optionals.getOrNull */ class ExperimentFetchParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val limit: Long?, private val maxRootSpanId: String?, private val maxXactId: String?, @@ -27,7 +26,7 @@ private constructor( ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) /** * limit the number of traces fetched @@ -81,22 +80,19 @@ private constructor( */ fun version(): Optional = Optional.ofNullable(version) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ExperimentFetchParams]. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - */ + @JvmStatic fun none(): ExperimentFetchParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ExperimentFetchParams]. */ @JvmStatic fun builder() = Builder() } @@ -123,7 +119,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) /** * limit the number of traces fetched @@ -300,17 +299,10 @@ private constructor( * Returns an immutable instance of [ExperimentFetchParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ExperimentFetchParams = ExperimentFetchParams( - checkRequired("experimentId", experimentId), + experimentId, limit, maxRootSpanId, maxXactId, @@ -322,7 +314,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -344,10 +336,26 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentFetchParams && experimentId == other.experimentId && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentFetchParams && + experimentId == other.experimentId && + limit == other.limit && + maxRootSpanId == other.maxRootSpanId && + maxXactId == other.maxXactId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, limit, maxRootSpanId, maxXactId, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + experimentId, + limit, + maxRootSpanId, + maxXactId, + version, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ExperimentFetchParams{experimentId=$experimentId, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt index d1c52fb9..44326a64 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentFetchPostParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class ExperimentFetchPostParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) /** * An opaque string to be used as a cursor for the next page of results, in order from latest to @@ -148,21 +147,20 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { + @JvmStatic fun none(): ExperimentFetchPostParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [ExperimentFetchPostParams]. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -184,7 +182,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) /** * Sets the entire request body. @@ -450,17 +451,10 @@ private constructor( * Returns an immutable instance of [ExperimentFetchPostParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ExperimentFetchPostParams = ExperimentFetchPostParams( - checkRequired("experimentId", experimentId), + experimentId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -471,7 +465,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -480,6 +474,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cursor: JsonField, private val limit: JsonField, @@ -866,12 +861,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + cursor == other.cursor && + limit == other.limit && + maxRootSpanId == other.maxRootSpanId && + maxXactId == other.maxXactId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -884,10 +885,15 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentFetchPostParams && experimentId == other.experimentId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentFetchPostParams && + experimentId == other.experimentId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ExperimentFetchPostParams{experimentId=$experimentId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt index 2112cf67..75c76af3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentInsertParams.kt @@ -19,19 +19,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Insert a set of events into the experiment */ class ExperimentInsertParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) /** * A list of experiment events to insert @@ -50,8 +51,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -63,7 +66,6 @@ private constructor( * * The following fields are required: * ```java - * .experimentId() * .events() * ``` */ @@ -87,7 +89,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) /** * Sets the entire request body. @@ -241,7 +246,6 @@ private constructor( * * The following fields are required: * ```java - * .experimentId() * .events() * ``` * @@ -249,7 +253,7 @@ private constructor( */ fun build(): ExperimentInsertParams = ExperimentInsertParams( - checkRequired("experimentId", experimentId), + experimentId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -260,7 +264,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -269,6 +273,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val additionalProperties: MutableMap, @@ -433,12 +438,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + events == other.events && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -450,10 +455,15 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentInsertParams && experimentId == other.experimentId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentInsertParams && + experimentId == other.experimentId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ExperimentInsertParams{experimentId=$experimentId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt index 64e38158..6bed69f4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ExperimentService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [ExperimentService.list] */ +/** @see ExperimentService.list */ class ExperimentListPage private constructor( private val service: ExperimentService, private val params: ExperimentListParams, private val response: ExperimentListPageResponse, -) { +) : Page { /** * Delegates to [ExperimentListPageResponse], but gracefully handles missing data. * - * @see [ExperimentListPageResponse.objects] + * @see ExperimentListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ExperimentListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ExperimentListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ExperimentListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: ExperimentListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ExperimentListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ExperimentListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ExperimentListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt index b8b5c33d..f4109fe6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ExperimentServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [ExperimentServiceAsync.list] */ +/** @see ExperimentServiceAsync.list */ class ExperimentListPageAsync private constructor( private val service: ExperimentServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ExperimentListParams, private val response: ExperimentListPageResponse, -) { +) : PageAsync { /** * Delegates to [ExperimentListPageResponse], but gracefully handles missing data. * - * @see [ExperimentListPageResponse.objects] + * @see ExperimentListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ExperimentListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ExperimentListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: ExperimentServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ExperimentListParams? = null private var response: ExperimentListPageResponse? = null @JvmSynthetic internal fun from(experimentListPageAsync: ExperimentListPageAsync) = apply { service = experimentListPageAsync.service + streamHandlerExecutor = experimentListPageAsync.streamHandlerExecutor params = experimentListPageAsync.params response = experimentListPageAsync.response } fun service(service: ExperimentServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ExperimentListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): ExperimentListPageAsync = ExperimentListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: ExperimentListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Experiment) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ExperimentListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ExperimentListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "ExperimentListPageAsync{service=$service, params=$params, response=$response}" + "ExperimentListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt index ae4bfd1c..4e931a3d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ExperimentListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ExperimentListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt index 29c78e5b..3de2aa0c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -67,8 +68,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -366,10 +369,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -382,7 +385,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -399,10 +402,32 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentListParams && endingBefore == other.endingBefore && experimentName == other.experimentName && ids == other.ids && limit == other.limit && orgName == other.orgName && projectId == other.projectId && projectName == other.projectName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentListParams && + endingBefore == other.endingBefore && + experimentName == other.experimentName && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectId == other.projectId && + projectName == other.projectName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, experimentName, ids, limit, orgName, projectId, projectName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + experimentName, + ids, + limit, + orgName, + projectId, + projectName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ExperimentListParams{endingBefore=$endingBefore, experimentName=$experimentName, ids=$ids, limit=$limit, orgName=$orgName, projectId=$projectId, projectName=$projectName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt index 6b7a9da3..b12294df 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an experiment object by its id */ class ExperimentRetrieveParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ExperimentRetrieveParams]. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - */ + @JvmStatic fun none(): ExperimentRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ExperimentRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [ExperimentRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ExperimentRetrieveParams = ExperimentRetrieveParams( - checkRequired("experimentId", experimentId), + experimentId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -188,10 +182,14 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentRetrieveParams && experimentId == other.experimentId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentRetrieveParams && + experimentId == other.experimentId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(experimentId, additionalHeaders, additionalQueryParams) override fun toString() = "ExperimentRetrieveParams{experimentId=$experimentId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt index 3b4de8f0..f944a937 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentSummarizeParams.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects @@ -13,7 +12,7 @@ import kotlin.jvm.optionals.getOrNull /** Summarize experiment */ class ExperimentSummarizeParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val comparisonExperimentId: String?, private val summarizeScores: Boolean?, private val additionalHeaders: Headers, @@ -21,7 +20,7 @@ private constructor( ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) /** * The experiment to compare against, if summarizing scores and metrics. If omitted, will fall @@ -36,21 +35,20 @@ private constructor( */ fun summarizeScores(): Optional = Optional.ofNullable(summarizeScores) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { + @JvmStatic fun none(): ExperimentSummarizeParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [ExperimentSummarizeParams]. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -74,7 +72,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) /** * The experiment to compare against, if summarizing scores and metrics. If omitted, will @@ -214,17 +215,10 @@ private constructor( * Returns an immutable instance of [ExperimentSummarizeParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ExperimentSummarizeParams = ExperimentSummarizeParams( - checkRequired("experimentId", experimentId), + experimentId, comparisonExperimentId, summarizeScores, additionalHeaders.build(), @@ -234,7 +228,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -254,10 +248,22 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentSummarizeParams && experimentId == other.experimentId && comparisonExperimentId == other.comparisonExperimentId && summarizeScores == other.summarizeScores && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentSummarizeParams && + experimentId == other.experimentId && + comparisonExperimentId == other.comparisonExperimentId && + summarizeScores == other.summarizeScores && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, comparisonExperimentId, summarizeScores, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + experimentId, + comparisonExperimentId, + summarizeScores, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ExperimentSummarizeParams{experimentId=$experimentId, comparisonExperimentId=$comparisonExperimentId, summarizeScores=$summarizeScores, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt index 75600e2e..647ca5ab 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ExperimentUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable @@ -28,14 +27,14 @@ import kotlin.jvm.optionals.getOrNull */ class ExperimentUpdateParams private constructor( - private val experimentId: String, + private val experimentId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Experiment id */ - fun experimentId(): String = experimentId + fun experimentId(): Optional = Optional.ofNullable(experimentId) /** * Id of default base experiment to compare against when viewing this experiment @@ -161,22 +160,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ExperimentUpdateParams]. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - */ + @JvmStatic fun none(): ExperimentUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ExperimentUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -197,7 +193,10 @@ private constructor( } /** Experiment id */ - fun experimentId(experimentId: String) = apply { this.experimentId = experimentId } + fun experimentId(experimentId: String?) = apply { this.experimentId = experimentId } + + /** Alias for calling [Builder.experimentId] with `experimentId.orElse(null)`. */ + fun experimentId(experimentId: Optional) = experimentId(experimentId.getOrNull()) /** * Sets the entire request body. @@ -470,17 +469,10 @@ private constructor( * Returns an immutable instance of [ExperimentUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .experimentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ExperimentUpdateParams = ExperimentUpdateParams( - checkRequired("experimentId", experimentId), + experimentId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -491,7 +483,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> experimentId + 0 -> experimentId ?: "" else -> "" } @@ -500,6 +492,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val baseExpId: JsonField, private val datasetId: JsonField, @@ -945,12 +938,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && baseExpId == other.baseExpId && datasetId == other.datasetId && datasetVersion == other.datasetVersion && description == other.description && metadata == other.metadata && name == other.name && public_ == other.public_ && repoInfo == other.repoInfo && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + baseExpId == other.baseExpId && + datasetId == other.datasetId && + datasetVersion == other.datasetVersion && + description == other.description && + metadata == other.metadata && + name == other.name && + public_ == other.public_ && + repoInfo == other.repoInfo && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(baseExpId, datasetId, datasetVersion, description, metadata, name, public_, repoInfo, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + baseExpId, + datasetId, + datasetVersion, + description, + metadata, + name, + public_, + repoInfo, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1048,12 +1060,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1065,10 +1075,15 @@ private constructor( return true } - return /* spotless:off */ other is ExperimentUpdateParams && experimentId == other.experimentId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ExperimentUpdateParams && + experimentId == other.experimentId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(experimentId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ExperimentUpdateParams{experimentId=$experimentId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt index 9986ad76..d4e345ad 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackDatasetItem.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class FeedbackDatasetItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val comment: JsonField, @@ -421,12 +422,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -559,7 +558,7 @@ private constructor( return true } - return /* spotless:off */ other is Source && value == other.value /* spotless:on */ + return other is Source && value == other.value } override fun hashCode() = value.hashCode() @@ -572,12 +571,18 @@ private constructor( return true } - return /* spotless:off */ other is FeedbackDatasetItem && id == other.id && comment == other.comment && metadata == other.metadata && source == other.source && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FeedbackDatasetItem && + id == other.id && + comment == other.comment && + metadata == other.metadata && + source == other.source && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, comment, metadata, source, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, comment, metadata, source, tags, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt index ef903e91..34472611 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackExperimentItem.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class FeedbackExperimentItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val comment: JsonField, @@ -478,12 +479,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -583,12 +582,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -721,7 +718,7 @@ private constructor( return true } - return /* spotless:off */ other is Source && value == other.value /* spotless:on */ + return other is Source && value == other.value } override fun hashCode() = value.hashCode() @@ -734,12 +731,20 @@ private constructor( return true } - return /* spotless:off */ other is FeedbackExperimentItem && id == other.id && comment == other.comment && expected == other.expected && metadata == other.metadata && scores == other.scores && source == other.source && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FeedbackExperimentItem && + id == other.id && + comment == other.comment && + expected == other.expected && + metadata == other.metadata && + scores == other.scores && + source == other.source && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, comment, expected, metadata, scores, source, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, comment, expected, metadata, scores, source, tags, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt index a121b9e5..1858d30c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackProjectLogsItem.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class FeedbackProjectLogsItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val comment: JsonField, @@ -478,12 +479,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -583,12 +582,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -721,7 +718,7 @@ private constructor( return true } - return /* spotless:off */ other is Source && value == other.value /* spotless:on */ + return other is Source && value == other.value } override fun hashCode() = value.hashCode() @@ -734,12 +731,20 @@ private constructor( return true } - return /* spotless:off */ other is FeedbackProjectLogsItem && id == other.id && comment == other.comment && expected == other.expected && metadata == other.metadata && scores == other.scores && source == other.source && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FeedbackProjectLogsItem && + id == other.id && + comment == other.comment && + expected == other.expected && + metadata == other.metadata && + scores == other.scores && + source == other.source && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, comment, expected, metadata, scores, source, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, comment, expected, metadata, scores, source, tags, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt index ef0b762b..f5f0e6a0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FeedbackResponseSchema.kt @@ -18,6 +18,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class FeedbackResponseSchema +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val status: JsonField, private val additionalProperties: MutableMap, @@ -265,7 +266,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -278,12 +279,12 @@ private constructor( return true } - return /* spotless:off */ other is FeedbackResponseSchema && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FeedbackResponseSchema && + status == other.status && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(status, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt index e6658cf9..a8373def 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchDatasetEventsResponse.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class FetchDatasetEventsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val cursor: JsonField, @@ -225,12 +226,13 @@ private constructor( return true } - return /* spotless:off */ other is FetchDatasetEventsResponse && events == other.events && cursor == other.cursor && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FetchDatasetEventsResponse && + events == other.events && + cursor == other.cursor && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, cursor, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt index 12ee5436..c1c85b0c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchExperimentEventsResponse.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class FetchExperimentEventsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val cursor: JsonField, @@ -226,12 +227,13 @@ private constructor( return true } - return /* spotless:off */ other is FetchExperimentEventsResponse && events == other.events && cursor == other.cursor && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FetchExperimentEventsResponse && + events == other.events && + cursor == other.cursor && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, cursor, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt index ad177f9c..9b637b71 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FetchProjectLogsEventsResponse.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class FetchProjectLogsEventsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val cursor: JsonField, @@ -229,12 +230,13 @@ private constructor( return true } - return /* spotless:off */ other is FetchProjectLogsEventsResponse && events == other.events && cursor == other.cursor && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FetchProjectLogsEventsResponse && + events == other.events && + cursor == other.cursor && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, cursor, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt index d3a0bb30..3044df80 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Function.kt @@ -33,6 +33,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class Function +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _xactId: JsonField, @@ -875,10 +876,13 @@ private constructor( return true } - return /* spotless:off */ other is FunctionData && prompt == other.prompt && code == other.code && global == other.global /* spotless:on */ + return other is FunctionData && + prompt == other.prompt && + code == other.code && + global == other.global } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(prompt, code, global) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(prompt, code, global) override fun toString(): String = when { @@ -976,6 +980,7 @@ private constructor( } class Prompt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -1230,7 +1235,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1243,12 +1248,12 @@ private constructor( return true } - return /* spotless:off */ other is Prompt && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Prompt && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1257,6 +1262,7 @@ private constructor( } class Code + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField, private val type: JsonField, @@ -1521,10 +1527,10 @@ private constructor( return true } - return /* spotless:off */ other is Data && bundle == other.bundle && inline == other.inline /* spotless:on */ + return other is Data && bundle == other.bundle && inline == other.inline } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(bundle, inline) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(bundle, inline) override fun toString(): String = when { @@ -1614,6 +1620,7 @@ private constructor( } class Bundle + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bundleId: JsonField, private val location: JsonField, @@ -2072,7 +2079,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2085,12 +2092,25 @@ private constructor( return true } - return /* spotless:off */ other is Bundle && bundleId == other.bundleId && location == other.location && runtimeContext == other.runtimeContext && preview == other.preview && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Bundle && + bundleId == other.bundleId && + location == other.location && + runtimeContext == other.runtimeContext && + preview == other.preview && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bundleId, location, runtimeContext, preview, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bundleId, + location, + runtimeContext, + preview, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2099,6 +2119,7 @@ private constructor( } class Inline + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val code: JsonField, private val runtimeContext: JsonField, @@ -2326,6 +2347,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class RuntimeContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -2652,7 +2674,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -2665,12 +2687,15 @@ private constructor( return true } - return /* spotless:off */ other is RuntimeContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RuntimeContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(runtime, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2799,7 +2824,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2812,12 +2837,16 @@ private constructor( return true } - return /* spotless:off */ other is Inline && code == other.code && runtimeContext == other.runtimeContext && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Inline && + code == other.code && + runtimeContext == other.runtimeContext && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, runtimeContext, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(code, runtimeContext, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2942,7 +2971,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2955,12 +2984,13 @@ private constructor( return true } - return /* spotless:off */ other is Code && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Code && + data == other.data && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2969,6 +2999,7 @@ private constructor( } class Global + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -3261,7 +3292,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3274,12 +3305,13 @@ private constructor( return true } - return /* spotless:off */ other is Global && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Global && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3402,7 +3434,7 @@ private constructor( return true } - return /* spotless:off */ other is LogId && value == other.value /* spotless:on */ + return other is LogId && value == other.value } override fun hashCode() = value.hashCode() @@ -3412,6 +3444,7 @@ private constructor( /** JSON schema for the function's parameters and return type */ class FunctionSchema + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val parameters: JsonValue, private val returns: JsonValue, @@ -3523,12 +3556,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionSchema && parameters == other.parameters && returns == other.returns && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionSchema && + parameters == other.parameters && + returns == other.returns && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, returns, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(parameters, returns, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3670,7 +3706,7 @@ private constructor( return true } - return /* spotless:off */ other is FunctionType && value == other.value /* spotless:on */ + return other is FunctionType && value == other.value } override fun hashCode() = value.hashCode() @@ -3768,12 +3804,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3781,6 +3815,7 @@ private constructor( } class Origin + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -4021,12 +4056,16 @@ private constructor( return true } - return /* spotless:off */ other is Origin && objectId == other.objectId && objectType == other.objectType && internal_ == other.internal_ && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Origin && + objectId == other.objectId && + objectType == other.objectType && + internal_ == other.internal_ && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, internal_, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(objectId, objectType, internal_, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4039,12 +4078,47 @@ private constructor( return true } - return /* spotless:off */ other is Function && id == other.id && _xactId == other._xactId && functionData == other.functionData && logId == other.logId && name == other.name && orgId == other.orgId && projectId == other.projectId && slug == other.slug && created == other.created && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && metadata == other.metadata && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + id == other.id && + _xactId == other._xactId && + functionData == other.functionData && + logId == other.logId && + name == other.name && + orgId == other.orgId && + projectId == other.projectId && + slug == other.slug && + created == other.created && + description == other.description && + functionSchema == other.functionSchema && + functionType == other.functionType && + metadata == other.metadata && + origin == other.origin && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _xactId, functionData, logId, name, orgId, projectId, slug, created, description, functionSchema, functionType, metadata, origin, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _xactId, + functionData, + logId, + name, + orgId, + projectId, + slug, + created, + description, + functionSchema, + functionType, + metadata, + origin, + promptData, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt index 0e55e810..d0c71981 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionCreateParams.kt @@ -192,8 +192,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -547,6 +549,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val functionData: JsonField, private val name: JsonField, @@ -1089,12 +1092,35 @@ private constructor( return true } - return /* spotless:off */ other is Body && functionData == other.functionData && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + functionData == other.functionData && + name == other.name && + projectId == other.projectId && + slug == other.slug && + description == other.description && + functionSchema == other.functionSchema && + functionType == other.functionType && + origin == other.origin && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(functionData, name, projectId, slug, description, functionSchema, functionType, origin, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + functionData, + name, + projectId, + slug, + description, + functionSchema, + functionType, + origin, + promptData, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1198,10 +1224,13 @@ private constructor( return true } - return /* spotless:off */ other is FunctionData && prompt == other.prompt && code == other.code && global == other.global /* spotless:on */ + return other is FunctionData && + prompt == other.prompt && + code == other.code && + global == other.global } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(prompt, code, global) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(prompt, code, global) override fun toString(): String = when { @@ -1299,6 +1328,7 @@ private constructor( } class Prompt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -1553,7 +1583,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1566,12 +1596,12 @@ private constructor( return true } - return /* spotless:off */ other is Prompt && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Prompt && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1580,6 +1610,7 @@ private constructor( } class Code + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField, private val type: JsonField, @@ -1844,10 +1875,10 @@ private constructor( return true } - return /* spotless:off */ other is Data && bundle == other.bundle && inline == other.inline /* spotless:on */ + return other is Data && bundle == other.bundle && inline == other.inline } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(bundle, inline) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(bundle, inline) override fun toString(): String = when { @@ -1937,6 +1968,7 @@ private constructor( } class Bundle + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bundleId: JsonField, private val location: JsonField, @@ -2395,7 +2427,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2408,12 +2440,25 @@ private constructor( return true } - return /* spotless:off */ other is Bundle && bundleId == other.bundleId && location == other.location && runtimeContext == other.runtimeContext && preview == other.preview && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Bundle && + bundleId == other.bundleId && + location == other.location && + runtimeContext == other.runtimeContext && + preview == other.preview && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bundleId, location, runtimeContext, preview, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bundleId, + location, + runtimeContext, + preview, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2422,6 +2467,7 @@ private constructor( } class Inline + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val code: JsonField, private val runtimeContext: JsonField, @@ -2649,6 +2695,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class RuntimeContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -2975,7 +3022,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -2988,12 +3035,15 @@ private constructor( return true } - return /* spotless:off */ other is RuntimeContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RuntimeContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(runtime, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3122,7 +3172,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3135,12 +3185,16 @@ private constructor( return true } - return /* spotless:off */ other is Inline && code == other.code && runtimeContext == other.runtimeContext && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Inline && + code == other.code && + runtimeContext == other.runtimeContext && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, runtimeContext, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(code, runtimeContext, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3265,7 +3319,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3278,12 +3332,13 @@ private constructor( return true } - return /* spotless:off */ other is Code && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Code && + data == other.data && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3292,6 +3347,7 @@ private constructor( } class Global + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -3584,7 +3640,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3597,12 +3653,13 @@ private constructor( return true } - return /* spotless:off */ other is Global && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Global && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3613,6 +3670,7 @@ private constructor( /** JSON schema for the function's parameters and return type */ class FunctionSchema + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val parameters: JsonValue, private val returns: JsonValue, @@ -3724,12 +3782,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionSchema && parameters == other.parameters && returns == other.returns && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionSchema && + parameters == other.parameters && + returns == other.returns && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, returns, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(parameters, returns, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3871,7 +3932,7 @@ private constructor( return true } - return /* spotless:off */ other is FunctionType && value == other.value /* spotless:on */ + return other is FunctionType && value == other.value } override fun hashCode() = value.hashCode() @@ -3880,6 +3941,7 @@ private constructor( } class Origin + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -4120,12 +4182,16 @@ private constructor( return true } - return /* spotless:off */ other is Origin && objectId == other.objectId && objectType == other.objectType && internal_ == other.internal_ && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Origin && + objectId == other.objectId && + objectType == other.objectType && + internal_ == other.internal_ && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, internal_, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(objectId, objectType, internal_, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4138,10 +4204,13 @@ private constructor( return true } - return /* spotless:off */ other is FunctionCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is FunctionCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "FunctionCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt index 0fe9dab9..5ae4c720 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a function object by its id */ class FunctionDeleteParams private constructor( - private val functionId: String, + private val functionId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Function id */ - fun functionId(): String = functionId + fun functionId(): Optional = Optional.ofNullable(functionId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [FunctionDeleteParams]. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - */ + @JvmStatic fun none(): FunctionDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [FunctionDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Function id */ - fun functionId(functionId: String) = apply { this.functionId = functionId } + fun functionId(functionId: String?) = apply { this.functionId = functionId } + + /** Alias for calling [Builder.functionId] with `functionId.orElse(null)`. */ + fun functionId(functionId: Optional) = functionId(functionId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [FunctionDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): FunctionDeleteParams = FunctionDeleteParams( - checkRequired("functionId", functionId), + functionId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> functionId + 0 -> functionId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionDeleteParams && functionId == other.functionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is FunctionDeleteParams && + functionId == other.functionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(functionId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "FunctionDeleteParams{functionId=$functionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt index d5512a91..5700fbb5 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeParams.kt @@ -37,14 +37,14 @@ import kotlin.jvm.optionals.getOrNull /** Invoke a function. */ class FunctionInvokeParams private constructor( - private val functionId: String, + private val functionId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Function id */ - fun functionId(): String = functionId + fun functionId(): Optional = Optional.ofNullable(functionId) /** The expected output of the function */ fun _expected(): JsonValue = body._expected() @@ -145,22 +145,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [FunctionInvokeParams]. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - */ + @JvmStatic fun none(): FunctionInvokeParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [FunctionInvokeParams]. */ @JvmStatic fun builder() = Builder() } @@ -181,7 +178,10 @@ private constructor( } /** Function id */ - fun functionId(functionId: String) = apply { this.functionId = functionId } + fun functionId(functionId: String?) = apply { this.functionId = functionId } + + /** Alias for calling [Builder.functionId] with `functionId.orElse(null)`. */ + fun functionId(functionId: Optional) = functionId(functionId.getOrNull()) /** * Sets the entire request body. @@ -444,17 +444,10 @@ private constructor( * Returns an immutable instance of [FunctionInvokeParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): FunctionInvokeParams = FunctionInvokeParams( - checkRequired("functionId", functionId), + functionId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -465,7 +458,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> functionId + 0 -> functionId ?: "" else -> "" } @@ -475,6 +468,7 @@ private constructor( /** The request to invoke a function */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val expected: JsonValue, private val input: JsonValue, @@ -865,12 +859,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && expected == other.expected && input == other.input && messages == other.messages && metadata == other.metadata && mode == other.mode && parent == other.parent && stream == other.stream && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + expected == other.expected && + input == other.input && + messages == other.messages && + metadata == other.metadata && + mode == other.mode && + parent == other.parent && + stream == other.stream && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(expected, input, messages, metadata, mode, parent, stream, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + expected, + input, + messages, + metadata, + mode, + parent, + stream, + version, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1016,10 +1029,17 @@ private constructor( return true } - return /* spotless:off */ other is Message && system == other.system && user == other.user && assistant == other.assistant && tool == other.tool && function == other.function && fallback == other.fallback /* spotless:on */ + return other is Message && + system == other.system && + user == other.user && + assistant == other.assistant && + tool == other.tool && + function == other.function && + fallback == other.fallback } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(system, user, assistant, tool, function, fallback) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(system, user, assistant, tool, function, fallback) override fun toString(): String = when { @@ -1143,6 +1163,7 @@ private constructor( } class System + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -1465,7 +1486,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -1478,12 +1499,16 @@ private constructor( return true } - return /* spotless:off */ other is System && role == other.role && content == other.content && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is System && + role == other.role && + content == other.content && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1492,6 +1517,7 @@ private constructor( } class User + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -1821,7 +1847,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -1910,10 +1936,10 @@ private constructor( return true } - return /* spotless:off */ other is Content && text == other.text && array == other.array /* spotless:on */ + return other is Content && text == other.text && array == other.array } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(text, array) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(text, array) override fun toString(): String = when { @@ -1928,7 +1954,8 @@ private constructor( @JvmStatic fun ofText(text: String) = Content(text = text) @JvmStatic - fun ofArray(array: List) = Content(array = array) + fun ofArray(array: List) = + Content(array = array.toImmutable()) } /** @@ -2090,10 +2117,12 @@ private constructor( return true } - return /* spotless:off */ other is ChatCompletionContentPart && text == other.text && image == other.image /* spotless:on */ + return other is ChatCompletionContentPart && + text == other.text && + image == other.image } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(text, image) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(text, image) override fun toString(): String = when { @@ -2214,12 +2243,16 @@ private constructor( return true } - return /* spotless:off */ other is User && role == other.role && content == other.content && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is User && + role == other.role && + content == other.content && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2228,6 +2261,7 @@ private constructor( } class Assistant + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -2655,7 +2689,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -2664,6 +2698,7 @@ private constructor( } class FunctionCall + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val arguments: JsonField, private val name: JsonField, @@ -2853,12 +2888,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionCall && arguments == other.arguments && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionCall && + arguments == other.arguments && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(arguments, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(arguments, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2871,12 +2909,18 @@ private constructor( return true } - return /* spotless:off */ other is Assistant && role == other.role && content == other.content && functionCall == other.functionCall && name == other.name && toolCalls == other.toolCalls && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Assistant && + role == other.role && + content == other.content && + functionCall == other.functionCall && + name == other.name && + toolCalls == other.toolCalls && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, functionCall, name, toolCalls, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, functionCall, name, toolCalls, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2885,6 +2929,7 @@ private constructor( } class Tool + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -3214,7 +3259,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -3227,12 +3272,16 @@ private constructor( return true } - return /* spotless:off */ other is Tool && role == other.role && content == other.content && toolCallId == other.toolCallId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Tool && + role == other.role && + content == other.content && + toolCallId == other.toolCallId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, toolCallId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, toolCallId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3241,6 +3290,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val role: JsonField, @@ -3566,7 +3616,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -3579,12 +3629,16 @@ private constructor( return true } - return /* spotless:off */ other is Function && name == other.name && role == other.role && content == other.content && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + name == other.name && + role == other.role && + content == other.content && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, role, content, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, role, content, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3593,6 +3647,7 @@ private constructor( } class Fallback + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -3887,7 +3942,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -3900,12 +3955,13 @@ private constructor( return true } - return /* spotless:off */ other is Fallback && role == other.role && content == other.content && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Fallback && + role == other.role && + content == other.content && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(role, content, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -4004,12 +4060,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -4136,7 +4190,7 @@ private constructor( return true } - return /* spotless:off */ other is Mode && value == other.value /* spotless:on */ + return other is Mode && value == other.value } override fun hashCode() = value.hashCode() @@ -4230,10 +4284,12 @@ private constructor( return true } - return /* spotless:off */ other is Parent && spanParentStruct == other.spanParentStruct && string == other.string /* spotless:on */ + return other is Parent && + spanParentStruct == other.spanParentStruct && + string == other.string } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanParentStruct, string) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(spanParentStruct, string) override fun toString(): String = when { @@ -4326,6 +4382,7 @@ private constructor( /** Span parent properties */ class SpanParentStruct + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -4733,7 +4790,7 @@ private constructor( return true } - return /* spotless:off */ other is ObjectType && value == other.value /* spotless:on */ + return other is ObjectType && value == other.value } override fun hashCode() = value.hashCode() @@ -4839,12 +4896,11 @@ private constructor( return true } - return /* spotless:off */ other is PropagatedEvent && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PropagatedEvent && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -4854,6 +4910,7 @@ private constructor( /** Identifiers for the row to to log a subspan under */ class RowIds + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val rootSpanId: JsonField, @@ -5088,12 +5145,16 @@ private constructor( return true } - return /* spotless:off */ other is RowIds && id == other.id && rootSpanId == other.rootSpanId && spanId == other.spanId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RowIds && + id == other.id && + rootSpanId == other.rootSpanId && + spanId == other.spanId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, rootSpanId, spanId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, rootSpanId, spanId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5106,12 +5167,17 @@ private constructor( return true } - return /* spotless:off */ other is SpanParentStruct && objectId == other.objectId && objectType == other.objectType && propagatedEvent == other.propagatedEvent && rowIds == other.rowIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SpanParentStruct && + objectId == other.objectId && + objectType == other.objectType && + propagatedEvent == other.propagatedEvent && + rowIds == other.rowIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, propagatedEvent, rowIds, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(objectId, objectType, propagatedEvent, rowIds, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5125,10 +5191,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionInvokeParams && functionId == other.functionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is FunctionInvokeParams && + functionId == other.functionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(functionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "FunctionInvokeParams{functionId=$functionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt index 924b5b93..b932f1ff 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionInvokeResponse.kt @@ -12,6 +12,7 @@ import java.util.Collections import java.util.Objects class FunctionInvokeResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor(private val additionalProperties: MutableMap) { @JsonCreator private constructor() : this(mutableMapOf()) @@ -102,12 +103,10 @@ private constructor(private val additionalProperties: MutableMap { /** * Delegates to [FunctionListPageResponse], but gracefully handles missing data. * - * @see [FunctionListPageResponse.objects] + * @see FunctionListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): FunctionListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): FunctionListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): FunctionListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: FunctionListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is FunctionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is FunctionListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "FunctionListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt index 77b7c749..5cd52e24 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.FunctionServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [FunctionServiceAsync.list] */ +/** @see FunctionServiceAsync.list */ class FunctionListPageAsync private constructor( private val service: FunctionServiceAsync, + private val streamHandlerExecutor: Executor, private val params: FunctionListParams, private val response: FunctionListPageResponse, -) { +) : PageAsync { /** * Delegates to [FunctionListPageResponse], but gracefully handles missing data. * - * @see [FunctionListPageResponse.objects] + * @see FunctionListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): FunctionListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): FunctionListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: FunctionServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: FunctionListParams? = null private var response: FunctionListPageResponse? = null @JvmSynthetic internal fun from(functionListPageAsync: FunctionListPageAsync) = apply { service = functionListPageAsync.service + streamHandlerExecutor = functionListPageAsync.streamHandlerExecutor params = functionListPageAsync.params response = functionListPageAsync.response } fun service(service: FunctionServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: FunctionListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): FunctionListPageAsync = FunctionListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: FunctionListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Function) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is FunctionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is FunctionListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "FunctionListPageAsync{service=$service, params=$params, response=$response}" + "FunctionListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt index 09acf2d6..423c3fba 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class FunctionListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is FunctionListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt index bfbc5441..33d8f263 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -80,8 +81,10 @@ private constructor( */ fun version(): Optional = Optional.ofNullable(version) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -403,10 +406,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -419,7 +422,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -436,10 +439,36 @@ private constructor( return true } - return /* spotless:off */ other is FunctionListParams && endingBefore == other.endingBefore && functionName == other.functionName && ids == other.ids && limit == other.limit && orgName == other.orgName && projectId == other.projectId && projectName == other.projectName && slug == other.slug && startingAfter == other.startingAfter && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is FunctionListParams && + endingBefore == other.endingBefore && + functionName == other.functionName && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectId == other.projectId && + projectName == other.projectName && + slug == other.slug && + startingAfter == other.startingAfter && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, functionName, ids, limit, orgName, projectId, projectName, slug, startingAfter, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + functionName, + ids, + limit, + orgName, + projectId, + projectName, + slug, + startingAfter, + version, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "FunctionListParams{endingBefore=$endingBefore, functionName=$functionName, ids=$ids, limit=$limit, orgName=$orgName, projectId=$projectId, projectName=$projectName, slug=$slug, startingAfter=$startingAfter, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt index 79093cb3..8d4962e5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionReplaceParams.kt @@ -192,8 +192,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -547,6 +549,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val functionData: JsonField, private val name: JsonField, @@ -1089,12 +1092,35 @@ private constructor( return true } - return /* spotless:off */ other is Body && functionData == other.functionData && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionSchema == other.functionSchema && functionType == other.functionType && origin == other.origin && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + functionData == other.functionData && + name == other.name && + projectId == other.projectId && + slug == other.slug && + description == other.description && + functionSchema == other.functionSchema && + functionType == other.functionType && + origin == other.origin && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(functionData, name, projectId, slug, description, functionSchema, functionType, origin, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + functionData, + name, + projectId, + slug, + description, + functionSchema, + functionType, + origin, + promptData, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1198,10 +1224,13 @@ private constructor( return true } - return /* spotless:off */ other is FunctionData && prompt == other.prompt && code == other.code && global == other.global /* spotless:on */ + return other is FunctionData && + prompt == other.prompt && + code == other.code && + global == other.global } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(prompt, code, global) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(prompt, code, global) override fun toString(): String = when { @@ -1299,6 +1328,7 @@ private constructor( } class Prompt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -1553,7 +1583,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1566,12 +1596,12 @@ private constructor( return true } - return /* spotless:off */ other is Prompt && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Prompt && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1580,6 +1610,7 @@ private constructor( } class Code + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField, private val type: JsonField, @@ -1844,10 +1875,10 @@ private constructor( return true } - return /* spotless:off */ other is Data && bundle == other.bundle && inline == other.inline /* spotless:on */ + return other is Data && bundle == other.bundle && inline == other.inline } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(bundle, inline) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(bundle, inline) override fun toString(): String = when { @@ -1937,6 +1968,7 @@ private constructor( } class Bundle + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bundleId: JsonField, private val location: JsonField, @@ -2395,7 +2427,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2408,12 +2440,25 @@ private constructor( return true } - return /* spotless:off */ other is Bundle && bundleId == other.bundleId && location == other.location && runtimeContext == other.runtimeContext && preview == other.preview && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Bundle && + bundleId == other.bundleId && + location == other.location && + runtimeContext == other.runtimeContext && + preview == other.preview && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bundleId, location, runtimeContext, preview, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bundleId, + location, + runtimeContext, + preview, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2422,6 +2467,7 @@ private constructor( } class Inline + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val code: JsonField, private val runtimeContext: JsonField, @@ -2649,6 +2695,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class RuntimeContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -2975,7 +3022,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -2988,12 +3035,15 @@ private constructor( return true } - return /* spotless:off */ other is RuntimeContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RuntimeContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(runtime, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3122,7 +3172,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3135,12 +3185,16 @@ private constructor( return true } - return /* spotless:off */ other is Inline && code == other.code && runtimeContext == other.runtimeContext && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Inline && + code == other.code && + runtimeContext == other.runtimeContext && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, runtimeContext, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(code, runtimeContext, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3265,7 +3319,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3278,12 +3332,13 @@ private constructor( return true } - return /* spotless:off */ other is Code && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Code && + data == other.data && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3292,6 +3347,7 @@ private constructor( } class Global + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -3584,7 +3640,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3597,12 +3653,13 @@ private constructor( return true } - return /* spotless:off */ other is Global && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Global && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3613,6 +3670,7 @@ private constructor( /** JSON schema for the function's parameters and return type */ class FunctionSchema + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val parameters: JsonValue, private val returns: JsonValue, @@ -3724,12 +3782,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionSchema && parameters == other.parameters && returns == other.returns && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionSchema && + parameters == other.parameters && + returns == other.returns && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, returns, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(parameters, returns, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3871,7 +3932,7 @@ private constructor( return true } - return /* spotless:off */ other is FunctionType && value == other.value /* spotless:on */ + return other is FunctionType && value == other.value } override fun hashCode() = value.hashCode() @@ -3880,6 +3941,7 @@ private constructor( } class Origin + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -4120,12 +4182,16 @@ private constructor( return true } - return /* spotless:off */ other is Origin && objectId == other.objectId && objectType == other.objectType && internal_ == other.internal_ && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Origin && + objectId == other.objectId && + objectType == other.objectType && + internal_ == other.internal_ && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, internal_, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(objectId, objectType, internal_, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4138,10 +4204,13 @@ private constructor( return true } - return /* spotless:off */ other is FunctionReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is FunctionReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "FunctionReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt index 17d1b879..e38243ac 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a function object by its id */ class FunctionRetrieveParams private constructor( - private val functionId: String, + private val functionId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Function id */ - fun functionId(): String = functionId + fun functionId(): Optional = Optional.ofNullable(functionId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [FunctionRetrieveParams]. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - */ + @JvmStatic fun none(): FunctionRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [FunctionRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Function id */ - fun functionId(functionId: String) = apply { this.functionId = functionId } + fun functionId(functionId: String?) = apply { this.functionId = functionId } + + /** Alias for calling [Builder.functionId] with `functionId.orElse(null)`. */ + fun functionId(functionId: Optional) = functionId(functionId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [FunctionRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): FunctionRetrieveParams = FunctionRetrieveParams( - checkRequired("functionId", functionId), + functionId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> functionId + 0 -> functionId ?: "" else -> "" } @@ -188,10 +182,14 @@ private constructor( return true } - return /* spotless:off */ other is FunctionRetrieveParams && functionId == other.functionId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is FunctionRetrieveParams && + functionId == other.functionId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(functionId, additionalHeaders, additionalQueryParams) override fun toString() = "FunctionRetrieveParams{functionId=$functionId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt index bc199968..6d3ac626 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/FunctionUpdateParams.kt @@ -42,14 +42,14 @@ import kotlin.jvm.optionals.getOrNull */ class FunctionUpdateParams private constructor( - private val functionId: String, + private val functionId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Function id */ - fun functionId(): String = functionId + fun functionId(): Optional = Optional.ofNullable(functionId) /** * Textual description of the prompt @@ -126,22 +126,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [FunctionUpdateParams]. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - */ + @JvmStatic fun none(): FunctionUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [FunctionUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -162,7 +159,10 @@ private constructor( } /** Function id */ - fun functionId(functionId: String) = apply { this.functionId = functionId } + fun functionId(functionId: String?) = apply { this.functionId = functionId } + + /** Alias for calling [Builder.functionId] with `functionId.orElse(null)`. */ + fun functionId(functionId: Optional) = functionId(functionId.getOrNull()) /** * Sets the entire request body. @@ -391,17 +391,10 @@ private constructor( * Returns an immutable instance of [FunctionUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .functionId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): FunctionUpdateParams = FunctionUpdateParams( - checkRequired("functionId", functionId), + functionId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -412,7 +405,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> functionId + 0 -> functionId ?: "" else -> "" } @@ -421,6 +414,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val description: JsonField, private val functionData: JsonField, @@ -745,12 +739,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && functionData == other.functionData && name == other.name && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + description == other.description && + functionData == other.functionData && + name == other.name && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, functionData, name, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(description, functionData, name, promptData, tags, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -854,10 +854,13 @@ private constructor( return true } - return /* spotless:off */ other is FunctionData && prompt == other.prompt && code == other.code && global == other.global /* spotless:on */ + return other is FunctionData && + prompt == other.prompt && + code == other.code && + global == other.global } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(prompt, code, global) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(prompt, code, global) override fun toString(): String = when { @@ -955,6 +958,7 @@ private constructor( } class Prompt + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -1209,7 +1213,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1222,12 +1226,12 @@ private constructor( return true } - return /* spotless:off */ other is Prompt && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Prompt && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1236,6 +1240,7 @@ private constructor( } class Code + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val data: JsonField, private val type: JsonField, @@ -1500,10 +1505,10 @@ private constructor( return true } - return /* spotless:off */ other is Data && bundle == other.bundle && inline == other.inline /* spotless:on */ + return other is Data && bundle == other.bundle && inline == other.inline } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(bundle, inline) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(bundle, inline) override fun toString(): String = when { @@ -1593,6 +1598,7 @@ private constructor( } class Bundle + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val bundleId: JsonField, private val location: JsonField, @@ -2051,7 +2057,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2064,12 +2070,25 @@ private constructor( return true } - return /* spotless:off */ other is Bundle && bundleId == other.bundleId && location == other.location && runtimeContext == other.runtimeContext && preview == other.preview && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Bundle && + bundleId == other.bundleId && + location == other.location && + runtimeContext == other.runtimeContext && + preview == other.preview && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(bundleId, location, runtimeContext, preview, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + bundleId, + location, + runtimeContext, + preview, + type, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2078,6 +2097,7 @@ private constructor( } class Inline + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val code: JsonField, private val runtimeContext: JsonField, @@ -2305,6 +2325,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class RuntimeContext + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val runtime: JsonField, private val version: JsonField, @@ -2631,7 +2652,7 @@ private constructor( return true } - return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */ + return other is Runtime && value == other.value } override fun hashCode() = value.hashCode() @@ -2644,12 +2665,15 @@ private constructor( return true } - return /* spotless:off */ other is RuntimeContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RuntimeContext && + runtime == other.runtime && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(runtime, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2778,7 +2802,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2791,12 +2815,16 @@ private constructor( return true } - return /* spotless:off */ other is Inline && code == other.code && runtimeContext == other.runtimeContext && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Inline && + code == other.code && + runtimeContext == other.runtimeContext && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, runtimeContext, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(code, runtimeContext, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2921,7 +2949,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2934,12 +2962,13 @@ private constructor( return true } - return /* spotless:off */ other is Code && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Code && + data == other.data && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2948,6 +2977,7 @@ private constructor( } class Global + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -3240,7 +3270,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3253,12 +3283,13 @@ private constructor( return true } - return /* spotless:off */ other is Global && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Global && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3272,10 +3303,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionUpdateParams && functionId == other.functionId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is FunctionUpdateParams && + functionId == other.functionId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(functionId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(functionId, body, additionalHeaders, additionalQueryParams) override fun toString() = "FunctionUpdateParams{functionId=$functionId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt index 756c44c0..8d26f5d0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Group.kt @@ -26,6 +26,7 @@ import kotlin.jvm.optionals.getOrNull * Groups can consist of individual users, as well as a set of groups they inherit from */ class Group +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -532,12 +533,33 @@ private constructor( return true } - return /* spotless:off */ other is Group && id == other.id && name == other.name && orgId == other.orgId && created == other.created && deletedAt == other.deletedAt && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Group && + id == other.id && + name == other.name && + orgId == other.orgId && + created == other.created && + deletedAt == other.deletedAt && + description == other.description && + memberGroups == other.memberGroups && + memberUsers == other.memberUsers && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, orgId, created, deletedAt, description, memberGroups, memberUsers, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + orgId, + created, + deletedAt, + description, + memberGroups, + memberUsers, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt index 8843a37b..2cc4d139 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupCreateParams.kt @@ -115,8 +115,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -404,6 +406,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val description: JsonField, @@ -759,13 +762,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + description == other.description && + memberGroups == other.memberGroups && + memberUsers == other.memberUsers && + orgName == other.orgName && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + name, + description, + memberGroups, + memberUsers, + orgName, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberGroups, memberUsers, orgName, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -777,10 +793,13 @@ private constructor( return true } - return /* spotless:off */ other is GroupCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is GroupCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "GroupCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt index 95ce78c4..aaf2ab81 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a group object by its id */ class GroupDeleteParams private constructor( - private val groupId: String, + private val groupId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Group id */ - fun groupId(): String = groupId + fun groupId(): Optional = Optional.ofNullable(groupId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [GroupDeleteParams]. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - */ + @JvmStatic fun none(): GroupDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [GroupDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Group id */ - fun groupId(groupId: String) = apply { this.groupId = groupId } + fun groupId(groupId: String?) = apply { this.groupId = groupId } + + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [GroupDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): GroupDeleteParams = GroupDeleteParams( - checkRequired("groupId", groupId), + groupId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> groupId + 0 -> groupId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is GroupDeleteParams && groupId == other.groupId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is GroupDeleteParams && + groupId == other.groupId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(groupId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(groupId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "GroupDeleteParams{groupId=$groupId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt index af4e384c..0e0898de 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.GroupService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [GroupService.list] */ +/** @see GroupService.list */ class GroupListPage private constructor( private val service: GroupService, private val params: GroupListParams, private val response: GroupListPageResponse, -) { +) : Page { /** * Delegates to [GroupListPageResponse], but gracefully handles missing data. * - * @see [GroupListPageResponse.objects] + * @see GroupListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): GroupListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): GroupListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): GroupListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: GroupListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is GroupListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "GroupListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt index 57388a7d..688fe9a2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageAsync.kt @@ -2,53 +2,46 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.GroupServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [GroupServiceAsync.list] */ +/** @see GroupServiceAsync.list */ class GroupListPageAsync private constructor( private val service: GroupServiceAsync, + private val streamHandlerExecutor: Executor, private val params: GroupListParams, private val response: GroupListPageResponse, -) { +) : PageAsync { /** * Delegates to [GroupListPageResponse], but gracefully handles missing data. * - * @see [GroupListPageResponse.objects] + * @see GroupListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): GroupListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): GroupListParams = params @@ -66,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +71,24 @@ private constructor( class Builder internal constructor() { private var service: GroupServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: GroupListParams? = null private var response: GroupListPageResponse? = null @JvmSynthetic internal fun from(groupListPageAsync: GroupListPageAsync) = apply { service = groupListPageAsync.service + streamHandlerExecutor = groupListPageAsync.streamHandlerExecutor params = groupListPageAsync.params response = groupListPageAsync.response } fun service(service: GroupServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: GroupListParams) = apply { this.params = params } @@ -103,6 +103,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +113,26 @@ private constructor( fun build(): GroupListPageAsync = GroupListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: GroupListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Group) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is GroupListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is GroupListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "GroupListPageAsync{service=$service, params=$params, response=$response}" + "GroupListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt index dafbd5f2..2041e2a3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class GroupListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is GroupListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GroupListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt index eb8cc72c..186ac5df 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -59,8 +60,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -337,10 +340,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -353,7 +356,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -370,10 +373,28 @@ private constructor( return true } - return /* spotless:off */ other is GroupListParams && endingBefore == other.endingBefore && groupName == other.groupName && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is GroupListParams && + endingBefore == other.endingBefore && + groupName == other.groupName && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, groupName, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + groupName, + ids, + limit, + orgName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "GroupListParams{endingBefore=$endingBefore, groupName=$groupName, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt index 281249c7..8c31f44d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupReplaceParams.kt @@ -115,8 +115,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -404,6 +406,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val description: JsonField, @@ -759,13 +762,26 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberGroups == other.memberGroups && memberUsers == other.memberUsers && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + description == other.description && + memberGroups == other.memberGroups && + memberUsers == other.memberUsers && + orgName == other.orgName && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + name, + description, + memberGroups, + memberUsers, + orgName, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberGroups, memberUsers, orgName, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -777,10 +793,13 @@ private constructor( return true } - return /* spotless:off */ other is GroupReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is GroupReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "GroupReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt index 0134decd..ec78ce09 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a group object by its id */ class GroupRetrieveParams private constructor( - private val groupId: String, + private val groupId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Group id */ - fun groupId(): String = groupId + fun groupId(): Optional = Optional.ofNullable(groupId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [GroupRetrieveParams]. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - */ + @JvmStatic fun none(): GroupRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [GroupRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Group id */ - fun groupId(groupId: String) = apply { this.groupId = groupId } + fun groupId(groupId: String?) = apply { this.groupId = groupId } + + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [GroupRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): GroupRetrieveParams = - GroupRetrieveParams( - checkRequired("groupId", groupId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + GroupRetrieveParams(groupId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> groupId + 0 -> groupId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is GroupRetrieveParams && groupId == other.groupId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is GroupRetrieveParams && + groupId == other.groupId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(groupId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(groupId, additionalHeaders, additionalQueryParams) override fun toString() = "GroupRetrieveParams{groupId=$groupId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt index 1eef9986..3ea798f9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/GroupUpdateParams.kt @@ -8,7 +8,6 @@ import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable @@ -29,14 +28,14 @@ import kotlin.jvm.optionals.getOrNull */ class GroupUpdateParams private constructor( - private val groupId: String, + private val groupId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Group id */ - fun groupId(): String = groupId + fun groupId(): Optional = Optional.ofNullable(groupId) /** * A list of group IDs to add to the group's inheriting-from set @@ -132,22 +131,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [GroupUpdateParams]. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - */ + @JvmStatic fun none(): GroupUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [GroupUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -168,7 +164,10 @@ private constructor( } /** Group id */ - fun groupId(groupId: String) = apply { this.groupId = groupId } + fun groupId(groupId: String?) = apply { this.groupId = groupId } + + /** Alias for calling [Builder.groupId] with `groupId.orElse(null)`. */ + fun groupId(groupId: Optional) = groupId(groupId.getOrNull()) /** * Sets the entire request body. @@ -450,17 +449,10 @@ private constructor( * Returns an immutable instance of [GroupUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .groupId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): GroupUpdateParams = GroupUpdateParams( - checkRequired("groupId", groupId), + groupId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -471,7 +463,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> groupId + 0 -> groupId ?: "" else -> "" } @@ -480,6 +472,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val addMemberGroups: JsonField>, private val addMemberUsers: JsonField>, @@ -907,13 +900,28 @@ private constructor( return true } - return /* spotless:off */ other is Body && addMemberGroups == other.addMemberGroups && addMemberUsers == other.addMemberUsers && description == other.description && name == other.name && removeMemberGroups == other.removeMemberGroups && removeMemberUsers == other.removeMemberUsers && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + addMemberGroups == other.addMemberGroups && + addMemberUsers == other.addMemberUsers && + description == other.description && + name == other.name && + removeMemberGroups == other.removeMemberGroups && + removeMemberUsers == other.removeMemberUsers && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + addMemberGroups, + addMemberUsers, + description, + name, + removeMemberGroups, + removeMemberUsers, + additionalProperties, + ) } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addMemberGroups, addMemberUsers, description, name, removeMemberGroups, removeMemberUsers, additionalProperties) } - /* spotless:on */ - override fun hashCode(): Int = hashCode override fun toString() = @@ -925,10 +933,15 @@ private constructor( return true } - return /* spotless:off */ other is GroupUpdateParams && groupId == other.groupId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is GroupUpdateParams && + groupId == other.groupId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(groupId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(groupId, body, additionalHeaders, additionalQueryParams) override fun toString() = "GroupUpdateParams{groupId=$groupId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt index f19ac1e2..aa7784d0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertDatasetEvent.kt @@ -21,6 +21,7 @@ import kotlin.jvm.optionals.getOrNull /** A dataset event */ class InsertDatasetEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _isMerge: JsonField, @@ -865,6 +866,7 @@ private constructor( * must be strings */ class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val additionalProperties: MutableMap, @@ -994,12 +996,12 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && + model == other.model && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1012,12 +1014,43 @@ private constructor( return true } - return /* spotless:off */ other is InsertDatasetEvent && id == other.id && _isMerge == other._isMerge && _mergePaths == other._mergePaths && _objectDelete == other._objectDelete && _parentId == other._parentId && created == other.created && expected == other.expected && input == other.input && metadata == other.metadata && origin == other.origin && rootSpanId == other.rootSpanId && spanId == other.spanId && spanParents == other.spanParents && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InsertDatasetEvent && + id == other.id && + _isMerge == other._isMerge && + _mergePaths == other._mergePaths && + _objectDelete == other._objectDelete && + _parentId == other._parentId && + created == other.created && + expected == other.expected && + input == other.input && + metadata == other.metadata && + origin == other.origin && + rootSpanId == other.rootSpanId && + spanId == other.spanId && + spanParents == other.spanParents && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _isMerge, _mergePaths, _objectDelete, _parentId, created, expected, input, metadata, origin, rootSpanId, spanId, spanParents, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _isMerge, + _mergePaths, + _objectDelete, + _parentId, + created, + expected, + input, + metadata, + origin, + rootSpanId, + spanId, + spanParents, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt index becc87ae..4d343317 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertEventsResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class InsertEventsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val rowIds: JsonField>, private val additionalProperties: MutableMap, @@ -179,12 +180,12 @@ private constructor( return true } - return /* spotless:off */ other is InsertEventsResponse && rowIds == other.rowIds && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InsertEventsResponse && + rowIds == other.rowIds && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(rowIds, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt index d45b6b9a..a2d9a918 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertExperimentEvent.kt @@ -21,6 +21,7 @@ import kotlin.jvm.optionals.getOrNull /** An experiment event */ class InsertExperimentEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _isMerge: JsonField, @@ -1098,6 +1099,7 @@ private constructor( * location in code which produced the experiment event */ class Context + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonField, private val callerFunctionname: JsonField, @@ -1343,12 +1345,16 @@ private constructor( return true } - return /* spotless:off */ other is Context && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Context && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1364,6 +1370,7 @@ private constructor( * must be strings */ class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val additionalProperties: MutableMap, @@ -1493,12 +1500,12 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && + model == other.model && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1512,6 +1519,7 @@ private constructor( * event was produced */ class Metrics + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonValue, private val callerFunctionname: JsonValue, @@ -1922,12 +1930,31 @@ private constructor( return true } - return /* spotless:off */ other is Metrics && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && completionTokens == other.completionTokens && end == other.end && promptTokens == other.promptTokens && start == other.start && tokens == other.tokens && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metrics && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + completionTokens == other.completionTokens && + end == other.end && + promptTokens == other.promptTokens && + start == other.start && + tokens == other.tokens && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, completionTokens, end, promptTokens, start, tokens, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2033,12 +2060,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2050,12 +2075,55 @@ private constructor( return true } - return /* spotless:off */ other is InsertExperimentEvent && id == other.id && _isMerge == other._isMerge && _mergePaths == other._mergePaths && _objectDelete == other._objectDelete && _parentId == other._parentId && context == other.context && created == other.created && error == other.error && expected == other.expected && input == other.input && metadata == other.metadata && metrics == other.metrics && origin == other.origin && output == other.output && rootSpanId == other.rootSpanId && scores == other.scores && spanAttributes == other.spanAttributes && spanId == other.spanId && spanParents == other.spanParents && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InsertExperimentEvent && + id == other.id && + _isMerge == other._isMerge && + _mergePaths == other._mergePaths && + _objectDelete == other._objectDelete && + _parentId == other._parentId && + context == other.context && + created == other.created && + error == other.error && + expected == other.expected && + input == other.input && + metadata == other.metadata && + metrics == other.metrics && + origin == other.origin && + output == other.output && + rootSpanId == other.rootSpanId && + scores == other.scores && + spanAttributes == other.spanAttributes && + spanId == other.spanId && + spanParents == other.spanParents && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _isMerge, _mergePaths, _objectDelete, _parentId, context, created, error, expected, input, metadata, metrics, origin, output, rootSpanId, scores, spanAttributes, spanId, spanParents, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _isMerge, + _mergePaths, + _objectDelete, + _parentId, + context, + created, + error, + expected, + input, + metadata, + metrics, + origin, + output, + rootSpanId, + scores, + spanAttributes, + spanId, + spanParents, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt index 1062598d..15a2d806 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/InsertProjectLogsEvent.kt @@ -21,6 +21,7 @@ import kotlin.jvm.optionals.getOrNull /** A project logs event */ class InsertProjectLogsEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _isMerge: JsonField, @@ -1090,6 +1091,7 @@ private constructor( * location in code which produced the project logs event */ class Context + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonField, private val callerFunctionname: JsonField, @@ -1335,12 +1337,16 @@ private constructor( return true } - return /* spotless:off */ other is Context && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Context && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1356,6 +1362,7 @@ private constructor( * must be strings */ class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val additionalProperties: MutableMap, @@ -1485,12 +1492,12 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && + model == other.model && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1504,6 +1511,7 @@ private constructor( * event was produced */ class Metrics + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonValue, private val callerFunctionname: JsonValue, @@ -1914,12 +1922,31 @@ private constructor( return true } - return /* spotless:off */ other is Metrics && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && completionTokens == other.completionTokens && end == other.end && promptTokens == other.promptTokens && start == other.start && tokens == other.tokens && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metrics && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + completionTokens == other.completionTokens && + end == other.end && + promptTokens == other.promptTokens && + start == other.start && + tokens == other.tokens && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, completionTokens, end, promptTokens, start, tokens, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2025,12 +2052,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2042,12 +2067,55 @@ private constructor( return true } - return /* spotless:off */ other is InsertProjectLogsEvent && id == other.id && _isMerge == other._isMerge && _mergePaths == other._mergePaths && _objectDelete == other._objectDelete && _parentId == other._parentId && context == other.context && created == other.created && error == other.error && expected == other.expected && input == other.input && metadata == other.metadata && metrics == other.metrics && origin == other.origin && output == other.output && rootSpanId == other.rootSpanId && scores == other.scores && spanAttributes == other.spanAttributes && spanId == other.spanId && spanParents == other.spanParents && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InsertProjectLogsEvent && + id == other.id && + _isMerge == other._isMerge && + _mergePaths == other._mergePaths && + _objectDelete == other._objectDelete && + _parentId == other._parentId && + context == other.context && + created == other.created && + error == other.error && + expected == other.expected && + input == other.input && + metadata == other.metadata && + metrics == other.metrics && + origin == other.origin && + output == other.output && + rootSpanId == other.rootSpanId && + scores == other.scores && + spanAttributes == other.spanAttributes && + spanId == other.spanId && + spanParents == other.spanParents && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _isMerge, _mergePaths, _objectDelete, _parentId, context, created, error, expected, input, metadata, metrics, origin, output, rootSpanId, scores, spanAttributes, spanId, spanParents, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _isMerge, + _mergePaths, + _objectDelete, + _parentId, + context, + created, + error, + expected, + input, + metadata, + metrics, + origin, + output, + rootSpanId, + scores, + spanAttributes, + spanId, + spanParents, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt index 04a8b3fe..c4631b77 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/MetricSummary.kt @@ -18,6 +18,7 @@ import java.util.Optional /** Summary of a metric's performance */ class MetricSummary +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val improvements: JsonField, private val metric: JsonField, @@ -343,12 +344,19 @@ private constructor( return true } - return /* spotless:off */ other is MetricSummary && improvements == other.improvements && metric == other.metric && name == other.name && regressions == other.regressions && unit == other.unit && diff == other.diff && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MetricSummary && + improvements == other.improvements && + metric == other.metric && + name == other.name && + regressions == other.regressions && + unit == other.unit && + diff == other.diff && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(improvements, metric, name, regressions, unit, diff, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(improvements, metric, name, regressions, unit, diff, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt index b55336ff..dc51c408 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ObjectReference.kt @@ -20,6 +20,7 @@ import kotlin.jvm.optionals.getOrNull /** Indicates the event was copied from another object. */ class ObjectReference +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _xactId: JsonField, @@ -451,7 +452,7 @@ private constructor( return true } - return /* spotless:off */ other is ObjectType && value == other.value /* spotless:on */ + return other is ObjectType && value == other.value } override fun hashCode() = value.hashCode() @@ -464,12 +465,18 @@ private constructor( return true } - return /* spotless:off */ other is ObjectReference && id == other.id && _xactId == other._xactId && objectId == other.objectId && objectType == other.objectType && created == other.created && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ObjectReference && + id == other.id && + _xactId == other._xactId && + objectId == other.objectId && + objectType == other.objectType && + created == other.created && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _xactId, objectId, objectType, created, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, _xactId, objectId, objectType, created, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt index e44af8fe..3e1905bb 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OnlineScoreConfig.kt @@ -32,6 +32,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class OnlineScoreConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val samplingRate: JsonField, private val scorers: JsonField>, @@ -429,10 +430,10 @@ private constructor( return true } - return /* spotless:off */ other is Scorer && function == other.function && global == other.global /* spotless:on */ + return other is Scorer && function == other.function && global == other.global } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(function, global) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(function, global) override fun toString(): String = when { @@ -518,6 +519,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val type: JsonField, @@ -810,7 +812,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -823,12 +825,13 @@ private constructor( return true } - return /* spotless:off */ other is Function && id == other.id && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + id == other.id && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -837,6 +840,7 @@ private constructor( } class Global + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -1129,7 +1133,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1142,12 +1146,13 @@ private constructor( return true } - return /* spotless:off */ other is Global && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Global && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1161,12 +1166,17 @@ private constructor( return true } - return /* spotless:off */ other is OnlineScoreConfig && samplingRate == other.samplingRate && scorers == other.scorers && applyToRootSpan == other.applyToRootSpan && applyToSpanNames == other.applyToSpanNames && additionalProperties == other.additionalProperties /* spotless:on */ + return other is OnlineScoreConfig && + samplingRate == other.samplingRate && + scorers == other.scorers && + applyToRootSpan == other.applyToRootSpan && + applyToSpanNames == other.applyToSpanNames && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(samplingRate, scorers, applyToRootSpan, applyToSpanNames, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(samplingRate, scorers, applyToRootSpan, applyToSpanNames, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt index d80fcb7f..86b44aed 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Organization.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class Organization +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -390,12 +391,29 @@ private constructor( return true } - return /* spotless:off */ other is Organization && id == other.id && name == other.name && apiUrl == other.apiUrl && created == other.created && isUniversalApi == other.isUniversalApi && proxyUrl == other.proxyUrl && realtimeUrl == other.realtimeUrl && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Organization && + id == other.id && + name == other.name && + apiUrl == other.apiUrl && + created == other.created && + isUniversalApi == other.isUniversalApi && + proxyUrl == other.proxyUrl && + realtimeUrl == other.realtimeUrl && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, apiUrl, created, isUniversalApi, proxyUrl, realtimeUrl, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + apiUrl, + created, + isUniversalApi, + proxyUrl, + realtimeUrl, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt index 7247f8ec..cc9d76b9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete an organization object by its id */ class OrganizationDeleteParams private constructor( - private val organizationId: String, + private val organizationId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Organization id */ - fun organizationId(): String = organizationId + fun organizationId(): Optional = Optional.ofNullable(organizationId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [OrganizationDeleteParams]. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - */ + @JvmStatic fun none(): OrganizationDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [OrganizationDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -62,7 +60,11 @@ private constructor( } /** Organization id */ - fun organizationId(organizationId: String) = apply { this.organizationId = organizationId } + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -188,17 +190,10 @@ private constructor( * Returns an immutable instance of [OrganizationDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): OrganizationDeleteParams = OrganizationDeleteParams( - checkRequired("organizationId", organizationId), + organizationId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -210,7 +205,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> organizationId + 0 -> organizationId ?: "" else -> "" } @@ -223,10 +218,20 @@ private constructor( return true } - return /* spotless:off */ other is OrganizationDeleteParams && organizationId == other.organizationId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is OrganizationDeleteParams && + organizationId == other.organizationId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(organizationId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + organizationId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "OrganizationDeleteParams{organizationId=$organizationId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt index f8d68211..6d51bbe6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.OrganizationService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [OrganizationService.list] */ +/** @see OrganizationService.list */ class OrganizationListPage private constructor( private val service: OrganizationService, private val params: OrganizationListParams, private val response: OrganizationListPageResponse, -) { +) : Page { /** * Delegates to [OrganizationListPageResponse], but gracefully handles missing data. * - * @see [OrganizationListPageResponse.objects] + * @see OrganizationListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): OrganizationListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): OrganizationListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): OrganizationListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: OrganizationListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is OrganizationListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is OrganizationListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "OrganizationListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt index 8d1fb8a2..0509c367 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.OrganizationServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [OrganizationServiceAsync.list] */ +/** @see OrganizationServiceAsync.list */ class OrganizationListPageAsync private constructor( private val service: OrganizationServiceAsync, + private val streamHandlerExecutor: Executor, private val params: OrganizationListParams, private val response: OrganizationListPageResponse, -) { +) : PageAsync { /** * Delegates to [OrganizationListPageResponse], but gracefully handles missing data. * - * @see [OrganizationListPageResponse.objects] + * @see OrganizationListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): OrganizationListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): OrganizationListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: OrganizationServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: OrganizationListParams? = null private var response: OrganizationListPageResponse? = null @JvmSynthetic internal fun from(organizationListPageAsync: OrganizationListPageAsync) = apply { service = organizationListPageAsync.service + streamHandlerExecutor = organizationListPageAsync.streamHandlerExecutor params = organizationListPageAsync.params response = organizationListPageAsync.response } fun service(service: OrganizationServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: OrganizationListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): OrganizationListPageAsync = OrganizationListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: OrganizationListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Organization) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is OrganizationListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is OrganizationListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "OrganizationListPageAsync{service=$service, params=$params, response=$response}" + "OrganizationListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt index 2bd0dfe3..b68414d7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class OrganizationListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is OrganizationListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is OrganizationListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt index af6f46c8..bdb9a6d1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -55,8 +56,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -323,10 +326,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -339,7 +342,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -356,10 +359,26 @@ private constructor( return true } - return /* spotless:off */ other is OrganizationListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is OrganizationListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "OrganizationListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt index 0cb08253..589862c0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationMemberUpdateParams.kt @@ -95,8 +95,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -345,6 +347,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val inviteUsers: JsonField, private val orgId: JsonField, @@ -615,12 +618,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && inviteUsers == other.inviteUsers && orgId == other.orgId && orgName == other.orgName && removeUsers == other.removeUsers && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + inviteUsers == other.inviteUsers && + orgId == other.orgId && + orgName == other.orgName && + removeUsers == other.removeUsers && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(inviteUsers, orgId, orgName, removeUsers, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(inviteUsers, orgId, orgName, removeUsers, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -630,6 +638,7 @@ private constructor( /** Users to invite to the organization */ class InviteUsers + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val emails: JsonField>, private val groupId: JsonField, @@ -1081,12 +1090,29 @@ private constructor( return true } - return /* spotless:off */ other is InviteUsers && emails == other.emails && groupId == other.groupId && groupIds == other.groupIds && groupName == other.groupName && groupNames == other.groupNames && ids == other.ids && sendInviteEmails == other.sendInviteEmails && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InviteUsers && + emails == other.emails && + groupId == other.groupId && + groupIds == other.groupIds && + groupName == other.groupName && + groupNames == other.groupNames && + ids == other.ids && + sendInviteEmails == other.sendInviteEmails && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(emails, groupId, groupIds, groupName, groupNames, ids, sendInviteEmails, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + emails, + groupId, + groupIds, + groupName, + groupNames, + ids, + sendInviteEmails, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1096,6 +1122,7 @@ private constructor( /** Users to remove from the organization */ class RemoveUsers + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val emails: JsonField>, private val ids: JsonField>, @@ -1294,12 +1321,13 @@ private constructor( return true } - return /* spotless:off */ other is RemoveUsers && emails == other.emails && ids == other.ids && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RemoveUsers && + emails == other.emails && + ids == other.ids && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(emails, ids, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1312,10 +1340,13 @@ private constructor( return true } - return /* spotless:off */ other is OrganizationMemberUpdateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is OrganizationMemberUpdateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "OrganizationMemberUpdateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt index 6be05478..c3edc93e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationRetrieveParams.kt @@ -3,37 +3,37 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an organization object by its id */ class OrganizationRetrieveParams private constructor( - private val organizationId: String, + private val organizationId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Organization id */ - fun organizationId(): String = organizationId + fun organizationId(): Optional = Optional.ofNullable(organizationId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { + @JvmStatic fun none(): OrganizationRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [OrganizationRetrieveParams]. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -53,7 +53,11 @@ private constructor( } /** Organization id */ - fun organizationId(organizationId: String) = apply { this.organizationId = organizationId } + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +161,10 @@ private constructor( * Returns an immutable instance of [OrganizationRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): OrganizationRetrieveParams = OrganizationRetrieveParams( - checkRequired("organizationId", organizationId), + organizationId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +172,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> organizationId + 0 -> organizationId ?: "" else -> "" } @@ -188,10 +185,14 @@ private constructor( return true } - return /* spotless:off */ other is OrganizationRetrieveParams && organizationId == other.organizationId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is OrganizationRetrieveParams && + organizationId == other.organizationId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(organizationId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(organizationId, additionalHeaders, additionalQueryParams) override fun toString() = "OrganizationRetrieveParams{organizationId=$organizationId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt index 83ffe1a5..9061f6f3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/OrganizationUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class OrganizationUpdateParams private constructor( - private val organizationId: String, + private val organizationId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Organization id */ - fun organizationId(): String = organizationId + fun organizationId(): Optional = Optional.ofNullable(organizationId) /** * @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -105,22 +104,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [OrganizationUpdateParams]. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - */ + @JvmStatic fun none(): OrganizationUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [OrganizationUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -141,7 +137,11 @@ private constructor( } /** Organization id */ - fun organizationId(organizationId: String) = apply { this.organizationId = organizationId } + fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId } + + /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ + fun organizationId(organizationId: Optional) = + organizationId(organizationId.getOrNull()) /** * Sets the entire request body. @@ -356,17 +356,10 @@ private constructor( * Returns an immutable instance of [OrganizationUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .organizationId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): OrganizationUpdateParams = OrganizationUpdateParams( - checkRequired("organizationId", organizationId), + organizationId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -377,7 +370,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> organizationId + 0 -> organizationId ?: "" else -> "" } @@ -386,6 +379,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val apiUrl: JsonField, private val isUniversalApi: JsonField, @@ -681,12 +675,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && apiUrl == other.apiUrl && isUniversalApi == other.isUniversalApi && name == other.name && proxyUrl == other.proxyUrl && realtimeUrl == other.realtimeUrl && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + apiUrl == other.apiUrl && + isUniversalApi == other.isUniversalApi && + name == other.name && + proxyUrl == other.proxyUrl && + realtimeUrl == other.realtimeUrl && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(apiUrl, isUniversalApi, name, proxyUrl, realtimeUrl, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(apiUrl, isUniversalApi, name, proxyUrl, realtimeUrl, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -699,10 +699,15 @@ private constructor( return true } - return /* spotless:off */ other is OrganizationUpdateParams && organizationId == other.organizationId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is OrganizationUpdateParams && + organizationId == other.organizationId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(organizationId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(organizationId, body, additionalHeaders, additionalQueryParams) override fun toString() = "OrganizationUpdateParams{organizationId=$organizationId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt index 03a43cc2..e50e673d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PatchOrganizationMembersOutput.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class PatchOrganizationMembersOutput +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val orgId: JsonField, private val status: JsonField, @@ -354,7 +355,7 @@ private constructor( return true } - return /* spotless:off */ other is Status && value == other.value /* spotless:on */ + return other is Status && value == other.value } override fun hashCode() = value.hashCode() @@ -367,12 +368,16 @@ private constructor( return true } - return /* spotless:off */ other is PatchOrganizationMembersOutput && orgId == other.orgId && status == other.status && sendEmailError == other.sendEmailError && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PatchOrganizationMembersOutput && + orgId == other.orgId && + status == other.status && + sendEmailError == other.sendEmailError && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(orgId, status, sendEmailError, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(orgId, status, sendEmailError, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt index 7e4cb415..50e97a37 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Permission.kt @@ -163,7 +163,7 @@ class Permission @JsonCreator private constructor(private val value: JsonField, private val name: JsonField, @@ -385,12 +386,20 @@ private constructor( return true } - return /* spotless:off */ other is Project && id == other.id && name == other.name && orgId == other.orgId && created == other.created && deletedAt == other.deletedAt && settings == other.settings && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Project && + id == other.id && + name == other.name && + orgId == other.orgId && + created == other.created && + deletedAt == other.deletedAt && + settings == other.settings && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, orgId, created, deletedAt, settings, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, name, orgId, created, deletedAt, settings, userId, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt index f09b95b2..e4fc5033 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectCreateParams.kt @@ -65,8 +65,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -281,6 +283,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val orgName: JsonField, @@ -465,12 +468,13 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + orgName == other.orgName && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -483,10 +487,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt index 1da020c8..3cfacf7a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a project object by its id */ class ProjectDeleteParams private constructor( - private val projectId: String, + private val projectId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectDeleteParams]. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - */ + @JvmStatic fun none(): ProjectDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [ProjectDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectDeleteParams = ProjectDeleteParams( - checkRequired("projectId", projectId), + projectId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectDeleteParams && projectId == other.projectId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is ProjectDeleteParams && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "ProjectDeleteParams{projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt index 0ed7293d..abd9a6c9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ProjectService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [ProjectService.list] */ +/** @see ProjectService.list */ class ProjectListPage private constructor( private val service: ProjectService, private val params: ProjectListParams, private val response: ProjectListPageResponse, -) { +) : Page { /** * Delegates to [ProjectListPageResponse], but gracefully handles missing data. * - * @see [ProjectListPageResponse.objects] + * @see ProjectListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ProjectListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ProjectListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ProjectListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: ProjectListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ProjectListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ProjectListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt index 3051a64a..e583e63c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ProjectServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [ProjectServiceAsync.list] */ +/** @see ProjectServiceAsync.list */ class ProjectListPageAsync private constructor( private val service: ProjectServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ProjectListParams, private val response: ProjectListPageResponse, -) { +) : PageAsync { /** * Delegates to [ProjectListPageResponse], but gracefully handles missing data. * - * @see [ProjectListPageResponse.objects] + * @see ProjectListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ProjectListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ProjectListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: ProjectServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ProjectListParams? = null private var response: ProjectListPageResponse? = null @JvmSynthetic internal fun from(projectListPageAsync: ProjectListPageAsync) = apply { service = projectListPageAsync.service + streamHandlerExecutor = projectListPageAsync.streamHandlerExecutor params = projectListPageAsync.params response = projectListPageAsync.response } fun service(service: ProjectServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ProjectListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): ProjectListPageAsync = ProjectListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: ProjectListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Project) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ProjectListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "ProjectListPageAsync{service=$service, params=$params, response=$response}" + "ProjectListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt index b789cd90..eb9f328d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ProjectListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is ProjectListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt index 75beee12..b541d16e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -59,8 +60,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -337,10 +340,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -353,7 +356,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -370,10 +373,28 @@ private constructor( return true } - return /* spotless:off */ other is ProjectListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && projectName == other.projectName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectName == other.projectName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, projectName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + projectName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ProjectListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, projectName=$projectName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt index e8cac1f5..f1c32bd7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFeedbackParams.kt @@ -19,19 +19,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Log feedback for a set of project logs events */ class ProjectLogFeedbackParams private constructor( - private val projectId: String, + private val projectId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) /** * A list of project logs feedback items @@ -50,8 +51,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -63,7 +66,6 @@ private constructor( * * The following fields are required: * ```java - * .projectId() * .feedback() * ``` */ @@ -87,7 +89,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) /** * Sets the entire request body. @@ -243,7 +248,6 @@ private constructor( * * The following fields are required: * ```java - * .projectId() * .feedback() * ``` * @@ -251,7 +255,7 @@ private constructor( */ fun build(): ProjectLogFeedbackParams = ProjectLogFeedbackParams( - checkRequired("projectId", projectId), + projectId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -262,7 +266,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -271,6 +275,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val feedback: JsonField>, private val additionalProperties: MutableMap, @@ -435,12 +440,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + feedback == other.feedback && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -453,10 +458,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectLogFeedbackParams && projectId == other.projectId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectLogFeedbackParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectLogFeedbackParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt index 3b8204f5..8ee83088 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchParams.kt @@ -3,7 +3,6 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects @@ -17,7 +16,7 @@ import kotlin.jvm.optionals.getOrNull */ class ProjectLogFetchParams private constructor( - private val projectId: String, + private val projectId: String?, private val limit: Long?, private val maxRootSpanId: String?, private val maxXactId: String?, @@ -27,7 +26,7 @@ private constructor( ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) /** * limit the number of traces fetched @@ -81,22 +80,19 @@ private constructor( */ fun version(): Optional = Optional.ofNullable(version) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectLogFetchParams]. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - */ + @JvmStatic fun none(): ProjectLogFetchParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectLogFetchParams]. */ @JvmStatic fun builder() = Builder() } @@ -123,7 +119,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) /** * limit the number of traces fetched @@ -300,17 +299,10 @@ private constructor( * Returns an immutable instance of [ProjectLogFetchParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectLogFetchParams = ProjectLogFetchParams( - checkRequired("projectId", projectId), + projectId, limit, maxRootSpanId, maxXactId, @@ -322,7 +314,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -344,10 +336,26 @@ private constructor( return true } - return /* spotless:off */ other is ProjectLogFetchParams && projectId == other.projectId && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectLogFetchParams && + projectId == other.projectId && + limit == other.limit && + maxRootSpanId == other.maxRootSpanId && + maxXactId == other.maxXactId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, limit, maxRootSpanId, maxXactId, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + projectId, + limit, + maxRootSpanId, + maxXactId, + version, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ProjectLogFetchParams{projectId=$projectId, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt index 31b5a074..4099db79 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogFetchPostParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class ProjectLogFetchPostParams private constructor( - private val projectId: String, + private val projectId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) /** * An opaque string to be used as a cursor for the next page of results, in order from latest to @@ -148,21 +147,20 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { + @JvmStatic fun none(): ProjectLogFetchPostParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [ProjectLogFetchPostParams]. - * - * The following fields are required: - * ```java - * .projectId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -184,7 +182,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) /** * Sets the entire request body. @@ -450,17 +451,10 @@ private constructor( * Returns an immutable instance of [ProjectLogFetchPostParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectLogFetchPostParams = ProjectLogFetchPostParams( - checkRequired("projectId", projectId), + projectId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -471,7 +465,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -480,6 +474,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cursor: JsonField, private val limit: JsonField, @@ -866,12 +861,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && cursor == other.cursor && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + cursor == other.cursor && + limit == other.limit && + maxRootSpanId == other.maxRootSpanId && + maxXactId == other.maxXactId && + version == other.version && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(cursor, limit, maxRootSpanId, maxXactId, version, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -884,10 +885,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectLogFetchPostParams && projectId == other.projectId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectLogFetchPostParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectLogFetchPostParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt index 8ea2f668..c242c2bc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogInsertParams.kt @@ -19,19 +19,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Insert a set of events into the project logs */ class ProjectLogInsertParams private constructor( - private val projectId: String, + private val projectId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) /** * A list of project logs events to insert @@ -50,8 +51,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -63,7 +66,6 @@ private constructor( * * The following fields are required: * ```java - * .projectId() * .events() * ``` */ @@ -87,7 +89,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) /** * Sets the entire request body. @@ -241,7 +246,6 @@ private constructor( * * The following fields are required: * ```java - * .projectId() * .events() * ``` * @@ -249,7 +253,7 @@ private constructor( */ fun build(): ProjectLogInsertParams = ProjectLogInsertParams( - checkRequired("projectId", projectId), + projectId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -260,7 +264,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -269,6 +273,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val events: JsonField>, private val additionalProperties: MutableMap, @@ -433,12 +438,12 @@ private constructor( return true } - return /* spotless:off */ other is Body && events == other.events && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + events == other.events && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(events, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -450,10 +455,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectLogInsertParams && projectId == other.projectId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectLogInsertParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectLogInsertParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt index 5d6dd53e..49befc6b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectLogsEvent.kt @@ -22,6 +22,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ProjectLogsEvent +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _xactId: JsonField, @@ -1054,7 +1055,7 @@ private constructor( return true } - return /* spotless:off */ other is LogId && value == other.value /* spotless:on */ + return other is LogId && value == other.value } override fun hashCode() = value.hashCode() @@ -1068,6 +1069,7 @@ private constructor( * location in code which produced the project logs event */ class Context + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonField, private val callerFunctionname: JsonField, @@ -1313,12 +1315,16 @@ private constructor( return true } - return /* spotless:off */ other is Context && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Context && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(callerFilename, callerFunctionname, callerLineno, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1334,6 +1340,7 @@ private constructor( * must be strings */ class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val additionalProperties: MutableMap, @@ -1463,12 +1470,12 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && + model == other.model && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1482,6 +1489,7 @@ private constructor( * event was produced */ class Metrics + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val callerFilename: JsonValue, private val callerFunctionname: JsonValue, @@ -1892,12 +1900,31 @@ private constructor( return true } - return /* spotless:off */ other is Metrics && callerFilename == other.callerFilename && callerFunctionname == other.callerFunctionname && callerLineno == other.callerLineno && completionTokens == other.completionTokens && end == other.end && promptTokens == other.promptTokens && start == other.start && tokens == other.tokens && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metrics && + callerFilename == other.callerFilename && + callerFunctionname == other.callerFunctionname && + callerLineno == other.callerLineno && + completionTokens == other.completionTokens && + end == other.end && + promptTokens == other.promptTokens && + start == other.start && + tokens == other.tokens && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(callerFilename, callerFunctionname, callerLineno, completionTokens, end, promptTokens, start, tokens, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + callerFilename, + callerFunctionname, + callerLineno, + completionTokens, + end, + promptTokens, + start, + tokens, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -2003,12 +2030,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2020,12 +2045,57 @@ private constructor( return true } - return /* spotless:off */ other is ProjectLogsEvent && id == other.id && _xactId == other._xactId && created == other.created && logId == other.logId && orgId == other.orgId && projectId == other.projectId && rootSpanId == other.rootSpanId && spanId == other.spanId && context == other.context && error == other.error && expected == other.expected && input == other.input && isRoot == other.isRoot && metadata == other.metadata && metrics == other.metrics && origin == other.origin && output == other.output && scores == other.scores && spanAttributes == other.spanAttributes && spanParents == other.spanParents && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectLogsEvent && + id == other.id && + _xactId == other._xactId && + created == other.created && + logId == other.logId && + orgId == other.orgId && + projectId == other.projectId && + rootSpanId == other.rootSpanId && + spanId == other.spanId && + context == other.context && + error == other.error && + expected == other.expected && + input == other.input && + isRoot == other.isRoot && + metadata == other.metadata && + metrics == other.metrics && + origin == other.origin && + output == other.output && + scores == other.scores && + spanAttributes == other.spanAttributes && + spanParents == other.spanParents && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _xactId, created, logId, orgId, projectId, rootSpanId, spanId, context, error, expected, input, isRoot, metadata, metrics, origin, output, scores, spanAttributes, spanParents, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _xactId, + created, + logId, + orgId, + projectId, + rootSpanId, + spanId, + context, + error, + expected, + input, + isRoot, + metadata, + metrics, + origin, + output, + scores, + spanAttributes, + spanParents, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt index 5fddd2dc..6e52ff5a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a project object by its id */ class ProjectRetrieveParams private constructor( - private val projectId: String, + private val projectId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectRetrieveParams]. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - */ + @JvmStatic fun none(): ProjectRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [ProjectRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectRetrieveParams = ProjectRetrieveParams( - checkRequired("projectId", projectId), + projectId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -188,10 +182,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectRetrieveParams && projectId == other.projectId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectRetrieveParams && + projectId == other.projectId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(projectId, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectRetrieveParams{projectId=$projectId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt index 48b771b0..2594b23c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScore.kt @@ -32,6 +32,7 @@ import kotlin.jvm.optionals.getOrNull /** A project score is a user-configured score, which can be manually-labeled through the UI */ class ProjectScore +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -629,10 +630,13 @@ private constructor( return true } - return /* spotless:off */ other is Categories && categorical == other.categorical && weighted == other.weighted && minimum == other.minimum /* spotless:on */ + return other is Categories && + categorical == other.categorical && + weighted == other.weighted && + minimum == other.minimum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(categorical, weighted, minimum) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(categorical, weighted, minimum) override fun toString(): String = when { @@ -648,13 +652,14 @@ private constructor( /** For categorical-type project scores, the list of all categories */ @JvmStatic fun ofCategorical(categorical: List) = - Categories(categorical = categorical) + Categories(categorical = categorical.toImmutable()) /** For weighted-type project scores, the weights of each score */ @JvmStatic fun ofWeighted(weighted: Weighted) = Categories(weighted = weighted) /** For minimum-type project scores, the list of included scores */ - @JvmStatic fun ofMinimum(minimum: List) = Categories(minimum = minimum) + @JvmStatic + fun ofMinimum(minimum: List) = Categories(minimum = minimum.toImmutable()) } /** @@ -828,12 +833,10 @@ private constructor( return true } - return /* spotless:off */ other is Weighted && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Weighted && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -846,12 +849,35 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScore && id == other.id && name == other.name && projectId == other.projectId && scoreType == other.scoreType && userId == other.userId && categories == other.categories && config == other.config && created == other.created && description == other.description && position == other.position && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectScore && + id == other.id && + name == other.name && + projectId == other.projectId && + scoreType == other.scoreType && + userId == other.userId && + categories == other.categories && + config == other.config && + created == other.created && + description == other.description && + position == other.position && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, projectId, scoreType, userId, categories, config, created, description, position, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + projectId, + scoreType, + userId, + categories, + config, + created, + description, + position, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt index 92dcb461..fb7903b4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCategory.kt @@ -17,6 +17,7 @@ import java.util.Objects /** For categorical-type project scores, defines a single category */ class ProjectScoreCategory +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val value: JsonField, @@ -195,12 +196,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreCategory && name == other.name && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectScoreCategory && + name == other.name && + value == other.value && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, value, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt index 6e3e4571..0ab1a525 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreConfig.kt @@ -17,6 +17,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ProjectScoreConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val destination: JsonField, private val multiSelect: JsonField, @@ -231,12 +232,16 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreConfig && destination == other.destination && multiSelect == other.multiSelect && online == other.online && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectScoreConfig && + destination == other.destination && + multiSelect == other.multiSelect && + online == other.online && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(destination, multiSelect, online, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(destination, multiSelect, online, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt index ca9cd18b..9f912fe6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreCreateParams.kt @@ -133,8 +133,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -419,6 +421,7 @@ private constructor( /** A project score is a user-configured score, which can be manually-labeled through the UI */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -781,12 +784,27 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && scoreType == other.scoreType && categories == other.categories && config == other.config && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + scoreType == other.scoreType && + categories == other.categories && + config == other.config && + description == other.description && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, scoreType, categories, config, description, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + projectId, + scoreType, + categories, + config, + description, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -896,10 +914,13 @@ private constructor( return true } - return /* spotless:off */ other is Categories && categorical == other.categorical && weighted == other.weighted && minimum == other.minimum /* spotless:on */ + return other is Categories && + categorical == other.categorical && + weighted == other.weighted && + minimum == other.minimum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(categorical, weighted, minimum) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(categorical, weighted, minimum) override fun toString(): String = when { @@ -915,13 +936,14 @@ private constructor( /** For categorical-type project scores, the list of all categories */ @JvmStatic fun ofCategorical(categorical: List) = - Categories(categorical = categorical) + Categories(categorical = categorical.toImmutable()) /** For weighted-type project scores, the weights of each score */ @JvmStatic fun ofWeighted(weighted: Weighted) = Categories(weighted = weighted) /** For minimum-type project scores, the list of included scores */ - @JvmStatic fun ofMinimum(minimum: List) = Categories(minimum = minimum) + @JvmStatic + fun ofMinimum(minimum: List) = Categories(minimum = minimum.toImmutable()) } /** @@ -1095,12 +1117,10 @@ private constructor( return true } - return /* spotless:off */ other is Weighted && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Weighted && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1113,10 +1133,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectScoreCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectScoreCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt index e9f282f5..da4a7464 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a project_score object by its id */ class ProjectScoreDeleteParams private constructor( - private val projectScoreId: String, + private val projectScoreId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** ProjectScore id */ - fun projectScoreId(): String = projectScoreId + fun projectScoreId(): Optional = Optional.ofNullable(projectScoreId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectScoreDeleteParams]. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` - */ + @JvmStatic fun none(): ProjectScoreDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectScoreDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -62,7 +60,11 @@ private constructor( } /** ProjectScore id */ - fun projectScoreId(projectScoreId: String) = apply { this.projectScoreId = projectScoreId } + fun projectScoreId(projectScoreId: String?) = apply { this.projectScoreId = projectScoreId } + + /** Alias for calling [Builder.projectScoreId] with `projectScoreId.orElse(null)`. */ + fun projectScoreId(projectScoreId: Optional) = + projectScoreId(projectScoreId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -188,17 +190,10 @@ private constructor( * Returns an immutable instance of [ProjectScoreDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectScoreDeleteParams = ProjectScoreDeleteParams( - checkRequired("projectScoreId", projectScoreId), + projectScoreId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -210,7 +205,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectScoreId + 0 -> projectScoreId ?: "" else -> "" } @@ -223,10 +218,20 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreDeleteParams && projectScoreId == other.projectScoreId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is ProjectScoreDeleteParams && + projectScoreId == other.projectScoreId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectScoreId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + projectScoreId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "ProjectScoreDeleteParams{projectScoreId=$projectScoreId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt index ad6b1c2d..67eda9d4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ProjectScoreService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [ProjectScoreService.list] */ +/** @see ProjectScoreService.list */ class ProjectScoreListPage private constructor( private val service: ProjectScoreService, private val params: ProjectScoreListParams, private val response: ProjectScoreListPageResponse, -) { +) : Page { /** * Delegates to [ProjectScoreListPageResponse], but gracefully handles missing data. * - * @see [ProjectScoreListPageResponse.objects] + * @see ProjectScoreListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ProjectScoreListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ProjectScoreListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ProjectScoreListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: ProjectScoreListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectScoreListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ProjectScoreListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ProjectScoreListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt index 66769492..d946a037 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ProjectScoreServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [ProjectScoreServiceAsync.list] */ +/** @see ProjectScoreServiceAsync.list */ class ProjectScoreListPageAsync private constructor( private val service: ProjectScoreServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ProjectScoreListParams, private val response: ProjectScoreListPageResponse, -) { +) : PageAsync { /** * Delegates to [ProjectScoreListPageResponse], but gracefully handles missing data. * - * @see [ProjectScoreListPageResponse.objects] + * @see ProjectScoreListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ProjectScoreListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ProjectScoreListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: ProjectScoreServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ProjectScoreListParams? = null private var response: ProjectScoreListPageResponse? = null @JvmSynthetic internal fun from(projectScoreListPageAsync: ProjectScoreListPageAsync) = apply { service = projectScoreListPageAsync.service + streamHandlerExecutor = projectScoreListPageAsync.streamHandlerExecutor params = projectScoreListPageAsync.params response = projectScoreListPageAsync.response } fun service(service: ProjectScoreServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ProjectScoreListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): ProjectScoreListPageAsync = ProjectScoreListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: ProjectScoreListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (ProjectScore) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectScoreListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ProjectScoreListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "ProjectScoreListPageAsync{service=$service, params=$params, response=$response}" + "ProjectScoreListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt index de075aa9..631c551e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ProjectScoreListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectScoreListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt index 0b850233..5e0dd49b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -71,8 +72,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -403,10 +406,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -419,7 +422,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -468,10 +471,12 @@ private constructor( return true } - return /* spotless:off */ other is ScoreType && project == other.project && projectScoreTypes == other.projectScoreTypes /* spotless:on */ + return other is ScoreType && + project == other.project && + projectScoreTypes == other.projectScoreTypes } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(project, projectScoreTypes) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(project, projectScoreTypes) override fun toString(): String = when { @@ -488,7 +493,7 @@ private constructor( /** The type of the configured score */ @JvmStatic fun ofProjectScoreTypes(projectScoreTypes: List) = - ScoreType(projectScoreTypes = projectScoreTypes) + ScoreType(projectScoreTypes = projectScoreTypes.toImmutable()) } /** @@ -509,10 +514,34 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && projectId == other.projectId && projectName == other.projectName && projectScoreName == other.projectScoreName && scoreType == other.scoreType && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectScoreListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectId == other.projectId && + projectName == other.projectName && + projectScoreName == other.projectScoreName && + scoreType == other.scoreType && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, projectId, projectName, projectScoreName, scoreType, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + projectId, + projectName, + projectScoreName, + scoreType, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ProjectScoreListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, projectId=$projectId, projectName=$projectName, projectScoreName=$projectScoreName, scoreType=$scoreType, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt index 4f9186a0..c745d420 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreReplaceParams.kt @@ -134,8 +134,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -420,6 +422,7 @@ private constructor( /** A project score is a user-configured score, which can be manually-labeled through the UI */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -782,12 +785,27 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && scoreType == other.scoreType && categories == other.categories && config == other.config && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + scoreType == other.scoreType && + categories == other.categories && + config == other.config && + description == other.description && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, scoreType, categories, config, description, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + projectId, + scoreType, + categories, + config, + description, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -897,10 +915,13 @@ private constructor( return true } - return /* spotless:off */ other is Categories && categorical == other.categorical && weighted == other.weighted && minimum == other.minimum /* spotless:on */ + return other is Categories && + categorical == other.categorical && + weighted == other.weighted && + minimum == other.minimum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(categorical, weighted, minimum) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(categorical, weighted, minimum) override fun toString(): String = when { @@ -916,13 +937,14 @@ private constructor( /** For categorical-type project scores, the list of all categories */ @JvmStatic fun ofCategorical(categorical: List) = - Categories(categorical = categorical) + Categories(categorical = categorical.toImmutable()) /** For weighted-type project scores, the weights of each score */ @JvmStatic fun ofWeighted(weighted: Weighted) = Categories(weighted = weighted) /** For minimum-type project scores, the list of included scores */ - @JvmStatic fun ofMinimum(minimum: List) = Categories(minimum = minimum) + @JvmStatic + fun ofMinimum(minimum: List) = Categories(minimum = minimum.toImmutable()) } /** @@ -1096,12 +1118,10 @@ private constructor( return true } - return /* spotless:off */ other is Weighted && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Weighted && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1114,10 +1134,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectScoreReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectScoreReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt index ee9e6b7c..401cebac 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreRetrieveParams.kt @@ -3,37 +3,37 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a project_score object by its id */ class ProjectScoreRetrieveParams private constructor( - private val projectScoreId: String, + private val projectScoreId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** ProjectScore id */ - fun projectScoreId(): String = projectScoreId + fun projectScoreId(): Optional = Optional.ofNullable(projectScoreId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { + @JvmStatic fun none(): ProjectScoreRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [ProjectScoreRetrieveParams]. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -53,7 +53,11 @@ private constructor( } /** ProjectScore id */ - fun projectScoreId(projectScoreId: String) = apply { this.projectScoreId = projectScoreId } + fun projectScoreId(projectScoreId: String?) = apply { this.projectScoreId = projectScoreId } + + /** Alias for calling [Builder.projectScoreId] with `projectScoreId.orElse(null)`. */ + fun projectScoreId(projectScoreId: Optional) = + projectScoreId(projectScoreId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +161,10 @@ private constructor( * Returns an immutable instance of [ProjectScoreRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectScoreRetrieveParams = ProjectScoreRetrieveParams( - checkRequired("projectScoreId", projectScoreId), + projectScoreId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +172,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectScoreId + 0 -> projectScoreId ?: "" else -> "" } @@ -188,10 +185,14 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreRetrieveParams && projectScoreId == other.projectScoreId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectScoreRetrieveParams && + projectScoreId == other.projectScoreId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectScoreId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectScoreId, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectScoreRetrieveParams{projectScoreId=$projectScoreId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt index 6951cec7..67cc2c66 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreType.kt @@ -156,7 +156,7 @@ class ProjectScoreType @JsonCreator private constructor(private val value: JsonF return true } - return /* spotless:off */ other is ProjectScoreType && value == other.value /* spotless:on */ + return other is ProjectScoreType && value == other.value } override fun hashCode() = value.hashCode() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt index 3e601691..514c809a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectScoreUpdateParams.kt @@ -10,7 +10,6 @@ import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.allMaxBy -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams @@ -39,14 +38,14 @@ import kotlin.jvm.optionals.getOrNull */ class ProjectScoreUpdateParams private constructor( - private val projectScoreId: String, + private val projectScoreId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** ProjectScore id */ - fun projectScoreId(): String = projectScoreId + fun projectScoreId(): Optional = Optional.ofNullable(projectScoreId) /** * For categorical-type project scores, the list of all categories @@ -123,22 +122,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectScoreUpdateParams]. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` - */ + @JvmStatic fun none(): ProjectScoreUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectScoreUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -159,7 +155,11 @@ private constructor( } /** ProjectScore id */ - fun projectScoreId(projectScoreId: String) = apply { this.projectScoreId = projectScoreId } + fun projectScoreId(projectScoreId: String?) = apply { this.projectScoreId = projectScoreId } + + /** Alias for calling [Builder.projectScoreId] with `projectScoreId.orElse(null)`. */ + fun projectScoreId(projectScoreId: Optional) = + projectScoreId(projectScoreId.getOrNull()) /** * Sets the entire request body. @@ -380,17 +380,10 @@ private constructor( * Returns an immutable instance of [ProjectScoreUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectScoreId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectScoreUpdateParams = ProjectScoreUpdateParams( - checkRequired("projectScoreId", projectScoreId), + projectScoreId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -401,7 +394,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectScoreId + 0 -> projectScoreId ?: "" else -> "" } @@ -411,6 +404,7 @@ private constructor( /** A project score is a user-configured score, which can be manually-labeled through the UI */ class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val categories: JsonField, private val config: JsonField, @@ -725,12 +719,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && categories == other.categories && config == other.config && description == other.description && name == other.name && scoreType == other.scoreType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + categories == other.categories && + config == other.config && + description == other.description && + name == other.name && + scoreType == other.scoreType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(categories, config, description, name, scoreType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(categories, config, description, name, scoreType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -840,10 +840,13 @@ private constructor( return true } - return /* spotless:off */ other is Categories && categorical == other.categorical && weighted == other.weighted && minimum == other.minimum /* spotless:on */ + return other is Categories && + categorical == other.categorical && + weighted == other.weighted && + minimum == other.minimum } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(categorical, weighted, minimum) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(categorical, weighted, minimum) override fun toString(): String = when { @@ -859,13 +862,14 @@ private constructor( /** For categorical-type project scores, the list of all categories */ @JvmStatic fun ofCategorical(categorical: List) = - Categories(categorical = categorical) + Categories(categorical = categorical.toImmutable()) /** For weighted-type project scores, the weights of each score */ @JvmStatic fun ofWeighted(weighted: Weighted) = Categories(weighted = weighted) /** For minimum-type project scores, the list of included scores */ - @JvmStatic fun ofMinimum(minimum: List) = Categories(minimum = minimum) + @JvmStatic + fun ofMinimum(minimum: List) = Categories(minimum = minimum.toImmutable()) } /** @@ -1039,12 +1043,10 @@ private constructor( return true } - return /* spotless:off */ other is Weighted && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Weighted && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1057,10 +1059,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectScoreUpdateParams && projectScoreId == other.projectScoreId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectScoreUpdateParams && + projectScoreId == other.projectScoreId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectScoreId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectScoreId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectScoreUpdateParams{projectScoreId=$projectScoreId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt index 474d6826..6d8d6a57 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectSettings.kt @@ -21,6 +21,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ProjectSettings +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val baselineExperimentId: JsonField, private val comparisonKey: JsonField, @@ -267,6 +268,7 @@ private constructor( (spanFieldOrder.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) class SpanFieldOrder + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val columnId: JsonField, private val objectType: JsonField, @@ -634,7 +636,7 @@ private constructor( return true } - return /* spotless:off */ other is Layout && value == other.value /* spotless:on */ + return other is Layout && value == other.value } override fun hashCode() = value.hashCode() @@ -647,12 +649,17 @@ private constructor( return true } - return /* spotless:off */ other is SpanFieldOrder && columnId == other.columnId && objectType == other.objectType && position == other.position && layout == other.layout && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SpanFieldOrder && + columnId == other.columnId && + objectType == other.objectType && + position == other.position && + layout == other.layout && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(columnId, objectType, position, layout, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(columnId, objectType, position, layout, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -665,12 +672,16 @@ private constructor( return true } - return /* spotless:off */ other is ProjectSettings && baselineExperimentId == other.baselineExperimentId && comparisonKey == other.comparisonKey && spanFieldOrder == other.spanFieldOrder && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectSettings && + baselineExperimentId == other.baselineExperimentId && + comparisonKey == other.comparisonKey && + spanFieldOrder == other.spanFieldOrder && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(baselineExperimentId, comparisonKey, spanFieldOrder, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(baselineExperimentId, comparisonKey, spanFieldOrder, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt index b97d8d90..20af1bb4 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTag.kt @@ -23,6 +23,7 @@ import kotlin.jvm.optionals.getOrNull * other data */ class ProjectTag +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -384,12 +385,20 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTag && id == other.id && name == other.name && projectId == other.projectId && userId == other.userId && color == other.color && created == other.created && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectTag && + id == other.id && + name == other.name && + projectId == other.projectId && + userId == other.userId && + color == other.color && + created == other.created && + description == other.description && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, projectId, userId, color, created, description, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, name, projectId, userId, color, created, description, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt index c6346741..d37bfca2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagCreateParams.kt @@ -93,8 +93,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -336,6 +338,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -600,12 +603,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && color == other.color && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + color == other.color && + description == other.description && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, color, description, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, projectId, color, description, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -618,10 +626,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectTagCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectTagCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt index bf7c316a..94aa9d2d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a project_tag object by its id */ class ProjectTagDeleteParams private constructor( - private val projectTagId: String, + private val projectTagId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** ProjectTag id */ - fun projectTagId(): String = projectTagId + fun projectTagId(): Optional = Optional.ofNullable(projectTagId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectTagDeleteParams]. - * - * The following fields are required: - * ```java - * .projectTagId() - * ``` - */ + @JvmStatic fun none(): ProjectTagDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectTagDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -62,7 +60,10 @@ private constructor( } /** ProjectTag id */ - fun projectTagId(projectTagId: String) = apply { this.projectTagId = projectTagId } + fun projectTagId(projectTagId: String?) = apply { this.projectTagId = projectTagId } + + /** Alias for calling [Builder.projectTagId] with `projectTagId.orElse(null)`. */ + fun projectTagId(projectTagId: Optional) = projectTagId(projectTagId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -188,17 +189,10 @@ private constructor( * Returns an immutable instance of [ProjectTagDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectTagId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectTagDeleteParams = ProjectTagDeleteParams( - checkRequired("projectTagId", projectTagId), + projectTagId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -210,7 +204,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectTagId + 0 -> projectTagId ?: "" else -> "" } @@ -223,10 +217,20 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagDeleteParams && projectTagId == other.projectTagId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is ProjectTagDeleteParams && + projectTagId == other.projectTagId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectTagId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + projectTagId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "ProjectTagDeleteParams{projectTagId=$projectTagId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt index 6180b9a9..cdc55b4e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ProjectTagService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [ProjectTagService.list] */ +/** @see ProjectTagService.list */ class ProjectTagListPage private constructor( private val service: ProjectTagService, private val params: ProjectTagListParams, private val response: ProjectTagListPageResponse, -) { +) : Page { /** * Delegates to [ProjectTagListPageResponse], but gracefully handles missing data. * - * @see [ProjectTagListPageResponse.objects] + * @see ProjectTagListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ProjectTagListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ProjectTagListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ProjectTagListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: ProjectTagListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectTagListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ProjectTagListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ProjectTagListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt index 26fc37ac..7d7621fc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ProjectTagServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [ProjectTagServiceAsync.list] */ +/** @see ProjectTagServiceAsync.list */ class ProjectTagListPageAsync private constructor( private val service: ProjectTagServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ProjectTagListParams, private val response: ProjectTagListPageResponse, -) { +) : PageAsync { /** * Delegates to [ProjectTagListPageResponse], but gracefully handles missing data. * - * @see [ProjectTagListPageResponse.objects] + * @see ProjectTagListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ProjectTagListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ProjectTagListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: ProjectTagServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ProjectTagListParams? = null private var response: ProjectTagListPageResponse? = null @JvmSynthetic internal fun from(projectTagListPageAsync: ProjectTagListPageAsync) = apply { service = projectTagListPageAsync.service + streamHandlerExecutor = projectTagListPageAsync.streamHandlerExecutor params = projectTagListPageAsync.params response = projectTagListPageAsync.response } fun service(service: ProjectTagServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ProjectTagListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): ProjectTagListPageAsync = ProjectTagListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: ProjectTagListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (ProjectTag) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectTagListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ProjectTagListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "ProjectTagListPageAsync{service=$service, params=$params, response=$response}" + "ProjectTagListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt index b50ad2b4..c3107b65 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ProjectTagListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ProjectTagListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt index d24144b0..5ff04cc3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -67,8 +68,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -366,10 +369,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -382,7 +385,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -399,10 +402,32 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && projectId == other.projectId && projectName == other.projectName && projectTagName == other.projectTagName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectTagListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectId == other.projectId && + projectName == other.projectName && + projectTagName == other.projectTagName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, projectId, projectName, projectTagName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + projectId, + projectName, + projectTagName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ProjectTagListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, projectId=$projectId, projectName=$projectName, projectTagName=$projectTagName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt index 3b1cb3fd..f3a0b0d2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagReplaceParams.kt @@ -94,8 +94,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -337,6 +339,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -601,12 +604,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && color == other.color && description == other.description && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + color == other.color && + description == other.description && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, color, description, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, projectId, color, description, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -619,10 +627,13 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectTagReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectTagReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt index 20c3485b..474a8d22 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a project_tag object by its id */ class ProjectTagRetrieveParams private constructor( - private val projectTagId: String, + private val projectTagId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** ProjectTag id */ - fun projectTagId(): String = projectTagId + fun projectTagId(): Optional = Optional.ofNullable(projectTagId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectTagRetrieveParams]. - * - * The following fields are required: - * ```java - * .projectTagId() - * ``` - */ + @JvmStatic fun none(): ProjectTagRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectTagRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** ProjectTag id */ - fun projectTagId(projectTagId: String) = apply { this.projectTagId = projectTagId } + fun projectTagId(projectTagId: String?) = apply { this.projectTagId = projectTagId } + + /** Alias for calling [Builder.projectTagId] with `projectTagId.orElse(null)`. */ + fun projectTagId(projectTagId: Optional) = projectTagId(projectTagId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [ProjectTagRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectTagId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectTagRetrieveParams = ProjectTagRetrieveParams( - checkRequired("projectTagId", projectTagId), + projectTagId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectTagId + 0 -> projectTagId ?: "" else -> "" } @@ -188,10 +182,14 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagRetrieveParams && projectTagId == other.projectTagId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectTagRetrieveParams && + projectTagId == other.projectTagId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectTagId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectTagId, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectTagRetrieveParams{projectTagId=$projectTagId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt index 9f4bcf04..d767ab90 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectTagUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class ProjectTagUpdateParams private constructor( - private val projectTagId: String, + private val projectTagId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** ProjectTag id */ - fun projectTagId(): String = projectTagId + fun projectTagId(): Optional = Optional.ofNullable(projectTagId) /** * Color of the tag for the UI @@ -83,22 +82,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectTagUpdateParams]. - * - * The following fields are required: - * ```java - * .projectTagId() - * ``` - */ + @JvmStatic fun none(): ProjectTagUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectTagUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -119,7 +115,10 @@ private constructor( } /** ProjectTag id */ - fun projectTagId(projectTagId: String) = apply { this.projectTagId = projectTagId } + fun projectTagId(projectTagId: String?) = apply { this.projectTagId = projectTagId } + + /** Alias for calling [Builder.projectTagId] with `projectTagId.orElse(null)`. */ + fun projectTagId(projectTagId: Optional) = projectTagId(projectTagId.getOrNull()) /** * Sets the entire request body. @@ -296,17 +295,10 @@ private constructor( * Returns an immutable instance of [ProjectTagUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectTagId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectTagUpdateParams = ProjectTagUpdateParams( - checkRequired("projectTagId", projectTagId), + projectTagId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -317,7 +309,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectTagId + 0 -> projectTagId ?: "" else -> "" } @@ -326,6 +318,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val color: JsonField, private val description: JsonField, @@ -535,12 +528,16 @@ private constructor( return true } - return /* spotless:off */ other is Body && color == other.color && description == other.description && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + color == other.color && + description == other.description && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(color, description, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(color, description, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -553,10 +550,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectTagUpdateParams && projectTagId == other.projectTagId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectTagUpdateParams && + projectTagId == other.projectTagId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectTagId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectTagId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectTagUpdateParams{projectTagId=$projectTagId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt index b97b8926..f9d70c38 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ProjectUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class ProjectUpdateParams private constructor( - private val projectId: String, + private val projectId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Project id */ - fun projectId(): String = projectId + fun projectId(): Optional = Optional.ofNullable(projectId) /** * Name of the project @@ -69,22 +68,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [ProjectUpdateParams]. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - */ + @JvmStatic fun none(): ProjectUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [ProjectUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -105,7 +101,10 @@ private constructor( } /** Project id */ - fun projectId(projectId: String) = apply { this.projectId = projectId } + fun projectId(projectId: String?) = apply { this.projectId = projectId } + + /** Alias for calling [Builder.projectId] with `projectId.orElse(null)`. */ + fun projectId(projectId: Optional) = projectId(projectId.getOrNull()) /** * Sets the entire request body. @@ -270,17 +269,10 @@ private constructor( * Returns an immutable instance of [ProjectUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .projectId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): ProjectUpdateParams = ProjectUpdateParams( - checkRequired("projectId", projectId), + projectId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -291,7 +283,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> projectId + 0 -> projectId ?: "" else -> "" } @@ -300,6 +292,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val settings: JsonField, @@ -475,12 +468,13 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && settings == other.settings && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + settings == other.settings && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, settings, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -493,10 +487,15 @@ private constructor( return true } - return /* spotless:off */ other is ProjectUpdateParams && projectId == other.projectId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ProjectUpdateParams && + projectId == other.projectId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(projectId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ProjectUpdateParams{projectId=$projectId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt index 9157056c..f39b3655 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Prompt.kt @@ -22,6 +22,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class Prompt +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val _xactId: JsonField, @@ -753,7 +754,7 @@ private constructor( return true } - return /* spotless:off */ other is LogId && value == other.value /* spotless:on */ + return other is LogId && value == other.value } override fun hashCode() = value.hashCode() @@ -895,7 +896,7 @@ private constructor( return true } - return /* spotless:off */ other is FunctionType && value == other.value /* spotless:on */ + return other is FunctionType && value == other.value } override fun hashCode() = value.hashCode() @@ -993,12 +994,10 @@ private constructor( return true } - return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metadata && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1010,12 +1009,41 @@ private constructor( return true } - return /* spotless:off */ other is Prompt && id == other.id && _xactId == other._xactId && logId == other.logId && name == other.name && orgId == other.orgId && projectId == other.projectId && slug == other.slug && created == other.created && description == other.description && functionType == other.functionType && metadata == other.metadata && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Prompt && + id == other.id && + _xactId == other._xactId && + logId == other.logId && + name == other.name && + orgId == other.orgId && + projectId == other.projectId && + slug == other.slug && + created == other.created && + description == other.description && + functionType == other.functionType && + metadata == other.metadata && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, _xactId, logId, name, orgId, projectId, slug, created, description, functionType, metadata, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + _xactId, + logId, + name, + orgId, + projectId, + slug, + created, + description, + functionType, + metadata, + promptData, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt index b631e3b1..cd63f886 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptCreateParams.kt @@ -139,8 +139,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -437,6 +439,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -835,12 +838,29 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionType == other.functionType && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + slug == other.slug && + description == other.description && + functionType == other.functionType && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, slug, description, functionType, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + projectId, + slug, + description, + functionType, + promptData, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -982,7 +1002,7 @@ private constructor( return true } - return /* spotless:off */ other is FunctionType && value == other.value /* spotless:on */ + return other is FunctionType && value == other.value } override fun hashCode() = value.hashCode() @@ -995,10 +1015,13 @@ private constructor( return true } - return /* spotless:off */ other is PromptCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PromptCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "PromptCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt index 9248eaac..0d628a7e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptData.kt @@ -33,6 +33,7 @@ import kotlin.jvm.optionals.getOrNull /** The prompt, model, and its parameters */ class PromptData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val options: JsonField, private val origin: JsonField, @@ -329,6 +330,7 @@ private constructor( (toolFunctions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) class Origin + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val projectId: JsonField, private val promptId: JsonField, @@ -526,12 +528,16 @@ private constructor( return true } - return /* spotless:off */ other is Origin && projectId == other.projectId && promptId == other.promptId && promptVersion == other.promptVersion && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Origin && + projectId == other.projectId && + promptId == other.promptId && + promptVersion == other.promptVersion && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(projectId, promptId, promptVersion, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(projectId, promptId, promptVersion, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -540,6 +546,7 @@ private constructor( } class Parser + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val choiceScores: JsonField, private val type: JsonField, @@ -843,12 +850,10 @@ private constructor( return true } - return /* spotless:off */ other is ChoiceScores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ChoiceScores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -968,7 +973,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -981,12 +986,16 @@ private constructor( return true } - return /* spotless:off */ other is Parser && choiceScores == other.choiceScores && type == other.type && useCot == other.useCot && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Parser && + choiceScores == other.choiceScores && + type == other.type && + useCot == other.useCot && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(choiceScores, type, useCot, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(choiceScores, type, useCot, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1076,10 +1085,10 @@ private constructor( return true } - return /* spotless:off */ other is Prompt && completion == other.completion && chat == other.chat /* spotless:on */ + return other is Prompt && completion == other.completion && chat == other.chat } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(completion, chat) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(completion, chat) override fun toString(): String = when { @@ -1165,6 +1174,7 @@ private constructor( } class Completion + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val content: JsonField, private val type: JsonField, @@ -1459,7 +1469,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -1472,12 +1482,13 @@ private constructor( return true } - return /* spotless:off */ other is Completion && content == other.content && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Completion && + content == other.content && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(content, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1486,6 +1497,7 @@ private constructor( } class Chat + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val messages: JsonField>, private val type: JsonField, @@ -1871,10 +1883,17 @@ private constructor( return true } - return /* spotless:off */ other is Message && system == other.system && user == other.user && assistant == other.assistant && tool == other.tool && function == other.function && fallback == other.fallback /* spotless:on */ + return other is Message && + system == other.system && + user == other.user && + assistant == other.assistant && + tool == other.tool && + function == other.function && + fallback == other.fallback } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(system, user, assistant, tool, function, fallback) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(system, user, assistant, tool, function, fallback) override fun toString(): String = when { @@ -2001,6 +2020,7 @@ private constructor( } class System + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -2338,7 +2358,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -2351,12 +2371,16 @@ private constructor( return true } - return /* spotless:off */ other is System && role == other.role && content == other.content && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is System && + role == other.role && + content == other.content && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -2365,6 +2389,7 @@ private constructor( } class User + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -2709,7 +2734,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -2802,10 +2827,10 @@ private constructor( return true } - return /* spotless:off */ other is Content && text == other.text && array == other.array /* spotless:on */ + return other is Content && text == other.text && array == other.array } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(text, array) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(text, array) override fun toString(): String = when { @@ -2821,7 +2846,7 @@ private constructor( @JvmStatic fun ofArray(array: List) = - Content(array = array) + Content(array = array.toImmutable()) } /** @@ -2995,10 +3020,12 @@ private constructor( return true } - return /* spotless:off */ other is ChatCompletionContentPart && text == other.text && image == other.image /* spotless:on */ + return other is ChatCompletionContentPart && + text == other.text && + image == other.image } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(text, image) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(text, image) override fun toString(): String = when { @@ -3137,12 +3164,16 @@ private constructor( return true } - return /* spotless:off */ other is User && role == other.role && content == other.content && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is User && + role == other.role && + content == other.content && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3151,6 +3182,7 @@ private constructor( } class Assistant + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -3602,7 +3634,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -3611,6 +3643,7 @@ private constructor( } class FunctionCall + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val arguments: JsonField, private val name: JsonField, @@ -3806,12 +3839,15 @@ private constructor( return true } - return /* spotless:off */ other is FunctionCall && arguments == other.arguments && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is FunctionCall && + arguments == other.arguments && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(arguments, name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(arguments, name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3824,12 +3860,25 @@ private constructor( return true } - return /* spotless:off */ other is Assistant && role == other.role && content == other.content && functionCall == other.functionCall && name == other.name && toolCalls == other.toolCalls && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Assistant && + role == other.role && + content == other.content && + functionCall == other.functionCall && + name == other.name && + toolCalls == other.toolCalls && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, functionCall, name, toolCalls, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + role, + content, + functionCall, + name, + toolCalls, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -3838,6 +3887,7 @@ private constructor( } class Tool + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -4179,7 +4229,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -4192,12 +4242,16 @@ private constructor( return true } - return /* spotless:off */ other is Tool && role == other.role && content == other.content && toolCallId == other.toolCallId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Tool && + role == other.role && + content == other.content && + toolCallId == other.toolCallId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, toolCallId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, toolCallId, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4206,6 +4260,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val role: JsonField, @@ -4546,7 +4601,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -4559,12 +4614,16 @@ private constructor( return true } - return /* spotless:off */ other is Function && name == other.name && role == other.role && content == other.content && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + name == other.name && + role == other.role && + content == other.content && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, role, content, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, role, content, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4573,6 +4632,7 @@ private constructor( } class Fallback + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val role: JsonField, private val content: JsonField, @@ -4879,7 +4939,7 @@ private constructor( return true } - return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + return other is Role && value == other.value } override fun hashCode() = value.hashCode() @@ -4892,12 +4952,15 @@ private constructor( return true } - return /* spotless:off */ other is Fallback && role == other.role && content == other.content && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Fallback && + role == other.role && + content == other.content && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(role, content, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(role, content, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5022,7 +5085,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -5035,12 +5098,16 @@ private constructor( return true } - return /* spotless:off */ other is Chat && messages == other.messages && type == other.type && tools == other.tools && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Chat && + messages == other.messages && + type == other.type && + tools == other.tools && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(messages, type, tools, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(messages, type, tools, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5131,10 +5198,10 @@ private constructor( return true } - return /* spotless:off */ other is ToolFunction && function == other.function && global == other.global /* spotless:on */ + return other is ToolFunction && function == other.function && global == other.global } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(function, global) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(function, global) override fun toString(): String = when { @@ -5223,6 +5290,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val type: JsonField, @@ -5515,7 +5583,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -5528,12 +5596,13 @@ private constructor( return true } - return /* spotless:off */ other is Function && id == other.id && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + id == other.id && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(id, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -5542,6 +5611,7 @@ private constructor( } class Global + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -5834,7 +5904,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -5847,12 +5917,13 @@ private constructor( return true } - return /* spotless:off */ other is Global && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Global && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -5866,12 +5937,18 @@ private constructor( return true } - return /* spotless:off */ other is PromptData && options == other.options && origin == other.origin && parser == other.parser && prompt == other.prompt && toolFunctions == other.toolFunctions && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PromptData && + options == other.options && + origin == other.origin && + parser == other.parser && + prompt == other.prompt && + toolFunctions == other.toolFunctions && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(options, origin, parser, prompt, toolFunctions, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(options, origin, parser, prompt, toolFunctions, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt index e5a58880..81450806 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a prompt object by its id */ class PromptDeleteParams private constructor( - private val promptId: String, + private val promptId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Prompt id */ - fun promptId(): String = promptId + fun promptId(): Optional = Optional.ofNullable(promptId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [PromptDeleteParams]. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - */ + @JvmStatic fun none(): PromptDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [PromptDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Prompt id */ - fun promptId(promptId: String) = apply { this.promptId = promptId } + fun promptId(promptId: String?) = apply { this.promptId = promptId } + + /** Alias for calling [Builder.promptId] with `promptId.orElse(null)`. */ + fun promptId(promptId: Optional) = promptId(promptId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [PromptDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PromptDeleteParams = PromptDeleteParams( - checkRequired("promptId", promptId), + promptId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> promptId + 0 -> promptId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is PromptDeleteParams && promptId == other.promptId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is PromptDeleteParams && + promptId == other.promptId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(promptId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(promptId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "PromptDeleteParams{promptId=$promptId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt index abba5831..2999576f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.PromptService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [PromptService.list] */ +/** @see PromptService.list */ class PromptListPage private constructor( private val service: PromptService, private val params: PromptListParams, private val response: PromptListPageResponse, -) { +) : Page { /** * Delegates to [PromptListPageResponse], but gracefully handles missing data. * - * @see [PromptListPageResponse.objects] + * @see PromptListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): PromptListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): PromptListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): PromptListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: PromptListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PromptListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is PromptListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "PromptListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt index e87031b9..fca34922 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageAsync.kt @@ -2,53 +2,46 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.PromptServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [PromptServiceAsync.list] */ +/** @see PromptServiceAsync.list */ class PromptListPageAsync private constructor( private val service: PromptServiceAsync, + private val streamHandlerExecutor: Executor, private val params: PromptListParams, private val response: PromptListPageResponse, -) { +) : PageAsync { /** * Delegates to [PromptListPageResponse], but gracefully handles missing data. * - * @see [PromptListPageResponse.objects] + * @see PromptListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): PromptListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): PromptListParams = params @@ -66,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +71,24 @@ private constructor( class Builder internal constructor() { private var service: PromptServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: PromptListParams? = null private var response: PromptListPageResponse? = null @JvmSynthetic internal fun from(promptListPageAsync: PromptListPageAsync) = apply { service = promptListPageAsync.service + streamHandlerExecutor = promptListPageAsync.streamHandlerExecutor params = promptListPageAsync.params response = promptListPageAsync.response } fun service(service: PromptServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: PromptListParams) = apply { this.params = params } @@ -103,6 +103,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +113,26 @@ private constructor( fun build(): PromptListPageAsync = PromptListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: PromptListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Prompt) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PromptListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is PromptListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "PromptListPageAsync{service=$service, params=$params, response=$response}" + "PromptListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt index 5af60fcc..86c17a00 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class PromptListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is PromptListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PromptListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt index a5c5adda..1f2ba2ba 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -80,8 +81,10 @@ private constructor( */ fun version(): Optional = Optional.ofNullable(version) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -403,10 +406,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -419,7 +422,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -436,10 +439,36 @@ private constructor( return true } - return /* spotless:off */ other is PromptListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && projectId == other.projectId && projectName == other.projectName && promptName == other.promptName && slug == other.slug && startingAfter == other.startingAfter && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PromptListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + projectId == other.projectId && + projectName == other.projectName && + promptName == other.promptName && + slug == other.slug && + startingAfter == other.startingAfter && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, projectId, projectName, promptName, slug, startingAfter, version, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + projectId, + projectName, + promptName, + slug, + startingAfter, + version, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "PromptListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, projectId=$projectId, projectName=$projectName, promptName=$promptName, slug=$slug, startingAfter=$startingAfter, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt index 92357d35..0034e601 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptOptions.kt @@ -32,6 +32,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class PromptOptions +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val model: JsonField, private val params: JsonField, @@ -358,10 +359,16 @@ private constructor( return true } - return /* spotless:off */ other is Params && openaiModel == other.openaiModel && anthropicModel == other.anthropicModel && googleModel == other.googleModel && windowAiModel == other.windowAiModel && jsCompletion == other.jsCompletion /* spotless:on */ + return other is Params && + openaiModel == other.openaiModel && + anthropicModel == other.anthropicModel && + googleModel == other.googleModel && + windowAiModel == other.windowAiModel && + jsCompletion == other.jsCompletion } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(openaiModel, anthropicModel, googleModel, windowAiModel, jsCompletion) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(openaiModel, anthropicModel, googleModel, windowAiModel, jsCompletion) override fun toString(): String = when { @@ -482,6 +489,7 @@ private constructor( } class OpenAIModelParams + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val frequencyPenalty: JsonField, private val functionCall: JsonField, @@ -1222,10 +1230,12 @@ private constructor( return true } - return /* spotless:off */ other is FunctionCall && unionMember0 == other.unionMember0 && function == other.function /* spotless:on */ + return other is FunctionCall && + unionMember0 == other.unionMember0 && + function == other.function } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unionMember0, function) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(unionMember0, function) override fun toString(): String = when { @@ -1446,7 +1456,7 @@ private constructor( return true } - return /* spotless:off */ other is UnionMember0 && value == other.value /* spotless:on */ + return other is UnionMember0 && value == other.value } override fun hashCode() = value.hashCode() @@ -1455,6 +1465,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val additionalProperties: MutableMap, @@ -1605,12 +1616,12 @@ private constructor( return true } - return /* spotless:off */ other is Function && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -1752,7 +1763,7 @@ private constructor( return true } - return /* spotless:off */ other is ReasoningEffort && value == other.value /* spotless:on */ + return other is ReasoningEffort && value == other.value } override fun hashCode() = value.hashCode() @@ -1858,10 +1869,13 @@ private constructor( return true } - return /* spotless:off */ other is ResponseFormat && jsonObject == other.jsonObject && jsonSchema == other.jsonSchema && text == other.text /* spotless:on */ + return other is ResponseFormat && + jsonObject == other.jsonObject && + jsonSchema == other.jsonSchema && + text == other.text } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(jsonObject, jsonSchema, text) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(jsonObject, jsonSchema, text) override fun toString(): String = when { @@ -1965,6 +1979,7 @@ private constructor( } class JsonObject + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -2231,7 +2246,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -2244,12 +2259,12 @@ private constructor( return true } - return /* spotless:off */ other is JsonObject && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is JsonObject && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -2258,6 +2273,7 @@ private constructor( } class JsonSchema + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val jsonSchema: JsonField, private val type: JsonField, @@ -2447,6 +2463,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class InnerJsonSchema + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val description: JsonField, @@ -2807,10 +2824,12 @@ private constructor( return true } - return /* spotless:off */ other is Schema && object_ == other.object_ && string == other.string /* spotless:on */ + return other is Schema && + object_ == other.object_ && + string == other.string } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(object_, string) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(object_, string) override fun toString(): String = when { @@ -3007,12 +3026,13 @@ private constructor( return true } - return /* spotless:off */ other is Object && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Object && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3026,12 +3046,17 @@ private constructor( return true } - return /* spotless:off */ other is InnerJsonSchema && name == other.name && description == other.description && schema == other.schema && strict == other.strict && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InnerJsonSchema && + name == other.name && + description == other.description && + schema == other.schema && + strict == other.strict && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, schema, strict, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, description, schema, strict, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3160,7 +3185,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3173,12 +3198,15 @@ private constructor( return true } - return /* spotless:off */ other is JsonSchema && jsonSchema == other.jsonSchema && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is JsonSchema && + jsonSchema == other.jsonSchema && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(jsonSchema, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(jsonSchema, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -3187,6 +3215,7 @@ private constructor( } class Text + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val type: JsonField, private val additionalProperties: MutableMap, @@ -3450,7 +3479,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -3463,12 +3492,12 @@ private constructor( return true } - return /* spotless:off */ other is Text && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Text && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -3560,10 +3589,12 @@ private constructor( return true } - return /* spotless:off */ other is ToolChoice && unionMember0 == other.unionMember0 && function == other.function /* spotless:on */ + return other is ToolChoice && + unionMember0 == other.unionMember0 && + function == other.function } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(unionMember0, function) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(unionMember0, function) override fun toString(): String = when { @@ -3789,7 +3820,7 @@ private constructor( return true } - return /* spotless:off */ other is UnionMember0 && value == other.value /* spotless:on */ + return other is UnionMember0 && value == other.value } override fun hashCode() = value.hashCode() @@ -3798,6 +3829,7 @@ private constructor( } class Function + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val function: JsonField, private val type: JsonField, @@ -3986,6 +4018,7 @@ private constructor( (type.asKnown().getOrNull()?.validity() ?: 0) class InnerFunction + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val additionalProperties: MutableMap, @@ -4139,12 +4172,14 @@ private constructor( return true } - return /* spotless:off */ other is InnerFunction && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + return other is InnerFunction && + name == other.name && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4273,7 +4308,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return other is Type && value == other.value } override fun hashCode() = value.hashCode() @@ -4286,12 +4321,15 @@ private constructor( return true } - return /* spotless:off */ other is Function && function == other.function && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Function && + function == other.function && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(function, type, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(function, type, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -4305,12 +4343,41 @@ private constructor( return true } - return /* spotless:off */ other is OpenAIModelParams && frequencyPenalty == other.frequencyPenalty && functionCall == other.functionCall && maxCompletionTokens == other.maxCompletionTokens && maxTokens == other.maxTokens && n == other.n && presencePenalty == other.presencePenalty && reasoningEffort == other.reasoningEffort && responseFormat == other.responseFormat && stop == other.stop && temperature == other.temperature && toolChoice == other.toolChoice && topP == other.topP && useCache == other.useCache && additionalProperties == other.additionalProperties /* spotless:on */ + return other is OpenAIModelParams && + frequencyPenalty == other.frequencyPenalty && + functionCall == other.functionCall && + maxCompletionTokens == other.maxCompletionTokens && + maxTokens == other.maxTokens && + n == other.n && + presencePenalty == other.presencePenalty && + reasoningEffort == other.reasoningEffort && + responseFormat == other.responseFormat && + stop == other.stop && + temperature == other.temperature && + toolChoice == other.toolChoice && + topP == other.topP && + useCache == other.useCache && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequencyPenalty, functionCall, maxCompletionTokens, maxTokens, n, presencePenalty, reasoningEffort, responseFormat, stop, temperature, toolChoice, topP, useCache, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + frequencyPenalty, + functionCall, + maxCompletionTokens, + maxTokens, + n, + presencePenalty, + reasoningEffort, + responseFormat, + stop, + temperature, + toolChoice, + topP, + useCache, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -4319,6 +4386,7 @@ private constructor( } class AnthropicModelParams + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val maxTokens: JsonField, private val temperature: JsonField, @@ -4714,12 +4782,29 @@ private constructor( return true } - return /* spotless:off */ other is AnthropicModelParams && maxTokens == other.maxTokens && temperature == other.temperature && maxTokensToSample == other.maxTokensToSample && stopSequences == other.stopSequences && topK == other.topK && topP == other.topP && useCache == other.useCache && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AnthropicModelParams && + maxTokens == other.maxTokens && + temperature == other.temperature && + maxTokensToSample == other.maxTokensToSample && + stopSequences == other.stopSequences && + topK == other.topK && + topP == other.topP && + useCache == other.useCache && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(maxTokens, temperature, maxTokensToSample, stopSequences, topK, topP, useCache, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + maxTokens, + temperature, + maxTokensToSample, + stopSequences, + topK, + topP, + useCache, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -4728,6 +4813,7 @@ private constructor( } class GoogleModelParams + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val maxOutputTokens: JsonField, private val temperature: JsonField, @@ -5006,12 +5092,25 @@ private constructor( return true } - return /* spotless:off */ other is GoogleModelParams && maxOutputTokens == other.maxOutputTokens && temperature == other.temperature && topK == other.topK && topP == other.topP && useCache == other.useCache && additionalProperties == other.additionalProperties /* spotless:on */ + return other is GoogleModelParams && + maxOutputTokens == other.maxOutputTokens && + temperature == other.temperature && + topK == other.topK && + topP == other.topP && + useCache == other.useCache && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(maxOutputTokens, temperature, topK, topP, useCache, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + maxOutputTokens, + temperature, + topK, + topP, + useCache, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -5020,6 +5119,7 @@ private constructor( } class WindowAiModelParams + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val temperature: JsonField, private val topK: JsonField, @@ -5228,12 +5328,16 @@ private constructor( return true } - return /* spotless:off */ other is WindowAiModelParams && temperature == other.temperature && topK == other.topK && useCache == other.useCache && additionalProperties == other.additionalProperties /* spotless:on */ + return other is WindowAiModelParams && + temperature == other.temperature && + topK == other.topK && + useCache == other.useCache && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(temperature, topK, useCache, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(temperature, topK, useCache, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -5242,6 +5346,7 @@ private constructor( } class JsCompletionParams + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val useCache: JsonField, private val additionalProperties: MutableMap, @@ -5377,12 +5482,12 @@ private constructor( return true } - return /* spotless:off */ other is JsCompletionParams && useCache == other.useCache && additionalProperties == other.additionalProperties /* spotless:on */ + return other is JsCompletionParams && + useCache == other.useCache && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(useCache, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -5396,12 +5501,16 @@ private constructor( return true } - return /* spotless:off */ other is PromptOptions && model == other.model && params == other.params && position == other.position && additionalProperties == other.additionalProperties /* spotless:on */ + return other is PromptOptions && + model == other.model && + params == other.params && + position == other.position && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(model, params, position, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(model, params, position, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt index 3274f771..97a12f57 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptReplaceParams.kt @@ -139,8 +139,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -437,6 +439,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -835,12 +838,29 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && slug == other.slug && description == other.description && functionType == other.functionType && promptData == other.promptData && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + slug == other.slug && + description == other.description && + functionType == other.functionType && + promptData == other.promptData && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, slug, description, functionType, promptData, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + projectId, + slug, + description, + functionType, + promptData, + tags, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -982,7 +1002,7 @@ private constructor( return true } - return /* spotless:off */ other is FunctionType && value == other.value /* spotless:on */ + return other is FunctionType && value == other.value } override fun hashCode() = value.hashCode() @@ -995,10 +1015,13 @@ private constructor( return true } - return /* spotless:off */ other is PromptReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PromptReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "PromptReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt index b05a03df..0dda7e97 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a prompt object by its id */ class PromptRetrieveParams private constructor( - private val promptId: String, + private val promptId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Prompt id */ - fun promptId(): String = promptId + fun promptId(): Optional = Optional.ofNullable(promptId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [PromptRetrieveParams]. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - */ + @JvmStatic fun none(): PromptRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [PromptRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Prompt id */ - fun promptId(promptId: String) = apply { this.promptId = promptId } + fun promptId(promptId: String?) = apply { this.promptId = promptId } + + /** Alias for calling [Builder.promptId] with `promptId.orElse(null)`. */ + fun promptId(promptId: Optional) = promptId(promptId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [PromptRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PromptRetrieveParams = - PromptRetrieveParams( - checkRequired("promptId", promptId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + PromptRetrieveParams(promptId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> promptId + 0 -> promptId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is PromptRetrieveParams && promptId == other.promptId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PromptRetrieveParams && + promptId == other.promptId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(promptId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(promptId, additionalHeaders, additionalQueryParams) override fun toString() = "PromptRetrieveParams{promptId=$promptId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt index 73422bc0..0cfcc0a0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/PromptUpdateParams.kt @@ -8,7 +8,6 @@ import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.checkKnown -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable @@ -29,14 +28,14 @@ import kotlin.jvm.optionals.getOrNull */ class PromptUpdateParams private constructor( - private val promptId: String, + private val promptId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Prompt id */ - fun promptId(): String = promptId + fun promptId(): Optional = Optional.ofNullable(promptId) /** * Textual description of the prompt @@ -115,22 +114,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [PromptUpdateParams]. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - */ + @JvmStatic fun none(): PromptUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [PromptUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -151,7 +147,10 @@ private constructor( } /** Prompt id */ - fun promptId(promptId: String) = apply { this.promptId = promptId } + fun promptId(promptId: String?) = apply { this.promptId = promptId } + + /** Alias for calling [Builder.promptId] with `promptId.orElse(null)`. */ + fun promptId(promptId: Optional) = promptId(promptId.getOrNull()) /** * Sets the entire request body. @@ -368,17 +367,10 @@ private constructor( * Returns an immutable instance of [PromptUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .promptId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PromptUpdateParams = PromptUpdateParams( - checkRequired("promptId", promptId), + promptId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -389,7 +381,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> promptId + 0 -> promptId ?: "" else -> "" } @@ -398,6 +390,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val description: JsonField, private val name: JsonField, @@ -705,12 +698,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && name == other.name && promptData == other.promptData && slug == other.slug && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + description == other.description && + name == other.name && + promptData == other.promptData && + slug == other.slug && + tags == other.tags && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, name, promptData, slug, tags, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(description, name, promptData, slug, tags, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -723,10 +722,15 @@ private constructor( return true } - return /* spotless:off */ other is PromptUpdateParams && promptId == other.promptId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is PromptUpdateParams && + promptId == other.promptId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(promptId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(promptId, body, additionalHeaders, additionalQueryParams) override fun toString() = "PromptUpdateParams{promptId=$promptId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt index d51766be..d81c3eef 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RepoInfo.kt @@ -18,6 +18,7 @@ import kotlin.jvm.optionals.getOrNull /** Metadata about the state of the repo when the experiment was created */ class RepoInfo +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val authorEmail: JsonField, private val authorName: JsonField, @@ -481,12 +482,33 @@ private constructor( return true } - return /* spotless:off */ other is RepoInfo && authorEmail == other.authorEmail && authorName == other.authorName && branch == other.branch && commit == other.commit && commitMessage == other.commitMessage && commitTime == other.commitTime && dirty == other.dirty && gitDiff == other.gitDiff && tag == other.tag && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RepoInfo && + authorEmail == other.authorEmail && + authorName == other.authorName && + branch == other.branch && + commit == other.commit && + commitMessage == other.commitMessage && + commitTime == other.commitTime && + dirty == other.dirty && + gitDiff == other.gitDiff && + tag == other.tag && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(authorEmail, authorName, branch, commit, commitMessage, commitTime, dirty, gitDiff, tag, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + authorEmail, + authorName, + branch, + commit, + commitMessage, + commitTime, + dirty, + gitDiff, + tag, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt index f55b44e3..8863415e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Role.kt @@ -26,6 +26,7 @@ import kotlin.jvm.optionals.getOrNull * Roles can consist of individual permissions, as well as a set of roles they inherit from */ class Role +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -537,6 +538,7 @@ private constructor( (if (userId.asKnown().isPresent) 1 else 0) class MemberPermission + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val permission: JsonField, private val restrictObjectType: JsonField, @@ -746,12 +748,15 @@ private constructor( return true } - return /* spotless:off */ other is MemberPermission && permission == other.permission && restrictObjectType == other.restrictObjectType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MemberPermission && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(permission, restrictObjectType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(permission, restrictObjectType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -764,12 +769,33 @@ private constructor( return true } - return /* spotless:off */ other is Role && id == other.id && name == other.name && created == other.created && deletedAt == other.deletedAt && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgId == other.orgId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Role && + id == other.id && + name == other.name && + created == other.created && + deletedAt == other.deletedAt && + description == other.description && + memberPermissions == other.memberPermissions && + memberRoles == other.memberRoles && + orgId == other.orgId && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, created, deletedAt, description, memberPermissions, memberRoles, orgId, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + created, + deletedAt, + description, + memberPermissions, + memberRoles, + orgId, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt index 4e8526c6..9f3a93c7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleCreateParams.kt @@ -116,8 +116,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -405,6 +407,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val description: JsonField, @@ -763,12 +766,25 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + description == other.description && + memberPermissions == other.memberPermissions && + memberRoles == other.memberRoles && + orgName == other.orgName && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberPermissions, memberRoles, orgName, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + description, + memberPermissions, + memberRoles, + orgName, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -777,6 +793,7 @@ private constructor( } class MemberPermission + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val permission: JsonField, private val restrictObjectType: JsonField, @@ -986,12 +1003,15 @@ private constructor( return true } - return /* spotless:off */ other is MemberPermission && permission == other.permission && restrictObjectType == other.restrictObjectType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MemberPermission && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(permission, restrictObjectType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(permission, restrictObjectType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1004,10 +1024,13 @@ private constructor( return true } - return /* spotless:off */ other is RoleCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is RoleCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "RoleCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt index 596b4e90..046d491b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a role object by its id */ class RoleDeleteParams private constructor( - private val roleId: String, + private val roleId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** Role id */ - fun roleId(): String = roleId + fun roleId(): Optional = Optional.ofNullable(roleId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [RoleDeleteParams]. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - */ + @JvmStatic fun none(): RoleDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RoleDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -61,7 +59,10 @@ private constructor( } /** Role id */ - fun roleId(roleId: String) = apply { this.roleId = roleId } + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -187,17 +188,10 @@ private constructor( * Returns an immutable instance of [RoleDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): RoleDeleteParams = RoleDeleteParams( - checkRequired("roleId", roleId), + roleId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -209,7 +203,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> roleId + 0 -> roleId ?: "" else -> "" } @@ -222,10 +216,15 @@ private constructor( return true } - return /* spotless:off */ other is RoleDeleteParams && roleId == other.roleId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is RoleDeleteParams && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(roleId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(roleId, additionalHeaders, additionalQueryParams, additionalBodyProperties) override fun toString() = "RoleDeleteParams{roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt index c9437627..9982ae81 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.RoleService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [RoleService.list] */ +/** @see RoleService.list */ class RoleListPage private constructor( private val service: RoleService, private val params: RoleListParams, private val response: RoleListPageResponse, -) { +) : Page { /** * Delegates to [RoleListPageResponse], but gracefully handles missing data. * - * @see [RoleListPageResponse.objects] + * @see RoleListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): RoleListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): RoleListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): RoleListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: RoleListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is RoleListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is RoleListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "RoleListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt index 11469901..bd22807d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageAsync.kt @@ -2,53 +2,46 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.RoleServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [RoleServiceAsync.list] */ +/** @see RoleServiceAsync.list */ class RoleListPageAsync private constructor( private val service: RoleServiceAsync, + private val streamHandlerExecutor: Executor, private val params: RoleListParams, private val response: RoleListPageResponse, -) { +) : PageAsync { /** * Delegates to [RoleListPageResponse], but gracefully handles missing data. * - * @see [RoleListPageResponse.objects] + * @see RoleListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): RoleListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): RoleListParams = params @@ -66,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +71,24 @@ private constructor( class Builder internal constructor() { private var service: RoleServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: RoleListParams? = null private var response: RoleListPageResponse? = null @JvmSynthetic internal fun from(roleListPageAsync: RoleListPageAsync) = apply { service = roleListPageAsync.service + streamHandlerExecutor = roleListPageAsync.streamHandlerExecutor params = roleListPageAsync.params response = roleListPageAsync.response } fun service(service: RoleServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: RoleListParams) = apply { this.params = params } @@ -103,6 +103,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +113,26 @@ private constructor( fun build(): RoleListPageAsync = RoleListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: RoleListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Role) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is RoleListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is RoleListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "RoleListPageAsync{service=$service, params=$params, response=$response}" + "RoleListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt index 083c5ccd..e02593db 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class RoleListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is RoleListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RoleListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt index f90f054c..7ae51b50 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -59,8 +60,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -337,10 +340,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -353,7 +356,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -370,10 +373,28 @@ private constructor( return true } - return /* spotless:off */ other is RoleListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && roleName == other.roleName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is RoleListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + roleName == other.roleName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, roleName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + roleName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "RoleListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, roleName=$roleName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt index 791e3fd8..6f369bab 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleReplaceParams.kt @@ -116,8 +116,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -409,6 +411,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val description: JsonField, @@ -767,12 +770,25 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && description == other.description && memberPermissions == other.memberPermissions && memberRoles == other.memberRoles && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + description == other.description && + memberPermissions == other.memberPermissions && + memberRoles == other.memberRoles && + orgName == other.orgName && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, description, memberPermissions, memberRoles, orgName, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + description, + memberPermissions, + memberRoles, + orgName, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -781,6 +797,7 @@ private constructor( } class MemberPermission + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val permission: JsonField, private val restrictObjectType: JsonField, @@ -990,12 +1007,15 @@ private constructor( return true } - return /* spotless:off */ other is MemberPermission && permission == other.permission && restrictObjectType == other.restrictObjectType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is MemberPermission && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(permission, restrictObjectType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(permission, restrictObjectType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1008,10 +1028,13 @@ private constructor( return true } - return /* spotless:off */ other is RoleReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is RoleReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "RoleReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt index 2b82d6ea..ab31b790 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a role object by its id */ class RoleRetrieveParams private constructor( - private val roleId: String, + private val roleId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Role id */ - fun roleId(): String = roleId + fun roleId(): Optional = Optional.ofNullable(roleId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - */ + @JvmStatic fun none(): RoleRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RoleRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** Role id */ - fun roleId(roleId: String) = apply { this.roleId = roleId } + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [RoleRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): RoleRetrieveParams = - RoleRetrieveParams( - checkRequired("roleId", roleId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + RoleRetrieveParams(roleId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> roleId + 0 -> roleId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is RoleRetrieveParams && roleId == other.roleId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is RoleRetrieveParams && + roleId == other.roleId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(roleId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(roleId, additionalHeaders, additionalQueryParams) override fun toString() = "RoleRetrieveParams{roleId=$roleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt index 390da928..de9e7fb3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/RoleUpdateParams.kt @@ -29,14 +29,14 @@ import kotlin.jvm.optionals.getOrNull */ class RoleUpdateParams private constructor( - private val roleId: String, + private val roleId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** Role id */ - fun roleId(): String = roleId + fun roleId(): Optional = Optional.ofNullable(roleId) /** * A list of permissions to add to the role @@ -135,22 +135,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [RoleUpdateParams]. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - */ + @JvmStatic fun none(): RoleUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RoleUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -171,7 +168,10 @@ private constructor( } /** Role id */ - fun roleId(roleId: String) = apply { this.roleId = roleId } + fun roleId(roleId: String?) = apply { this.roleId = roleId } + + /** Alias for calling [Builder.roleId] with `roleId.orElse(null)`. */ + fun roleId(roleId: Optional) = roleId(roleId.getOrNull()) /** * Sets the entire request body. @@ -460,17 +460,10 @@ private constructor( * Returns an immutable instance of [RoleUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .roleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): RoleUpdateParams = RoleUpdateParams( - checkRequired("roleId", roleId), + roleId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -481,7 +474,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> roleId + 0 -> roleId ?: "" else -> "" } @@ -490,6 +483,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val addMemberPermissions: JsonField>, private val addMemberRoles: JsonField>, @@ -927,12 +921,27 @@ private constructor( return true } - return /* spotless:off */ other is Body && addMemberPermissions == other.addMemberPermissions && addMemberRoles == other.addMemberRoles && description == other.description && name == other.name && removeMemberPermissions == other.removeMemberPermissions && removeMemberRoles == other.removeMemberRoles && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + addMemberPermissions == other.addMemberPermissions && + addMemberRoles == other.addMemberRoles && + description == other.description && + name == other.name && + removeMemberPermissions == other.removeMemberPermissions && + removeMemberRoles == other.removeMemberRoles && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(addMemberPermissions, addMemberRoles, description, name, removeMemberPermissions, removeMemberRoles, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + addMemberPermissions, + addMemberRoles, + description, + name, + removeMemberPermissions, + removeMemberRoles, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -941,6 +950,7 @@ private constructor( } class AddMemberPermission + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val permission: JsonField, private val restrictObjectType: JsonField, @@ -1150,12 +1160,15 @@ private constructor( return true } - return /* spotless:off */ other is AddMemberPermission && permission == other.permission && restrictObjectType == other.restrictObjectType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is AddMemberPermission && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(permission, restrictObjectType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(permission, restrictObjectType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1164,6 +1177,7 @@ private constructor( } class RemoveMemberPermission + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val permission: JsonField, private val restrictObjectType: JsonField, @@ -1373,12 +1387,15 @@ private constructor( return true } - return /* spotless:off */ other is RemoveMemberPermission && permission == other.permission && restrictObjectType == other.restrictObjectType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is RemoveMemberPermission && + permission == other.permission && + restrictObjectType == other.restrictObjectType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(permission, restrictObjectType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(permission, restrictObjectType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -1391,10 +1408,15 @@ private constructor( return true } - return /* spotless:off */ other is RoleUpdateParams && roleId == other.roleId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is RoleUpdateParams && + roleId == other.roleId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(roleId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(roleId, body, additionalHeaders, additionalQueryParams) override fun toString() = "RoleUpdateParams{roleId=$roleId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt index 207b7123..a960bd03 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ScoreSummary.kt @@ -18,6 +18,7 @@ import java.util.Optional /** Summary of a score's performance */ class ScoreSummary +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val improvements: JsonField, private val name: JsonField, @@ -308,12 +309,18 @@ private constructor( return true } - return /* spotless:off */ other is ScoreSummary && improvements == other.improvements && name == other.name && regressions == other.regressions && score == other.score && diff == other.diff && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ScoreSummary && + improvements == other.improvements && + name == other.name && + regressions == other.regressions && + score == other.score && + diff == other.diff && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(improvements, name, regressions, score, diff, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(improvements, name, regressions, score, diff, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt index 13b88570..0c75a9a3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanAttributes.kt @@ -18,6 +18,7 @@ import kotlin.jvm.optionals.getOrNull /** Human-identifying attributes of the span, such as name, type, etc. */ class SpanAttributes +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val type: JsonField, @@ -182,12 +183,13 @@ private constructor( return true } - return /* spotless:off */ other is SpanAttributes && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SpanAttributes && + name == other.name && + type == other.type && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(name, type, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt index 65ede1b3..672c8cfc 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIFrame.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class SpanIFrame +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -487,12 +488,33 @@ private constructor( return true } - return /* spotless:off */ other is SpanIFrame && id == other.id && name == other.name && projectId == other.projectId && url == other.url && created == other.created && deletedAt == other.deletedAt && description == other.description && postMessage == other.postMessage && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SpanIFrame && + id == other.id && + name == other.name && + projectId == other.projectId && + url == other.url && + created == other.created && + deletedAt == other.deletedAt && + description == other.description && + postMessage == other.postMessage && + userId == other.userId && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, projectId, url, created, deletedAt, description, postMessage, userId, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + projectId, + url, + created, + deletedAt, + description, + postMessage, + userId, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt index 8d2e050d..ff2b7316 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeCreateParams.kt @@ -109,8 +109,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -378,6 +380,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -695,12 +698,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && url == other.url && description == other.description && postMessage == other.postMessage && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + url == other.url && + description == other.description && + postMessage == other.postMessage && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, url, description, postMessage, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, projectId, url, description, postMessage, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -713,10 +722,13 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SpanIframeCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "SpanIframeCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt index cf73c830..78f3a416 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeDeleteParams.kt @@ -4,43 +4,41 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Delete a span_iframe object by its id */ class SpanIframeDeleteParams private constructor( - private val spanIframeId: String, + private val spanIframeId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { /** SpanIframe id */ - fun spanIframeId(): String = spanIframeId + fun spanIframeId(): Optional = Optional.ofNullable(spanIframeId) + /** Additional body properties to send with the request. */ fun _additionalBodyProperties(): Map = additionalBodyProperties + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [SpanIframeDeleteParams]. - * - * The following fields are required: - * ```java - * .spanIframeId() - * ``` - */ + @JvmStatic fun none(): SpanIframeDeleteParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SpanIframeDeleteParams]. */ @JvmStatic fun builder() = Builder() } @@ -62,7 +60,10 @@ private constructor( } /** SpanIframe id */ - fun spanIframeId(spanIframeId: String) = apply { this.spanIframeId = spanIframeId } + fun spanIframeId(spanIframeId: String?) = apply { this.spanIframeId = spanIframeId } + + /** Alias for calling [Builder.spanIframeId] with `spanIframeId.orElse(null)`. */ + fun spanIframeId(spanIframeId: Optional) = spanIframeId(spanIframeId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -188,17 +189,10 @@ private constructor( * Returns an immutable instance of [SpanIframeDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .spanIframeId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SpanIframeDeleteParams = SpanIframeDeleteParams( - checkRequired("spanIframeId", spanIframeId), + spanIframeId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -210,7 +204,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> spanIframeId + 0 -> spanIframeId ?: "" else -> "" } @@ -223,10 +217,20 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeDeleteParams && spanIframeId == other.spanIframeId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return other is SpanIframeDeleteParams && + spanIframeId == other.spanIframeId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanIframeId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + spanIframeId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) override fun toString() = "SpanIframeDeleteParams{spanIframeId=$spanIframeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt index 40522df7..6fcfd056 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.SpanIframeService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [SpanIframeService.list] */ +/** @see SpanIframeService.list */ class SpanIframeListPage private constructor( private val service: SpanIframeService, private val params: SpanIframeListParams, private val response: SpanIframeListPageResponse, -) { +) : Page { /** * Delegates to [SpanIframeListPageResponse], but gracefully handles missing data. * - * @see [SpanIframeListPageResponse.objects] + * @see SpanIframeListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): SpanIframeListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): SpanIframeListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): SpanIframeListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: SpanIframeListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is SpanIframeListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is SpanIframeListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "SpanIframeListPage{service=$service, params=$params, response=$response}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt index 7a564ec0..c7541bca 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageAsync.kt @@ -2,53 +2,47 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.SpanIframeServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [SpanIframeServiceAsync.list] */ +/** @see SpanIframeServiceAsync.list */ class SpanIframeListPageAsync private constructor( private val service: SpanIframeServiceAsync, + private val streamHandlerExecutor: Executor, private val params: SpanIframeListParams, private val response: SpanIframeListPageResponse, -) { +) : PageAsync { /** * Delegates to [SpanIframeListPageResponse], but gracefully handles missing data. * - * @see [SpanIframeListPageResponse.objects] + * @see SpanIframeListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): SpanIframeListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): SpanIframeListParams = params @@ -66,6 +60,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +72,24 @@ private constructor( class Builder internal constructor() { private var service: SpanIframeServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: SpanIframeListParams? = null private var response: SpanIframeListPageResponse? = null @JvmSynthetic internal fun from(spanIframeListPageAsync: SpanIframeListPageAsync) = apply { service = spanIframeListPageAsync.service + streamHandlerExecutor = spanIframeListPageAsync.streamHandlerExecutor params = spanIframeListPageAsync.params response = spanIframeListPageAsync.response } fun service(service: SpanIframeServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: SpanIframeListParams) = apply { this.params = params } @@ -103,6 +104,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +114,26 @@ private constructor( fun build(): SpanIframeListPageAsync = SpanIframeListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: SpanIframeListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (SpanIFrame) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is SpanIframeListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is SpanIframeListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "SpanIframeListPageAsync{service=$service, params=$params, response=$response}" + "SpanIframeListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt index f6d22bda..a5b8da6f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class SpanIframeListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -180,12 +181,12 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SpanIframeListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt index 7ad05511..c2b00d9b 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -59,8 +60,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -338,10 +341,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -354,7 +357,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -371,10 +374,28 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeListParams && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && spanIframeName == other.spanIframeName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SpanIframeListParams && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + spanIframeName == other.spanIframeName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(endingBefore, ids, limit, orgName, spanIframeName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + endingBefore, + ids, + limit, + orgName, + spanIframeName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "SpanIframeListParams{endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, spanIframeName=$spanIframeName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt index 5b2265b4..66e52233 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeReplaceParams.kt @@ -109,8 +109,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -378,6 +380,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val projectId: JsonField, @@ -695,12 +698,18 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && url == other.url && description == other.description && postMessage == other.postMessage && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + projectId == other.projectId && + url == other.url && + description == other.description && + postMessage == other.postMessage && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, projectId, url, description, postMessage, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(name, projectId, url, description, postMessage, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -713,10 +722,13 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SpanIframeReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "SpanIframeReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt index 63c737bb..b5d6c6e0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a span_iframe object by its id */ class SpanIframeRetrieveParams private constructor( - private val spanIframeId: String, + private val spanIframeId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** SpanIframe id */ - fun spanIframeId(): String = spanIframeId + fun spanIframeId(): Optional = Optional.ofNullable(spanIframeId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [SpanIframeRetrieveParams]. - * - * The following fields are required: - * ```java - * .spanIframeId() - * ``` - */ + @JvmStatic fun none(): SpanIframeRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SpanIframeRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** SpanIframe id */ - fun spanIframeId(spanIframeId: String) = apply { this.spanIframeId = spanIframeId } + fun spanIframeId(spanIframeId: String?) = apply { this.spanIframeId = spanIframeId } + + /** Alias for calling [Builder.spanIframeId] with `spanIframeId.orElse(null)`. */ + fun spanIframeId(spanIframeId: Optional) = spanIframeId(spanIframeId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,17 +158,10 @@ private constructor( * Returns an immutable instance of [SpanIframeRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .spanIframeId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SpanIframeRetrieveParams = SpanIframeRetrieveParams( - checkRequired("spanIframeId", spanIframeId), + spanIframeId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -175,7 +169,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> spanIframeId + 0 -> spanIframeId ?: "" else -> "" } @@ -188,10 +182,14 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeRetrieveParams && spanIframeId == other.spanIframeId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SpanIframeRetrieveParams && + spanIframeId == other.spanIframeId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanIframeId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(spanIframeId, additionalHeaders, additionalQueryParams) override fun toString() = "SpanIframeRetrieveParams{spanIframeId=$spanIframeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt index 7236e5a9..0dd41fd8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanIframeUpdateParams.kt @@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField import com.braintrustdata.api.core.JsonMissing import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import com.braintrustdata.api.errors.BraintrustInvalidDataException @@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull */ class SpanIframeUpdateParams private constructor( - private val spanIframeId: String, + private val spanIframeId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** SpanIframe id */ - fun spanIframeId(): String = spanIframeId + fun spanIframeId(): Optional = Optional.ofNullable(spanIframeId) /** * Textual description of the span iframe @@ -99,22 +98,19 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [SpanIframeUpdateParams]. - * - * The following fields are required: - * ```java - * .spanIframeId() - * ``` - */ + @JvmStatic fun none(): SpanIframeUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [SpanIframeUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -135,7 +131,10 @@ private constructor( } /** SpanIframe id */ - fun spanIframeId(spanIframeId: String) = apply { this.spanIframeId = spanIframeId } + fun spanIframeId(spanIframeId: String?) = apply { this.spanIframeId = spanIframeId } + + /** Alias for calling [Builder.spanIframeId] with `spanIframeId.orElse(null)`. */ + fun spanIframeId(spanIframeId: Optional) = spanIframeId(spanIframeId.getOrNull()) /** * Sets the entire request body. @@ -338,17 +337,10 @@ private constructor( * Returns an immutable instance of [SpanIframeUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .spanIframeId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SpanIframeUpdateParams = SpanIframeUpdateParams( - checkRequired("spanIframeId", spanIframeId), + spanIframeId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -359,7 +351,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> spanIframeId + 0 -> spanIframeId ?: "" else -> "" } @@ -368,6 +360,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val description: JsonField, private val name: JsonField, @@ -631,12 +624,17 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && name == other.name && postMessage == other.postMessage && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + description == other.description && + name == other.name && + postMessage == other.postMessage && + url == other.url && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, name, postMessage, url, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(description, name, postMessage, url, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -649,10 +647,15 @@ private constructor( return true } - return /* spotless:off */ other is SpanIframeUpdateParams && spanIframeId == other.spanIframeId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is SpanIframeUpdateParams && + spanIframeId == other.spanIframeId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(spanIframeId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(spanIframeId, body, additionalHeaders, additionalQueryParams) override fun toString() = "SpanIframeUpdateParams{spanIframeId=$spanIframeId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt index 33527e47..ec98994e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SpanType.kt @@ -147,7 +147,7 @@ class SpanType @JsonCreator private constructor(private val value: JsonField, private val datasetUrl: JsonField, @@ -327,12 +328,25 @@ private constructor( return true } - return /* spotless:off */ other is SummarizeDatasetResponse && datasetName == other.datasetName && datasetUrl == other.datasetUrl && projectName == other.projectName && projectUrl == other.projectUrl && dataSummary == other.dataSummary && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SummarizeDatasetResponse && + datasetName == other.datasetName && + datasetUrl == other.datasetUrl && + projectName == other.projectName && + projectUrl == other.projectUrl && + dataSummary == other.dataSummary && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(datasetName, datasetUrl, projectName, projectUrl, dataSummary, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + datasetName, + datasetUrl, + projectName, + projectUrl, + dataSummary, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt index 05066a50..b2acbaa8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/SummarizeExperimentResponse.kt @@ -20,6 +20,7 @@ import kotlin.jvm.optionals.getOrNull /** Summary of an experiment */ class SummarizeExperimentResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val experimentName: JsonField, private val experimentUrl: JsonField, @@ -507,12 +508,10 @@ private constructor( return true } - return /* spotless:off */ other is Metrics && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Metrics && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -609,12 +608,10 @@ private constructor( return true } - return /* spotless:off */ other is Scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Scores && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -626,12 +623,29 @@ private constructor( return true } - return /* spotless:off */ other is SummarizeExperimentResponse && experimentName == other.experimentName && experimentUrl == other.experimentUrl && projectName == other.projectName && projectUrl == other.projectUrl && comparisonExperimentName == other.comparisonExperimentName && metrics == other.metrics && scores == other.scores && additionalProperties == other.additionalProperties /* spotless:on */ + return other is SummarizeExperimentResponse && + experimentName == other.experimentName && + experimentUrl == other.experimentUrl && + projectName == other.projectName && + projectUrl == other.projectUrl && + comparisonExperimentName == other.comparisonExperimentName && + metrics == other.metrics && + scores == other.scores && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(experimentName, experimentUrl, projectName, projectUrl, comparisonExperimentName, metrics, scores, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + experimentName, + experimentUrl, + projectName, + projectUrl, + comparisonExperimentName, + metrics, + scores, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt index 07da14b6..da51fccf 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/TopLevelHelloWorldParams.kt @@ -14,8 +14,10 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -156,10 +158,12 @@ private constructor( return true } - return /* spotless:off */ other is TopLevelHelloWorldParams && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is TopLevelHelloWorldParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) override fun toString() = "TopLevelHelloWorldParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt index d2a2db23..46f7ad70 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/User.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class User +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val avatarUrl: JsonField, @@ -351,12 +352,19 @@ private constructor( return true } - return /* spotless:off */ other is User && id == other.id && avatarUrl == other.avatarUrl && created == other.created && email == other.email && familyName == other.familyName && givenName == other.givenName && additionalProperties == other.additionalProperties /* spotless:on */ + return other is User && + id == other.id && + avatarUrl == other.avatarUrl && + created == other.created && + email == other.email && + familyName == other.familyName && + givenName == other.givenName && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, avatarUrl, created, email, familyName, givenName, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(id, avatarUrl, created, email, familyName, givenName, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt index 25aaa0e1..e8fa075b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.UserService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [UserService.list] */ +/** @see UserService.list */ class UserListPage private constructor( private val service: UserService, private val params: UserListParams, private val response: UserListPageResponse, -) { +) : Page { /** * Delegates to [UserListPageResponse], but gracefully handles missing data. * - * @see [UserListPageResponse.objects] + * @see UserListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): UserListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): UserListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): UserListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: UserListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UserListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is UserListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "UserListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt index 412a21a0..8635b6e5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageAsync.kt @@ -2,53 +2,46 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.UserServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [UserServiceAsync.list] */ +/** @see UserServiceAsync.list */ class UserListPageAsync private constructor( private val service: UserServiceAsync, + private val streamHandlerExecutor: Executor, private val params: UserListParams, private val response: UserListPageResponse, -) { +) : PageAsync { /** * Delegates to [UserListPageResponse], but gracefully handles missing data. * - * @see [UserListPageResponse.objects] + * @see UserListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): UserListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): UserListParams = params @@ -66,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +71,24 @@ private constructor( class Builder internal constructor() { private var service: UserServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: UserListParams? = null private var response: UserListPageResponse? = null @JvmSynthetic internal fun from(userListPageAsync: UserListPageAsync) = apply { service = userListPageAsync.service + streamHandlerExecutor = userListPageAsync.streamHandlerExecutor params = userListPageAsync.params response = userListPageAsync.response } fun service(service: UserServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: UserListParams) = apply { this.params = params } @@ -103,6 +103,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +113,26 @@ private constructor( fun build(): UserListPageAsync = UserListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: UserListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (User) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is UserListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is UserListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "UserListPageAsync{service=$service, params=$params, response=$response}" + "UserListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt index b38d950e..9d561b45 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class UserListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is UserListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is UserListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt index 70081294..6b14d619 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserListParams.kt @@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -76,8 +77,10 @@ private constructor( */ fun startingAfter(): Optional = Optional.ofNullable(startingAfter) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -431,10 +434,10 @@ private constructor( return true } - return /* spotless:off */ other is Email && string == other.string && strings == other.strings /* spotless:on */ + return other is Email && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -447,7 +450,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Email(string = string) - @JvmStatic fun ofStrings(strings: List) = Email(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Email(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Email] to a value of type [T]. */ @@ -493,10 +496,10 @@ private constructor( return true } - return /* spotless:off */ other is FamilyName && string == other.string && strings == other.strings /* spotless:on */ + return other is FamilyName && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -509,7 +512,8 @@ private constructor( @JvmStatic fun ofString(string: String) = FamilyName(string = string) - @JvmStatic fun ofStrings(strings: List) = FamilyName(strings = strings) + @JvmStatic + fun ofStrings(strings: List) = FamilyName(strings = strings.toImmutable()) } /** @@ -557,10 +561,10 @@ private constructor( return true } - return /* spotless:off */ other is GivenName && string == other.string && strings == other.strings /* spotless:on */ + return other is GivenName && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -573,7 +577,8 @@ private constructor( @JvmStatic fun ofString(string: String) = GivenName(string = string) - @JvmStatic fun ofStrings(strings: List) = GivenName(strings = strings) + @JvmStatic + fun ofStrings(strings: List) = GivenName(strings = strings.toImmutable()) } /** @@ -621,10 +626,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -637,7 +642,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -654,10 +659,32 @@ private constructor( return true } - return /* spotless:off */ other is UserListParams && email == other.email && endingBefore == other.endingBefore && familyName == other.familyName && givenName == other.givenName && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is UserListParams && + email == other.email && + endingBefore == other.endingBefore && + familyName == other.familyName && + givenName == other.givenName && + ids == other.ids && + limit == other.limit && + orgName == other.orgName && + startingAfter == other.startingAfter && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(email, endingBefore, familyName, givenName, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + email, + endingBefore, + familyName, + givenName, + ids, + limit, + orgName, + startingAfter, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "UserListParams{email=$email, endingBefore=$endingBefore, familyName=$familyName, givenName=$givenName, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt index 3a97c821..b403a90a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/UserRetrieveParams.kt @@ -3,38 +3,36 @@ package com.braintrustdata.api.models import com.braintrustdata.api.core.Params -import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a user object by its id */ class UserRetrieveParams private constructor( - private val userId: String, + private val userId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** User id */ - fun userId(): String = userId + fun userId(): Optional = Optional.ofNullable(userId) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) companion object { - /** - * Returns a mutable builder for constructing an instance of [UserRetrieveParams]. - * - * The following fields are required: - * ```java - * .userId() - * ``` - */ + @JvmStatic fun none(): UserRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [UserRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -53,7 +51,10 @@ private constructor( } /** User id */ - fun userId(userId: String) = apply { this.userId = userId } + fun userId(userId: String?) = apply { this.userId = userId } + + /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + fun userId(userId: Optional) = userId(userId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -157,25 +158,14 @@ private constructor( * Returns an immutable instance of [UserRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .userId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): UserRetrieveParams = - UserRetrieveParams( - checkRequired("userId", userId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + UserRetrieveParams(userId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> userId + 0 -> userId ?: "" else -> "" } @@ -188,10 +178,13 @@ private constructor( return true } - return /* spotless:off */ other is UserRetrieveParams && userId == other.userId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is UserRetrieveParams && + userId == other.userId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(userId, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(userId, additionalHeaders, additionalQueryParams) override fun toString() = "UserRetrieveParams{userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt index 5ca9dc21..c95c3d06 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/View.kt @@ -20,6 +20,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class View +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, private val name: JsonField, @@ -686,7 +687,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewType && value == other.value /* spotless:on */ + return other is ViewType && value == other.value } override fun hashCode() = value.hashCode() @@ -699,12 +700,35 @@ private constructor( return true } - return /* spotless:off */ other is View && id == other.id && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && created == other.created && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ + return other is View && + id == other.id && + name == other.name && + objectId == other.objectId && + objectType == other.objectType && + viewType == other.viewType && + created == other.created && + deletedAt == other.deletedAt && + options == other.options && + userId == other.userId && + viewData == other.viewData && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, name, objectId, objectType, viewType, created, deletedAt, options, userId, viewData, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + id, + name, + objectId, + objectType, + viewType, + created, + deletedAt, + options, + userId, + viewData, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt index 608ecf69..29b4d710 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewCreateParams.kt @@ -155,8 +155,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -456,6 +458,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val objectId: JsonField, @@ -891,12 +894,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + objectId == other.objectId && + objectType == other.objectType && + viewType == other.viewType && + deletedAt == other.deletedAt && + options == other.options && + userId == other.userId && + viewData == other.viewData && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, viewType, deletedAt, options, userId, viewData, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + objectId, + objectType, + viewType, + deletedAt, + options, + userId, + viewData, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1078,7 +1100,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewType && value == other.value /* spotless:on */ + return other is ViewType && value == other.value } override fun hashCode() = value.hashCode() @@ -1091,10 +1113,13 @@ private constructor( return true } - return /* spotless:off */ other is ViewCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ViewCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ViewCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt index ebc6ae84..1ad28233 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewData.kt @@ -18,6 +18,7 @@ import kotlin.jvm.optionals.getOrNull /** The view definition */ class ViewData +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val search: JsonField, private val additionalProperties: MutableMap, @@ -143,12 +144,12 @@ private constructor( return true } - return /* spotless:off */ other is ViewData && search == other.search && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ViewData && + search == other.search && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(search, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt index 3868ec17..100f0481 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDataSearch.kt @@ -19,6 +19,7 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull class ViewDataSearch +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val filter: JsonField>, private val match: JsonField>, @@ -310,12 +311,17 @@ private constructor( return true } - return /* spotless:off */ other is ViewDataSearch && filter == other.filter && match == other.match && sort == other.sort && tag == other.tag && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ViewDataSearch && + filter == other.filter && + match == other.match && + sort == other.sort && + tag == other.tag && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(filter, match, sort, tag, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(filter, match, sort, tag, additionalProperties) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt index 4cde6f81..c675954c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewDeleteParams.kt @@ -17,19 +17,20 @@ import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import java.util.Collections import java.util.Objects +import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Delete a view object by its id */ class ViewDeleteParams private constructor( - private val viewId: String, + private val viewId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { /** View id */ - fun viewId(): String = viewId + fun viewId(): Optional = Optional.ofNullable(viewId) /** * The id of the object the view applies to @@ -63,8 +64,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -76,7 +79,6 @@ private constructor( * * The following fields are required: * ```java - * .viewId() * .objectId() * .objectType() * ``` @@ -101,7 +103,10 @@ private constructor( } /** View id */ - fun viewId(viewId: String) = apply { this.viewId = viewId } + fun viewId(viewId: String?) = apply { this.viewId = viewId } + + /** Alias for calling [Builder.viewId] with `viewId.orElse(null)`. */ + fun viewId(viewId: Optional) = viewId(viewId.getOrNull()) /** * Sets the entire request body. @@ -260,7 +265,6 @@ private constructor( * * The following fields are required: * ```java - * .viewId() * .objectId() * .objectType() * ``` @@ -269,7 +273,7 @@ private constructor( */ fun build(): ViewDeleteParams = ViewDeleteParams( - checkRequired("viewId", viewId), + viewId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -280,7 +284,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> viewId + 0 -> viewId ?: "" else -> "" } @@ -289,6 +293,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -479,12 +484,15 @@ private constructor( return true } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + objectId == other.objectId && + objectType == other.objectType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash(objectId, objectType, additionalProperties) + } override fun hashCode(): Int = hashCode @@ -497,10 +505,15 @@ private constructor( return true } - return /* spotless:off */ other is ViewDeleteParams && viewId == other.viewId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ViewDeleteParams && + viewId == other.viewId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(viewId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(viewId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ViewDeleteParams{viewId=$viewId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt index 820ea8ba..f4f062c2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPage.kt @@ -2,49 +2,43 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPager +import com.braintrustdata.api.core.Page import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.blocking.ViewService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** @see [ViewService.list] */ +/** @see ViewService.list */ class ViewListPage private constructor( private val service: ViewService, private val params: ViewListParams, private val response: ViewListPageResponse, -) { +) : Page { /** * Delegates to [ViewListPageResponse], but gracefully handles missing data. * - * @see [ViewListPageResponse.objects] + * @see ViewListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ViewListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ViewListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ViewListParams = params @@ -113,34 +107,18 @@ private constructor( ) } - class AutoPager(private val firstPage: ViewListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.objects().size) { - yield(page.objects()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ViewListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ViewListPage && + service == other.service && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, params, response) override fun toString() = "ViewListPage{service=$service, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt index c5c6bd0e..a2cffbac 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageAsync.kt @@ -2,53 +2,46 @@ package com.braintrustdata.api.models +import com.braintrustdata.api.core.AutoPagerAsync +import com.braintrustdata.api.core.PageAsync import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.services.async.ViewServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** @see [ViewServiceAsync.list] */ +/** @see ViewServiceAsync.list */ class ViewListPageAsync private constructor( private val service: ViewServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ViewListParams, private val response: ViewListPageResponse, -) { +) : PageAsync { /** * Delegates to [ViewListPageResponse], but gracefully handles missing data. * - * @see [ViewListPageResponse.objects] + * @see ViewListPageResponse.objects */ fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = objects().isNotEmpty() + override fun items(): List = objects() - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } + override fun hasNextPage(): Boolean = items().isNotEmpty() - return Optional.of( - if (params.endingBefore().isPresent) { - params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build() - } else { - params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build() - } - ) - } + fun nextPageParams(): ViewListParams = + if (params.endingBefore().isPresent) { + params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build() + } else { + params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build() + } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ViewListParams = params @@ -66,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -77,18 +71,24 @@ private constructor( class Builder internal constructor() { private var service: ViewServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ViewListParams? = null private var response: ViewListPageResponse? = null @JvmSynthetic internal fun from(viewListPageAsync: ViewListPageAsync) = apply { service = viewListPageAsync.service + streamHandlerExecutor = viewListPageAsync.streamHandlerExecutor params = viewListPageAsync.params response = viewListPageAsync.response } fun service(service: ViewServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ViewListParams) = apply { this.params = params } @@ -103,6 +103,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -112,47 +113,26 @@ private constructor( fun build(): ViewListPageAsync = ViewListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: ViewListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (View) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.objects().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ViewListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return other is ViewListPageAsync && + service == other.service && + streamHandlerExecutor == other.streamHandlerExecutor && + params == other.params && + response == other.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) override fun toString() = - "ViewListPageAsync{service=$service, params=$params, response=$response}" + "ViewListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt index 47ad5868..b44c4997 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListPageResponse.kt @@ -19,6 +19,7 @@ import java.util.Objects import kotlin.jvm.optionals.getOrNull class ViewListPageResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objects: JsonField>, private val additionalProperties: MutableMap, @@ -178,12 +179,12 @@ private constructor( return true } - return /* spotless:off */ other is ViewListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ViewListPageResponse && + objects == other.objects && + additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt index decac7ce..3577873a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewListParams.kt @@ -7,6 +7,7 @@ import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.getOrThrow import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams +import com.braintrustdata.api.core.toImmutable import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -68,8 +69,10 @@ private constructor( /** Type of table that the view corresponds to. */ fun viewType(): Optional = Optional.ofNullable(viewType) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -374,10 +377,10 @@ private constructor( return true } - return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */ + return other is Ids && string == other.string && strings == other.strings } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(string, strings) override fun toString(): String = when { @@ -390,7 +393,7 @@ private constructor( @JvmStatic fun ofString(string: String) = Ids(string = string) - @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings) + @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable()) } /** An interface that defines how to map each variant of [Ids] to a value of type [T]. */ @@ -407,10 +410,32 @@ private constructor( return true } - return /* spotless:off */ other is ViewListParams && objectId == other.objectId && objectType == other.objectType && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && startingAfter == other.startingAfter && viewName == other.viewName && viewType == other.viewType && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ViewListParams && + objectId == other.objectId && + objectType == other.objectType && + endingBefore == other.endingBefore && + ids == other.ids && + limit == other.limit && + startingAfter == other.startingAfter && + viewName == other.viewName && + viewType == other.viewType && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(objectId, objectType, endingBefore, ids, limit, startingAfter, viewName, viewType, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash( + objectId, + objectType, + endingBefore, + ids, + limit, + startingAfter, + viewName, + viewType, + additionalHeaders, + additionalQueryParams, + ) override fun toString() = "ViewListParams{objectId=$objectId, objectType=$objectType, endingBefore=$endingBefore, ids=$ids, limit=$limit, startingAfter=$startingAfter, viewName=$viewName, viewType=$viewType, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt index 2a50e44b..6dbe6150 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewOptions.kt @@ -20,6 +20,7 @@ import kotlin.jvm.optionals.getOrNull /** Options for the view in the app */ class ViewOptions +@JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val columnOrder: JsonField>, private val columnSizing: JsonField, @@ -447,12 +448,10 @@ private constructor( return true } - return /* spotless:off */ other is ColumnSizing && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ColumnSizing && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -548,12 +547,10 @@ private constructor( return true } - return /* spotless:off */ other is ColumnVisibility && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ColumnVisibility && additionalProperties == other.additionalProperties } - /* spotless:off */ private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ override fun hashCode(): Int = hashCode @@ -565,12 +562,27 @@ private constructor( return true } - return /* spotless:off */ other is ViewOptions && columnOrder == other.columnOrder && columnSizing == other.columnSizing && columnVisibility == other.columnVisibility && grouping == other.grouping && layout == other.layout && rowHeight == other.rowHeight && additionalProperties == other.additionalProperties /* spotless:on */ + return other is ViewOptions && + columnOrder == other.columnOrder && + columnSizing == other.columnSizing && + columnVisibility == other.columnVisibility && + grouping == other.grouping && + layout == other.layout && + rowHeight == other.rowHeight && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(columnOrder, columnSizing, columnVisibility, grouping, layout, rowHeight, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + columnOrder, + columnSizing, + columnVisibility, + grouping, + layout, + rowHeight, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt index 1f5303d5..db31cf9e 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewReplaceParams.kt @@ -155,8 +155,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -460,6 +462,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val name: JsonField, private val objectId: JsonField, @@ -895,12 +898,31 @@ private constructor( return true } - return /* spotless:off */ other is Body && name == other.name && objectId == other.objectId && objectType == other.objectType && viewType == other.viewType && deletedAt == other.deletedAt && options == other.options && userId == other.userId && viewData == other.viewData && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + name == other.name && + objectId == other.objectId && + objectType == other.objectType && + viewType == other.viewType && + deletedAt == other.deletedAt && + options == other.options && + userId == other.userId && + viewData == other.viewData && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, objectId, objectType, viewType, deletedAt, options, userId, viewData, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + name, + objectId, + objectType, + viewType, + deletedAt, + options, + userId, + viewData, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1082,7 +1104,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewType && value == other.value /* spotless:on */ + return other is ViewType && value == other.value } override fun hashCode() = value.hashCode() @@ -1095,10 +1117,13 @@ private constructor( return true } - return /* spotless:off */ other is ViewReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ViewReplaceParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) override fun toString() = "ViewReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt index 7f27c2a4..d61fa274 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewRetrieveParams.kt @@ -7,11 +7,13 @@ import com.braintrustdata.api.core.checkRequired import com.braintrustdata.api.core.http.Headers import com.braintrustdata.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get a view object by its id */ class ViewRetrieveParams private constructor( - private val viewId: String, + private val viewId: String?, private val objectId: String, private val objectType: AclObjectType, private val additionalHeaders: Headers, @@ -19,7 +21,7 @@ private constructor( ) : Params { /** View id */ - fun viewId(): String = viewId + fun viewId(): Optional = Optional.ofNullable(viewId) /** The id of the object the ACL applies to */ fun objectId(): String = objectId @@ -27,8 +29,10 @@ private constructor( /** The object type that the ACL applies to */ fun objectType(): AclObjectType = objectType + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -40,7 +44,6 @@ private constructor( * * The following fields are required: * ```java - * .viewId() * .objectId() * .objectType() * ``` @@ -67,7 +70,10 @@ private constructor( } /** View id */ - fun viewId(viewId: String) = apply { this.viewId = viewId } + fun viewId(viewId: String?) = apply { this.viewId = viewId } + + /** Alias for calling [Builder.viewId] with `viewId.orElse(null)`. */ + fun viewId(viewId: Optional) = viewId(viewId.getOrNull()) /** The id of the object the ACL applies to */ fun objectId(objectId: String) = apply { this.objectId = objectId } @@ -180,7 +186,6 @@ private constructor( * * The following fields are required: * ```java - * .viewId() * .objectId() * .objectType() * ``` @@ -189,7 +194,7 @@ private constructor( */ fun build(): ViewRetrieveParams = ViewRetrieveParams( - checkRequired("viewId", viewId), + viewId, checkRequired("objectId", objectId), checkRequired("objectType", objectType), additionalHeaders.build(), @@ -199,7 +204,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> viewId + 0 -> viewId ?: "" else -> "" } @@ -219,10 +224,16 @@ private constructor( return true } - return /* spotless:off */ other is ViewRetrieveParams && viewId == other.viewId && objectId == other.objectId && objectType == other.objectType && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ViewRetrieveParams && + viewId == other.viewId && + objectId == other.objectId && + objectType == other.objectType && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(viewId, objectId, objectType, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(viewId, objectId, objectType, additionalHeaders, additionalQueryParams) override fun toString() = "ViewRetrieveParams{viewId=$viewId, objectId=$objectId, objectType=$objectType, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt index 9f8db16f..6744a88f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ViewType.kt @@ -177,7 +177,7 @@ class ViewType @JsonCreator private constructor(private val value: JsonField = Optional.ofNullable(viewId) /** * The id of the object the view applies to @@ -144,8 +144,10 @@ private constructor( fun _additionalBodyProperties(): Map = body._additionalProperties() + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders + /** Additional query param to send with the request. */ fun _additionalQueryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -157,7 +159,6 @@ private constructor( * * The following fields are required: * ```java - * .viewId() * .objectId() * .objectType() * ``` @@ -182,7 +183,10 @@ private constructor( } /** View id */ - fun viewId(viewId: String) = apply { this.viewId = viewId } + fun viewId(viewId: String?) = apply { this.viewId = viewId } + + /** Alias for calling [Builder.viewId] with `viewId.orElse(null)`. */ + fun viewId(viewId: Optional) = viewId(viewId.getOrNull()) /** * Sets the entire request body. @@ -418,7 +422,6 @@ private constructor( * * The following fields are required: * ```java - * .viewId() * .objectId() * .objectType() * ``` @@ -427,7 +430,7 @@ private constructor( */ fun build(): ViewUpdateParams = ViewUpdateParams( - checkRequired("viewId", viewId), + viewId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -438,7 +441,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> viewId + 0 -> viewId ?: "" else -> "" } @@ -447,6 +450,7 @@ private constructor( override fun _queryParams(): QueryParams = additionalQueryParams class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val objectId: JsonField, private val objectType: JsonField, @@ -828,12 +832,29 @@ private constructor( return true } - return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && name == other.name && options == other.options && userId == other.userId && viewData == other.viewData && viewType == other.viewType && additionalProperties == other.additionalProperties /* spotless:on */ + return other is Body && + objectId == other.objectId && + objectType == other.objectType && + name == other.name && + options == other.options && + userId == other.userId && + viewData == other.viewData && + viewType == other.viewType && + additionalProperties == other.additionalProperties } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(objectId, objectType, name, options, userId, viewData, viewType, additionalProperties) } - /* spotless:on */ + private val hashCode: Int by lazy { + Objects.hash( + objectId, + objectType, + name, + options, + userId, + viewData, + viewType, + additionalProperties, + ) + } override fun hashCode(): Int = hashCode @@ -1015,7 +1036,7 @@ private constructor( return true } - return /* spotless:off */ other is ViewType && value == other.value /* spotless:on */ + return other is ViewType && value == other.value } override fun hashCode() = value.hashCode() @@ -1028,10 +1049,15 @@ private constructor( return true } - return /* spotless:off */ other is ViewUpdateParams && viewId == other.viewId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + return other is ViewUpdateParams && + viewId == other.viewId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(viewId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun hashCode(): Int = + Objects.hash(viewId, body, additionalHeaders, additionalQueryParams) override fun toString() = "ViewUpdateParams{viewId=$viewId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsync.kt index a1688232..53d5b9f8 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Acl @@ -13,8 +14,8 @@ import com.braintrustdata.api.models.AclFindAndDeleteParams import com.braintrustdata.api.models.AclListPageAsync import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclRetrieveParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface AclServiceAsync { @@ -23,6 +24,13 @@ interface AclServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AclServiceAsync + /** * Create a new acl. If there is an existing acl with the same contents as the one specified in * the request, will return the existing acl unmodified @@ -30,22 +38,42 @@ interface AclServiceAsync { fun create(params: AclCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: AclCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get an acl object by its id */ - fun retrieve(params: AclRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(aclId: String): CompletableFuture = retrieve(aclId, AclRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = retrieve(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + ): CompletableFuture = retrieve(aclId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: AclRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: AclRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(aclId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(aclId, AclRetrieveParams.none(), requestOptions) + /** * List out all acls. The acls are sorted by creation date, with the most recently-created acls * coming first @@ -53,22 +81,42 @@ interface AclServiceAsync { fun list(params: AclListParams): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list( params: AclListParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Delete an acl object by its id */ - fun delete(params: AclDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(aclId: String): CompletableFuture = delete(aclId, AclDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = delete(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see delete */ + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + ): CompletableFuture = delete(aclId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: AclDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: AclDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(aclId: String, requestOptions: RequestOptions): CompletableFuture = + delete(aclId, AclDeleteParams.none(), requestOptions) + /** * Batch update acls. This operation is idempotent, so adding acls which already exist will have * no effect, and removing acls which do not exist will have no effect. @@ -76,18 +124,18 @@ interface AclServiceAsync { fun batchUpdate(): CompletableFuture = batchUpdate(AclBatchUpdateParams.none()) - /** @see [batchUpdate] */ + /** @see batchUpdate */ fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [batchUpdate] */ + /** @see batchUpdate */ fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none() ): CompletableFuture = batchUpdate(params, RequestOptions.none()) - /** @see [batchUpdate] */ + /** @see batchUpdate */ fun batchUpdate(requestOptions: RequestOptions): CompletableFuture = batchUpdate(AclBatchUpdateParams.none(), requestOptions) @@ -95,7 +143,7 @@ interface AclServiceAsync { fun findAndDelete(params: AclFindAndDeleteParams): CompletableFuture = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ + /** @see findAndDelete */ fun findAndDelete( params: AclFindAndDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -104,16 +152,21 @@ interface AclServiceAsync { /** A view of [AclServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AclServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/acl`, but is otherwise the same as * [AclServiceAsync.create]. */ - @MustBeClosed fun create(params: AclCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: AclCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -123,27 +176,48 @@ interface AclServiceAsync { * Returns a raw HTTP response for `get /v1/acl/{acl_id}`, but is otherwise the same as * [AclServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: AclRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(aclId: String): CompletableFuture> = + retrieve(aclId, AclRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().aclId(aclId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + ): CompletableFuture> = retrieve(aclId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: AclRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: AclRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + aclId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(aclId, AclRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/acl`, but is otherwise the same as * [AclServiceAsync.list]. */ - @MustBeClosed fun list(params: AclListParams): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: AclListParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -153,41 +227,60 @@ interface AclServiceAsync { * Returns a raw HTTP response for `delete /v1/acl/{acl_id}`, but is otherwise the same as * [AclServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: AclDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(aclId: String): CompletableFuture> = + delete(aclId, AclDeleteParams.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see delete */ + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + ): CompletableFuture> = delete(aclId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: AclDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: AclDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + aclId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(aclId, AclDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/acl/batch_update`, but is otherwise the same as * [AclServiceAsync.batchUpdate]. */ - @MustBeClosed fun batchUpdate(): CompletableFuture> = batchUpdate(AclBatchUpdateParams.none()) - /** @see [batchUpdate] */ - @MustBeClosed + /** @see batchUpdate */ fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [batchUpdate] */ - @MustBeClosed + /** @see batchUpdate */ fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none() ): CompletableFuture> = batchUpdate(params, RequestOptions.none()) - /** @see [batchUpdate] */ - @MustBeClosed + /** @see batchUpdate */ fun batchUpdate( requestOptions: RequestOptions ): CompletableFuture> = @@ -197,12 +290,10 @@ interface AclServiceAsync { * Returns a raw HTTP response for `delete /v1/acl`, but is otherwise the same as * [AclServiceAsync.findAndDelete]. */ - @MustBeClosed fun findAndDelete(params: AclFindAndDeleteParams): CompletableFuture> = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ - @MustBeClosed + /** @see findAndDelete */ fun findAndDelete( params: AclFindAndDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt index 2cde27c7..a9dee716 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -26,6 +27,8 @@ import com.braintrustdata.api.models.AclListPageResponse import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclRetrieveParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class AclServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : AclServiceAsync { @@ -36,6 +39,9 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client override fun withRawResponse(): AclServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): AclServiceAsync = + AclServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: AclCreateParams, requestOptions: RequestOptions, @@ -81,10 +87,17 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AclServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): AclServiceAsync.WithRawResponse = + AclServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: AclCreateParams, @@ -93,6 +106,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -101,7 +115,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -113,16 +127,19 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: AclRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aclId", params.aclId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -130,7 +147,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -144,7 +161,6 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: AclListParams, @@ -153,6 +169,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl") .build() .prepareAsync(clientOptions, params) @@ -160,7 +177,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -171,6 +188,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client .let { AclListPageAsync.builder() .service(AclServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -179,16 +197,19 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: AclDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aclId", params.aclId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -197,7 +218,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -211,7 +232,6 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client private val batchUpdateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun batchUpdate( params: AclBatchUpdateParams, @@ -220,6 +240,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl", "batch_update") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -228,7 +249,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { batchUpdateHandler.handle(it) } .also { @@ -240,8 +261,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val findAndDeleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val findAndDeleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun findAndDelete( params: AclFindAndDeleteParams, @@ -250,6 +270,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -258,7 +279,7 @@ class AclServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { findAndDeleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsync.kt index dc90a38c..2a3e9996 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.AISecret @@ -13,8 +14,8 @@ import com.braintrustdata.api.models.AiSecretListParams import com.braintrustdata.api.models.AiSecretReplaceParams import com.braintrustdata.api.models.AiSecretRetrieveParams import com.braintrustdata.api.models.AiSecretUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface AiSecretServiceAsync { @@ -23,6 +24,13 @@ interface AiSecretServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AiSecretServiceAsync + /** * Create a new ai_secret. If there is an existing ai_secret with the same name as the one * specified in the request, will return the existing ai_secret unmodified @@ -30,72 +38,138 @@ interface AiSecretServiceAsync { fun create(params: AiSecretCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: AiSecretCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get an ai_secret object by its id */ - fun retrieve(params: AiSecretRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(aiSecretId: String): CompletableFuture = + retrieve(aiSecretId, AiSecretRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + ): CompletableFuture = retrieve(aiSecretId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: AiSecretRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: AiSecretRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(aiSecretId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(aiSecretId, AiSecretRetrieveParams.none(), requestOptions) + /** * Partially update an ai_secret object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: AiSecretUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(aiSecretId: String): CompletableFuture = + update(aiSecretId, AiSecretUpdateParams.none()) + + /** @see update */ + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see update */ + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + ): CompletableFuture = update(aiSecretId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: AiSecretUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: AiSecretUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(aiSecretId: String, requestOptions: RequestOptions): CompletableFuture = + update(aiSecretId, AiSecretUpdateParams.none(), requestOptions) + /** * List out all ai_secrets. The ai_secrets are sorted by creation date, with the most * recently-created ai_secrets coming first */ fun list(): CompletableFuture = list(AiSecretListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: AiSecretListParams = AiSecretListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: AiSecretListParams = AiSecretListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(AiSecretListParams.none(), requestOptions) /** Delete an ai_secret object by its id */ - fun delete(params: AiSecretDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(aiSecretId: String): CompletableFuture = + delete(aiSecretId, AiSecretDeleteParams.none()) + + /** @see delete */ + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see delete */ + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + ): CompletableFuture = delete(aiSecretId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: AiSecretDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: AiSecretDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(aiSecretId: String, requestOptions: RequestOptions): CompletableFuture = + delete(aiSecretId, AiSecretDeleteParams.none(), requestOptions) + /** Delete a single ai_secret */ fun findAndDelete(params: AiSecretFindAndDeleteParams): CompletableFuture = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ + /** @see findAndDelete */ fun findAndDelete( params: AiSecretFindAndDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -108,7 +182,7 @@ interface AiSecretServiceAsync { fun replace(params: AiSecretReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: AiSecretReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -119,16 +193,23 @@ interface AiSecretServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): AiSecretServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/ai_secret`, but is otherwise the same as * [AiSecretServiceAsync.create]. */ - @MustBeClosed fun create(params: AiSecretCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: AiSecretCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -138,56 +219,100 @@ interface AiSecretServiceAsync { * Returns a raw HTTP response for `get /v1/ai_secret/{ai_secret_id}`, but is otherwise the * same as [AiSecretServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: AiSecretRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(aiSecretId: String): CompletableFuture> = + retrieve(aiSecretId, AiSecretRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + ): CompletableFuture> = + retrieve(aiSecretId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: AiSecretRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: AiSecretRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(aiSecretId, AiSecretRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/ai_secret/{ai_secret_id}`, but is otherwise * the same as [AiSecretServiceAsync.update]. */ - @MustBeClosed - fun update(params: AiSecretUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(aiSecretId: String): CompletableFuture> = + update(aiSecretId, AiSecretUpdateParams.none()) + + /** @see update */ + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see update */ + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + ): CompletableFuture> = + update(aiSecretId, params, RequestOptions.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ fun update( params: AiSecretUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: AiSecretUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + aiSecretId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(aiSecretId, AiSecretUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/ai_secret`, but is otherwise the same as * [AiSecretServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(AiSecretListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: AiSecretListParams = AiSecretListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: AiSecretListParams = AiSecretListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -197,29 +322,51 @@ interface AiSecretServiceAsync { * Returns a raw HTTP response for `delete /v1/ai_secret/{ai_secret_id}`, but is otherwise * the same as [AiSecretServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: AiSecretDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(aiSecretId: String): CompletableFuture> = + delete(aiSecretId, AiSecretDeleteParams.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see delete */ + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + ): CompletableFuture> = + delete(aiSecretId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: AiSecretDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: AiSecretDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + aiSecretId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(aiSecretId, AiSecretDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `delete /v1/ai_secret`, but is otherwise the same as * [AiSecretServiceAsync.findAndDelete]. */ - @MustBeClosed fun findAndDelete( params: AiSecretFindAndDeleteParams ): CompletableFuture> = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ - @MustBeClosed + /** @see findAndDelete */ fun findAndDelete( params: AiSecretFindAndDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -229,12 +376,10 @@ interface AiSecretServiceAsync { * Returns a raw HTTP response for `put /v1/ai_secret`, but is otherwise the same as * [AiSecretServiceAsync.replace]. */ - @MustBeClosed fun replace(params: AiSecretReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: AiSecretReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt index 5cd2d51e..247ce3f1 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -26,6 +27,8 @@ import com.braintrustdata.api.models.AiSecretReplaceParams import com.braintrustdata.api.models.AiSecretRetrieveParams import com.braintrustdata.api.models.AiSecretUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : AiSecretServiceAsync { @@ -36,6 +39,9 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C override fun withRawResponse(): AiSecretServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): AiSecretServiceAsync = + AiSecretServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: AiSecretCreateParams, requestOptions: RequestOptions, @@ -88,10 +94,18 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AiSecretServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): AiSecretServiceAsync.WithRawResponse = + AiSecretServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: AiSecretCreateParams, @@ -100,6 +114,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -108,7 +123,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -121,15 +136,19 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: AiSecretRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aiSecretId", params.aiSecretId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -137,7 +156,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -150,15 +169,19 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: AiSecretUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aiSecretId", params.aiSecretId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -167,7 +190,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -181,7 +204,6 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: AiSecretListParams, @@ -190,6 +212,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .build() .prepareAsync(clientOptions, params) @@ -197,7 +220,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -208,6 +231,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C .let { AiSecretListPageAsync.builder() .service(AiSecretServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -217,15 +241,19 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: AiSecretDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aiSecretId", params.aiSecretId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -234,7 +262,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -247,7 +275,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } private val findAndDeleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun findAndDelete( params: AiSecretFindAndDeleteParams, @@ -256,6 +284,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -264,7 +293,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { findAndDeleteHandler.handle(it) } .also { @@ -277,7 +306,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: AiSecretReplaceParams, @@ -286,6 +315,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -294,7 +324,7 @@ class AiSecretServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsync.kt index 94e69910..4de06104 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.ApiKey @@ -11,8 +12,8 @@ import com.braintrustdata.api.models.ApiKeyListPageAsync import com.braintrustdata.api.models.ApiKeyListParams import com.braintrustdata.api.models.ApiKeyRetrieveParams import com.braintrustdata.api.models.CreateApiKeyOutput -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface ApiKeyServiceAsync { @@ -21,6 +22,13 @@ interface ApiKeyServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ApiKeyServiceAsync + /** * Create a new api_key. It is possible to have multiple API keys with the same name. There is * no de-duplication @@ -28,70 +36,121 @@ interface ApiKeyServiceAsync { fun create(params: ApiKeyCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ApiKeyCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get an api_key object by its id */ - fun retrieve(params: ApiKeyRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(apiKeyId: String): CompletableFuture = + retrieve(apiKeyId, ApiKeyRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + ): CompletableFuture = retrieve(apiKeyId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ApiKeyRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: ApiKeyRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(apiKeyId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(apiKeyId, ApiKeyRetrieveParams.none(), requestOptions) + /** * List out all api_keys. The api_keys are sorted by creation date, with the most * recently-created api_keys coming first */ fun list(): CompletableFuture = list(ApiKeyListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ApiKeyListParams = ApiKeyListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: ApiKeyListParams = ApiKeyListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(ApiKeyListParams.none(), requestOptions) /** Delete an api_key object by its id */ - fun delete(params: ApiKeyDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(apiKeyId: String): CompletableFuture = + delete(apiKeyId, ApiKeyDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) + + /** @see delete */ + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + ): CompletableFuture = delete(apiKeyId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ApiKeyDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: ApiKeyDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(apiKeyId: String, requestOptions: RequestOptions): CompletableFuture = + delete(apiKeyId, ApiKeyDeleteParams.none(), requestOptions) + /** * A view of [ApiKeyServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ApiKeyServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/api_key`, but is otherwise the same as * [ApiKeyServiceAsync.create]. */ - @MustBeClosed fun create( params: ApiKeyCreateParams ): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: ApiKeyCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -101,41 +160,61 @@ interface ApiKeyServiceAsync { * Returns a raw HTTP response for `get /v1/api_key/{api_key_id}`, but is otherwise the same * as [ApiKeyServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: ApiKeyRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(apiKeyId: String): CompletableFuture> = + retrieve(apiKeyId, ApiKeyRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + ): CompletableFuture> = + retrieve(apiKeyId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ApiKeyRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: ApiKeyRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(apiKeyId, ApiKeyRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/api_key`, but is otherwise the same as * [ApiKeyServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(ApiKeyListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ApiKeyListParams = ApiKeyListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ApiKeyListParams = ApiKeyListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -145,15 +224,39 @@ interface ApiKeyServiceAsync { * Returns a raw HTTP response for `delete /v1/api_key/{api_key_id}`, but is otherwise the * same as [ApiKeyServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: ApiKeyDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(apiKeyId: String): CompletableFuture> = + delete(apiKeyId, ApiKeyDeleteParams.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) + + /** @see delete */ + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + ): CompletableFuture> = + delete(apiKeyId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ApiKeyDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see delete */ + fun delete(params: ApiKeyDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + apiKeyId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(apiKeyId, ApiKeyDeleteParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt index c0298579..0bffa187 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.ApiKeyListParams import com.braintrustdata.api.models.ApiKeyRetrieveParams import com.braintrustdata.api.models.CreateApiKeyOutput import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ApiKeyServiceAsync { @@ -34,6 +37,9 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun withRawResponse(): ApiKeyServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ApiKeyServiceAsync = + ApiKeyServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ApiKeyCreateParams, requestOptions: RequestOptions, @@ -65,10 +71,18 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ApiKeyServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ApiKeyServiceAsync.WithRawResponse = + ApiKeyServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ApiKeyCreateParams, @@ -77,6 +91,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -85,7 +100,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -97,16 +112,19 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ApiKeyRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("apiKeyId", params.apiKeyId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -114,7 +132,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -128,7 +146,6 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ApiKeyListParams, @@ -137,6 +154,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key") .build() .prepareAsync(clientOptions, params) @@ -144,7 +162,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -155,6 +173,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli .let { ApiKeyListPageAsync.builder() .service(ApiKeyServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -163,16 +182,19 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: ApiKeyDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("apiKeyId", params.apiKeyId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -181,7 +203,7 @@ class ApiKeyServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsync.kt index a6d7c52c..e352ecfc 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Dataset @@ -20,8 +21,8 @@ import com.braintrustdata.api.models.FeedbackResponseSchema import com.braintrustdata.api.models.FetchDatasetEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeDatasetResponse -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface DatasetServiceAsync { @@ -30,6 +31,13 @@ interface DatasetServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DatasetServiceAsync + /** * Create a new dataset. If there is an existing dataset in the project with the same name as * the one specified in the request, will return the existing dataset unmodified @@ -37,72 +45,153 @@ interface DatasetServiceAsync { fun create(params: DatasetCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: DatasetCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a dataset object by its id */ - fun retrieve(params: DatasetRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(datasetId: String): CompletableFuture = + retrieve(datasetId, DatasetRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + ): CompletableFuture = retrieve(datasetId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: DatasetRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: DatasetRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(datasetId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(datasetId, DatasetRetrieveParams.none(), requestOptions) + /** * Partially update a dataset object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: DatasetUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(datasetId: String): CompletableFuture = + update(datasetId, DatasetUpdateParams.none()) + + /** @see update */ + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + ): CompletableFuture = update(datasetId, params, RequestOptions.none()) + + /** @see update */ fun update( params: DatasetUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: DatasetUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(datasetId: String, requestOptions: RequestOptions): CompletableFuture = + update(datasetId, DatasetUpdateParams.none(), requestOptions) + /** * List out all datasets. The datasets are sorted by creation date, with the most * recently-created datasets coming first */ fun list(): CompletableFuture = list(DatasetListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: DatasetListParams = DatasetListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: DatasetListParams = DatasetListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(DatasetListParams.none(), requestOptions) /** Delete a dataset object by its id */ - fun delete(params: DatasetDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(datasetId: String): CompletableFuture = + delete(datasetId, DatasetDeleteParams.none()) + + /** @see delete */ + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see delete */ + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + ): CompletableFuture = delete(datasetId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: DatasetDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: DatasetDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(datasetId: String, requestOptions: RequestOptions): CompletableFuture = + delete(datasetId, DatasetDeleteParams.none(), requestOptions) + /** Log feedback for a set of dataset events */ + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + ): CompletableFuture = + feedback(datasetId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + feedback(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see feedback */ fun feedback(params: DatasetFeedbackParams): CompletableFuture = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ fun feedback( params: DatasetFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -113,64 +202,163 @@ interface DatasetServiceAsync { * parameters in the URL query rather than in the request body. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetch(params: DatasetFetchParams): CompletableFuture = - fetch(params, RequestOptions.none()) + fun fetch(datasetId: String): CompletableFuture = + fetch(datasetId, DatasetFetchParams.none()) + + /** @see fetch */ + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + fetch(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [fetch] */ + /** @see fetch */ + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + ): CompletableFuture = + fetch(datasetId, params, RequestOptions.none()) + + /** @see fetch */ fun fetch( params: DatasetFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see fetch */ + fun fetch(params: DatasetFetchParams): CompletableFuture = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + fetch(datasetId, DatasetFetchParams.none(), requestOptions) + /** * Fetch the events in a dataset. Equivalent to the GET form of the same path, but with the * parameters in the request body rather than in the URL query. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetchPost(params: DatasetFetchPostParams): CompletableFuture = - fetchPost(params, RequestOptions.none()) + fun fetchPost(datasetId: String): CompletableFuture = + fetchPost(datasetId, DatasetFetchPostParams.none()) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + fetchPost(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + ): CompletableFuture = + fetchPost(datasetId, params, RequestOptions.none()) - /** @see [fetchPost] */ + /** @see fetchPost */ fun fetchPost( params: DatasetFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see fetchPost */ + fun fetchPost(params: DatasetFetchPostParams): CompletableFuture = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + fetchPost(datasetId, DatasetFetchPostParams.none(), requestOptions) + /** Insert a set of events into the dataset */ + fun insert( + datasetId: String, + params: DatasetInsertParams, + ): CompletableFuture = insert(datasetId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + datasetId: String, + params: DatasetInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + insert(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see insert */ fun insert(params: DatasetInsertParams): CompletableFuture = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ fun insert( params: DatasetInsertParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Summarize dataset */ - fun summarize(params: DatasetSummarizeParams): CompletableFuture = - summarize(params, RequestOptions.none()) + fun summarize(datasetId: String): CompletableFuture = + summarize(datasetId, DatasetSummarizeParams.none()) + + /** @see summarize */ + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + summarize(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [summarize] */ + /** @see summarize */ + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + ): CompletableFuture = + summarize(datasetId, params, RequestOptions.none()) + + /** @see summarize */ fun summarize( params: DatasetSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see summarize */ + fun summarize(params: DatasetSummarizeParams): CompletableFuture = + summarize(params, RequestOptions.none()) + + /** @see summarize */ + fun summarize( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + summarize(datasetId, DatasetSummarizeParams.none(), requestOptions) + /** * A view of [DatasetServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): DatasetServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/dataset`, but is otherwise the same as * [DatasetServiceAsync.create]. */ - @MustBeClosed fun create(params: DatasetCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: DatasetCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -180,56 +368,100 @@ interface DatasetServiceAsync { * Returns a raw HTTP response for `get /v1/dataset/{dataset_id}`, but is otherwise the same * as [DatasetServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: DatasetRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(datasetId: String): CompletableFuture> = + retrieve(datasetId, DatasetRetrieveParams.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + ): CompletableFuture> = + retrieve(datasetId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: DatasetRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: DatasetRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(datasetId, DatasetRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/dataset/{dataset_id}`, but is otherwise the * same as [DatasetServiceAsync.update]. */ - @MustBeClosed - fun update(params: DatasetUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(datasetId: String): CompletableFuture> = + update(datasetId, DatasetUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see update */ + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + ): CompletableFuture> = + update(datasetId, params, RequestOptions.none()) + + /** @see update */ fun update( params: DatasetUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: DatasetUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(datasetId, DatasetUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/dataset`, but is otherwise the same as * [DatasetServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(DatasetListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: DatasetListParams = DatasetListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: DatasetListParams = DatasetListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -239,29 +471,66 @@ interface DatasetServiceAsync { * Returns a raw HTTP response for `delete /v1/dataset/{dataset_id}`, but is otherwise the * same as [DatasetServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: DatasetDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(datasetId: String): CompletableFuture> = + delete(datasetId, DatasetDeleteParams.none()) + + /** @see delete */ + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see delete */ + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + ): CompletableFuture> = + delete(datasetId, params, RequestOptions.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ fun delete( params: DatasetDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: DatasetDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(datasetId, DatasetDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/dataset/{dataset_id}/feedback`, but is * otherwise the same as [DatasetServiceAsync.feedback]. */ - @MustBeClosed + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + ): CompletableFuture> = + feedback(datasetId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + feedback(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see feedback */ fun feedback( params: DatasetFeedbackParams ): CompletableFuture> = feedback(params, RequestOptions.none()) - /** @see [feedback] */ - @MustBeClosed + /** @see feedback */ fun feedback( params: DatasetFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -271,48 +540,113 @@ interface DatasetServiceAsync { * Returns a raw HTTP response for `get /v1/dataset/{dataset_id}/fetch`, but is otherwise * the same as [DatasetServiceAsync.fetch]. */ - @MustBeClosed fun fetch( - params: DatasetFetchParams + datasetId: String ): CompletableFuture> = - fetch(params, RequestOptions.none()) + fetch(datasetId, DatasetFetchParams.none()) + + /** @see fetch */ + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + fetch(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [fetch] */ - @MustBeClosed + /** @see fetch */ + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + ): CompletableFuture> = + fetch(datasetId, params, RequestOptions.none()) + + /** @see fetch */ fun fetch( params: DatasetFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see fetch */ + fun fetch( + params: DatasetFetchParams + ): CompletableFuture> = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + fetch(datasetId, DatasetFetchParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/dataset/{dataset_id}/fetch`, but is otherwise * the same as [DatasetServiceAsync.fetchPost]. */ - @MustBeClosed fun fetchPost( - params: DatasetFetchPostParams + datasetId: String ): CompletableFuture> = - fetchPost(params, RequestOptions.none()) + fetchPost(datasetId, DatasetFetchPostParams.none()) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + fetchPost(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + ): CompletableFuture> = + fetchPost(datasetId, params, RequestOptions.none()) - /** @see [fetchPost] */ - @MustBeClosed + /** @see fetchPost */ fun fetchPost( params: DatasetFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see fetchPost */ + fun fetchPost( + params: DatasetFetchPostParams + ): CompletableFuture> = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + fetchPost(datasetId, DatasetFetchPostParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/dataset/{dataset_id}/insert`, but is otherwise * the same as [DatasetServiceAsync.insert]. */ - @MustBeClosed + fun insert( + datasetId: String, + params: DatasetInsertParams, + ): CompletableFuture> = + insert(datasetId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + datasetId: String, + params: DatasetInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + insert(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see insert */ fun insert( params: DatasetInsertParams ): CompletableFuture> = insert(params, RequestOptions.none()) - /** @see [insert] */ - @MustBeClosed + /** @see insert */ fun insert( params: DatasetInsertParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -322,17 +656,43 @@ interface DatasetServiceAsync { * Returns a raw HTTP response for `get /v1/dataset/{dataset_id}/summarize`, but is * otherwise the same as [DatasetServiceAsync.summarize]. */ - @MustBeClosed fun summarize( - params: DatasetSummarizeParams + datasetId: String ): CompletableFuture> = - summarize(params, RequestOptions.none()) + summarize(datasetId, DatasetSummarizeParams.none()) + + /** @see summarize */ + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + summarize(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see summarize */ + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + ): CompletableFuture> = + summarize(datasetId, params, RequestOptions.none()) - /** @see [summarize] */ - @MustBeClosed + /** @see summarize */ fun summarize( params: DatasetSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see summarize */ + fun summarize( + params: DatasetSummarizeParams + ): CompletableFuture> = + summarize(params, RequestOptions.none()) + + /** @see summarize */ + fun summarize( + datasetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + summarize(datasetId, DatasetSummarizeParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt index 14e26354..3c31da2f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -33,6 +34,8 @@ import com.braintrustdata.api.models.FetchDatasetEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeDatasetResponse import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class DatasetServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : DatasetServiceAsync { @@ -43,6 +46,9 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun withRawResponse(): DatasetServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): DatasetServiceAsync = + DatasetServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: DatasetCreateParams, requestOptions: RequestOptions, @@ -116,10 +122,17 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : DatasetServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): DatasetServiceAsync.WithRawResponse = + DatasetServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: DatasetCreateParams, @@ -128,6 +141,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -136,7 +150,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -149,15 +163,19 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: DatasetRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -165,7 +183,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -177,16 +195,19 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: DatasetUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -195,7 +216,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -209,7 +230,6 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: DatasetListParams, @@ -218,6 +238,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset") .build() .prepareAsync(clientOptions, params) @@ -225,7 +246,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -236,6 +257,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { DatasetListPageAsync.builder() .service(DatasetServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -244,16 +266,19 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: DatasetDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -262,7 +287,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -276,15 +301,18 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun feedback( params: DatasetFeedbackParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -293,7 +321,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { feedbackHandler.handle(it) } .also { @@ -307,15 +335,18 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: DatasetFetchParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .build() .prepareAsync(clientOptions, params) @@ -323,7 +354,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -337,15 +368,18 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl private val fetchPostHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchPost( params: DatasetFetchPostParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -354,7 +388,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchPostHandler.handle(it) } .also { @@ -368,15 +402,18 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl private val insertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun insert( params: DatasetInsertParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -385,7 +422,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { insertHandler.handle(it) } .also { @@ -399,15 +436,18 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl private val summarizeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun summarize( params: DatasetSummarizeParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "summarize") .build() .prepareAsync(clientOptions, params) @@ -415,7 +455,7 @@ class DatasetServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { summarizeHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsync.kt index 49a3693f..07a075b2 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.EnvVar @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.EnvVarListResponse import com.braintrustdata.api.models.EnvVarReplaceParams import com.braintrustdata.api.models.EnvVarRetrieveParams import com.braintrustdata.api.models.EnvVarUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface EnvVarServiceAsync { @@ -22,6 +23,13 @@ interface EnvVarServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EnvVarServiceAsync + /** * Create a new env_var. If there is an existing env_var with the same name as the one specified * in the request, will return the existing env_var unmodified @@ -29,31 +37,65 @@ interface EnvVarServiceAsync { fun create(params: EnvVarCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: EnvVarCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get an env_var object by its id */ - fun retrieve(params: EnvVarRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(envVarId: String): CompletableFuture = + retrieve(envVarId, EnvVarRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().envVarId(envVarId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + ): CompletableFuture = retrieve(envVarId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: EnvVarRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: EnvVarRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(envVarId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(envVarId, EnvVarRetrieveParams.none(), requestOptions) + /** * Partially update an env_var object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ + fun update(envVarId: String, params: EnvVarUpdateParams): CompletableFuture = + update(envVarId, params, RequestOptions.none()) + + /** @see update */ + fun update( + envVarId: String, + params: EnvVarUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see update */ fun update(params: EnvVarUpdateParams): CompletableFuture = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: EnvVarUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -65,31 +107,53 @@ interface EnvVarServiceAsync { */ fun list(): CompletableFuture = list(EnvVarListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: EnvVarListParams = EnvVarListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: EnvVarListParams = EnvVarListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(EnvVarListParams.none(), requestOptions) /** Delete an env_var object by its id */ - fun delete(params: EnvVarDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(envVarId: String): CompletableFuture = + delete(envVarId, EnvVarDeleteParams.none()) + + /** @see delete */ + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().envVarId(envVarId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + ): CompletableFuture = delete(envVarId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: EnvVarDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: EnvVarDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(envVarId: String, requestOptions: RequestOptions): CompletableFuture = + delete(envVarId, EnvVarDeleteParams.none(), requestOptions) + /** * Create or replace env_var. If there is an existing env_var with the same name as the one * specified in the request, will replace the existing env_var with the provided fields @@ -97,7 +161,7 @@ interface EnvVarServiceAsync { fun replace(params: EnvVarReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: EnvVarReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -108,16 +172,23 @@ interface EnvVarServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): EnvVarServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/env_var`, but is otherwise the same as * [EnvVarServiceAsync.create]. */ - @MustBeClosed fun create(params: EnvVarCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: EnvVarCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -127,27 +198,64 @@ interface EnvVarServiceAsync { * Returns a raw HTTP response for `get /v1/env_var/{env_var_id}`, but is otherwise the same * as [EnvVarServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: EnvVarRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(envVarId: String): CompletableFuture> = + retrieve(envVarId, EnvVarRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + ): CompletableFuture> = + retrieve(envVarId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: EnvVarRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: EnvVarRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + envVarId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(envVarId, EnvVarRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/env_var/{env_var_id}`, but is otherwise the * same as [EnvVarServiceAsync.update]. */ - @MustBeClosed + fun update( + envVarId: String, + params: EnvVarUpdateParams, + ): CompletableFuture> = + update(envVarId, params, RequestOptions.none()) + + /** @see update */ + fun update( + envVarId: String, + params: EnvVarUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see update */ fun update(params: EnvVarUpdateParams): CompletableFuture> = update(params, RequestOptions.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ fun update( params: EnvVarUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -157,26 +265,22 @@ interface EnvVarServiceAsync { * Returns a raw HTTP response for `get /v1/env_var`, but is otherwise the same as * [EnvVarServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(EnvVarListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: EnvVarListParams = EnvVarListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: EnvVarListParams = EnvVarListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -186,27 +290,49 @@ interface EnvVarServiceAsync { * Returns a raw HTTP response for `delete /v1/env_var/{env_var_id}`, but is otherwise the * same as [EnvVarServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: EnvVarDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(envVarId: String): CompletableFuture> = + delete(envVarId, EnvVarDeleteParams.none()) + + /** @see delete */ + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see delete */ + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + ): CompletableFuture> = + delete(envVarId, params, RequestOptions.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ fun delete( params: EnvVarDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: EnvVarDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + envVarId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(envVarId, EnvVarDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/env_var`, but is otherwise the same as * [EnvVarServiceAsync.replace]. */ - @MustBeClosed fun replace(params: EnvVarReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: EnvVarReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt index a3480f74..dd7e690d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.EnvVarReplaceParams import com.braintrustdata.api.models.EnvVarRetrieveParams import com.braintrustdata.api.models.EnvVarUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : EnvVarServiceAsync { @@ -34,6 +37,9 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun withRawResponse(): EnvVarServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): EnvVarServiceAsync = + EnvVarServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: EnvVarCreateParams, requestOptions: RequestOptions, @@ -79,10 +85,17 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EnvVarServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): EnvVarServiceAsync.WithRawResponse = + EnvVarServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: EnvVarCreateParams, @@ -91,6 +104,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -99,7 +113,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -111,16 +125,19 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: EnvVarRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("envVarId", params.envVarId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -128,7 +145,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -140,16 +157,19 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: EnvVarUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("envVarId", params.envVarId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -158,7 +178,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -171,7 +191,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli } private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: EnvVarListParams, @@ -180,6 +200,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var") .build() .prepareAsync(clientOptions, params) @@ -187,7 +208,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -199,16 +220,19 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: EnvVarDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("envVarId", params.envVarId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -217,7 +241,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -229,8 +253,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: EnvVarReplaceParams, @@ -239,6 +262,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -247,7 +271,7 @@ class EnvVarServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsync.kt index 69b6f45c..88ecbb29 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsync.kt @@ -2,12 +2,13 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.EvalCreateParams import com.braintrustdata.api.models.SummarizeExperimentResponse -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface EvalServiceAsync { @@ -16,6 +17,13 @@ interface EvalServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EvalServiceAsync + /** * Launch an evaluation. This is the API-equivalent of the `Eval` function that is built into * the Braintrust SDK. In the Eval API, you provide pointers to a dataset, task function, and @@ -26,7 +34,7 @@ interface EvalServiceAsync { fun create(params: EvalCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: EvalCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -35,18 +43,23 @@ interface EvalServiceAsync { /** A view of [EvalServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EvalServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/eval`, but is otherwise the same as * [EvalServiceAsync.create]. */ - @MustBeClosed fun create( params: EvalCreateParams ): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: EvalCreateParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt index 619ae690..ffdc48b0 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/EvalServiceAsyncImpl.kt @@ -3,13 +3,13 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -18,6 +18,7 @@ import com.braintrustdata.api.core.prepareAsync import com.braintrustdata.api.models.EvalCreateParams import com.braintrustdata.api.models.SummarizeExperimentResponse import java.util.concurrent.CompletableFuture +import java.util.function.Consumer class EvalServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : EvalServiceAsync { @@ -28,6 +29,9 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun withRawResponse(): EvalServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): EvalServiceAsync = + EvalServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: EvalCreateParams, requestOptions: RequestOptions, @@ -38,11 +42,18 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EvalServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): EvalServiceAsync.WithRawResponse = + EvalServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: EvalCreateParams, @@ -51,6 +62,7 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "eval") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -59,7 +71,7 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsync.kt index e10046e6..32bc1644 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Experiment @@ -20,8 +21,8 @@ import com.braintrustdata.api.models.FeedbackResponseSchema import com.braintrustdata.api.models.FetchExperimentEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeExperimentResponse -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface ExperimentServiceAsync { @@ -30,6 +31,13 @@ interface ExperimentServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ExperimentServiceAsync + /** * Create a new experiment. If there is an existing experiment in the project with the same name * as the one specified in the request, will return the existing experiment unmodified @@ -37,72 +45,162 @@ interface ExperimentServiceAsync { fun create(params: ExperimentCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ExperimentCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get an experiment object by its id */ - fun retrieve(params: ExperimentRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(experimentId: String): CompletableFuture = + retrieve(experimentId, ExperimentRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + ): CompletableFuture = retrieve(experimentId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ExperimentRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: ExperimentRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(experimentId, ExperimentRetrieveParams.none(), requestOptions) + /** * Partially update an experiment object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ExperimentUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(experimentId: String): CompletableFuture = + update(experimentId, ExperimentUpdateParams.none()) + + /** @see update */ + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see update */ + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + ): CompletableFuture = update(experimentId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: ExperimentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: ExperimentUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(experimentId, ExperimentUpdateParams.none(), requestOptions) + /** * List out all experiments. The experiments are sorted by creation date, with the most * recently-created experiments coming first */ fun list(): CompletableFuture = list(ExperimentListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ExperimentListParams = ExperimentListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: ExperimentListParams = ExperimentListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(ExperimentListParams.none(), requestOptions) /** Delete an experiment object by its id */ - fun delete(params: ExperimentDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(experimentId: String): CompletableFuture = + delete(experimentId, ExperimentDeleteParams.none()) + + /** @see delete */ + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().experimentId(experimentId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + ): CompletableFuture = delete(experimentId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ExperimentDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: ExperimentDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(experimentId, ExperimentDeleteParams.none(), requestOptions) + /** Log feedback for a set of experiment events */ + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + ): CompletableFuture = + feedback(experimentId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + feedback(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see feedback */ fun feedback(params: ExperimentFeedbackParams): CompletableFuture = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ fun feedback( params: ExperimentFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -113,67 +211,166 @@ interface ExperimentServiceAsync { * parameters in the URL query rather than in the request body. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetch(params: ExperimentFetchParams): CompletableFuture = - fetch(params, RequestOptions.none()) + fun fetch(experimentId: String): CompletableFuture = + fetch(experimentId, ExperimentFetchParams.none()) - /** @see [fetch] */ + /** @see fetch */ + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + fetch(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + ): CompletableFuture = + fetch(experimentId, params, RequestOptions.none()) + + /** @see fetch */ fun fetch( params: ExperimentFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see fetch */ + fun fetch(params: ExperimentFetchParams): CompletableFuture = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + fetch(experimentId, ExperimentFetchParams.none(), requestOptions) + /** * Fetch the events in an experiment. Equivalent to the GET form of the same path, but with the * parameters in the request body rather than in the URL query. For more complex queries, use * the `POST /btql` endpoint. */ + fun fetchPost(experimentId: String): CompletableFuture = + fetchPost(experimentId, ExperimentFetchPostParams.none()) + + /** @see fetchPost */ fun fetchPost( - params: ExperimentFetchPostParams - ): CompletableFuture = fetchPost(params, RequestOptions.none()) + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + fetchPost(params.toBuilder().experimentId(experimentId).build(), requestOptions) - /** @see [fetchPost] */ + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + ): CompletableFuture = + fetchPost(experimentId, params, RequestOptions.none()) + + /** @see fetchPost */ fun fetchPost( params: ExperimentFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see fetchPost */ + fun fetchPost( + params: ExperimentFetchPostParams + ): CompletableFuture = fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + fetchPost(experimentId, ExperimentFetchPostParams.none(), requestOptions) + /** Insert a set of events into the experiment */ + fun insert( + experimentId: String, + params: ExperimentInsertParams, + ): CompletableFuture = insert(experimentId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + experimentId: String, + params: ExperimentInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + insert(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see insert */ fun insert(params: ExperimentInsertParams): CompletableFuture = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ fun insert( params: ExperimentInsertParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Summarize experiment */ + fun summarize(experimentId: String): CompletableFuture = + summarize(experimentId, ExperimentSummarizeParams.none()) + + /** @see summarize */ fun summarize( - params: ExperimentSummarizeParams - ): CompletableFuture = summarize(params, RequestOptions.none()) + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + summarize(params.toBuilder().experimentId(experimentId).build(), requestOptions) - /** @see [summarize] */ + /** @see summarize */ + fun summarize( + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + ): CompletableFuture = + summarize(experimentId, params, RequestOptions.none()) + + /** @see summarize */ fun summarize( params: ExperimentSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see summarize */ + fun summarize( + params: ExperimentSummarizeParams + ): CompletableFuture = summarize(params, RequestOptions.none()) + + /** @see summarize */ + fun summarize( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + summarize(experimentId, ExperimentSummarizeParams.none(), requestOptions) + /** * A view of [ExperimentServiceAsync] that provides access to raw HTTP responses for each * method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ExperimentServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/experiment`, but is otherwise the same as * [ExperimentServiceAsync.create]. */ - @MustBeClosed fun create(params: ExperimentCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: ExperimentCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -183,57 +380,101 @@ interface ExperimentServiceAsync { * Returns a raw HTTP response for `get /v1/experiment/{experiment_id}`, but is otherwise * the same as [ExperimentServiceAsync.retrieve]. */ - @MustBeClosed + fun retrieve(experimentId: String): CompletableFuture> = + retrieve(experimentId, ExperimentRetrieveParams.none()) + + /** @see retrieve */ fun retrieve( - params: ExperimentRetrieveParams - ): CompletableFuture> = retrieve(params, RequestOptions.none()) + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().experimentId(experimentId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + ): CompletableFuture> = + retrieve(experimentId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ExperimentRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve( + params: ExperimentRetrieveParams + ): CompletableFuture> = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(experimentId, ExperimentRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/experiment/{experiment_id}`, but is otherwise * the same as [ExperimentServiceAsync.update]. */ - @MustBeClosed - fun update(params: ExperimentUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(experimentId: String): CompletableFuture> = + update(experimentId, ExperimentUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see update */ + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + ): CompletableFuture> = + update(experimentId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ExperimentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: ExperimentUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(experimentId, ExperimentUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/experiment`, but is otherwise the same as * [ExperimentServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(ExperimentListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ExperimentListParams = ExperimentListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ExperimentListParams = ExperimentListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -243,29 +484,66 @@ interface ExperimentServiceAsync { * Returns a raw HTTP response for `delete /v1/experiment/{experiment_id}`, but is otherwise * the same as [ExperimentServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: ExperimentDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(experimentId: String): CompletableFuture> = + delete(experimentId, ExperimentDeleteParams.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see delete */ + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + ): CompletableFuture> = + delete(experimentId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ExperimentDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: ExperimentDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(experimentId, ExperimentDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/experiment/{experiment_id}/feedback`, but is * otherwise the same as [ExperimentServiceAsync.feedback]. */ - @MustBeClosed + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + ): CompletableFuture> = + feedback(experimentId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + feedback(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see feedback */ fun feedback( params: ExperimentFeedbackParams ): CompletableFuture> = feedback(params, RequestOptions.none()) - /** @see [feedback] */ - @MustBeClosed + /** @see feedback */ fun feedback( params: ExperimentFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -275,48 +553,113 @@ interface ExperimentServiceAsync { * Returns a raw HTTP response for `get /v1/experiment/{experiment_id}/fetch`, but is * otherwise the same as [ExperimentServiceAsync.fetch]. */ - @MustBeClosed fun fetch( - params: ExperimentFetchParams + experimentId: String ): CompletableFuture> = - fetch(params, RequestOptions.none()) + fetch(experimentId, ExperimentFetchParams.none()) + + /** @see fetch */ + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + fetch(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + ): CompletableFuture> = + fetch(experimentId, params, RequestOptions.none()) - /** @see [fetch] */ - @MustBeClosed + /** @see fetch */ fun fetch( params: ExperimentFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see fetch */ + fun fetch( + params: ExperimentFetchParams + ): CompletableFuture> = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + fetch(experimentId, ExperimentFetchParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/experiment/{experiment_id}/fetch`, but is * otherwise the same as [ExperimentServiceAsync.fetchPost]. */ - @MustBeClosed fun fetchPost( - params: ExperimentFetchPostParams + experimentId: String ): CompletableFuture> = - fetchPost(params, RequestOptions.none()) + fetchPost(experimentId, ExperimentFetchPostParams.none()) + + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + fetchPost(params.toBuilder().experimentId(experimentId).build(), requestOptions) - /** @see [fetchPost] */ - @MustBeClosed + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + ): CompletableFuture> = + fetchPost(experimentId, params, RequestOptions.none()) + + /** @see fetchPost */ fun fetchPost( params: ExperimentFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see fetchPost */ + fun fetchPost( + params: ExperimentFetchPostParams + ): CompletableFuture> = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + fetchPost(experimentId, ExperimentFetchPostParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/experiment/{experiment_id}/insert`, but is * otherwise the same as [ExperimentServiceAsync.insert]. */ - @MustBeClosed + fun insert( + experimentId: String, + params: ExperimentInsertParams, + ): CompletableFuture> = + insert(experimentId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + experimentId: String, + params: ExperimentInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + insert(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see insert */ fun insert( params: ExperimentInsertParams ): CompletableFuture> = insert(params, RequestOptions.none()) - /** @see [insert] */ - @MustBeClosed + /** @see insert */ fun insert( params: ExperimentInsertParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -326,17 +669,43 @@ interface ExperimentServiceAsync { * Returns a raw HTTP response for `get /v1/experiment/{experiment_id}/summarize`, but is * otherwise the same as [ExperimentServiceAsync.summarize]. */ - @MustBeClosed fun summarize( - params: ExperimentSummarizeParams + experimentId: String ): CompletableFuture> = - summarize(params, RequestOptions.none()) + summarize(experimentId, ExperimentSummarizeParams.none()) + + /** @see summarize */ + fun summarize( + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + summarize(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see summarize */ + fun summarize( + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + ): CompletableFuture> = + summarize(experimentId, params, RequestOptions.none()) - /** @see [summarize] */ - @MustBeClosed + /** @see summarize */ fun summarize( params: ExperimentSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see summarize */ + fun summarize( + params: ExperimentSummarizeParams + ): CompletableFuture> = + summarize(params, RequestOptions.none()) + + /** @see summarize */ + fun summarize( + experimentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + summarize(experimentId, ExperimentSummarizeParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt index 1b41174a..a90f64f0 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -33,6 +34,8 @@ import com.braintrustdata.api.models.FetchExperimentEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeExperimentResponse import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ExperimentServiceAsync { @@ -43,6 +46,9 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: override fun withRawResponse(): ExperimentServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ExperimentServiceAsync = + ExperimentServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ExperimentCreateParams, requestOptions: RequestOptions, @@ -116,10 +122,18 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExperimentServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ExperimentServiceAsync.WithRawResponse = + ExperimentServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ExperimentCreateParams, @@ -128,6 +142,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -136,7 +151,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -149,15 +164,19 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ExperimentRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -165,7 +184,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -178,15 +197,19 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: ExperimentUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -195,7 +218,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -209,7 +232,6 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ExperimentListParams, @@ -218,6 +240,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment") .build() .prepareAsync(clientOptions, params) @@ -225,7 +248,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -236,6 +259,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: .let { ExperimentListPageAsync.builder() .service(ExperimentServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -245,15 +269,19 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: ExperimentDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -262,7 +290,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -276,15 +304,18 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun feedback( params: ExperimentFeedbackParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -293,7 +324,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { feedbackHandler.handle(it) } .also { @@ -307,15 +338,18 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: ExperimentFetchParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .build() .prepareAsync(clientOptions, params) @@ -323,7 +357,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -337,15 +371,18 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: private val fetchPostHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchPost( params: ExperimentFetchPostParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -354,7 +391,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchPostHandler.handle(it) } .also { @@ -368,15 +405,18 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: private val insertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun insert( params: ExperimentInsertParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -385,7 +425,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { insertHandler.handle(it) } .also { @@ -399,15 +439,18 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: private val summarizeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun summarize( params: ExperimentSummarizeParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "summarize") .build() .prepareAsync(clientOptions, params) @@ -415,7 +458,7 @@ class ExperimentServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { summarizeHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsync.kt index b625969e..5aec01d2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Function @@ -14,9 +15,9 @@ import com.braintrustdata.api.models.FunctionListParams import com.braintrustdata.api.models.FunctionReplaceParams import com.braintrustdata.api.models.FunctionRetrieveParams import com.braintrustdata.api.models.FunctionUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.Optional import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface FunctionServiceAsync { @@ -25,6 +26,13 @@ interface FunctionServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): FunctionServiceAsync + /** * Create a new function. If there is an existing function in the project with the same slug as * the one specified in the request, will return the existing function unmodified @@ -32,77 +40,169 @@ interface FunctionServiceAsync { fun create(params: FunctionCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: FunctionCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a function object by its id */ - fun retrieve(params: FunctionRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(functionId: String): CompletableFuture = + retrieve(functionId, FunctionRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + ): CompletableFuture = retrieve(functionId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: FunctionRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: FunctionRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(functionId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(functionId, FunctionRetrieveParams.none(), requestOptions) + /** * Partially update a function object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: FunctionUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(functionId: String): CompletableFuture = + update(functionId, FunctionUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see update */ + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + ): CompletableFuture = update(functionId, params, RequestOptions.none()) + + /** @see update */ fun update( params: FunctionUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: FunctionUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(functionId: String, requestOptions: RequestOptions): CompletableFuture = + update(functionId, FunctionUpdateParams.none(), requestOptions) + /** * List out all functions. The functions are sorted by creation date, with the most * recently-created functions coming first */ fun list(): CompletableFuture = list(FunctionListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: FunctionListParams = FunctionListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: FunctionListParams = FunctionListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(FunctionListParams.none(), requestOptions) /** Delete a function object by its id */ - fun delete(params: FunctionDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(functionId: String): CompletableFuture = + delete(functionId, FunctionDeleteParams.none()) + + /** @see delete */ + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().functionId(functionId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + ): CompletableFuture = delete(functionId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: FunctionDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: FunctionDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(functionId: String, requestOptions: RequestOptions): CompletableFuture = + delete(functionId, FunctionDeleteParams.none(), requestOptions) + /** Invoke a function. */ - fun invoke(params: FunctionInvokeParams): CompletableFuture> = - invoke(params, RequestOptions.none()) + fun invoke(functionId: String): CompletableFuture> = + invoke(functionId, FunctionInvokeParams.none()) + + /** @see invoke */ + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + invoke(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see invoke */ + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + ): CompletableFuture> = + invoke(functionId, params, RequestOptions.none()) - /** @see [invoke] */ + /** @see invoke */ fun invoke( params: FunctionInvokeParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see invoke */ + fun invoke(params: FunctionInvokeParams): CompletableFuture> = + invoke(params, RequestOptions.none()) + + /** @see invoke */ + fun invoke( + functionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + invoke(functionId, FunctionInvokeParams.none(), requestOptions) + /** * Create or replace function. If there is an existing function in the project with the same * slug as the one specified in the request, will replace the existing function with the @@ -111,7 +211,7 @@ interface FunctionServiceAsync { fun replace(params: FunctionReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: FunctionReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -122,16 +222,23 @@ interface FunctionServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): FunctionServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/function`, but is otherwise the same as * [FunctionServiceAsync.create]. */ - @MustBeClosed fun create(params: FunctionCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: FunctionCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -141,56 +248,100 @@ interface FunctionServiceAsync { * Returns a raw HTTP response for `get /v1/function/{function_id}`, but is otherwise the * same as [FunctionServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: FunctionRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(functionId: String): CompletableFuture> = + retrieve(functionId, FunctionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().functionId(functionId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + ): CompletableFuture> = + retrieve(functionId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: FunctionRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: FunctionRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + functionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(functionId, FunctionRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/function/{function_id}`, but is otherwise the * same as [FunctionServiceAsync.update]. */ - @MustBeClosed - fun update(params: FunctionUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(functionId: String): CompletableFuture> = + update(functionId, FunctionUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see update */ + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + ): CompletableFuture> = + update(functionId, params, RequestOptions.none()) + + /** @see update */ fun update( params: FunctionUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: FunctionUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + functionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(functionId, FunctionUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/function`, but is otherwise the same as * [FunctionServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(FunctionListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: FunctionListParams = FunctionListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: FunctionListParams = FunctionListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -200,44 +351,92 @@ interface FunctionServiceAsync { * Returns a raw HTTP response for `delete /v1/function/{function_id}`, but is otherwise the * same as [FunctionServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: FunctionDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(functionId: String): CompletableFuture> = + delete(functionId, FunctionDeleteParams.none()) + + /** @see delete */ + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see delete */ + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + ): CompletableFuture> = + delete(functionId, params, RequestOptions.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ fun delete( params: FunctionDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: FunctionDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + functionId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(functionId, FunctionDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/function/{function_id}/invoke`, but is * otherwise the same as [FunctionServiceAsync.invoke]. */ - @MustBeClosed fun invoke( - params: FunctionInvokeParams + functionId: String ): CompletableFuture>> = - invoke(params, RequestOptions.none()) + invoke(functionId, FunctionInvokeParams.none()) + + /** @see invoke */ + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture>> = + invoke(params.toBuilder().functionId(functionId).build(), requestOptions) - /** @see [invoke] */ - @MustBeClosed + /** @see invoke */ + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + ): CompletableFuture>> = + invoke(functionId, params, RequestOptions.none()) + + /** @see invoke */ fun invoke( params: FunctionInvokeParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture>> + /** @see invoke */ + fun invoke( + params: FunctionInvokeParams + ): CompletableFuture>> = + invoke(params, RequestOptions.none()) + + /** @see invoke */ + fun invoke( + functionId: String, + requestOptions: RequestOptions, + ): CompletableFuture>> = + invoke(functionId, FunctionInvokeParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/function`, but is otherwise the same as * [FunctionServiceAsync.replace]. */ - @MustBeClosed fun replace(params: FunctionReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: FunctionReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt index b646d9eb..e7a864d7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -28,6 +29,8 @@ import com.braintrustdata.api.models.FunctionRetrieveParams import com.braintrustdata.api.models.FunctionUpdateParams import java.util.Optional import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class FunctionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : FunctionServiceAsync { @@ -38,6 +41,9 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C override fun withRawResponse(): FunctionServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): FunctionServiceAsync = + FunctionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: FunctionCreateParams, requestOptions: RequestOptions, @@ -90,10 +96,18 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : FunctionServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): FunctionServiceAsync.WithRawResponse = + FunctionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: FunctionCreateParams, @@ -102,6 +116,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -110,7 +125,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -123,15 +138,19 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: FunctionRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -139,7 +158,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -152,15 +171,19 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: FunctionUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -169,7 +192,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -183,7 +206,6 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: FunctionListParams, @@ -192,6 +214,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function") .build() .prepareAsync(clientOptions, params) @@ -199,7 +222,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -210,6 +233,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C .let { FunctionListPageAsync.builder() .service(FunctionServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -219,15 +243,19 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: FunctionDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -236,7 +264,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -250,15 +278,18 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C private val invokeHandler: Handler> = jsonHandler>(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun invoke( params: FunctionInvokeParams, requestOptions: RequestOptions, ): CompletableFuture>> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0), "invoke") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -267,7 +298,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { invokeHandler.handle(it) } .also { @@ -280,7 +311,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: FunctionReplaceParams, @@ -289,6 +320,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -297,7 +329,7 @@ class FunctionServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsync.kt index 9c172789..07a132eb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Group @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.GroupListParams import com.braintrustdata.api.models.GroupReplaceParams import com.braintrustdata.api.models.GroupRetrieveParams import com.braintrustdata.api.models.GroupUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface GroupServiceAsync { @@ -22,6 +23,13 @@ interface GroupServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): GroupServiceAsync + /** * Create a new group. If there is an existing group with the same name as the one specified in * the request, will return the existing group unmodified @@ -29,67 +37,133 @@ interface GroupServiceAsync { fun create(params: GroupCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: GroupCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a group object by its id */ - fun retrieve(params: GroupRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(groupId: String): CompletableFuture = + retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + ): CompletableFuture = retrieve(groupId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: GroupRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(groupId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** * Partially update a group object. Specify the fields to update in the payload. Any object-type * fields will be deep-merged with existing content. Currently we do not support removing fields * or setting them to null. */ - fun update(params: GroupUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(groupId: String): CompletableFuture = + update(groupId, GroupUpdateParams.none()) + + /** @see update */ + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().groupId(groupId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + ): CompletableFuture = update(groupId, params, RequestOptions.none()) + + /** @see update */ fun update( params: GroupUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: GroupUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(groupId: String, requestOptions: RequestOptions): CompletableFuture = + update(groupId, GroupUpdateParams.none(), requestOptions) + /** * List out all groups. The groups are sorted by creation date, with the most recently-created * groups coming first */ fun list(): CompletableFuture = list(GroupListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: GroupListParams = GroupListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: GroupListParams = GroupListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(GroupListParams.none(), requestOptions) /** Delete a group object by its id */ - fun delete(params: GroupDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(groupId: String): CompletableFuture = + delete(groupId, GroupDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see delete */ + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + ): CompletableFuture = delete(groupId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: GroupDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: GroupDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(groupId: String, requestOptions: RequestOptions): CompletableFuture = + delete(groupId, GroupDeleteParams.none(), requestOptions) + /** * Create or replace group. If there is an existing group with the same name as the one * specified in the request, will replace the existing group with the provided fields @@ -97,7 +171,7 @@ interface GroupServiceAsync { fun replace(params: GroupReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: GroupReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -106,16 +180,23 @@ interface GroupServiceAsync { /** A view of [GroupServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): GroupServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/group`, but is otherwise the same as * [GroupServiceAsync.create]. */ - @MustBeClosed fun create(params: GroupCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: GroupCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -125,56 +206,100 @@ interface GroupServiceAsync { * Returns a raw HTTP response for `get /v1/group/{group_id}`, but is otherwise the same as * [GroupServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: GroupRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(groupId: String): CompletableFuture> = + retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + ): CompletableFuture> = + retrieve(groupId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: GroupRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/group/{group_id}`, but is otherwise the same * as [GroupServiceAsync.update]. */ - @MustBeClosed - fun update(params: GroupUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(groupId: String): CompletableFuture> = + update(groupId, GroupUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see update */ + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + ): CompletableFuture> = + update(groupId, params, RequestOptions.none()) + + /** @see update */ fun update( params: GroupUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: GroupUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + groupId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(groupId, GroupUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/group`, but is otherwise the same as * [GroupServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(GroupListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: GroupListParams = GroupListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: GroupListParams = GroupListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -184,27 +309,49 @@ interface GroupServiceAsync { * Returns a raw HTTP response for `delete /v1/group/{group_id}`, but is otherwise the same * as [GroupServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: GroupDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(groupId: String): CompletableFuture> = + delete(groupId, GroupDeleteParams.none()) + + /** @see delete */ + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().groupId(groupId).build(), requestOptions) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + ): CompletableFuture> = + delete(groupId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: GroupDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: GroupDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + groupId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(groupId, GroupDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/group`, but is otherwise the same as * [GroupServiceAsync.replace]. */ - @MustBeClosed fun replace(params: GroupReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: GroupReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt index e434a12f..2f06ad80 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.GroupReplaceParams import com.braintrustdata.api.models.GroupRetrieveParams import com.braintrustdata.api.models.GroupUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class GroupServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : GroupServiceAsync { @@ -35,6 +38,9 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie override fun withRawResponse(): GroupServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): GroupServiceAsync = + GroupServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: GroupCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,17 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : GroupServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): GroupServiceAsync.WithRawResponse = + GroupServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: GroupCreateParams, @@ -92,6 +105,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +114,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -112,16 +126,19 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: GroupRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +146,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -141,16 +158,19 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: GroupUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +179,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +193,6 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: GroupListParams, @@ -182,6 +201,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group") .build() .prepareAsync(clientOptions, params) @@ -189,7 +209,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +220,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie .let { GroupListPageAsync.builder() .service(GroupServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -208,16 +229,19 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: GroupDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -226,7 +250,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -238,8 +262,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: GroupReplaceParams, @@ -248,6 +271,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +280,7 @@ class GroupServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsync.kt index a224dbd9..326f5c44 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Organization @@ -11,8 +12,8 @@ import com.braintrustdata.api.models.OrganizationListParams import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams import com.braintrustdata.api.services.async.organizations.MemberServiceAsync -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface OrganizationServiceAsync { @@ -21,128 +22,263 @@ interface OrganizationServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): OrganizationServiceAsync + fun members(): MemberServiceAsync /** Get an organization object by its id */ - fun retrieve(params: OrganizationRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(organizationId: String): CompletableFuture = + retrieve(organizationId, OrganizationRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + ): CompletableFuture = retrieve(organizationId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: OrganizationRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: OrganizationRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + organizationId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(organizationId, OrganizationRetrieveParams.none(), requestOptions) + /** * Partially update an organization object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: OrganizationUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(organizationId: String): CompletableFuture = + update(organizationId, OrganizationUpdateParams.none()) + + /** @see update */ + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see update */ + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + ): CompletableFuture = update(organizationId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: OrganizationUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: OrganizationUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + organizationId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(organizationId, OrganizationUpdateParams.none(), requestOptions) + /** * List out all organizations. The organizations are sorted by creation date, with the most * recently-created organizations coming first */ fun list(): CompletableFuture = list(OrganizationListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: OrganizationListParams = OrganizationListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: OrganizationListParams = OrganizationListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(OrganizationListParams.none(), requestOptions) /** Delete an organization object by its id */ - fun delete(params: OrganizationDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(organizationId: String): CompletableFuture = + delete(organizationId, OrganizationDeleteParams.none()) + + /** @see delete */ + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see delete */ + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + ): CompletableFuture = delete(organizationId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: OrganizationDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: OrganizationDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + organizationId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(organizationId, OrganizationDeleteParams.none(), requestOptions) + /** * A view of [OrganizationServiceAsync] that provides access to raw HTTP responses for each * method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): OrganizationServiceAsync.WithRawResponse + fun members(): MemberServiceAsync.WithRawResponse /** * Returns a raw HTTP response for `get /v1/organization/{organization_id}`, but is * otherwise the same as [OrganizationServiceAsync.retrieve]. */ - @MustBeClosed + fun retrieve(organizationId: String): CompletableFuture> = + retrieve(organizationId, OrganizationRetrieveParams.none()) + + /** @see retrieve */ fun retrieve( - params: OrganizationRetrieveParams + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + ): CompletableFuture> = + retrieve(organizationId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: OrganizationRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve( + params: OrganizationRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + organizationId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(organizationId, OrganizationRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/organization/{organization_id}`, but is * otherwise the same as [OrganizationServiceAsync.update]. */ - @MustBeClosed + fun update(organizationId: String): CompletableFuture> = + update(organizationId, OrganizationUpdateParams.none()) + + /** @see update */ fun update( - params: OrganizationUpdateParams - ): CompletableFuture> = update(params, RequestOptions.none()) + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().organizationId(organizationId).build(), requestOptions) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + ): CompletableFuture> = + update(organizationId, params, RequestOptions.none()) + + /** @see update */ fun update( params: OrganizationUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update( + params: OrganizationUpdateParams + ): CompletableFuture> = update(params, RequestOptions.none()) + + /** @see update */ + fun update( + organizationId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(organizationId, OrganizationUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/organization`, but is otherwise the same as * [OrganizationServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(OrganizationListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: OrganizationListParams = OrganizationListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: OrganizationListParams = OrganizationListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -152,16 +288,40 @@ interface OrganizationServiceAsync { * Returns a raw HTTP response for `delete /v1/organization/{organization_id}`, but is * otherwise the same as [OrganizationServiceAsync.delete]. */ - @MustBeClosed + fun delete(organizationId: String): CompletableFuture> = + delete(organizationId, OrganizationDeleteParams.none()) + + /** @see delete */ fun delete( - params: OrganizationDeleteParams - ): CompletableFuture> = delete(params, RequestOptions.none()) + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().organizationId(organizationId).build(), requestOptions) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + ): CompletableFuture> = + delete(organizationId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: OrganizationDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see delete */ + fun delete( + params: OrganizationDeleteParams + ): CompletableFuture> = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + organizationId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(organizationId, OrganizationDeleteParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt index 00950daa..ba60634f 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.OrganizationUpdateParams import com.braintrustdata.api.services.async.organizations.MemberServiceAsync import com.braintrustdata.api.services.async.organizations.MemberServiceAsyncImpl import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class OrganizationServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : OrganizationServiceAsync { @@ -37,6 +40,9 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption override fun withRawResponse(): OrganizationServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): OrganizationServiceAsync = + OrganizationServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun members(): MemberServiceAsync = members override fun retrieve( @@ -70,24 +76,36 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : OrganizationServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val members: MemberServiceAsync.WithRawResponse by lazy { MemberServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + override fun withOptions( + modifier: Consumer + ): OrganizationServiceAsync.WithRawResponse = + OrganizationServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + override fun members(): MemberServiceAsync.WithRawResponse = members private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: OrganizationRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("organizationId", params.organizationId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -95,7 +113,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -108,15 +126,19 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: OrganizationUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("organizationId", params.organizationId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -125,7 +147,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -139,7 +161,6 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: OrganizationListParams, @@ -148,6 +169,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization") .build() .prepareAsync(clientOptions, params) @@ -155,7 +177,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -166,6 +188,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption .let { OrganizationListPageAsync.builder() .service(OrganizationServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -175,15 +198,19 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: OrganizationDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("organizationId", params.organizationId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -192,7 +219,7 @@ class OrganizationServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsync.kt index beca7a59..cec1cff9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.ProjectScore @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.ProjectScoreListParams import com.braintrustdata.api.models.ProjectScoreReplaceParams import com.braintrustdata.api.models.ProjectScoreRetrieveParams import com.braintrustdata.api.models.ProjectScoreUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface ProjectScoreServiceAsync { @@ -22,6 +23,13 @@ interface ProjectScoreServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectScoreServiceAsync + /** * Create a new project_score. If there is an existing project_score in the project with the * same name as the one specified in the request, will return the existing project_score @@ -30,67 +38,142 @@ interface ProjectScoreServiceAsync { fun create(params: ProjectScoreCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ProjectScoreCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a project_score object by its id */ - fun retrieve(params: ProjectScoreRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(projectScoreId: String): CompletableFuture = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + ): CompletableFuture = retrieve(projectScoreId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ProjectScoreRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: ProjectScoreRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none(), requestOptions) + /** * Partially update a project_score object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ProjectScoreUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(projectScoreId: String): CompletableFuture = + update(projectScoreId, ProjectScoreUpdateParams.none()) + + /** @see update */ + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see update */ + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + ): CompletableFuture = update(projectScoreId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: ProjectScoreUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: ProjectScoreUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectScoreId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(projectScoreId, ProjectScoreUpdateParams.none(), requestOptions) + /** * List out all project_scores. The project_scores are sorted by creation date, with the most * recently-created project_scores coming first */ fun list(): CompletableFuture = list(ProjectScoreListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ProjectScoreListParams = ProjectScoreListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: ProjectScoreListParams = ProjectScoreListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(ProjectScoreListParams.none(), requestOptions) /** Delete a project_score object by its id */ - fun delete(params: ProjectScoreDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(projectScoreId: String): CompletableFuture = + delete(projectScoreId, ProjectScoreDeleteParams.none()) + + /** @see delete */ + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + ): CompletableFuture = delete(projectScoreId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: ProjectScoreDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: ProjectScoreDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectScoreId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(projectScoreId, ProjectScoreDeleteParams.none(), requestOptions) + /** * Create or replace project_score. If there is an existing project_score in the project with * the same name as the one specified in the request, will replace the existing project_score @@ -99,7 +182,7 @@ interface ProjectScoreServiceAsync { fun replace(params: ProjectScoreReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: ProjectScoreReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -111,17 +194,24 @@ interface ProjectScoreServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ProjectScoreServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/project_score`, but is otherwise the same as * [ProjectScoreServiceAsync.create]. */ - @MustBeClosed fun create( params: ProjectScoreCreateParams ): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: ProjectScoreCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -131,59 +221,103 @@ interface ProjectScoreServiceAsync { * Returns a raw HTTP response for `get /v1/project_score/{project_score_id}`, but is * otherwise the same as [ProjectScoreServiceAsync.retrieve]. */ - @MustBeClosed + fun retrieve(projectScoreId: String): CompletableFuture> = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none()) + + /** @see retrieve */ fun retrieve( - params: ProjectScoreRetrieveParams + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + ): CompletableFuture> = + retrieve(projectScoreId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: ProjectScoreRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve( + params: ProjectScoreRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/project_score/{project_score_id}`, but is * otherwise the same as [ProjectScoreServiceAsync.update]. */ - @MustBeClosed + fun update(projectScoreId: String): CompletableFuture> = + update(projectScoreId, ProjectScoreUpdateParams.none()) + + /** @see update */ fun update( - params: ProjectScoreUpdateParams - ): CompletableFuture> = update(params, RequestOptions.none()) + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + ): CompletableFuture> = + update(projectScoreId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectScoreUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update( + params: ProjectScoreUpdateParams + ): CompletableFuture> = update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectScoreId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(projectScoreId, ProjectScoreUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/project_score`, but is otherwise the same as * [ProjectScoreServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(ProjectScoreListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ProjectScoreListParams = ProjectScoreListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ProjectScoreListParams = ProjectScoreListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -193,29 +327,51 @@ interface ProjectScoreServiceAsync { * Returns a raw HTTP response for `delete /v1/project_score/{project_score_id}`, but is * otherwise the same as [ProjectScoreServiceAsync.delete]. */ - @MustBeClosed + fun delete(projectScoreId: String): CompletableFuture> = + delete(projectScoreId, ProjectScoreDeleteParams.none()) + + /** @see delete */ fun delete( - params: ProjectScoreDeleteParams - ): CompletableFuture> = delete(params, RequestOptions.none()) + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + ): CompletableFuture> = + delete(projectScoreId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectScoreDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete( + params: ProjectScoreDeleteParams + ): CompletableFuture> = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectScoreId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(projectScoreId, ProjectScoreDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/project_score`, but is otherwise the same as * [ProjectScoreServiceAsync.replace]. */ - @MustBeClosed fun replace( params: ProjectScoreReplaceParams ): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: ProjectScoreReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt index 3d22e48b..944fc4a7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.ProjectScoreReplaceParams import com.braintrustdata.api.models.ProjectScoreRetrieveParams import com.braintrustdata.api.models.ProjectScoreUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ProjectScoreServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ProjectScoreServiceAsync { @@ -35,6 +38,9 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption override fun withRawResponse(): ProjectScoreServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ProjectScoreServiceAsync = + ProjectScoreServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ProjectScoreCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,18 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectScoreServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ProjectScoreServiceAsync.WithRawResponse = + ProjectScoreServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ProjectScoreCreateParams, @@ -92,6 +106,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +115,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -113,15 +128,19 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ProjectScoreRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectScoreId", params.projectScoreId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +148,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -142,15 +161,19 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: ProjectScoreUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectScoreId", params.projectScoreId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +182,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +196,6 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ProjectScoreListParams, @@ -182,6 +204,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score") .build() .prepareAsync(clientOptions, params) @@ -189,7 +212,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +223,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption .let { ProjectScoreListPageAsync.builder() .service(ProjectScoreServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -209,15 +233,19 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: ProjectScoreDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectScoreId", params.projectScoreId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -226,7 +254,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -239,7 +267,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: ProjectScoreReplaceParams, @@ -248,6 +276,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +285,7 @@ class ProjectScoreServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsync.kt index c1c67326..ca90c67a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Project @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.ProjectListParams import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectUpdateParams import com.braintrustdata.api.services.async.projects.LogServiceAsync -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface ProjectServiceAsync { @@ -22,6 +23,13 @@ interface ProjectServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectServiceAsync + fun logs(): LogServiceAsync /** @@ -31,84 +39,157 @@ interface ProjectServiceAsync { fun create(params: ProjectCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ProjectCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a project object by its id */ - fun retrieve(params: ProjectRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(projectId: String): CompletableFuture = + retrieve(projectId, ProjectRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + ): CompletableFuture = retrieve(projectId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: ProjectRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: ProjectRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(projectId, ProjectRetrieveParams.none(), requestOptions) + /** * Partially update a project object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ProjectUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(projectId: String): CompletableFuture = + update(projectId, ProjectUpdateParams.none()) + + /** @see update */ + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + ): CompletableFuture = update(projectId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: ProjectUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(projectId: String, requestOptions: RequestOptions): CompletableFuture = + update(projectId, ProjectUpdateParams.none(), requestOptions) + /** * List out all projects. The projects are sorted by creation date, with the most * recently-created projects coming first */ fun list(): CompletableFuture = list(ProjectListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ProjectListParams = ProjectListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: ProjectListParams = ProjectListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(ProjectListParams.none(), requestOptions) /** Delete a project object by its id */ - fun delete(params: ProjectDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(projectId: String): CompletableFuture = + delete(projectId, ProjectDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + ): CompletableFuture = delete(projectId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: ProjectDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(projectId: String, requestOptions: RequestOptions): CompletableFuture = + delete(projectId, ProjectDeleteParams.none(), requestOptions) + /** * A view of [ProjectServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ProjectServiceAsync.WithRawResponse + fun logs(): LogServiceAsync.WithRawResponse /** * Returns a raw HTTP response for `post /v1/project`, but is otherwise the same as * [ProjectServiceAsync.create]. */ - @MustBeClosed fun create(params: ProjectCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: ProjectCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -118,56 +199,100 @@ interface ProjectServiceAsync { * Returns a raw HTTP response for `get /v1/project/{project_id}`, but is otherwise the same * as [ProjectServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: ProjectRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(projectId: String): CompletableFuture> = + retrieve(projectId, ProjectRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + ): CompletableFuture> = + retrieve(projectId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: ProjectRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: ProjectRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(projectId, ProjectRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/project/{project_id}`, but is otherwise the * same as [ProjectServiceAsync.update]. */ - @MustBeClosed - fun update(params: ProjectUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(projectId: String): CompletableFuture> = + update(projectId, ProjectUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + ): CompletableFuture> = + update(projectId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: ProjectUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(projectId, ProjectUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/project`, but is otherwise the same as * [ProjectServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(ProjectListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ProjectListParams = ProjectListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ProjectListParams = ProjectListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -177,15 +302,39 @@ interface ProjectServiceAsync { * Returns a raw HTTP response for `delete /v1/project/{project_id}`, but is otherwise the * same as [ProjectServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: ProjectDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(projectId: String): CompletableFuture> = + delete(projectId, ProjectDeleteParams.none()) + + /** @see delete */ + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + ): CompletableFuture> = + delete(projectId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see delete */ + fun delete(params: ProjectDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(projectId, ProjectDeleteParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt index 0953c5f2..b8ae8ac1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -26,6 +27,8 @@ import com.braintrustdata.api.models.ProjectUpdateParams import com.braintrustdata.api.services.async.projects.LogServiceAsync import com.braintrustdata.api.services.async.projects.LogServiceAsyncImpl import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ProjectServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ProjectServiceAsync { @@ -38,6 +41,9 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun withRawResponse(): ProjectServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ProjectServiceAsync = + ProjectServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun logs(): LogServiceAsync = logs override fun create( @@ -78,16 +84,23 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val logs: LogServiceAsync.WithRawResponse by lazy { LogServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + override fun withOptions( + modifier: Consumer + ): ProjectServiceAsync.WithRawResponse = + ProjectServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + override fun logs(): LogServiceAsync.WithRawResponse = logs - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: ProjectCreateParams, @@ -96,6 +109,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -104,7 +118,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -117,15 +131,19 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ProjectRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -133,7 +151,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -145,16 +163,19 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: ProjectUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -163,7 +184,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -177,7 +198,6 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ProjectListParams, @@ -186,6 +206,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project") .build() .prepareAsync(clientOptions, params) @@ -193,7 +214,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -204,6 +225,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { ProjectListPageAsync.builder() .service(ProjectServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -212,16 +234,19 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: ProjectDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -230,7 +255,7 @@ class ProjectServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsync.kt index 6d681309..2ea9f564 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.ProjectTag @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.ProjectTagListParams import com.braintrustdata.api.models.ProjectTagReplaceParams import com.braintrustdata.api.models.ProjectTagRetrieveParams import com.braintrustdata.api.models.ProjectTagUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface ProjectTagServiceAsync { @@ -22,6 +23,13 @@ interface ProjectTagServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectTagServiceAsync + /** * Create a new project_tag. If there is an existing project_tag in the project with the same * name as the one specified in the request, will return the existing project_tag unmodified @@ -29,67 +37,142 @@ interface ProjectTagServiceAsync { fun create(params: ProjectTagCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ProjectTagCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a project_tag object by its id */ - fun retrieve(params: ProjectTagRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(projectTagId: String): CompletableFuture = + retrieve(projectTagId, ProjectTagRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + ): CompletableFuture = retrieve(projectTagId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: ProjectTagRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: ProjectTagRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectTagId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(projectTagId, ProjectTagRetrieveParams.none(), requestOptions) + /** * Partially update a project_tag object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ProjectTagUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(projectTagId: String): CompletableFuture = + update(projectTagId, ProjectTagUpdateParams.none()) + + /** @see update */ + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + ): CompletableFuture = update(projectTagId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectTagUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: ProjectTagUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectTagId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(projectTagId, ProjectTagUpdateParams.none(), requestOptions) + /** * List out all project_tags. The project_tags are sorted by creation date, with the most * recently-created project_tags coming first */ fun list(): CompletableFuture = list(ProjectTagListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ProjectTagListParams = ProjectTagListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: ProjectTagListParams = ProjectTagListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(ProjectTagListParams.none(), requestOptions) /** Delete a project_tag object by its id */ - fun delete(params: ProjectTagDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(projectTagId: String): CompletableFuture = + delete(projectTagId, ProjectTagDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + ): CompletableFuture = delete(projectTagId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectTagDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: ProjectTagDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectTagId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(projectTagId, ProjectTagDeleteParams.none(), requestOptions) + /** * Create or replace project_tag. If there is an existing project_tag in the project with the * same name as the one specified in the request, will replace the existing project_tag with the @@ -98,7 +181,7 @@ interface ProjectTagServiceAsync { fun replace(params: ProjectTagReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: ProjectTagReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -110,16 +193,23 @@ interface ProjectTagServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ProjectTagServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/project_tag`, but is otherwise the same as * [ProjectTagServiceAsync.create]. */ - @MustBeClosed fun create(params: ProjectTagCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: ProjectTagCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -129,57 +219,101 @@ interface ProjectTagServiceAsync { * Returns a raw HTTP response for `get /v1/project_tag/{project_tag_id}`, but is otherwise * the same as [ProjectTagServiceAsync.retrieve]. */ - @MustBeClosed + fun retrieve(projectTagId: String): CompletableFuture> = + retrieve(projectTagId, ProjectTagRetrieveParams.none()) + + /** @see retrieve */ fun retrieve( - params: ProjectTagRetrieveParams - ): CompletableFuture> = retrieve(params, RequestOptions.none()) + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + ): CompletableFuture> = + retrieve(projectTagId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ProjectTagRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve( + params: ProjectTagRetrieveParams + ): CompletableFuture> = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + projectTagId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(projectTagId, ProjectTagRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/project_tag/{project_tag_id}`, but is * otherwise the same as [ProjectTagServiceAsync.update]. */ - @MustBeClosed - fun update(params: ProjectTagUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(projectTagId: String): CompletableFuture> = + update(projectTagId, ProjectTagUpdateParams.none()) + + /** @see update */ + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + ): CompletableFuture> = + update(projectTagId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectTagUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: ProjectTagUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + projectTagId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(projectTagId, ProjectTagUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/project_tag`, but is otherwise the same as * [ProjectTagServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(ProjectTagListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ProjectTagListParams = ProjectTagListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ProjectTagListParams = ProjectTagListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -189,28 +323,50 @@ interface ProjectTagServiceAsync { * Returns a raw HTTP response for `delete /v1/project_tag/{project_tag_id}`, but is * otherwise the same as [ProjectTagServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: ProjectTagDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(projectTagId: String): CompletableFuture> = + delete(projectTagId, ProjectTagDeleteParams.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + ): CompletableFuture> = + delete(projectTagId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectTagDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: ProjectTagDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + projectTagId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(projectTagId, ProjectTagDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/project_tag`, but is otherwise the same as * [ProjectTagServiceAsync.replace]. */ - @MustBeClosed fun replace( params: ProjectTagReplaceParams ): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: ProjectTagReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt index 193e671e..3257d2c7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.ProjectTagReplaceParams import com.braintrustdata.api.models.ProjectTagRetrieveParams import com.braintrustdata.api.models.ProjectTagUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ProjectTagServiceAsync { @@ -35,6 +38,9 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: override fun withRawResponse(): ProjectTagServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ProjectTagServiceAsync = + ProjectTagServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ProjectTagCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,18 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectTagServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ProjectTagServiceAsync.WithRawResponse = + ProjectTagServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ProjectTagCreateParams, @@ -92,6 +106,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +115,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -113,15 +128,19 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ProjectTagRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectTagId", params.projectTagId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +148,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -142,15 +161,19 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: ProjectTagUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectTagId", params.projectTagId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +182,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +196,6 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ProjectTagListParams, @@ -182,6 +204,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag") .build() .prepareAsync(clientOptions, params) @@ -189,7 +212,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +223,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: .let { ProjectTagListPageAsync.builder() .service(ProjectTagServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -209,15 +233,19 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: ProjectTagDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectTagId", params.projectTagId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -226,7 +254,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -239,7 +267,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: ProjectTagReplaceParams, @@ -248,6 +276,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +285,7 @@ class ProjectTagServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsync.kt index afb7a900..f961f5a7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Prompt @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.PromptListParams import com.braintrustdata.api.models.PromptReplaceParams import com.braintrustdata.api.models.PromptRetrieveParams import com.braintrustdata.api.models.PromptUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface PromptServiceAsync { @@ -22,6 +23,13 @@ interface PromptServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PromptServiceAsync + /** * Create a new prompt. If there is an existing prompt in the project with the same slug as the * one specified in the request, will return the existing prompt unmodified @@ -29,67 +37,133 @@ interface PromptServiceAsync { fun create(params: PromptCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: PromptCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a prompt object by its id */ - fun retrieve(params: PromptRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(promptId: String): CompletableFuture = + retrieve(promptId, PromptRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + ): CompletableFuture = retrieve(promptId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: PromptRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: PromptRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(promptId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(promptId, PromptRetrieveParams.none(), requestOptions) + /** * Partially update a prompt object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: PromptUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(promptId: String): CompletableFuture = + update(promptId, PromptUpdateParams.none()) + + /** @see update */ + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().promptId(promptId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + ): CompletableFuture = update(promptId, params, RequestOptions.none()) + + /** @see update */ fun update( params: PromptUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: PromptUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(promptId: String, requestOptions: RequestOptions): CompletableFuture = + update(promptId, PromptUpdateParams.none(), requestOptions) + /** * List out all prompts. The prompts are sorted by creation date, with the most recently-created * prompts coming first */ fun list(): CompletableFuture = list(PromptListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: PromptListParams = PromptListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: PromptListParams = PromptListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(PromptListParams.none(), requestOptions) /** Delete a prompt object by its id */ - fun delete(params: PromptDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(promptId: String): CompletableFuture = + delete(promptId, PromptDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see delete */ + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + ): CompletableFuture = delete(promptId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: PromptDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: PromptDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(promptId: String, requestOptions: RequestOptions): CompletableFuture = + delete(promptId, PromptDeleteParams.none(), requestOptions) + /** * Create or replace prompt. If there is an existing prompt in the project with the same slug as * the one specified in the request, will replace the existing prompt with the provided fields @@ -97,7 +171,7 @@ interface PromptServiceAsync { fun replace(params: PromptReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: PromptReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -108,16 +182,23 @@ interface PromptServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): PromptServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/prompt`, but is otherwise the same as * [PromptServiceAsync.create]. */ - @MustBeClosed fun create(params: PromptCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: PromptCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -127,56 +208,100 @@ interface PromptServiceAsync { * Returns a raw HTTP response for `get /v1/prompt/{prompt_id}`, but is otherwise the same * as [PromptServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: PromptRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(promptId: String): CompletableFuture> = + retrieve(promptId, PromptRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + ): CompletableFuture> = + retrieve(promptId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: PromptRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: PromptRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + promptId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(promptId, PromptRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/prompt/{prompt_id}`, but is otherwise the same * as [PromptServiceAsync.update]. */ - @MustBeClosed - fun update(params: PromptUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(promptId: String): CompletableFuture> = + update(promptId, PromptUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see update */ + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + ): CompletableFuture> = + update(promptId, params, RequestOptions.none()) + + /** @see update */ fun update( params: PromptUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: PromptUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + promptId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(promptId, PromptUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/prompt`, but is otherwise the same as * [PromptServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(PromptListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: PromptListParams = PromptListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: PromptListParams = PromptListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -186,27 +311,49 @@ interface PromptServiceAsync { * Returns a raw HTTP response for `delete /v1/prompt/{prompt_id}`, but is otherwise the * same as [PromptServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: PromptDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(promptId: String): CompletableFuture> = + delete(promptId, PromptDeleteParams.none()) + + /** @see delete */ + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().promptId(promptId).build(), requestOptions) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + ): CompletableFuture> = + delete(promptId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: PromptDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: PromptDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + promptId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(promptId, PromptDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/prompt`, but is otherwise the same as * [PromptServiceAsync.replace]. */ - @MustBeClosed fun replace(params: PromptReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: PromptReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt index 32bdece7..bff1e648 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.PromptReplaceParams import com.braintrustdata.api.models.PromptRetrieveParams import com.braintrustdata.api.models.PromptUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class PromptServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : PromptServiceAsync { @@ -35,6 +38,9 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun withRawResponse(): PromptServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): PromptServiceAsync = + PromptServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: PromptCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,17 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PromptServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): PromptServiceAsync.WithRawResponse = + PromptServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: PromptCreateParams, @@ -92,6 +105,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +114,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -112,16 +126,19 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: PromptRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("promptId", params.promptId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +146,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -141,16 +158,19 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PromptUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("promptId", params.promptId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +179,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +193,6 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: PromptListParams, @@ -182,6 +201,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt") .build() .prepareAsync(clientOptions, params) @@ -189,7 +209,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +220,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli .let { PromptListPageAsync.builder() .service(PromptServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -208,16 +229,19 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: PromptDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("promptId", params.promptId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -226,7 +250,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -238,8 +262,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: PromptReplaceParams, @@ -248,6 +271,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +280,7 @@ class PromptServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsync.kt index 988acc47..7699d12a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Role @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.RoleListParams import com.braintrustdata.api.models.RoleReplaceParams import com.braintrustdata.api.models.RoleRetrieveParams import com.braintrustdata.api.models.RoleUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface RoleServiceAsync { @@ -22,6 +23,13 @@ interface RoleServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RoleServiceAsync + /** * Create a new role. If there is an existing role with the same name as the one specified in * the request, will return the existing role unmodified @@ -29,66 +37,127 @@ interface RoleServiceAsync { fun create(params: RoleCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: RoleCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a role object by its id */ - fun retrieve(params: RoleRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(roleId: String): CompletableFuture = + retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + ): CompletableFuture = retrieve(roleId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: RoleRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(roleId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** * Partially update a role object. Specify the fields to update in the payload. Any object-type * fields will be deep-merged with existing content. Currently we do not support removing fields * or setting them to null. */ - fun update(params: RoleUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(roleId: String): CompletableFuture = update(roleId, RoleUpdateParams.none()) + + /** @see update */ + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = update(params.toBuilder().roleId(roleId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + ): CompletableFuture = update(roleId, params, RequestOptions.none()) + + /** @see update */ fun update( params: RoleUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: RoleUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(roleId: String, requestOptions: RequestOptions): CompletableFuture = + update(roleId, RoleUpdateParams.none(), requestOptions) + /** * List out all roles. The roles are sorted by creation date, with the most recently-created * roles coming first */ fun list(): CompletableFuture = list(RoleListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: RoleListParams = RoleListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list(params: RoleListParams = RoleListParams.none()): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(RoleListParams.none(), requestOptions) /** Delete a role object by its id */ - fun delete(params: RoleDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(roleId: String): CompletableFuture = delete(roleId, RoleDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = delete(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see delete */ + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + ): CompletableFuture = delete(roleId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: RoleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: RoleDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(roleId: String, requestOptions: RequestOptions): CompletableFuture = + delete(roleId, RoleDeleteParams.none(), requestOptions) + /** * Create or replace role. If there is an existing role with the same name as the one specified * in the request, will replace the existing role with the provided fields @@ -96,7 +165,7 @@ interface RoleServiceAsync { fun replace(params: RoleReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: RoleReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -105,16 +174,21 @@ interface RoleServiceAsync { /** A view of [RoleServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RoleServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/role`, but is otherwise the same as * [RoleServiceAsync.create]. */ - @MustBeClosed fun create(params: RoleCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: RoleCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -124,56 +198,99 @@ interface RoleServiceAsync { * Returns a raw HTTP response for `get /v1/role/{role_id}`, but is otherwise the same as * [RoleServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: RoleRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(roleId: String): CompletableFuture> = + retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + ): CompletableFuture> = + retrieve(roleId, params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: RoleRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/role/{role_id}`, but is otherwise the same as * [RoleServiceAsync.update]. */ - @MustBeClosed - fun update(params: RoleUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(roleId: String): CompletableFuture> = + update(roleId, RoleUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see update */ + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + ): CompletableFuture> = update(roleId, params, RequestOptions.none()) + + /** @see update */ fun update( params: RoleUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: RoleUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + roleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(roleId, RoleUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/role`, but is otherwise the same as * [RoleServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(RoleListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: RoleListParams = RoleListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: RoleListParams = RoleListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -183,27 +300,48 @@ interface RoleServiceAsync { * Returns a raw HTTP response for `delete /v1/role/{role_id}`, but is otherwise the same as * [RoleServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: RoleDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(roleId: String): CompletableFuture> = + delete(roleId, RoleDeleteParams.none()) + + /** @see delete */ + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().roleId(roleId).build(), requestOptions) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + ): CompletableFuture> = delete(roleId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: RoleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: RoleDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + roleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(roleId, RoleDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/role`, but is otherwise the same as * [RoleServiceAsync.replace]. */ - @MustBeClosed fun replace(params: RoleReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: RoleReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt index 0da885cc..304d8cb5 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.RoleReplaceParams import com.braintrustdata.api.models.RoleRetrieveParams import com.braintrustdata.api.models.RoleUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class RoleServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : RoleServiceAsync { @@ -35,6 +38,9 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun withRawResponse(): RoleServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): RoleServiceAsync = + RoleServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: RoleCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,17 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : RoleServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RoleServiceAsync.WithRawResponse = + RoleServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: RoleCreateParams, @@ -92,6 +105,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +114,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -112,16 +126,19 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: RoleRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +146,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -141,16 +158,19 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: RoleUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +179,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +193,6 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: RoleListParams, @@ -182,6 +201,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role") .build() .prepareAsync(clientOptions, params) @@ -189,7 +209,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +220,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien .let { RoleListPageAsync.builder() .service(RoleServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -208,16 +229,19 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: RoleDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -226,7 +250,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -238,8 +262,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: RoleReplaceParams, @@ -248,6 +271,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +280,7 @@ class RoleServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsync.kt index 442357ea..ffb031b8 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.SpanIFrame @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.SpanIframeListParams import com.braintrustdata.api.models.SpanIframeReplaceParams import com.braintrustdata.api.models.SpanIframeRetrieveParams import com.braintrustdata.api.models.SpanIframeUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface SpanIframeServiceAsync { @@ -22,6 +23,13 @@ interface SpanIframeServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SpanIframeServiceAsync + /** * Create a new span_iframe. If there is an existing span_iframe with the same name as the one * specified in the request, will return the existing span_iframe unmodified @@ -29,67 +37,142 @@ interface SpanIframeServiceAsync { fun create(params: SpanIframeCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: SpanIframeCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a span_iframe object by its id */ - fun retrieve(params: SpanIframeRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(spanIframeId: String): CompletableFuture = + retrieve(spanIframeId, SpanIframeRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + ): CompletableFuture = retrieve(spanIframeId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: SpanIframeRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: SpanIframeRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(spanIframeId, SpanIframeRetrieveParams.none(), requestOptions) + /** * Partially update a span_iframe object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: SpanIframeUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(spanIframeId: String): CompletableFuture = + update(spanIframeId, SpanIframeUpdateParams.none()) + + /** @see update */ + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + ): CompletableFuture = update(spanIframeId, params, RequestOptions.none()) + + /** @see update */ fun update( params: SpanIframeUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see update */ + fun update(params: SpanIframeUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + spanIframeId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(spanIframeId, SpanIframeUpdateParams.none(), requestOptions) + /** * List out all span_iframes. The span_iframes are sorted by creation date, with the most * recently-created span_iframes coming first */ fun list(): CompletableFuture = list(SpanIframeListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: SpanIframeListParams = SpanIframeListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list( params: SpanIframeListParams = SpanIframeListParams.none() ): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(SpanIframeListParams.none(), requestOptions) /** Delete a span_iframe object by its id */ - fun delete(params: SpanIframeDeleteParams): CompletableFuture = - delete(params, RequestOptions.none()) + fun delete(spanIframeId: String): CompletableFuture = + delete(spanIframeId, SpanIframeDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) + + /** @see delete */ + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + ): CompletableFuture = delete(spanIframeId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: SpanIframeDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see delete */ + fun delete(params: SpanIframeDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + spanIframeId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(spanIframeId, SpanIframeDeleteParams.none(), requestOptions) + /** * Create or replace span_iframe. If there is an existing span_iframe with the same name as the * one specified in the request, will replace the existing span_iframe with the provided fields @@ -97,7 +180,7 @@ interface SpanIframeServiceAsync { fun replace(params: SpanIframeReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: SpanIframeReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -109,16 +192,23 @@ interface SpanIframeServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SpanIframeServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/span_iframe`, but is otherwise the same as * [SpanIframeServiceAsync.create]. */ - @MustBeClosed fun create(params: SpanIframeCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: SpanIframeCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -128,57 +218,101 @@ interface SpanIframeServiceAsync { * Returns a raw HTTP response for `get /v1/span_iframe/{span_iframe_id}`, but is otherwise * the same as [SpanIframeServiceAsync.retrieve]. */ - @MustBeClosed + fun retrieve(spanIframeId: String): CompletableFuture> = + retrieve(spanIframeId, SpanIframeRetrieveParams.none()) + + /** @see retrieve */ fun retrieve( - params: SpanIframeRetrieveParams - ): CompletableFuture> = retrieve(params, RequestOptions.none()) + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + ): CompletableFuture> = + retrieve(spanIframeId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: SpanIframeRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve( + params: SpanIframeRetrieveParams + ): CompletableFuture> = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(spanIframeId, SpanIframeRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/span_iframe/{span_iframe_id}`, but is * otherwise the same as [SpanIframeServiceAsync.update]. */ - @MustBeClosed - fun update(params: SpanIframeUpdateParams): CompletableFuture> = - update(params, RequestOptions.none()) + fun update(spanIframeId: String): CompletableFuture> = + update(spanIframeId, SpanIframeUpdateParams.none()) + + /** @see update */ + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) - /** @see [update] */ - @MustBeClosed + /** @see update */ + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + ): CompletableFuture> = + update(spanIframeId, params, RequestOptions.none()) + + /** @see update */ fun update( params: SpanIframeUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see update */ + fun update(params: SpanIframeUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + spanIframeId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(spanIframeId, SpanIframeUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/span_iframe`, but is otherwise the same as * [SpanIframeServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(SpanIframeListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: SpanIframeListParams = SpanIframeListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: SpanIframeListParams = SpanIframeListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = @@ -188,28 +322,50 @@ interface SpanIframeServiceAsync { * Returns a raw HTTP response for `delete /v1/span_iframe/{span_iframe_id}`, but is * otherwise the same as [SpanIframeServiceAsync.delete]. */ - @MustBeClosed - fun delete(params: SpanIframeDeleteParams): CompletableFuture> = - delete(params, RequestOptions.none()) + fun delete(spanIframeId: String): CompletableFuture> = + delete(spanIframeId, SpanIframeDeleteParams.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) + + /** @see delete */ + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + ): CompletableFuture> = + delete(spanIframeId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: SpanIframeDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see delete */ + fun delete(params: SpanIframeDeleteParams): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete( + spanIframeId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(spanIframeId, SpanIframeDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/span_iframe`, but is otherwise the same as * [SpanIframeServiceAsync.replace]. */ - @MustBeClosed fun replace( params: SpanIframeReplaceParams ): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: SpanIframeReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt index 843f6b1e..cde9bd46 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.SpanIframeReplaceParams import com.braintrustdata.api.models.SpanIframeRetrieveParams import com.braintrustdata.api.models.SpanIframeUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : SpanIframeServiceAsync { @@ -35,6 +38,9 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: override fun withRawResponse(): SpanIframeServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): SpanIframeServiceAsync = + SpanIframeServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: SpanIframeCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,18 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SpanIframeServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): SpanIframeServiceAsync.WithRawResponse = + SpanIframeServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: SpanIframeCreateParams, @@ -92,6 +106,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +115,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -113,15 +128,19 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: SpanIframeRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("spanIframeId", params.spanIframeId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +148,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -142,15 +161,19 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: SpanIframeUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("spanIframeId", params.spanIframeId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +182,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +196,6 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: SpanIframeListParams, @@ -182,6 +204,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe") .build() .prepareAsync(clientOptions, params) @@ -189,7 +212,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +223,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: .let { SpanIframeListPageAsync.builder() .service(SpanIframeServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -209,15 +233,19 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: SpanIframeDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("spanIframeId", params.spanIframeId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() @@ -226,7 +254,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -239,7 +267,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: SpanIframeReplaceParams, @@ -248,6 +276,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +285,7 @@ class SpanIframeServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsync.kt index 5411c270..27da770d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsync.kt @@ -2,11 +2,12 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.TopLevelHelloWorldParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface TopLevelServiceAsync { @@ -15,21 +16,28 @@ interface TopLevelServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): TopLevelServiceAsync + /** Default endpoint. Simply replies with 'Hello, World!'. Authorization is not required */ fun helloWorld(): CompletableFuture = helloWorld(TopLevelHelloWorldParams.none()) - /** @see [helloWorld] */ + /** @see helloWorld */ fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [helloWorld] */ + /** @see helloWorld */ fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none() ): CompletableFuture = helloWorld(params, RequestOptions.none()) - /** @see [helloWorld] */ + /** @see helloWorld */ fun helloWorld(requestOptions: RequestOptions): CompletableFuture = helloWorld(TopLevelHelloWorldParams.none(), requestOptions) @@ -38,29 +46,34 @@ interface TopLevelServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): TopLevelServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `get /v1`, but is otherwise the same as * [TopLevelServiceAsync.helloWorld]. */ - @MustBeClosed fun helloWorld(): CompletableFuture> = helloWorld(TopLevelHelloWorldParams.none()) - /** @see [helloWorld] */ - @MustBeClosed + /** @see helloWorld */ fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [helloWorld] */ - @MustBeClosed + /** @see helloWorld */ fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none() ): CompletableFuture> = helloWorld(params, RequestOptions.none()) - /** @see [helloWorld] */ - @MustBeClosed + /** @see helloWorld */ fun helloWorld(requestOptions: RequestOptions): CompletableFuture> = helloWorld(TopLevelHelloWorldParams.none(), requestOptions) } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt index 26749e99..89144d24 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/TopLevelServiceAsyncImpl.kt @@ -3,19 +3,20 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.stringHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepareAsync import com.braintrustdata.api.models.TopLevelHelloWorldParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelServiceAsync { @@ -26,6 +27,9 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C override fun withRawResponse(): TopLevelServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): TopLevelServiceAsync = + TopLevelServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun helloWorld( params: TopLevelHelloWorldParams, requestOptions: RequestOptions, @@ -36,10 +40,17 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): TopLevelServiceAsync.WithRawResponse = + TopLevelServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val helloWorldHandler: Handler = - stringHandler().withErrorHandler(errorHandler) + private val helloWorldHandler: Handler = stringHandler() override fun helloWorld( params: TopLevelHelloWorldParams, @@ -48,6 +59,7 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1") .build() .prepareAsync(clientOptions, params) @@ -55,7 +67,9 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { response.use { helloWorldHandler.handle(it) } } + errorHandler.handle(response).parseable { + response.use { helloWorldHandler.handle(it) } + } } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsync.kt index 2bf974c5..a1609c69 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsync.kt @@ -2,14 +2,15 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.User import com.braintrustdata.api.models.UserListPageAsync import com.braintrustdata.api.models.UserListParams import com.braintrustdata.api.models.UserRetrieveParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface UserServiceAsync { @@ -18,78 +19,133 @@ interface UserServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): UserServiceAsync + /** Get a user object by its id */ - fun retrieve(params: UserRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(userId: String): CompletableFuture = + retrieve(userId, UserRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = retrieve(params.toBuilder().userId(userId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + ): CompletableFuture = retrieve(userId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see retrieve */ + fun retrieve(params: UserRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(userId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(userId, UserRetrieveParams.none(), requestOptions) + /** * List out all users. The users are sorted by creation date, with the most recently-created * users coming first */ fun list(): CompletableFuture = list(UserListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: UserListParams = UserListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [list] */ + /** @see list */ fun list(params: UserListParams = UserListParams.none()): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): CompletableFuture = list(UserListParams.none(), requestOptions) /** A view of [UserServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): UserServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `get /v1/user/{user_id}`, but is otherwise the same as * [UserServiceAsync.retrieve]. */ - @MustBeClosed - fun retrieve(params: UserRetrieveParams): CompletableFuture> = - retrieve(params, RequestOptions.none()) + fun retrieve(userId: String): CompletableFuture> = + retrieve(userId, UserRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().userId(userId).build(), requestOptions) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + ): CompletableFuture> = + retrieve(userId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see retrieve */ + fun retrieve(params: UserRetrieveParams): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(userId, UserRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/user`, but is otherwise the same as * [UserServiceAsync.list]. */ - @MustBeClosed fun list(): CompletableFuture> = list(UserListParams.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: UserListParams = UserListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: UserListParams = UserListParams.none() ): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( requestOptions: RequestOptions ): CompletableFuture> = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt index b5d79eb8..558d7631 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable @@ -20,6 +21,8 @@ import com.braintrustdata.api.models.UserListPageResponse import com.braintrustdata.api.models.UserListParams import com.braintrustdata.api.models.UserRetrieveParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class UserServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : UserServiceAsync { @@ -30,6 +33,9 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun withRawResponse(): UserServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): UserServiceAsync = + UserServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions, @@ -47,18 +53,29 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : UserServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): UserServiceAsync.WithRawResponse = + UserServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("userId", params.userId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "user", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -66,7 +83,7 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -80,7 +97,6 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: UserListParams, @@ -89,6 +105,7 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "user") .build() .prepareAsync(clientOptions, params) @@ -96,7 +113,7 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -107,6 +124,7 @@ class UserServiceAsyncImpl internal constructor(private val clientOptions: Clien .let { UserListPageAsync.builder() .service(UserServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsync.kt index f70248e9..b0a95453 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.View @@ -12,8 +13,8 @@ import com.braintrustdata.api.models.ViewListParams import com.braintrustdata.api.models.ViewReplaceParams import com.braintrustdata.api.models.ViewRetrieveParams import com.braintrustdata.api.models.ViewUpdateParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface ViewServiceAsync { @@ -22,6 +23,13 @@ interface ViewServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ViewServiceAsync + /** * Create a new view. If there is an existing view with the same name as the one specified in * the request, will return the existing view unmodified @@ -29,17 +37,28 @@ interface ViewServiceAsync { fun create(params: ViewCreateParams): CompletableFuture = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ViewCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Get a view object by its id */ + fun retrieve(viewId: String, params: ViewRetrieveParams): CompletableFuture = + retrieve(viewId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + viewId: String, + params: ViewRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = retrieve(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see retrieve */ fun retrieve(params: ViewRetrieveParams): CompletableFuture = retrieve(params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: ViewRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -50,10 +69,21 @@ interface ViewServiceAsync { * fields will be deep-merged with existing content. Currently we do not support removing fields * or setting them to null. */ + fun update(viewId: String, params: ViewUpdateParams): CompletableFuture = + update(viewId, params, RequestOptions.none()) + + /** @see update */ + fun update( + viewId: String, + params: ViewUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = update(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see update */ fun update(params: ViewUpdateParams): CompletableFuture = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: ViewUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -66,17 +96,28 @@ interface ViewServiceAsync { fun list(params: ViewListParams): CompletableFuture = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list( params: ViewListParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture /** Delete a view object by its id */ + fun delete(viewId: String, params: ViewDeleteParams): CompletableFuture = + delete(viewId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + viewId: String, + params: ViewDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = delete(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see delete */ fun delete(params: ViewDeleteParams): CompletableFuture = delete(params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: ViewDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -89,7 +130,7 @@ interface ViewServiceAsync { fun replace(params: ViewReplaceParams): CompletableFuture = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: ViewReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -98,16 +139,21 @@ interface ViewServiceAsync { /** A view of [ViewServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ViewServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/view`, but is otherwise the same as * [ViewServiceAsync.create]. */ - @MustBeClosed fun create(params: ViewCreateParams): CompletableFuture> = create(params, RequestOptions.none()) - /** @see [create] */ - @MustBeClosed + /** @see create */ fun create( params: ViewCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -117,12 +163,25 @@ interface ViewServiceAsync { * Returns a raw HTTP response for `get /v1/view/{view_id}`, but is otherwise the same as * [ViewServiceAsync.retrieve]. */ - @MustBeClosed + fun retrieve( + viewId: String, + params: ViewRetrieveParams, + ): CompletableFuture> = + retrieve(viewId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + viewId: String, + params: ViewRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see retrieve */ fun retrieve(params: ViewRetrieveParams): CompletableFuture> = retrieve(params, RequestOptions.none()) - /** @see [retrieve] */ - @MustBeClosed + /** @see retrieve */ fun retrieve( params: ViewRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -132,12 +191,24 @@ interface ViewServiceAsync { * Returns a raw HTTP response for `patch /v1/view/{view_id}`, but is otherwise the same as * [ViewServiceAsync.update]. */ - @MustBeClosed + fun update( + viewId: String, + params: ViewUpdateParams, + ): CompletableFuture> = update(viewId, params, RequestOptions.none()) + + /** @see update */ + fun update( + viewId: String, + params: ViewUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see update */ fun update(params: ViewUpdateParams): CompletableFuture> = update(params, RequestOptions.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ fun update( params: ViewUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -147,12 +218,10 @@ interface ViewServiceAsync { * Returns a raw HTTP response for `get /v1/view`, but is otherwise the same as * [ViewServiceAsync.list]. */ - @MustBeClosed fun list(params: ViewListParams): CompletableFuture> = list(params, RequestOptions.none()) - /** @see [list] */ - @MustBeClosed + /** @see list */ fun list( params: ViewListParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -162,12 +231,24 @@ interface ViewServiceAsync { * Returns a raw HTTP response for `delete /v1/view/{view_id}`, but is otherwise the same as * [ViewServiceAsync.delete]. */ - @MustBeClosed + fun delete( + viewId: String, + params: ViewDeleteParams, + ): CompletableFuture> = delete(viewId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + viewId: String, + params: ViewDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + delete(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see delete */ fun delete(params: ViewDeleteParams): CompletableFuture> = delete(params, RequestOptions.none()) - /** @see [delete] */ - @MustBeClosed + /** @see delete */ fun delete( params: ViewDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -177,12 +258,10 @@ interface ViewServiceAsync { * Returns a raw HTTP response for `put /v1/view`, but is otherwise the same as * [ViewServiceAsync.replace]. */ - @MustBeClosed fun replace(params: ViewReplaceParams): CompletableFuture> = replace(params, RequestOptions.none()) - /** @see [replace] */ - @MustBeClosed + /** @see replace */ fun replace( params: ViewReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt index 35a95111..b9e958a2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/ViewServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.ViewReplaceParams import com.braintrustdata.api.models.ViewRetrieveParams import com.braintrustdata.api.models.ViewUpdateParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ViewServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ViewServiceAsync { @@ -35,6 +38,9 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun withRawResponse(): ViewServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ViewServiceAsync = + ViewServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ViewCreateParams, requestOptions: RequestOptions, @@ -80,10 +86,17 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ViewServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ViewServiceAsync.WithRawResponse = + ViewServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: ViewCreateParams, @@ -92,6 +105,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -100,7 +114,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -112,16 +126,19 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ViewRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("viewId", params.viewId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view", params._pathParam(0)) .build() .prepareAsync(clientOptions, params) @@ -129,7 +146,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -141,16 +158,19 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: ViewUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("viewId", params.viewId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -159,7 +179,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -173,7 +193,6 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ViewListParams, @@ -182,6 +201,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view") .build() .prepareAsync(clientOptions, params) @@ -189,7 +209,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -200,6 +220,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien .let { ViewListPageAsync.builder() .service(ViewServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -208,16 +229,19 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: ViewDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("viewId", params.viewId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -226,7 +250,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -238,8 +262,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: ViewReplaceParams, @@ -248,6 +271,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -256,7 +280,7 @@ class ViewServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsync.kt index 78042415..5caf9ef7 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsync.kt @@ -2,12 +2,13 @@ package com.braintrustdata.api.services.async.organizations +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.OrganizationMemberUpdateParams import com.braintrustdata.api.models.PatchOrganizationMembersOutput -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface MemberServiceAsync { @@ -16,22 +17,29 @@ interface MemberServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): MemberServiceAsync + /** Modify organization membership */ fun update(): CompletableFuture = update(OrganizationMemberUpdateParams.none()) - /** @see [update] */ + /** @see update */ fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see [update] */ + /** @see update */ fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none() ): CompletableFuture = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update(requestOptions: RequestOptions): CompletableFuture = update(OrganizationMemberUpdateParams.none(), requestOptions) @@ -40,30 +48,35 @@ interface MemberServiceAsync { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): MemberServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `patch /v1/organization/members`, but is otherwise the * same as [MemberServiceAsync.update]. */ - @MustBeClosed fun update(): CompletableFuture> = update(OrganizationMemberUpdateParams.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see [update] */ - @MustBeClosed + /** @see update */ fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none() ): CompletableFuture> = update(params, RequestOptions.none()) - /** @see [update] */ - @MustBeClosed + /** @see update */ fun update( requestOptions: RequestOptions ): CompletableFuture> = diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt index 40d22d7b..3a0b4d49 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/organizations/MemberServiceAsyncImpl.kt @@ -3,13 +3,13 @@ package com.braintrustdata.api.services.async.organizations import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -18,6 +18,7 @@ import com.braintrustdata.api.core.prepareAsync import com.braintrustdata.api.models.OrganizationMemberUpdateParams import com.braintrustdata.api.models.PatchOrganizationMembersOutput import java.util.concurrent.CompletableFuture +import java.util.function.Consumer class MemberServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : MemberServiceAsync { @@ -28,6 +29,9 @@ class MemberServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun withRawResponse(): MemberServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): MemberServiceAsync = + MemberServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun update( params: OrganizationMemberUpdateParams, requestOptions: RequestOptions, @@ -38,11 +42,18 @@ class MemberServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MemberServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): MemberServiceAsync.WithRawResponse = + MemberServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun update( params: OrganizationMemberUpdateParams, @@ -51,6 +62,7 @@ class MemberServiceAsyncImpl internal constructor(private val clientOptions: Cli val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", "members") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -59,7 +71,7 @@ class MemberServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsync.kt index b1d19e58..1cb8326f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsync.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsync.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.async.projects +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.FeedbackResponseSchema @@ -11,8 +12,8 @@ import com.braintrustdata.api.models.ProjectLogFeedbackParams import com.braintrustdata.api.models.ProjectLogFetchParams import com.braintrustdata.api.models.ProjectLogFetchPostParams import com.braintrustdata.api.models.ProjectLogInsertParams -import com.google.errorprone.annotations.MustBeClosed import java.util.concurrent.CompletableFuture +import java.util.function.Consumer interface LogServiceAsync { @@ -21,11 +22,33 @@ interface LogServiceAsync { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): LogServiceAsync + /** Log feedback for a set of project logs events */ + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + ): CompletableFuture = + feedback(projectId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + feedback(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see feedback */ fun feedback(params: ProjectLogFeedbackParams): CompletableFuture = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -36,35 +59,101 @@ interface LogServiceAsync { * the parameters in the URL query rather than in the request body. For more complex queries, * use the `POST /btql` endpoint. */ - fun fetch(params: ProjectLogFetchParams): CompletableFuture = - fetch(params, RequestOptions.none()) + fun fetch(projectId: String): CompletableFuture = + fetch(projectId, ProjectLogFetchParams.none()) - /** @see [fetch] */ + /** @see fetch */ + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + fetch(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + ): CompletableFuture = + fetch(projectId, params, RequestOptions.none()) + + /** @see fetch */ fun fetch( params: ProjectLogFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see fetch */ + fun fetch(params: ProjectLogFetchParams): CompletableFuture = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + fetch(projectId, ProjectLogFetchParams.none(), requestOptions) + /** * Fetch the events in a project logs. Equivalent to the GET form of the same path, but with the * parameters in the request body rather than in the URL query. For more complex queries, use * the `POST /btql` endpoint. */ + fun fetchPost(projectId: String): CompletableFuture = + fetchPost(projectId, ProjectLogFetchPostParams.none()) + + /** @see fetchPost */ fun fetchPost( - params: ProjectLogFetchPostParams - ): CompletableFuture = fetchPost(params, RequestOptions.none()) + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + fetchPost(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see fetchPost */ + fun fetchPost( + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + ): CompletableFuture = + fetchPost(projectId, params, RequestOptions.none()) - /** @see [fetchPost] */ + /** @see fetchPost */ fun fetchPost( params: ProjectLogFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see fetchPost */ + fun fetchPost( + params: ProjectLogFetchPostParams + ): CompletableFuture = fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + fetchPost(projectId, ProjectLogFetchPostParams.none(), requestOptions) + /** Insert a set of events into the project logs */ + fun insert( + projectId: String, + params: ProjectLogInsertParams, + ): CompletableFuture = insert(projectId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + projectId: String, + params: ProjectLogInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + insert(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see insert */ fun insert(params: ProjectLogInsertParams): CompletableFuture = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ fun insert( params: ProjectLogInsertParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -73,18 +162,38 @@ interface LogServiceAsync { /** A view of [LogServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): LogServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/project_logs/{project_id}/feedback`, but is * otherwise the same as [LogServiceAsync.feedback]. */ - @MustBeClosed + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + ): CompletableFuture> = + feedback(projectId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + feedback(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see feedback */ fun feedback( params: ProjectLogFeedbackParams ): CompletableFuture> = feedback(params, RequestOptions.none()) - /** @see [feedback] */ - @MustBeClosed + /** @see feedback */ fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -94,48 +203,113 @@ interface LogServiceAsync { * Returns a raw HTTP response for `get /v1/project_logs/{project_id}/fetch`, but is * otherwise the same as [LogServiceAsync.fetch]. */ - @MustBeClosed fun fetch( - params: ProjectLogFetchParams + projectId: String ): CompletableFuture> = - fetch(params, RequestOptions.none()) + fetch(projectId, ProjectLogFetchParams.none()) + + /** @see fetch */ + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + fetch(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + ): CompletableFuture> = + fetch(projectId, params, RequestOptions.none()) - /** @see [fetch] */ - @MustBeClosed + /** @see fetch */ fun fetch( params: ProjectLogFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see fetch */ + fun fetch( + params: ProjectLogFetchParams + ): CompletableFuture> = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + fetch(projectId, ProjectLogFetchParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/project_logs/{project_id}/fetch`, but is * otherwise the same as [LogServiceAsync.fetchPost]. */ - @MustBeClosed fun fetchPost( - params: ProjectLogFetchPostParams + projectId: String ): CompletableFuture> = - fetchPost(params, RequestOptions.none()) + fetchPost(projectId, ProjectLogFetchPostParams.none()) - /** @see [fetchPost] */ - @MustBeClosed + /** @see fetchPost */ + fun fetchPost( + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + fetchPost(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see fetchPost */ + fun fetchPost( + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + ): CompletableFuture> = + fetchPost(projectId, params, RequestOptions.none()) + + /** @see fetchPost */ fun fetchPost( params: ProjectLogFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see fetchPost */ + fun fetchPost( + params: ProjectLogFetchPostParams + ): CompletableFuture> = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + projectId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + fetchPost(projectId, ProjectLogFetchPostParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/project_logs/{project_id}/insert`, but is * otherwise the same as [LogServiceAsync.insert]. */ - @MustBeClosed + fun insert( + projectId: String, + params: ProjectLogInsertParams, + ): CompletableFuture> = + insert(projectId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + projectId: String, + params: ProjectLogInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + insert(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see insert */ fun insert( params: ProjectLogInsertParams ): CompletableFuture> = insert(params, RequestOptions.none()) - /** @see [insert] */ - @MustBeClosed + /** @see insert */ fun insert( params: ProjectLogInsertParams, requestOptions: RequestOptions = RequestOptions.none(), diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt index 477e9056..6a10c298 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/async/projects/LogServiceAsyncImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.async.projects import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -23,6 +24,8 @@ import com.braintrustdata.api.models.ProjectLogFetchParams import com.braintrustdata.api.models.ProjectLogFetchPostParams import com.braintrustdata.api.models.ProjectLogInsertParams import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class LogServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : LogServiceAsync { @@ -33,6 +36,9 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client override fun withRawResponse(): LogServiceAsync.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): LogServiceAsync = + LogServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions, @@ -64,19 +70,30 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : LogServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): LogServiceAsync.WithRawResponse = + LogServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -85,7 +102,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { feedbackHandler.handle(it) } .also { @@ -99,15 +116,18 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: ProjectLogFetchParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .build() .prepareAsync(clientOptions, params) @@ -115,7 +135,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -129,15 +149,18 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client private val fetchPostHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchPost( params: ProjectLogFetchPostParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -146,7 +169,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchPostHandler.handle(it) } .also { @@ -160,15 +183,18 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client private val insertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun insert( params: ProjectLogInsertParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() @@ -177,7 +203,7 @@ class LogServiceAsyncImpl internal constructor(private val clientOptions: Client return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { insertHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclService.kt index c94852cc..7821eba9 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Acl @@ -14,6 +15,7 @@ import com.braintrustdata.api.models.AclListPage import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclRetrieveParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface AclService { @@ -22,60 +24,103 @@ interface AclService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AclService + /** * Create a new acl. If there is an existing acl with the same contents as the one specified in * the request, will return the existing acl unmodified */ fun create(params: AclCreateParams): Acl = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create(params: AclCreateParams, requestOptions: RequestOptions = RequestOptions.none()): Acl /** Get an acl object by its id */ - fun retrieve(params: AclRetrieveParams): Acl = retrieve(params, RequestOptions.none()) + fun retrieve(aclId: String): Acl = retrieve(aclId, AclRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Acl = retrieve(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(aclId: String, params: AclRetrieveParams = AclRetrieveParams.none()): Acl = + retrieve(aclId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: AclRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Acl + /** @see retrieve */ + fun retrieve(params: AclRetrieveParams): Acl = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(aclId: String, requestOptions: RequestOptions): Acl = + retrieve(aclId, AclRetrieveParams.none(), requestOptions) + /** * List out all acls. The acls are sorted by creation date, with the most recently-created acls * coming first */ fun list(params: AclListParams): AclListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list( params: AclListParams, requestOptions: RequestOptions = RequestOptions.none(), ): AclListPage /** Delete an acl object by its id */ - fun delete(params: AclDeleteParams): Acl = delete(params, RequestOptions.none()) + fun delete(aclId: String): Acl = delete(aclId, AclDeleteParams.none()) + + /** @see delete */ + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Acl = delete(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see delete */ + fun delete(aclId: String, params: AclDeleteParams = AclDeleteParams.none()): Acl = + delete(aclId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete(params: AclDeleteParams, requestOptions: RequestOptions = RequestOptions.none()): Acl + /** @see delete */ + fun delete(params: AclDeleteParams): Acl = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(aclId: String, requestOptions: RequestOptions): Acl = + delete(aclId, AclDeleteParams.none(), requestOptions) + /** * Batch update acls. This operation is idempotent, so adding acls which already exist will have * no effect, and removing acls which do not exist will have no effect. */ fun batchUpdate(): AclBatchUpdateResponse = batchUpdate(AclBatchUpdateParams.none()) - /** @see [batchUpdate] */ + /** @see batchUpdate */ fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): AclBatchUpdateResponse - /** @see [batchUpdate] */ + /** @see batchUpdate */ fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none() ): AclBatchUpdateResponse = batchUpdate(params, RequestOptions.none()) - /** @see [batchUpdate] */ + /** @see batchUpdate */ fun batchUpdate(requestOptions: RequestOptions): AclBatchUpdateResponse = batchUpdate(AclBatchUpdateParams.none(), requestOptions) @@ -83,7 +128,7 @@ interface AclService { fun findAndDelete(params: AclFindAndDeleteParams): Acl = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ + /** @see findAndDelete */ fun findAndDelete( params: AclFindAndDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -92,6 +137,13 @@ interface AclService { /** A view of [AclService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AclService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/acl`, but is otherwise the same as * [AclService.create]. @@ -100,7 +152,7 @@ interface AclService { fun create(params: AclCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: AclCreateParams, @@ -112,16 +164,41 @@ interface AclService { * [AclService.retrieve]. */ @MustBeClosed - fun retrieve(params: AclRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(aclId: String): HttpResponseFor = + retrieve(aclId, AclRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = retrieve(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + aclId: String, + params: AclRetrieveParams = AclRetrieveParams.none(), + ): HttpResponseFor = retrieve(aclId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: AclRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: AclRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(aclId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(aclId, AclRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/acl`, but is otherwise the same as * [AclService.list]. @@ -130,7 +207,7 @@ interface AclService { fun list(params: AclListParams): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: AclListParams, @@ -142,16 +219,40 @@ interface AclService { * [AclService.delete]. */ @MustBeClosed - fun delete(params: AclDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(aclId: String): HttpResponseFor = delete(aclId, AclDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = delete(params.toBuilder().aclId(aclId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + aclId: String, + params: AclDeleteParams = AclDeleteParams.none(), + ): HttpResponseFor = delete(aclId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: AclDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: AclDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(aclId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(aclId, AclDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/acl/batch_update`, but is otherwise the same as * [AclService.batchUpdate]. @@ -160,20 +261,20 @@ interface AclService { fun batchUpdate(): HttpResponseFor = batchUpdate(AclBatchUpdateParams.none()) - /** @see [batchUpdate] */ + /** @see batchUpdate */ @MustBeClosed fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [batchUpdate] */ + /** @see batchUpdate */ @MustBeClosed fun batchUpdate( params: AclBatchUpdateParams = AclBatchUpdateParams.none() ): HttpResponseFor = batchUpdate(params, RequestOptions.none()) - /** @see [batchUpdate] */ + /** @see batchUpdate */ @MustBeClosed fun batchUpdate(requestOptions: RequestOptions): HttpResponseFor = batchUpdate(AclBatchUpdateParams.none(), requestOptions) @@ -186,7 +287,7 @@ interface AclService { fun findAndDelete(params: AclFindAndDeleteParams): HttpResponseFor = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ + /** @see findAndDelete */ @MustBeClosed fun findAndDelete( params: AclFindAndDeleteParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt index 6511ad61..ccff6e0c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AclServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.AclListPage import com.braintrustdata.api.models.AclListPageResponse import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class AclServiceImpl internal constructor(private val clientOptions: ClientOptions) : AclService { @@ -34,6 +37,9 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio override fun withRawResponse(): AclService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): AclService = + AclServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: AclCreateParams, requestOptions: RequestOptions): Acl = // post /v1/acl withRawResponse().create(params, requestOptions).parse() @@ -67,10 +73,17 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AclService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): AclService.WithRawResponse = + AclServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: AclCreateParams, @@ -79,13 +92,14 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -96,22 +110,25 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: AclRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aclId", params.aclId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -124,7 +141,6 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: AclListParams, @@ -133,12 +149,13 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -156,23 +173,26 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: AclDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aclId", params.aclId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -185,7 +205,6 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio private val batchUpdateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun batchUpdate( params: AclBatchUpdateParams, @@ -194,13 +213,14 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl", "batch_update") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { batchUpdateHandler.handle(it) } .also { @@ -211,8 +231,7 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val findAndDeleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val findAndDeleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun findAndDelete( params: AclFindAndDeleteParams, @@ -221,13 +240,14 @@ class AclServiceImpl internal constructor(private val clientOptions: ClientOptio val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "acl") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { findAndDeleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretService.kt index 867aab8c..d514dc2f 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.AISecret @@ -14,6 +15,7 @@ import com.braintrustdata.api.models.AiSecretReplaceParams import com.braintrustdata.api.models.AiSecretRetrieveParams import com.braintrustdata.api.models.AiSecretUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface AiSecretService { @@ -22,74 +24,141 @@ interface AiSecretService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AiSecretService + /** * Create a new ai_secret. If there is an existing ai_secret with the same name as the one * specified in the request, will return the existing ai_secret unmodified */ fun create(params: AiSecretCreateParams): AISecret = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: AiSecretCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): AISecret /** Get an ai_secret object by its id */ - fun retrieve(params: AiSecretRetrieveParams): AISecret = retrieve(params, RequestOptions.none()) + fun retrieve(aiSecretId: String): AISecret = retrieve(aiSecretId, AiSecretRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AISecret = retrieve(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + ): AISecret = retrieve(aiSecretId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: AiSecretRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): AISecret + /** @see retrieve */ + fun retrieve(params: AiSecretRetrieveParams): AISecret = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(aiSecretId: String, requestOptions: RequestOptions): AISecret = + retrieve(aiSecretId, AiSecretRetrieveParams.none(), requestOptions) + /** * Partially update an ai_secret object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: AiSecretUpdateParams): AISecret = update(params, RequestOptions.none()) + fun update(aiSecretId: String): AISecret = update(aiSecretId, AiSecretUpdateParams.none()) + + /** @see update */ + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AISecret = update(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see update */ + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + ): AISecret = update(aiSecretId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: AiSecretUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): AISecret + /** @see update */ + fun update(params: AiSecretUpdateParams): AISecret = update(params, RequestOptions.none()) + + /** @see update */ + fun update(aiSecretId: String, requestOptions: RequestOptions): AISecret = + update(aiSecretId, AiSecretUpdateParams.none(), requestOptions) + /** * List out all ai_secrets. The ai_secrets are sorted by creation date, with the most * recently-created ai_secrets coming first */ fun list(): AiSecretListPage = list(AiSecretListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: AiSecretListParams = AiSecretListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): AiSecretListPage - /** @see [list] */ + /** @see list */ fun list(params: AiSecretListParams = AiSecretListParams.none()): AiSecretListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): AiSecretListPage = list(AiSecretListParams.none(), requestOptions) /** Delete an ai_secret object by its id */ - fun delete(params: AiSecretDeleteParams): AISecret = delete(params, RequestOptions.none()) + fun delete(aiSecretId: String): AISecret = delete(aiSecretId, AiSecretDeleteParams.none()) + + /** @see delete */ + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AISecret = delete(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + ): AISecret = delete(aiSecretId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: AiSecretDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): AISecret + /** @see delete */ + fun delete(params: AiSecretDeleteParams): AISecret = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(aiSecretId: String, requestOptions: RequestOptions): AISecret = + delete(aiSecretId, AiSecretDeleteParams.none(), requestOptions) + /** Delete a single ai_secret */ fun findAndDelete(params: AiSecretFindAndDeleteParams): AISecret = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ + /** @see findAndDelete */ fun findAndDelete( params: AiSecretFindAndDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -101,7 +170,7 @@ interface AiSecretService { */ fun replace(params: AiSecretReplaceParams): AISecret = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: AiSecretReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -110,6 +179,13 @@ interface AiSecretService { /** A view of [AiSecretService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AiSecretService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/ai_secret`, but is otherwise the same as * [AiSecretService.create]. @@ -118,7 +194,7 @@ interface AiSecretService { fun create(params: AiSecretCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: AiSecretCreateParams, @@ -130,31 +206,86 @@ interface AiSecretService { * same as [AiSecretService.retrieve]. */ @MustBeClosed - fun retrieve(params: AiSecretRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(aiSecretId: String): HttpResponseFor = + retrieve(aiSecretId, AiSecretRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + aiSecretId: String, + params: AiSecretRetrieveParams = AiSecretRetrieveParams.none(), + ): HttpResponseFor = retrieve(aiSecretId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: AiSecretRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: AiSecretRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + aiSecretId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(aiSecretId, AiSecretRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/ai_secret/{ai_secret_id}`, but is otherwise * the same as [AiSecretService.update]. */ @MustBeClosed - fun update(params: AiSecretUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(aiSecretId: String): HttpResponseFor = + update(aiSecretId, AiSecretUpdateParams.none()) + + /** @see update */ + @MustBeClosed + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + aiSecretId: String, + params: AiSecretUpdateParams = AiSecretUpdateParams.none(), + ): HttpResponseFor = update(aiSecretId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: AiSecretUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: AiSecretUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(aiSecretId: String, requestOptions: RequestOptions): HttpResponseFor = + update(aiSecretId, AiSecretUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/ai_secret`, but is otherwise the same as * [AiSecretService.list]. @@ -162,20 +293,20 @@ interface AiSecretService { @MustBeClosed fun list(): HttpResponseFor = list(AiSecretListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: AiSecretListParams = AiSecretListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: AiSecretListParams = AiSecretListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(AiSecretListParams.none(), requestOptions) @@ -185,16 +316,42 @@ interface AiSecretService { * the same as [AiSecretService.delete]. */ @MustBeClosed - fun delete(params: AiSecretDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(aiSecretId: String): HttpResponseFor = + delete(aiSecretId, AiSecretDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().aiSecretId(aiSecretId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + aiSecretId: String, + params: AiSecretDeleteParams = AiSecretDeleteParams.none(), + ): HttpResponseFor = delete(aiSecretId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: AiSecretDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: AiSecretDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(aiSecretId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(aiSecretId, AiSecretDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `delete /v1/ai_secret`, but is otherwise the same as * [AiSecretService.findAndDelete]. @@ -203,7 +360,7 @@ interface AiSecretService { fun findAndDelete(params: AiSecretFindAndDeleteParams): HttpResponseFor = findAndDelete(params, RequestOptions.none()) - /** @see [findAndDelete] */ + /** @see findAndDelete */ @MustBeClosed fun findAndDelete( params: AiSecretFindAndDeleteParams, @@ -218,7 +375,7 @@ interface AiSecretService { fun replace(params: AiSecretReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: AiSecretReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt index e5da7242..d93a7fcd 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.AiSecretListParams import com.braintrustdata.api.models.AiSecretReplaceParams import com.braintrustdata.api.models.AiSecretRetrieveParams import com.braintrustdata.api.models.AiSecretUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class AiSecretServiceImpl internal constructor(private val clientOptions: ClientOptions) : AiSecretService { @@ -35,6 +38,9 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client override fun withRawResponse(): AiSecretService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): AiSecretService = + AiSecretServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: AiSecretCreateParams, requestOptions: RequestOptions): AISecret = // post /v1/ai_secret withRawResponse().create(params, requestOptions).parse() @@ -75,10 +81,18 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AiSecretService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): AiSecretService.WithRawResponse = + AiSecretServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: AiSecretCreateParams, @@ -87,13 +101,14 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -105,21 +120,25 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: AiSecretRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aiSecretId", params.aiSecretId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -131,22 +150,26 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: AiSecretUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aiSecretId", params.aiSecretId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -159,7 +182,6 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: AiSecretListParams, @@ -168,12 +190,13 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -192,22 +215,26 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: AiSecretDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("aiSecretId", params.aiSecretId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -219,7 +246,7 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client } private val findAndDeleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun findAndDelete( params: AiSecretFindAndDeleteParams, @@ -228,13 +255,14 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { findAndDeleteHandler.handle(it) } .also { @@ -246,7 +274,7 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: AiSecretReplaceParams, @@ -255,13 +283,14 @@ class AiSecretServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "ai_secret") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyService.kt index 7f07d4a8..7955b47d 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.ApiKey @@ -12,6 +13,7 @@ import com.braintrustdata.api.models.ApiKeyListParams import com.braintrustdata.api.models.ApiKeyRetrieveParams import com.braintrustdata.api.models.CreateApiKeyOutput import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface ApiKeyService { @@ -20,6 +22,13 @@ interface ApiKeyService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ApiKeyService + /** * Create a new api_key. It is possible to have multiple API keys with the same name. There is * no de-duplication @@ -27,53 +36,98 @@ interface ApiKeyService { fun create(params: ApiKeyCreateParams): CreateApiKeyOutput = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ApiKeyCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CreateApiKeyOutput /** Get an api_key object by its id */ - fun retrieve(params: ApiKeyRetrieveParams): ApiKey = retrieve(params, RequestOptions.none()) + fun retrieve(apiKeyId: String): ApiKey = retrieve(apiKeyId, ApiKeyRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ApiKey = retrieve(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + ): ApiKey = retrieve(apiKeyId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ApiKeyRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): ApiKey + /** @see retrieve */ + fun retrieve(params: ApiKeyRetrieveParams): ApiKey = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(apiKeyId: String, requestOptions: RequestOptions): ApiKey = + retrieve(apiKeyId, ApiKeyRetrieveParams.none(), requestOptions) + /** * List out all api_keys. The api_keys are sorted by creation date, with the most * recently-created api_keys coming first */ fun list(): ApiKeyListPage = list(ApiKeyListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ApiKeyListParams = ApiKeyListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ApiKeyListPage - /** @see [list] */ + /** @see list */ fun list(params: ApiKeyListParams = ApiKeyListParams.none()): ApiKeyListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): ApiKeyListPage = list(ApiKeyListParams.none(), requestOptions) /** Delete an api_key object by its id */ - fun delete(params: ApiKeyDeleteParams): ApiKey = delete(params, RequestOptions.none()) + fun delete(apiKeyId: String): ApiKey = delete(apiKeyId, ApiKeyDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ApiKey = delete(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) + + /** @see delete */ + fun delete(apiKeyId: String, params: ApiKeyDeleteParams = ApiKeyDeleteParams.none()): ApiKey = + delete(apiKeyId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ApiKeyDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): ApiKey + /** @see delete */ + fun delete(params: ApiKeyDeleteParams): ApiKey = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(apiKeyId: String, requestOptions: RequestOptions): ApiKey = + delete(apiKeyId, ApiKeyDeleteParams.none(), requestOptions) + /** A view of [ApiKeyService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ApiKeyService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/api_key`, but is otherwise the same as * [ApiKeyService.create]. @@ -82,7 +136,7 @@ interface ApiKeyService { fun create(params: ApiKeyCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: ApiKeyCreateParams, @@ -94,36 +148,62 @@ interface ApiKeyService { * as [ApiKeyService.retrieve]. */ @MustBeClosed - fun retrieve(params: ApiKeyRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(apiKeyId: String): HttpResponseFor = + retrieve(apiKeyId, ApiKeyRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + apiKeyId: String, + params: ApiKeyRetrieveParams = ApiKeyRetrieveParams.none(), + ): HttpResponseFor = retrieve(apiKeyId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: ApiKeyRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ApiKeyRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(apiKeyId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(apiKeyId, ApiKeyRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/api_key`, but is otherwise the same as * [ApiKeyService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(ApiKeyListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ApiKeyListParams = ApiKeyListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ApiKeyListParams = ApiKeyListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(ApiKeyListParams.none(), requestOptions) @@ -133,14 +213,40 @@ interface ApiKeyService { * same as [ApiKeyService.delete]. */ @MustBeClosed - fun delete(params: ApiKeyDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(apiKeyId: String): HttpResponseFor = + delete(apiKeyId, ApiKeyDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().apiKeyId(apiKeyId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + apiKeyId: String, + params: ApiKeyDeleteParams = ApiKeyDeleteParams.none(), + ): HttpResponseFor = delete(apiKeyId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: ApiKeyDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see delete */ + @MustBeClosed + fun delete(params: ApiKeyDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(apiKeyId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(apiKeyId, ApiKeyDeleteParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt index dd948b0d..9f803003 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -23,6 +24,8 @@ import com.braintrustdata.api.models.ApiKeyListPageResponse import com.braintrustdata.api.models.ApiKeyListParams import com.braintrustdata.api.models.ApiKeyRetrieveParams import com.braintrustdata.api.models.CreateApiKeyOutput +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOptions) : ApiKeyService { @@ -33,6 +36,9 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp override fun withRawResponse(): ApiKeyService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ApiKeyService = + ApiKeyServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ApiKeyCreateParams, requestOptions: RequestOptions, @@ -55,10 +61,18 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ApiKeyService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ApiKeyService.WithRawResponse = + ApiKeyServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ApiKeyCreateParams, @@ -67,13 +81,14 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -84,22 +99,25 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ApiKeyRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("apiKeyId", params.apiKeyId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -112,7 +130,6 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ApiKeyListParams, @@ -121,12 +138,13 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -144,23 +162,26 @@ class ApiKeyServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: ApiKeyDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("apiKeyId", params.apiKeyId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "api_key", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetService.kt index 91a18478..0caaa200 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Dataset @@ -21,6 +22,7 @@ import com.braintrustdata.api.models.FetchDatasetEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeDatasetResponse import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface DatasetService { @@ -29,74 +31,153 @@ interface DatasetService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DatasetService + /** * Create a new dataset. If there is an existing dataset in the project with the same name as * the one specified in the request, will return the existing dataset unmodified */ fun create(params: DatasetCreateParams): Dataset = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: DatasetCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Dataset /** Get a dataset object by its id */ - fun retrieve(params: DatasetRetrieveParams): Dataset = retrieve(params, RequestOptions.none()) + fun retrieve(datasetId: String): Dataset = retrieve(datasetId, DatasetRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Dataset = retrieve(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + ): Dataset = retrieve(datasetId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: DatasetRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Dataset + /** @see retrieve */ + fun retrieve(params: DatasetRetrieveParams): Dataset = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(datasetId: String, requestOptions: RequestOptions): Dataset = + retrieve(datasetId, DatasetRetrieveParams.none(), requestOptions) + /** * Partially update a dataset object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: DatasetUpdateParams): Dataset = update(params, RequestOptions.none()) + fun update(datasetId: String): Dataset = update(datasetId, DatasetUpdateParams.none()) + + /** @see update */ + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Dataset = update(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see update */ + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + ): Dataset = update(datasetId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: DatasetUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Dataset + /** @see update */ + fun update(params: DatasetUpdateParams): Dataset = update(params, RequestOptions.none()) + + /** @see update */ + fun update(datasetId: String, requestOptions: RequestOptions): Dataset = + update(datasetId, DatasetUpdateParams.none(), requestOptions) + /** * List out all datasets. The datasets are sorted by creation date, with the most * recently-created datasets coming first */ fun list(): DatasetListPage = list(DatasetListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: DatasetListParams = DatasetListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): DatasetListPage - /** @see [list] */ + /** @see list */ fun list(params: DatasetListParams = DatasetListParams.none()): DatasetListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): DatasetListPage = list(DatasetListParams.none(), requestOptions) /** Delete a dataset object by its id */ - fun delete(params: DatasetDeleteParams): Dataset = delete(params, RequestOptions.none()) + fun delete(datasetId: String): Dataset = delete(datasetId, DatasetDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Dataset = delete(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see delete */ + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + ): Dataset = delete(datasetId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: DatasetDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Dataset + /** @see delete */ + fun delete(params: DatasetDeleteParams): Dataset = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(datasetId: String, requestOptions: RequestOptions): Dataset = + delete(datasetId, DatasetDeleteParams.none(), requestOptions) + /** Log feedback for a set of dataset events */ + fun feedback(datasetId: String, params: DatasetFeedbackParams): FeedbackResponseSchema = + feedback(datasetId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): FeedbackResponseSchema = + feedback(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see feedback */ fun feedback(params: DatasetFeedbackParams): FeedbackResponseSchema = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ fun feedback( params: DatasetFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -107,52 +188,137 @@ interface DatasetService { * parameters in the URL query rather than in the request body. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetch(params: DatasetFetchParams): FetchDatasetEventsResponse = - fetch(params, RequestOptions.none()) + fun fetch(datasetId: String): FetchDatasetEventsResponse = + fetch(datasetId, DatasetFetchParams.none()) + + /** @see fetch */ + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): FetchDatasetEventsResponse = + fetch(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + ): FetchDatasetEventsResponse = fetch(datasetId, params, RequestOptions.none()) - /** @see [fetch] */ + /** @see fetch */ fun fetch( params: DatasetFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): FetchDatasetEventsResponse + /** @see fetch */ + fun fetch(params: DatasetFetchParams): FetchDatasetEventsResponse = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch(datasetId: String, requestOptions: RequestOptions): FetchDatasetEventsResponse = + fetch(datasetId, DatasetFetchParams.none(), requestOptions) + /** * Fetch the events in a dataset. Equivalent to the GET form of the same path, but with the * parameters in the request body rather than in the URL query. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetchPost(params: DatasetFetchPostParams): FetchDatasetEventsResponse = - fetchPost(params, RequestOptions.none()) + fun fetchPost(datasetId: String): FetchDatasetEventsResponse = + fetchPost(datasetId, DatasetFetchPostParams.none()) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): FetchDatasetEventsResponse = + fetchPost(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see fetchPost */ + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + ): FetchDatasetEventsResponse = fetchPost(datasetId, params, RequestOptions.none()) - /** @see [fetchPost] */ + /** @see fetchPost */ fun fetchPost( params: DatasetFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): FetchDatasetEventsResponse + /** @see fetchPost */ + fun fetchPost(params: DatasetFetchPostParams): FetchDatasetEventsResponse = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost(datasetId: String, requestOptions: RequestOptions): FetchDatasetEventsResponse = + fetchPost(datasetId, DatasetFetchPostParams.none(), requestOptions) + /** Insert a set of events into the dataset */ + fun insert(datasetId: String, params: DatasetInsertParams): InsertEventsResponse = + insert(datasetId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + datasetId: String, + params: DatasetInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): InsertEventsResponse = + insert(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see insert */ fun insert(params: DatasetInsertParams): InsertEventsResponse = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ fun insert( params: DatasetInsertParams, requestOptions: RequestOptions = RequestOptions.none(), ): InsertEventsResponse /** Summarize dataset */ - fun summarize(params: DatasetSummarizeParams): SummarizeDatasetResponse = - summarize(params, RequestOptions.none()) + fun summarize(datasetId: String): SummarizeDatasetResponse = + summarize(datasetId, DatasetSummarizeParams.none()) + + /** @see summarize */ + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SummarizeDatasetResponse = + summarize(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see summarize */ + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + ): SummarizeDatasetResponse = summarize(datasetId, params, RequestOptions.none()) - /** @see [summarize] */ + /** @see summarize */ fun summarize( params: DatasetSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): SummarizeDatasetResponse + /** @see summarize */ + fun summarize(params: DatasetSummarizeParams): SummarizeDatasetResponse = + summarize(params, RequestOptions.none()) + + /** @see summarize */ + fun summarize(datasetId: String, requestOptions: RequestOptions): SummarizeDatasetResponse = + summarize(datasetId, DatasetSummarizeParams.none(), requestOptions) + /** A view of [DatasetService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): DatasetService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/dataset`, but is otherwise the same as * [DatasetService.create]. @@ -161,7 +327,7 @@ interface DatasetService { fun create(params: DatasetCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: DatasetCreateParams, @@ -173,51 +339,103 @@ interface DatasetService { * as [DatasetService.retrieve]. */ @MustBeClosed - fun retrieve(params: DatasetRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(datasetId: String): HttpResponseFor = + retrieve(datasetId, DatasetRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + datasetId: String, + params: DatasetRetrieveParams = DatasetRetrieveParams.none(), + ): HttpResponseFor = retrieve(datasetId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: DatasetRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: DatasetRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(datasetId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(datasetId, DatasetRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/dataset/{dataset_id}`, but is otherwise the * same as [DatasetService.update]. */ @MustBeClosed - fun update(params: DatasetUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(datasetId: String): HttpResponseFor = + update(datasetId, DatasetUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + datasetId: String, + params: DatasetUpdateParams = DatasetUpdateParams.none(), + ): HttpResponseFor = update(datasetId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: DatasetUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: DatasetUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(datasetId: String, requestOptions: RequestOptions): HttpResponseFor = + update(datasetId, DatasetUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/dataset`, but is otherwise the same as * [DatasetService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(DatasetListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: DatasetListParams = DatasetListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: DatasetListParams = DatasetListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(DatasetListParams.none(), requestOptions) @@ -227,25 +445,68 @@ interface DatasetService { * same as [DatasetService.delete]. */ @MustBeClosed - fun delete(params: DatasetDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(datasetId: String): HttpResponseFor = + delete(datasetId, DatasetDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + datasetId: String, + params: DatasetDeleteParams = DatasetDeleteParams.none(), + ): HttpResponseFor = delete(datasetId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: DatasetDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: DatasetDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(datasetId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(datasetId, DatasetDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/dataset/{dataset_id}/feedback`, but is * otherwise the same as [DatasetService.feedback]. */ @MustBeClosed + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + ): HttpResponseFor = + feedback(datasetId, params, RequestOptions.none()) + + /** @see feedback */ + @MustBeClosed + fun feedback( + datasetId: String, + params: DatasetFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + feedback(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see feedback */ + @MustBeClosed fun feedback(params: DatasetFeedbackParams): HttpResponseFor = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ @MustBeClosed fun feedback( params: DatasetFeedbackParams, @@ -257,40 +518,116 @@ interface DatasetService { * the same as [DatasetService.fetch]. */ @MustBeClosed - fun fetch(params: DatasetFetchParams): HttpResponseFor = - fetch(params, RequestOptions.none()) + fun fetch(datasetId: String): HttpResponseFor = + fetch(datasetId, DatasetFetchParams.none()) + + /** @see fetch */ + @MustBeClosed + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + fetch(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [fetch] */ + /** @see fetch */ + @MustBeClosed + fun fetch( + datasetId: String, + params: DatasetFetchParams = DatasetFetchParams.none(), + ): HttpResponseFor = + fetch(datasetId, params, RequestOptions.none()) + + /** @see fetch */ @MustBeClosed fun fetch( params: DatasetFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see fetch */ + @MustBeClosed + fun fetch(params: DatasetFetchParams): HttpResponseFor = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + @MustBeClosed + fun fetch( + datasetId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + fetch(datasetId, DatasetFetchParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/dataset/{dataset_id}/fetch`, but is otherwise * the same as [DatasetService.fetchPost]. */ @MustBeClosed - fun fetchPost(params: DatasetFetchPostParams): HttpResponseFor = - fetchPost(params, RequestOptions.none()) + fun fetchPost(datasetId: String): HttpResponseFor = + fetchPost(datasetId, DatasetFetchPostParams.none()) + + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + fetchPost(params.toBuilder().datasetId(datasetId).build(), requestOptions) - /** @see [fetchPost] */ + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + datasetId: String, + params: DatasetFetchPostParams = DatasetFetchPostParams.none(), + ): HttpResponseFor = + fetchPost(datasetId, params, RequestOptions.none()) + + /** @see fetchPost */ @MustBeClosed fun fetchPost( params: DatasetFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see fetchPost */ + @MustBeClosed + fun fetchPost(params: DatasetFetchPostParams): HttpResponseFor = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + datasetId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + fetchPost(datasetId, DatasetFetchPostParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/dataset/{dataset_id}/insert`, but is otherwise * the same as [DatasetService.insert]. */ @MustBeClosed + fun insert( + datasetId: String, + params: DatasetInsertParams, + ): HttpResponseFor = insert(datasetId, params, RequestOptions.none()) + + /** @see insert */ + @MustBeClosed + fun insert( + datasetId: String, + params: DatasetInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + insert(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see insert */ + @MustBeClosed fun insert(params: DatasetInsertParams): HttpResponseFor = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ @MustBeClosed fun insert( params: DatasetInsertParams, @@ -302,14 +639,44 @@ interface DatasetService { * otherwise the same as [DatasetService.summarize]. */ @MustBeClosed - fun summarize(params: DatasetSummarizeParams): HttpResponseFor = - summarize(params, RequestOptions.none()) + fun summarize(datasetId: String): HttpResponseFor = + summarize(datasetId, DatasetSummarizeParams.none()) - /** @see [summarize] */ + /** @see summarize */ + @MustBeClosed + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + summarize(params.toBuilder().datasetId(datasetId).build(), requestOptions) + + /** @see summarize */ + @MustBeClosed + fun summarize( + datasetId: String, + params: DatasetSummarizeParams = DatasetSummarizeParams.none(), + ): HttpResponseFor = + summarize(datasetId, params, RequestOptions.none()) + + /** @see summarize */ @MustBeClosed fun summarize( params: DatasetSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see summarize */ + @MustBeClosed + fun summarize(params: DatasetSummarizeParams): HttpResponseFor = + summarize(params, RequestOptions.none()) + + /** @see summarize */ + @MustBeClosed + fun summarize( + datasetId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + summarize(datasetId, DatasetSummarizeParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt index 39a0a0e3..e1691602 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -32,6 +33,8 @@ import com.braintrustdata.api.models.FeedbackResponseSchema import com.braintrustdata.api.models.FetchDatasetEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeDatasetResponse +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class DatasetServiceImpl internal constructor(private val clientOptions: ClientOptions) : DatasetService { @@ -42,6 +45,9 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO override fun withRawResponse(): DatasetService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): DatasetService = + DatasetServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: DatasetCreateParams, requestOptions: RequestOptions): Dataset = // post /v1/dataset withRawResponse().create(params, requestOptions).parse() @@ -100,10 +106,17 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : DatasetService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): DatasetService.WithRawResponse = + DatasetServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: DatasetCreateParams, @@ -112,13 +125,14 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -130,21 +144,25 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: DatasetRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -155,23 +173,26 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: DatasetUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -184,7 +205,6 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: DatasetListParams, @@ -193,12 +213,13 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -216,23 +237,26 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: DatasetDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -245,22 +269,25 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun feedback( params: DatasetFeedbackParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { feedbackHandler.handle(it) } .also { @@ -273,21 +300,24 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: DatasetFetchParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -300,22 +330,25 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO private val fetchPostHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchPost( params: DatasetFetchPostParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchPostHandler.handle(it) } .also { @@ -328,22 +361,25 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO private val insertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun insert( params: DatasetInsertParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { insertHandler.handle(it) } .also { @@ -356,21 +392,24 @@ class DatasetServiceImpl internal constructor(private val clientOptions: ClientO private val summarizeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun summarize( params: DatasetSummarizeParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("datasetId", params.datasetId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "dataset", params._pathParam(0), "summarize") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { summarizeHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarService.kt index 843a4762..89e7ecbe 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.EnvVar @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.EnvVarReplaceParams import com.braintrustdata.api.models.EnvVarRetrieveParams import com.braintrustdata.api.models.EnvVarUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface EnvVarService { @@ -21,35 +23,73 @@ interface EnvVarService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EnvVarService + /** * Create a new env_var. If there is an existing env_var with the same name as the one specified * in the request, will return the existing env_var unmodified */ fun create(params: EnvVarCreateParams): EnvVar = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: EnvVarCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): EnvVar /** Get an env_var object by its id */ - fun retrieve(params: EnvVarRetrieveParams): EnvVar = retrieve(params, RequestOptions.none()) + fun retrieve(envVarId: String): EnvVar = retrieve(envVarId, EnvVarRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): EnvVar = retrieve(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + ): EnvVar = retrieve(envVarId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: EnvVarRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): EnvVar + /** @see retrieve */ + fun retrieve(params: EnvVarRetrieveParams): EnvVar = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(envVarId: String, requestOptions: RequestOptions): EnvVar = + retrieve(envVarId, EnvVarRetrieveParams.none(), requestOptions) + /** * Partially update an env_var object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ + fun update(envVarId: String, params: EnvVarUpdateParams): EnvVar = + update(envVarId, params, RequestOptions.none()) + + /** @see update */ + fun update( + envVarId: String, + params: EnvVarUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): EnvVar = update(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see update */ fun update(params: EnvVarUpdateParams): EnvVar = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: EnvVarUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -61,36 +101,54 @@ interface EnvVarService { */ fun list(): EnvVarListResponse = list(EnvVarListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: EnvVarListParams = EnvVarListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): EnvVarListResponse - /** @see [list] */ + /** @see list */ fun list(params: EnvVarListParams = EnvVarListParams.none()): EnvVarListResponse = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): EnvVarListResponse = list(EnvVarListParams.none(), requestOptions) /** Delete an env_var object by its id */ - fun delete(params: EnvVarDeleteParams): EnvVar = delete(params, RequestOptions.none()) + fun delete(envVarId: String): EnvVar = delete(envVarId, EnvVarDeleteParams.none()) + + /** @see delete */ + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): EnvVar = delete(params.toBuilder().envVarId(envVarId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete(envVarId: String, params: EnvVarDeleteParams = EnvVarDeleteParams.none()): EnvVar = + delete(envVarId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: EnvVarDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): EnvVar + /** @see delete */ + fun delete(params: EnvVarDeleteParams): EnvVar = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(envVarId: String, requestOptions: RequestOptions): EnvVar = + delete(envVarId, EnvVarDeleteParams.none(), requestOptions) + /** * Create or replace env_var. If there is an existing env_var with the same name as the one * specified in the request, will replace the existing env_var with the provided fields */ fun replace(params: EnvVarReplaceParams): EnvVar = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: EnvVarReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -99,6 +157,13 @@ interface EnvVarService { /** A view of [EnvVarService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EnvVarService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/env_var`, but is otherwise the same as * [EnvVarService.create]. @@ -107,7 +172,7 @@ interface EnvVarService { fun create(params: EnvVarCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: EnvVarCreateParams, @@ -119,25 +184,65 @@ interface EnvVarService { * as [EnvVarService.retrieve]. */ @MustBeClosed - fun retrieve(params: EnvVarRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(envVarId: String): HttpResponseFor = + retrieve(envVarId, EnvVarRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + envVarId: String, + params: EnvVarRetrieveParams = EnvVarRetrieveParams.none(), + ): HttpResponseFor = retrieve(envVarId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: EnvVarRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: EnvVarRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(envVarId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(envVarId, EnvVarRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/env_var/{env_var_id}`, but is otherwise the * same as [EnvVarService.update]. */ @MustBeClosed + fun update(envVarId: String, params: EnvVarUpdateParams): HttpResponseFor = + update(envVarId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + envVarId: String, + params: EnvVarUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see update */ + @MustBeClosed fun update(params: EnvVarUpdateParams): HttpResponseFor = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ @MustBeClosed fun update( params: EnvVarUpdateParams, @@ -151,20 +256,20 @@ interface EnvVarService { @MustBeClosed fun list(): HttpResponseFor = list(EnvVarListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: EnvVarListParams = EnvVarListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: EnvVarListParams = EnvVarListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(EnvVarListParams.none(), requestOptions) @@ -174,16 +279,42 @@ interface EnvVarService { * same as [EnvVarService.delete]. */ @MustBeClosed - fun delete(params: EnvVarDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(envVarId: String): HttpResponseFor = + delete(envVarId, EnvVarDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().envVarId(envVarId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + envVarId: String, + params: EnvVarDeleteParams = EnvVarDeleteParams.none(), + ): HttpResponseFor = delete(envVarId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ @MustBeClosed fun delete( params: EnvVarDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: EnvVarDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(envVarId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(envVarId, EnvVarDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/env_var`, but is otherwise the same as * [EnvVarService.replace]. @@ -192,7 +323,7 @@ interface EnvVarService { fun replace(params: EnvVarReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: EnvVarReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt index 042d24b9..87948806 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -23,6 +24,8 @@ import com.braintrustdata.api.models.EnvVarListResponse import com.braintrustdata.api.models.EnvVarReplaceParams import com.braintrustdata.api.models.EnvVarRetrieveParams import com.braintrustdata.api.models.EnvVarUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOptions) : EnvVarService { @@ -33,6 +36,9 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp override fun withRawResponse(): EnvVarService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): EnvVarService = + EnvVarServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: EnvVarCreateParams, requestOptions: RequestOptions): EnvVar = // post /v1/env_var withRawResponse().create(params, requestOptions).parse() @@ -63,10 +69,17 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EnvVarService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): EnvVarService.WithRawResponse = + EnvVarServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: EnvVarCreateParams, @@ -75,13 +88,14 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -92,22 +106,25 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: EnvVarRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("envVarId", params.envVarId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -118,23 +135,26 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: EnvVarUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("envVarId", params.envVarId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -146,7 +166,7 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp } private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: EnvVarListParams, @@ -155,12 +175,13 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -171,23 +192,26 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: EnvVarDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("envVarId", params.envVarId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -198,8 +222,7 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: EnvVarReplaceParams, @@ -208,13 +231,14 @@ class EnvVarServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "env_var") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalService.kt index fa1bcc99..3b96070c 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalService.kt @@ -2,11 +2,13 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.EvalCreateParams import com.braintrustdata.api.models.SummarizeExperimentResponse import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface EvalService { @@ -15,6 +17,13 @@ interface EvalService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EvalService + /** * Launch an evaluation. This is the API-equivalent of the `Eval` function that is built into * the Braintrust SDK. In the Eval API, you provide pointers to a dataset, task function, and @@ -25,7 +34,7 @@ interface EvalService { fun create(params: EvalCreateParams): SummarizeExperimentResponse = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: EvalCreateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -34,6 +43,13 @@ interface EvalService { /** A view of [EvalService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): EvalService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/eval`, but is otherwise the same as * [EvalService.create]. @@ -42,7 +58,7 @@ interface EvalService { fun create(params: EvalCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: EvalCreateParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt index c590863e..6fe04f25 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/EvalServiceImpl.kt @@ -3,13 +3,13 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -17,6 +17,7 @@ import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare import com.braintrustdata.api.models.EvalCreateParams import com.braintrustdata.api.models.SummarizeExperimentResponse +import java.util.function.Consumer class EvalServiceImpl internal constructor(private val clientOptions: ClientOptions) : EvalService { @@ -26,6 +27,9 @@ class EvalServiceImpl internal constructor(private val clientOptions: ClientOpti override fun withRawResponse(): EvalService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): EvalService = + EvalServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: EvalCreateParams, requestOptions: RequestOptions, @@ -36,11 +40,18 @@ class EvalServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EvalService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): EvalService.WithRawResponse = + EvalServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: EvalCreateParams, @@ -49,13 +60,14 @@ class EvalServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "eval") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentService.kt index 17bc351f..a71044d7 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Experiment @@ -21,6 +22,7 @@ import com.braintrustdata.api.models.FetchExperimentEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeExperimentResponse import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface ExperimentService { @@ -29,75 +31,157 @@ interface ExperimentService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ExperimentService + /** * Create a new experiment. If there is an existing experiment in the project with the same name * as the one specified in the request, will return the existing experiment unmodified */ fun create(params: ExperimentCreateParams): Experiment = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ExperimentCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Experiment /** Get an experiment object by its id */ - fun retrieve(params: ExperimentRetrieveParams): Experiment = - retrieve(params, RequestOptions.none()) + fun retrieve(experimentId: String): Experiment = + retrieve(experimentId, ExperimentRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Experiment = retrieve(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + ): Experiment = retrieve(experimentId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ExperimentRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Experiment + /** @see retrieve */ + fun retrieve(params: ExperimentRetrieveParams): Experiment = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(experimentId: String, requestOptions: RequestOptions): Experiment = + retrieve(experimentId, ExperimentRetrieveParams.none(), requestOptions) + /** * Partially update an experiment object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ExperimentUpdateParams): Experiment = update(params, RequestOptions.none()) + fun update(experimentId: String): Experiment = + update(experimentId, ExperimentUpdateParams.none()) + + /** @see update */ + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Experiment = update(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see update */ + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + ): Experiment = update(experimentId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: ExperimentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Experiment + /** @see update */ + fun update(params: ExperimentUpdateParams): Experiment = update(params, RequestOptions.none()) + + /** @see update */ + fun update(experimentId: String, requestOptions: RequestOptions): Experiment = + update(experimentId, ExperimentUpdateParams.none(), requestOptions) + /** * List out all experiments. The experiments are sorted by creation date, with the most * recently-created experiments coming first */ fun list(): ExperimentListPage = list(ExperimentListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ExperimentListParams = ExperimentListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ExperimentListPage - /** @see [list] */ + /** @see list */ fun list(params: ExperimentListParams = ExperimentListParams.none()): ExperimentListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): ExperimentListPage = list(ExperimentListParams.none(), requestOptions) /** Delete an experiment object by its id */ - fun delete(params: ExperimentDeleteParams): Experiment = delete(params, RequestOptions.none()) + fun delete(experimentId: String): Experiment = + delete(experimentId, ExperimentDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Experiment = delete(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see delete */ + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + ): Experiment = delete(experimentId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ExperimentDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Experiment + /** @see delete */ + fun delete(params: ExperimentDeleteParams): Experiment = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(experimentId: String, requestOptions: RequestOptions): Experiment = + delete(experimentId, ExperimentDeleteParams.none(), requestOptions) + /** Log feedback for a set of experiment events */ + fun feedback(experimentId: String, params: ExperimentFeedbackParams): FeedbackResponseSchema = + feedback(experimentId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): FeedbackResponseSchema = + feedback(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see feedback */ fun feedback(params: ExperimentFeedbackParams): FeedbackResponseSchema = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ fun feedback( params: ExperimentFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -108,52 +192,145 @@ interface ExperimentService { * parameters in the URL query rather than in the request body. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetch(params: ExperimentFetchParams): FetchExperimentEventsResponse = - fetch(params, RequestOptions.none()) + fun fetch(experimentId: String): FetchExperimentEventsResponse = + fetch(experimentId, ExperimentFetchParams.none()) + + /** @see fetch */ + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): FetchExperimentEventsResponse = + fetch(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + ): FetchExperimentEventsResponse = fetch(experimentId, params, RequestOptions.none()) - /** @see [fetch] */ + /** @see fetch */ fun fetch( params: ExperimentFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): FetchExperimentEventsResponse + /** @see fetch */ + fun fetch(params: ExperimentFetchParams): FetchExperimentEventsResponse = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch(experimentId: String, requestOptions: RequestOptions): FetchExperimentEventsResponse = + fetch(experimentId, ExperimentFetchParams.none(), requestOptions) + /** * Fetch the events in an experiment. Equivalent to the GET form of the same path, but with the * parameters in the request body rather than in the URL query. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetchPost(params: ExperimentFetchPostParams): FetchExperimentEventsResponse = - fetchPost(params, RequestOptions.none()) + fun fetchPost(experimentId: String): FetchExperimentEventsResponse = + fetchPost(experimentId, ExperimentFetchPostParams.none()) + + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): FetchExperimentEventsResponse = + fetchPost(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + ): FetchExperimentEventsResponse = fetchPost(experimentId, params, RequestOptions.none()) - /** @see [fetchPost] */ + /** @see fetchPost */ fun fetchPost( params: ExperimentFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): FetchExperimentEventsResponse + /** @see fetchPost */ + fun fetchPost(params: ExperimentFetchPostParams): FetchExperimentEventsResponse = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + experimentId: String, + requestOptions: RequestOptions, + ): FetchExperimentEventsResponse = + fetchPost(experimentId, ExperimentFetchPostParams.none(), requestOptions) + /** Insert a set of events into the experiment */ + fun insert(experimentId: String, params: ExperimentInsertParams): InsertEventsResponse = + insert(experimentId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + experimentId: String, + params: ExperimentInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): InsertEventsResponse = + insert(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see insert */ fun insert(params: ExperimentInsertParams): InsertEventsResponse = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ fun insert( params: ExperimentInsertParams, requestOptions: RequestOptions = RequestOptions.none(), ): InsertEventsResponse /** Summarize experiment */ - fun summarize(params: ExperimentSummarizeParams): SummarizeExperimentResponse = - summarize(params, RequestOptions.none()) + fun summarize(experimentId: String): SummarizeExperimentResponse = + summarize(experimentId, ExperimentSummarizeParams.none()) - /** @see [summarize] */ + /** @see summarize */ + fun summarize( + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SummarizeExperimentResponse = + summarize(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see summarize */ + fun summarize( + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + ): SummarizeExperimentResponse = summarize(experimentId, params, RequestOptions.none()) + + /** @see summarize */ fun summarize( params: ExperimentSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): SummarizeExperimentResponse + /** @see summarize */ + fun summarize(params: ExperimentSummarizeParams): SummarizeExperimentResponse = + summarize(params, RequestOptions.none()) + + /** @see summarize */ + fun summarize( + experimentId: String, + requestOptions: RequestOptions, + ): SummarizeExperimentResponse = + summarize(experimentId, ExperimentSummarizeParams.none(), requestOptions) + /** A view of [ExperimentService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ExperimentService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/experiment`, but is otherwise the same as * [ExperimentService.create]. @@ -162,7 +339,7 @@ interface ExperimentService { fun create(params: ExperimentCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: ExperimentCreateParams, @@ -174,31 +351,89 @@ interface ExperimentService { * the same as [ExperimentService.retrieve]. */ @MustBeClosed - fun retrieve(params: ExperimentRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(experimentId: String): HttpResponseFor = + retrieve(experimentId, ExperimentRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + experimentId: String, + params: ExperimentRetrieveParams = ExperimentRetrieveParams.none(), + ): HttpResponseFor = retrieve(experimentId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ @MustBeClosed fun retrieve( params: ExperimentRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ExperimentRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + experimentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(experimentId, ExperimentRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/experiment/{experiment_id}`, but is otherwise * the same as [ExperimentService.update]. */ @MustBeClosed - fun update(params: ExperimentUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(experimentId: String): HttpResponseFor = + update(experimentId, ExperimentUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + experimentId: String, + params: ExperimentUpdateParams = ExperimentUpdateParams.none(), + ): HttpResponseFor = update(experimentId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: ExperimentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: ExperimentUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + experimentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(experimentId, ExperimentUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/experiment`, but is otherwise the same as * [ExperimentService.list]. @@ -206,20 +441,20 @@ interface ExperimentService { @MustBeClosed fun list(): HttpResponseFor = list(ExperimentListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ExperimentListParams = ExperimentListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ExperimentListParams = ExperimentListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(ExperimentListParams.none(), requestOptions) @@ -229,25 +464,71 @@ interface ExperimentService { * the same as [ExperimentService.delete]. */ @MustBeClosed - fun delete(params: ExperimentDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(experimentId: String): HttpResponseFor = + delete(experimentId, ExperimentDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + experimentId: String, + params: ExperimentDeleteParams = ExperimentDeleteParams.none(), + ): HttpResponseFor = delete(experimentId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ @MustBeClosed fun delete( params: ExperimentDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: ExperimentDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + experimentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(experimentId, ExperimentDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/experiment/{experiment_id}/feedback`, but is * otherwise the same as [ExperimentService.feedback]. */ @MustBeClosed + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + ): HttpResponseFor = + feedback(experimentId, params, RequestOptions.none()) + + /** @see feedback */ + @MustBeClosed + fun feedback( + experimentId: String, + params: ExperimentFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + feedback(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see feedback */ + @MustBeClosed fun feedback(params: ExperimentFeedbackParams): HttpResponseFor = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ @MustBeClosed fun feedback( params: ExperimentFeedbackParams, @@ -259,41 +540,118 @@ interface ExperimentService { * otherwise the same as [ExperimentService.fetch]. */ @MustBeClosed - fun fetch(params: ExperimentFetchParams): HttpResponseFor = - fetch(params, RequestOptions.none()) + fun fetch(experimentId: String): HttpResponseFor = + fetch(experimentId, ExperimentFetchParams.none()) + + /** @see fetch */ + @MustBeClosed + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + fetch(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see fetch */ + @MustBeClosed + fun fetch( + experimentId: String, + params: ExperimentFetchParams = ExperimentFetchParams.none(), + ): HttpResponseFor = + fetch(experimentId, params, RequestOptions.none()) - /** @see [fetch] */ + /** @see fetch */ @MustBeClosed fun fetch( params: ExperimentFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see fetch */ + @MustBeClosed + fun fetch(params: ExperimentFetchParams): HttpResponseFor = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + @MustBeClosed + fun fetch( + experimentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + fetch(experimentId, ExperimentFetchParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/experiment/{experiment_id}/fetch`, but is * otherwise the same as [ExperimentService.fetchPost]. */ @MustBeClosed + fun fetchPost(experimentId: String): HttpResponseFor = + fetchPost(experimentId, ExperimentFetchPostParams.none()) + + /** @see fetchPost */ + @MustBeClosed fun fetchPost( - params: ExperimentFetchPostParams - ): HttpResponseFor = fetchPost(params, RequestOptions.none()) + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + fetchPost(params.toBuilder().experimentId(experimentId).build(), requestOptions) - /** @see [fetchPost] */ + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + experimentId: String, + params: ExperimentFetchPostParams = ExperimentFetchPostParams.none(), + ): HttpResponseFor = + fetchPost(experimentId, params, RequestOptions.none()) + + /** @see fetchPost */ @MustBeClosed fun fetchPost( params: ExperimentFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + params: ExperimentFetchPostParams + ): HttpResponseFor = fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + experimentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + fetchPost(experimentId, ExperimentFetchPostParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/experiment/{experiment_id}/insert`, but is * otherwise the same as [ExperimentService.insert]. */ @MustBeClosed + fun insert( + experimentId: String, + params: ExperimentInsertParams, + ): HttpResponseFor = + insert(experimentId, params, RequestOptions.none()) + + /** @see insert */ + @MustBeClosed + fun insert( + experimentId: String, + params: ExperimentInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + insert(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see insert */ + @MustBeClosed fun insert(params: ExperimentInsertParams): HttpResponseFor = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ @MustBeClosed fun insert( params: ExperimentInsertParams, @@ -305,15 +663,45 @@ interface ExperimentService { * otherwise the same as [ExperimentService.summarize]. */ @MustBeClosed + fun summarize(experimentId: String): HttpResponseFor = + summarize(experimentId, ExperimentSummarizeParams.none()) + + /** @see summarize */ + @MustBeClosed fun summarize( - params: ExperimentSummarizeParams - ): HttpResponseFor = summarize(params, RequestOptions.none()) + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + summarize(params.toBuilder().experimentId(experimentId).build(), requestOptions) + + /** @see summarize */ + @MustBeClosed + fun summarize( + experimentId: String, + params: ExperimentSummarizeParams = ExperimentSummarizeParams.none(), + ): HttpResponseFor = + summarize(experimentId, params, RequestOptions.none()) - /** @see [summarize] */ + /** @see summarize */ @MustBeClosed fun summarize( params: ExperimentSummarizeParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see summarize */ + @MustBeClosed + fun summarize( + params: ExperimentSummarizeParams + ): HttpResponseFor = summarize(params, RequestOptions.none()) + + /** @see summarize */ + @MustBeClosed + fun summarize( + experimentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + summarize(experimentId, ExperimentSummarizeParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt index f7d1da12..81a4d350 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -32,6 +33,8 @@ import com.braintrustdata.api.models.FeedbackResponseSchema import com.braintrustdata.api.models.FetchExperimentEventsResponse import com.braintrustdata.api.models.InsertEventsResponse import com.braintrustdata.api.models.SummarizeExperimentResponse +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ExperimentServiceImpl internal constructor(private val clientOptions: ClientOptions) : ExperimentService { @@ -42,6 +45,9 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie override fun withRawResponse(): ExperimentService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ExperimentService = + ExperimentServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ExperimentCreateParams, requestOptions: RequestOptions, @@ -115,10 +121,18 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExperimentService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ExperimentService.WithRawResponse = + ExperimentServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ExperimentCreateParams, @@ -127,13 +141,14 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -145,21 +160,25 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ExperimentRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -171,22 +190,26 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: ExperimentUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -199,7 +222,6 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ExperimentListParams, @@ -208,12 +230,13 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -232,22 +255,26 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: ExperimentDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -260,22 +287,25 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun feedback( params: ExperimentFeedbackParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { feedbackHandler.handle(it) } .also { @@ -288,21 +318,24 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: ExperimentFetchParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -315,22 +348,25 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie private val fetchPostHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchPost( params: ExperimentFetchPostParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchPostHandler.handle(it) } .also { @@ -343,22 +379,25 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie private val insertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun insert( params: ExperimentInsertParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { insertHandler.handle(it) } .also { @@ -371,21 +410,24 @@ class ExperimentServiceImpl internal constructor(private val clientOptions: Clie private val summarizeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun summarize( params: ExperimentSummarizeParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("experimentId", params.experimentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "experiment", params._pathParam(0), "summarize") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { summarizeHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionService.kt index 2002b104..21f834fe 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Function @@ -16,6 +17,7 @@ import com.braintrustdata.api.models.FunctionRetrieveParams import com.braintrustdata.api.models.FunctionUpdateParams import com.google.errorprone.annotations.MustBeClosed import java.util.Optional +import java.util.function.Consumer interface FunctionService { @@ -24,79 +26,171 @@ interface FunctionService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): FunctionService + /** * Create a new function. If there is an existing function in the project with the same slug as * the one specified in the request, will return the existing function unmodified */ fun create(params: FunctionCreateParams): Function = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: FunctionCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Function /** Get a function object by its id */ - fun retrieve(params: FunctionRetrieveParams): Function = retrieve(params, RequestOptions.none()) + fun retrieve(functionId: String): Function = retrieve(functionId, FunctionRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Function = retrieve(params.toBuilder().functionId(functionId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + ): Function = retrieve(functionId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: FunctionRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Function + /** @see retrieve */ + fun retrieve(params: FunctionRetrieveParams): Function = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(functionId: String, requestOptions: RequestOptions): Function = + retrieve(functionId, FunctionRetrieveParams.none(), requestOptions) + /** * Partially update a function object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: FunctionUpdateParams): Function = update(params, RequestOptions.none()) + fun update(functionId: String): Function = update(functionId, FunctionUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Function = update(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see update */ + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + ): Function = update(functionId, params, RequestOptions.none()) + + /** @see update */ fun update( params: FunctionUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Function + /** @see update */ + fun update(params: FunctionUpdateParams): Function = update(params, RequestOptions.none()) + + /** @see update */ + fun update(functionId: String, requestOptions: RequestOptions): Function = + update(functionId, FunctionUpdateParams.none(), requestOptions) + /** * List out all functions. The functions are sorted by creation date, with the most * recently-created functions coming first */ fun list(): FunctionListPage = list(FunctionListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: FunctionListParams = FunctionListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): FunctionListPage - /** @see [list] */ + /** @see list */ fun list(params: FunctionListParams = FunctionListParams.none()): FunctionListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): FunctionListPage = list(FunctionListParams.none(), requestOptions) /** Delete a function object by its id */ - fun delete(params: FunctionDeleteParams): Function = delete(params, RequestOptions.none()) + fun delete(functionId: String): Function = delete(functionId, FunctionDeleteParams.none()) + + /** @see delete */ + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Function = delete(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see delete */ + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + ): Function = delete(functionId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: FunctionDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Function + /** @see delete */ + fun delete(params: FunctionDeleteParams): Function = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(functionId: String, requestOptions: RequestOptions): Function = + delete(functionId, FunctionDeleteParams.none(), requestOptions) + /** Invoke a function. */ - fun invoke(params: FunctionInvokeParams): Optional = - invoke(params, RequestOptions.none()) + fun invoke(functionId: String): Optional = + invoke(functionId, FunctionInvokeParams.none()) + + /** @see invoke */ + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Optional = + invoke(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see invoke */ + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + ): Optional = invoke(functionId, params, RequestOptions.none()) - /** @see [invoke] */ + /** @see invoke */ fun invoke( params: FunctionInvokeParams, requestOptions: RequestOptions = RequestOptions.none(), ): Optional + /** @see invoke */ + fun invoke(params: FunctionInvokeParams): Optional = + invoke(params, RequestOptions.none()) + + /** @see invoke */ + fun invoke( + functionId: String, + requestOptions: RequestOptions, + ): Optional = + invoke(functionId, FunctionInvokeParams.none(), requestOptions) + /** * Create or replace function. If there is an existing function in the project with the same * slug as the one specified in the request, will replace the existing function with the @@ -104,7 +198,7 @@ interface FunctionService { */ fun replace(params: FunctionReplaceParams): Function = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: FunctionReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -113,6 +207,13 @@ interface FunctionService { /** A view of [FunctionService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): FunctionService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/function`, but is otherwise the same as * [FunctionService.create]. @@ -121,7 +222,7 @@ interface FunctionService { fun create(params: FunctionCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: FunctionCreateParams, @@ -133,31 +234,86 @@ interface FunctionService { * same as [FunctionService.retrieve]. */ @MustBeClosed - fun retrieve(params: FunctionRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(functionId: String): HttpResponseFor = + retrieve(functionId, FunctionRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + functionId: String, + params: FunctionRetrieveParams = FunctionRetrieveParams.none(), + ): HttpResponseFor = retrieve(functionId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ @MustBeClosed fun retrieve( params: FunctionRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: FunctionRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + functionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(functionId, FunctionRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/function/{function_id}`, but is otherwise the * same as [FunctionService.update]. */ @MustBeClosed - fun update(params: FunctionUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(functionId: String): HttpResponseFor = + update(functionId, FunctionUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + functionId: String, + params: FunctionUpdateParams = FunctionUpdateParams.none(), + ): HttpResponseFor = update(functionId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: FunctionUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: FunctionUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(functionId: String, requestOptions: RequestOptions): HttpResponseFor = + update(functionId, FunctionUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/function`, but is otherwise the same as * [FunctionService.list]. @@ -165,20 +321,20 @@ interface FunctionService { @MustBeClosed fun list(): HttpResponseFor = list(FunctionListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: FunctionListParams = FunctionListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: FunctionListParams = FunctionListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(FunctionListParams.none(), requestOptions) @@ -188,32 +344,88 @@ interface FunctionService { * same as [FunctionService.delete]. */ @MustBeClosed - fun delete(params: FunctionDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(functionId: String): HttpResponseFor = + delete(functionId, FunctionDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().functionId(functionId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed + fun delete( + functionId: String, + params: FunctionDeleteParams = FunctionDeleteParams.none(), + ): HttpResponseFor = delete(functionId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: FunctionDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: FunctionDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(functionId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(functionId, FunctionDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/function/{function_id}/invoke`, but is * otherwise the same as [FunctionService.invoke]. */ @MustBeClosed + fun invoke(functionId: String): HttpResponseFor> = + invoke(functionId, FunctionInvokeParams.none()) + + /** @see invoke */ + @MustBeClosed fun invoke( - params: FunctionInvokeParams - ): HttpResponseFor> = invoke(params, RequestOptions.none()) + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor> = + invoke(params.toBuilder().functionId(functionId).build(), requestOptions) - /** @see [invoke] */ + /** @see invoke */ + @MustBeClosed + fun invoke( + functionId: String, + params: FunctionInvokeParams = FunctionInvokeParams.none(), + ): HttpResponseFor> = + invoke(functionId, params, RequestOptions.none()) + + /** @see invoke */ @MustBeClosed fun invoke( params: FunctionInvokeParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor> + /** @see invoke */ + @MustBeClosed + fun invoke( + params: FunctionInvokeParams + ): HttpResponseFor> = invoke(params, RequestOptions.none()) + + /** @see invoke */ + @MustBeClosed + fun invoke( + functionId: String, + requestOptions: RequestOptions, + ): HttpResponseFor> = + invoke(functionId, FunctionInvokeParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/function`, but is otherwise the same as * [FunctionService.replace]. @@ -222,7 +434,7 @@ interface FunctionService { fun replace(params: FunctionReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: FunctionReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt index 9658b5bc..85edcaca 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -27,6 +28,8 @@ import com.braintrustdata.api.models.FunctionReplaceParams import com.braintrustdata.api.models.FunctionRetrieveParams import com.braintrustdata.api.models.FunctionUpdateParams import java.util.Optional +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class FunctionServiceImpl internal constructor(private val clientOptions: ClientOptions) : FunctionService { @@ -37,6 +40,9 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client override fun withRawResponse(): FunctionService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): FunctionService = + FunctionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: FunctionCreateParams, requestOptions: RequestOptions): Function = // post /v1/function withRawResponse().create(params, requestOptions).parse() @@ -77,10 +83,18 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : FunctionService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): FunctionService.WithRawResponse = + FunctionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: FunctionCreateParams, @@ -89,13 +103,14 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -107,21 +122,25 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: FunctionRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -133,22 +152,26 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: FunctionUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -161,7 +184,6 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: FunctionListParams, @@ -170,12 +192,13 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -194,22 +217,26 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: FunctionDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -222,22 +249,25 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client private val invokeHandler: Handler> = jsonHandler>(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun invoke( params: FunctionInvokeParams, requestOptions: RequestOptions, ): HttpResponseFor> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("functionId", params.functionId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function", params._pathParam(0), "invoke") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { invokeHandler.handle(it) } .also { @@ -249,7 +279,7 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: FunctionReplaceParams, @@ -258,13 +288,14 @@ class FunctionServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "function") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupService.kt index 5249cbc6..f045afc6 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Group @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.GroupReplaceParams import com.braintrustdata.api.models.GroupRetrieveParams import com.braintrustdata.api.models.GroupUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface GroupService { @@ -21,76 +23,137 @@ interface GroupService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): GroupService + /** * Create a new group. If there is an existing group with the same name as the one specified in * the request, will return the existing group unmodified */ fun create(params: GroupCreateParams): Group = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: GroupCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Group /** Get a group object by its id */ - fun retrieve(params: GroupRetrieveParams): Group = retrieve(params, RequestOptions.none()) + fun retrieve(groupId: String): Group = retrieve(groupId, GroupRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Group = retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(groupId: String, params: GroupRetrieveParams = GroupRetrieveParams.none()): Group = + retrieve(groupId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: GroupRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Group + /** @see retrieve */ + fun retrieve(params: GroupRetrieveParams): Group = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(groupId: String, requestOptions: RequestOptions): Group = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** * Partially update a group object. Specify the fields to update in the payload. Any object-type * fields will be deep-merged with existing content. Currently we do not support removing fields * or setting them to null. */ - fun update(params: GroupUpdateParams): Group = update(params, RequestOptions.none()) + fun update(groupId: String): Group = update(groupId, GroupUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Group = update(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see update */ + fun update(groupId: String, params: GroupUpdateParams = GroupUpdateParams.none()): Group = + update(groupId, params, RequestOptions.none()) + + /** @see update */ fun update( params: GroupUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Group + /** @see update */ + fun update(params: GroupUpdateParams): Group = update(params, RequestOptions.none()) + + /** @see update */ + fun update(groupId: String, requestOptions: RequestOptions): Group = + update(groupId, GroupUpdateParams.none(), requestOptions) + /** * List out all groups. The groups are sorted by creation date, with the most recently-created * groups coming first */ fun list(): GroupListPage = list(GroupListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: GroupListParams = GroupListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): GroupListPage - /** @see [list] */ + /** @see list */ fun list(params: GroupListParams = GroupListParams.none()): GroupListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): GroupListPage = list(GroupListParams.none(), requestOptions) /** Delete a group object by its id */ - fun delete(params: GroupDeleteParams): Group = delete(params, RequestOptions.none()) + fun delete(groupId: String): Group = delete(groupId, GroupDeleteParams.none()) + + /** @see delete */ + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Group = delete(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see delete */ + fun delete(groupId: String, params: GroupDeleteParams = GroupDeleteParams.none()): Group = + delete(groupId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: GroupDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Group + /** @see delete */ + fun delete(params: GroupDeleteParams): Group = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(groupId: String, requestOptions: RequestOptions): Group = + delete(groupId, GroupDeleteParams.none(), requestOptions) + /** * Create or replace group. If there is an existing group with the same name as the one * specified in the request, will replace the existing group with the provided fields */ fun replace(params: GroupReplaceParams): Group = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: GroupReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -99,6 +162,13 @@ interface GroupService { /** A view of [GroupService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): GroupService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/group`, but is otherwise the same as * [GroupService.create]. @@ -107,7 +177,7 @@ interface GroupService { fun create(params: GroupCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: GroupCreateParams, @@ -119,50 +189,102 @@ interface GroupService { * [GroupService.retrieve]. */ @MustBeClosed - fun retrieve(params: GroupRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(groupId: String): HttpResponseFor = + retrieve(groupId, GroupRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + groupId: String, + params: GroupRetrieveParams = GroupRetrieveParams.none(), + ): HttpResponseFor = retrieve(groupId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: GroupRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: GroupRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(groupId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(groupId, GroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/group/{group_id}`, but is otherwise the same * as [GroupService.update]. */ @MustBeClosed - fun update(params: GroupUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(groupId: String): HttpResponseFor = + update(groupId, GroupUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().groupId(groupId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + groupId: String, + params: GroupUpdateParams = GroupUpdateParams.none(), + ): HttpResponseFor = update(groupId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: GroupUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: GroupUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(groupId: String, requestOptions: RequestOptions): HttpResponseFor = + update(groupId, GroupUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/group`, but is otherwise the same as * [GroupService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(GroupListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: GroupListParams = GroupListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(params: GroupListParams = GroupListParams.none()): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(GroupListParams.none(), requestOptions) @@ -172,16 +294,42 @@ interface GroupService { * as [GroupService.delete]. */ @MustBeClosed - fun delete(params: GroupDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(groupId: String): HttpResponseFor = + delete(groupId, GroupDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().groupId(groupId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + groupId: String, + params: GroupDeleteParams = GroupDeleteParams.none(), + ): HttpResponseFor = delete(groupId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: GroupDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: GroupDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(groupId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(groupId, GroupDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/group`, but is otherwise the same as * [GroupService.replace]. @@ -190,7 +338,7 @@ interface GroupService { fun replace(params: GroupReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: GroupReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt index 30e51563..074c5d95 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/GroupServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.GroupListParams import com.braintrustdata.api.models.GroupReplaceParams import com.braintrustdata.api.models.GroupRetrieveParams import com.braintrustdata.api.models.GroupUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class GroupServiceImpl internal constructor(private val clientOptions: ClientOptions) : GroupService { @@ -34,6 +37,9 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt override fun withRawResponse(): GroupService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): GroupService = + GroupServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: GroupCreateParams, requestOptions: RequestOptions): Group = // post /v1/group withRawResponse().create(params, requestOptions).parse() @@ -61,10 +67,17 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : GroupService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): GroupService.WithRawResponse = + GroupServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: GroupCreateParams, @@ -73,13 +86,14 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -90,22 +104,25 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: GroupRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -116,23 +133,26 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: GroupUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -145,7 +165,6 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: GroupListParams, @@ -154,12 +173,13 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -177,23 +197,26 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: GroupDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("groupId", params.groupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -204,8 +227,7 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: GroupReplaceParams, @@ -214,13 +236,14 @@ class GroupServiceImpl internal constructor(private val clientOptions: ClientOpt val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "group") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationService.kt index b2ddae2c..b2ddd297 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Organization @@ -12,6 +13,7 @@ import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams import com.braintrustdata.api.services.blocking.organizations.MemberService import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface OrganizationService { @@ -20,67 +22,149 @@ interface OrganizationService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): OrganizationService + fun members(): MemberService /** Get an organization object by its id */ - fun retrieve(params: OrganizationRetrieveParams): Organization = - retrieve(params, RequestOptions.none()) + fun retrieve(organizationId: String): Organization = + retrieve(organizationId, OrganizationRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Organization = + retrieve(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + ): Organization = retrieve(organizationId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: OrganizationRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Organization + /** @see retrieve */ + fun retrieve(params: OrganizationRetrieveParams): Organization = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(organizationId: String, requestOptions: RequestOptions): Organization = + retrieve(organizationId, OrganizationRetrieveParams.none(), requestOptions) + /** * Partially update an organization object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: OrganizationUpdateParams): Organization = - update(params, RequestOptions.none()) + fun update(organizationId: String): Organization = + update(organizationId, OrganizationUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Organization = + update(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see update */ + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + ): Organization = update(organizationId, params, RequestOptions.none()) + + /** @see update */ fun update( params: OrganizationUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Organization + /** @see update */ + fun update(params: OrganizationUpdateParams): Organization = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(organizationId: String, requestOptions: RequestOptions): Organization = + update(organizationId, OrganizationUpdateParams.none(), requestOptions) + /** * List out all organizations. The organizations are sorted by creation date, with the most * recently-created organizations coming first */ fun list(): OrganizationListPage = list(OrganizationListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: OrganizationListParams = OrganizationListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): OrganizationListPage - /** @see [list] */ + /** @see list */ fun list(params: OrganizationListParams = OrganizationListParams.none()): OrganizationListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): OrganizationListPage = list(OrganizationListParams.none(), requestOptions) /** Delete an organization object by its id */ - fun delete(params: OrganizationDeleteParams): Organization = - delete(params, RequestOptions.none()) + fun delete(organizationId: String): Organization = + delete(organizationId, OrganizationDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Organization = + delete(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see delete */ + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + ): Organization = delete(organizationId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: OrganizationDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Organization + /** @see delete */ + fun delete(params: OrganizationDeleteParams): Organization = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(organizationId: String, requestOptions: RequestOptions): Organization = + delete(organizationId, OrganizationDeleteParams.none(), requestOptions) + /** * A view of [OrganizationService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): OrganizationService.WithRawResponse + fun members(): MemberService.WithRawResponse /** @@ -88,31 +172,89 @@ interface OrganizationService { * otherwise the same as [OrganizationService.retrieve]. */ @MustBeClosed - fun retrieve(params: OrganizationRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(organizationId: String): HttpResponseFor = + retrieve(organizationId, OrganizationRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().organizationId(organizationId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + organizationId: String, + params: OrganizationRetrieveParams = OrganizationRetrieveParams.none(), + ): HttpResponseFor = retrieve(organizationId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: OrganizationRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: OrganizationRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + organizationId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(organizationId, OrganizationRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/organization/{organization_id}`, but is * otherwise the same as [OrganizationService.update]. */ @MustBeClosed - fun update(params: OrganizationUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(organizationId: String): HttpResponseFor = + update(organizationId, OrganizationUpdateParams.none()) + + /** @see update */ + @MustBeClosed + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().organizationId(organizationId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + organizationId: String, + params: OrganizationUpdateParams = OrganizationUpdateParams.none(), + ): HttpResponseFor = update(organizationId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: OrganizationUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: OrganizationUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + organizationId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(organizationId, OrganizationUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/organization`, but is otherwise the same as * [OrganizationService.list]. @@ -120,20 +262,20 @@ interface OrganizationService { @MustBeClosed fun list(): HttpResponseFor = list(OrganizationListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: OrganizationListParams = OrganizationListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: OrganizationListParams = OrganizationListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(OrganizationListParams.none(), requestOptions) @@ -143,14 +285,43 @@ interface OrganizationService { * otherwise the same as [OrganizationService.delete]. */ @MustBeClosed - fun delete(params: OrganizationDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(organizationId: String): HttpResponseFor = + delete(organizationId, OrganizationDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().organizationId(organizationId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + organizationId: String, + params: OrganizationDeleteParams = OrganizationDeleteParams.none(), + ): HttpResponseFor = delete(organizationId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: OrganizationDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see delete */ + @MustBeClosed + fun delete(params: OrganizationDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + organizationId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(organizationId, OrganizationDeleteParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt index ea53c72a..a12cd028 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams import com.braintrustdata.api.services.blocking.organizations.MemberService import com.braintrustdata.api.services.blocking.organizations.MemberServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class OrganizationServiceImpl internal constructor(private val clientOptions: ClientOptions) : OrganizationService { @@ -36,6 +39,9 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl override fun withRawResponse(): OrganizationService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): OrganizationService = + OrganizationServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun members(): MemberService = members override fun retrieve( @@ -69,30 +75,42 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : OrganizationService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val members: MemberService.WithRawResponse by lazy { MemberServiceImpl.WithRawResponseImpl(clientOptions) } + override fun withOptions( + modifier: Consumer + ): OrganizationService.WithRawResponse = + OrganizationServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + override fun members(): MemberService.WithRawResponse = members private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: OrganizationRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("organizationId", params.organizationId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -104,22 +122,26 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: OrganizationUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("organizationId", params.organizationId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -132,7 +154,6 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: OrganizationListParams, @@ -141,12 +162,13 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -165,22 +187,26 @@ class OrganizationServiceImpl internal constructor(private val clientOptions: Cl } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: OrganizationDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("organizationId", params.organizationId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreService.kt index 5f9df9bc..5422601c 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.ProjectScore @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.ProjectScoreReplaceParams import com.braintrustdata.api.models.ProjectScoreRetrieveParams import com.braintrustdata.api.models.ProjectScoreUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface ProjectScoreService { @@ -21,6 +23,13 @@ interface ProjectScoreService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectScoreService + /** * Create a new project_score. If there is an existing project_score in the project with the * same name as the one specified in the request, will return the existing project_score @@ -29,66 +38,132 @@ interface ProjectScoreService { fun create(params: ProjectScoreCreateParams): ProjectScore = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ProjectScoreCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectScore /** Get a project_score object by its id */ - fun retrieve(params: ProjectScoreRetrieveParams): ProjectScore = - retrieve(params, RequestOptions.none()) + fun retrieve(projectScoreId: String): ProjectScore = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectScore = + retrieve(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + ): ProjectScore = retrieve(projectScoreId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ProjectScoreRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectScore + /** @see retrieve */ + fun retrieve(params: ProjectScoreRetrieveParams): ProjectScore = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectScoreId: String, requestOptions: RequestOptions): ProjectScore = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none(), requestOptions) + /** * Partially update a project_score object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ProjectScoreUpdateParams): ProjectScore = - update(params, RequestOptions.none()) + fun update(projectScoreId: String): ProjectScore = + update(projectScoreId, ProjectScoreUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectScore = + update(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see update */ + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + ): ProjectScore = update(projectScoreId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectScoreUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectScore + /** @see update */ + fun update(params: ProjectScoreUpdateParams): ProjectScore = + update(params, RequestOptions.none()) + + /** @see update */ + fun update(projectScoreId: String, requestOptions: RequestOptions): ProjectScore = + update(projectScoreId, ProjectScoreUpdateParams.none(), requestOptions) + /** * List out all project_scores. The project_scores are sorted by creation date, with the most * recently-created project_scores coming first */ fun list(): ProjectScoreListPage = list(ProjectScoreListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ProjectScoreListParams = ProjectScoreListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ProjectScoreListPage - /** @see [list] */ + /** @see list */ fun list(params: ProjectScoreListParams = ProjectScoreListParams.none()): ProjectScoreListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): ProjectScoreListPage = list(ProjectScoreListParams.none(), requestOptions) /** Delete a project_score object by its id */ - fun delete(params: ProjectScoreDeleteParams): ProjectScore = - delete(params, RequestOptions.none()) + fun delete(projectScoreId: String): ProjectScore = + delete(projectScoreId, ProjectScoreDeleteParams.none()) - /** @see [delete] */ + /** @see delete */ + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectScore = + delete(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see delete */ + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + ): ProjectScore = delete(projectScoreId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectScoreDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectScore + /** @see delete */ + fun delete(params: ProjectScoreDeleteParams): ProjectScore = + delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(projectScoreId: String, requestOptions: RequestOptions): ProjectScore = + delete(projectScoreId, ProjectScoreDeleteParams.none(), requestOptions) + /** * Create or replace project_score. If there is an existing project_score in the project with * the same name as the one specified in the request, will replace the existing project_score @@ -97,7 +172,7 @@ interface ProjectScoreService { fun replace(params: ProjectScoreReplaceParams): ProjectScore = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: ProjectScoreReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -108,6 +183,15 @@ interface ProjectScoreService { */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ProjectScoreService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/project_score`, but is otherwise the same as * [ProjectScoreService.create]. @@ -116,7 +200,7 @@ interface ProjectScoreService { fun create(params: ProjectScoreCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: ProjectScoreCreateParams, @@ -128,31 +212,89 @@ interface ProjectScoreService { * otherwise the same as [ProjectScoreService.retrieve]. */ @MustBeClosed - fun retrieve(params: ProjectScoreRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(projectScoreId: String): HttpResponseFor = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectScoreId: String, + params: ProjectScoreRetrieveParams = ProjectScoreRetrieveParams.none(), + ): HttpResponseFor = retrieve(projectScoreId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: ProjectScoreRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ProjectScoreRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectScoreId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(projectScoreId, ProjectScoreRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/project_score/{project_score_id}`, but is * otherwise the same as [ProjectScoreService.update]. */ @MustBeClosed - fun update(params: ProjectScoreUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(projectScoreId: String): HttpResponseFor = + update(projectScoreId, ProjectScoreUpdateParams.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + projectScoreId: String, + params: ProjectScoreUpdateParams = ProjectScoreUpdateParams.none(), + ): HttpResponseFor = update(projectScoreId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: ProjectScoreUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: ProjectScoreUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectScoreId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(projectScoreId, ProjectScoreUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/project_score`, but is otherwise the same as * [ProjectScoreService.list]. @@ -160,20 +302,20 @@ interface ProjectScoreService { @MustBeClosed fun list(): HttpResponseFor = list(ProjectScoreListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ProjectScoreListParams = ProjectScoreListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ProjectScoreListParams = ProjectScoreListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(ProjectScoreListParams.none(), requestOptions) @@ -183,16 +325,45 @@ interface ProjectScoreService { * otherwise the same as [ProjectScoreService.delete]. */ @MustBeClosed - fun delete(params: ProjectScoreDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(projectScoreId: String): HttpResponseFor = + delete(projectScoreId, ProjectScoreDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().projectScoreId(projectScoreId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + projectScoreId: String, + params: ProjectScoreDeleteParams = ProjectScoreDeleteParams.none(), + ): HttpResponseFor = delete(projectScoreId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: ProjectScoreDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: ProjectScoreDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectScoreId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(projectScoreId, ProjectScoreDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/project_score`, but is otherwise the same as * [ProjectScoreService.replace]. @@ -201,7 +372,7 @@ interface ProjectScoreService { fun replace(params: ProjectScoreReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: ProjectScoreReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt index 78c4f8ce..b6f4f8ec 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.ProjectScoreListParams import com.braintrustdata.api.models.ProjectScoreReplaceParams import com.braintrustdata.api.models.ProjectScoreRetrieveParams import com.braintrustdata.api.models.ProjectScoreUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ProjectScoreServiceImpl internal constructor(private val clientOptions: ClientOptions) : ProjectScoreService { @@ -34,6 +37,9 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl override fun withRawResponse(): ProjectScoreService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ProjectScoreService = + ProjectScoreServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ProjectScoreCreateParams, requestOptions: RequestOptions, @@ -79,10 +85,18 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectScoreService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ProjectScoreService.WithRawResponse = + ProjectScoreServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ProjectScoreCreateParams, @@ -91,13 +105,14 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -109,21 +124,25 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ProjectScoreRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectScoreId", params.projectScoreId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -135,22 +154,26 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: ProjectScoreUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectScoreId", params.projectScoreId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -163,7 +186,6 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ProjectScoreListParams, @@ -172,12 +194,13 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -196,22 +219,26 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: ProjectScoreDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectScoreId", params.projectScoreId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -223,7 +250,7 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: ProjectScoreReplaceParams, @@ -232,13 +259,14 @@ class ProjectScoreServiceImpl internal constructor(private val clientOptions: Cl val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_score") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectService.kt index 197931d5..c79cab6b 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Project @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectUpdateParams import com.braintrustdata.api.services.blocking.projects.LogService import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface ProjectService { @@ -21,6 +23,13 @@ interface ProjectService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectService + fun logs(): LogService /** @@ -29,66 +38,133 @@ interface ProjectService { */ fun create(params: ProjectCreateParams): Project = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ProjectCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Project /** Get a project object by its id */ - fun retrieve(params: ProjectRetrieveParams): Project = retrieve(params, RequestOptions.none()) + fun retrieve(projectId: String): Project = retrieve(projectId, ProjectRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Project = retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + ): Project = retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ProjectRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Project + /** @see retrieve */ + fun retrieve(params: ProjectRetrieveParams): Project = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectId: String, requestOptions: RequestOptions): Project = + retrieve(projectId, ProjectRetrieveParams.none(), requestOptions) + /** * Partially update a project object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ProjectUpdateParams): Project = update(params, RequestOptions.none()) + fun update(projectId: String): Project = update(projectId, ProjectUpdateParams.none()) + + /** @see update */ + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Project = update(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see update */ + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + ): Project = update(projectId, params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: ProjectUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Project + /** @see update */ + fun update(params: ProjectUpdateParams): Project = update(params, RequestOptions.none()) + + /** @see update */ + fun update(projectId: String, requestOptions: RequestOptions): Project = + update(projectId, ProjectUpdateParams.none(), requestOptions) + /** * List out all projects. The projects are sorted by creation date, with the most * recently-created projects coming first */ fun list(): ProjectListPage = list(ProjectListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ProjectListParams = ProjectListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ProjectListPage - /** @see [list] */ + /** @see list */ fun list(params: ProjectListParams = ProjectListParams.none()): ProjectListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): ProjectListPage = list(ProjectListParams.none(), requestOptions) /** Delete a project object by its id */ - fun delete(params: ProjectDeleteParams): Project = delete(params, RequestOptions.none()) + fun delete(projectId: String): Project = delete(projectId, ProjectDeleteParams.none()) + + /** @see delete */ + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Project = delete(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + ): Project = delete(projectId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Project + /** @see delete */ + fun delete(params: ProjectDeleteParams): Project = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(projectId: String, requestOptions: RequestOptions): Project = + delete(projectId, ProjectDeleteParams.none(), requestOptions) + /** A view of [ProjectService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectService.WithRawResponse + fun logs(): LogService.WithRawResponse /** @@ -99,7 +175,7 @@ interface ProjectService { fun create(params: ProjectCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: ProjectCreateParams, @@ -111,51 +187,103 @@ interface ProjectService { * as [ProjectService.retrieve]. */ @MustBeClosed - fun retrieve(params: ProjectRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(projectId: String): HttpResponseFor = + retrieve(projectId, ProjectRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectId: String, + params: ProjectRetrieveParams = ProjectRetrieveParams.none(), + ): HttpResponseFor = retrieve(projectId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: ProjectRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ProjectRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(projectId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(projectId, ProjectRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/project/{project_id}`, but is otherwise the * same as [ProjectService.update]. */ @MustBeClosed - fun update(params: ProjectUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(projectId: String): HttpResponseFor = + update(projectId, ProjectUpdateParams.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + projectId: String, + params: ProjectUpdateParams = ProjectUpdateParams.none(), + ): HttpResponseFor = update(projectId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: ProjectUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: ProjectUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(projectId: String, requestOptions: RequestOptions): HttpResponseFor = + update(projectId, ProjectUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/project`, but is otherwise the same as * [ProjectService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(ProjectListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ProjectListParams = ProjectListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ProjectListParams = ProjectListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(ProjectListParams.none(), requestOptions) @@ -165,14 +293,40 @@ interface ProjectService { * same as [ProjectService.delete]. */ @MustBeClosed - fun delete(params: ProjectDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(projectId: String): HttpResponseFor = + delete(projectId, ProjectDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + projectId: String, + params: ProjectDeleteParams = ProjectDeleteParams.none(), + ): HttpResponseFor = delete(projectId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: ProjectDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see delete */ + @MustBeClosed + fun delete(params: ProjectDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(projectId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(projectId, ProjectDeleteParams.none(), requestOptions) } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt index 7ccbce80..ec8c29d3 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -25,6 +26,8 @@ import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectUpdateParams import com.braintrustdata.api.services.blocking.projects.LogService import com.braintrustdata.api.services.blocking.projects.LogServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ProjectServiceImpl internal constructor(private val clientOptions: ClientOptions) : ProjectService { @@ -37,6 +40,9 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO override fun withRawResponse(): ProjectService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ProjectService = + ProjectServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun logs(): LogService = logs override fun create(params: ProjectCreateParams, requestOptions: RequestOptions): Project = @@ -62,16 +68,23 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val logs: LogService.WithRawResponse by lazy { LogServiceImpl.WithRawResponseImpl(clientOptions) } + override fun withOptions( + modifier: Consumer + ): ProjectService.WithRawResponse = + ProjectServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + override fun logs(): LogService.WithRawResponse = logs - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: ProjectCreateParams, @@ -80,13 +93,14 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -98,21 +112,25 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ProjectRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -123,23 +141,26 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: ProjectUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -152,7 +173,6 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ProjectListParams, @@ -161,12 +181,13 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -184,23 +205,26 @@ class ProjectServiceImpl internal constructor(private val clientOptions: ClientO } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: ProjectDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagService.kt index d06930e4..c6188d4d 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.ProjectTag @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.ProjectTagReplaceParams import com.braintrustdata.api.models.ProjectTagRetrieveParams import com.braintrustdata.api.models.ProjectTagUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface ProjectTagService { @@ -21,70 +23,140 @@ interface ProjectTagService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ProjectTagService + /** * Create a new project_tag. If there is an existing project_tag in the project with the same * name as the one specified in the request, will return the existing project_tag unmodified */ fun create(params: ProjectTagCreateParams): ProjectTag = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ProjectTagCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectTag /** Get a project_tag object by its id */ - fun retrieve(params: ProjectTagRetrieveParams): ProjectTag = - retrieve(params, RequestOptions.none()) + fun retrieve(projectTagId: String): ProjectTag = + retrieve(projectTagId, ProjectTagRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectTag = retrieve(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + ): ProjectTag = retrieve(projectTagId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: ProjectTagRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectTag + /** @see retrieve */ + fun retrieve(params: ProjectTagRetrieveParams): ProjectTag = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(projectTagId: String, requestOptions: RequestOptions): ProjectTag = + retrieve(projectTagId, ProjectTagRetrieveParams.none(), requestOptions) + /** * Partially update a project_tag object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: ProjectTagUpdateParams): ProjectTag = update(params, RequestOptions.none()) + fun update(projectTagId: String): ProjectTag = + update(projectTagId, ProjectTagUpdateParams.none()) + + /** @see update */ + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectTag = update(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + ): ProjectTag = update(projectTagId, params, RequestOptions.none()) + + /** @see update */ fun update( params: ProjectTagUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectTag + /** @see update */ + fun update(params: ProjectTagUpdateParams): ProjectTag = update(params, RequestOptions.none()) + + /** @see update */ + fun update(projectTagId: String, requestOptions: RequestOptions): ProjectTag = + update(projectTagId, ProjectTagUpdateParams.none(), requestOptions) + /** * List out all project_tags. The project_tags are sorted by creation date, with the most * recently-created project_tags coming first */ fun list(): ProjectTagListPage = list(ProjectTagListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: ProjectTagListParams = ProjectTagListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): ProjectTagListPage - /** @see [list] */ + /** @see list */ fun list(params: ProjectTagListParams = ProjectTagListParams.none()): ProjectTagListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): ProjectTagListPage = list(ProjectTagListParams.none(), requestOptions) /** Delete a project_tag object by its id */ - fun delete(params: ProjectTagDeleteParams): ProjectTag = delete(params, RequestOptions.none()) + fun delete(projectTagId: String): ProjectTag = + delete(projectTagId, ProjectTagDeleteParams.none()) + + /** @see delete */ + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ProjectTag = delete(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + ): ProjectTag = delete(projectTagId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: ProjectTagDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): ProjectTag + /** @see delete */ + fun delete(params: ProjectTagDeleteParams): ProjectTag = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(projectTagId: String, requestOptions: RequestOptions): ProjectTag = + delete(projectTagId, ProjectTagDeleteParams.none(), requestOptions) + /** * Create or replace project_tag. If there is an existing project_tag in the project with the * same name as the one specified in the request, will replace the existing project_tag with the @@ -93,7 +165,7 @@ interface ProjectTagService { fun replace(params: ProjectTagReplaceParams): ProjectTag = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: ProjectTagReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -102,6 +174,15 @@ interface ProjectTagService { /** A view of [ProjectTagService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ProjectTagService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/project_tag`, but is otherwise the same as * [ProjectTagService.create]. @@ -110,7 +191,7 @@ interface ProjectTagService { fun create(params: ProjectTagCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: ProjectTagCreateParams, @@ -122,31 +203,89 @@ interface ProjectTagService { * the same as [ProjectTagService.retrieve]. */ @MustBeClosed - fun retrieve(params: ProjectTagRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(projectTagId: String): HttpResponseFor = + retrieve(projectTagId, ProjectTagRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectTagId: String, + params: ProjectTagRetrieveParams = ProjectTagRetrieveParams.none(), + ): HttpResponseFor = retrieve(projectTagId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: ProjectTagRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: ProjectTagRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + projectTagId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(projectTagId, ProjectTagRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/project_tag/{project_tag_id}`, but is * otherwise the same as [ProjectTagService.update]. */ @MustBeClosed - fun update(params: ProjectTagUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(projectTagId: String): HttpResponseFor = + update(projectTagId, ProjectTagUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + projectTagId: String, + params: ProjectTagUpdateParams = ProjectTagUpdateParams.none(), + ): HttpResponseFor = update(projectTagId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: ProjectTagUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: ProjectTagUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + projectTagId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(projectTagId, ProjectTagUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/project_tag`, but is otherwise the same as * [ProjectTagService.list]. @@ -154,20 +293,20 @@ interface ProjectTagService { @MustBeClosed fun list(): HttpResponseFor = list(ProjectTagListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ProjectTagListParams = ProjectTagListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ProjectTagListParams = ProjectTagListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(ProjectTagListParams.none(), requestOptions) @@ -177,16 +316,45 @@ interface ProjectTagService { * otherwise the same as [ProjectTagService.delete]. */ @MustBeClosed - fun delete(params: ProjectTagDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(projectTagId: String): HttpResponseFor = + delete(projectTagId, ProjectTagDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().projectTagId(projectTagId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + projectTagId: String, + params: ProjectTagDeleteParams = ProjectTagDeleteParams.none(), + ): HttpResponseFor = delete(projectTagId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: ProjectTagDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: ProjectTagDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + projectTagId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(projectTagId, ProjectTagDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/project_tag`, but is otherwise the same as * [ProjectTagService.replace]. @@ -195,7 +363,7 @@ interface ProjectTagService { fun replace(params: ProjectTagReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: ProjectTagReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt index 17629219..cae57310 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.ProjectTagListParams import com.braintrustdata.api.models.ProjectTagReplaceParams import com.braintrustdata.api.models.ProjectTagRetrieveParams import com.braintrustdata.api.models.ProjectTagUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ProjectTagServiceImpl internal constructor(private val clientOptions: ClientOptions) : ProjectTagService { @@ -34,6 +37,9 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie override fun withRawResponse(): ProjectTagService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ProjectTagService = + ProjectTagServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: ProjectTagCreateParams, requestOptions: RequestOptions, @@ -79,10 +85,18 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ProjectTagService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ProjectTagService.WithRawResponse = + ProjectTagServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: ProjectTagCreateParams, @@ -91,13 +105,14 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -109,21 +124,25 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ProjectTagRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectTagId", params.projectTagId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -135,22 +154,26 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: ProjectTagUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectTagId", params.projectTagId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -163,7 +186,6 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ProjectTagListParams, @@ -172,12 +194,13 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -196,22 +219,26 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: ProjectTagDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectTagId", params.projectTagId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -223,7 +250,7 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: ProjectTagReplaceParams, @@ -232,13 +259,14 @@ class ProjectTagServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_tag") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptService.kt index e3d04a03..46f50a11 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Prompt @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.PromptReplaceParams import com.braintrustdata.api.models.PromptRetrieveParams import com.braintrustdata.api.models.PromptUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface PromptService { @@ -21,76 +23,139 @@ interface PromptService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PromptService + /** * Create a new prompt. If there is an existing prompt in the project with the same slug as the * one specified in the request, will return the existing prompt unmodified */ fun create(params: PromptCreateParams): Prompt = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: PromptCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Prompt /** Get a prompt object by its id */ - fun retrieve(params: PromptRetrieveParams): Prompt = retrieve(params, RequestOptions.none()) + fun retrieve(promptId: String): Prompt = retrieve(promptId, PromptRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Prompt = retrieve(params.toBuilder().promptId(promptId).build(), requestOptions) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + ): Prompt = retrieve(promptId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: PromptRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Prompt + /** @see retrieve */ + fun retrieve(params: PromptRetrieveParams): Prompt = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(promptId: String, requestOptions: RequestOptions): Prompt = + retrieve(promptId, PromptRetrieveParams.none(), requestOptions) + /** * Partially update a prompt object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: PromptUpdateParams): Prompt = update(params, RequestOptions.none()) + fun update(promptId: String): Prompt = update(promptId, PromptUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Prompt = update(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see update */ + fun update(promptId: String, params: PromptUpdateParams = PromptUpdateParams.none()): Prompt = + update(promptId, params, RequestOptions.none()) + + /** @see update */ fun update( params: PromptUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Prompt + /** @see update */ + fun update(params: PromptUpdateParams): Prompt = update(params, RequestOptions.none()) + + /** @see update */ + fun update(promptId: String, requestOptions: RequestOptions): Prompt = + update(promptId, PromptUpdateParams.none(), requestOptions) + /** * List out all prompts. The prompts are sorted by creation date, with the most recently-created * prompts coming first */ fun list(): PromptListPage = list(PromptListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: PromptListParams = PromptListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): PromptListPage - /** @see [list] */ + /** @see list */ fun list(params: PromptListParams = PromptListParams.none()): PromptListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): PromptListPage = list(PromptListParams.none(), requestOptions) /** Delete a prompt object by its id */ - fun delete(params: PromptDeleteParams): Prompt = delete(params, RequestOptions.none()) + fun delete(promptId: String): Prompt = delete(promptId, PromptDeleteParams.none()) + + /** @see delete */ + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Prompt = delete(params.toBuilder().promptId(promptId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete(promptId: String, params: PromptDeleteParams = PromptDeleteParams.none()): Prompt = + delete(promptId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: PromptDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Prompt + /** @see delete */ + fun delete(params: PromptDeleteParams): Prompt = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(promptId: String, requestOptions: RequestOptions): Prompt = + delete(promptId, PromptDeleteParams.none(), requestOptions) + /** * Create or replace prompt. If there is an existing prompt in the project with the same slug as * the one specified in the request, will replace the existing prompt with the provided fields */ fun replace(params: PromptReplaceParams): Prompt = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: PromptReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -99,6 +164,13 @@ interface PromptService { /** A view of [PromptService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PromptService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/prompt`, but is otherwise the same as * [PromptService.create]. @@ -107,7 +179,7 @@ interface PromptService { fun create(params: PromptCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: PromptCreateParams, @@ -119,51 +191,103 @@ interface PromptService { * as [PromptService.retrieve]. */ @MustBeClosed - fun retrieve(params: PromptRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(promptId: String): HttpResponseFor = + retrieve(promptId, PromptRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + promptId: String, + params: PromptRetrieveParams = PromptRetrieveParams.none(), + ): HttpResponseFor = retrieve(promptId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ @MustBeClosed fun retrieve( params: PromptRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: PromptRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(promptId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(promptId, PromptRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/prompt/{prompt_id}`, but is otherwise the same * as [PromptService.update]. */ @MustBeClosed - fun update(params: PromptUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(promptId: String): HttpResponseFor = + update(promptId, PromptUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().promptId(promptId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + promptId: String, + params: PromptUpdateParams = PromptUpdateParams.none(), + ): HttpResponseFor = update(promptId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: PromptUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: PromptUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(promptId: String, requestOptions: RequestOptions): HttpResponseFor = + update(promptId, PromptUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/prompt`, but is otherwise the same as * [PromptService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(PromptListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: PromptListParams = PromptListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: PromptListParams = PromptListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(PromptListParams.none(), requestOptions) @@ -173,16 +297,42 @@ interface PromptService { * same as [PromptService.delete]. */ @MustBeClosed - fun delete(params: PromptDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(promptId: String): HttpResponseFor = + delete(promptId, PromptDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().promptId(promptId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + promptId: String, + params: PromptDeleteParams = PromptDeleteParams.none(), + ): HttpResponseFor = delete(promptId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: PromptDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: PromptDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(promptId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(promptId, PromptDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/prompt`, but is otherwise the same as * [PromptService.replace]. @@ -191,7 +341,7 @@ interface PromptService { fun replace(params: PromptReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: PromptReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt index 105c1629..2abf6d64 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/PromptServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.PromptListParams import com.braintrustdata.api.models.PromptReplaceParams import com.braintrustdata.api.models.PromptRetrieveParams import com.braintrustdata.api.models.PromptUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class PromptServiceImpl internal constructor(private val clientOptions: ClientOptions) : PromptService { @@ -34,6 +37,9 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp override fun withRawResponse(): PromptService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): PromptService = + PromptServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: PromptCreateParams, requestOptions: RequestOptions): Prompt = // post /v1/prompt withRawResponse().create(params, requestOptions).parse() @@ -61,10 +67,17 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PromptService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): PromptService.WithRawResponse = + PromptServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: PromptCreateParams, @@ -73,13 +86,14 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -90,22 +104,25 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: PromptRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("promptId", params.promptId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -116,23 +133,26 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PromptUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("promptId", params.promptId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -145,7 +165,6 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: PromptListParams, @@ -154,12 +173,13 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -177,23 +197,26 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: PromptDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("promptId", params.promptId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -204,8 +227,7 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: PromptReplaceParams, @@ -214,13 +236,14 @@ class PromptServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "prompt") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleService.kt index a913ecca..a6ba04a2 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.Role @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.RoleReplaceParams import com.braintrustdata.api.models.RoleRetrieveParams import com.braintrustdata.api.models.RoleUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface RoleService { @@ -21,76 +23,137 @@ interface RoleService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RoleService + /** * Create a new role. If there is an existing role with the same name as the one specified in * the request, will return the existing role unmodified */ fun create(params: RoleCreateParams): Role = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: RoleCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Role /** Get a role object by its id */ - fun retrieve(params: RoleRetrieveParams): Role = retrieve(params, RequestOptions.none()) + fun retrieve(roleId: String): Role = retrieve(roleId, RoleRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Role = retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(roleId: String, params: RoleRetrieveParams = RoleRetrieveParams.none()): Role = + retrieve(roleId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: RoleRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): Role + /** @see retrieve */ + fun retrieve(params: RoleRetrieveParams): Role = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(roleId: String, requestOptions: RequestOptions): Role = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** * Partially update a role object. Specify the fields to update in the payload. Any object-type * fields will be deep-merged with existing content. Currently we do not support removing fields * or setting them to null. */ - fun update(params: RoleUpdateParams): Role = update(params, RequestOptions.none()) + fun update(roleId: String): Role = update(roleId, RoleUpdateParams.none()) - /** @see [update] */ + /** @see update */ + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Role = update(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see update */ + fun update(roleId: String, params: RoleUpdateParams = RoleUpdateParams.none()): Role = + update(roleId, params, RequestOptions.none()) + + /** @see update */ fun update( params: RoleUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): Role + /** @see update */ + fun update(params: RoleUpdateParams): Role = update(params, RequestOptions.none()) + + /** @see update */ + fun update(roleId: String, requestOptions: RequestOptions): Role = + update(roleId, RoleUpdateParams.none(), requestOptions) + /** * List out all roles. The roles are sorted by creation date, with the most recently-created * roles coming first */ fun list(): RoleListPage = list(RoleListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: RoleListParams = RoleListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): RoleListPage - /** @see [list] */ + /** @see list */ fun list(params: RoleListParams = RoleListParams.none()): RoleListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): RoleListPage = list(RoleListParams.none(), requestOptions) /** Delete a role object by its id */ - fun delete(params: RoleDeleteParams): Role = delete(params, RequestOptions.none()) + fun delete(roleId: String): Role = delete(roleId, RoleDeleteParams.none()) + + /** @see delete */ + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Role = delete(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see delete */ + fun delete(roleId: String, params: RoleDeleteParams = RoleDeleteParams.none()): Role = + delete(roleId, params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: RoleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): Role + /** @see delete */ + fun delete(params: RoleDeleteParams): Role = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(roleId: String, requestOptions: RequestOptions): Role = + delete(roleId, RoleDeleteParams.none(), requestOptions) + /** * Create or replace role. If there is an existing role with the same name as the one specified * in the request, will replace the existing role with the provided fields */ fun replace(params: RoleReplaceParams): Role = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: RoleReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -99,6 +162,13 @@ interface RoleService { /** A view of [RoleService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RoleService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/role`, but is otherwise the same as * [RoleService.create]. @@ -107,7 +177,7 @@ interface RoleService { fun create(params: RoleCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: RoleCreateParams, @@ -119,50 +189,100 @@ interface RoleService { * [RoleService.retrieve]. */ @MustBeClosed - fun retrieve(params: RoleRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(roleId: String): HttpResponseFor = + retrieve(roleId, RoleRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + roleId: String, + params: RoleRetrieveParams = RoleRetrieveParams.none(), + ): HttpResponseFor = retrieve(roleId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: RoleRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RoleRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(roleId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(roleId, RoleRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/role/{role_id}`, but is otherwise the same as * [RoleService.update]. */ @MustBeClosed - fun update(params: RoleUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(roleId: String): HttpResponseFor = update(roleId, RoleUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = update(params.toBuilder().roleId(roleId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + roleId: String, + params: RoleUpdateParams = RoleUpdateParams.none(), + ): HttpResponseFor = update(roleId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: RoleUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: RoleUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update(roleId: String, requestOptions: RequestOptions): HttpResponseFor = + update(roleId, RoleUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/role`, but is otherwise the same as * [RoleService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(RoleListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: RoleListParams = RoleListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(params: RoleListParams = RoleListParams.none()): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(RoleListParams.none(), requestOptions) @@ -172,16 +292,40 @@ interface RoleService { * [RoleService.delete]. */ @MustBeClosed - fun delete(params: RoleDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(roleId: String): HttpResponseFor = delete(roleId, RoleDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = delete(params.toBuilder().roleId(roleId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + roleId: String, + params: RoleDeleteParams = RoleDeleteParams.none(), + ): HttpResponseFor = delete(roleId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: RoleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: RoleDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete(roleId: String, requestOptions: RequestOptions): HttpResponseFor = + delete(roleId, RoleDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/role`, but is otherwise the same as * [RoleService.replace]. @@ -190,7 +334,7 @@ interface RoleService { fun replace(params: RoleReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: RoleReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt index 12949e33..091c5fcb 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/RoleServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.RoleListParams import com.braintrustdata.api.models.RoleReplaceParams import com.braintrustdata.api.models.RoleRetrieveParams import com.braintrustdata.api.models.RoleUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class RoleServiceImpl internal constructor(private val clientOptions: ClientOptions) : RoleService { @@ -33,6 +36,9 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti override fun withRawResponse(): RoleService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): RoleService = + RoleServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: RoleCreateParams, requestOptions: RequestOptions): Role = // post /v1/role withRawResponse().create(params, requestOptions).parse() @@ -60,10 +66,17 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : RoleService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RoleService.WithRawResponse = + RoleServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: RoleCreateParams, @@ -72,13 +85,14 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -89,22 +103,25 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: RoleRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -115,23 +132,26 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: RoleUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -144,7 +164,6 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: RoleListParams, @@ -153,12 +172,13 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -176,23 +196,26 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: RoleDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("roleId", params.roleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -203,8 +226,7 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: RoleReplaceParams, @@ -213,13 +235,14 @@ class RoleServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "role") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeService.kt index f8630cc6..d0b65980 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.SpanIFrame @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.SpanIframeReplaceParams import com.braintrustdata.api.models.SpanIframeRetrieveParams import com.braintrustdata.api.models.SpanIframeUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface SpanIframeService { @@ -21,70 +23,140 @@ interface SpanIframeService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): SpanIframeService + /** * Create a new span_iframe. If there is an existing span_iframe with the same name as the one * specified in the request, will return the existing span_iframe unmodified */ fun create(params: SpanIframeCreateParams): SpanIFrame = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: SpanIframeCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): SpanIFrame /** Get a span_iframe object by its id */ - fun retrieve(params: SpanIframeRetrieveParams): SpanIFrame = - retrieve(params, RequestOptions.none()) + fun retrieve(spanIframeId: String): SpanIFrame = + retrieve(spanIframeId, SpanIframeRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SpanIFrame = retrieve(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + ): SpanIFrame = retrieve(spanIframeId, params, RequestOptions.none()) + + /** @see retrieve */ fun retrieve( params: SpanIframeRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): SpanIFrame + /** @see retrieve */ + fun retrieve(params: SpanIframeRetrieveParams): SpanIFrame = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(spanIframeId: String, requestOptions: RequestOptions): SpanIFrame = + retrieve(spanIframeId, SpanIframeRetrieveParams.none(), requestOptions) + /** * Partially update a span_iframe object. Specify the fields to update in the payload. Any * object-type fields will be deep-merged with existing content. Currently we do not support * removing fields or setting them to null. */ - fun update(params: SpanIframeUpdateParams): SpanIFrame = update(params, RequestOptions.none()) + fun update(spanIframeId: String): SpanIFrame = + update(spanIframeId, SpanIframeUpdateParams.none()) + + /** @see update */ + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SpanIFrame = update(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) - /** @see [update] */ + /** @see update */ + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + ): SpanIFrame = update(spanIframeId, params, RequestOptions.none()) + + /** @see update */ fun update( params: SpanIframeUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): SpanIFrame + /** @see update */ + fun update(params: SpanIframeUpdateParams): SpanIFrame = update(params, RequestOptions.none()) + + /** @see update */ + fun update(spanIframeId: String, requestOptions: RequestOptions): SpanIFrame = + update(spanIframeId, SpanIframeUpdateParams.none(), requestOptions) + /** * List out all span_iframes. The span_iframes are sorted by creation date, with the most * recently-created span_iframes coming first */ fun list(): SpanIframeListPage = list(SpanIframeListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: SpanIframeListParams = SpanIframeListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): SpanIframeListPage - /** @see [list] */ + /** @see list */ fun list(params: SpanIframeListParams = SpanIframeListParams.none()): SpanIframeListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): SpanIframeListPage = list(SpanIframeListParams.none(), requestOptions) /** Delete a span_iframe object by its id */ - fun delete(params: SpanIframeDeleteParams): SpanIFrame = delete(params, RequestOptions.none()) + fun delete(spanIframeId: String): SpanIFrame = + delete(spanIframeId, SpanIframeDeleteParams.none()) + + /** @see delete */ + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): SpanIFrame = delete(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + ): SpanIFrame = delete(spanIframeId, params, RequestOptions.none()) + + /** @see delete */ fun delete( params: SpanIframeDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): SpanIFrame + /** @see delete */ + fun delete(params: SpanIframeDeleteParams): SpanIFrame = delete(params, RequestOptions.none()) + + /** @see delete */ + fun delete(spanIframeId: String, requestOptions: RequestOptions): SpanIFrame = + delete(spanIframeId, SpanIframeDeleteParams.none(), requestOptions) + /** * Create or replace span_iframe. If there is an existing span_iframe with the same name as the * one specified in the request, will replace the existing span_iframe with the provided fields @@ -92,7 +164,7 @@ interface SpanIframeService { fun replace(params: SpanIframeReplaceParams): SpanIFrame = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: SpanIframeReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -101,6 +173,15 @@ interface SpanIframeService { /** A view of [SpanIframeService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): SpanIframeService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/span_iframe`, but is otherwise the same as * [SpanIframeService.create]. @@ -109,7 +190,7 @@ interface SpanIframeService { fun create(params: SpanIframeCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: SpanIframeCreateParams, @@ -121,31 +202,89 @@ interface SpanIframeService { * the same as [SpanIframeService.retrieve]. */ @MustBeClosed - fun retrieve(params: SpanIframeRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(spanIframeId: String): HttpResponseFor = + retrieve(spanIframeId, SpanIframeRetrieveParams.none()) - /** @see [retrieve] */ + /** @see retrieve */ + @MustBeClosed + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + spanIframeId: String, + params: SpanIframeRetrieveParams = SpanIframeRetrieveParams.none(), + ): HttpResponseFor = retrieve(spanIframeId, params, RequestOptions.none()) + + /** @see retrieve */ @MustBeClosed fun retrieve( params: SpanIframeRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: SpanIframeRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + spanIframeId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(spanIframeId, SpanIframeRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `patch /v1/span_iframe/{span_iframe_id}`, but is * otherwise the same as [SpanIframeService.update]. */ @MustBeClosed - fun update(params: SpanIframeUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(spanIframeId: String): HttpResponseFor = + update(spanIframeId, SpanIframeUpdateParams.none()) - /** @see [update] */ + /** @see update */ + @MustBeClosed + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update( + spanIframeId: String, + params: SpanIframeUpdateParams = SpanIframeUpdateParams.none(), + ): HttpResponseFor = update(spanIframeId, params, RequestOptions.none()) + + /** @see update */ @MustBeClosed fun update( params: SpanIframeUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see update */ + @MustBeClosed + fun update(params: SpanIframeUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + spanIframeId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(spanIframeId, SpanIframeUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/span_iframe`, but is otherwise the same as * [SpanIframeService.list]. @@ -153,20 +292,20 @@ interface SpanIframeService { @MustBeClosed fun list(): HttpResponseFor = list(SpanIframeListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: SpanIframeListParams = SpanIframeListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: SpanIframeListParams = SpanIframeListParams.none() ): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(SpanIframeListParams.none(), requestOptions) @@ -176,16 +315,45 @@ interface SpanIframeService { * otherwise the same as [SpanIframeService.delete]. */ @MustBeClosed - fun delete(params: SpanIframeDeleteParams): HttpResponseFor = - delete(params, RequestOptions.none()) + fun delete(spanIframeId: String): HttpResponseFor = + delete(spanIframeId, SpanIframeDeleteParams.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().spanIframeId(spanIframeId).build(), requestOptions) - /** @see [delete] */ + /** @see delete */ + @MustBeClosed + fun delete( + spanIframeId: String, + params: SpanIframeDeleteParams = SpanIframeDeleteParams.none(), + ): HttpResponseFor = delete(spanIframeId, params, RequestOptions.none()) + + /** @see delete */ @MustBeClosed fun delete( params: SpanIframeDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see delete */ + @MustBeClosed + fun delete(params: SpanIframeDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + spanIframeId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(spanIframeId, SpanIframeDeleteParams.none(), requestOptions) + /** * Returns a raw HTTP response for `put /v1/span_iframe`, but is otherwise the same as * [SpanIframeService.replace]. @@ -194,7 +362,7 @@ interface SpanIframeService { fun replace(params: SpanIframeReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: SpanIframeReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt index d094ddea..5d1a2af3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.SpanIframeListParams import com.braintrustdata.api.models.SpanIframeReplaceParams import com.braintrustdata.api.models.SpanIframeRetrieveParams import com.braintrustdata.api.models.SpanIframeUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class SpanIframeServiceImpl internal constructor(private val clientOptions: ClientOptions) : SpanIframeService { @@ -34,6 +37,9 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie override fun withRawResponse(): SpanIframeService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): SpanIframeService = + SpanIframeServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create( params: SpanIframeCreateParams, requestOptions: RequestOptions, @@ -79,10 +85,18 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SpanIframeService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): SpanIframeService.WithRawResponse = + SpanIframeServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: SpanIframeCreateParams, @@ -91,13 +105,14 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -109,21 +124,25 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie } private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: SpanIframeRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("spanIframeId", params.spanIframeId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -135,22 +154,26 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: SpanIframeUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("spanIframeId", params.spanIframeId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -163,7 +186,6 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: SpanIframeListParams, @@ -172,12 +194,13 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -196,22 +219,26 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie } private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun delete( params: SpanIframeDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("spanIframeId", params.spanIframeId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe", params._pathParam(0)) .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -223,7 +250,7 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie } private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun replace( params: SpanIframeReplaceParams, @@ -232,13 +259,14 @@ class SpanIframeServiceImpl internal constructor(private val clientOptions: Clie val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "span_iframe") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelService.kt index f7d77d83..ba60b79a 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelService.kt @@ -2,10 +2,12 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.TopLevelHelloWorldParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface TopLevelService { @@ -14,26 +16,40 @@ interface TopLevelService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): TopLevelService + /** Default endpoint. Simply replies with 'Hello, World!'. Authorization is not required */ fun helloWorld(): String = helloWorld(TopLevelHelloWorldParams.none()) - /** @see [helloWorld] */ + /** @see helloWorld */ fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): String - /** @see [helloWorld] */ + /** @see helloWorld */ fun helloWorld(params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none()): String = helloWorld(params, RequestOptions.none()) - /** @see [helloWorld] */ + /** @see helloWorld */ fun helloWorld(requestOptions: RequestOptions): String = helloWorld(TopLevelHelloWorldParams.none(), requestOptions) /** A view of [TopLevelService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): TopLevelService.WithRawResponse + /** * Returns a raw HTTP response for `get /v1`, but is otherwise the same as * [TopLevelService.helloWorld]. @@ -41,20 +57,20 @@ interface TopLevelService { @MustBeClosed fun helloWorld(): HttpResponseFor = helloWorld(TopLevelHelloWorldParams.none()) - /** @see [helloWorld] */ + /** @see helloWorld */ @MustBeClosed fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [helloWorld] */ + /** @see helloWorld */ @MustBeClosed fun helloWorld( params: TopLevelHelloWorldParams = TopLevelHelloWorldParams.none() ): HttpResponseFor = helloWorld(params, RequestOptions.none()) - /** @see [helloWorld] */ + /** @see helloWorld */ @MustBeClosed fun helloWorld(requestOptions: RequestOptions): HttpResponseFor = helloWorld(TopLevelHelloWorldParams.none(), requestOptions) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt index 44401cd1..a04c4278 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/TopLevelServiceImpl.kt @@ -3,18 +3,19 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.stringHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare import com.braintrustdata.api.models.TopLevelHelloWorldParams +import java.util.function.Consumer class TopLevelServiceImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelService { @@ -25,6 +26,9 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client override fun withRawResponse(): TopLevelService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): TopLevelService = + TopLevelServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun helloWorld( params: TopLevelHelloWorldParams, requestOptions: RequestOptions, @@ -35,10 +39,17 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): TopLevelService.WithRawResponse = + TopLevelServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val helloWorldHandler: Handler = - stringHandler().withErrorHandler(errorHandler) + private val helloWorldHandler: Handler = stringHandler() override fun helloWorld( params: TopLevelHelloWorldParams, @@ -47,12 +58,15 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { response.use { helloWorldHandler.handle(it) } } + return errorHandler.handle(response).parseable { + response.use { helloWorldHandler.handle(it) } + } } } } diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserService.kt index 8a297070..802878d1 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.User @@ -9,6 +10,7 @@ import com.braintrustdata.api.models.UserListPage import com.braintrustdata.api.models.UserListParams import com.braintrustdata.api.models.UserRetrieveParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface UserService { @@ -17,72 +19,130 @@ interface UserService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): UserService + /** Get a user object by its id */ - fun retrieve(params: UserRetrieveParams): User = retrieve(params, RequestOptions.none()) + fun retrieve(userId: String): User = retrieve(userId, UserRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): User = retrieve(params.toBuilder().userId(userId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(userId: String, params: UserRetrieveParams = UserRetrieveParams.none()): User = + retrieve(userId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): User + /** @see retrieve */ + fun retrieve(params: UserRetrieveParams): User = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(userId: String, requestOptions: RequestOptions): User = + retrieve(userId, UserRetrieveParams.none(), requestOptions) + /** * List out all users. The users are sorted by creation date, with the most recently-created * users coming first */ fun list(): UserListPage = list(UserListParams.none()) - /** @see [list] */ + /** @see list */ fun list( params: UserListParams = UserListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): UserListPage - /** @see [list] */ + /** @see list */ fun list(params: UserListParams = UserListParams.none()): UserListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list(requestOptions: RequestOptions): UserListPage = list(UserListParams.none(), requestOptions) /** A view of [UserService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): UserService.WithRawResponse + /** * Returns a raw HTTP response for `get /v1/user/{user_id}`, but is otherwise the same as * [UserService.retrieve]. */ @MustBeClosed - fun retrieve(params: UserRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(userId: String): HttpResponseFor = + retrieve(userId, UserRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().userId(userId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + userId: String, + params: UserRetrieveParams = UserRetrieveParams.none(), + ): HttpResponseFor = retrieve(userId, params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ @MustBeClosed fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: UserRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(userId: String, requestOptions: RequestOptions): HttpResponseFor = + retrieve(userId, UserRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /v1/user`, but is otherwise the same as * [UserService.list]. */ @MustBeClosed fun list(): HttpResponseFor = list(UserListParams.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: UserListParams = UserListParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(params: UserListParams = UserListParams.none()): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list(requestOptions: RequestOptions): HttpResponseFor = list(UserListParams.none(), requestOptions) diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt index ade1f669..3e44a297 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/UserServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.parseable @@ -19,6 +20,8 @@ import com.braintrustdata.api.models.UserListPage import com.braintrustdata.api.models.UserListPageResponse import com.braintrustdata.api.models.UserListParams import com.braintrustdata.api.models.UserRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class UserServiceImpl internal constructor(private val clientOptions: ClientOptions) : UserService { @@ -28,6 +31,9 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti override fun withRawResponse(): UserService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): UserService = + UserServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun retrieve(params: UserRetrieveParams, requestOptions: RequestOptions): User = // get /v1/user/{user_id} withRawResponse().retrieve(params, requestOptions).parse() @@ -39,24 +45,35 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : UserService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): UserService.WithRawResponse = + UserServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: UserRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("userId", params.userId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "user", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -69,7 +86,6 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: UserListParams, @@ -78,12 +94,13 @@ class UserServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "user") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewService.kt index f997b1b2..ee428b59 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.View @@ -13,6 +14,7 @@ import com.braintrustdata.api.models.ViewReplaceParams import com.braintrustdata.api.models.ViewRetrieveParams import com.braintrustdata.api.models.ViewUpdateParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface ViewService { @@ -21,22 +23,40 @@ interface ViewService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ViewService + /** * Create a new view. If there is an existing view with the same name as the one specified in * the request, will return the existing view unmodified */ fun create(params: ViewCreateParams): View = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ fun create( params: ViewCreateParams, requestOptions: RequestOptions = RequestOptions.none(), ): View /** Get a view object by its id */ + fun retrieve(viewId: String, params: ViewRetrieveParams): View = + retrieve(viewId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + viewId: String, + params: ViewRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): View = retrieve(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see retrieve */ fun retrieve(params: ViewRetrieveParams): View = retrieve(params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ fun retrieve( params: ViewRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -47,9 +67,20 @@ interface ViewService { * fields will be deep-merged with existing content. Currently we do not support removing fields * or setting them to null. */ + fun update(viewId: String, params: ViewUpdateParams): View = + update(viewId, params, RequestOptions.none()) + + /** @see update */ + fun update( + viewId: String, + params: ViewUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): View = update(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see update */ fun update(params: ViewUpdateParams): View = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update( params: ViewUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -61,16 +92,27 @@ interface ViewService { */ fun list(params: ViewListParams): ViewListPage = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ fun list( params: ViewListParams, requestOptions: RequestOptions = RequestOptions.none(), ): ViewListPage /** Delete a view object by its id */ + fun delete(viewId: String, params: ViewDeleteParams): View = + delete(viewId, params, RequestOptions.none()) + + /** @see delete */ + fun delete( + viewId: String, + params: ViewDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): View = delete(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see delete */ fun delete(params: ViewDeleteParams): View = delete(params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ fun delete( params: ViewDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -82,7 +124,7 @@ interface ViewService { */ fun replace(params: ViewReplaceParams): View = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ fun replace( params: ViewReplaceParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -91,6 +133,13 @@ interface ViewService { /** A view of [ViewService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ViewService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/view`, but is otherwise the same as * [ViewService.create]. @@ -99,7 +148,7 @@ interface ViewService { fun create(params: ViewCreateParams): HttpResponseFor = create(params, RequestOptions.none()) - /** @see [create] */ + /** @see create */ @MustBeClosed fun create( params: ViewCreateParams, @@ -111,10 +160,24 @@ interface ViewService { * [ViewService.retrieve]. */ @MustBeClosed + fun retrieve(viewId: String, params: ViewRetrieveParams): HttpResponseFor = + retrieve(viewId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + viewId: String, + params: ViewRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed fun retrieve(params: ViewRetrieveParams): HttpResponseFor = retrieve(params, RequestOptions.none()) - /** @see [retrieve] */ + /** @see retrieve */ @MustBeClosed fun retrieve( params: ViewRetrieveParams, @@ -126,10 +189,23 @@ interface ViewService { * [ViewService.update]. */ @MustBeClosed + fun update(viewId: String, params: ViewUpdateParams): HttpResponseFor = + update(viewId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + viewId: String, + params: ViewUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = update(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see update */ + @MustBeClosed fun update(params: ViewUpdateParams): HttpResponseFor = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ @MustBeClosed fun update( params: ViewUpdateParams, @@ -144,7 +220,7 @@ interface ViewService { fun list(params: ViewListParams): HttpResponseFor = list(params, RequestOptions.none()) - /** @see [list] */ + /** @see list */ @MustBeClosed fun list( params: ViewListParams, @@ -156,10 +232,23 @@ interface ViewService { * [ViewService.delete]. */ @MustBeClosed + fun delete(viewId: String, params: ViewDeleteParams): HttpResponseFor = + delete(viewId, params, RequestOptions.none()) + + /** @see delete */ + @MustBeClosed + fun delete( + viewId: String, + params: ViewDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = delete(params.toBuilder().viewId(viewId).build(), requestOptions) + + /** @see delete */ + @MustBeClosed fun delete(params: ViewDeleteParams): HttpResponseFor = delete(params, RequestOptions.none()) - /** @see [delete] */ + /** @see delete */ @MustBeClosed fun delete( params: ViewDeleteParams, @@ -174,7 +263,7 @@ interface ViewService { fun replace(params: ViewReplaceParams): HttpResponseFor = replace(params, RequestOptions.none()) - /** @see [replace] */ + /** @see replace */ @MustBeClosed fun replace( params: ViewReplaceParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt index 823fa36e..6fcff875 100755 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/ViewServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -24,6 +25,8 @@ import com.braintrustdata.api.models.ViewListParams import com.braintrustdata.api.models.ViewReplaceParams import com.braintrustdata.api.models.ViewRetrieveParams import com.braintrustdata.api.models.ViewUpdateParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class ViewServiceImpl internal constructor(private val clientOptions: ClientOptions) : ViewService { @@ -33,6 +36,9 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti override fun withRawResponse(): ViewService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): ViewService = + ViewServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun create(params: ViewCreateParams, requestOptions: RequestOptions): View = // post /v1/view withRawResponse().create(params, requestOptions).parse() @@ -60,10 +66,17 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ViewService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ViewService.WithRawResponse = + ViewServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: ViewCreateParams, @@ -72,13 +85,14 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -89,22 +103,25 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: ViewRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("viewId", params.viewId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view", params._pathParam(0)) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -115,23 +132,26 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: ViewUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("viewId", params.viewId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -144,7 +164,6 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ViewListParams, @@ -153,12 +172,13 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -176,23 +196,26 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val deleteHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun delete( params: ViewDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("viewId", params.viewId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view", params._pathParam(0)) .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deleteHandler.handle(it) } .also { @@ -203,8 +226,7 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val replaceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val replaceHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun replace( params: ViewReplaceParams, @@ -213,13 +235,14 @@ class ViewServiceImpl internal constructor(private val clientOptions: ClientOpti val request = HttpRequest.builder() .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "view") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { replaceHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberService.kt index d6298636..d664ed0e 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberService.kt @@ -2,11 +2,13 @@ package com.braintrustdata.api.services.blocking.organizations +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.OrganizationMemberUpdateParams import com.braintrustdata.api.models.PatchOrganizationMembersOutput import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface MemberService { @@ -15,27 +17,41 @@ interface MemberService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): MemberService + /** Modify organization membership */ fun update(): PatchOrganizationMembersOutput = update(OrganizationMemberUpdateParams.none()) - /** @see [update] */ + /** @see update */ fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): PatchOrganizationMembersOutput - /** @see [update] */ + /** @see update */ fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none() ): PatchOrganizationMembersOutput = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ fun update(requestOptions: RequestOptions): PatchOrganizationMembersOutput = update(OrganizationMemberUpdateParams.none(), requestOptions) /** A view of [MemberService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): MemberService.WithRawResponse + /** * Returns a raw HTTP response for `patch /v1/organization/members`, but is otherwise the * same as [MemberService.update]. @@ -44,20 +60,20 @@ interface MemberService { fun update(): HttpResponseFor = update(OrganizationMemberUpdateParams.none()) - /** @see [update] */ + /** @see update */ @MustBeClosed fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none(), requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see [update] */ + /** @see update */ @MustBeClosed fun update( params: OrganizationMemberUpdateParams = OrganizationMemberUpdateParams.none() ): HttpResponseFor = update(params, RequestOptions.none()) - /** @see [update] */ + /** @see update */ @MustBeClosed fun update( requestOptions: RequestOptions diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt index df56e162..23d69d69 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/organizations/MemberServiceImpl.kt @@ -3,13 +3,13 @@ package com.braintrustdata.api.services.blocking.organizations import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -17,6 +17,7 @@ import com.braintrustdata.api.core.http.parseable import com.braintrustdata.api.core.prepare import com.braintrustdata.api.models.OrganizationMemberUpdateParams import com.braintrustdata.api.models.PatchOrganizationMembersOutput +import java.util.function.Consumer class MemberServiceImpl internal constructor(private val clientOptions: ClientOptions) : MemberService { @@ -27,6 +28,9 @@ class MemberServiceImpl internal constructor(private val clientOptions: ClientOp override fun withRawResponse(): MemberService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): MemberService = + MemberServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun update( params: OrganizationMemberUpdateParams, requestOptions: RequestOptions, @@ -37,11 +41,18 @@ class MemberServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MemberService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): MemberService.WithRawResponse = + MemberServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun update( params: OrganizationMemberUpdateParams, @@ -50,13 +61,14 @@ class MemberServiceImpl internal constructor(private val clientOptions: ClientOp val request = HttpRequest.builder() .method(HttpMethod.PATCH) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "organization", "members") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogService.kt index 3289dca2..c12218d3 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogService.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogService.kt @@ -2,6 +2,7 @@ package com.braintrustdata.api.services.blocking.projects +import com.braintrustdata.api.core.ClientOptions import com.braintrustdata.api.core.RequestOptions import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.models.FeedbackResponseSchema @@ -12,6 +13,7 @@ import com.braintrustdata.api.models.ProjectLogFetchParams import com.braintrustdata.api.models.ProjectLogFetchPostParams import com.braintrustdata.api.models.ProjectLogInsertParams import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer interface LogService { @@ -20,11 +22,30 @@ interface LogService { */ fun withRawResponse(): WithRawResponse + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): LogService + /** Log feedback for a set of project logs events */ + fun feedback(projectId: String, params: ProjectLogFeedbackParams): FeedbackResponseSchema = + feedback(projectId, params, RequestOptions.none()) + + /** @see feedback */ + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): FeedbackResponseSchema = + feedback(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see feedback */ fun feedback(params: ProjectLogFeedbackParams): FeedbackResponseSchema = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -35,34 +56,93 @@ interface LogService { * the parameters in the URL query rather than in the request body. For more complex queries, * use the `POST /btql` endpoint. */ - fun fetch(params: ProjectLogFetchParams): FetchProjectLogsEventsResponse = - fetch(params, RequestOptions.none()) + fun fetch(projectId: String): FetchProjectLogsEventsResponse = + fetch(projectId, ProjectLogFetchParams.none()) + + /** @see fetch */ + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): FetchProjectLogsEventsResponse = + fetch(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see fetch */ + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + ): FetchProjectLogsEventsResponse = fetch(projectId, params, RequestOptions.none()) - /** @see [fetch] */ + /** @see fetch */ fun fetch( params: ProjectLogFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): FetchProjectLogsEventsResponse + /** @see fetch */ + fun fetch(params: ProjectLogFetchParams): FetchProjectLogsEventsResponse = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + fun fetch(projectId: String, requestOptions: RequestOptions): FetchProjectLogsEventsResponse = + fetch(projectId, ProjectLogFetchParams.none(), requestOptions) + /** * Fetch the events in a project logs. Equivalent to the GET form of the same path, but with the * parameters in the request body rather than in the URL query. For more complex queries, use * the `POST /btql` endpoint. */ - fun fetchPost(params: ProjectLogFetchPostParams): FetchProjectLogsEventsResponse = - fetchPost(params, RequestOptions.none()) + fun fetchPost(projectId: String): FetchProjectLogsEventsResponse = + fetchPost(projectId, ProjectLogFetchPostParams.none()) + + /** @see fetchPost */ + fun fetchPost( + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): FetchProjectLogsEventsResponse = + fetchPost(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [fetchPost] */ + /** @see fetchPost */ + fun fetchPost( + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + ): FetchProjectLogsEventsResponse = fetchPost(projectId, params, RequestOptions.none()) + + /** @see fetchPost */ fun fetchPost( params: ProjectLogFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): FetchProjectLogsEventsResponse + /** @see fetchPost */ + fun fetchPost(params: ProjectLogFetchPostParams): FetchProjectLogsEventsResponse = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + fun fetchPost( + projectId: String, + requestOptions: RequestOptions, + ): FetchProjectLogsEventsResponse = + fetchPost(projectId, ProjectLogFetchPostParams.none(), requestOptions) + /** Insert a set of events into the project logs */ + fun insert(projectId: String, params: ProjectLogInsertParams): InsertEventsResponse = + insert(projectId, params, RequestOptions.none()) + + /** @see insert */ + fun insert( + projectId: String, + params: ProjectLogInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): InsertEventsResponse = + insert(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see insert */ fun insert(params: ProjectLogInsertParams): InsertEventsResponse = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ fun insert( params: ProjectLogInsertParams, requestOptions: RequestOptions = RequestOptions.none(), @@ -71,15 +151,39 @@ interface LogService { /** A view of [LogService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): LogService.WithRawResponse + /** * Returns a raw HTTP response for `post /v1/project_logs/{project_id}/feedback`, but is * otherwise the same as [LogService.feedback]. */ @MustBeClosed + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + ): HttpResponseFor = + feedback(projectId, params, RequestOptions.none()) + + /** @see feedback */ + @MustBeClosed + fun feedback( + projectId: String, + params: ProjectLogFeedbackParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + feedback(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see feedback */ + @MustBeClosed fun feedback(params: ProjectLogFeedbackParams): HttpResponseFor = feedback(params, RequestOptions.none()) - /** @see [feedback] */ + /** @see feedback */ @MustBeClosed fun feedback( params: ProjectLogFeedbackParams, @@ -91,42 +195,118 @@ interface LogService { * otherwise the same as [LogService.fetch]. */ @MustBeClosed - fun fetch(params: ProjectLogFetchParams): HttpResponseFor = - fetch(params, RequestOptions.none()) + fun fetch(projectId: String): HttpResponseFor = + fetch(projectId, ProjectLogFetchParams.none()) + + /** @see fetch */ + @MustBeClosed + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + fetch(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see fetch */ + @MustBeClosed + fun fetch( + projectId: String, + params: ProjectLogFetchParams = ProjectLogFetchParams.none(), + ): HttpResponseFor = + fetch(projectId, params, RequestOptions.none()) - /** @see [fetch] */ + /** @see fetch */ @MustBeClosed fun fetch( params: ProjectLogFetchParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see fetch */ + @MustBeClosed + fun fetch(params: ProjectLogFetchParams): HttpResponseFor = + fetch(params, RequestOptions.none()) + + /** @see fetch */ + @MustBeClosed + fun fetch( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + fetch(projectId, ProjectLogFetchParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/project_logs/{project_id}/fetch`, but is * otherwise the same as [LogService.fetchPost]. */ @MustBeClosed + fun fetchPost(projectId: String): HttpResponseFor = + fetchPost(projectId, ProjectLogFetchPostParams.none()) + + /** @see fetchPost */ + @MustBeClosed fun fetchPost( - params: ProjectLogFetchPostParams + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor = - fetchPost(params, RequestOptions.none()) + fetchPost(params.toBuilder().projectId(projectId).build(), requestOptions) - /** @see [fetchPost] */ + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + projectId: String, + params: ProjectLogFetchPostParams = ProjectLogFetchPostParams.none(), + ): HttpResponseFor = + fetchPost(projectId, params, RequestOptions.none()) + + /** @see fetchPost */ @MustBeClosed fun fetchPost( params: ProjectLogFetchPostParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + params: ProjectLogFetchPostParams + ): HttpResponseFor = + fetchPost(params, RequestOptions.none()) + + /** @see fetchPost */ + @MustBeClosed + fun fetchPost( + projectId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + fetchPost(projectId, ProjectLogFetchPostParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /v1/project_logs/{project_id}/insert`, but is * otherwise the same as [LogService.insert]. */ @MustBeClosed + fun insert( + projectId: String, + params: ProjectLogInsertParams, + ): HttpResponseFor = insert(projectId, params, RequestOptions.none()) + + /** @see insert */ + @MustBeClosed + fun insert( + projectId: String, + params: ProjectLogInsertParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + insert(params.toBuilder().projectId(projectId).build(), requestOptions) + + /** @see insert */ + @MustBeClosed fun insert(params: ProjectLogInsertParams): HttpResponseFor = insert(params, RequestOptions.none()) - /** @see [insert] */ + /** @see insert */ @MustBeClosed fun insert( params: ProjectLogInsertParams, diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt index ec5204b8..b2f5c6aa 100644 --- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt +++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/services/blocking/projects/LogServiceImpl.kt @@ -3,13 +3,14 @@ package com.braintrustdata.api.services.blocking.projects import com.braintrustdata.api.core.ClientOptions -import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.checkRequired +import com.braintrustdata.api.core.handlers.errorBodyHandler import com.braintrustdata.api.core.handlers.errorHandler import com.braintrustdata.api.core.handlers.jsonHandler -import com.braintrustdata.api.core.handlers.withErrorHandler import com.braintrustdata.api.core.http.HttpMethod import com.braintrustdata.api.core.http.HttpRequest +import com.braintrustdata.api.core.http.HttpResponse import com.braintrustdata.api.core.http.HttpResponse.Handler import com.braintrustdata.api.core.http.HttpResponseFor import com.braintrustdata.api.core.http.json @@ -22,6 +23,8 @@ import com.braintrustdata.api.models.ProjectLogFeedbackParams import com.braintrustdata.api.models.ProjectLogFetchParams import com.braintrustdata.api.models.ProjectLogFetchPostParams import com.braintrustdata.api.models.ProjectLogInsertParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull class LogServiceImpl internal constructor(private val clientOptions: ClientOptions) : LogService { @@ -31,6 +34,9 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio override fun withRawResponse(): LogService.WithRawResponse = withRawResponse + override fun withOptions(modifier: Consumer): LogService = + LogServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + override fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions, @@ -62,26 +68,37 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : LogService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): LogService.WithRawResponse = + LogServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) private val feedbackHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun feedback( params: ProjectLogFeedbackParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "feedback") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { feedbackHandler.handle(it) } .also { @@ -94,21 +111,24 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: ProjectLogFetchParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -121,22 +141,25 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio private val fetchPostHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchPost( params: ProjectLogFetchPostParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "fetch") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchPostHandler.handle(it) } .also { @@ -149,22 +172,25 @@ class LogServiceImpl internal constructor(private val clientOptions: ClientOptio private val insertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun insert( params: ProjectLogInsertParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("projectId", params.projectId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) .addPathSegments("v1", "project_logs", params._pathParam(0), "insert") .body(json(clientOptions.jsonMapper, params._body())) .build() .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { insertHandler.handle(it) } .also { diff --git a/braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro b/braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro new file mode 100644 index 00000000..02cd18c2 --- /dev/null +++ b/braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro @@ -0,0 +1,32 @@ +# Jackson uses reflection and depends heavily on runtime attributes. +-keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation* + +# Jackson uses Kotlin reflection utilities, which themselves use reflection to access things. +-keep class kotlin.reflect.** { *; } +-keep class kotlin.Metadata { *; } + +# Jackson uses reflection to access enum members (e.g. via `java.lang.Class.getEnumConstants()`). +-keepclassmembers class com.fasterxml.jackson.** extends java.lang.Enum { + ; + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# Jackson uses reflection to access annotation members. +-keepclassmembers @interface com.fasterxml.jackson.annotation.** { + *; +} + +# Jackson uses reified type information to serialize and deserialize our classes (via `TypeReference`). +-keep class com.fasterxml.jackson.core.type.TypeReference { *; } +-keep class * extends com.fasterxml.jackson.core.type.TypeReference { *; } + +# Jackson uses reflection to access our class serializers and deserializers. +-keep @com.fasterxml.jackson.databind.annotation.JsonSerialize class com.braintrustdata.api.** { *; } +-keep @com.fasterxml.jackson.databind.annotation.JsonDeserialize class com.braintrustdata.api.** { *; } + +# Jackson uses reflection to serialize and deserialize our classes based on their constructors and annotated members. +-keepclassmembers class com.braintrustdata.api.** { + (...); + @com.fasterxml.jackson.annotation.* *; +} \ No newline at end of file diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/AutoPagerAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/AutoPagerAsyncTest.kt new file mode 100644 index 00000000..df8e2d08 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/AutoPagerAsyncTest.kt @@ -0,0 +1,182 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +import com.braintrustdata.api.core.http.AsyncStreamResponse +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.any +import org.mockito.kotlin.clearInvocations +import org.mockito.kotlin.doAnswer +import org.mockito.kotlin.inOrder +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.spy +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +@ExtendWith(MockitoExtension::class) +internal class AutoPagerAsyncTest { + + companion object { + + private val ERROR = RuntimeException("ERROR!") + } + + private class PageAsyncImpl( + private val items: List, + private val hasNext: Boolean = true, + ) : PageAsync { + + val nextPageFuture: CompletableFuture> = CompletableFuture() + + override fun hasNextPage(): Boolean = hasNext + + override fun nextPage(): CompletableFuture> = nextPageFuture + + override fun items(): List = items + } + + private val executor = + spy { + doAnswer { invocation -> invocation.getArgument(0).run() } + .whenever(it) + .execute(any()) + } + private val handler = mock>() + + @Test + fun subscribe_whenAlreadySubscribed_throws() { + val autoPagerAsync = AutoPagerAsync.from(PageAsyncImpl(emptyList()), executor) + autoPagerAsync.subscribe {} + clearInvocations(executor) + + val throwable = catchThrowable { autoPagerAsync.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe more than once") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenClosed_throws() { + val autoPagerAsync = AutoPagerAsync.from(PageAsyncImpl(emptyList()), executor) + autoPagerAsync.close() + + val throwable = catchThrowable { autoPagerAsync.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe after the response is closed") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenFirstPageNonEmpty_runsHandler() { + val page = PageAsyncImpl(listOf("item1", "item2", "item3"), hasNext = false) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + + autoPagerAsync.subscribe(handler) + + inOrder(executor, handler) { + verify(executor, times(1)).execute(any()) + verify(handler, times(1)).onNext("item1") + verify(handler, times(1)).onNext("item2") + verify(handler, times(1)).onNext("item3") + verify(handler, times(1)).onComplete(Optional.empty()) + } + } + + @Test + fun subscribe_whenFutureCompletesAfterClose_doesNothing() { + val page = PageAsyncImpl(listOf("page1")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe(handler) + autoPagerAsync.close() + + page.nextPageFuture.complete(PageAsyncImpl(listOf("page2"))) + + verify(handler, times(1)).onNext("page1") + verify(handler, never()).onNext("page2") + verify(handler, times(1)).onComplete(Optional.empty()) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureErrors_callsOnComplete() { + val page = PageAsyncImpl(emptyList()) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe(handler) + + page.nextPageFuture.completeExceptionally(ERROR) + + verify(executor, times(1)).execute(any()) + verify(handler, never()).onNext(any()) + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + } + + @Test + fun subscribe_whenFutureCompletes_runsHandler() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + + autoPagerAsync.subscribe(handler) + + verify(handler, never()).onComplete(any()) + inOrder(executor, handler) { + verify(executor, times(1)).execute(any()) + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + } + clearInvocations(executor, handler) + + page.nextPageFuture.complete(PageAsyncImpl(listOf("chunk3", "chunk4"), hasNext = false)) + + verify(executor, never()).execute(any()) + inOrder(handler) { + verify(handler, times(1)).onNext("chunk3") + verify(handler, times(1)).onNext("chunk4") + verify(handler, times(1)).onComplete(Optional.empty()) + } + } + + @Test + fun onCompleteFuture_whenNextPageFutureNotCompleted_onCompleteFutureNotCompleted() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenNextPageFutureErrors_onCompleteFutureCompletedExceptionally() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + page.nextPageFuture.completeExceptionally(ERROR) + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenNoNextPage_onCompleteFutureCompleted() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2"), hasNext = false) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/AutoPagerTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/AutoPagerTest.kt new file mode 100644 index 00000000..d456fd7b --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/AutoPagerTest.kt @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AutoPagerTest { + + private class PageImpl( + private val items: List, + private val nextPage: Page? = null, + ) : Page { + + override fun hasNextPage(): Boolean = nextPage != null + + override fun nextPage(): Page = nextPage!! + + override fun items(): List = items + } + + @Test + fun iterator() { + val firstPage = + PageImpl(listOf("chunk1", "chunk2"), nextPage = PageImpl(listOf("chunk3", "chunk4"))) + + val autoPager = AutoPager.from(firstPage) + + assertThat(autoPager).containsExactly("chunk1", "chunk2", "chunk3", "chunk4") + } + + @Test + fun stream() { + val firstPage = + PageImpl(listOf("chunk1", "chunk2"), nextPage = PageImpl(listOf("chunk3", "chunk4"))) + + val autoPager = AutoPager.from(firstPage) + + assertThat(autoPager.stream()).containsExactly("chunk1", "chunk2", "chunk3", "chunk4") + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ClientOptionsTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ClientOptionsTest.kt new file mode 100644 index 00000000..9e5eb475 --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/ClientOptionsTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.core + +import com.braintrustdata.api.core.http.HttpClient +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.verify + +@ExtendWith(MockitoExtension::class) +internal class ClientOptionsTest { + + private val httpClient = mock() + + @Test + fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient() { + var clientOptions = + ClientOptions.builder().httpClient(httpClient).apiKey("My API Key").build() + verify(httpClient, never()).close() + + // Overwrite the `clientOptions` variable so that the original `ClientOptions` is GC'd. + clientOptions = clientOptions.toBuilder().build() + System.gc() + Thread.sleep(100) + + verify(httpClient, never()).close() + // This exists so that `clientOptions` is still reachable. + assertThat(clientOptions).isEqualTo(clientOptions) + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponseTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponseTest.kt new file mode 100644 index 00000000..a622292c --- /dev/null +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponseTest.kt @@ -0,0 +1,268 @@ +package com.braintrustdata.api.core.http + +import java.util.* +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.stream.Stream +import kotlin.streams.asStream +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.* + +@ExtendWith(MockitoExtension::class) +internal class AsyncStreamResponseTest { + + companion object { + private val ERROR = RuntimeException("ERROR!") + } + + private val streamResponse = + spy> { + doReturn(Stream.of("chunk1", "chunk2", "chunk3")).whenever(it).stream() + } + private val erroringStreamResponse = + spy> { + doReturn( + sequence { + yield("chunk1") + yield("chunk2") + throw ERROR + } + .asStream() + ) + .whenever(it) + .stream() + } + private val executor = + spy { + doAnswer { invocation -> invocation.getArgument(0).run() } + .whenever(it) + .execute(any()) + } + private val handler = mock>() + + @Test + fun subscribe_whenAlreadySubscribed_throws() { + val asyncStreamResponse = CompletableFuture>().toAsync(executor) + asyncStreamResponse.subscribe {} + + val throwable = catchThrowable { asyncStreamResponse.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe more than once") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenClosed_throws() { + val asyncStreamResponse = CompletableFuture>().toAsync(executor) + asyncStreamResponse.close() + + val throwable = catchThrowable { asyncStreamResponse.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe after the response is closed") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenFutureCompletesAfterClose_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + asyncStreamResponse.close() + + future.complete(streamResponse) + + verify(handler, never()).onNext(any()) + verify(handler, never()).onComplete(any()) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureErrors_callsOnComplete() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.completeExceptionally(ERROR) + + verify(handler, never()).onNext(any()) + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureCompletes_runsHandler() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.complete(streamResponse) + + inOrder(handler, streamResponse) { + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + verify(handler, times(1)).onNext("chunk3") + verify(handler, times(1)).onComplete(Optional.empty()) + verify(streamResponse, times(1)).close() + } + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenStreamErrors_callsOnCompleteEarly() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.complete(erroringStreamResponse) + + inOrder(handler, erroringStreamResponse) { + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + verify(erroringStreamResponse, times(1)).close() + } + verify(executor, times(1)).execute(any()) + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureNotCompleted_onCompleteFutureNotCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureErrors_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + future.completeExceptionally(ERROR) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedButStillStreaming_onCompleteFutureNotCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedAndStreamErrors_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + future.complete(erroringStreamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedAndStreamCompleted_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun onCompleteFuture_whenHandlerOnCompleteWithoutThrowableThrows_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe( + object : AsyncStreamResponse.Handler { + override fun onNext(value: String) {} + + override fun onComplete(error: Optional) = throw ERROR + } + ) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun onCompleteFuture_whenHandlerOnCompleteWithThrowableThrows_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe( + object : AsyncStreamResponse.Handler { + override fun onNext(value: String) {} + + override fun onComplete(error: Optional) = throw ERROR + } + ) + future.complete(erroringStreamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenClosed_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun close_whenNotClosed_closesStreamResponse() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + + asyncStreamResponse.close() + future.complete(streamResponse) + + verify(streamResponse, times(1)).close() + } + + @Test + fun close_whenAlreadyClosed_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + future.complete(streamResponse) + + asyncStreamResponse.close() + + verify(streamResponse, times(1)).close() + } + + @Test + fun close_whenFutureErrors_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + + assertDoesNotThrow { future.completeExceptionally(ERROR) } + } +} diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt index cb68648b..c34665e3 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/core/http/RetryingHttpClientTest.kt @@ -2,6 +2,8 @@ package com.braintrustdata.api.core.http import com.braintrustdata.api.client.okhttp.OkHttpClient import com.braintrustdata.api.core.RequestOptions +import com.braintrustdata.api.core.Sleeper +import com.braintrustdata.api.errors.BraintrustRetryableException import com.github.tomakehurst.wiremock.client.WireMock.* import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest @@ -20,11 +22,13 @@ import org.junit.jupiter.params.provider.ValueSource internal class RetryingHttpClientTest { private var openResponseCount = 0 + private lateinit var baseUrl: String private lateinit var httpClient: HttpClient @BeforeEach fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) { - val okHttpClient = OkHttpClient.builder().baseUrl(wmRuntimeInfo.httpBaseUrl).build() + baseUrl = wmRuntimeInfo.httpBaseUrl + val okHttpClient = OkHttpClient.builder().build() httpClient = object : HttpClient { @@ -75,7 +79,11 @@ internal class RetryingHttpClientTest { val response = retryingClient.execute( - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build(), async, ) @@ -97,7 +105,11 @@ internal class RetryingHttpClientTest { val response = retryingClient.execute( - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build(), async, ) @@ -139,7 +151,11 @@ internal class RetryingHttpClientTest { val response = retryingClient.execute( - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build(), async, ) @@ -187,6 +203,7 @@ internal class RetryingHttpClientTest { retryingClient.execute( HttpRequest.builder() .method(HttpMethod.POST) + .baseUrl(baseUrl) .addPathSegment("something") .putHeader("x-stainless-retry-count", "42") .build(), @@ -223,7 +240,11 @@ internal class RetryingHttpClientTest { val response = retryingClient.execute( - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build(), async, ) @@ -232,17 +253,97 @@ internal class RetryingHttpClientTest { assertNoResponseLeaks() } + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun execute_withRetryableException(async: Boolean) { + stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) + + var callCount = 0 + val failingHttpClient = + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions, + ): HttpResponse { + callCount++ + if (callCount == 1) { + throw BraintrustRetryableException("Simulated retryable failure") + } + return httpClient.execute(request, requestOptions) + } + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions, + ): CompletableFuture { + callCount++ + if (callCount == 1) { + val future = CompletableFuture() + future.completeExceptionally( + BraintrustRetryableException("Simulated retryable failure") + ) + return future + } + return httpClient.executeAsync(request, requestOptions) + } + + override fun close() = httpClient.close() + } + + val retryingClient = + RetryingHttpClient.builder() + .httpClient(failingHttpClient) + .maxRetries(2) + .sleeper( + object : Sleeper { + + override fun sleep(duration: Duration) {} + + override fun sleepAsync(duration: Duration): CompletableFuture = + CompletableFuture.completedFuture(null) + + override fun close() {} + } + ) + .build() + + val response = + retryingClient.execute( + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build(), + async, + ) + + assertThat(response.statusCode()).isEqualTo(200) + verify( + 1, + postRequestedFor(urlPathEqualTo("/something")) + .withHeader("x-stainless-retry-count", equalTo("1")), + ) + verify( + 0, + postRequestedFor(urlPathEqualTo("/something")) + .withHeader("x-stainless-retry-count", equalTo("0")), + ) + assertNoResponseLeaks() + } + private fun retryingHttpClientBuilder() = RetryingHttpClient.builder() .httpClient(httpClient) // Use a no-op `Sleeper` to make the test fast. .sleeper( - object : RetryingHttpClient.Sleeper { + object : Sleeper { override fun sleep(duration: Duration) {} override fun sleepAsync(duration: Duration): CompletableFuture = CompletableFuture.completedFuture(null) + + override fun close() {} } ) diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt index d1b745a7..7be04bf5 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/ErrorHandlingTest.kt @@ -80,6 +80,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate400WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(400).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(400) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate401() { val projectService = client.projects() @@ -102,6 +124,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate401WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(401).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(401) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate403() { val projectService = client.projects() @@ -124,6 +168,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate403WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(403).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(403) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate404() { val projectService = client.projects() @@ -146,6 +212,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate404WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(404).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(404) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate422() { val projectService = client.projects() @@ -168,6 +256,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate422WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(422).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(422) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate429() { val projectService = client.projects() @@ -190,6 +300,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate429WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(429).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(429) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate500() { val projectService = client.projects() @@ -212,6 +344,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate500WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(500).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(500) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreate999() { val projectService = client.projects() @@ -234,6 +388,28 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun projectsCreate999WithRawResponse() { + val projectService = client.projects().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(999).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + projectService.create( + ProjectCreateParams.builder().name("x").orgName("org_name").build() + ) + } + + assertThat(e.statusCode()).isEqualTo(999) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun projectsCreateInvalidJsonBody() { val projectService = client.projects() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncTest.kt index 97eca503..0be8c044 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AclServiceAsyncTest.kt @@ -6,11 +6,9 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.AclBatchUpdateParams import com.braintrustdata.api.models.AclCreateParams -import com.braintrustdata.api.models.AclDeleteParams import com.braintrustdata.api.models.AclFindAndDeleteParams import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclObjectType -import com.braintrustdata.api.models.AclRetrieveParams import com.braintrustdata.api.models.Permission import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -53,10 +51,7 @@ internal class AclServiceAsyncTest { .build() val aclServiceAsync = client.acls() - val aclFuture = - aclServiceAsync.retrieve( - AclRetrieveParams.builder().aclId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val aclFuture = aclServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val acl = aclFuture.get() acl.validate() @@ -92,10 +87,7 @@ internal class AclServiceAsyncTest { .build() val aclServiceAsync = client.acls() - val aclFuture = - aclServiceAsync.delete( - AclDeleteParams.builder().aclId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val aclFuture = aclServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val acl = aclFuture.get() acl.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncTest.kt index f9dd58e3..a4eed2d1 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/AiSecretServiceAsyncTest.kt @@ -6,10 +6,8 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.AiSecretCreateParams -import com.braintrustdata.api.models.AiSecretDeleteParams import com.braintrustdata.api.models.AiSecretFindAndDeleteParams import com.braintrustdata.api.models.AiSecretReplaceParams -import com.braintrustdata.api.models.AiSecretRetrieveParams import com.braintrustdata.api.models.AiSecretUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -54,12 +52,7 @@ internal class AiSecretServiceAsyncTest { .build() val aiSecretServiceAsync = client.aiSecrets() - val aISecretFuture = - aiSecretServiceAsync.retrieve( - AiSecretRetrieveParams.builder() - .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val aISecretFuture = aiSecretServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val aISecret = aISecretFuture.get() aISecret.validate() @@ -117,12 +110,7 @@ internal class AiSecretServiceAsyncTest { .build() val aiSecretServiceAsync = client.aiSecrets() - val aISecretFuture = - aiSecretServiceAsync.delete( - AiSecretDeleteParams.builder() - .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val aISecretFuture = aiSecretServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val aISecret = aISecretFuture.get() aISecret.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncTest.kt index 71d9172a..5b6ce107 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ApiKeyServiceAsyncTest.kt @@ -5,8 +5,6 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.ApiKeyCreateParams -import com.braintrustdata.api.models.ApiKeyDeleteParams -import com.braintrustdata.api.models.ApiKeyRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -40,12 +38,7 @@ internal class ApiKeyServiceAsyncTest { .build() val apiKeyServiceAsync = client.apiKeys() - val apiKeyFuture = - apiKeyServiceAsync.retrieve( - ApiKeyRetrieveParams.builder() - .apiKeyId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val apiKeyFuture = apiKeyServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val apiKey = apiKeyFuture.get() apiKey.validate() @@ -75,12 +68,7 @@ internal class ApiKeyServiceAsyncTest { .build() val apiKeyServiceAsync = client.apiKeys() - val apiKeyFuture = - apiKeyServiceAsync.delete( - ApiKeyDeleteParams.builder() - .apiKeyId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val apiKeyFuture = apiKeyServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val apiKey = apiKeyFuture.get() apiKey.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncTest.kt index dba276c4..abda8106 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/DatasetServiceAsyncTest.kt @@ -6,12 +6,10 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.DatasetCreateParams -import com.braintrustdata.api.models.DatasetDeleteParams import com.braintrustdata.api.models.DatasetFeedbackParams import com.braintrustdata.api.models.DatasetFetchParams import com.braintrustdata.api.models.DatasetFetchPostParams import com.braintrustdata.api.models.DatasetInsertParams -import com.braintrustdata.api.models.DatasetRetrieveParams import com.braintrustdata.api.models.DatasetSummarizeParams import com.braintrustdata.api.models.DatasetUpdateParams import com.braintrustdata.api.models.FeedbackDatasetItem @@ -60,12 +58,7 @@ internal class DatasetServiceAsyncTest { .build() val datasetServiceAsync = client.datasets() - val datasetFuture = - datasetServiceAsync.retrieve( - DatasetRetrieveParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val datasetFuture = datasetServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val dataset = datasetFuture.get() dataset.validate() @@ -122,12 +115,7 @@ internal class DatasetServiceAsyncTest { .build() val datasetServiceAsync = client.datasets() - val datasetFuture = - datasetServiceAsync.delete( - DatasetDeleteParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val datasetFuture = datasetServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val dataset = datasetFuture.get() dataset.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt index f17f8a4e..eeb42915 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/EnvVarServiceAsyncTest.kt @@ -5,11 +5,9 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.EnvVarCreateParams -import com.braintrustdata.api.models.EnvVarDeleteParams import com.braintrustdata.api.models.EnvVarListParams import com.braintrustdata.api.models.EnvVarObjectType import com.braintrustdata.api.models.EnvVarReplaceParams -import com.braintrustdata.api.models.EnvVarRetrieveParams import com.braintrustdata.api.models.EnvVarUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -49,12 +47,7 @@ internal class EnvVarServiceAsyncTest { .build() val envVarServiceAsync = client.envVars() - val envVarFuture = - envVarServiceAsync.retrieve( - EnvVarRetrieveParams.builder() - .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val envVarFuture = envVarServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val envVar = envVarFuture.get() envVar.validate() @@ -115,12 +108,7 @@ internal class EnvVarServiceAsyncTest { .build() val envVarServiceAsync = client.envVars() - val envVarFuture = - envVarServiceAsync.delete( - EnvVarDeleteParams.builder() - .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val envVarFuture = envVarServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val envVar = envVarFuture.get() envVar.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncTest.kt index 854ef1dd..1c558edb 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ExperimentServiceAsyncTest.kt @@ -6,12 +6,10 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.ExperimentCreateParams -import com.braintrustdata.api.models.ExperimentDeleteParams import com.braintrustdata.api.models.ExperimentFeedbackParams import com.braintrustdata.api.models.ExperimentFetchParams import com.braintrustdata.api.models.ExperimentFetchPostParams import com.braintrustdata.api.models.ExperimentInsertParams -import com.braintrustdata.api.models.ExperimentRetrieveParams import com.braintrustdata.api.models.ExperimentSummarizeParams import com.braintrustdata.api.models.ExperimentUpdateParams import com.braintrustdata.api.models.FeedbackExperimentItem @@ -82,11 +80,7 @@ internal class ExperimentServiceAsyncTest { val experimentServiceAsync = client.experiments() val experimentFuture = - experimentServiceAsync.retrieve( - ExperimentRetrieveParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + experimentServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val experiment = experimentFuture.get() experiment.validate() @@ -160,12 +154,7 @@ internal class ExperimentServiceAsyncTest { .build() val experimentServiceAsync = client.experiments() - val experimentFuture = - experimentServiceAsync.delete( - ExperimentDeleteParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val experimentFuture = experimentServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val experiment = experimentFuture.get() experiment.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncTest.kt index 74787883..279f89c4 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/FunctionServiceAsyncTest.kt @@ -7,10 +7,8 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.AclObjectType import com.braintrustdata.api.models.FunctionCreateParams -import com.braintrustdata.api.models.FunctionDeleteParams import com.braintrustdata.api.models.FunctionInvokeParams import com.braintrustdata.api.models.FunctionReplaceParams -import com.braintrustdata.api.models.FunctionRetrieveParams import com.braintrustdata.api.models.FunctionUpdateParams import com.braintrustdata.api.models.PromptData import com.braintrustdata.api.models.PromptOptions @@ -155,12 +153,7 @@ internal class FunctionServiceAsyncTest { .build() val functionServiceAsync = client.functions() - val functionFuture = - functionServiceAsync.retrieve( - FunctionRetrieveParams.builder() - .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val functionFuture = functionServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val function = functionFuture.get() function.validate() @@ -300,12 +293,7 @@ internal class FunctionServiceAsyncTest { .build() val functionServiceAsync = client.functions() - val functionFuture = - functionServiceAsync.delete( - FunctionDeleteParams.builder() - .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val functionFuture = functionServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val function = functionFuture.get() function.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncTest.kt index 5b8f2e23..ea16d5e2 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/GroupServiceAsyncTest.kt @@ -5,9 +5,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.GroupCreateParams -import com.braintrustdata.api.models.GroupDeleteParams import com.braintrustdata.api.models.GroupReplaceParams -import com.braintrustdata.api.models.GroupRetrieveParams import com.braintrustdata.api.models.GroupUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -48,12 +46,7 @@ internal class GroupServiceAsyncTest { .build() val groupServiceAsync = client.groups() - val groupFuture = - groupServiceAsync.retrieve( - GroupRetrieveParams.builder() - .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val groupFuture = groupServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val group = groupFuture.get() group.validate() @@ -109,10 +102,7 @@ internal class GroupServiceAsyncTest { .build() val groupServiceAsync = client.groups() - val groupFuture = - groupServiceAsync.delete( - GroupDeleteParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val groupFuture = groupServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val group = groupFuture.get() group.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncTest.kt index 17e8d406..d25afe9f 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/OrganizationServiceAsyncTest.kt @@ -4,8 +4,6 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync -import com.braintrustdata.api.models.OrganizationDeleteParams -import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -23,11 +21,7 @@ internal class OrganizationServiceAsyncTest { val organizationServiceAsync = client.organizations() val organizationFuture = - organizationServiceAsync.retrieve( - OrganizationRetrieveParams.builder() - .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + organizationServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val organization = organizationFuture.get() organization.validate() @@ -83,11 +77,7 @@ internal class OrganizationServiceAsyncTest { val organizationServiceAsync = client.organizations() val organizationFuture = - organizationServiceAsync.delete( - OrganizationDeleteParams.builder() - .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + organizationServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val organization = organizationFuture.get() organization.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncTest.kt index cf9b25d3..9114be85 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectScoreServiceAsyncTest.kt @@ -8,9 +8,7 @@ import com.braintrustdata.api.models.OnlineScoreConfig import com.braintrustdata.api.models.ProjectScoreCategory import com.braintrustdata.api.models.ProjectScoreConfig import com.braintrustdata.api.models.ProjectScoreCreateParams -import com.braintrustdata.api.models.ProjectScoreDeleteParams import com.braintrustdata.api.models.ProjectScoreReplaceParams -import com.braintrustdata.api.models.ProjectScoreRetrieveParams import com.braintrustdata.api.models.ProjectScoreType import com.braintrustdata.api.models.ProjectScoreUpdateParams import org.junit.jupiter.api.Test @@ -74,11 +72,7 @@ internal class ProjectScoreServiceAsyncTest { val projectScoreServiceAsync = client.projectScores() val projectScoreFuture = - projectScoreServiceAsync.retrieve( - ProjectScoreRetrieveParams.builder() - .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + projectScoreServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val projectScore = projectScoreFuture.get() projectScore.validate() @@ -154,11 +148,7 @@ internal class ProjectScoreServiceAsyncTest { val projectScoreServiceAsync = client.projectScores() val projectScoreFuture = - projectScoreServiceAsync.delete( - ProjectScoreDeleteParams.builder() - .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + projectScoreServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val projectScore = projectScoreFuture.get() projectScore.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncTest.kt index 79ae13f8..9e476bd8 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectServiceAsyncTest.kt @@ -5,8 +5,6 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.ProjectCreateParams -import com.braintrustdata.api.models.ProjectDeleteParams -import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectSettings import com.braintrustdata.api.models.ProjectUpdateParams import org.junit.jupiter.api.Test @@ -42,12 +40,7 @@ internal class ProjectServiceAsyncTest { .build() val projectServiceAsync = client.projects() - val projectFuture = - projectServiceAsync.retrieve( - ProjectRetrieveParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectFuture = projectServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val project = projectFuture.get() project.validate() @@ -112,12 +105,7 @@ internal class ProjectServiceAsyncTest { .build() val projectServiceAsync = client.projects() - val projectFuture = - projectServiceAsync.delete( - ProjectDeleteParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectFuture = projectServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val project = projectFuture.get() project.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncTest.kt index 8f4ee746..6513ddc2 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/ProjectTagServiceAsyncTest.kt @@ -5,9 +5,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.ProjectTagCreateParams -import com.braintrustdata.api.models.ProjectTagDeleteParams import com.braintrustdata.api.models.ProjectTagReplaceParams -import com.braintrustdata.api.models.ProjectTagRetrieveParams import com.braintrustdata.api.models.ProjectTagUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -48,11 +46,7 @@ internal class ProjectTagServiceAsyncTest { val projectTagServiceAsync = client.projectTags() val projectTagFuture = - projectTagServiceAsync.retrieve( - ProjectTagRetrieveParams.builder() - .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + projectTagServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val projectTag = projectTagFuture.get() projectTag.validate() @@ -105,12 +99,7 @@ internal class ProjectTagServiceAsyncTest { .build() val projectTagServiceAsync = client.projectTags() - val projectTagFuture = - projectTagServiceAsync.delete( - ProjectTagDeleteParams.builder() - .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectTagFuture = projectTagServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val projectTag = projectTagFuture.get() projectTag.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncTest.kt index 2216c197..23704cdd 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/PromptServiceAsyncTest.kt @@ -7,10 +7,8 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.PromptCreateParams import com.braintrustdata.api.models.PromptData -import com.braintrustdata.api.models.PromptDeleteParams import com.braintrustdata.api.models.PromptOptions import com.braintrustdata.api.models.PromptReplaceParams -import com.braintrustdata.api.models.PromptRetrieveParams import com.braintrustdata.api.models.PromptUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -134,12 +132,7 @@ internal class PromptServiceAsyncTest { .build() val promptServiceAsync = client.prompts() - val promptFuture = - promptServiceAsync.retrieve( - PromptRetrieveParams.builder() - .promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val promptFuture = promptServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val prompt = promptFuture.get() prompt.validate() @@ -275,12 +268,7 @@ internal class PromptServiceAsyncTest { .build() val promptServiceAsync = client.prompts() - val promptFuture = - promptServiceAsync.delete( - PromptDeleteParams.builder() - .promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val promptFuture = promptServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val prompt = promptFuture.get() prompt.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncTest.kt index 45d60fc2..ac57e006 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/RoleServiceAsyncTest.kt @@ -7,9 +7,7 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.AclObjectType import com.braintrustdata.api.models.Permission import com.braintrustdata.api.models.RoleCreateParams -import com.braintrustdata.api.models.RoleDeleteParams import com.braintrustdata.api.models.RoleReplaceParams -import com.braintrustdata.api.models.RoleRetrieveParams import com.braintrustdata.api.models.RoleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -55,10 +53,7 @@ internal class RoleServiceAsyncTest { .build() val roleServiceAsync = client.roles() - val roleFuture = - roleServiceAsync.retrieve( - RoleRetrieveParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val roleFuture = roleServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val role = roleFuture.get() role.validate() @@ -124,10 +119,7 @@ internal class RoleServiceAsyncTest { .build() val roleServiceAsync = client.roles() - val roleFuture = - roleServiceAsync.delete( - RoleDeleteParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val roleFuture = roleServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val role = roleFuture.get() role.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncTest.kt index 7f3f4d1c..1f3a44e0 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/SpanIframeServiceAsyncTest.kt @@ -5,9 +5,7 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync import com.braintrustdata.api.models.SpanIframeCreateParams -import com.braintrustdata.api.models.SpanIframeDeleteParams import com.braintrustdata.api.models.SpanIframeReplaceParams -import com.braintrustdata.api.models.SpanIframeRetrieveParams import com.braintrustdata.api.models.SpanIframeUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -49,11 +47,7 @@ internal class SpanIframeServiceAsyncTest { val spanIframeServiceAsync = client.spanIframes() val spanIFrameFuture = - spanIframeServiceAsync.retrieve( - SpanIframeRetrieveParams.builder() - .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + spanIframeServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val spanIFrame = spanIFrameFuture.get() spanIFrame.validate() @@ -107,12 +101,7 @@ internal class SpanIframeServiceAsyncTest { .build() val spanIframeServiceAsync = client.spanIframes() - val spanIFrameFuture = - spanIframeServiceAsync.delete( - SpanIframeDeleteParams.builder() - .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val spanIFrameFuture = spanIframeServiceAsync.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val spanIFrame = spanIFrameFuture.get() spanIFrame.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncTest.kt index 39fa2e1c..3352ae50 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/async/UserServiceAsyncTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.services.async import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClientAsync -import com.braintrustdata.api.models.UserRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,10 +19,7 @@ internal class UserServiceAsyncTest { .build() val userServiceAsync = client.users() - val userFuture = - userServiceAsync.retrieve( - UserRetrieveParams.builder().userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val userFuture = userServiceAsync.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") val user = userFuture.get() user.validate() diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AclServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AclServiceTest.kt index f50e01c6..7838f8f7 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AclServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AclServiceTest.kt @@ -6,11 +6,9 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.AclBatchUpdateParams import com.braintrustdata.api.models.AclCreateParams -import com.braintrustdata.api.models.AclDeleteParams import com.braintrustdata.api.models.AclFindAndDeleteParams import com.braintrustdata.api.models.AclListParams import com.braintrustdata.api.models.AclObjectType -import com.braintrustdata.api.models.AclRetrieveParams import com.braintrustdata.api.models.Permission import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -52,10 +50,7 @@ internal class AclServiceTest { .build() val aclService = client.acls() - val acl = - aclService.retrieve( - AclRetrieveParams.builder().aclId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val acl = aclService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") acl.validate() } @@ -89,10 +84,7 @@ internal class AclServiceTest { .build() val aclService = client.acls() - val acl = - aclService.delete( - AclDeleteParams.builder().aclId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val acl = aclService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") acl.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceTest.kt index 6d9e6bd1..911cdcdb 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/AiSecretServiceTest.kt @@ -6,10 +6,8 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.AiSecretCreateParams -import com.braintrustdata.api.models.AiSecretDeleteParams import com.braintrustdata.api.models.AiSecretFindAndDeleteParams import com.braintrustdata.api.models.AiSecretReplaceParams -import com.braintrustdata.api.models.AiSecretRetrieveParams import com.braintrustdata.api.models.AiSecretUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -53,12 +51,7 @@ internal class AiSecretServiceTest { .build() val aiSecretService = client.aiSecrets() - val aISecret = - aiSecretService.retrieve( - AiSecretRetrieveParams.builder() - .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val aISecret = aiSecretService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") aISecret.validate() } @@ -113,12 +106,7 @@ internal class AiSecretServiceTest { .build() val aiSecretService = client.aiSecrets() - val aISecret = - aiSecretService.delete( - AiSecretDeleteParams.builder() - .aiSecretId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val aISecret = aiSecretService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") aISecret.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceTest.kt index 953d839e..471eaa44 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ApiKeyServiceTest.kt @@ -5,8 +5,6 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.ApiKeyCreateParams -import com.braintrustdata.api.models.ApiKeyDeleteParams -import com.braintrustdata.api.models.ApiKeyRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -39,12 +37,7 @@ internal class ApiKeyServiceTest { .build() val apiKeyService = client.apiKeys() - val apiKey = - apiKeyService.retrieve( - ApiKeyRetrieveParams.builder() - .apiKeyId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val apiKey = apiKeyService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") apiKey.validate() } @@ -72,12 +65,7 @@ internal class ApiKeyServiceTest { .build() val apiKeyService = client.apiKeys() - val apiKey = - apiKeyService.delete( - ApiKeyDeleteParams.builder() - .apiKeyId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val apiKey = apiKeyService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") apiKey.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceTest.kt index 3f79928e..b2f77a0b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/DatasetServiceTest.kt @@ -6,12 +6,10 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.DatasetCreateParams -import com.braintrustdata.api.models.DatasetDeleteParams import com.braintrustdata.api.models.DatasetFeedbackParams import com.braintrustdata.api.models.DatasetFetchParams import com.braintrustdata.api.models.DatasetFetchPostParams import com.braintrustdata.api.models.DatasetInsertParams -import com.braintrustdata.api.models.DatasetRetrieveParams import com.braintrustdata.api.models.DatasetSummarizeParams import com.braintrustdata.api.models.DatasetUpdateParams import com.braintrustdata.api.models.FeedbackDatasetItem @@ -59,12 +57,7 @@ internal class DatasetServiceTest { .build() val datasetService = client.datasets() - val dataset = - datasetService.retrieve( - DatasetRetrieveParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val dataset = datasetService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") dataset.validate() } @@ -118,12 +111,7 @@ internal class DatasetServiceTest { .build() val datasetService = client.datasets() - val dataset = - datasetService.delete( - DatasetDeleteParams.builder() - .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val dataset = datasetService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") dataset.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt index d57db964..04d3edce 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/EnvVarServiceTest.kt @@ -5,11 +5,9 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.EnvVarCreateParams -import com.braintrustdata.api.models.EnvVarDeleteParams import com.braintrustdata.api.models.EnvVarListParams import com.braintrustdata.api.models.EnvVarObjectType import com.braintrustdata.api.models.EnvVarReplaceParams -import com.braintrustdata.api.models.EnvVarRetrieveParams import com.braintrustdata.api.models.EnvVarUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -48,12 +46,7 @@ internal class EnvVarServiceTest { .build() val envVarService = client.envVars() - val envVar = - envVarService.retrieve( - EnvVarRetrieveParams.builder() - .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val envVar = envVarService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") envVar.validate() } @@ -111,12 +104,7 @@ internal class EnvVarServiceTest { .build() val envVarService = client.envVars() - val envVar = - envVarService.delete( - EnvVarDeleteParams.builder() - .envVarId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val envVar = envVarService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") envVar.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceTest.kt index 1f41453e..cccec10d 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ExperimentServiceTest.kt @@ -6,12 +6,10 @@ import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.ExperimentCreateParams -import com.braintrustdata.api.models.ExperimentDeleteParams import com.braintrustdata.api.models.ExperimentFeedbackParams import com.braintrustdata.api.models.ExperimentFetchParams import com.braintrustdata.api.models.ExperimentFetchPostParams import com.braintrustdata.api.models.ExperimentInsertParams -import com.braintrustdata.api.models.ExperimentRetrieveParams import com.braintrustdata.api.models.ExperimentSummarizeParams import com.braintrustdata.api.models.ExperimentUpdateParams import com.braintrustdata.api.models.FeedbackExperimentItem @@ -80,12 +78,7 @@ internal class ExperimentServiceTest { .build() val experimentService = client.experiments() - val experiment = - experimentService.retrieve( - ExperimentRetrieveParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val experiment = experimentService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") experiment.validate() } @@ -156,12 +149,7 @@ internal class ExperimentServiceTest { .build() val experimentService = client.experiments() - val experiment = - experimentService.delete( - ExperimentDeleteParams.builder() - .experimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val experiment = experimentService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") experiment.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt index 5666dd34..d22bb379 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/FunctionServiceTest.kt @@ -7,10 +7,8 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.AclObjectType import com.braintrustdata.api.models.FunctionCreateParams -import com.braintrustdata.api.models.FunctionDeleteParams import com.braintrustdata.api.models.FunctionInvokeParams import com.braintrustdata.api.models.FunctionReplaceParams -import com.braintrustdata.api.models.FunctionRetrieveParams import com.braintrustdata.api.models.FunctionUpdateParams import com.braintrustdata.api.models.PromptData import com.braintrustdata.api.models.PromptOptions @@ -154,12 +152,7 @@ internal class FunctionServiceTest { .build() val functionService = client.functions() - val function = - functionService.retrieve( - FunctionRetrieveParams.builder() - .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val function = functionService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") function.validate() } @@ -296,12 +289,7 @@ internal class FunctionServiceTest { .build() val functionService = client.functions() - val function = - functionService.delete( - FunctionDeleteParams.builder() - .functionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val function = functionService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") function.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/GroupServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/GroupServiceTest.kt index ef587787..480533ef 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/GroupServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/GroupServiceTest.kt @@ -5,9 +5,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.GroupCreateParams -import com.braintrustdata.api.models.GroupDeleteParams import com.braintrustdata.api.models.GroupReplaceParams -import com.braintrustdata.api.models.GroupRetrieveParams import com.braintrustdata.api.models.GroupUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -47,12 +45,7 @@ internal class GroupServiceTest { .build() val groupService = client.groups() - val group = - groupService.retrieve( - GroupRetrieveParams.builder() - .groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val group = groupService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") group.validate() } @@ -105,10 +98,7 @@ internal class GroupServiceTest { .build() val groupService = client.groups() - val group = - groupService.delete( - GroupDeleteParams.builder().groupId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val group = groupService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") group.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceTest.kt index 35ab34c7..c387c81b 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/OrganizationServiceTest.kt @@ -4,8 +4,6 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient -import com.braintrustdata.api.models.OrganizationDeleteParams -import com.braintrustdata.api.models.OrganizationRetrieveParams import com.braintrustdata.api.models.OrganizationUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -22,12 +20,7 @@ internal class OrganizationServiceTest { .build() val organizationService = client.organizations() - val organization = - organizationService.retrieve( - OrganizationRetrieveParams.builder() - .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val organization = organizationService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") organization.validate() } @@ -79,12 +72,7 @@ internal class OrganizationServiceTest { .build() val organizationService = client.organizations() - val organization = - organizationService.delete( - OrganizationDeleteParams.builder() - .organizationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val organization = organizationService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") organization.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceTest.kt index e09d814c..16d8e5ef 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectScoreServiceTest.kt @@ -8,9 +8,7 @@ import com.braintrustdata.api.models.OnlineScoreConfig import com.braintrustdata.api.models.ProjectScoreCategory import com.braintrustdata.api.models.ProjectScoreConfig import com.braintrustdata.api.models.ProjectScoreCreateParams -import com.braintrustdata.api.models.ProjectScoreDeleteParams import com.braintrustdata.api.models.ProjectScoreReplaceParams -import com.braintrustdata.api.models.ProjectScoreRetrieveParams import com.braintrustdata.api.models.ProjectScoreType import com.braintrustdata.api.models.ProjectScoreUpdateParams import org.junit.jupiter.api.Test @@ -72,12 +70,7 @@ internal class ProjectScoreServiceTest { .build() val projectScoreService = client.projectScores() - val projectScore = - projectScoreService.retrieve( - ProjectScoreRetrieveParams.builder() - .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectScore = projectScoreService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") projectScore.validate() } @@ -149,12 +142,7 @@ internal class ProjectScoreServiceTest { .build() val projectScoreService = client.projectScores() - val projectScore = - projectScoreService.delete( - ProjectScoreDeleteParams.builder() - .projectScoreId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectScore = projectScoreService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") projectScore.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceTest.kt index 8e31fe94..b179eb69 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectServiceTest.kt @@ -5,8 +5,6 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.ProjectCreateParams -import com.braintrustdata.api.models.ProjectDeleteParams -import com.braintrustdata.api.models.ProjectRetrieveParams import com.braintrustdata.api.models.ProjectSettings import com.braintrustdata.api.models.ProjectUpdateParams import org.junit.jupiter.api.Test @@ -41,12 +39,7 @@ internal class ProjectServiceTest { .build() val projectService = client.projects() - val project = - projectService.retrieve( - ProjectRetrieveParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val project = projectService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") project.validate() } @@ -108,12 +101,7 @@ internal class ProjectServiceTest { .build() val projectService = client.projects() - val project = - projectService.delete( - ProjectDeleteParams.builder() - .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val project = projectService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") project.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceTest.kt index 709ed83a..4244bf41 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/ProjectTagServiceTest.kt @@ -5,9 +5,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.ProjectTagCreateParams -import com.braintrustdata.api.models.ProjectTagDeleteParams import com.braintrustdata.api.models.ProjectTagReplaceParams -import com.braintrustdata.api.models.ProjectTagRetrieveParams import com.braintrustdata.api.models.ProjectTagUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -46,12 +44,7 @@ internal class ProjectTagServiceTest { .build() val projectTagService = client.projectTags() - val projectTag = - projectTagService.retrieve( - ProjectTagRetrieveParams.builder() - .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectTag = projectTagService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") projectTag.validate() } @@ -101,12 +94,7 @@ internal class ProjectTagServiceTest { .build() val projectTagService = client.projectTags() - val projectTag = - projectTagService.delete( - ProjectTagDeleteParams.builder() - .projectTagId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val projectTag = projectTagService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") projectTag.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt index e972b345..3544ab5c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/PromptServiceTest.kt @@ -7,10 +7,8 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.core.JsonValue import com.braintrustdata.api.models.PromptCreateParams import com.braintrustdata.api.models.PromptData -import com.braintrustdata.api.models.PromptDeleteParams import com.braintrustdata.api.models.PromptOptions import com.braintrustdata.api.models.PromptReplaceParams -import com.braintrustdata.api.models.PromptRetrieveParams import com.braintrustdata.api.models.PromptUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -133,12 +131,7 @@ internal class PromptServiceTest { .build() val promptService = client.prompts() - val prompt = - promptService.retrieve( - PromptRetrieveParams.builder() - .promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val prompt = promptService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") prompt.validate() } @@ -271,12 +264,7 @@ internal class PromptServiceTest { .build() val promptService = client.prompts() - val prompt = - promptService.delete( - PromptDeleteParams.builder() - .promptId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val prompt = promptService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") prompt.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/RoleServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/RoleServiceTest.kt index 219fd06e..3bab9b17 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/RoleServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/RoleServiceTest.kt @@ -7,9 +7,7 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.AclObjectType import com.braintrustdata.api.models.Permission import com.braintrustdata.api.models.RoleCreateParams -import com.braintrustdata.api.models.RoleDeleteParams import com.braintrustdata.api.models.RoleReplaceParams -import com.braintrustdata.api.models.RoleRetrieveParams import com.braintrustdata.api.models.RoleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -54,10 +52,7 @@ internal class RoleServiceTest { .build() val roleService = client.roles() - val role = - roleService.retrieve( - RoleRetrieveParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val role = roleService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") role.validate() } @@ -120,10 +115,7 @@ internal class RoleServiceTest { .build() val roleService = client.roles() - val role = - roleService.delete( - RoleDeleteParams.builder().roleId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val role = roleService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") role.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceTest.kt index c17eec2b..1d2c51ae 100644 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/SpanIframeServiceTest.kt @@ -5,9 +5,7 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient import com.braintrustdata.api.models.SpanIframeCreateParams -import com.braintrustdata.api.models.SpanIframeDeleteParams import com.braintrustdata.api.models.SpanIframeReplaceParams -import com.braintrustdata.api.models.SpanIframeRetrieveParams import com.braintrustdata.api.models.SpanIframeUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -47,12 +45,7 @@ internal class SpanIframeServiceTest { .build() val spanIframeService = client.spanIframes() - val spanIFrame = - spanIframeService.retrieve( - SpanIframeRetrieveParams.builder() - .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val spanIFrame = spanIframeService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") spanIFrame.validate() } @@ -103,12 +96,7 @@ internal class SpanIframeServiceTest { .build() val spanIframeService = client.spanIframes() - val spanIFrame = - spanIframeService.delete( - SpanIframeDeleteParams.builder() - .spanIframeId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) + val spanIFrame = spanIframeService.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") spanIFrame.validate() } diff --git a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/UserServiceTest.kt b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/UserServiceTest.kt index 70032d95..6376460c 100755 --- a/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/UserServiceTest.kt +++ b/braintrust-java-core/src/test/kotlin/com/braintrustdata/api/services/blocking/UserServiceTest.kt @@ -4,7 +4,6 @@ package com.braintrustdata.api.services.blocking import com.braintrustdata.api.TestServerExtension import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient -import com.braintrustdata.api.models.UserRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,10 +19,7 @@ internal class UserServiceTest { .build() val userService = client.users() - val user = - userService.retrieve( - UserRetrieveParams.builder().userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) + val user = userService.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") user.validate() } diff --git a/braintrust-java-example/build.gradle.kts b/braintrust-java-example/build.gradle.kts index 298fe690..7c705e6e 100644 --- a/braintrust-java-example/build.gradle.kts +++ b/braintrust-java-example/build.gradle.kts @@ -17,5 +17,12 @@ tasks.withType().configureEach { } application { - mainClass = "com.braintrustdata.api.example.Main" + // Use `./gradlew :braintrust-java-example:run` to run `Main` + // Use `./gradlew :braintrust-java-example:run -Pexample=Something` to run `SomethingExample` + mainClass = "com.braintrustdata.api.example.${ + if (project.hasProperty("example")) + "${project.property("example")}Example" + else + "Main" + }" } diff --git a/braintrust-java-proguard-test/build.gradle.kts b/braintrust-java-proguard-test/build.gradle.kts new file mode 100644 index 00000000..d17b1a54 --- /dev/null +++ b/braintrust-java-proguard-test/build.gradle.kts @@ -0,0 +1,101 @@ +plugins { + id("braintrust.kotlin") + id("com.gradleup.shadow") version "8.3.8" +} + +buildscript { + repositories { + google() + } + + dependencies { + classpath("com.guardsquare:proguard-gradle:7.4.2") + classpath("com.android.tools:r8:8.3.37") + } +} + +dependencies { + testImplementation(project(":braintrust-java")) + testImplementation(kotlin("test")) + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") + testImplementation("org.assertj:assertj-core:3.25.3") + testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") +} + +tasks.shadowJar { + from(sourceSets.test.get().output) + configurations = listOf(project.configurations.testRuntimeClasspath.get()) +} + +val proguardJarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-proguard.jar" +val proguardJar by tasks.registering(proguard.gradle.ProGuardTask::class) { + group = "verification" + dependsOn(tasks.shadowJar) + notCompatibleWithConfigurationCache("ProGuard") + + injars(tasks.shadowJar) + outjars(proguardJarPath) + printmapping("${layout.buildDirectory.get()}/proguard-mapping.txt") + + val javaHome = System.getProperty("java.home") + if (System.getProperty("java.version").startsWith("1.")) { + // Before Java 9, the runtime classes were packaged in a single jar file. + libraryjars("$javaHome/lib/rt.jar") + } else { + // As of Java 9, the runtime classes are packaged in modular jmod files. + libraryjars( + // Filters must be specified first, as a map. + mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"), + "$javaHome/jmods/java.base.jmod" + ) + } + + configuration("./test.pro") + configuration("../braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro") +} + +val testProGuard by tasks.registering(JavaExec::class) { + group = "verification" + dependsOn(proguardJar) + notCompatibleWithConfigurationCache("ProGuard") + + mainClass.set("com.braintrustdata.api.proguard.ProGuardCompatibilityTest") + classpath = files(proguardJarPath) +} + +val r8JarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-r8.jar" +val r8Jar by tasks.registering(JavaExec::class) { + group = "verification" + dependsOn(tasks.shadowJar) + notCompatibleWithConfigurationCache("R8") + + mainClass.set("com.android.tools.r8.R8") + classpath = buildscript.configurations["classpath"] + + args = listOf( + "--release", + "--classfile", + "--output", r8JarPath, + "--lib", System.getProperty("java.home"), + "--pg-conf", "./test.pro", + "--pg-conf", "../braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro", + "--pg-map-output", "${layout.buildDirectory.get()}/r8-mapping.txt", + tasks.shadowJar.get().archiveFile.get().asFile.absolutePath, + ) +} + +val testR8 by tasks.registering(JavaExec::class) { + group = "verification" + dependsOn(r8Jar) + notCompatibleWithConfigurationCache("R8") + + mainClass.set("com.braintrustdata.api.proguard.ProGuardCompatibilityTest") + classpath = files(r8JarPath) +} + +tasks.test { + dependsOn(testProGuard) + dependsOn(testR8) + // We defer to the tests run via the ProGuard JAR. + enabled = false +} diff --git a/braintrust-java-proguard-test/src/test/kotlin/com/braintrustdata/api/proguard/ProGuardCompatibilityTest.kt b/braintrust-java-proguard-test/src/test/kotlin/com/braintrustdata/api/proguard/ProGuardCompatibilityTest.kt new file mode 100644 index 00000000..a33fc6ed --- /dev/null +++ b/braintrust-java-proguard-test/src/test/kotlin/com/braintrustdata/api/proguard/ProGuardCompatibilityTest.kt @@ -0,0 +1,128 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.braintrustdata.api.proguard + +import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient +import com.braintrustdata.api.core.jsonMapper +import com.braintrustdata.api.models.AclObjectType +import com.braintrustdata.api.models.Project +import com.braintrustdata.api.models.ProjectListPageResponse +import com.braintrustdata.api.models.ProjectSettings +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime +import kotlin.reflect.full.memberFunctions +import kotlin.reflect.jvm.javaMethod +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ProGuardCompatibilityTest { + + companion object { + + @JvmStatic + fun main(args: Array) { + // To debug that we're using the right JAR. + val jarPath = this::class.java.getProtectionDomain().codeSource.location + println("JAR being used: $jarPath") + + // We have to manually run the test methods instead of using the JUnit runner because it + // seems impossible to get working with R8. + val test = ProGuardCompatibilityTest() + test::class + .memberFunctions + .asSequence() + .filter { function -> + function.javaMethod?.isAnnotationPresent(Test::class.java) == true + } + .forEach { it.call(test) } + } + } + + @Test + fun proguardRules() { + val rulesFile = + javaClass.classLoader.getResourceAsStream("META-INF/proguard/braintrust-java-core.pro") + + assertThat(rulesFile).isNotNull() + } + + @Test + fun client() { + val client = BraintrustOkHttpClient.builder().apiKey("My API Key").build() + + assertThat(client).isNotNull() + assertThat(client.topLevel()).isNotNull() + assertThat(client.projects()).isNotNull() + assertThat(client.experiments()).isNotNull() + assertThat(client.datasets()).isNotNull() + assertThat(client.prompts()).isNotNull() + assertThat(client.roles()).isNotNull() + assertThat(client.groups()).isNotNull() + assertThat(client.acls()).isNotNull() + assertThat(client.users()).isNotNull() + assertThat(client.projectScores()).isNotNull() + assertThat(client.projectTags()).isNotNull() + assertThat(client.spanIframes()).isNotNull() + assertThat(client.functions()).isNotNull() + assertThat(client.views()).isNotNull() + assertThat(client.organizations()).isNotNull() + assertThat(client.apiKeys()).isNotNull() + assertThat(client.aiSecrets()).isNotNull() + assertThat(client.envVars()).isNotNull() + assertThat(client.evals()).isNotNull() + } + + @Test + fun projectListPageResponseRoundtrip() { + val jsonMapper = jsonMapper() + val projectListPageResponse = + ProjectListPageResponse.builder() + .addObject( + Project.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .name("name") + .orgId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deletedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .settings( + ProjectSettings.builder() + .baselineExperimentId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .comparisonKey("comparison_key") + .addSpanFieldOrder( + ProjectSettings.SpanFieldOrder.builder() + .columnId("column_id") + .objectType("object_type") + .position("position") + .layout(ProjectSettings.SpanFieldOrder.Layout.FULL) + .build() + ) + .build() + ) + .userId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .build() + + val roundtrippedProjectListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(projectListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedProjectListPageResponse).isEqualTo(projectListPageResponse) + } + + @Test + fun aclObjectTypeRoundtrip() { + val jsonMapper = jsonMapper() + val aclObjectType = AclObjectType.ORGANIZATION + + val roundtrippedAclObjectType = + jsonMapper.readValue( + jsonMapper.writeValueAsString(aclObjectType), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAclObjectType).isEqualTo(aclObjectType) + } +} diff --git a/braintrust-java-proguard-test/test.pro b/braintrust-java-proguard-test/test.pro new file mode 100644 index 00000000..a55227f1 --- /dev/null +++ b/braintrust-java-proguard-test/test.pro @@ -0,0 +1,9 @@ +# Specify the entrypoint where ProGuard starts to determine what's reachable. +-keep class com.braintrustdata.api.proguard.** { *; } + +# For the testing framework. +-keep class org.junit.** { *; } + +# Many warnings don't apply for our testing purposes. +-dontnote +-dontwarn \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index d8afa3b2..b525a99e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,20 @@ repositories { allprojects { group = "com.braintrustdata.api" - version = "0.9.0" // x-release-please-version + version = "0.10.0" // x-release-please-version +} + +subprojects { + // These are populated with dependencies by `buildSrc` scripts. + tasks.register("format") { + group = "Verification" + description = "Formats all source files." + } + tasks.register("lint") { + group = "Verification" + description = "Verifies all source files are formatted." + } + apply(plugin = "org.jetbrains.dokka") } subprojects { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 778c89de..c6dc92ec 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -10,7 +10,6 @@ repositories { } dependencies { - implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0") } diff --git a/buildSrc/src/main/kotlin/braintrust.java.gradle.kts b/buildSrc/src/main/kotlin/braintrust.java.gradle.kts index e39d9ac6..70fc33f4 100755 --- a/buildSrc/src/main/kotlin/braintrust.java.gradle.kts +++ b/buildSrc/src/main/kotlin/braintrust.java.gradle.kts @@ -1,27 +1,16 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat plugins { `java-library` - id("com.diffplug.spotless") } repositories { mavenCentral() } -configure { - java { - importOrder() - removeUnusedImports() - palantirJavaFormat() - toggleOffOn() - } -} - java { toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(21)) } sourceCompatibility = JavaVersion.VERSION_1_8 @@ -53,3 +42,86 @@ tasks.withType().configureEach { exceptionFormat = TestExceptionFormat.FULL } } + +val palantir by configurations.creating +dependencies { + palantir("com.palantir.javaformat:palantir-java-format:2.73.0") +} + +fun registerPalantir( + name: String, + description: String, +) { + val javaName = "${name}Java" + tasks.register(javaName) { + group = "Verification" + this.description = description + + classpath = palantir + mainClass = "com.palantir.javaformat.java.Main" + + // Avoid an `IllegalAccessError` on Java 9+. + jvmArgs( + "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + ) + + // Use paths relative to the current module. + val argumentFile = + project.layout.buildDirectory.file("palantir-$name-args.txt").get().asFile + val lastRunTimeFile = + project.layout.buildDirectory.file("palantir-$name-last-run.txt").get().asFile + + // Read the time when this task was last executed for this module (if ever). + val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L + + // Use a `fileTree` relative to the module's source directory. + val javaFiles = project.fileTree("src") { include("**/*.java") } + + // Determine if any files need to be formatted or linted and continue only if there is at least + // one file. + onlyIf { javaFiles.any { it.lastModified() > lastRunTime } } + + inputs.files(javaFiles) + + doFirst { + // Create the argument file and set the preferred formatting style. + argumentFile.parentFile.mkdirs() + argumentFile.writeText("--palantir\n") + + if (name == "lint") { + // For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of + // the default 0) if any files need to be formatted, indicating that linting has failed. + argumentFile.appendText("--dry-run\n") + argumentFile.appendText("--set-exit-if-changed\n") + } else { + // `--dry-run` and `--replace` (for in-place formatting) are mutually exclusive. + argumentFile.appendText("--replace\n") + } + + // Write the modified files to the argument file. + javaFiles.filter { it.lastModified() > lastRunTime } + .forEach { argumentFile.appendText("${it.absolutePath}\n") } + } + + doLast { + // Record the last execution time for later up-to-date checking. + lastRunTimeFile.writeText(System.currentTimeMillis().toString()) + } + + // Pass the argument file using the @ symbol + args = listOf("@${argumentFile.absolutePath}") + + outputs.upToDateWhen { javaFiles.none { it.lastModified() > lastRunTime } } + } + + tasks.named(name) { + dependsOn(tasks.named(javaName)) + } +} + +registerPalantir(name = "format", description = "Formats all Java source files.") +registerPalantir(name = "lint", description = "Verifies all Java source files are formatted.") diff --git a/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts b/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts index 14b60c20..832189a3 100755 --- a/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/braintrust.kotlin.gradle.kts @@ -1,4 +1,3 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion @@ -7,6 +6,10 @@ plugins { kotlin("jvm") } +repositories { + mavenCentral() +} + kotlin { jvmToolchain { languageVersion.set(JavaLanguageVersion.of(21)) @@ -19,8 +22,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) @@ -29,14 +30,77 @@ kotlin { } } -configure { - kotlin { - ktfmt().kotlinlangStyle() - toggleOffOn() - } -} - tasks.withType().configureEach { systemProperty("junit.jupiter.execution.parallel.enabled", true) systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent") } + +val ktfmt by configurations.creating +dependencies { + ktfmt("com.facebook:ktfmt:0.56") +} + +fun registerKtfmt( + name: String, + description: String, +) { + val kotlinName = "${name}Kotlin" + tasks.register(kotlinName) { + group = "Verification" + this.description = description + + classpath = ktfmt + mainClass = "com.facebook.ktfmt.cli.Main" + + // Use paths relative to the current module. + val argumentFile = project.layout.buildDirectory.file("ktfmt-$name-args.txt").get().asFile + val lastRunTimeFile = + project.layout.buildDirectory.file("ktfmt-$name-last-run.txt").get().asFile + + // Read the time when this task was last executed for this module (if ever). + val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L + + // Use a `fileTree` relative to the module's source directory. + val kotlinFiles = project.fileTree("src") { include("**/*.kt") } + + // Determine if any files need to be formatted or linted and continue only if there is at least + // one file (otherwise Ktfmt will fail). + onlyIf { kotlinFiles.any { it.lastModified() > lastRunTime } } + + inputs.files(kotlinFiles) + + doFirst { + // Create the argument file and set the preferred formatting style. + argumentFile.parentFile.mkdirs() + argumentFile.writeText("--kotlinlang-style\n") + + if (name == "lint") { + // For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of + // the default 0) if any files need to be formatted, indicating that linting has failed. + argumentFile.appendText("--dry-run\n") + argumentFile.appendText("--set-exit-if-changed\n") + } + + // Write the modified files to the argument file. + kotlinFiles.filter { it.lastModified() > lastRunTime } + .forEach { argumentFile.appendText("${it.absolutePath}\n") } + } + + doLast { + // Record the last execution time for later up-to-date checking. + lastRunTimeFile.writeText(System.currentTimeMillis().toString()) + } + + // Pass the argument file using the @ symbol + args = listOf("@${argumentFile.absolutePath}") + + outputs.upToDateWhen { kotlinFiles.none { it.lastModified() > lastRunTime } } + } + + tasks.named(name) { + dependsOn(tasks.named(kotlinName)) + } +} + +registerKtfmt(name = "format", description = "Formats all Kotlin source files.") +registerKtfmt(name = "lint", description = "Verifies all Kotlin source files are formatted.") diff --git a/buildSrc/src/main/kotlin/braintrust.publish.gradle.kts b/buildSrc/src/main/kotlin/braintrust.publish.gradle.kts index c96736ac..747be62d 100755 --- a/buildSrc/src/main/kotlin/braintrust.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/braintrust.publish.gradle.kts @@ -53,3 +53,7 @@ configure { } } } + +tasks.withType().configureEach { + isZip64 = true +} diff --git a/gradle.properties b/gradle.properties index ff76593f..6680f9ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,12 +4,13 @@ org.gradle.parallel=true org.gradle.daemon=false # These options improve our compilation and test performance. They are inherited by the Kotlin daemon. org.gradle.jvmargs=\ - -Xms1g \ - -Xmx4g \ + -Xms2g \ + -Xmx8g \ -XX:+UseParallelGC \ -XX:InitialCodeCacheSize=256m \ -XX:ReservedCodeCacheSize=1G \ - -XX:MetaspaceSize=256m \ + -XX:MetaspaceSize=512m \ + -XX:MaxMetaspaceSize=2G \ -XX:TieredStopAtLevel=1 \ -XX:GCTimeRatio=4 \ -XX:CICompilerCount=4 \ diff --git a/scripts/build b/scripts/build new file mode 100755 index 00000000..f4063482 --- /dev/null +++ b/scripts/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +echo "==> Building classes" +./gradlew build testClasses -x test diff --git a/scripts/fast-format b/scripts/fast-format new file mode 100755 index 00000000..1b3bc473 --- /dev/null +++ b/scripts/fast-format @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -euo pipefail + +echo "Script started with $# arguments" +echo "Arguments: $*" +echo "Script location: $(dirname "$0")" + +cd "$(dirname "$0")/.." +echo "Changed to directory: $(pwd)" + +if [ $# -eq 0 ]; then + echo "Usage: $0 [additional-formatter-args...]" + echo "The file should contain one file path per line" + exit 1 +fi + +FILE_LIST="$1" + +echo "Looking for file: $FILE_LIST" + +if [ ! -f "$FILE_LIST" ]; then + echo "Error: File '$FILE_LIST' not found" + exit 1 +fi + +if ! command -v ktfmt-fast-format &> /dev/null; then + echo "Error: ktfmt-fast-format not found" + exit 1 +fi + +# Process Kotlin files +echo "==> Looking for Kotlin files" +kt_files=$(grep -E '\.kt$' "$FILE_LIST" | grep -v './buildSrc/build/' || true) +echo "==> Done looking for Kotlin files" + +if [[ -n "$kt_files" ]]; then + echo "==> will format Kotlin files" + echo "$kt_files" | tr '\n' '\0' | xargs -0 ktfmt-fast-format --kotlinlang-style "$@" +else + echo "No Kotlin files to format -- expected outcome during incremental formatting" +fi + +# TODO(mbudayr): support palantir-java-format +# Process Java files +# grep -E '\.java$' "$FILE_LIST" | grep -v './buildSrc/build/' | tr '\n' '\0' | xargs -0 -r palantir-java-format --palantir --replace "$@" diff --git a/scripts/format b/scripts/format index 456a69db..65db1769 100755 --- a/scripts/format +++ b/scripts/format @@ -4,5 +4,18 @@ set -e cd "$(dirname "$0")/.." -echo "==> Running spotlessApply" -./gradlew spotlessApply +if command -v ktfmt &> /dev/null; then + echo "==> Running ktfmt" + ./scripts/kotlin-format +else + echo "==> Running gradlew formatKotlin" + ./gradlew formatKotlin +fi + +if command -v palantir-java-format &> /dev/null; then + echo "==> Running palantir-java-format" + ./scripts/java-format +else + echo "==> Running gradlew formatJava" + ./gradlew formatJava +fi diff --git a/scripts/java-format b/scripts/java-format new file mode 100755 index 00000000..ad5febce --- /dev/null +++ b/scripts/java-format @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +find . -name "*.java" -not -path "./buildSrc/build/*" -print0 | xargs -0 -r palantir-java-format --palantir --replace "$@" diff --git a/scripts/kotlin-format b/scripts/kotlin-format new file mode 100755 index 00000000..3b8be9ea --- /dev/null +++ b/scripts/kotlin-format @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +find . -name "*.kt" -not -path "./buildSrc/build/*" -print0 | xargs -0 -r ktfmt --kotlinlang-style "$@" diff --git a/scripts/lint b/scripts/lint index e3a5f5e2..dbc8f776 100755 --- a/scripts/lint +++ b/scripts/lint @@ -4,5 +4,20 @@ set -e cd "$(dirname "$0")/.." -echo "==> Build classes" -./gradlew build testClasses -x test +echo "==> Running lints" + +if command -v ktfmt &> /dev/null; then + echo "==> Checking ktfmt" + ./scripts/kotlin-format --dry-run --set-exit-if-changed +else + echo "==> Running gradlew lintKotlin" + ./gradlew lintKotlin +fi + +if command -v palantir-java-format &> /dev/null; then + echo "==> Checking palantir-java-format" + ./scripts/java-format --dry-run --set-exit-if-changed +else + echo "==> Running gradlew lintJava" + ./gradlew lintJava +fi diff --git a/scripts/mock b/scripts/mock index d2814ae6..0b28f6ea 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" + npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" fi diff --git a/scripts/test b/scripts/test index 6b750a74..047bc1db 100755 --- a/scripts/test +++ b/scripts/test @@ -43,7 +43,7 @@ elif ! prism_is_running ; then echo -e "To run the server, pass in the path or url of your OpenAPI" echo -e "spec to the prism command:" echo - echo -e " \$ ${YELLOW}npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock path/to/your.openapi.yml${NC}" + echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}" echo exit 1 @@ -53,4 +53,4 @@ else fi echo "==> Running tests" -./gradlew test +./gradlew test "$@" diff --git a/settings.gradle.kts b/settings.gradle.kts index be7364dc..dce7cbbe 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,14 @@ rootProject.name = "braintrust-java-root" -include("braintrust-java") -include("braintrust-java-client-okhttp") -include("braintrust-java-core") -include("braintrust-java-example") +val projectNames = rootDir.listFiles() + ?.asSequence() + .orEmpty() + .filter { file -> + file.isDirectory && + file.name.startsWith("braintrust-java") && + file.listFiles()?.asSequence().orEmpty().any { it.name == "build.gradle.kts" } + } + .map { it.name } + .toList() +println("projects: $projectNames") +projectNames.forEach { include(it) }