@seed-hypermedia/client 0.0.131 → 0.0.133

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 (60) hide show
  1. package/dist/apps.mjs +12 -9
  2. package/dist/auto-link.mjs +5 -5
  3. package/dist/block-diff.d.ts +37 -0
  4. package/dist/block-diff.mjs +10 -1
  5. package/dist/block-edits.d.ts +33 -0
  6. package/dist/block-edits.mjs +9 -0
  7. package/dist/blocks-to-markdown.d.ts +21 -6
  8. package/dist/blocks-to-markdown.mjs +3 -3
  9. package/dist/capability.mjs +2 -2
  10. package/dist/change.d.ts +2 -0
  11. package/dist/change.mjs +1 -1
  12. package/dist/{chunk-SUVJSSHG.mjs → chunk-4ELQ4LJL.mjs} +68 -9
  13. package/dist/chunk-53PY4AWT.mjs +163 -0
  14. package/dist/{chunk-3KLY2B27.mjs → chunk-7FPJWOXB.mjs} +148 -1
  15. package/dist/{chunk-QU6XHE3U.mjs → chunk-DGNAMVGH.mjs} +5 -2
  16. package/dist/{chunk-2XNVA2GK.mjs → chunk-ETIDW7ZJ.mjs} +1 -1
  17. package/dist/{chunk-ANR3R5NH.mjs → chunk-FU7FIYHI.mjs} +1 -1
  18. package/dist/{chunk-HY4NWSHF.mjs → chunk-H2R4GYNV.mjs} +4 -3
  19. package/dist/{chunk-2LSZJ2IM.mjs → chunk-HL43SJUP.mjs} +1 -1
  20. package/dist/{chunk-JM4WXPLC.mjs → chunk-IFELP3LQ.mjs} +1 -1
  21. package/dist/{chunk-IXSAJRZA.mjs → chunk-JQKYF5NB.mjs} +3 -3
  22. package/dist/{chunk-IRP2ZGH3.mjs → chunk-KAZNQFXV.mjs} +12 -8
  23. package/dist/{chunk-O5MHN2EO.mjs → chunk-KM2NR4YA.mjs} +1 -0
  24. package/dist/{chunk-RPBGROOJ.mjs → chunk-LDCWJXIP.mjs} +1 -1
  25. package/dist/{chunk-JRJ6U6B2.mjs → chunk-NEUDKUBC.mjs} +1 -1
  26. package/dist/{chunk-D3PRDISB.mjs → chunk-O36UBGLF.mjs} +3 -3
  27. package/dist/{chunk-4JFL3SUQ.mjs → chunk-Q7CWMEBZ.mjs} +1 -1
  28. package/dist/{chunk-NWOYBZWP.mjs → chunk-QFIEZZYJ.mjs} +215 -330
  29. package/dist/{chunk-QLR4OWHG.mjs → chunk-QS6PIRUE.mjs} +1 -1
  30. package/dist/{chunk-QRSUQQTZ.mjs → chunk-T7SWLR32.mjs} +2 -2
  31. package/dist/{chunk-WD332LPF.mjs → chunk-VSMUWHIY.mjs} +1 -1
  32. package/dist/{chunk-APL23ACF.mjs → chunk-YRNPRWYG.mjs} +1 -1
  33. package/dist/{chunk-ETQZ6PRJ.mjs → chunk-Z7VKSY7P.mjs} +3 -3
  34. package/dist/client.d.ts +2 -0
  35. package/dist/client.mjs +3 -3
  36. package/dist/comment.mjs +2 -2
  37. package/dist/create-document.mjs +2 -2
  38. package/dist/document-state.mjs +2 -2
  39. package/dist/editorblock-to-hmblock.mjs +2 -2
  40. package/dist/hm-resolver.mjs +2 -2
  41. package/dist/hm-types.d.ts +9 -0
  42. package/dist/hm-types.mjs +1 -1
  43. package/dist/hmblock-to-editorblock.mjs +2 -2
  44. package/dist/index.d.ts +5 -3
  45. package/dist/index.mjs +64 -50
  46. package/dist/markdown-to-blocks.d.ts +25 -5
  47. package/dist/markdown-to-blocks.mjs +7 -3
  48. package/dist/pdf-to-blocks.mjs +3 -3
  49. package/dist/prepare-change.d.ts +6 -0
  50. package/dist/prepare-change.mjs +4 -4
  51. package/dist/resource-read.mjs +5 -5
  52. package/dist/schema-engine.mjs +2 -2
  53. package/dist/schema-registry.generated.mjs +1 -1
  54. package/dist/schema-resolve.mjs +4 -4
  55. package/dist/schema-subtypes.mjs +4 -4
  56. package/dist/schema-types.generated.d.ts +2 -0
  57. package/dist/signed-blob.mjs +2 -2
  58. package/dist/tei-to-blocks.mjs +2 -2
  59. package/dist/unicode.mjs +1 -1
  60. package/package.json +1 -1
@@ -1,3 +1,10 @@
1
+ import {
2
+ parseMarkdown
3
+ } from "./chunk-4ELQ4LJL.mjs";
4
+ import {
5
+ blocksToMarkdown
6
+ } from "./chunk-QFIEZZYJ.mjs";
7
+
1
8
  // src/block-diff.ts
2
9
  function createBlocksMap(nodes, parentId = "") {
3
10
  const result = {};
@@ -370,6 +377,144 @@ function hmBlockNodeToBlockNode(node) {
370
377
  children: (node.children || []).map(hmBlockNodeToBlockNode)
371
378
  };
372
379
  }
380
+ var TABLE_PARTS = /* @__PURE__ */ new Set(["Table", "TableColumn", "TableRow"]);
381
+ function stableJson(value) {
382
+ if (Array.isArray(value)) return "[" + value.map(stableJson).join(",") + "]";
383
+ if (value && typeof value === "object") {
384
+ const map = value;
385
+ const keys = Object.keys(map).filter((key) => map[key] !== void 0).sort();
386
+ return "{" + keys.map((key) => JSON.stringify(key) + ":" + stableJson(map[key])).join(",") + "}";
387
+ }
388
+ return JSON.stringify(value) ?? "null";
389
+ }
390
+ function nativeIpfsLink(link) {
391
+ const gateway = "https://ipfs.io/ipfs/";
392
+ return link.startsWith(gateway) ? "ipfs://" + link.slice(gateway.length) : link;
393
+ }
394
+ function blockKey(block, own = false) {
395
+ const annotations = (block.annotations || []).map(canonicalAnnotation).filter(hasRange).map((annotation) => stableJson(annotation)).sort();
396
+ return stableJson([
397
+ block.type,
398
+ block.text || "",
399
+ nativeIpfsLink(block.link || ""),
400
+ annotations,
401
+ own ? "" : block.childrenType || "",
402
+ block.language || "",
403
+ block.attributes || {}
404
+ ]);
405
+ }
406
+ function eachBlock(nodes, visit) {
407
+ for (const node of nodes) {
408
+ visit(node.block);
409
+ eachBlock(node.children, visit);
410
+ }
411
+ }
412
+ function markdownUpdateTree(oldContent, written) {
413
+ const oldNodes = oldContent.map(toAPIBlockNode);
414
+ const tree = rebindTableIdentities(oldNodes, written);
415
+ const stored = /* @__PURE__ */ new Map();
416
+ eachBlock(oldContent.map(hmBlockNodeToBlockNode), (block) => {
417
+ if (block.id && !stored.has(block.id)) stored.set(block.id, block);
418
+ });
419
+ const readsAs = /* @__PURE__ */ new Map();
420
+ const readsAsOwn = /* @__PURE__ */ new Map();
421
+ for (const mentionLabel of [() => "", void 0]) {
422
+ try {
423
+ const markdown = blocksToMarkdown({ metadata: {}, content: oldContent }, {
424
+ ipfsGateway: false,
425
+ mentionLabel
426
+ });
427
+ eachBlock(rebindTableIdentities(oldNodes, parseMarkdown(markdown).tree), (block) => {
428
+ if (!stored.has(block.id)) return;
429
+ readsAs.set(block.id, (readsAs.get(block.id) || /* @__PURE__ */ new Set()).add(blockKey(block)));
430
+ readsAsOwn.set(block.id, (readsAsOwn.get(block.id) || /* @__PURE__ */ new Set()).add(blockKey(block, true)));
431
+ });
432
+ } catch {
433
+ }
434
+ }
435
+ const present = /* @__PURE__ */ new Set();
436
+ eachBlock(tree, (block) => present.add(block.id));
437
+ const matchable = (block) => !TABLE_PARTS.has(block.type) && !!(block.text || block.link);
438
+ const unclaimed = /* @__PURE__ */ new Map();
439
+ for (const [id, block] of Array.from(stored)) {
440
+ if (present.has(id) || !matchable(block)) continue;
441
+ for (const key of Array.from(readsAsOwn.get(id) || [])) {
442
+ const ids = unclaimed.get(key);
443
+ if (ids) ids.push(id);
444
+ else unclaimed.set(key, [id]);
445
+ }
446
+ }
447
+ const claim = (key) => {
448
+ const ids = unclaimed.get(key) || [];
449
+ while (ids.length) {
450
+ const id = ids.shift();
451
+ if (!present.has(id)) {
452
+ present.add(id);
453
+ return id;
454
+ }
455
+ }
456
+ return void 0;
457
+ };
458
+ const walk = (nodes) => nodes.map((node) => {
459
+ var _a;
460
+ const key = blockKey(node.block);
461
+ let id = node.block.id;
462
+ if (!stored.has(id) && matchable(node.block)) id = claim(blockKey(node.block, true)) ?? id;
463
+ const block = ((_a = readsAs.get(id)) == null ? void 0 : _a.has(key)) ? stored.get(id) : id === node.block.id ? node.block : { ...node.block, id };
464
+ return { block, children: walk(node.children) };
465
+ });
466
+ return walk(tree);
467
+ }
468
+ function longestOrdered(ids, rank) {
469
+ const tails = [];
470
+ for (const id of ids) {
471
+ const value = rank.get(id);
472
+ let low = 0;
473
+ let high = tails.length;
474
+ while (low < high) {
475
+ const mid = low + high >> 1;
476
+ if (tails[mid] < value) low = mid + 1;
477
+ else high = mid;
478
+ }
479
+ tails[low] = value;
480
+ }
481
+ return tails.length;
482
+ }
483
+ function describeContentChange(oldNodes, newTree, ops) {
484
+ const place = (nodes) => {
485
+ const placed = /* @__PURE__ */ new Map();
486
+ const walk = (list, parent) => list.forEach((node, index) => {
487
+ var _a;
488
+ if (!((_a = node.block) == null ? void 0 : _a.id) || placed.has(node.block.id)) return;
489
+ placed.set(node.block.id, { parent, index });
490
+ walk(node.children || [], node.block.id);
491
+ });
492
+ walk(nodes, "");
493
+ return placed;
494
+ };
495
+ const before = place(oldNodes);
496
+ const after = place(newTree);
497
+ let added = 0;
498
+ let moved = 0;
499
+ const kept = /* @__PURE__ */ new Map();
500
+ for (const [id, now] of Array.from(after)) {
501
+ const was = before.get(id);
502
+ if (!was) added++;
503
+ else if (was.parent !== now.parent) moved++;
504
+ else kept.set(now.parent, [...kept.get(now.parent) || [], id]);
505
+ }
506
+ for (const ids of Array.from(kept.values())) {
507
+ const rank = new Map(ids.map((id) => [id, before.get(id).index]));
508
+ moved += ids.length - longestOrdered(ids, rank);
509
+ }
510
+ let deleted = 0;
511
+ for (const id of Array.from(before.keys())) if (!after.has(id)) deleted++;
512
+ let rewritten = 0;
513
+ for (const op of ops) {
514
+ if (op.type === "ReplaceBlock" && before.has(String(op.block.id))) rewritten++;
515
+ }
516
+ return { blocks: before.size, added, rewritten, moved, deleted };
517
+ }
373
518
 
374
519
  export {
375
520
  createBlocksMap,
@@ -377,5 +522,7 @@ export {
377
522
  rebindTableIdentities,
378
523
  computeReplaceOps,
379
524
  toAPIBlockNode,
380
- hmBlockNodeToBlockNode
525
+ hmBlockNodeToBlockNode,
526
+ markdownUpdateTree,
527
+ describeContentChange
381
528
  };
@@ -1258,7 +1258,8 @@ var HMRawDocumentChangeSchema = z.object({
1258
1258
  id: z.string().optional(),
1259
1259
  author: z.string().optional(),
1260
1260
  deps: z.array(z.string()).optional(),
1261
- createTime: z.string().optional()
1261
+ createTime: z.string().optional(),
1262
+ message: z.string().optional()
1262
1263
  });
1263
1264
  var HMListChangesOutputSchema = z.object({
1264
1265
  changes: z.array(HMRawDocumentChangeSchema),
@@ -1460,7 +1461,9 @@ var HMPrepareDocumentChangeInputSchema = z.object({
1460
1461
  baseVersion: z.string().optional(),
1461
1462
  changes: z.array(ProtoDocumentChangeSchema),
1462
1463
  capability: z.string().optional(),
1463
- visibility: z.number().int().optional()
1464
+ visibility: z.number().int().optional(),
1465
+ /** Optional human-readable description of the change, like a commit message. */
1466
+ message: z.string().optional()
1464
1467
  });
1465
1468
  var HMPrepareDocumentChangeOutputSchema = z.object({
1466
1469
  unsignedChange: z.custom((val) => ArrayBuffer.isView(val) && "byteLength" in val, {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getSupportedHMQueryFilters,
3
3
  isSurrogate
4
- } from "./chunk-QU6XHE3U.mjs";
4
+ } from "./chunk-DGNAMVGH.mjs";
5
5
 
6
6
  // src/hmblock-to-editorblock.ts
7
7
  function toEditorBlockType(hmBlockType) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  codePointLength
3
- } from "./chunk-QU6XHE3U.mjs";
3
+ } from "./chunk-DGNAMVGH.mjs";
4
4
 
5
5
  // src/tei-to-blocks.ts
6
6
  function generateBlockId() {
@@ -7,7 +7,7 @@ import {
7
7
  createDocumentChange,
8
8
  createHomeGenesisChange,
9
9
  signDocumentChange
10
- } from "./chunk-O5MHN2EO.mjs";
10
+ } from "./chunk-KM2NR4YA.mjs";
11
11
  import {
12
12
  createVersionRef
13
13
  } from "./chunk-PJ2RFT5A.mjs";
@@ -15,7 +15,7 @@ import {
15
15
  HMActionSchema,
16
16
  HMRequestSchema,
17
17
  packHmId
18
- } from "./chunk-QU6XHE3U.mjs";
18
+ } from "./chunk-DGNAMVGH.mjs";
19
19
 
20
20
  // src/client.ts
21
21
  import { encode as cborEncode } from "@ipld/dag-cbor";
@@ -292,7 +292,8 @@ function createSeedClient(baseUrl, options) {
292
292
  baseVersion: input.baseVersion,
293
293
  changes: input.changes,
294
294
  capability: input.capability,
295
- visibility: input.visibility
295
+ visibility: input.visibility,
296
+ message: input.message
296
297
  };
297
298
  const { unsignedChange } = await request("PrepareDocumentChange", prepareInput);
298
299
  const { publishInput, changeCid, genesis, generation } = await signDocumentChange(
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  hmIdPathToEntityQueryPath,
11
11
  packHmId
12
- } from "./chunk-QU6XHE3U.mjs";
12
+ } from "./chunk-DGNAMVGH.mjs";
13
13
 
14
14
  // src/comment.ts
15
15
  import { decode as cborDecode, encode as cborEncode } from "@ipld/dag-cbor";
@@ -7,7 +7,7 @@ import {
7
7
  codePointLength,
8
8
  parseHMQueryFiltersJSON,
9
9
  toNumber
10
- } from "./chunk-QU6XHE3U.mjs";
10
+ } from "./chunk-DGNAMVGH.mjs";
11
11
 
12
12
  // src/editorblock-to-hmblock.ts
13
13
  function toHMBlockType(editorBlockType) {
@@ -10,17 +10,17 @@ import {
10
10
  schemaForCid,
11
11
  structFields,
12
12
  validate
13
- } from "./chunk-JRJ6U6B2.mjs";
13
+ } from "./chunk-NEUDKUBC.mjs";
14
14
  import {
15
15
  HM_SCHEMAS
16
- } from "./chunk-QRSUQQTZ.mjs";
16
+ } from "./chunk-T7SWLR32.mjs";
17
17
  import {
18
18
  parseCidString
19
19
  } from "./chunk-VWSAFDOL.mjs";
20
20
  import {
21
21
  packHmId,
22
22
  unpackHmId
23
- } from "./chunk-QU6XHE3U.mjs";
23
+ } from "./chunk-DGNAMVGH.mjs";
24
24
 
25
25
  // src/schema-resolve.ts
26
26
  var DAG_CBOR_CODE = 113;
@@ -1,3 +1,6 @@
1
+ import {
2
+ sameDocumentVersion
3
+ } from "./chunk-QS6PIRUE.mjs";
1
4
  import {
2
5
  SeedClientError
3
6
  } from "./chunk-CBELM7KX.mjs";
@@ -6,13 +9,10 @@ import {
6
9
  createChangeOps,
7
10
  signDocumentChange,
8
11
  visibilityToCbor
9
- } from "./chunk-O5MHN2EO.mjs";
12
+ } from "./chunk-KM2NR4YA.mjs";
10
13
  import {
11
14
  createVersionRef
12
15
  } from "./chunk-PJ2RFT5A.mjs";
13
- import {
14
- sameDocumentVersion
15
- } from "./chunk-QLR4OWHG.mjs";
16
16
 
17
17
  // src/prepare-change.ts
18
18
  import { decode as cborDecode } from "@ipld/dag-cbor";
@@ -364,7 +364,8 @@ async function prepareDocumentUpdateBlobs(input) {
364
364
  baseVersion: input.baseVersion,
365
365
  changes,
366
366
  capability: input.capability,
367
- visibility: input.visibility
367
+ visibility: input.visibility,
368
+ message: input.message
368
369
  },
369
370
  { signal: input.signal }
370
371
  );
@@ -417,7 +418,8 @@ async function clientBuiltDocumentUpdateBlobs(input) {
417
418
  genesisCid: CID.parse(input.state.genesis),
418
419
  deps: input.state.heads.map((head) => CID.parse(head)),
419
420
  depth,
420
- ts: BigInt(headTs !== void 0 && Number.isFinite(headTs) && headTs >= now ? headTs + 1 : now)
421
+ ts: BigInt(headTs !== void 0 && Number.isFinite(headTs) && headTs >= now ? headTs + 1 : now),
422
+ message: input.message
421
423
  });
422
424
  const change = await createChange(unsignedBytes, input.signer);
423
425
  const generation = keptGeneration(input.currentGeneration, Number(ts));
@@ -463,7 +465,8 @@ async function documentUpdateBlobs(input) {
463
465
  capability: input.capability,
464
466
  currentGeneration: input.currentGeneration,
465
467
  visibility: input.visibility,
466
- now: input.now
468
+ now: input.now,
469
+ message: input.message
467
470
  });
468
471
  return { ...built, builtBy: "local", localReason };
469
472
  };
@@ -499,7 +502,8 @@ async function documentUpdateBlobs(input) {
499
502
  baseVersion: state.version,
500
503
  changes,
501
504
  capability: input.capability,
502
- visibility: input.visibility
505
+ visibility: input.visibility,
506
+ message: input.message
503
507
  },
504
508
  { signal: abort.signal }
505
509
  );
@@ -29,6 +29,7 @@ function createChangeOps(input) {
29
29
  unsigned.deps = input.deps ?? [];
30
30
  unsigned.depth = input.depth ?? 1;
31
31
  }
32
+ if (input.message) unsigned.message = input.message;
32
33
  return { unsignedBytes: cborEncode(unsigned), ts };
33
34
  }
34
35
  async function createChange(unsignedBytes, signer) {
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  entityQueryPathToHmIdPath,
9
9
  packBaseId
10
- } from "./chunk-QU6XHE3U.mjs";
10
+ } from "./chunk-DGNAMVGH.mjs";
11
11
 
12
12
  // src/capability.ts
13
13
  import { base58btc } from "multiformats/bases/base58";
@@ -2,7 +2,7 @@ import {
2
2
  HM_SCHEMAS,
3
3
  HM_SCHEMA_MANIFEST,
4
4
  HM_SCHEMA_PAGES
5
- } from "./chunk-QRSUQQTZ.mjs";
5
+ } from "./chunk-T7SWLR32.mjs";
6
6
 
7
7
  // src/schema-engine.ts
8
8
  var LIBRARY_AUTHORITY = "hyper.media";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  documentUpdateBlobs
3
- } from "./chunk-IRP2ZGH3.mjs";
3
+ } from "./chunk-KAZNQFXV.mjs";
4
4
  import {
5
5
  resolveDocumentState
6
- } from "./chunk-QLR4OWHG.mjs";
6
+ } from "./chunk-QS6PIRUE.mjs";
7
7
  import {
8
8
  entityQueryPathToHmIdPath,
9
9
  packHmId,
10
10
  unpackHmId
11
- } from "./chunk-QU6XHE3U.mjs";
11
+ } from "./chunk-DGNAMVGH.mjs";
12
12
 
13
13
  // src/auto-link.ts
14
14
  function documentContainsLinkToChild(document, childId) {
@@ -2,7 +2,7 @@ import {
2
2
  entityQueryPathToHmIdPath,
3
3
  parseFragment,
4
4
  unpackHmId
5
- } from "./chunk-QU6XHE3U.mjs";
5
+ } from "./chunk-DGNAMVGH.mjs";
6
6
  import {
7
7
  pageParamsFromUrl
8
8
  } from "./chunk-AHQWDCHV.mjs";