@protobase/client 0.19.16 → 0.20.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.
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FilterInput, ListParams, MapParams } from "./query-string.js";
2
2
  import { ClientOptions } from "./transport.js";
3
3
  import { UploadProgress } from "./upload-request.js";
4
- import { BatchOp, BatchResult, Facet, Histogram, ListPage, MapResult, MetaResult, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
4
+ import { Aggregate, AggregateParams, BatchOp, BatchResult, Facet, Histogram, ListPage, MapResult, MetaResult, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
5
5
  import { KeyValue } from "@protobase/schema";
6
6
  //#region src/client.d.ts
7
7
  /** How `invoke` calls a function: GET without a body, POST with one, unless `method` says otherwise. */
@@ -59,6 +59,7 @@ export declare const createClient: (options?: ClientOptions) => {
59
59
  limit?: number;
60
60
  label?: string;
61
61
  }) => Promise<Facet[]>;
62
+ aggregate: (resource: ResourceRef, params: AggregateParams) => Promise<Aggregate>;
62
63
  series: (resource: ResourceRef, params: SeriesParams & {
63
64
  filter?: FilterInput;
64
65
  }) => Promise<Series>;
package/dist/client.js CHANGED
@@ -152,6 +152,32 @@ const createClient = (options = {}) => {
152
152
  })
153
153
  })).json()).facets;
154
154
  };
155
+ /** Totals per value of a field, or per bucket of a date field (`:aggregate`). */
156
+ const aggregate = async (resource, params) => {
157
+ const body = await (await send({
158
+ method: "GET",
159
+ path: `/${nameOf(resource)}:aggregate`,
160
+ query: queryString({
161
+ group_by: params.groupBy,
162
+ filter: filterText(params.filter) || void 0,
163
+ sum: params.sum,
164
+ average: params.average,
165
+ limit: params.limit,
166
+ label: params.label,
167
+ granularity: params.granularity,
168
+ range: params.range,
169
+ from: params.from,
170
+ to: params.to,
171
+ time_zone: params.timeZone
172
+ })
173
+ })).json();
174
+ return {
175
+ groupBy: body.group_by,
176
+ granularity: body.granularity,
177
+ timeZone: body.time_zone,
178
+ groups: body.groups
179
+ };
180
+ };
155
181
  const series = async (resource, params) => {
156
182
  const body = await (await send({
157
183
  method: "GET",
@@ -289,6 +315,7 @@ const createClient = (options = {}) => {
289
315
  reveal,
290
316
  batchWrite,
291
317
  facets,
318
+ aggregate,
292
319
  series,
293
320
  histogram,
294
321
  map,
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FilterInput, ListParams, MapParams, filterText, listWire } from "./query-string.js";
2
2
  import { ClientOptions } from "./transport.js";
3
3
  import { UploadProgress } from "./upload-request.js";
4
- import { BatchOp, BatchRef, BatchResult, Facet, Histogram, HistogramBucket, ListPage, MapBounds, MapBucket, MapLayerModel, MapResult, Meta, MetaResult, PluginRef, RecordOf, RecordPermissions, RecordPhotos, RelatedLabels, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile, StoredFileVariant } from "./types.js";
4
+ import { Aggregate, AggregateGroup, AggregateParams, BatchOp, BatchRef, BatchResult, Facet, Histogram, HistogramBucket, ListPage, MapBounds, MapBucket, MapLayerModel, MapResult, Meta, MetaResult, PluginRef, RecordOf, RecordPermissions, RecordPhotos, RelatedLabels, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile, StoredFileVariant } from "./types.js";
5
5
  import { Client, InvokeOptions, UploadOptions, UploadResult, createClient } from "./client.js";
6
6
  import { ApiError, PreconditionFailedError, ProblemDetails, ProblemError, isApiError } from "./problem.js";
7
7
  import { fileUrl } from "./file-urls.js";
@@ -18,4 +18,4 @@ import { AuthSession, AuthSessionOptions, createAuthSession, tokenExpiry } from
18
18
  import { createStaticSession } from "./static-session.js";
19
19
  import { AssistantClient, AssistantClientOptions, AssistantConnection, createAssistantClient } from "./assistant.js";
20
20
  import { RuntimeClient, RuntimeClientOptions, RuntimeLastUpdate, RuntimePolicy, RuntimeStatus, RuntimeUpdateStage, createRuntimeClient } from "./runtime.js";
21
- export { type AccountSecurity, type AccountSignIn, type ActiveRole, ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type CurrentOrganization, type Facet, type FilterInput, type Histogram, type HistogramBucket, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type Meta, type MetaResult, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationRole, type OrganizationsClient, type Passkey, type PlatformSignIn, type PluginRef, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type RecordPhotos, type RelatedLabels, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimeLastUpdate, type RuntimePolicy, type RuntimeStatus, type RuntimeUpdateStage, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
21
+ export { type AccountSecurity, type AccountSignIn, type ActiveRole, type Aggregate, type AggregateGroup, type AggregateParams, ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type CurrentOrganization, type Facet, type FilterInput, type Histogram, type HistogramBucket, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type Meta, type MetaResult, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationRole, type OrganizationsClient, type Passkey, type PlatformSignIn, type PluginRef, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type RecordPhotos, type RelatedLabels, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimeLastUpdate, type RuntimePolicy, type RuntimeStatus, type RuntimeUpdateStage, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
@@ -23,6 +23,7 @@ const routedClient = (own, sourceOf) => {
23
23
  return (apis[0] ?? own).batchWrite(ops);
24
24
  },
25
25
  facets: (resource, field, options) => to(resource).facets(resource, field, options),
26
+ aggregate: (resource, params) => to(resource).aggregate(resource, params),
26
27
  series: (resource, params) => to(resource).series(resource, params),
27
28
  histogram: (resource, field, options) => to(resource).histogram(resource, field, options),
28
29
  map: (resource, params) => to(resource).map(resource, params),
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { FilterInput } from "./query-string.js";
1
2
  import { BottomBarModel, InferRecord, ResourceModel, SignInViewModel, UserMenuModel, ViewModel } from "@protobase/schema";
2
3
  import { PageModel } from "@protobase/layout";
3
4
  //#region src/types.d.ts
@@ -54,6 +55,39 @@ export type SeriesParams = {
54
55
  granularity?: 'hour' | 'day' | 'week' | 'month';
55
56
  timeZone?: string;
56
57
  };
58
+ export type AggregateParams = {
59
+ /** A filterable field: its values make the groups, or for a date or timestamp field its buckets. */
60
+ groupBy: string;
61
+ filter?: FilterInput;
62
+ /** A numeric field to add up per group. */
63
+ sum?: string;
64
+ /** A numeric field to average per group, instead of `sum`. */
65
+ average?: string;
66
+ /** Value groups only: the most to return, default 100. */
67
+ limit?: number;
68
+ /** Value groups only: for a relation, the field of the related record that names each group. */
69
+ label?: string;
70
+ /** Date groups only. */
71
+ granularity?: 'hour' | 'day' | 'week' | 'month' | 'year';
72
+ range?: '7d' | '30d' | '90d' | '1y' | 'all';
73
+ from?: string;
74
+ to?: string;
75
+ timeZone?: string;
76
+ };
77
+ /** One group: its value (a date group's bucket in local ISO time), how many records it holds and its sum or average. */
78
+ export type AggregateGroup = {
79
+ value: string | number | boolean | null;
80
+ label?: string;
81
+ count: number;
82
+ sum?: number | null;
83
+ average?: number | null;
84
+ };
85
+ export type Aggregate = {
86
+ groupBy: string;
87
+ granularity?: string;
88
+ timeZone?: string;
89
+ groups: AggregateGroup[];
90
+ };
57
91
  export type HistogramBucket = {
58
92
  from: number;
59
93
  to: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/client",
3
- "version": "0.19.16",
3
+ "version": "0.20.0",
4
4
  "description": "Typed fetch client for the Protobase REST API.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@better-auth/passkey": "^1.7.7",
33
- "@protobase/layout": "0.19.16",
34
- "@protobase/schema": "0.19.16",
33
+ "@protobase/layout": "0.20.0",
34
+ "@protobase/schema": "0.20.0",
35
35
  "@simplewebauthn/browser": "^13.3.0",
36
36
  "better-auth": "^1.7.7"
37
37
  }