techne-sdk 0.3.3 → 0.3.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +5 -4
  3. package/dist/auth/app-key.js +2 -2
  4. package/dist/auth/index.js +1 -1
  5. package/dist/catalog/catalog.gen.d.ts +24 -24
  6. package/dist/catalog/catalog.gen.js +356 -66
  7. package/dist/connect.d.ts +96 -12
  8. package/dist/connect.js +83 -12
  9. package/dist/generated/lexicons.d.ts +140 -36
  10. package/dist/generated/lexicons.js +77 -18
  11. package/dist/generated/nsid.d.ts +4 -0
  12. package/dist/generated/nsid.js +4 -0
  13. package/dist/generated/nsid.json +4 -0
  14. package/dist/generated/types/pub/techne/draft/beacon.d.ts +2 -0
  15. package/dist/generated/types/pub/techne/draft/collective.d.ts +1 -1
  16. package/dist/generated/types/pub/techne/draft/identity/attest.d.ts +3 -0
  17. package/dist/generated/types/pub/techne/draft/identity/attest.js +7 -0
  18. package/dist/generated/types/pub/techne/draft/identity/beginAddMethod.d.ts +3 -0
  19. package/dist/generated/types/pub/techne/draft/identity/beginAddMethod.js +7 -0
  20. package/dist/generated/types/pub/techne/draft/identity/finishAddMethod.d.ts +6 -0
  21. package/dist/generated/types/pub/techne/draft/identity/finishAddMethod.js +14 -0
  22. package/dist/generated/types/pub/techne/draft/identity/resolve.d.ts +6 -0
  23. package/dist/generated/types/pub/techne/draft/membership.d.ts +1 -1
  24. package/dist/generated/types/pub/techne/draft/permissioned/deleteRecord.d.ts +3 -0
  25. package/dist/generated/types/pub/techne/draft/permissioned/deleteRecord.js +7 -0
  26. package/dist/generated/types/pub/techne/draft/permissioned/putRecord.d.ts +3 -0
  27. package/dist/generated/types/pub/techne/draft/permissioned/putRecord.js +7 -0
  28. package/dist/generated/types/pub/techne/draft/permissioned/putRecords.d.ts +4 -1
  29. package/dist/generated/types/pub/techne/draft/permissioned/putRecords.js +7 -0
  30. package/dist/generated/types/pub/techne/draft/summary.d.ts +2 -0
  31. package/dist/item.d.ts +130 -0
  32. package/dist/item.js +74 -0
  33. package/dist/links/index.d.ts +15 -8
  34. package/dist/links/index.js +18 -0
  35. package/dist/put/contacts.d.ts +2 -2
  36. package/dist/put/index.d.ts +6 -9
  37. package/dist/put/index.js +8 -166
  38. package/dist/put/put.d.ts +14 -0
  39. package/dist/put/put.js +206 -0
  40. package/dist/query/compose.d.ts +246 -0
  41. package/dist/query/compose.js +572 -0
  42. package/dist/query/hosts.d.ts +98 -1
  43. package/dist/query/hosts.js +143 -2
  44. package/dist/query/index.d.ts +60 -29
  45. package/dist/query/index.js +55 -26
  46. package/dist/react/context.d.ts +18 -0
  47. package/dist/react/context.js +19 -0
  48. package/dist/react/index.d.ts +14 -0
  49. package/dist/react/index.js +14 -0
  50. package/dist/react/query.d.ts +75 -0
  51. package/dist/react/query.js +116 -0
  52. package/dist/read/index.d.ts +60 -0
  53. package/dist/read/index.js +107 -0
  54. package/dist/resend.d.ts +25 -0
  55. package/dist/resend.js +52 -0
  56. package/dist/versions/entities.gen.d.ts +8 -0
  57. package/dist/versions/entities.gen.js +9 -0
  58. package/dist/versions/index.d.ts +59 -17
  59. package/dist/versions/index.js +156 -22
  60. package/dist/versions/react.d.ts +1 -1
  61. package/dist/versions/react.js +1 -1
  62. package/dist/versions/text.d.ts +19 -0
  63. package/dist/versions/text.js +73 -0
  64. package/dist/wasm/techne-wasm.gen.js +1 -1
  65. package/dist/wasm/techne-wasm2js.gen.js +8928 -8927
  66. package/package.json +17 -5
@@ -0,0 +1,73 @@
1
+ /**
2
+ * A version's text as plain text: the commons' publish-time decode, ported from commons
3
+ * `sources/scraper_kit/commons.py` (`decode_entities`, `clean_text`, `decode_text_fields`, main f8334c9).
4
+ *
5
+ * Sources hand the commons HTML-escaped strings in plain-text fields (`Parks & Open Space`). The
6
+ * commons decodes them when it publishes, but a record published before it did keeps the entity, and a
7
+ * record whose CID is pinned is never rewritten. Comparing and showing every version through the same
8
+ * decode makes an encoding difference what it is: no difference.
9
+ */
10
+ import { INVALID_CHARREFS, INVALID_CODEPOINTS, LEGACY, NAMED } from './entities.gen.js';
11
+ /** A character reference WITH its terminating `;`: `&`, `’`, `'`. The legacy forms
12
+ * without one (`&copy`, `&deg`) are not matched, so `Smith&degroot` stays as written. */
13
+ const ENTITY = /&(?:#[0-9]{1,7}|#[xX][0-9a-fA-F]{1,6}|[A-Za-z][A-Za-z0-9]{1,31});/g;
14
+ /** `&` (escaped twice upstream) needs two passes; the bound keeps a pathological value from looping. */
15
+ const ENTITY_PASSES = 3;
16
+ /** The text fields decoded: names, descriptions and an address's words. Never a uri, a time, a code or a coordinate. */
17
+ const TEXT_FIELDS = new Set(['name', 'description', 'street', 'locality', 'region']);
18
+ /** Deleted outright: ZERO WIDTH SPACE, SOFT HYPHEN, BOM. */
19
+ const INVISIBLE = /[\u200b\u00ad\ufeff]/g;
20
+ /** Control characters (Unicode `Cc`), each made a space. */
21
+ const CONTROL = /[\u0000-\u001f\u007f-\u009f]/g;
22
+ const LEGACY_NAMES = new Set(LEGACY);
23
+ /** One reference (with its `;`) as Python's `html.unescape` decodes it. */
24
+ function decodeReference(ref) {
25
+ const body = ref.slice(1, -1);
26
+ if (body[0] === '#') {
27
+ const n = body[1] === 'x' || body[1] === 'X' ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
28
+ const fixed = INVALID_CHARREFS.get(n);
29
+ if (fixed !== undefined)
30
+ return fixed;
31
+ if ((n >= 0xd800 && n <= 0xdfff) || n > 0x10ffff)
32
+ return '�';
33
+ if (INVALID_CODEPOINTS.some(([lo, hi]) => n >= lo && n <= hi))
34
+ return '';
35
+ return String.fromCodePoint(n);
36
+ }
37
+ const exact = NAMED.get(body);
38
+ if (exact !== undefined)
39
+ return exact;
40
+ // The longest legacy name the reference starts with (`&notit;` is `¬it;`), as the HTML5 parser reads it.
41
+ for (let len = body.length; len >= 2; len--) {
42
+ const name = body.slice(0, len);
43
+ if (LEGACY_NAMES.has(name))
44
+ return NAMED.get(name) + ref.slice(len + 1);
45
+ }
46
+ return ref;
47
+ }
48
+ /** The scrapers' text clean-up: invisibles removed, every control character a space, NFC, runs of
49
+ * whitespace one space, trimmed (commons `clean_text`). */
50
+ export function cleanText(text) {
51
+ return text.replace(INVISIBLE, '').replace(CONTROL, ' ').normalize('NFC').split(/\s+/).filter(Boolean).join(' ');
52
+ }
53
+ /** `text` with its `;`-terminated HTML character references decoded, up to 3 passes (`&amp;amp;` is
54
+ * `&`), then cleaned, since a reference can decode to what the clean-up removes (`Room&#10;B`). Text with
55
+ * no reference comes back as it was (commons `decode_entities`). */
56
+ export function decodeEntities(text) {
57
+ let out = text;
58
+ for (let pass = 0; pass < ENTITY_PASSES; pass++) {
59
+ const decoded = out.replace(ENTITY, decodeReference);
60
+ if (decoded === out)
61
+ break;
62
+ out = decoded;
63
+ }
64
+ return out === text ? text : cleanText(out);
65
+ }
66
+ export function decodeTextFields(value) {
67
+ if (Array.isArray(value))
68
+ return value.map(decodeTextFields);
69
+ if (value && typeof value === 'object' && [Object.prototype, null].includes(Object.getPrototypeOf(value))) {
70
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, TEXT_FIELDS.has(k) && typeof v === 'string' ? decodeEntities(v) : decodeTextFields(v)]));
71
+ }
72
+ return value;
73
+ }