@boltstore/client 0.5.0 → 0.5.2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@boltstore/client",
3
- "version": "0.5.0",
4
- "description": "TypeScript SDK for Boltstore \u2014 works in Bun, Node 18+, browsers, React Native",
3
+ "version": "0.5.2",
4
+ "description": "TypeScript SDK for Boltstore works in Bun, Node 18+, browsers, React Native",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "bin": {
@@ -41,5 +41,8 @@
41
41
  "repository": {
42
42
  "type": "git",
43
43
  "url": "https://github.com/boltstore/client"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
44
47
  }
45
48
  }
package/src/index.ts CHANGED
@@ -27,8 +27,10 @@ export {
27
27
  deleteRecord,
28
28
  getAllRecords,
29
29
  batch,
30
+ aggregateRecords,
31
+ bulkCreateRecords,
30
32
  } from "./records";
31
- export type { RecordQuery, RecordListResult } from "./records";
33
+ export type { RecordQuery, RecordListResult, AggregateQuery, AggregateResult } from "./records";
32
34
 
33
35
  // ── Collections ──
34
36
  export {
package/src/records.ts CHANGED
@@ -13,6 +13,8 @@ export interface RecordQuery extends PaginationParams {
13
13
  perPage?: number;
14
14
  expand?: string;
15
15
  search?: string;
16
+ fields?: string;
17
+ cursor?: string;
16
18
  }
17
19
 
18
20
  export interface RecordListResult {
@@ -21,6 +23,8 @@ export interface RecordListResult {
21
23
  perPage: number;
22
24
  totalItems: number;
23
25
  totalPages: number;
26
+ hasNextPage?: boolean;
27
+ nextCursor?: string;
24
28
  }
25
29
 
26
30
  // ── Batch Operations ──
@@ -55,6 +59,91 @@ export async function batch(
55
59
  return result.data.results;
56
60
  }
57
61
 
62
+ // ── Aggregate ──
63
+
64
+ export interface AggregateQuery {
65
+ groupBy?: string | string[];
66
+ aggregate?: "count" | "sum" | "avg" | "min" | "max";
67
+ aggregateField?: string;
68
+ filter?: string;
69
+ sort?: string;
70
+ limit?: number;
71
+ }
72
+
73
+ export interface AggregateResult {
74
+ items: Record<string, unknown>[];
75
+ groupBy: string[];
76
+ aggregate?: string;
77
+ total?: number;
78
+ }
79
+
80
+ /**
81
+ * Aggregate records (GROUP BY / COUNT / SUM / AVG / MIN / MAX).
82
+ *
83
+ * @example
84
+ * const result = await aggregateRecords(client, "jobs", {
85
+ * groupBy: "company",
86
+ * aggregate: "count",
87
+ * sort: "-total",
88
+ * });
89
+ */
90
+ export async function aggregateRecords(
91
+ client: BoltstoreClient,
92
+ collection: string,
93
+ query?: AggregateQuery
94
+ ): Promise<AggregateResult> {
95
+ const params: Record<string, string> = {};
96
+
97
+ if (query?.groupBy) {
98
+ params.groupBy = Array.isArray(query.groupBy)
99
+ ? query.groupBy.join(",")
100
+ : query.groupBy;
101
+ }
102
+ if (query?.aggregate) params.aggregate = query.aggregate;
103
+ if (query?.aggregateField) params.aggregateField = query.aggregateField;
104
+ if (query?.filter) params.filter = query.filter;
105
+ if (query?.sort) params.sort = query.sort;
106
+ if (query?.limit) params.limit = String(query.limit);
107
+
108
+ const result = await client.get<AggregateResult>(
109
+ `/api/collections/${collection}/aggregate`,
110
+ params
111
+ );
112
+
113
+ if (!result.success || !result.data) {
114
+ throw new Error(result.error?.message ?? "Failed to aggregate records");
115
+ }
116
+
117
+ return result.data;
118
+ }
119
+
120
+ /**
121
+ * Bulk create multiple records in a single request.
122
+ * Uses the bulk array endpoint (more efficient than batch API).
123
+ *
124
+ * @example
125
+ * const created = await bulkCreateRecords(client, "todos", [
126
+ * { title: "A" },
127
+ * { title: "B" },
128
+ * ]);
129
+ */
130
+ export async function bulkCreateRecords(
131
+ client: BoltstoreClient,
132
+ collection: string,
133
+ records: Record<string, unknown>[]
134
+ ): Promise<RecordData[]> {
135
+ const result = await client.post<RecordData[]>(
136
+ `/api/collections/${collection}/records`,
137
+ records
138
+ );
139
+
140
+ if (!result.success || !result.data) {
141
+ throw new Error(result.error?.message ?? "Failed to bulk create records");
142
+ }
143
+
144
+ return result.data;
145
+ }
146
+
58
147
  // ── CRUD Operations ──
59
148
 
60
149
  /**
@@ -80,6 +169,8 @@ export async function listRecords(
80
169
  if (query?.perPage) params.perPage = String(query.perPage);
81
170
  if (query?.expand) params.expand = query.expand;
82
171
  if (query?.search) params.search = query.search;
172
+ if (query?.fields) params.fields = query.fields;
173
+ if (query?.cursor) params.cursor = query.cursor;
83
174
 
84
175
  const result = await client.get<RecordListResult>(
85
176
  `/api/collections/${collection}/records`,
File without changes