techne-sdk 0.11.0 → 0.12.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.
@@ -11,6 +11,16 @@ export class InvalidRequestError extends XRPCError {
11
11
  super(src.status, src.error, src.message, src.headers, { cause: src });
12
12
  }
13
13
  }
14
+ export class ViewRequiredError extends XRPCError {
15
+ constructor(src) {
16
+ super(src.status, src.error, src.message, src.headers, { cause: src });
17
+ }
18
+ }
19
+ export class NotCuratedError extends XRPCError {
20
+ constructor(src) {
21
+ super(src.status, src.error, src.message, src.headers, { cause: src });
22
+ }
23
+ }
14
24
  export class NotFoundError extends XRPCError {
15
25
  constructor(src) {
16
26
  super(src.status, src.error, src.message, src.headers, { cause: src });
@@ -20,6 +30,10 @@ export function toKnownErr(e) {
20
30
  if (e instanceof XRPCError) {
21
31
  if (e.error === 'InvalidRequest')
22
32
  return new InvalidRequestError(e);
33
+ if (e.error === 'ViewRequired')
34
+ return new ViewRequiredError(e);
35
+ if (e.error === 'NotCurated')
36
+ return new NotCuratedError(e);
23
37
  if (e.error === 'NotFound')
24
38
  return new NotFoundError(e);
25
39
  }
@@ -40,6 +40,12 @@ export interface Response {
40
40
  export declare class InvalidRequestError extends XRPCError {
41
41
  constructor(src: XRPCError);
42
42
  }
43
+ export declare class ViewRequiredError extends XRPCError {
44
+ constructor(src: XRPCError);
45
+ }
46
+ export declare class NotCuratedError extends XRPCError {
47
+ constructor(src: XRPCError);
48
+ }
43
49
  export declare class NotFoundError extends XRPCError {
44
50
  constructor(src: XRPCError);
45
51
  }
@@ -62,7 +68,7 @@ export interface Record {
62
68
  space?: string;
63
69
  /** Whether the record is public (on the firehose) or permissioned. */
64
70
  source: 'public' | 'permissioned' | (string & {});
65
- /** A public record that is a live curated record: a curator the commons root trusts merged it from its sources, and it is not superseded. Its `pub.techne.draft.provenance` (same author, subject this record) names who it is from. Absent otherwise. */
71
+ /** A public record that is a live curated record: a curator the commons root trusts merged it from its sources, and it is not superseded. Its `pub.techne.draft.provenance` (same author, subject this record) names who it is from. Always answered: false for every other record (a source copy, a superseded one, a permissioned one). */
66
72
  curated?: boolean;
67
73
  /** The caller's own permissioned record that the reach limit holds back from the people it would reach: a withheld act (a share or a circle add), answered to its author alone (to anyone else it is not found) until the limit admits it. Absent otherwise. A query with `held: true` answers only these. */
68
74
  held?: boolean;
@@ -11,6 +11,16 @@ export class InvalidRequestError extends XRPCError {
11
11
  super(src.status, src.error, src.message, src.headers, { cause: src });
12
12
  }
13
13
  }
14
+ export class ViewRequiredError extends XRPCError {
15
+ constructor(src) {
16
+ super(src.status, src.error, src.message, src.headers, { cause: src });
17
+ }
18
+ }
19
+ export class NotCuratedError extends XRPCError {
20
+ constructor(src) {
21
+ super(src.status, src.error, src.message, src.headers, { cause: src });
22
+ }
23
+ }
14
24
  export class NotFoundError extends XRPCError {
15
25
  constructor(src) {
16
26
  super(src.status, src.error, src.message, src.headers, { cause: src });
@@ -20,6 +30,10 @@ export function toKnownErr(e) {
20
30
  if (e instanceof XRPCError) {
21
31
  if (e.error === 'InvalidRequest')
22
32
  return new InvalidRequestError(e);
33
+ if (e.error === 'ViewRequired')
34
+ return new ViewRequiredError(e);
35
+ if (e.error === 'NotCurated')
36
+ return new NotCuratedError(e);
23
37
  if (e.error === 'NotFound')
24
38
  return new NotFoundError(e);
25
39
  }
package/dist/item.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * the one shape every read answers (`Item<T>`), typed URIs, and the check that
4
4
  * gives each item its verdict.
5
5
  *
6
- * An item is `{ uri, cid, record, verdict, problems, curated, byline }`:
6
+ * An item is `{ uri, cid, author, record, verdict, problems, curated, byline }`:
7
7
  *
8
8
  * - `uri` is typed (`Uri<Place>`), so a hook handed `item.uri` comes back typed. A bare string is no
9
9
  * `Uri<Place>` (only an item, or `Place.uri(s)`, makes one); a read taking a bare string answers
@@ -59,6 +59,8 @@ export interface Byline extends BylineRef {
59
59
  interface ItemBase<T> {
60
60
  uri: Uri<T>;
61
61
  cid: string;
62
+ /** The DID whose repo holds the record: its author (a curated record's is the curator's). */
63
+ author: string;
62
64
  /** Why it is not valid: the check's reasons when invalid, what it waits for when pending. */
63
65
  problems: string[];
64
66
  /** A live curated record (the commons composed it from versions). */
package/dist/item.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * the one shape every read answers (`Item<T>`), typed URIs, and the check that
4
4
  * gives each item its verdict.
5
5
  *
6
- * An item is `{ uri, cid, record, verdict, problems, curated, byline }`:
6
+ * An item is `{ uri, cid, author, record, verdict, problems, curated, byline }`:
7
7
  *
8
8
  * - `uri` is typed (`Uri<Place>`), so a hook handed `item.uri` comes back typed. A bare string is no
9
9
  * `Uri<Place>` (only an item, or `Place.uri(s)`, makes one); a read taking a bare string answers
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import { type Binding, type EnvelopeField, type Composed, type Composition, type Reader, type StepRecord, type StepRef } from './compose.js';
25
25
  import { type Query, type QueryReader, type QueryRecord } from './index.js';
26
- /** The provenance records written about `$uris` (as written: a read scoped to subjects). */
26
+ /** The provenance records written about `$uris` (as written). */
27
27
  export declare const PROVENANCE_OF_QUERY: Query;
28
28
  /** The mirror sidecars written about `$uris` (`source`, and the frozen old-Almanac `sourceRef`). */
29
29
  export declare const MIRROR_SIDECARS_QUERY: Query;
@@ -24,12 +24,14 @@
24
24
  import { NSID } from '../generated/nsid.js';
25
25
  import { compose, ENVELOPE_ONLY, MAX_STEP_LIMIT } from './compose.js';
26
26
  import { getRecords, listAllRecordsFor } from './index.js';
27
- /** The provenance records written about `$uris` (as written: a read scoped to subjects). */
27
+ /** The provenance records written about `$uris` (as written). */
28
28
  export const PROVENANCE_OF_QUERY = {
29
+ view: 'asWritten',
29
30
  where: { all: [{ type: { is: NSID.PROVENANCE } }, { subject: { in: ['$uris'] } }] },
30
31
  };
31
32
  /** The mirror sidecars written about `$uris` (`source`, and the frozen old-Almanac `sourceRef`). */
32
33
  export const MIRROR_SIDECARS_QUERY = {
34
+ view: 'asWritten',
33
35
  where: { all: [{ type: { in: [NSID.SOURCE, NSID.SOURCE_REF] } }, { subject: { in: ['$uris'] } }] },
34
36
  };
35
37
  const authority = (uri) => uri.split('/')[2] ?? '';
@@ -130,7 +132,7 @@ export const HOST_SOURCES_QUERY = {
130
132
  { not: [{ has: { via: 'subject', by: 'author', where: { type: { in: [NSID.SOURCE, NSID.SOURCE_REF] } } } }] },
131
133
  ],
132
134
  },
133
- curated: false,
135
+ view: 'asWritten',
134
136
  };
135
137
  /** The record fields {@link hostsFrom} reads of the host steps' records: a page that hands the provenances to no
136
138
  * other rule asks {@link hostSteps} for exactly these. */
@@ -285,8 +287,8 @@ export async function listedOnOf(read, record) {
285
287
  /** The provenances naming any of `$uris` among their sources (the `references` role): a source copy finds
286
288
  * the curated record made from it. As written, so a provenance is found whatever lists. */
287
289
  export const CURATED_FROM_QUERY = {
290
+ view: 'asWritten',
288
291
  where: { all: [{ type: { is: NSID.PROVENANCE } }, { references: { in: ['$uris'] } }] },
289
- curated: false,
290
292
  };
291
293
  /**
292
294
  * The live curated record that stands for `uri` now, when `uri` itself is not one a reader is shown (the
@@ -39,19 +39,45 @@ export type QueryNode = {
39
39
  } | {
40
40
  readonly [role: string]: Condition | readonly QueryNode[];
41
41
  };
42
- /** A `pub.techne.draft.query`, as data (the platform validates it). */
43
- export interface Query {
42
+ /**
43
+ * Which public records a branch reads; every list names one, there is no default (the `view` property of `pub.techne.draft.query` and its `#branch`):
44
+ * - `curated`: the commons' listed records, one curated record per thing (merged from its sources by a curator
45
+ * the commons root trusts), moderated, not hidden; an event only inside the supported areas. A type no curator
46
+ * covers is refused with `NotCurated`, naming the type, never answered as an empty list.
47
+ * - `asWritten`: every public record as its author wrote it, each source copy and the curated record, not hidden,
48
+ * not superseded. Totals in this view count both copies of a curated thing.
49
+ * A permissioned record reads the same in both (it is never curated).
50
+ */
51
+ export type View = 'curated' | 'asWritten';
52
+ /** One branch of a query in the `any` form: its own view and `where`. */
53
+ export interface QueryBranch {
54
+ readonly view: View;
44
55
  readonly where: QueryNode;
45
- /** A role, a measure's `as` name, or `shuffle` (one deterministic order per {@link Query.seed}). */
56
+ }
57
+ /** What every query document carries besides its branches. */
58
+ export interface QueryOptions {
59
+ /** A role, a measure's `as` name, or `shuffle` (one deterministic order per `seed`). */
46
60
  readonly order?: string;
47
61
  /** The seed of `order: "shuffle"`: a literal or a `$param`; required with it, refused without it. */
48
62
  readonly seed?: string;
49
63
  readonly limit?: number;
50
64
  readonly signals?: readonly Readonly<Record<string, unknown>>[];
51
- readonly curated?: boolean;
52
65
  /** Only the caller's own permissioned records the reach limit is holding back (each marked `held`). */
53
66
  readonly held?: boolean;
54
67
  }
68
+ /** A `pub.techne.draft.query`, as data (the platform validates it). Every branch names its {@link View}: `view`
69
+ * beside `where` names it for every branch of the `where` (each child of a top-level `any` too), and the `any`
70
+ * form, `{ any: [{ view, where }, …] }`, one per branch (an app's feed: curated events and its own records as
71
+ * written, in one list). A query naming no view is refused with `ViewRequired`. */
72
+ export type Query = QueryOptions & ({
73
+ readonly view: View;
74
+ readonly where: QueryNode;
75
+ readonly any?: never;
76
+ } | {
77
+ readonly any: readonly [QueryBranch, ...QueryBranch[]];
78
+ readonly view?: never;
79
+ readonly where?: never;
80
+ });
55
81
  /** One record a query answered (`pub.techne.draft.query.listRecords#record`). */
56
82
  export interface QueryRecord<V = Record<string, unknown>> {
57
83
  uri: string;
@@ -65,7 +91,8 @@ export interface QueryRecord<V = Record<string, unknown>> {
65
91
  space?: string;
66
92
  source: 'public' | 'permissioned';
67
93
  /** A public record that is a live curated record (a curator the commons root trusts merged it); its
68
- * provenance names who it is from ({@link hostsOf}). Absent otherwise. */
94
+ * provenance names who it is from ({@link hostsOf}). Always answered, false otherwise (a platform from before
95
+ * views left it out when false). */
69
96
  curated?: boolean;
70
97
  /** The caller's own permissioned record the reach limit holds back from the people it would reach:
71
98
  * answered to its author alone (anyone else does not see it) until the limit admits it. */
@@ -3,8 +3,8 @@
3
3
  * {@link Item}s, and their options forms (`{ queryKey, queryFn }`, for TanStack Query). Internal: an app
4
4
  * calls them on what `connect` returns, which binds them to its session and the claims it holds.
5
5
  *
6
- * - `query(q, opts)`: one page of a query document (`pub.techne.draft.query.listRecords`). A list across
7
- * authors answers curated records (the query's `curated`, on the platform). `count` is a read option
6
+ * - `query(q, opts)`: one page of a query document (`pub.techne.draft.query.listRecords`). Every list reads
7
+ * the view the query names (`view`: `curated` or `asWritten`, on the platform). `count` is a read option
8
8
  * (the document has no count field); the page's `count` is what the platform counted, before `include`.
9
9
  * - `get(uri, opts)`: one record. By default the curated view: `commons.getVersions` resolves any copy to
10
10
  * its curated record, and a type nobody curates answers the record itself. `prefer: 'mine'` answers the
@@ -28,9 +28,10 @@ export const readerOf = (techne) => async (nsid, params) => (await techne.platfo
28
28
  export const posterOf = (techne) => async (nsid, body) => (await techne.platform.call(nsid, {}, body, { encoding: 'application/json' })).data;
29
29
  /** `r` as an item, with `byline` from its curated record's composition. */
30
30
  function itemOf(techne, r, curated, composition) {
31
- const { verdict, problems } = check({ uri: r.uri, collection: r.collection ?? collectionOf(r.uri), author: r.author ?? authorOf(r.uri), value: r.value, space: r.space, time: r.time, held: r.held }, techne.claims);
31
+ const author = r.author ?? authorOf(r.uri);
32
+ const { verdict, problems } = check({ uri: r.uri, collection: r.collection ?? collectionOf(r.uri), author, value: r.value, space: r.space, time: r.time, held: r.held }, techne.claims);
32
33
  // The check is what makes the record a `T`: valid and pending records passed its lexicon check.
33
- return { uri: r.uri, cid: r.cid, record: r.value, verdict, problems, curated, byline: curated ? bylineOf(composition) : null };
34
+ return { uri: r.uri, cid: r.cid, author, record: r.value, verdict, problems, curated, byline: curated ? bylineOf(composition) : null };
34
35
  }
35
36
  const fromQueryRecord = (techne, r, composition) => itemOf(techne, r, r.curated === true, composition);
36
37
  export async function query(techne, q, opts = {}) {