hydrousdb 1.1.1 → 2.0.0

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.
@@ -1,5 +1,5 @@
1
- import { a9 as HttpClient, c as AnalyticsQuery, V as RequestOptions, e as AnalyticsResponse, D as DateRange, C as CountResult, p as DistributionItem, a1 as SumResult, a2 as TimeSeriesPoint, r as FieldTimeSeriesPoint, a3 as TopNItem, F as FieldStatsResult, s as Filter, u as FilteredRecordsResult, M as MultiMetricItem, a0 as StorageStatsResult } from '../http-DbiqdKlw.mjs';
2
- export { d as AnalyticsQueryType } from '../http-DbiqdKlw.mjs';
1
+ import { a9 as HttpClient, c as AnalyticsQuery, V as RequestOptions, e as AnalyticsResponse, D as DateRange, C as CountResult, p as DistributionItem, a1 as SumResult, a2 as TimeSeriesPoint, r as FieldTimeSeriesPoint, a3 as TopNItem, F as FieldStatsResult, s as Filter, u as FilteredRecordsResult, M as MultiMetricItem, a0 as StorageStatsResult } from '../http-DTukpdAU.mjs';
2
+ export { d as AnalyticsQueryType } from '../http-DTukpdAU.mjs';
3
3
 
4
4
  type AnalyticsResult<T> = Omit<AnalyticsResponse, 'data'> & {
5
5
  data: T;
@@ -7,121 +7,126 @@ type AnalyticsResult<T> = Omit<AnalyticsResponse, 'data'> & {
7
7
  bucketKey: string | null;
8
8
  projectId: string;
9
9
  };
10
+ /** Options accepted by every analytics method */
11
+ interface BucketOptions {
12
+ /**
13
+ * The bucket to run the analytics query against.
14
+ * Required on all analytics calls.
15
+ *
16
+ * @example
17
+ * const { data } = await db.analytics.count({ bucketKey: 'orders' });
18
+ */
19
+ bucketKey: string;
20
+ }
10
21
  declare class AnalyticsClient {
11
22
  private readonly http;
12
23
  constructor(http: HttpClient);
13
- private get path();
24
+ /** Builds the path for a given bucket: /api/analytics/:bucketKey/:securityKey */
25
+ private path;
14
26
  /**
15
27
  * Run any analytics query with full control over the payload.
16
28
  * Prefer the typed convenience methods below for everyday use.
17
29
  */
18
- query<T = unknown>(payload: AnalyticsQuery, opts?: RequestOptions): Promise<AnalyticsResult<T>>;
30
+ query<T = unknown>(payload: AnalyticsQuery, options: BucketOptions & RequestOptions): Promise<AnalyticsResult<T>>;
19
31
  /**
20
32
  * Total record count, optionally scoped to a date range.
21
- * Server `queryType`: **"count"**
22
33
  *
23
34
  * @example
24
- * const { data } = await db.analytics.count();
25
- * console.log(data.count); // 1234
35
+ * const { data } = await db.analytics.count({ bucketKey: 'orders' });
36
+ * console.log(data.count);
26
37
  *
27
- * // With date range
28
38
  * const { data } = await db.analytics.count({
29
- * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' }
39
+ * bucketKey: 'orders',
40
+ * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' },
30
41
  * });
31
42
  */
32
- count(options?: {
43
+ count(options: {
33
44
  dateRange?: DateRange;
34
- } & RequestOptions): Promise<AnalyticsResult<CountResult>>;
45
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<CountResult>>;
35
46
  /**
36
47
  * Value distribution (histogram) for a field.
37
- * Server `queryType`: **"distribution"**
38
48
  *
39
49
  * @example
40
- * const { data } = await db.analytics.distribution('status');
50
+ * const { data } = await db.analytics.distribution('status', { bucketKey: 'orders' });
41
51
  * // [{ value: 'active', count: 80 }, { value: 'archived', count: 20 }]
42
52
  */
43
- distribution(field: string, options?: {
53
+ distribution(field: string, options: {
44
54
  limit?: number;
45
55
  order?: 'asc' | 'desc';
46
56
  dateRange?: DateRange;
47
- } & RequestOptions): Promise<AnalyticsResult<DistributionItem[]>>;
57
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<DistributionItem[]>>;
48
58
  /**
49
59
  * Sum a numeric field, with optional group-by.
50
- * Server `queryType`: **"sum"**
51
60
  *
52
61
  * @example
53
- * const { data } = await db.analytics.sum('revenue', { groupBy: 'region' });
62
+ * const { data } = await db.analytics.sum('revenue', { bucketKey: 'orders', groupBy: 'region' });
54
63
  */
55
- sum(field: string, options?: {
64
+ sum(field: string, options: {
56
65
  groupBy?: string;
57
66
  limit?: number;
58
67
  dateRange?: DateRange;
59
- } & RequestOptions): Promise<AnalyticsResult<SumResult>>;
68
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<SumResult>>;
60
69
  /**
61
70
  * Record count grouped over time.
62
- * Server `queryType`: **"timeSeries"**
63
71
  *
64
72
  * @example
65
- * const { data } = await db.analytics.timeSeries({ granularity: 'day' });
73
+ * const { data } = await db.analytics.timeSeries({ bucketKey: 'orders', granularity: 'day' });
66
74
  * // [{ date: '2025-01-01', count: 42 }, ...]
67
75
  */
68
- timeSeries(options?: {
76
+ timeSeries(options: {
69
77
  granularity?: 'hour' | 'day' | 'week' | 'month';
70
78
  dateRange?: DateRange;
71
- } & RequestOptions): Promise<AnalyticsResult<TimeSeriesPoint[]>>;
79
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<TimeSeriesPoint[]>>;
72
80
  /**
73
81
  * Aggregate a numeric field over time.
74
- * Server `queryType`: **"fieldTimeSeries"**
75
82
  *
76
83
  * @example
77
84
  * const { data } = await db.analytics.fieldTimeSeries('revenue', {
85
+ * bucketKey: 'orders',
78
86
  * granularity: 'month',
79
87
  * aggregation: 'sum',
80
88
  * });
81
89
  */
82
- fieldTimeSeries(field: string, options?: {
90
+ fieldTimeSeries(field: string, options: {
83
91
  aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';
84
92
  granularity?: 'hour' | 'day' | 'week' | 'month';
85
93
  dateRange?: DateRange;
86
- } & RequestOptions): Promise<AnalyticsResult<FieldTimeSeriesPoint[]>>;
94
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<FieldTimeSeriesPoint[]>>;
87
95
  /**
88
96
  * Top N most frequent values for a field.
89
- * Server `queryType`: **"topN"**
90
97
  *
91
98
  * @example
92
- * const { data } = await db.analytics.topN('country', 5);
99
+ * const { data } = await db.analytics.topN('country', 5, { bucketKey: 'users' });
93
100
  * // [{ label: 'US', value: 'US', count: 500 }, ...]
94
101
  */
95
- topN(field: string, n?: number, options?: {
102
+ topN(field: string, n: number | undefined, options: {
96
103
  labelField?: string;
97
104
  order?: 'asc' | 'desc';
98
105
  dateRange?: DateRange;
99
- } & RequestOptions): Promise<AnalyticsResult<TopNItem[]>>;
106
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<TopNItem[]>>;
100
107
  /**
101
108
  * Statistical summary for a numeric field: min, max, avg, stddev, p50, p90, p99.
102
- * Server `queryType`: **"stats"**
103
109
  *
104
110
  * @example
105
- * const { data } = await db.analytics.stats('score');
111
+ * const { data } = await db.analytics.stats('score', { bucketKey: 'users' });
106
112
  * console.log(data.avg, data.p99);
107
113
  */
108
- stats(field: string, options?: {
114
+ stats(field: string, options: {
109
115
  dateRange?: DateRange;
110
- } & RequestOptions): Promise<AnalyticsResult<FieldStatsResult>>;
116
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<FieldStatsResult>>;
111
117
  /**
112
118
  * Filtered, paginated raw records with optional field projection.
113
119
  * Supports filter ops: == != > < >= <= CONTAINS
114
- * Server `queryType`: **"records"**
115
120
  *
116
121
  * @example
117
122
  * const { data } = await db.analytics.records({
123
+ * bucketKey: 'users',
118
124
  * filters: [{ field: 'role', op: '==', value: 'admin' }],
119
125
  * selectFields: ['email', 'createdAt'],
120
126
  * limit: 25,
121
127
  * });
122
- * console.log(data.data, data.hasMore);
123
128
  */
124
- records(options?: {
129
+ records(options: {
125
130
  filters?: Filter[];
126
131
  selectFields?: string[];
127
132
  limit?: number;
@@ -129,40 +134,42 @@ declare class AnalyticsClient {
129
134
  orderBy?: string;
130
135
  order?: 'asc' | 'desc';
131
136
  dateRange?: DateRange;
132
- } & RequestOptions): Promise<AnalyticsResult<FilteredRecordsResult>>;
137
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<FilteredRecordsResult>>;
133
138
  /**
134
- * Multiple aggregations in a single BigQuery call — ideal for dashboard stat cards.
135
- * Server `queryType`: **"multiMetric"**
139
+ * Multiple aggregations in a single call — ideal for dashboard stat cards.
136
140
  *
137
141
  * @example
138
- * const { data } = await db.analytics.multiMetric([
139
- * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },
140
- * { name: 'avgScore', field: 'score', aggregation: 'avg' },
141
- * { name: 'userCount', field: 'userId', aggregation: 'count' },
142
- * ]);
143
- * console.log(data.totalRevenue, data.avgScore, data.userCount);
142
+ * const { data } = await db.analytics.multiMetric(
143
+ * [
144
+ * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },
145
+ * { name: 'avgScore', field: 'score', aggregation: 'avg' },
146
+ * ],
147
+ * { bucketKey: 'orders' }
148
+ * );
149
+ * console.log(data.totalRevenue, data.avgScore);
144
150
  */
145
- multiMetric(metrics: MultiMetricItem[], options?: {
151
+ multiMetric(metrics: MultiMetricItem[], options: {
146
152
  dateRange?: DateRange;
147
- } & RequestOptions): Promise<AnalyticsResult<Record<string, number>>>;
153
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<Record<string, number>>>;
148
154
  /**
149
- * Storage statistics for the bucket — total records, bytes, avg/min/max size.
150
- * Server `queryType`: **"storageStats"**
155
+ * Storage statistics for a bucket — total records, bytes, avg/min/max size.
151
156
  *
152
157
  * @example
153
- * const { data } = await db.analytics.storageStats();
158
+ * const { data } = await db.analytics.storageStats({ bucketKey: 'orders' });
154
159
  * console.log(data.totalRecords, data.totalBytes);
155
160
  */
156
- storageStats(options?: {
161
+ storageStats(options: {
157
162
  dateRange?: DateRange;
158
- } & RequestOptions): Promise<AnalyticsResult<StorageStatsResult>>;
163
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<StorageStatsResult>>;
159
164
  /**
160
165
  * Compare a metric across multiple buckets in one query.
161
- * Server `queryType`: **"crossBucket"**
166
+ * Note: `bucketKey` here is used only for auth — the actual buckets
167
+ * compared are specified via `bucketKeys`.
162
168
  *
163
169
  * @example
164
170
  * const { data } = await db.analytics.crossBucket({
165
- * bucketKeys: ['sales', 'refunds', 'trials'],
171
+ * bucketKey: 'sales-2025', // auth bucket
172
+ * bucketKeys: ['sales-2024', 'sales-2025'],
166
173
  * field: 'amount',
167
174
  * aggregation: 'sum',
168
175
  * });
@@ -172,7 +179,7 @@ declare class AnalyticsClient {
172
179
  field: string;
173
180
  aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';
174
181
  dateRange?: DateRange;
175
- } & RequestOptions): Promise<AnalyticsResult<unknown>>;
182
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<unknown>>;
176
183
  }
177
184
 
178
- export { AnalyticsClient, AnalyticsQuery, AnalyticsResponse, CountResult, DateRange, DistributionItem, FieldStatsResult, FieldTimeSeriesPoint, Filter, FilteredRecordsResult, MultiMetricItem, StorageStatsResult, SumResult, TimeSeriesPoint, TopNItem };
185
+ export { AnalyticsClient, AnalyticsQuery, AnalyticsResponse, type BucketOptions, CountResult, DateRange, DistributionItem, FieldStatsResult, FieldTimeSeriesPoint, Filter, FilteredRecordsResult, MultiMetricItem, StorageStatsResult, SumResult, TimeSeriesPoint, TopNItem };
@@ -1,5 +1,5 @@
1
- import { a9 as HttpClient, c as AnalyticsQuery, V as RequestOptions, e as AnalyticsResponse, D as DateRange, C as CountResult, p as DistributionItem, a1 as SumResult, a2 as TimeSeriesPoint, r as FieldTimeSeriesPoint, a3 as TopNItem, F as FieldStatsResult, s as Filter, u as FilteredRecordsResult, M as MultiMetricItem, a0 as StorageStatsResult } from '../http-DbiqdKlw.js';
2
- export { d as AnalyticsQueryType } from '../http-DbiqdKlw.js';
1
+ import { a9 as HttpClient, c as AnalyticsQuery, V as RequestOptions, e as AnalyticsResponse, D as DateRange, C as CountResult, p as DistributionItem, a1 as SumResult, a2 as TimeSeriesPoint, r as FieldTimeSeriesPoint, a3 as TopNItem, F as FieldStatsResult, s as Filter, u as FilteredRecordsResult, M as MultiMetricItem, a0 as StorageStatsResult } from '../http-DTukpdAU.js';
2
+ export { d as AnalyticsQueryType } from '../http-DTukpdAU.js';
3
3
 
4
4
  type AnalyticsResult<T> = Omit<AnalyticsResponse, 'data'> & {
5
5
  data: T;
@@ -7,121 +7,126 @@ type AnalyticsResult<T> = Omit<AnalyticsResponse, 'data'> & {
7
7
  bucketKey: string | null;
8
8
  projectId: string;
9
9
  };
10
+ /** Options accepted by every analytics method */
11
+ interface BucketOptions {
12
+ /**
13
+ * The bucket to run the analytics query against.
14
+ * Required on all analytics calls.
15
+ *
16
+ * @example
17
+ * const { data } = await db.analytics.count({ bucketKey: 'orders' });
18
+ */
19
+ bucketKey: string;
20
+ }
10
21
  declare class AnalyticsClient {
11
22
  private readonly http;
12
23
  constructor(http: HttpClient);
13
- private get path();
24
+ /** Builds the path for a given bucket: /api/analytics/:bucketKey/:securityKey */
25
+ private path;
14
26
  /**
15
27
  * Run any analytics query with full control over the payload.
16
28
  * Prefer the typed convenience methods below for everyday use.
17
29
  */
18
- query<T = unknown>(payload: AnalyticsQuery, opts?: RequestOptions): Promise<AnalyticsResult<T>>;
30
+ query<T = unknown>(payload: AnalyticsQuery, options: BucketOptions & RequestOptions): Promise<AnalyticsResult<T>>;
19
31
  /**
20
32
  * Total record count, optionally scoped to a date range.
21
- * Server `queryType`: **"count"**
22
33
  *
23
34
  * @example
24
- * const { data } = await db.analytics.count();
25
- * console.log(data.count); // 1234
35
+ * const { data } = await db.analytics.count({ bucketKey: 'orders' });
36
+ * console.log(data.count);
26
37
  *
27
- * // With date range
28
38
  * const { data } = await db.analytics.count({
29
- * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' }
39
+ * bucketKey: 'orders',
40
+ * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' },
30
41
  * });
31
42
  */
32
- count(options?: {
43
+ count(options: {
33
44
  dateRange?: DateRange;
34
- } & RequestOptions): Promise<AnalyticsResult<CountResult>>;
45
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<CountResult>>;
35
46
  /**
36
47
  * Value distribution (histogram) for a field.
37
- * Server `queryType`: **"distribution"**
38
48
  *
39
49
  * @example
40
- * const { data } = await db.analytics.distribution('status');
50
+ * const { data } = await db.analytics.distribution('status', { bucketKey: 'orders' });
41
51
  * // [{ value: 'active', count: 80 }, { value: 'archived', count: 20 }]
42
52
  */
43
- distribution(field: string, options?: {
53
+ distribution(field: string, options: {
44
54
  limit?: number;
45
55
  order?: 'asc' | 'desc';
46
56
  dateRange?: DateRange;
47
- } & RequestOptions): Promise<AnalyticsResult<DistributionItem[]>>;
57
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<DistributionItem[]>>;
48
58
  /**
49
59
  * Sum a numeric field, with optional group-by.
50
- * Server `queryType`: **"sum"**
51
60
  *
52
61
  * @example
53
- * const { data } = await db.analytics.sum('revenue', { groupBy: 'region' });
62
+ * const { data } = await db.analytics.sum('revenue', { bucketKey: 'orders', groupBy: 'region' });
54
63
  */
55
- sum(field: string, options?: {
64
+ sum(field: string, options: {
56
65
  groupBy?: string;
57
66
  limit?: number;
58
67
  dateRange?: DateRange;
59
- } & RequestOptions): Promise<AnalyticsResult<SumResult>>;
68
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<SumResult>>;
60
69
  /**
61
70
  * Record count grouped over time.
62
- * Server `queryType`: **"timeSeries"**
63
71
  *
64
72
  * @example
65
- * const { data } = await db.analytics.timeSeries({ granularity: 'day' });
73
+ * const { data } = await db.analytics.timeSeries({ bucketKey: 'orders', granularity: 'day' });
66
74
  * // [{ date: '2025-01-01', count: 42 }, ...]
67
75
  */
68
- timeSeries(options?: {
76
+ timeSeries(options: {
69
77
  granularity?: 'hour' | 'day' | 'week' | 'month';
70
78
  dateRange?: DateRange;
71
- } & RequestOptions): Promise<AnalyticsResult<TimeSeriesPoint[]>>;
79
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<TimeSeriesPoint[]>>;
72
80
  /**
73
81
  * Aggregate a numeric field over time.
74
- * Server `queryType`: **"fieldTimeSeries"**
75
82
  *
76
83
  * @example
77
84
  * const { data } = await db.analytics.fieldTimeSeries('revenue', {
85
+ * bucketKey: 'orders',
78
86
  * granularity: 'month',
79
87
  * aggregation: 'sum',
80
88
  * });
81
89
  */
82
- fieldTimeSeries(field: string, options?: {
90
+ fieldTimeSeries(field: string, options: {
83
91
  aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';
84
92
  granularity?: 'hour' | 'day' | 'week' | 'month';
85
93
  dateRange?: DateRange;
86
- } & RequestOptions): Promise<AnalyticsResult<FieldTimeSeriesPoint[]>>;
94
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<FieldTimeSeriesPoint[]>>;
87
95
  /**
88
96
  * Top N most frequent values for a field.
89
- * Server `queryType`: **"topN"**
90
97
  *
91
98
  * @example
92
- * const { data } = await db.analytics.topN('country', 5);
99
+ * const { data } = await db.analytics.topN('country', 5, { bucketKey: 'users' });
93
100
  * // [{ label: 'US', value: 'US', count: 500 }, ...]
94
101
  */
95
- topN(field: string, n?: number, options?: {
102
+ topN(field: string, n: number | undefined, options: {
96
103
  labelField?: string;
97
104
  order?: 'asc' | 'desc';
98
105
  dateRange?: DateRange;
99
- } & RequestOptions): Promise<AnalyticsResult<TopNItem[]>>;
106
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<TopNItem[]>>;
100
107
  /**
101
108
  * Statistical summary for a numeric field: min, max, avg, stddev, p50, p90, p99.
102
- * Server `queryType`: **"stats"**
103
109
  *
104
110
  * @example
105
- * const { data } = await db.analytics.stats('score');
111
+ * const { data } = await db.analytics.stats('score', { bucketKey: 'users' });
106
112
  * console.log(data.avg, data.p99);
107
113
  */
108
- stats(field: string, options?: {
114
+ stats(field: string, options: {
109
115
  dateRange?: DateRange;
110
- } & RequestOptions): Promise<AnalyticsResult<FieldStatsResult>>;
116
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<FieldStatsResult>>;
111
117
  /**
112
118
  * Filtered, paginated raw records with optional field projection.
113
119
  * Supports filter ops: == != > < >= <= CONTAINS
114
- * Server `queryType`: **"records"**
115
120
  *
116
121
  * @example
117
122
  * const { data } = await db.analytics.records({
123
+ * bucketKey: 'users',
118
124
  * filters: [{ field: 'role', op: '==', value: 'admin' }],
119
125
  * selectFields: ['email', 'createdAt'],
120
126
  * limit: 25,
121
127
  * });
122
- * console.log(data.data, data.hasMore);
123
128
  */
124
- records(options?: {
129
+ records(options: {
125
130
  filters?: Filter[];
126
131
  selectFields?: string[];
127
132
  limit?: number;
@@ -129,40 +134,42 @@ declare class AnalyticsClient {
129
134
  orderBy?: string;
130
135
  order?: 'asc' | 'desc';
131
136
  dateRange?: DateRange;
132
- } & RequestOptions): Promise<AnalyticsResult<FilteredRecordsResult>>;
137
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<FilteredRecordsResult>>;
133
138
  /**
134
- * Multiple aggregations in a single BigQuery call — ideal for dashboard stat cards.
135
- * Server `queryType`: **"multiMetric"**
139
+ * Multiple aggregations in a single call — ideal for dashboard stat cards.
136
140
  *
137
141
  * @example
138
- * const { data } = await db.analytics.multiMetric([
139
- * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },
140
- * { name: 'avgScore', field: 'score', aggregation: 'avg' },
141
- * { name: 'userCount', field: 'userId', aggregation: 'count' },
142
- * ]);
143
- * console.log(data.totalRevenue, data.avgScore, data.userCount);
142
+ * const { data } = await db.analytics.multiMetric(
143
+ * [
144
+ * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },
145
+ * { name: 'avgScore', field: 'score', aggregation: 'avg' },
146
+ * ],
147
+ * { bucketKey: 'orders' }
148
+ * );
149
+ * console.log(data.totalRevenue, data.avgScore);
144
150
  */
145
- multiMetric(metrics: MultiMetricItem[], options?: {
151
+ multiMetric(metrics: MultiMetricItem[], options: {
146
152
  dateRange?: DateRange;
147
- } & RequestOptions): Promise<AnalyticsResult<Record<string, number>>>;
153
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<Record<string, number>>>;
148
154
  /**
149
- * Storage statistics for the bucket — total records, bytes, avg/min/max size.
150
- * Server `queryType`: **"storageStats"**
155
+ * Storage statistics for a bucket — total records, bytes, avg/min/max size.
151
156
  *
152
157
  * @example
153
- * const { data } = await db.analytics.storageStats();
158
+ * const { data } = await db.analytics.storageStats({ bucketKey: 'orders' });
154
159
  * console.log(data.totalRecords, data.totalBytes);
155
160
  */
156
- storageStats(options?: {
161
+ storageStats(options: {
157
162
  dateRange?: DateRange;
158
- } & RequestOptions): Promise<AnalyticsResult<StorageStatsResult>>;
163
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<StorageStatsResult>>;
159
164
  /**
160
165
  * Compare a metric across multiple buckets in one query.
161
- * Server `queryType`: **"crossBucket"**
166
+ * Note: `bucketKey` here is used only for auth — the actual buckets
167
+ * compared are specified via `bucketKeys`.
162
168
  *
163
169
  * @example
164
170
  * const { data } = await db.analytics.crossBucket({
165
- * bucketKeys: ['sales', 'refunds', 'trials'],
171
+ * bucketKey: 'sales-2025', // auth bucket
172
+ * bucketKeys: ['sales-2024', 'sales-2025'],
166
173
  * field: 'amount',
167
174
  * aggregation: 'sum',
168
175
  * });
@@ -172,7 +179,7 @@ declare class AnalyticsClient {
172
179
  field: string;
173
180
  aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';
174
181
  dateRange?: DateRange;
175
- } & RequestOptions): Promise<AnalyticsResult<unknown>>;
182
+ } & BucketOptions & RequestOptions): Promise<AnalyticsResult<unknown>>;
176
183
  }
177
184
 
178
- export { AnalyticsClient, AnalyticsQuery, AnalyticsResponse, CountResult, DateRange, DistributionItem, FieldStatsResult, FieldTimeSeriesPoint, Filter, FilteredRecordsResult, MultiMetricItem, StorageStatsResult, SumResult, TimeSeriesPoint, TopNItem };
185
+ export { AnalyticsClient, AnalyticsQuery, AnalyticsResponse, type BucketOptions, CountResult, DateRange, DistributionItem, FieldStatsResult, FieldTimeSeriesPoint, Filter, FilteredRecordsResult, MultiMetricItem, StorageStatsResult, SumResult, TimeSeriesPoint, TopNItem };