@boltstore/client 0.5.0 → 0.5.1
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 +5 -2
- package/src/index.ts +3 -1
- package/src/records.ts +85 -0
- package/src/typegen/cli.ts +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boltstore/client",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "TypeScript SDK for Boltstore
|
|
3
|
+
"version": "0.5.1",
|
|
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
|
@@ -55,6 +55,91 @@ export async function batch(
|
|
|
55
55
|
return result.data.results;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// ── Aggregate ──
|
|
59
|
+
|
|
60
|
+
export interface AggregateQuery {
|
|
61
|
+
groupBy?: string | string[];
|
|
62
|
+
aggregate?: "count" | "sum" | "avg" | "min" | "max";
|
|
63
|
+
aggregateField?: string;
|
|
64
|
+
filter?: string;
|
|
65
|
+
sort?: string;
|
|
66
|
+
limit?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface AggregateResult {
|
|
70
|
+
items: Record<string, unknown>[];
|
|
71
|
+
groupBy: string[];
|
|
72
|
+
aggregate?: string;
|
|
73
|
+
total?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Aggregate records (GROUP BY / COUNT / SUM / AVG / MIN / MAX).
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const result = await aggregateRecords(client, "jobs", {
|
|
81
|
+
* groupBy: "company",
|
|
82
|
+
* aggregate: "count",
|
|
83
|
+
* sort: "-total",
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
export async function aggregateRecords(
|
|
87
|
+
client: BoltstoreClient,
|
|
88
|
+
collection: string,
|
|
89
|
+
query?: AggregateQuery
|
|
90
|
+
): Promise<AggregateResult> {
|
|
91
|
+
const params: Record<string, string> = {};
|
|
92
|
+
|
|
93
|
+
if (query?.groupBy) {
|
|
94
|
+
params.groupBy = Array.isArray(query.groupBy)
|
|
95
|
+
? query.groupBy.join(",")
|
|
96
|
+
: query.groupBy;
|
|
97
|
+
}
|
|
98
|
+
if (query?.aggregate) params.aggregate = query.aggregate;
|
|
99
|
+
if (query?.aggregateField) params.aggregateField = query.aggregateField;
|
|
100
|
+
if (query?.filter) params.filter = query.filter;
|
|
101
|
+
if (query?.sort) params.sort = query.sort;
|
|
102
|
+
if (query?.limit) params.limit = String(query.limit);
|
|
103
|
+
|
|
104
|
+
const result = await client.get<AggregateResult>(
|
|
105
|
+
`/api/collections/${collection}/aggregate`,
|
|
106
|
+
params
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (!result.success || !result.data) {
|
|
110
|
+
throw new Error(result.error?.message ?? "Failed to aggregate records");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return result.data;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Bulk create multiple records in a single request.
|
|
118
|
+
* Uses the bulk array endpoint (more efficient than batch API).
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const created = await bulkCreateRecords(client, "todos", [
|
|
122
|
+
* { title: "A" },
|
|
123
|
+
* { title: "B" },
|
|
124
|
+
* ]);
|
|
125
|
+
*/
|
|
126
|
+
export async function bulkCreateRecords(
|
|
127
|
+
client: BoltstoreClient,
|
|
128
|
+
collection: string,
|
|
129
|
+
records: Record<string, unknown>[]
|
|
130
|
+
): Promise<RecordData[]> {
|
|
131
|
+
const result = await client.post<RecordData[]>(
|
|
132
|
+
`/api/collections/${collection}/records`,
|
|
133
|
+
records
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (!result.success || !result.data) {
|
|
137
|
+
throw new Error(result.error?.message ?? "Failed to bulk create records");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result.data;
|
|
141
|
+
}
|
|
142
|
+
|
|
58
143
|
// ── CRUD Operations ──
|
|
59
144
|
|
|
60
145
|
/**
|
package/src/typegen/cli.ts
CHANGED
|
File without changes
|