@seed-hypermedia/client 0.0.129 → 0.0.131
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 +15 -1
- package/dist/apps.mjs +21 -32
- package/dist/auto-link.d.ts +12 -2
- package/dist/auto-link.mjs +4 -2
- package/dist/block-diff.d.ts +14 -4
- package/dist/{chunk-LGJJ4V2O.mjs → chunk-D3PRDISB.mjs} +19 -31
- package/dist/chunk-IRP2ZGH3.mjs +670 -0
- package/dist/{chunk-ZRJYHORB.mjs → chunk-QLR4OWHG.mjs} +23 -3
- package/dist/document-state.d.ts +13 -0
- package/dist/document-state.mjs +5 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +34 -8
- package/dist/prepare-change.d.ts +407 -0
- package/dist/prepare-change.mjs +35 -0
- package/package.json +1 -1
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 {
|
|
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,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
documentUpdateBlobs
|
|
3
|
+
} from "./chunk-IRP2ZGH3.mjs";
|
|
4
|
+
import "./chunk-CBELM7KX.mjs";
|
|
5
|
+
import "./chunk-O5MHN2EO.mjs";
|
|
6
|
+
import "./chunk-PJ2RFT5A.mjs";
|
|
5
7
|
import {
|
|
6
|
-
createVersionRef
|
|
7
|
-
} from "./chunk-PJ2RFT5A.mjs";
|
|
8
|
-
import {
|
|
9
|
-
editRefGeneration,
|
|
10
8
|
resolveEditableDocument
|
|
11
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-QLR4OWHG.mjs";
|
|
12
10
|
import {
|
|
13
11
|
computeReplaceOps,
|
|
14
12
|
createBlocksMap,
|
|
@@ -26,7 +24,6 @@ import "./chunk-AHQWDCHV.mjs";
|
|
|
26
24
|
import "./chunk-7P6ASYW6.mjs";
|
|
27
25
|
|
|
28
26
|
// src/apps.ts
|
|
29
|
-
import { CID } from "multiformats/cid";
|
|
30
27
|
var HM_APP_TYPE = "hm://hyper.media/app";
|
|
31
28
|
var HM_TOOL_TYPE = "hm://hyper.media/tool";
|
|
32
29
|
var HM_PAGE_TYPE = "hm://hyper.media/page";
|
|
@@ -119,34 +116,26 @@ async function createDocumentUpdateBlobs({
|
|
|
119
116
|
capability,
|
|
120
117
|
extraBlobs = []
|
|
121
118
|
}) {
|
|
119
|
+
var _a;
|
|
122
120
|
if (!ops.length) throw new Error("No document changes to publish");
|
|
123
121
|
const base = await resolveEditableDocument(client, id);
|
|
124
|
-
const
|
|
125
|
-
|
|
122
|
+
const update = await documentUpdateBlobs({
|
|
123
|
+
client,
|
|
124
|
+
signer,
|
|
125
|
+
account: base.targetId.uid,
|
|
126
|
+
path: hmIdPathToEntityQueryPath(base.targetId.path),
|
|
127
|
+
state: base.state,
|
|
126
128
|
ops,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
content: base.document.content ?? [],
|
|
130
|
+
documentVersion: base.document.version,
|
|
131
|
+
capability,
|
|
132
|
+
currentGeneration: (_a = base.document.generationInfo) == null ? void 0 : _a.generation
|
|
130
133
|
});
|
|
131
|
-
const change = await createChange(unsignedBytes, signer);
|
|
132
|
-
const ref = await createVersionRef(
|
|
133
|
-
{
|
|
134
|
-
space: base.targetId.uid,
|
|
135
|
-
path: hmIdPathToEntityQueryPath(base.targetId.path),
|
|
136
|
-
genesis: state.genesis,
|
|
137
|
-
version: change.cid.toString(),
|
|
138
|
-
generation: editRefGeneration(base.document, Number(ts)),
|
|
139
|
-
capability
|
|
140
|
-
},
|
|
141
|
-
signer
|
|
142
|
-
);
|
|
143
134
|
return {
|
|
144
|
-
blobs: [
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
],
|
|
149
|
-
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 } : {}
|
|
150
139
|
};
|
|
151
140
|
}
|
|
152
141
|
function versionless(id) {
|
package/dist/auto-link.d.ts
CHANGED
|
@@ -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
|
|
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
|
*/
|
package/dist/auto-link.mjs
CHANGED
|
@@ -4,10 +4,12 @@ import {
|
|
|
4
4
|
documentContainsLinkToChild,
|
|
5
5
|
documentHasSelfQuery,
|
|
6
6
|
shouldAutoLinkParent
|
|
7
|
-
} from "./chunk-
|
|
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-
|
|
12
|
+
import "./chunk-QLR4OWHG.mjs";
|
|
11
13
|
import "./chunk-LVAHHQIK.mjs";
|
|
12
14
|
import "./chunk-DR3HJ6BV.mjs";
|
|
13
15
|
import "./chunk-QU6XHE3U.mjs";
|
package/dist/block-diff.d.ts
CHANGED
|
@@ -68,13 +68,23 @@ export declare function matchBlockIds(oldNodes: APIBlockNode[], newNodes: BlockN
|
|
|
68
68
|
*/
|
|
69
69
|
export declare function rebindTableIdentities(oldNodes: APIBlockNode[], newNodes: BlockNode[]): BlockNode[];
|
|
70
70
|
/**
|
|
71
|
-
* Compare the new block tree against the old blocks map and produce
|
|
72
|
-
*
|
|
71
|
+
* Compare the new block tree against the old blocks map and produce the
|
|
72
|
+
* DocumentOperations that turn one into the other:
|
|
73
73
|
*
|
|
74
|
-
* - ReplaceBlock for new or content-changed blocks
|
|
75
|
-
* - MoveBlocks for
|
|
74
|
+
* - ReplaceBlock for new or content-changed blocks (an unchanged block gets none)
|
|
75
|
+
* - MoveBlocks for a level whose order changed (an unchanged level gets none)
|
|
76
76
|
* - DeleteBlocks for blocks removed from the document
|
|
77
77
|
*
|
|
78
|
+
* The replaces are minimal; the moves are not. A native MoveBlocks carries no
|
|
79
|
+
* anchor: it places its blocks at the start of the parent's children, in the
|
|
80
|
+
* order listed. So a level whose order changed in any way (a block added,
|
|
81
|
+
* removed or moved) is listed whole, the blocks already in place included.
|
|
82
|
+
* An update sent through `PrepareDocumentChange` (documentUpdateBlobs)
|
|
83
|
+
* drops the moves that change nothing, so the stored Change is minimal there;
|
|
84
|
+
* a Change built from these ops directly (createChangeOps) stores them all.
|
|
85
|
+
* Skipping unchanged blocks here still matters on the daemon path: it writes
|
|
86
|
+
* a block with a whole-number attribute again even when it is equal.
|
|
87
|
+
*
|
|
78
88
|
* The delete pass is global: every old block whose id does not appear
|
|
79
89
|
* anywhere in the new tree is deleted, including descendants of deleted
|
|
80
90
|
* blocks (so removing a table row also removes its cells, leaving no
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-O5MHN2EO.mjs";
|
|
2
|
+
documentUpdateBlobs
|
|
3
|
+
} from "./chunk-IRP2ZGH3.mjs";
|
|
5
4
|
import {
|
|
6
|
-
createVersionRef
|
|
7
|
-
} from "./chunk-PJ2RFT5A.mjs";
|
|
8
|
-
import {
|
|
9
|
-
editRefGeneration,
|
|
10
5
|
resolveDocumentState
|
|
11
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QLR4OWHG.mjs";
|
|
12
7
|
import {
|
|
13
8
|
entityQueryPathToHmIdPath,
|
|
14
9
|
packHmId,
|
|
@@ -16,7 +11,6 @@ import {
|
|
|
16
11
|
} from "./chunk-QU6XHE3U.mjs";
|
|
17
12
|
|
|
18
13
|
// src/auto-link.ts
|
|
19
|
-
import { CID } from "multiformats/cid";
|
|
20
14
|
function documentContainsLinkToChild(document, childId) {
|
|
21
15
|
const childUrlNormalized = packHmId({ ...childId, version: null, latest: null });
|
|
22
16
|
function searchBlocks(nodes) {
|
|
@@ -99,7 +93,8 @@ function createAutoLinkOps(parentDocument, childHmUrl, newBlockId) {
|
|
|
99
93
|
];
|
|
100
94
|
}
|
|
101
95
|
async function autoLinkChildToParent(opts) {
|
|
102
|
-
|
|
96
|
+
var _a;
|
|
97
|
+
const { client, account, path, childHmUrl, signer, capability } = opts;
|
|
103
98
|
const segments = path.replace(/^\//, "").split("/");
|
|
104
99
|
if (segments.length <= 1) return false;
|
|
105
100
|
const parentSegments = segments.slice(0, -1);
|
|
@@ -122,28 +117,21 @@ async function autoLinkChildToParent(opts) {
|
|
|
122
117
|
return false;
|
|
123
118
|
}
|
|
124
119
|
const newBlockId = generateBlockId();
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
path: parentPath,
|
|
138
|
-
genesis: state.genesis,
|
|
139
|
-
version: changeBlock.cid.toString(),
|
|
140
|
-
generation
|
|
141
|
-
},
|
|
142
|
-
signer
|
|
143
|
-
);
|
|
144
|
-
await client.publish({
|
|
145
|
-
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
|
|
146
132
|
});
|
|
133
|
+
if (!update.changed) return false;
|
|
134
|
+
await client.publish({ blobs: update.blobs });
|
|
147
135
|
return true;
|
|
148
136
|
}
|
|
149
137
|
function generateBlockId() {
|