@protobase/client 0.21.7 → 0.21.8

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 { Aggregate, AggregateParams, BatchOp, BatchResult, Facet, FormChallenge, FormProof, Histogram, HistoryPage, ListPage, MapResult, MetaResult, PublicForm, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
4
+ import { Aggregate, AggregateParams, BatchOp, BatchResult, CommentPage, Facet, FormChallenge, FormProof, Histogram, HistoryPage, ListPage, MapResult, MentionableUser, MetaResult, PublicForm, RecordComment, 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. */
@@ -52,11 +52,21 @@ export declare const createClient: (options?: ClientOptions) => {
52
52
  etag?: string;
53
53
  }) => Promise<void>;
54
54
  undelete: <R extends ResourceRef>(resource: R, key: KeyValue | readonly KeyValue[]) => Promise<Stored<RecordOf<R>>>;
55
+ generate: <R extends ResourceRef>(resource: R, key: KeyValue | readonly KeyValue[], action: string) => Promise<Stored<RecordOf<R>>>;
55
56
  reveal: (resource: ResourceRef, key: KeyValue | readonly KeyValue[], field: string) => Promise<unknown>;
56
57
  history: (resource: ResourceRef, key: KeyValue | readonly KeyValue[], { pageSize, pageToken }?: {
57
58
  pageSize?: number;
58
59
  pageToken?: string;
59
60
  }) => Promise<HistoryPage>;
61
+ comments: (resource: ResourceRef, key: KeyValue | readonly KeyValue[], { pageSize, pageToken }?: {
62
+ pageSize?: number;
63
+ pageToken?: string;
64
+ }) => Promise<CommentPage>;
65
+ comment: (resource: ResourceRef, key: KeyValue | readonly KeyValue[], { body, mentions }: {
66
+ body: string;
67
+ mentions?: string[];
68
+ }) => Promise<RecordComment>;
69
+ mentionable: (resource: ResourceRef, key: KeyValue | readonly KeyValue[], query: string) => Promise<MentionableUser[]>;
60
70
  batchWrite: (ops: BatchOp[]) => Promise<BatchResult>;
61
71
  facets: (resource: ResourceRef, field: string, o?: {
62
72
  filter?: FilterInput;
package/dist/client.js CHANGED
@@ -16,6 +16,10 @@ const toPage = (body, response, origin) => ({
16
16
  ...body.photos !== void 0 && { photos: photosWithOrigin(body.photos, origin) },
17
17
  ...response.headers.get("x-protobase-warning") && { warning: response.headers.get("x-protobase-warning") }
18
18
  });
19
+ const commentOf = ({ created_at, ...comment }) => ({
20
+ ...comment,
21
+ createdAt: created_at
22
+ });
19
23
  const etagOf = (response) => response.headers.get("etag") ?? "";
20
24
  /** A single-record response: the record without its `permissions` member, which travels beside it. */
21
25
  const storedOf = async (response, origin) => {
@@ -123,6 +127,15 @@ const createClient = (options = {}) => {
123
127
  body: { field }
124
128
  })).json()).value;
125
129
  };
130
+ /**
131
+ * Runs the record's AI action `action` (`a.ai`): the model writes the action's field from its prompt, as the caller.
132
+ * Resolves to the record as written; a record changed while the model answered rejects with `PreconditionFailedError`.
133
+ */
134
+ const generate = async (resource, key, action) => storedOf(await send({
135
+ method: "POST",
136
+ path: `${keyPath(resource, key)}:generate`,
137
+ body: { action }
138
+ }), origin);
126
139
  /** A page of a record's changes, newest first, for a resource with `.history()`; `pageToken` is the previous page's `nextPageToken`. */
127
140
  const history = async (resource, key, { pageSize, pageToken } = {}) => {
128
141
  const query = queryString({
@@ -142,6 +155,39 @@ const createClient = (options = {}) => {
142
155
  nextPageToken: body.next_page_token
143
156
  };
144
157
  };
158
+ /** A page of a record's comments, newest first, for a resource with `.comments()`; `pageToken` is the previous page's `nextPageToken`. */
159
+ const comments = async (resource, key, { pageSize, pageToken } = {}) => {
160
+ const query = queryString({
161
+ page_size: pageSize,
162
+ page_token: pageToken || void 0
163
+ });
164
+ const body = await (await send({
165
+ method: "GET",
166
+ path: `${keyPath(resource, key)}:comments`,
167
+ query
168
+ })).json();
169
+ return {
170
+ items: body.items.map(commentOf),
171
+ nextPageToken: body.next_page_token
172
+ };
173
+ };
174
+ /** Adds the caller's comment to a record, mentioning the users `mentions` names, who are emailed a link to it. */
175
+ const comment = async (resource, key, { body, mentions = [] }) => commentOf(await (await send({
176
+ method: "POST",
177
+ path: `${keyPath(resource, key)}:comments`,
178
+ body: {
179
+ body,
180
+ mentions
181
+ }
182
+ })).json());
183
+ /** The users a comment on a record may mention whose name contains `query`, at most 8, by name. */
184
+ const mentionable = async (resource, key, query) => {
185
+ return (await (await send({
186
+ method: "GET",
187
+ path: `${keyPath(resource, key)}:mentionable`,
188
+ query: queryString({ q: query })
189
+ })).json()).items;
190
+ };
145
191
  /** Applies several writes atomically (`POST /api/v1:batchWrite`), for example a record and its lines on Save. */
146
192
  const batchWrite = async (ops) => {
147
193
  const keyText = (key) => typeof key === "object" && key !== null && "$ref" in key ? key : encodeKey(key);
@@ -359,8 +405,12 @@ const createClient = (options = {}) => {
359
405
  update,
360
406
  remove,
361
407
  undelete,
408
+ generate,
362
409
  reveal,
363
410
  history,
411
+ comments,
412
+ comment,
413
+ mentionable,
364
414
  batchWrite,
365
415
  facets,
366
416
  aggregate,
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 { Aggregate, AggregateGroup, AggregateParams, BatchOp, BatchRef, BatchResult, Facet, FormChallenge, FormProof, Histogram, HistogramBucket, HistoryChange, HistoryPage, ListPage, MapBounds, MapBucket, MapLayerModel, MapResult, Meta, MetaResult, PluginRef, PublicForm, RecordOf, RecordPermissions, RecordPhotos, RelatedLabels, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile, StoredFileVariant } from "./types.js";
4
+ import { Aggregate, AggregateGroup, AggregateParams, BatchOp, BatchRef, BatchResult, CommentPage, CommentPerson, Facet, FormChallenge, FormProof, Histogram, HistogramBucket, HistoryChange, HistoryPage, ListPage, MapBounds, MapBucket, MapLayerModel, MapResult, MentionableUser, Meta, MetaResult, PluginRef, PublicForm, RecordComment, 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, 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 FormChallenge, type FormProof, type Histogram, type HistogramBucket, type HistoryChange, type HistoryPage, 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 PublicForm, 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 CommentPage, type CommentPerson, type CurrentOrganization, type Facet, type FilterInput, type FormChallenge, type FormProof, type Histogram, type HistogramBucket, type HistoryChange, type HistoryPage, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type MentionableUser, 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 PublicForm, type RecordComment, 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 };
@@ -16,8 +16,12 @@ const routedClient = (own, sourceOf) => {
16
16
  update: (resource, key, patch, etag) => to(resource).update(resource, key, patch, etag),
17
17
  remove: (resource, key, options) => to(resource).remove(resource, key, options),
18
18
  undelete: (resource, key) => to(resource).undelete(resource, key),
19
+ generate: (resource, key, action) => to(resource).generate(resource, key, action),
19
20
  reveal: (resource, key, field) => to(resource).reveal(resource, key, field),
20
21
  history: (resource, key, options) => to(resource).history(resource, key, options),
22
+ comments: (resource, key, options) => to(resource).comments(resource, key, options),
23
+ comment: (resource, key, input) => to(resource).comment(resource, key, input),
24
+ mentionable: (resource, key, query) => to(resource).mentionable(resource, key, query),
21
25
  batchWrite: (ops) => {
22
26
  const apis = [...new Set(ops.map((op) => to(op.resource)))];
23
27
  if (apis.length > 1) return Promise.reject(/* @__PURE__ */ new Error(`A batch writes to one API, but these writes are for ${[...new Set(ops.map((op) => nameOf(op.resource)))].join(", ")}, which different APIs serve`));
package/dist/types.d.ts CHANGED
@@ -71,6 +71,33 @@ export type FormProof = {
71
71
  derivedKey: string;
72
72
  };
73
73
  };
74
+ /** Someone a comment names: its author or a person it mentions, with their name when the server knows it. */
75
+ export type CommentPerson = {
76
+ id: string;
77
+ name?: string;
78
+ };
79
+ /** One comment on a record, as `comments` reads it. */
80
+ export type RecordComment = {
81
+ id: string;
82
+ /** When it was written, ISO 8601. */
83
+ createdAt: string;
84
+ /** Plain text, as written. */
85
+ body: string;
86
+ author: CommentPerson;
87
+ /** The users it mentions, each once. */
88
+ mentions: CommentPerson[];
89
+ };
90
+ /** A page of a record's comments, newest first. */
91
+ export type CommentPage = {
92
+ items: RecordComment[];
93
+ /** `""` on the last page. */
94
+ nextPageToken: string;
95
+ };
96
+ /** Someone a comment on a record may mention: a user who may read the record. */
97
+ export type MentionableUser = {
98
+ id: string;
99
+ name: string;
100
+ };
74
101
  /** A page of a record's history, newest first. */
75
102
  export type HistoryPage = {
76
103
  items: HistoryChange[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/client",
3
- "version": "0.21.7",
3
+ "version": "0.21.8",
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.21.7",
34
- "@protobase/schema": "0.21.7",
33
+ "@protobase/layout": "0.21.8",
34
+ "@protobase/schema": "0.21.8",
35
35
  "@simplewebauthn/browser": "^13.3.0",
36
36
  "better-auth": "^1.7.7"
37
37
  }