@seed-hypermedia/client 0.0.128 → 0.0.130

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/dist/apps.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * belong to the app and in what order. Agents, the CLI and the apps' own UI all go through the
8
8
  * helpers here, so the "every child is embedded" rule is enforced in one place.
9
9
  */
10
- import { type DocumentOperation } from './change';
10
+ import type { DocumentOperation } from './change';
11
11
  import type { SeedClient } from './client';
12
12
  import type { CollectedBlob } from './file-to-ipfs';
13
13
  import { type HMBlockNode, type UnpackedHypermediaId } from './hm-types';
@@ -61,6 +61,16 @@ export declare function removeAppChildOps(appId: UnpackedHypermediaId, content:
61
61
  * makes it the latest version. Returns the blobs to publish (`extraBlobs`, such as a tool's code
62
62
  * folder, come last). `capability` is the writer capability when the signer writes into another
63
63
  * account's space.
64
+ *
65
+ * The Change is computed by the daemon (`PrepareDocumentChange`, through
66
+ * {@link documentUpdateBlobs}), which leaves out every op that would change nothing. When
67
+ * nothing is left, `changed` is false and `blobs` holds only `extraBlobs`: no Change and no Ref.
68
+ * Publish `blobs` only when it is not empty. When the daemon cannot be asked for the update, or
69
+ * does not give a usable answer, the Change is built here with the ops as listed (`builtBy` is
70
+ * `'local'` and `localReason` says why); the result has the same shape.
71
+ *
72
+ * A redirected address is followed: the update lands on the document the address presents
73
+ * (`targetId`).
64
74
  */
65
75
  export declare function createDocumentUpdateBlobs({ client, signer, id, ops, capability, extraBlobs, }: {
66
76
  client: Pick<SeedClient, 'request'>;
@@ -72,6 +82,10 @@ export declare function createDocumentUpdateBlobs({ client, signer, id, ops, cap
72
82
  }): Promise<{
73
83
  blobs: CollectedBlob[];
74
84
  targetId: UnpackedHypermediaId;
85
+ changed: boolean;
86
+ /** Who computed the Change, when there is one. */
87
+ builtBy?: 'server' | 'local';
88
+ localReason?: string;
75
89
  }>;
76
90
  /**
77
91
  * A trigger document (`type: hm://hyper.media/trigger`) is a child of an app or an agent, listed in
package/dist/apps.mjs CHANGED
@@ -1,13 +1,12 @@
1
1
  import {
2
- createChange,
3
- createChangeOps
4
- } from "./chunk-O5MHN2EO.mjs";
5
- import {
6
- createVersionRef
7
- } from "./chunk-PJ2RFT5A.mjs";
2
+ documentUpdateBlobs
3
+ } from "./chunk-IRP2ZGH3.mjs";
4
+ import "./chunk-CBELM7KX.mjs";
5
+ import "./chunk-O5MHN2EO.mjs";
6
+ import "./chunk-PJ2RFT5A.mjs";
8
7
  import {
9
8
  resolveEditableDocument
10
- } from "./chunk-MJUI4O7L.mjs";
9
+ } from "./chunk-QLR4OWHG.mjs";
11
10
  import {
12
11
  computeReplaceOps,
13
12
  createBlocksMap,
@@ -25,7 +24,6 @@ import "./chunk-AHQWDCHV.mjs";
25
24
  import "./chunk-7P6ASYW6.mjs";
26
25
 
27
26
  // src/apps.ts
28
- import { CID } from "multiformats/cid";
29
27
  var HM_APP_TYPE = "hm://hyper.media/app";
30
28
  var HM_TOOL_TYPE = "hm://hyper.media/tool";
31
29
  var HM_PAGE_TYPE = "hm://hyper.media/page";
@@ -118,34 +116,26 @@ async function createDocumentUpdateBlobs({
118
116
  capability,
119
117
  extraBlobs = []
120
118
  }) {
119
+ var _a;
121
120
  if (!ops.length) throw new Error("No document changes to publish");
122
121
  const base = await resolveEditableDocument(client, id);
123
- const state = base.state;
124
- const { unsignedBytes, ts } = createChangeOps({
122
+ const update = await documentUpdateBlobs({
123
+ client,
124
+ signer,
125
+ account: base.targetId.uid,
126
+ path: hmIdPathToEntityQueryPath(base.targetId.path),
127
+ state: base.state,
125
128
  ops,
126
- genesisCid: CID.parse(state.genesis),
127
- deps: state.heads.map((head) => CID.parse(head)),
128
- depth: state.headDepth + 1
129
+ content: base.document.content ?? [],
130
+ documentVersion: base.document.version,
131
+ capability,
132
+ currentGeneration: (_a = base.document.generationInfo) == null ? void 0 : _a.generation
129
133
  });
130
- const change = await createChange(unsignedBytes, signer);
131
- const ref = await createVersionRef(
132
- {
133
- space: base.targetId.uid,
134
- path: hmIdPathToEntityQueryPath(base.targetId.path),
135
- genesis: state.genesis,
136
- version: change.cid.toString(),
137
- generation: Number(ts),
138
- capability
139
- },
140
- signer
141
- );
142
134
  return {
143
- blobs: [
144
- { cid: change.cid.toString(), data: new Uint8Array(change.bytes) },
145
- ...ref.blobs.map((blob) => ({ cid: blob.cid, data: blob.data })),
146
- ...extraBlobs
147
- ],
148
- targetId: base.targetId
135
+ blobs: [...update.blobs, ...extraBlobs],
136
+ targetId: base.targetId,
137
+ changed: update.changed,
138
+ ...update.changed ? { builtBy: update.builtBy, localReason: update.localReason } : {}
149
139
  };
150
140
  }
151
141
  function versionless(id) {
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * - Pure decision logic: should a link be added?
9
9
  * - Operation builder: what DocumentOperations to emit
10
- * - Full I/O convenience: fetch parent, check, build ops, sign, publish
10
+ * - Full I/O convenience: fetch parent, check, build the change, sign, publish
11
11
  */
12
12
  import type { HMDocument, UnpackedHypermediaId } from './hm-types';
13
13
  import type { AnySigner } from './signer';
@@ -39,6 +39,10 @@ export declare function shouldAutoLinkParent(isPrivate: boolean, parentDocument:
39
39
  * MoveBlocks that lists ALL root-level block IDs (existing + new) to ensure
40
40
  * correct ordering. The CBOR MoveBlocks format with no `ref` positions blocks
41
41
  * from the start, so we must re-specify the full ordering.
42
+ *
43
+ * Sent through `documentUpdateBlobs`, the daemon stores only the new block and
44
+ * its one placement after the last root block; a Change built from these ops
45
+ * directly stores the whole list.
42
46
  */
43
47
  export declare function createAutoLinkOps(parentDocument: HMDocument, childHmUrl: string, newBlockId: string): DocumentOperation[];
44
48
  /** Options for the auto-link convenience function. */
@@ -53,13 +57,19 @@ export type AutoLinkChildToParentOptions = {
53
57
  childHmUrl: string;
54
58
  /** Signer for the parent document change. */
55
59
  signer: AnySigner;
60
+ /** Writer capability CID, when the signer writes into another account's space. */
61
+ capability?: string;
56
62
  };
57
63
  /**
58
64
  * Auto-link a newly published child document to its parent.
59
65
  *
60
66
  * Computes the parent path, fetches the parent document, decides whether a link
61
67
  * is needed (using `shouldAutoLinkParent`), and if so publishes an Embed Card
62
- * block to the parent document.
68
+ * block to the parent document. The parent's Change goes through
69
+ * `documentUpdateBlobs`: the daemon computes it on top of the version that was
70
+ * read, so it holds only the new block and its placement; when the daemon
71
+ * cannot be asked or does not give a usable answer, the Change is built here
72
+ * and lists every root block, as it always did.
63
73
  *
64
74
  * Returns true if a link was added, false otherwise. Throws on network errors.
65
75
  */
@@ -4,10 +4,12 @@ import {
4
4
  documentContainsLinkToChild,
5
5
  documentHasSelfQuery,
6
6
  shouldAutoLinkParent
7
- } from "./chunk-BWAQAXHH.mjs";
7
+ } from "./chunk-D3PRDISB.mjs";
8
+ import "./chunk-IRP2ZGH3.mjs";
9
+ import "./chunk-CBELM7KX.mjs";
8
10
  import "./chunk-O5MHN2EO.mjs";
9
11
  import "./chunk-PJ2RFT5A.mjs";
10
- import "./chunk-MJUI4O7L.mjs";
12
+ import "./chunk-QLR4OWHG.mjs";
11
13
  import "./chunk-LVAHHQIK.mjs";
12
14
  import "./chunk-DR3HJ6BV.mjs";
13
15
  import "./chunk-QU6XHE3U.mjs";
@@ -1,13 +1,9 @@
1
1
  import {
2
- createChange,
3
- createChangeOps
4
- } from "./chunk-O5MHN2EO.mjs";
5
- import {
6
- createVersionRef
7
- } from "./chunk-PJ2RFT5A.mjs";
2
+ documentUpdateBlobs
3
+ } from "./chunk-IRP2ZGH3.mjs";
8
4
  import {
9
5
  resolveDocumentState
10
- } from "./chunk-MJUI4O7L.mjs";
6
+ } from "./chunk-QLR4OWHG.mjs";
11
7
  import {
12
8
  entityQueryPathToHmIdPath,
13
9
  packHmId,
@@ -15,7 +11,6 @@ import {
15
11
  } from "./chunk-QU6XHE3U.mjs";
16
12
 
17
13
  // src/auto-link.ts
18
- import { CID } from "multiformats/cid";
19
14
  function documentContainsLinkToChild(document, childId) {
20
15
  const childUrlNormalized = packHmId({ ...childId, version: null, latest: null });
21
16
  function searchBlocks(nodes) {
@@ -98,7 +93,8 @@ function createAutoLinkOps(parentDocument, childHmUrl, newBlockId) {
98
93
  ];
99
94
  }
100
95
  async function autoLinkChildToParent(opts) {
101
- const { client, account, path, childHmUrl, signer } = opts;
96
+ var _a;
97
+ const { client, account, path, childHmUrl, signer, capability } = opts;
102
98
  const segments = path.replace(/^\//, "").split("/");
103
99
  if (segments.length <= 1) return false;
104
100
  const parentSegments = segments.slice(0, -1);
@@ -121,28 +117,21 @@ async function autoLinkChildToParent(opts) {
121
117
  return false;
122
118
  }
123
119
  const newBlockId = generateBlockId();
124
- const ops = createAutoLinkOps(parentDocument, childHmUrl, newBlockId);
125
- const hmUrl = `hm://${account}${parentPath}`;
126
- const state = await resolveDocumentState(client, hmUrl);
127
- const genesisCid = CID.parse(state.genesis);
128
- const depCids = state.heads.map((h) => CID.parse(h));
129
- const newDepth = state.headDepth + 1;
130
- const { unsignedBytes, ts } = createChangeOps({ ops, genesisCid, deps: depCids, depth: newDepth });
131
- const changeBlock = await createChange(unsignedBytes, signer);
132
- const generation = Number(ts);
133
- const refInput = await createVersionRef(
134
- {
135
- space: account,
136
- path: parentPath,
137
- genesis: state.genesis,
138
- version: changeBlock.cid.toString(),
139
- generation
140
- },
141
- signer
142
- );
143
- await client.publish({
144
- blobs: [{ data: new Uint8Array(changeBlock.bytes), cid: changeBlock.cid.toString() }, ...refInput.blobs]
120
+ const state = await resolveDocumentState(client, `hm://${account}${parentPath}`);
121
+ const update = await documentUpdateBlobs({
122
+ client,
123
+ signer,
124
+ account,
125
+ path: parentPath,
126
+ state,
127
+ ops: createAutoLinkOps(parentDocument, childHmUrl, newBlockId),
128
+ content: parentDocument.content ?? [],
129
+ documentVersion: parentDocument.version,
130
+ capability,
131
+ currentGeneration: (_a = parentDocument.generationInfo) == null ? void 0 : _a.generation
145
132
  });
133
+ if (!update.changed) return false;
134
+ await client.publish({ blobs: update.blobs });
146
135
  return true;
147
136
  }
148
137
  function generateBlockId() {