@bunbase-ae/js 1.3.1-next.58.55becc8 → 1.3.1-next.60.a69db4b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/client.ts +8 -0
- package/src/index.ts +1 -0
- package/src/sequence.ts +35 -0
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { AuthClient } from "./auth";
|
|
|
12
12
|
import { CollectionClient } from "./collection";
|
|
13
13
|
import { HttpClient } from "./http";
|
|
14
14
|
import { RealtimeClient } from "./realtime";
|
|
15
|
+
import { SequenceClient } from "./sequence";
|
|
15
16
|
import { StorageClient } from "./storage";
|
|
16
17
|
import type { BunBaseClientOptions, TransactionOperation, TransactionResult } from "./types";
|
|
17
18
|
|
|
@@ -63,6 +64,13 @@ export class BunBaseClient {
|
|
|
63
64
|
return new CollectionClient<T>(this.http, name);
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
// Returns a sequence client for the given sequence name.
|
|
68
|
+
// Sequence names may contain letters, digits, colons, hyphens, underscores,
|
|
69
|
+
// and dots — e.g. "invoices:tenant-123:2026".
|
|
70
|
+
sequence(name: string): SequenceClient {
|
|
71
|
+
return new SequenceClient(this.http, name);
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
// Execute up to 50 create/update/delete operations across multiple collections
|
|
67
75
|
// atomically. All operations succeed or all are rolled back.
|
|
68
76
|
async batch<T = Record<string, unknown>>(
|
package/src/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ export { AuthClient, type AuthSnapshot } from "./auth";
|
|
|
38
38
|
export { BunBaseClient } from "./client";
|
|
39
39
|
export { CollectionClient } from "./collection";
|
|
40
40
|
export { RealtimeClient, type SubscribeOptions } from "./realtime";
|
|
41
|
+
export { SequenceClient } from "./sequence";
|
|
41
42
|
export { type SignedUploadResult, StorageClient, type UploadOptions } from "./storage";
|
|
42
43
|
export {
|
|
43
44
|
type AggregateFunction,
|
package/src/sequence.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SequenceClient — atomic gap-free sequential number generation.
|
|
2
|
+
//
|
|
3
|
+
// Usage:
|
|
4
|
+
// const seq = client.sequence("invoices:tenant-123:2026");
|
|
5
|
+
// const next = await seq.next(); // → 1, 2, 3, ... atomic, no gaps
|
|
6
|
+
// const peek = await seq.peek(); // → current value, no increment
|
|
7
|
+
|
|
8
|
+
import type { HttpClient } from "./http";
|
|
9
|
+
|
|
10
|
+
export class SequenceClient {
|
|
11
|
+
constructor(
|
|
12
|
+
private readonly http: HttpClient,
|
|
13
|
+
private readonly name: string,
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
// Atomically increment the sequence and return the new value.
|
|
17
|
+
// Concurrent calls are serialized at the database level — each caller
|
|
18
|
+
// gets a unique monotonically-increasing value with no gaps.
|
|
19
|
+
async next(): Promise<number> {
|
|
20
|
+
const result = await this.http.request<{ value: number }>(
|
|
21
|
+
"POST",
|
|
22
|
+
`/api/v1/sequences/${encodeURIComponent(this.name)}/next`,
|
|
23
|
+
);
|
|
24
|
+
return result.value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Return the current sequence value without incrementing.
|
|
28
|
+
async peek(): Promise<number> {
|
|
29
|
+
const result = await this.http.request<{ value: number }>(
|
|
30
|
+
"GET",
|
|
31
|
+
`/api/v1/sequences/${encodeURIComponent(this.name)}/peek`,
|
|
32
|
+
);
|
|
33
|
+
return result.value;
|
|
34
|
+
}
|
|
35
|
+
}
|