<commit_before>package com.github.msemys.esjc;

import com.github.msemys.esjc.operation.*;
import com.github.msemys.esjc.subscription.MaximumSubscribersReachedException;
import com.github.msemys.esjc.subscription.PersistentSubscriptionDeletedException;

import java.util.concurrent.CompletableFuture;

import static com.github.msemys.esjc.util.Preconditions.checkNotNull;
import static com.github.msemys.esjc.util.Strings.toBytes;

/**
 * An Event Store client with full duplex connection to server.
 * It is recommended that only one instance per application is created.
 */
public interface EventStore {

    /**
     * Gets client settings
     *
     * @return client settings
     */
    Settings settings();

    /**
     * Connects to server asynchronously.
     */
    void connect();

    /**
     * Disconnects client from server.
     */
    void disconnect();

    /**
     * Deletes a stream from the Event Store asynchronously using soft-deletion mode and default user credentials.
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #deleteStream(String, ExpectedVersion, boolean, UserCredentials)
     */
    default CompletableFuture<DeleteResult> deleteStream(String stream, ExpectedVersion expectedVersion) {
        return deleteStream(stream, expectedVersion, false, null);
    }

    /**
     * Deletes a stream from the Event Store asynchronously using soft-deletion mode.
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @param userCredentials user credentials to be used for this operation (use {@code null} for default user credentials).
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #deleteStream(String, ExpectedVersion, boolean, UserCredentials)
     */
    default CompletableFuture<DeleteResult> deleteStream(String stream,
                                                         ExpectedVersion expectedVersion,
                                                         UserCredentials userCredentials) {
        return deleteStream(stream, expectedVersion, false, userCredentials);
    }

    /**
     * Deletes a stream from the Event Store asynchronously using default user credentials.
     * There are two available deletion modes:
     * <ul>
     * <li>hard delete - streams can never be recreated</li>
     * <li>soft delete - streams can be written to again, but the event number sequence will not start from 0</li>
     * </ul>
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @param hardDelete      use {@code true} for "hard delete" or {@code false} for "soft delete" mode.
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #deleteStream(String, ExpectedVersion, boolean, UserCredentials)
     */
    default CompletableFuture<DeleteResult> deleteStream(String stream,
                                                         ExpectedVersion expectedVersion,
                                                         boolean hardDelete) {
        return deleteStream(stream, expectedVersion, hardDelete, null);
    }

    /**
     * Deletes a stream from the Event Store asynchronously.
     * There are two available deletion modes:
     * <ul>
     * <li>hard delete - streams can never be recreated</li>
     * <li>soft delete - streams can be written to again, but the event number sequence will not start from 0</li>
     * </ul>
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @param hardDelete      use {@code true} for "hard delete" or {@code false} for "soft delete" mode.
     * @param userCredentials user credentials to be used for this operation (use {@code null} for default user credentials).
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     */
    CompletableFuture<DeleteResult> deleteStream(String stream,
                                                 ExpectedVersion expectedVersion,
                                                 boolean hardDelete,
                                                 UserCredentials userCredentials);

    /**<commit_msg>added: improved EventStore api with 'appendToStream' for single event<commit_after>package com.github.msemys.esjc;

import com.github.msemys.esjc.operation.*;
import com.github.msemys.esjc.subscription.MaximumSubscribersReachedException;
import com.github.msemys.esjc.subscription.PersistentSubscriptionDeletedException;

import java.util.concurrent.CompletableFuture;

import static com.github.msemys.esjc.util.Preconditions.checkNotNull;
import static com.github.msemys.esjc.util.Strings.toBytes;
import static java.util.Collections.singletonList;

/**
 * An Event Store client with full duplex connection to server.
 * It is recommended that only one instance per application is created.
 */
public interface EventStore {

    /**
     * Gets client settings
     *
     * @return client settings
     */
    Settings settings();

    /**
     * Connects to server asynchronously.
     */
    void connect();

    /**
     * Disconnects client from server.
     */
    void disconnect();

    /**
     * Deletes a stream from the Event Store asynchronously using soft-deletion mode and default user credentials.
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #deleteStream(String, ExpectedVersion, boolean, UserCredentials)
     */
    default CompletableFuture<DeleteResult> deleteStream(String stream, ExpectedVersion expectedVersion) {
        return deleteStream(stream, expectedVersion, false, null);
    }

    /**
     * Deletes a stream from the Event Store asynchronously using soft-deletion mode.
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @param userCredentials user credentials to be used for this operation (use {@code null} for default user credentials).
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #deleteStream(String, ExpectedVersion, boolean, UserCredentials)
     */
    default CompletableFuture<DeleteResult> deleteStream(String stream,
                                                         ExpectedVersion expectedVersion,
                                                         UserCredentials userCredentials) {
        return deleteStream(stream, expectedVersion, false, userCredentials);
    }

    /**
     * Deletes a stream from the Event Store asynchronously using default user credentials.
     * There are two available deletion modes:
     * <ul>
     * <li>hard delete - streams can never be recreated</li>
     * <li>soft delete - streams can be written to again, but the event number sequence will not start from 0</li>
     * </ul>
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @param hardDelete      use {@code true} for "hard delete" or {@code false} for "soft delete" mode.
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #deleteStream(String, ExpectedVersion, boolean, UserCredentials)
     */
    default CompletableFuture<DeleteResult> deleteStream(String stream,
                                                         ExpectedVersion expectedVersion,
                                                         boolean hardDelete) {
        return deleteStream(stream, expectedVersion, hardDelete, null);
    }

    /**
     * Deletes a stream from the Event Store asynchronously.
     * There are two available deletion modes:
     * <ul>
     * <li>hard delete - streams can never be recreated</li>
     * <li>soft delete - streams can be written to again, but the event number sequence will not start from 0</li>
     * </ul>
     *
     * @param stream          the name of the stream to delete.
     * @param expectedVersion the expected version that the streams should have when being deleted.
     * @param hardDelete      use {@code true} for "hard delete" or {@code false} for "soft delete" mode.
     * @param userCredentials user credentials to be used for this operation (use {@code null} for default user credentials).
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     */
    CompletableFuture<DeleteResult> deleteStream(String stream,
                                                 ExpectedVersion expectedVersion,
                                                 boolean hardDelete,
                                                 UserCredentials userCredentials);

    /**
     * Appends single event to a stream asynchronously using default user credentials.
     *
     * @param stream          the name of the stream to append event to.
     * @param expectedVersion the version at which we currently expect the stream to be,
     *                        in order that an optimistic concurrency check can be performed.
     * @param event           the event to append.
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     * @see #appendToStream(String, ExpectedVersion, EventData, UserCredentials)
     */
    default CompletableFuture<WriteResult> appendToStream(String stream,
                                                          ExpectedVersion expectedVersion,
                                                          EventData event) {
        return appendToStream(stream, expectedVersion, event, null);
    }

    /**
     * Appends single event to a stream asynchronously.
     *
     * @param stream          the name of the stream to append event to.
     * @param expectedVersion the version at which we currently expect the stream to be,
     *                        in order that an optimistic concurrency check can be performed.
     * @param event           the event to append.
     * @param userCredentials user credentials to be used for this operation (use {@code null} for default user credentials).
     * @return a {@code CompletableFuture} representing the result of this operation. The future's methods
     * {@code get} and {@code join} can throw an exception with cause {@link WrongExpectedVersionException},
     * {@link StreamDeletedException}, {@link InvalidTransactionException}, {@link CommandNotExpectedException},
     * {@link NotAuthenticatedException}, {@link AccessDeniedException} or {@link ServerErrorException}
     * on exceptional completion.
     */
    default CompletableFuture<WriteResult> appendToStream(String stream,
                                                          ExpectedVersion expectedVersion,
                                                          EventData event,
                                                          UserCredentials userCredentials) {
        return appendToStream(stream, expectedVersion, singletonList(event), userCredentials);
    }

    /**
{'fraction_non_alphanumeric': 0.07585934413275386, 'fraction_numerical': 0.0002634005004609509, 'mean_word_length': 2.7816235059760954, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5708131', 'n_tokens_mistral': 3447, 'n_tokens_neox': 3396, 'n_words': 1349}