Skip to content

Commit 7729ea1

Browse files
committed
feat: expose API.Kv* types
1 parent df2f4c5 commit 7729ea1

3 files changed

Lines changed: 51 additions & 15 deletions

File tree

.changeset/tired-teams-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@badrap/libapp": patch
3+
---
4+
5+
Expose API.Kv\* types

src/api/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as v from "@badrap/valita";
22
import { HTTPError, APIError, Client, type ClientConfig } from "./client.ts";
33
import { Kv } from "./kv.ts";
4+
import type * as KvTypes from "./kv.ts";
45

56
export { HTTPError, APIError };
67

@@ -269,3 +270,29 @@ export class API<
269270
});
270271
}
271272
}
273+
274+
export declare namespace API {
275+
export type Kv = KvTypes.Kv;
276+
277+
export type KvKey = KvTypes.KvKey;
278+
279+
export type KvEntry<T> = KvTypes.KvEntry<T>;
280+
281+
export type KvEntryMaybe<T> = KvTypes.KvEntryMaybe<T>;
282+
283+
export type KvCheck = KvTypes.KvCheck;
284+
285+
export type KvMutation = KvTypes.KvMutation;
286+
287+
export type KvCommitResult = KvTypes.KvCommitResult;
288+
289+
export type KvCommitError = KvTypes.KvCommitError;
290+
291+
export type KvListSelector = KvTypes.KvListSelector;
292+
293+
export type KvListOptions = KvTypes.KvListOptions;
294+
295+
export type KvListIterator<T> = KvTypes.KvListIterator<T>;
296+
297+
export type KvAtomicOperation = KvTypes.KvAtomicOperation;
298+
}

src/api/kv.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import * as v from "@badrap/valita";
22
import { type Client, HTTPError } from "./client.ts";
33

4-
type KvKey = (number | string | boolean)[];
4+
export type KvKey = (number | string | boolean)[];
55

6-
type KvEntry<T> = { key: KvKey; value: T; versionstamp: string };
6+
export type KvEntry<T> = { key: KvKey; value: T; versionstamp: string };
77

8-
type KvEntryMaybe<T> =
8+
export type KvEntryMaybe<T> =
99
| KvEntry<T>
1010
| { key: KvKey; value: null; versionstamp: null };
1111

12-
type AtomicCheck = { key: KvKey; versionstamp: string | null };
12+
export type KvCheck = { key: KvKey; versionstamp: string | null };
1313

14-
type KvMutation =
14+
export type KvMutation =
1515
| {
1616
type: "set";
1717
key: KvKey;
@@ -31,19 +31,23 @@ type KvMutation =
3131
backoffSchedule?: number[];
3232
};
3333

34-
type KvCommitResult = { ok: true; versionstamp: string };
34+
export type KvCommitResult = { ok: true; versionstamp: string };
3535

36-
type KvCommitError = { ok: false };
36+
export type KvCommitError = { ok: false };
3737

38-
type KvListSelector =
38+
export type KvListSelector =
3939
| { prefix: KvKey; start?: undefined; end?: undefined }
4040
| { prefix: KvKey; start: KvKey; end?: undefined }
4141
| { prefix: KvKey; start?: undefined; end: KvKey }
4242
| { prefix?: undefined; start: KvKey; end: KvKey };
4343

44-
type KvListOptions = { limit?: number; reverse?: boolean; batchSize?: number };
44+
export type KvListOptions = {
45+
limit?: number;
46+
reverse?: boolean;
47+
batchSize?: number;
48+
};
4549

46-
type KvListIterator<T> = AsyncIterableIterator<KvEntry<T>>;
50+
export type KvListIterator<T> = AsyncIterableIterator<KvEntry<T>>;
4751

4852
const Key = v.array(v.union(v.string(), v.number(), v.boolean()));
4953

@@ -155,21 +159,21 @@ export class Kv {
155159
}
156160
}
157161

158-
atomic(): AtomicOperation {
159-
return new AtomicOperation(this.#client);
162+
atomic(): KvAtomicOperation {
163+
return new KvAtomicOperation(this.#client);
160164
}
161165
}
162166

163-
class AtomicOperation {
167+
export class KvAtomicOperation {
164168
readonly #client: Client;
165-
readonly #checks: AtomicCheck[] = [];
169+
readonly #checks: KvCheck[] = [];
166170
readonly #mutations: KvMutation[] = [];
167171

168172
constructor(client: Client) {
169173
this.#client = client;
170174
}
171175

172-
check(...checks: AtomicCheck[]): this {
176+
check(...checks: KvCheck[]): this {
173177
for (const { key, versionstamp } of checks) {
174178
this.#checks.push({ key, versionstamp });
175179
}

0 commit comments

Comments
 (0)