Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/39084-comment-threads-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@objectstack/spec': minor
'@objectstack/objectql': patch
'@objectstack/plugin-audit': patch
'@objectstack/client': patch
---

feat(plugin-audit,spec,client): one read returns the comment threads on the records a list filter selects, as the caller

Clause-②: yes (widening)
Metadata-protocol: added

Widened: a new route, `POST /api/v1/comments/threads/query`, mounted by plugin-audit's comment registrar beside the resolution and own-comment delete doors. The body (`CommentThreadsQueryRequestSchema`, strict) names an object and carries a list's filter in the `GET /data/{object}` syntax, with `showResolved`, `onlyMine`, `limit` (1 to `COMMENT_THREADS_MAX_LIMIT`, default `COMMENT_THREADS_DEFAULT_LIMIT`) and an opaque keyset `cursor`; the answer (`CommentThreadsQueryResponseSchema`) is one page of the object's top-level comments on the records the filter selects and the caller may read, newest first, each with its record's id and display name, its reply count at any depth and its latest three distinct repliers, and the next page's cursor. Every step runs as the caller: the engine plans the caller's read of the object with the filter (`ObjectQL#planReadScope`) and places it in the comment read as one subquery, so a view past the 1,000-id cap is answered in full; its refusals are the answer (`PERMISSION_DENIED` for a caller with no read on the object or a filter on a field the caller cannot read, `INVALID_FILTER` on MongoDB and OData). A query parameter, an unknown body key, a `limit` out of range or a cursor the read did not issue is `400 VALIDATION_ERROR` before anything is read, and a filter the list read cannot lower is `400 INVALID_FILTER`, as `GET /data/{object}` answers it, never dropped; an object with `enable.feeds: false` is `403 FEEDS_DISABLED`. The read is served on a kernel with an HTTP server; the hosted dispatcher's `/comments` domain does not claim it. `client.comments.queryThreads` is its SDK method. `@objectstack/objectql` exports the `PlanReadScopeOptions` and `ReadScopeComparand` types. No new error code. `Metadata-protocol: added`: the request and response schemas enter the `api` authorable-surface shard, which the level axis reads as added keys, so `@objectstack/spec` is a `minor`; nothing an author writes in an object, view or app definition changes.
78 changes: 78 additions & 0 deletions content/docs/api/data-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,84 @@ the approvals-family read and is unchanged.

---

## Comment threads

The discussions on the records a list shows, in one read: what a list page's
comment panel asks. Served by `@objectstack/plugin-audit` on a kernel with an
HTTP server; the SDK method is `client.comments.queryThreads`.

### `POST /comments/threads/query`

The body (`CommentThreadsQueryRequestSchema`) names the object and carries the
list's own filter, in the syntax `GET /data/:object` accepts: the saved view's
filter AND the reader's temporary filters. A search box is not a filter and is
not sent.

| Key | Meaning |
| :--- | :--- |
| `object` | The object whose records the list shows. Required; not `sys_comment`. |
| `filter` | The list's filter. Absent: every record of the object the caller may read. |
| `showResolved` | `true` answers resolved threads too. Absent: unresolved threads only. |
| `onlyMine` | `true` answers only the threads the caller started, replied in or is mentioned in. |
| `limit` | Threads per page, 1 to 50. Absent: 25. |
| `cursor` | The previous page's `nextCursor`, as it was answered. Absent: the first page. |

The answer is one page of the object's top-level comments on the records the
filter selects and the caller may read, newest first, and the cursor of the
next page (`null` on the last):

```json
{ "success": true, "data": {
"threads": [{
"comment": { "id": "cmt_9", "body": "Can we ship Friday?", "author_id": "usr_1", "is_resolved": false, "created_at": "2026-12-02T09:30:00.000Z" },
"record": { "id": "acc_1", "name": "Acme" },
"replyCount": 4,
"repliers": [{ "id": "usr_2", "name": "Ben", "avatarUrl": null }]
}],
"nextCursor": "WyIyMDI2LTEyLTAy..."
} }
```

`replyCount` counts the replies under the thread at any depth; `repliers` are
the latest distinct ones, newest first, at most three. `record.name` is the
record's title field read as the caller (`Record #` and the id when it is
empty or not served).

Every step runs as the caller. The records are the caller's own read of the
object with the filter, planned by the engine and placed in the comment read
as one subquery, so a view of any size is answered in full; where the engine
cannot prove that read it reads the ids as the caller and refuses past its cap
(`400 INVALID_FILTER`), never a part of the view. The comment read is an
ordinary read of `sys_comment`, so the comment read gate decides as on
`GET /data/sys_comment`. The cursor is a keyset over creation time and id: a
comment posted while you page does not repeat or skip a thread.

Refusals:

- any query parameter, a body key outside the table, a `limit` out of range, a
`cursor` the read did not issue, or `object: "sys_comment"`: `400 VALIDATION_ERROR`,
before anything is read;
- a filter the list read cannot lower (a filter array that is not a comparison,
a prefix `["and"|"or", ...]` node or a list of those, an infix join, or a
value that is neither a filter object nor a filter array): `400 INVALID_FILTER`,
before anything is read, the answer `GET /data/{object}` gives the same value;
`null` and `[]` are no filter;
- no signed-in caller: `401 UNAUTHENTICATED`;
- an unknown object: `404 OBJECT_NOT_FOUND`; an object the data door does not
serve: the data door's own refusal; an object with `enable.feeds: false`:
`403 FEEDS_DISABLED`;
- a caller with no read on the object, or a filter naming a field the caller
cannot read: `403 PERMISSION_DENIED`, the object read's own refusal, never an
empty answer;
- an object on a driver that cannot run the subquery (MongoDB, OData):
`400 INVALID_FILTER`.

A kernel with no HTTP server (a hosted tenant kernel) serves the other comment
doors through the dispatcher's `/comments` domain, which does not claim this
read, so it is not served there.

---

## Analytics

Semantic BI queries using a cube-style API. Provided by `@objectstack/service-analytics` —
Expand Down
9 changes: 5 additions & 4 deletions content/docs/references/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Protocol reference — every schema by module
navTitle: Protocol Reference
description: Every schema published by @objectstack/spec — 1756 schemas across 14 protocol modules
description: Every schema published by @objectstack/spec — 1761 schemas across 14 protocol modules
---

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
Expand All @@ -23,7 +23,7 @@ counts are sums of the rows they head. Regenerate with
| Module | Pages | Schemas | Description |
| :--- | ---: | ---: | :--- |
| [AI Protocol](/docs/references/ai) | 18 | 108 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. |
| [API Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/api) | 38 | 534 | REST contracts, endpoints, routing, realtime, batch, discovery. |
| [API Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/api) | 39 | 539 | REST contracts, endpoints, routing, realtime, batch, discovery. |
| [Automation Protocol](/docs/references/automation) | 16 | 82 | Flows and their nodes, approvals, ETL pipelines, webhooks, state machines, execution records. |
| [Data Protocol](/docs/references/data) | 35 | 198 | Objects, fields, queries, filters, datasources and drivers — the ObjectQL layer. |
| [Identity Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/identity) | 5 | 27 | Users and accounts, organizations, positions, SCIM provisioning. |
Expand All @@ -36,7 +36,7 @@ counts are sums of the rows they head. Regenerate with
| [Studio Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/studio) | 3 | 35 | Studio designer metadata — the authoring surfaces for the protocols above. |
| [System Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/system) | 40 | 298 | The runtime environment — logging, jobs, cache, metrics, notifications, i18n and compliance. |
| [UI Protocol](/docs/references/ui) | 17 | 188 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. |
| **Total** | **225** | **1756** | 14 protocol modules |
| **Total** | **226** | **1761** | 14 protocol modules |

---

Expand Down Expand Up @@ -71,7 +71,7 @@ Agents, tools, skills, RAG and knowledge sources, model registry, conversations.

## API Protocol

**Source:** `packages/spec/src/api/` · **Import:** `@objectstack/spec/api` · **38 pages, 534 schemas**
**Source:** `packages/spec/src/api/` · **Import:** `@objectstack/spec/api` · **39 pages, 539 schemas**

REST contracts, endpoints, routing, realtime, batch, discovery.

Expand All @@ -84,6 +84,7 @@ REST contracts, endpoints, routing, realtime, batch, discovery.
| [`auth-endpoints.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/auth-endpoints.md) | `AuthEndpoint`, `AuthFeaturesConfig`, `AuthProviderInfo`, `DeviceRequestResponse`, `DeviceTokenResponse`, `EmailPasswordConfigPublic`, `GetAuthConfigResponse`, `OneTimeTokenHandoffQuery`, `OneTimeTokenVerifyRequest`, `OneTimeTokenVerifyResponse`, `OrganizationEditionChoice` |
| [`automation-api.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/automation-api.md) | `AutomationApiErrorCode`, `AutomationFlowPathParams`, `AutomationRunPathParams`, `CloneFlowRequest`, `CloneFlowResponse`, `CreateFlowRequest`, `CreateFlowResponse`, `DeleteFlowRequest`, `DeleteFlowResponse`, `FlowFailureDetails`, `FlowInnerRefusal`, `GetFlowRequest`, `GetFlowResponse`, `GetRunRequest`, `GetRunResponse`, `ListRunsRequest`, `ListRunsResponse`, `RecordUpdateStart`, `RecordUpdateStartsRequest`, `RecordUpdateStartsResponse`, `ResumeFailureDetails`, `ToggleFlowRequest`, `ToggleFlowResponse`, `TriggerFlowRequest`, `TriggerFlowResponse`, `UpdateFlowRequest`, `UpdateFlowResponse` |
| [`batch.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/batch.md) | `BatchConfig`, `BatchOperationResult`, `BatchOperationType`, `BatchOptions`, `BatchRecord`, `BatchUpdateRequest`, `BatchUpdateResponse`, `CrossObjectBatchDroppedFields`, `CrossObjectBatchOperation`, `CrossObjectBatchRequest`, `CrossObjectBatchResponse`, `DeleteManyRequest`, `UpdateManyRecord`, `UpdateManyRequest` |
| [`comment-threads.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/comment-threads.md) | `CommentThread`, `CommentThreadRecord`, `CommentThreadReplier`, `CommentThreadsQueryRequest`, `CommentThreadsQueryResponse` |
| [`contract.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/contract.md) | `ApiError`, `BaseResponse`, `BatchLoadingStrategy`, `BulkRequest`, `BulkResponse`, `CreateRequest`, `DataLoaderConfig`, `DeleteResponse`, `ExportRequest`, `IdRequest`, `ListRecordResponse`, `ModificationResult`, `QueryOptimizationConfig`, `RecordData`, `SingleRecordResponse`, `UpdateRequest` |
| [`discovery.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/discovery.md) | `ApiRoutes`, `AuthFamilies`, `CapabilityDescriptor`, `Discovery`, `DiscoveryEnvironment`, `EnvironmentType`, `RouteHealthEntry`, `RouteHealthReport`, `ServiceInfo`, `ServiceSelfInfo`, `ServiceStatus`, `WellKnownCapabilities` |
| [`dispatcher.zod.ts`](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/references/api/dispatcher.md) | `DispatcherConfig`, `DispatcherErrorCode`, `DispatcherErrorResponse`, `DispatcherRoute` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate.

| Dir | Sites |
|---|---|
| `api/` | 550 |
| `api/` | 555 |
32 changes: 32 additions & 0 deletions packages/client/src/client-url-conformance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { REST_ROUTE_LEDGER } from '../../rest/src/rest-route-ledger';
import { STORAGE_ROUTE_LEDGER } from '../../services/service-storage/src/storage-route-ledger';
import { I18N_ROUTE_LEDGER } from '../../services/service-i18n/src/i18n-route-ledger';
import { AUTH_ROUTE_LEDGER } from '../../plugins/plugin-auth/src/auth-route-ledger';
import { COMMENT_ROUTE_LEDGER } from '../../plugins/plugin-audit/src/comment-route-ledger';

const BASE = 'http://localhost:9';

Expand Down Expand Up @@ -119,6 +120,10 @@ const PATTERNS: Pattern[] = [
...STORAGE_ROUTE_LEDGER.map((r) => r.route).flatMap((r) => compile(r, '', 'storage')),
...I18N_ROUTE_LEDGER.map((r) => r.route).flatMap((r) => compile(r, '', 'i18n')),
...AUTH_ROUTE_LEDGER.map((r) => r.route).flatMap((r) => compile(r, '', 'auth')),
// The comment registrar's own mount (plugin-audit, self-hosted only): the
// threads read is SDK surface (`comments.queryThreads`), so the URL that
// method builds is matched against the ledger of the registrar that mounts it.
...COMMENT_ROUTE_LEDGER.map((r) => r.route).flatMap((r) => compile(r, '', 'comments')),
]
// Exact rows before wildcard families, so a URL that a real route covers is
// never CREDITED to a `**` prefix claim that happens to sit earlier in the
Expand Down Expand Up @@ -481,3 +486,30 @@ describe('client URL conformance ↔ the union of all four route ledgers (#3642)
).toBe(0);
});
});

describe('the comment registrar ledger ↔ @objectstack/client', () => {
it('every comment ledger row naming a client method resolves to a real function', () => {
const client = new ObjectStackClient({ baseUrl: BASE });
const broken = COMMENT_ROUTE_LEDGER.filter((e) => e.client != null)
.filter((e) => typeof e.client!.split('.').reduce<unknown>((o, k) => (o == null ? o : (o as Record<string, unknown>)[k]), client) !== 'function')
.map((e) => `${e.route} → client.${e.client}`);
expect(broken).toEqual([]);
expect(COMMENT_ROUTE_LEDGER.filter((e) => e.disposition === 'sdk').map((e) => e.client)).toEqual(['comments.queryThreads']);
});

it('comments.queryThreads POSTs the request as the JSON body to the threads read, and resolves the answer\'s data', async () => {
const data = { threads: [], nextCursor: null };
const calls: Array<{ verb: string; url: string; body: unknown }> = [];
const client = new ObjectStackClient({
baseUrl: BASE,
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
calls.push({ verb: (init?.method ?? 'GET').toUpperCase(), url: String(input), body: init?.body });
return makeResponse({ success: true, data });
},
});
const request = { object: 'account', filter: [['status', '=', 'open']], showResolved: true, limit: 10, cursor: 'c' };
await expect(client.comments.queryThreads(request)).resolves.toEqual(data);
expect(calls.map((c) => `${c.verb} ${c.url}`)).toEqual([`POST ${BASE}/api/v1/comments/threads/query`]);
expect(JSON.parse(String(calls[0].body))).toEqual(request);
});
});
31 changes: 31 additions & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
GetRecordLocksResponse,
RecordPageRequest,
RecordPageResponse,
CommentThreadsQueryRequest,
CommentThreadsQueryResponse,
// [#32200] The batch dataset-query answer `analytics.queryDatasetBatch`
// resolves to the `data` of.
DatasetQueryBatchResponse,
Expand Down Expand Up @@ -7468,6 +7470,33 @@ export class ObjectStackClient {
* record, served under the data surface. Every route 501s
* [NOT_IMPLEMENTED] on deployments without the sharing service.
*/
/**
* Comment threads across records. Served by plugin-audit's comment
* registrar on a kernel with an HTTP server.
*/
comments = {
/**
* The comment threads on the records a list filter selects —
* `POST /api/v1/comments/threads/query`, declared by
* `CommentThreadsQueryRequestSchema` / `CommentThreadsQueryResponseSchema`
* (`@objectstack/spec/api`). One page of top-level comments on the records
* of `request.object` that `request.filter` (the `GET /data/{object}`
* filter syntax) selects and the caller may read, newest first, each with
* its record's id and name, its reply count and its latest repliers.
* Pass the answer's `nextCursor` back as `request.cursor` for the next
* page. Unresolved threads only unless `showResolved`; only the caller's
* own threads (started, replied in, mentioned in) when `onlyMine`. A
* caller with no read on the object rejects with that read's refusal.
*/
queryThreads: async (request: CommentThreadsQueryRequest): Promise<CommentThreadsQueryResponse> => {
const res = await this.fetch(`${this.baseUrl}/api/v1/comments/threads/query`, {
method: 'POST',
body: JSON.stringify(request),
});
return this.unwrapResponse<CommentThreadsQueryResponse>(res);
},
};

shares = {
/** List the sharing grants on a record. */
list: async (object: string, recordId: string): Promise<RecordShare[]> => {
Expand Down Expand Up @@ -9694,6 +9723,8 @@ export type {
RecordLockEntry,
RecordPageRequest,
RecordPageResponse,
CommentThreadsQueryRequest,
CommentThreadsQueryResponse,
RealtimeConnectRequest,
RealtimeConnectResponse,
RealtimeSubscribeRequest,
Expand Down
4 changes: 4 additions & 0 deletions packages/objectql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ export type { DatasourceDef } from './engine.js';
// refuses the filter rather than truncate it, and its words name this number.
// Exported so a caller running the two-step route itself can page by it.
export { RELATION_FILTER_ID_CAP } from './relation-filter-lowering.js';
// What `ObjectQL#planReadScope` takes besides the two object names, and the `$in`
// comparand it answers, so an in-process caller can name both (the comment threads
// read in plugin-audit plans and places one per request).
export type { PlanReadScopeOptions, ReadScopeComparand } from './engine-query-lowering.js';
// [ADR-0155 D4, plan step 5] The seam's recognition of D4's two classes and
// its reader of a driver's `fixedReadLeaves` declaration, so an evaluator that
// declines before it compiles (the analytics native compiler) asks the seam
Expand Down
Loading
Loading