@bunbase-ae/js 1.3.1-next.55.d32b998 → 1.3.1-next.57.ddb6045

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunbase-ae/js",
3
- "version": "1.3.1-next.55.d32b998",
3
+ "version": "1.3.1-next.57.ddb6045",
4
4
  "type": "module",
5
5
  "description": "TypeScript/JavaScript SDK for BunBase",
6
6
  "license": "UNLICENSED",
package/src/client.ts CHANGED
@@ -13,7 +13,7 @@ import { CollectionClient } from "./collection";
13
13
  import { HttpClient } from "./http";
14
14
  import { RealtimeClient } from "./realtime";
15
15
  import { StorageClient } from "./storage";
16
- import type { BunBaseClientOptions } from "./types";
16
+ import type { BunBaseClientOptions, TransactionOperation, TransactionResult } from "./types";
17
17
 
18
18
  export class BunBaseClient {
19
19
  readonly auth: AuthClient;
@@ -62,4 +62,17 @@ export class BunBaseClient {
62
62
  ): CollectionClient<T> {
63
63
  return new CollectionClient<T>(this.http, name);
64
64
  }
65
+
66
+ // Execute up to 50 create/update/delete operations across multiple collections
67
+ // atomically. All operations succeed or all are rolled back.
68
+ async batch<T = Record<string, unknown>>(
69
+ operations: TransactionOperation<T>[],
70
+ ): Promise<TransactionResult<T>[]> {
71
+ const result = await this.http.request<{ results: TransactionResult<T>[] }>(
72
+ "POST",
73
+ "/api/v1/transactions/execute",
74
+ { body: { operations } },
75
+ );
76
+ return result.results;
77
+ }
65
78
  }
package/src/index.ts CHANGED
@@ -77,6 +77,14 @@ export {
77
77
  type StorageAdapter,
78
78
  type TotpChallenge,
79
79
  type TotpSetup,
80
+ type TransactionCreate,
81
+ type TransactionDelete,
82
+ type TransactionOperation,
83
+ type TransactionResult,
84
+ type TransactionResultCreate,
85
+ type TransactionResultDelete,
86
+ type TransactionResultUpdate,
87
+ type TransactionUpdate,
80
88
  type UnsubscribeFn,
81
89
  type WithExpand,
82
90
  } from "./types";
package/src/types.ts CHANGED
@@ -239,6 +239,55 @@ export type BatchResult<T = Record<string, unknown>> =
239
239
  | BatchResultUpdate<T>
240
240
  | BatchResultDelete;
241
241
 
242
+ // ─── Transaction operations (cross-collection) ────────────────────────────────
243
+
244
+ export interface TransactionCreate<T = Record<string, unknown>> {
245
+ collection: string;
246
+ op: "create";
247
+ data: T;
248
+ }
249
+
250
+ export interface TransactionUpdate<T = Record<string, unknown>> {
251
+ collection: string;
252
+ op: "update";
253
+ id: string;
254
+ data: Partial<T>;
255
+ }
256
+
257
+ export interface TransactionDelete {
258
+ collection: string;
259
+ op: "delete";
260
+ id: string;
261
+ }
262
+
263
+ export type TransactionOperation<T = Record<string, unknown>> =
264
+ | TransactionCreate<T>
265
+ | TransactionUpdate<T>
266
+ | TransactionDelete;
267
+
268
+ export interface TransactionResultCreate<T = Record<string, unknown>> {
269
+ op: "create";
270
+ collection: string;
271
+ record: T & BunBaseRecord;
272
+ }
273
+
274
+ export interface TransactionResultUpdate<T = Record<string, unknown>> {
275
+ op: "update";
276
+ collection: string;
277
+ record: T & BunBaseRecord;
278
+ }
279
+
280
+ export interface TransactionResultDelete {
281
+ op: "delete";
282
+ collection: string;
283
+ id: string;
284
+ }
285
+
286
+ export type TransactionResult<T = Record<string, unknown>> =
287
+ | TransactionResultCreate<T>
288
+ | TransactionResultUpdate<T>
289
+ | TransactionResultDelete;
290
+
242
291
  export interface GetQuery {
243
292
  // Same expand semantics as ListQuery.
244
293
  expand?: string[];