|
1 | 1 | package studio.o7.octopus.plugin.api; |
2 | 2 |
|
3 | | -import org.jspecify.annotations.NullMarked; |
| 3 | +import gentle.Error; |
| 4 | +import gentle.Result; |
4 | 5 | import studio.o7.octopus.plugin.Unsafe; |
5 | | -import studio.o7.octopus.plugin.api.listener.Listener; |
6 | | -import studio.o7.octopus.sdk.gen.api.v1.Entry; |
7 | | -import studio.o7.octopus.sdk.gen.api.v1.Object; |
| 6 | +import studio.o7.octopus.sdk.v1.Entry; |
| 7 | +import studio.o7.octopus.sdk.v1.QueryResponse; |
8 | 8 |
|
9 | | -import javax.annotation.Nullable; |
10 | | -import java.time.Instant; |
11 | | -import java.util.Collection; |
12 | 9 | import java.util.UUID; |
13 | 10 |
|
14 | | -@NullMarked |
15 | 11 | public interface Octopus { |
16 | 12 |
|
17 | | - static Octopus get() { |
| 13 | + static Octopus instance() { |
18 | 14 | return Unsafe.getInstance().get(); |
19 | 15 | } |
20 | 16 |
|
21 | 17 | /** |
22 | | - * Retrieves existing entries from the database matching a |
23 | | - * key pattern. |
| 18 | + * Gets a unique entry of the given key |
| 19 | + * |
| 20 | + * @param key exact key pattern that will match between entries until one is found |
| 21 | + * @return Returns the first {@link studio.o7.octopus.sdk.v1.Entry} that matches the key |
24 | 22 | */ |
25 | | - default Collection<Entry> get(String keyPattern) { |
26 | | - return get(keyPattern, false); |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Retrieves existing entries from the database matching a |
31 | | - * key pattern. Can optionally include expired objects. |
32 | | - */ |
33 | | - default Collection<Entry> get(String keyPattern, boolean includeExpired) { |
34 | | - return get(keyPattern, includeExpired, null, null); |
35 | | - } |
| 23 | + Result<studio.o7.octopus.sdk.v1.Object, Error> get(String key); |
36 | 24 |
|
37 | 25 | /** |
38 | | - * Retrieves existing entries from the database matching a |
39 | | - * key pattern. Can optionally include expired objects and |
40 | | - * filter by revision creation time. |
| 26 | + * Query multiple Entries |
| 27 | + * |
| 28 | + * @param queryParameter Query parameter to build the query request |
| 29 | + * @return Returns a collection of matches for this query request |
41 | 30 | */ |
42 | | - Collection<Entry> get(String keyPattern, boolean includeExpired, @Nullable Instant createdRangeStart, @Nullable Instant createdRangeEnd); |
43 | | - |
44 | | - |
45 | | - void registerListener(Listener listener); |
46 | | - |
47 | | - default void unregisterListener(Listener listener) { |
48 | | - unregisterListener(listener.getListenerUniqueId()); |
49 | | - } |
50 | | - |
51 | | - void unregisterListener(UUID listenerUniqueId); |
| 31 | + Result<QueryResponse, Error> query(QueryParameter queryParameter); |
52 | 32 |
|
53 | 33 | /** |
| 34 | + * <h1>Call</h1> |
| 35 | + * <p> |
54 | 36 | * Stores an object on a key with new revision in the database |
55 | 37 | * and returns the stored version, including the new revision |
56 | 38 | * and ID. |
| 39 | + * |
| 40 | + * <h2>Expired</h2> |
| 41 | + * If an entry is expired. For example a permission, set the expired_at field |
| 42 | + * if it's not set and the entry will be flagged as expired |
| 43 | + * |
| 44 | + * <h2>Deletion</h2> |
| 45 | + * If an entry should be deleted, just set the deleted_at field and it will be |
| 46 | + * flagged as deleted |
| 47 | + * |
| 48 | + * @param obj Object that should be saved inside the database |
| 49 | + * @return returns the created {@link studio.o7.octopus.sdk.v1.Entry} |
57 | 50 | */ |
58 | | - Entry call(Object obj); |
| 51 | + Result<Entry, Error> call(studio.o7.octopus.sdk.v1.Object obj); |
59 | 52 |
|
60 | 53 | /** |
| 54 | + * <h1>Call</h1> |
| 55 | + * <p> |
61 | 56 | * Stores an object on a key with new revision in the database |
62 | 57 | * and just forgets it. All listeners will be called |
63 | 58 | * as usual without blocking this method. |
| 59 | + * |
| 60 | + * <h2>Expired</h2> |
| 61 | + * If an entry is expired. For example a permission, set the expired_at field |
| 62 | + * if it's not set and the entry will be flagged as expired |
| 63 | + * |
| 64 | + * <h2>Deletion</h2> |
| 65 | + * If an entry should be deleted, just set the deleted_at field and it will be |
| 66 | + * flagged as deleted |
| 67 | + * |
| 68 | + * @param obj Object that should be saved inside the database |
64 | 69 | */ |
65 | | - void callAndForget(Object obj); |
| 70 | + void write(studio.o7.octopus.sdk.v1.Object obj); |
66 | 71 |
|
| 72 | + /** |
| 73 | + * <p> |
| 74 | + * A registration of a handler will subscribe to its given key pattern |
| 75 | + * and receive all updates on the given key pattern. The handlers `onCall` |
| 76 | + * method will be invoked on the incoming {@link studio.o7.octopus.sdk.v1.EventCall} |
| 77 | + * </p> |
| 78 | + * |
| 79 | + * <p> |
| 80 | + * When subscribing, be reminded that the key pattern really matches the requested |
| 81 | + * EventCalls, using symbols such as `*` and `<` will subscribe on multiple keys |
| 82 | + * There's no safeguard to prevent subscribing to the same topic. So please make |
| 83 | + * shure you're not handling a topic twice! |
| 84 | + * </p> |
| 85 | + * |
| 86 | + * @param eventHandler Handler that will be invoked on matching incoming event |
| 87 | + */ |
| 88 | + void registerHandler(EventHandler eventHandler); |
| 89 | + |
| 90 | + /** |
| 91 | + * Unregister a handler |
| 92 | + * |
| 93 | + * @param eventHandler Handler to unregister |
| 94 | + */ |
| 95 | + default void unregisterHandler(EventHandler eventHandler) { |
| 96 | + unregisterHandler(eventHandler.getListenerUniqueId()); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Unregister a handler |
| 101 | + * |
| 102 | + * @param listenerUniqueId ID of the handler to unregister |
| 103 | + */ |
| 104 | + void unregisterHandler(UUID listenerUniqueId); |
67 | 105 | } |
0 commit comments