All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.openfga.client.StoreClient Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package io.quarkiverse.openfga.client;

import static io.quarkiverse.openfga.client.utils.PaginatedList.collectAllPages;

import java.util.List;

import javax.annotation.Nullable;

import io.quarkiverse.openfga.client.api.API;
import io.quarkiverse.openfga.client.model.Store;
import io.quarkiverse.openfga.client.model.Tuple;
import io.quarkiverse.openfga.client.model.TupleChange;
import io.quarkiverse.openfga.client.model.dto.GetStoreResponse;
import io.quarkiverse.openfga.client.model.dto.ReadChangesResponse;
import io.quarkiverse.openfga.client.model.dto.ReadTuplesBody;
import io.quarkiverse.openfga.client.utils.PaginatedList;
import io.smallrye.mutiny.Uni;

public class StoreClient {

    private final API api;
    private final Uni storeId;

    public StoreClient(API api, Uni storeId) {
        this.api = api;
        this.storeId = storeId;
    }

    public Uni get() {
        return storeId.flatMap(api::getStore)
                .map(GetStoreResponse::asStore);
    }

    public Uni delete() {
        return storeId.flatMap(api::deleteStore);
    }

    public Uni> changes(@Nullable String type, @Nullable Integer pageSize,
            @Nullable String continuationToken) {
        return storeId.flatMap(storeId -> api.readChanges(storeId, type, pageSize, continuationToken))
                .map(ReadChangesResponse::getChanges);
    }

    public Uni> readTuples(@Nullable Integer pageSize, @Nullable String pagingToken) {
        return storeId.flatMap(storeId -> api.readTuples(storeId, new ReadTuplesBody(pageSize, pagingToken)))
                .map(res -> new PaginatedList<>(res.getTuples(), res.getContinuationToken()));
    }

    public Uni> readAllTuples() {
        return readAllTuples(null);
    }

    public Uni> readAllTuples(@Nullable Integer pageSize) {
        return collectAllPages(pageSize, this::readTuples);
    }

    public AuthorizationModelsClient authorizationModels() {
        return new AuthorizationModelsClient(api, storeId);
    }

    public AssertionsClient assertions(String authorizationModelId) {
        return new AssertionsClient(api, storeId, authorizationModelId);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy