techne-sdk 0.3.3 → 0.3.4
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/CHANGELOG.md +60 -0
- package/README.md +5 -4
- package/dist/auth/app-key.js +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/catalog/catalog.gen.js +4 -12
- package/dist/connect.d.ts +96 -12
- package/dist/connect.js +83 -12
- package/dist/item.d.ts +130 -0
- package/dist/item.js +74 -0
- package/dist/links/index.d.ts +15 -8
- package/dist/links/index.js +18 -0
- package/dist/put/contacts.d.ts +2 -2
- package/dist/put/index.d.ts +6 -9
- package/dist/put/index.js +8 -166
- package/dist/put/put.d.ts +14 -0
- package/dist/put/put.js +206 -0
- package/dist/query/compose.d.ts +246 -0
- package/dist/query/compose.js +572 -0
- package/dist/query/hosts.d.ts +98 -1
- package/dist/query/hosts.js +143 -2
- package/dist/query/index.d.ts +60 -29
- package/dist/query/index.js +55 -26
- package/dist/react/context.d.ts +18 -0
- package/dist/react/context.js +19 -0
- package/dist/react/index.d.ts +14 -0
- package/dist/react/index.js +14 -0
- package/dist/react/query.d.ts +75 -0
- package/dist/react/query.js +116 -0
- package/dist/read/index.d.ts +60 -0
- package/dist/read/index.js +107 -0
- package/dist/resend.d.ts +25 -0
- package/dist/resend.js +52 -0
- package/dist/versions/entities.gen.d.ts +8 -0
- package/dist/versions/entities.gen.js +9 -0
- package/dist/versions/index.d.ts +59 -17
- package/dist/versions/index.js +156 -22
- package/dist/versions/react.d.ts +1 -1
- package/dist/versions/react.js +1 -1
- package/dist/versions/text.d.ts +19 -0
- package/dist/versions/text.js +73 -0
- package/package.json +17 -5
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pub.techne.draft.query.composeRecords` from the SDK (CQ2): several generic reads in one request, where a
|
|
3
|
+
* later step reads what an earlier one answered.
|
|
4
|
+
*
|
|
5
|
+
* A composition is built step by step and sent once:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const c = compose()
|
|
9
|
+
* const events = c.list('events', FEED_QUERY, { params, limit: 500 })
|
|
10
|
+
* const prov = c.list('prov', PROVENANCE_OF_QUERY, { params: { uris: events.uri }, fields: ['subject', 'sources[].uri'] })
|
|
11
|
+
* const sources = c.get('sources', [prov.value('sources[].uri')], { fields: ENVELOPE_ONLY })
|
|
12
|
+
* const answer = await c.run(post)
|
|
13
|
+
* answer.list(events).records // a ListPage
|
|
14
|
+
* answer.records(sources) // a Map by URI
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A step's handle names its outputs as bindings (`events.uri` is the string `"$events.uri"`), which the platform
|
|
18
|
+
* fills with that output over the earlier step's answered records (deduplicated, first seen first; possibly
|
|
19
|
+
* empty). A step asked with `return: false` only feeds later bindings: its handle cannot be read from the answer
|
|
20
|
+
* (a compile error). `fields` keeps only those value paths of each answered record, and `envelope` only those of
|
|
21
|
+
* its own fields ({@link ENVELOPE_FIELDS}: `cid`, `author` and the rest; every field without it); `uri: false`
|
|
22
|
+
* drops the record's `uri` too (`value` always comes back); bindings read the whole record, before any cut.
|
|
23
|
+
*
|
|
24
|
+
* The platform's rules (the lexicon's): at most {@link MAX_STEPS} steps; a list step's `limit` at most
|
|
25
|
+
* {@link MAX_STEP_LIMIT} (past {@link MAX_PAGE}, one `listRecords` page, the platform reads the pages and answers
|
|
26
|
+
* them as one); a `return: false` list step is read in full (no `limit` or `cursor`; past {@link MAX_STEP_LIMIT}
|
|
27
|
+
* records it fails); a get step at most {@link MAX_STEP_URIS} URIs after binding; a bound list at most
|
|
28
|
+
* {@link MAX_BOUND} values; at most {@link MAX_TOTAL_RECORDS} records across the one-page steps. A signed-in caller spends
|
|
29
|
+
* a row budget: `run` waits and asks again on `RateLimitExceeded` ({@link COMPOSE_RETRIES} times).
|
|
30
|
+
*
|
|
31
|
+
* **A failed step fails alone.** The platform answers a step it could not answer in `errors` (its own error, or
|
|
32
|
+
* `Skipped` when a step it binds to failed) and every other step as usual. A step built with `optional: true` (a
|
|
33
|
+
* decoration a screen can show without) then reads as empty, and {@link Composed.failed} names its error; any
|
|
34
|
+
* other step's failure fails `run` with that step's error ({@link ComposeStepError}), as a failed call would.
|
|
35
|
+
*
|
|
36
|
+
* The wire is plain data, so a stand-in platform can answer it from its own `listRecords` and `getRecords`
|
|
37
|
+
* ({@link emulateCompose}): tests and Beacon's dev seed do. It is not the platform: `references` and `subject`
|
|
38
|
+
* come from the type's query document there; the emulation reads `subject` (or `subject.uri`) and refuses
|
|
39
|
+
* `references`.
|
|
40
|
+
*/
|
|
41
|
+
import type * as ComposeRecords from '../generated/types/pub/techne/draft/query/composeRecords.js';
|
|
42
|
+
import { type ListPage, type Param, type Query, type QueryReader, type QueryRecord, type RecordsAnswer } from './index.js';
|
|
43
|
+
/** The one call {@link Composition.run} makes: a POST of a platform procedure with a JSON body. */
|
|
44
|
+
export type ComposePoster = <T>(nsid: string, body: unknown) => Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* A {@link QueryReader} that also carries the POST its compositions run on: `compose()…run(read.post)`. An app
|
|
47
|
+
* holds one (its GET and its POST over the same session); a test's stand-in gets one from {@link testReader}.
|
|
48
|
+
* Anything that takes a `QueryReader` takes a `Reader`.
|
|
49
|
+
*/
|
|
50
|
+
export type Reader = QueryReader & {
|
|
51
|
+
readonly post: ComposePoster;
|
|
52
|
+
};
|
|
53
|
+
/** `read` as a {@link Reader} posting with `post` (a new function: `read` itself is left alone). */
|
|
54
|
+
export declare function withPost(read: QueryReader, post: ComposePoster): Reader;
|
|
55
|
+
/** A stand-in platform's GET reader as a {@link Reader} whose POST answers `composeRecords` from those GETs
|
|
56
|
+
* ({@link emulateCompose}): for tests and dev seeds, never the platform. */
|
|
57
|
+
export declare function testReader(read: QueryReader, otherwise?: ComposePoster): Reader;
|
|
58
|
+
/** The most steps one call takes. */
|
|
59
|
+
export declare const MAX_STEPS = 12;
|
|
60
|
+
/** The most URIs one get step names, after its bindings are filled in. */
|
|
61
|
+
export declare const MAX_STEP_URIS = 500;
|
|
62
|
+
/** The most values one bound list holds. */
|
|
63
|
+
export declare const MAX_BOUND = 2000;
|
|
64
|
+
/** The most records the one-page steps of one call answer in all: a list step whose `limit` is over
|
|
65
|
+
* {@link MAX_PAGE}, or that is `return: false`, is not counted (its own limit bounds it). */
|
|
66
|
+
export declare const MAX_TOTAL_RECORDS = 3000;
|
|
67
|
+
/** The largest `limit` a list step takes, and the most records a `return: false` list step (read in full) may
|
|
68
|
+
* match before it fails. A step read for all of its records asks this and treats a cursor back as an error. */
|
|
69
|
+
export declare const MAX_STEP_LIMIT = 50000;
|
|
70
|
+
/** How many times `run` asks again after the platform answers `RateLimitExceeded` (the row budget refills at
|
|
71
|
+
* 500 rows a second, and a call is charged at most 3000). */
|
|
72
|
+
export declare const COMPOSE_RETRIES = 2;
|
|
73
|
+
/** `fields` that keep no value: a path no record has. For a step whose records count only by being there
|
|
74
|
+
* (a host's live source). */
|
|
75
|
+
export declare const ENVELOPE_ONLY: readonly string[];
|
|
76
|
+
/** The record fields a step's `envelope` may keep besides `uri` (kept unless the step asks `uri: false`) and
|
|
77
|
+
* `value` (always kept). */
|
|
78
|
+
export declare const ENVELOPE_FIELDS: readonly ["cid", "author", "collection", "time", "space", "source", "curated", "held", "measures", "signals"];
|
|
79
|
+
export type EnvelopeField = (typeof ENVELOPE_FIELDS)[number];
|
|
80
|
+
declare const envelopeOf: unique symbol;
|
|
81
|
+
declare const uriOf: unique symbol;
|
|
82
|
+
/** `'uri'` when a step keeps its records' `uri` (`U` true, the default), else nothing: a step asked `uri: false`,
|
|
83
|
+
* or one that may have been (`U` boolean), answers records without it. */
|
|
84
|
+
type KeptUri<U extends boolean> = [U] extends [true] ? 'uri' : never;
|
|
85
|
+
/** A record as a step with envelope `E` answers it: `uri` (unless `U` is false: the step asked `uri: false`),
|
|
86
|
+
* `value` (cut to the step's `fields`, which the type does not follow) and the `E` fields. Without an envelope
|
|
87
|
+
* `E` is every field: listRecords' record.
|
|
88
|
+
* It carries the same marker as {@link StepRef}: a record kept with more fields stands in for one needing fewer,
|
|
89
|
+
* never the other way, even when the field left out is optional (`space`, `curated`, `held`, `measures`,
|
|
90
|
+
* `signals`), which `Pick` alone would let through. A whole {@link QueryRecord} (no marker) stands in for any. */
|
|
91
|
+
export type StepRecord<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField, U extends boolean = true> = Pick<QueryRecord<V>, KeptUri<U> | 'value' | E> & {
|
|
92
|
+
/** Type only, never set: the record fields the step kept. */
|
|
93
|
+
readonly [envelopeOf]?: (field: E) => void;
|
|
94
|
+
};
|
|
95
|
+
/** A step's output another step can bind: the record's `uri`, `author`, `type` (collection), `space`,
|
|
96
|
+
* `subject` and `references` roles, or the strings at a value path. */
|
|
97
|
+
export type Output = 'uri' | 'author' | 'type' | 'space' | 'subject' | 'references' | `value.${string}`;
|
|
98
|
+
/** `"$<step>.<output>"`: an earlier step's output, filled in by the platform. */
|
|
99
|
+
export type Binding = `$${string}.${string}` & {
|
|
100
|
+
readonly __binding?: true;
|
|
101
|
+
};
|
|
102
|
+
/** A list step's param: a literal (string or list), or bindings, alone or mixed with literal strings in a list. */
|
|
103
|
+
export type StepParam = Param | Binding | readonly (string | Binding)[];
|
|
104
|
+
/** A step, by name, for later steps' bindings and for reading its answer. `R` is whether it is returned; `E` the
|
|
105
|
+
* record fields its envelope keeps (every one without an envelope), so a field it left out cannot be read; `U`
|
|
106
|
+
* whether its records keep their `uri` (false: asked `uri: false`; its `uri` binding still reads it). */
|
|
107
|
+
export interface StepRef<K extends 'list' | 'get', R extends boolean, E extends EnvelopeField = EnvelopeField, U extends boolean = true> {
|
|
108
|
+
readonly name: string;
|
|
109
|
+
readonly kind: K;
|
|
110
|
+
readonly returned: R;
|
|
111
|
+
readonly uri: Binding;
|
|
112
|
+
readonly author: Binding;
|
|
113
|
+
readonly type: Binding;
|
|
114
|
+
readonly space: Binding;
|
|
115
|
+
readonly subject: Binding;
|
|
116
|
+
readonly references: Binding;
|
|
117
|
+
/** The strings at `path` (`a`, `a.b`, `a[].b`) of each record's value. */
|
|
118
|
+
value(path: string): Binding;
|
|
119
|
+
/** Type only, never set: what the step's records keep. A function of `E` so a step keeping more fields stands in
|
|
120
|
+
* for one needing fewer, never the other way. Keyed by a private symbol, so no caller can name or set it. */
|
|
121
|
+
readonly [envelopeOf]?: (field: E) => void;
|
|
122
|
+
/** Type only, never set: whether the step's records keep their `uri`. A step that keeps it stands in for one
|
|
123
|
+
* read as maybe not (`U` boolean), never for one read as keeping it when it does not. */
|
|
124
|
+
readonly [uriOf]?: U;
|
|
125
|
+
}
|
|
126
|
+
interface Common<R extends boolean, E extends EnvelopeField, U extends boolean> {
|
|
127
|
+
/** False: the step's records only feed later bindings and are not in the answer. A list step so asked is read
|
|
128
|
+
* in full on the platform (no `limit` or `cursor`; past {@link MAX_STEP_LIMIT} records it fails). */
|
|
129
|
+
return?: R;
|
|
130
|
+
/** Value paths each answered record keeps (1 to 32). */
|
|
131
|
+
fields?: readonly string[];
|
|
132
|
+
/** The record fields each answered record keeps besides `uri` and `value` (every one when absent; `[]`: none).
|
|
133
|
+
* One left out is absent from the answer, so a flag (`curated`, `held`) left out reads as false. */
|
|
134
|
+
envelope?: readonly E[];
|
|
135
|
+
/** False: each answered record comes back without its own `uri` (default true). Bindings still read it, before
|
|
136
|
+
* the cut. For a step whose records nobody reads by URI. */
|
|
137
|
+
uri?: U;
|
|
138
|
+
/** The caller can do without this step: if it fails (or is skipped for a step it binds to), it reads as
|
|
139
|
+
* empty and `failed` names why, instead of failing `run`. The client's own; never sent. */
|
|
140
|
+
optional?: boolean;
|
|
141
|
+
}
|
|
142
|
+
export interface ListStepOpts<R extends boolean, E extends EnvelopeField = EnvelopeField, U extends boolean = true> extends Common<R, E, U> {
|
|
143
|
+
params?: Readonly<Record<string, StepParam>>;
|
|
144
|
+
/** How many records, up to {@link MAX_STEP_LIMIT}: past {@link MAX_PAGE} the platform reads `listRecords`' pages
|
|
145
|
+
* and answers them as one, with the cursor after the last. Not on a `return: false` step. */
|
|
146
|
+
limit?: number;
|
|
147
|
+
cursor?: string;
|
|
148
|
+
count?: boolean;
|
|
149
|
+
/** The handles of the repos of the records the page answers, as getRecords' `handles`. */
|
|
150
|
+
handles?: boolean;
|
|
151
|
+
/** The viewer's own records' curation status among those the page answers, as getRecords' `curation`. */
|
|
152
|
+
curation?: boolean;
|
|
153
|
+
}
|
|
154
|
+
export interface GetStepOpts<R extends boolean, E extends EnvelopeField = EnvelopeField, U extends boolean = true> extends Common<R, E, U> {
|
|
155
|
+
curated?: boolean;
|
|
156
|
+
handles?: boolean;
|
|
157
|
+
curation?: boolean;
|
|
158
|
+
defaults?: boolean;
|
|
159
|
+
includeBlockedByMe?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/** One step as it goes on the wire (`pub.techne.draft.query.composeRecords#step`). */
|
|
162
|
+
export type WireStep = Record<string, unknown> & {
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
165
|
+
/** Why a step has no result (`pub.techne.draft.query.composeRecords#stepError`): the error its method would
|
|
166
|
+
* answer alone, or `Skipped` (424) when a step it binds to failed. */
|
|
167
|
+
export type StepError = Omit<ComposeRecords.StepError, '$type'>;
|
|
168
|
+
/** A list step's page as `composeRecords` answers it: listRecords' page of {@link StepRecord}s, and asked with
|
|
169
|
+
* `handles` or `curation`, getRecords' for the records it answered (`#stepResult`). */
|
|
170
|
+
export interface ListStepPage<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField, U extends boolean = true> extends Omit<ListPage<V>, 'records'> {
|
|
171
|
+
records: StepRecord<V, E, U>[];
|
|
172
|
+
handles?: ComposeRecords.StepResult['handles'];
|
|
173
|
+
curation?: ComposeRecords.StepResult['curation'];
|
|
174
|
+
}
|
|
175
|
+
/** A required step of a composed call failed: the call fails as that step's method would have alone. */
|
|
176
|
+
export declare class ComposeStepError extends Error {
|
|
177
|
+
readonly step: string;
|
|
178
|
+
readonly status: number;
|
|
179
|
+
readonly error: string;
|
|
180
|
+
constructor(step: string, e: StepError);
|
|
181
|
+
}
|
|
182
|
+
/** What {@link Composition.run} takes beside the poster. */
|
|
183
|
+
export interface RunOpts {
|
|
184
|
+
/** How `run` waits before asking again after `RateLimitExceeded` (default: a timer). */
|
|
185
|
+
sleep?: (ms: number) => Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
/** One `composeRecords` call being built. Steps run in the order added; a binding names only an earlier step. */
|
|
188
|
+
export declare class Composition {
|
|
189
|
+
#private;
|
|
190
|
+
/** The steps as they will be sent. */
|
|
191
|
+
get steps(): readonly WireStep[];
|
|
192
|
+
/** A list step: one `listRecords` page of `query` (inline, or a published query's AT-URI). */
|
|
193
|
+
list<R extends boolean = true, E extends EnvelopeField = EnvelopeField, U extends boolean = true>(name: string, query: Query | {
|
|
194
|
+
queryUri: string;
|
|
195
|
+
}, opts?: ListStepOpts<R, E, U>): StepRef<'list', R, E, U>;
|
|
196
|
+
/** A get step: `getRecords` of `uris`, each an AT-URI or a binding (deduplicated). No URIs (or only bindings
|
|
197
|
+
* to left-out steps): the step is left out and answers nothing. */
|
|
198
|
+
get<R extends boolean = true, E extends EnvelopeField = EnvelopeField, U extends boolean = true>(name: string, uris: Iterable<string | Binding>, opts?: GetStepOpts<R, E, U>): StepRef<'get', R, E, U>;
|
|
199
|
+
/** Send the steps (one POST) and answer them. No steps left (every one could ask for nothing): no call.
|
|
200
|
+
* A step that failed and is not `optional` fails the run ({@link ComposeStepError}, the first in step
|
|
201
|
+
* order). `sleep` waits between retries (a test's stand-in; a timer otherwise). */
|
|
202
|
+
run(post: ComposePoster, opts?: RunOpts): Promise<Composed>;
|
|
203
|
+
}
|
|
204
|
+
/** A get step's answer: {@link RecordsAnswer} of {@link StepRecord}s. */
|
|
205
|
+
export type StepAnswer<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField> = Omit<RecordsAnswer<V>, 'records'> & {
|
|
206
|
+
records: Map<string, StepRecord<V, E>>;
|
|
207
|
+
};
|
|
208
|
+
/** A new composition. */
|
|
209
|
+
export declare const compose: () => Composition;
|
|
210
|
+
/** A `composeRecords` answer, read by step. A step left out (it could ask for nothing), or an optional one
|
|
211
|
+
* that failed, answers empty. */
|
|
212
|
+
export declare class Composed {
|
|
213
|
+
#private;
|
|
214
|
+
constructor(steps: Record<string, unknown>, errors?: Record<string, StepError>);
|
|
215
|
+
/** Why `step` has no answer: its error, or `Skipped` for a step it binds to; `undefined` when it answered
|
|
216
|
+
* (or was left out unsent). Only an `optional` step can have failed in an answer `run` gave. */
|
|
217
|
+
failed(step: {
|
|
218
|
+
readonly name: string;
|
|
219
|
+
}): StepError | undefined;
|
|
220
|
+
/** A list step's page: its records (value cut to its `fields`), cursor and, asked with `count`, count; asked
|
|
221
|
+
* with `handles` or `curation`, those of the records it answered. */
|
|
222
|
+
list<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField, U extends boolean = true>(step: StepRef<'list', true, E, U>): ListStepPage<V, E, U>;
|
|
223
|
+
/** A list step asked {@link MAX_STEP_LIMIT} records: all of them. A step that still answers a cursor matched more
|
|
224
|
+
* than the platform reads in one step, and this throws (`<who>: step <name> matched more than …`) rather than
|
|
225
|
+
* answer part of the list. */
|
|
226
|
+
whole<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField, U extends boolean = true>(step: StepRef<'list', true, E, U>, who: string): StepRecord<V, E, U>[];
|
|
227
|
+
/** A get step's answer as `getRecordsAnswer` gives it: records by URI, withheld, handles, curation, defaults.
|
|
228
|
+
* Only a step that keeps its records' `uri`. */
|
|
229
|
+
answer<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField>(step: StepRef<'get', true, E, true>): StepAnswer<V, E>;
|
|
230
|
+
/** A step's records in the order answered, list or get: the read for a step asked `uri: false`, whose records
|
|
231
|
+
* {@link records} cannot key by URI. */
|
|
232
|
+
answered<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField, U extends boolean = true>(step: StepRef<'list' | 'get', true, E, U>): StepRecord<V, E, U>[];
|
|
233
|
+
/** A step's records by URI: only a step that keeps their `uri`. */
|
|
234
|
+
records<V = Record<string, unknown>, E extends EnvelopeField = EnvelopeField>(step: StepRef<'list' | 'get', true, E, true>): Map<string, StepRecord<V, E>>;
|
|
235
|
+
}
|
|
236
|
+
/** `value` keeping only what `paths` reach (the platform's `select`). */
|
|
237
|
+
export declare function selectFields(value: unknown, paths: readonly string[]): Record<string, unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* A {@link ComposePoster} that answers `composeRecords` from a stand-in platform's `listRecords` and
|
|
240
|
+
* `getRecords` (the steps in order; a list step one page, or as many as the platform reads: its `limit` past one
|
|
241
|
+
* page, every page of a `return: false` step): for tests and dev seeds, never the platform. Any
|
|
242
|
+
* other POST goes to `otherwise` (or is refused). A stand-in read refused with 401 or 429 fails the whole call
|
|
243
|
+
* (thrown as is), as the platform refuses the caller before any step; any other failure is the step's.
|
|
244
|
+
*/
|
|
245
|
+
export declare function emulateCompose(read: QueryReader, otherwise?: ComposePoster): ComposePoster;
|
|
246
|
+
export {};
|