techne-sdk 0.4.0 → 0.6.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +12 -3
  3. package/dist/auth/app-key.d.ts +5 -0
  4. package/dist/auth/app-key.js +7 -0
  5. package/dist/auth/index.d.ts +19 -11
  6. package/dist/auth/index.js +21 -13
  7. package/dist/catalog/catalog.gen.js +499 -139
  8. package/dist/connect.d.ts +18 -3
  9. package/dist/connect.js +2 -0
  10. package/dist/generated/index.d.ts +3 -0
  11. package/dist/generated/index.js +9 -0
  12. package/dist/generated/lexicons.d.ts +590 -146
  13. package/dist/generated/lexicons.js +332 -71
  14. package/dist/generated/nsid.d.ts +3 -0
  15. package/dist/generated/nsid.js +3 -0
  16. package/dist/generated/nsid.json +3 -0
  17. package/dist/generated/types/pub/techne/draft/identity/attest.d.ts +2 -0
  18. package/dist/generated/types/pub/techne/draft/identity/defs.d.ts +23 -7
  19. package/dist/generated/types/pub/techne/draft/identity/defs.js +7 -0
  20. package/dist/generated/types/pub/techne/draft/identity/finishAddMethod.d.ts +3 -0
  21. package/dist/generated/types/pub/techne/draft/identity/listMethods.d.ts +2 -1
  22. package/dist/generated/types/pub/techne/draft/identity/manageMethods.d.ts +52 -10
  23. package/dist/generated/types/pub/techne/draft/identity/manageMethods.js +56 -0
  24. package/dist/generated/types/pub/techne/draft/identity/writeAsCollective.d.ts +51 -0
  25. package/dist/generated/types/pub/techne/draft/identity/writeAsCollective.js +55 -0
  26. package/dist/generated/types/pub/techne/draft/permissioned/putRecord.d.ts +1 -1
  27. package/dist/generated/types/pub/techne/draft/permissioned/putRecords.d.ts +1 -1
  28. package/dist/generated/types/pub/techne/draft/query/getRecords.d.ts +11 -0
  29. package/dist/generated/types/pub/techne/draft/query/getRecords.js +7 -0
  30. package/dist/query/compose.d.ts +1 -1
  31. package/dist/query/compose.js +1 -1
  32. package/dist/query/index.d.ts +7 -0
  33. package/dist/query/index.js +28 -1
  34. package/dist/versions/react.js +19 -6
  35. package/dist/wasm/techne-wasm.gen.js +1 -1
  36. package/dist/wasm/techne-wasm2js.gen.js +16836 -16838
  37. package/package.json +3 -2
@@ -150,6 +150,26 @@ export function shownHandle(handle) {
150
150
  const h = handle?.trim();
151
151
  return h && h.toLowerCase() !== 'handle.invalid' ? h : undefined;
152
152
  }
153
+ /** A `getRecords#handle` entry's `linked` list as {@link LinkedAccount}s: malformed entries, the entry's own DID
154
+ * and repeats left out. */
155
+ function linkedAccountsOf(list, self) {
156
+ if (!Array.isArray(list))
157
+ return [];
158
+ const seen = new Set([self]);
159
+ const out = [];
160
+ for (const v of list) {
161
+ if (!v || typeof v !== 'object')
162
+ continue;
163
+ const { did, handle, displayName } = v;
164
+ if (typeof did !== 'string' || !did || seen.has(did))
165
+ continue;
166
+ seen.add(did);
167
+ const shown = typeof handle === 'string' ? shownHandle(handle) : undefined;
168
+ const name = typeof displayName === 'string' ? displayName.trim() : '';
169
+ out.push({ did, ...(shown ? { handle: shown } : {}), ...(name ? { displayName: name } : {}) });
170
+ }
171
+ return out;
172
+ }
153
173
  /** The records at `uris` the viewer may read, by URI, and which of the asked URIs were withheld. With
154
174
  * `handles`, also the public handle of each repo the URIs name; with `curation`, the curation status
155
175
  * of each asked URI that is the signed-in caller's own (no extra read: the same call answers it).
@@ -168,15 +188,22 @@ export async function getRecordsAnswer(read, uris, opts = {}) {
168
188
  /** One or more `getRecords` pages (or a composed get step's answer) as a {@link RecordsAnswer}. */
169
189
  export function answerOf(pages) {
170
190
  const handles = new Map();
191
+ const linked = new Map();
171
192
  for (const h of pages.flatMap((p) => (Array.isArray(p.handles) ? p.handles : []))) {
172
- const handle = typeof h?.did === 'string' && typeof h.handle === 'string' ? shownHandle(h.handle) : undefined;
193
+ if (typeof h?.did !== 'string')
194
+ continue;
195
+ const handle = typeof h.handle === 'string' ? shownHandle(h.handle) : undefined;
173
196
  if (handle)
174
197
  handles.set(h.did, handle);
198
+ const others = linkedAccountsOf(h.linked, h.did);
199
+ if (others.length)
200
+ linked.set(h.did, others);
175
201
  }
176
202
  return {
177
203
  records: new Map(pages.flatMap((p) => p.records).map((r) => [r.uri, r])),
178
204
  withheld: new Set(pages.flatMap((p) => (Array.isArray(p.withheld) ? p.withheld : []))),
179
205
  handles,
206
+ linked,
180
207
  curation: new Map(pages
181
208
  .flatMap((p) => (Array.isArray(p.curation) ? p.curation : []))
182
209
  .map(curationOf)
@@ -40,20 +40,33 @@ export function useEvent(uri, options = {}) {
40
40
  useEffect(() => {
41
41
  loadRef.current = load;
42
42
  });
43
+ // Reads are numbered; an answer lands only when it is newer than the last one shown (`shown`), so the
44
+ // newest answer wins. `reload()` does not drop a read still in flight: a caller that reloads faster than
45
+ // the network answers would otherwise never see one. A uri (or data mode) change raises the floor to the
46
+ // last read sent, so nothing read for the previous uri ever lands. That effect is declared before the
47
+ // read's, so on a uri change the floor is raised before the new uri's read is numbered.
48
+ const sent = useRef(0);
49
+ const shown = useRef(0);
50
+ useEffect(() => {
51
+ shown.current = sent.current;
52
+ }, [uri, dataMode]);
43
53
  useEffect(() => {
44
54
  const read = loadRef.current;
45
55
  if (!uri || !read || dataMode)
46
56
  return;
47
- let live = true;
57
+ const seq = ++sent.current;
58
+ const landed = () => {
59
+ if (seq <= shown.current)
60
+ return false;
61
+ shown.current = seq;
62
+ return true;
63
+ };
48
64
  read(uri).then((out) => {
49
- if (!live)
65
+ if (!landed())
50
66
  return;
51
67
  setLoaded({ uri, out });
52
68
  setFailed(null);
53
- }, (e) => live && setFailed({ uri, error: e }));
54
- return () => {
55
- live = false;
56
- };
69
+ }, (e) => landed() && setFailed({ uri, error: e }));
57
70
  }, [uri, dataMode, reads]);
58
71
  const data = dataMode ? given ?? null : loaded && loaded.uri === uri ? loaded.out : null;
59
72
  const error = !dataMode && failed && failed.uri === uri ? failed.error : null;