@seed-hypermedia/client 0.0.27 → 0.0.29
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/auto-link.d.ts +5 -0
- package/dist/index.mjs +32 -17
- package/package.json +1 -1
package/dist/auto-link.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export declare function documentContainsLinkToChild(document: HMDocument, childI
|
|
|
20
20
|
/**
|
|
21
21
|
* Check if a document has a self-referential Query block
|
|
22
22
|
* (a query to itself that would automatically include children).
|
|
23
|
+
*
|
|
24
|
+
* A query block is self-referential when one of its `query.includes` entries
|
|
25
|
+
* has `space === documentId.uid` AND a path that, after normalization, equals
|
|
26
|
+
* the document's path. Empty `space` or `path` does not count as self — that
|
|
27
|
+
* represents an unconfigured query block, which the editor renders empty.
|
|
23
28
|
*/
|
|
24
29
|
export declare function documentHasSelfQuery(document: HMDocument, documentId: UnpackedHypermediaId): boolean;
|
|
25
30
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -668,6 +668,20 @@ function cleanContentOfUndefined(content) {
|
|
|
668
668
|
if (children) cleanContentOfUndefined(children);
|
|
669
669
|
});
|
|
670
670
|
}
|
|
671
|
+
function deepStripUndefined(value) {
|
|
672
|
+
if (Array.isArray(value)) {
|
|
673
|
+
return value.map((item) => deepStripUndefined(item));
|
|
674
|
+
}
|
|
675
|
+
if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
676
|
+
const result = {};
|
|
677
|
+
for (const [k, v] of Object.entries(value)) {
|
|
678
|
+
if (v === void 0) continue;
|
|
679
|
+
result[k] = deepStripUndefined(v);
|
|
680
|
+
}
|
|
681
|
+
return result;
|
|
682
|
+
}
|
|
683
|
+
return value;
|
|
684
|
+
}
|
|
671
685
|
function createUnsignedComment({
|
|
672
686
|
content,
|
|
673
687
|
docId,
|
|
@@ -724,7 +738,8 @@ async function createCommentBlob({
|
|
|
724
738
|
rootReplyCommentVersion,
|
|
725
739
|
visibility
|
|
726
740
|
});
|
|
727
|
-
const
|
|
741
|
+
const cleanedUnsignedComment = deepStripUndefined(unsignedComment);
|
|
742
|
+
const signedComment = await createSignedComment(cleanedUnsignedComment, signer);
|
|
728
743
|
return cborEncode6(signedComment);
|
|
729
744
|
}
|
|
730
745
|
function generateBlockId(length = 8) {
|
|
@@ -809,8 +824,9 @@ async function deleteComment(input, signer) {
|
|
|
809
824
|
sig: new Uint8Array(64)
|
|
810
825
|
};
|
|
811
826
|
if (input.visibility) tombstone.visibility = input.visibility;
|
|
812
|
-
|
|
813
|
-
|
|
827
|
+
const cleanedTombstone = deepStripUndefined(tombstone);
|
|
828
|
+
cleanedTombstone.sig = await signObject(signer, cleanedTombstone);
|
|
829
|
+
const encoded = cborEncode6(cleanedTombstone);
|
|
814
830
|
return toPublishInput(encoded, []);
|
|
815
831
|
}
|
|
816
832
|
async function updateComment(input, signer) {
|
|
@@ -836,8 +852,9 @@ async function updateComment(input, signer) {
|
|
|
836
852
|
if (input.replyParentVersion) comment.replyParent = CID3.parse(input.replyParentVersion);
|
|
837
853
|
if (input.rootReplyCommentVersion) comment.threadRoot = CID3.parse(input.rootReplyCommentVersion);
|
|
838
854
|
if (input.visibility) comment.visibility = input.visibility;
|
|
839
|
-
|
|
840
|
-
|
|
855
|
+
const cleanedComment = deepStripUndefined(comment);
|
|
856
|
+
cleanedComment.sig = await signObject(signer, cleanedComment);
|
|
857
|
+
const encoded = cborEncode6(cleanedComment);
|
|
841
858
|
return toPublishInput(encoded, []);
|
|
842
859
|
}
|
|
843
860
|
async function commentRecordIdFromBlob(blobData) {
|
|
@@ -3279,21 +3296,19 @@ function documentContainsLinkToChild(document, childId) {
|
|
|
3279
3296
|
return searchBlocks(document.content || []);
|
|
3280
3297
|
}
|
|
3281
3298
|
function documentHasSelfQuery(document, documentId) {
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3299
|
+
const parentPathStr = (documentId.path || []).join("/");
|
|
3300
|
+
function isSelfMatch(include) {
|
|
3301
|
+
if (!include) return false;
|
|
3302
|
+
if (include.space !== documentId.uid) return false;
|
|
3303
|
+
const includePath = entityQueryPathToHmIdPath(include.path);
|
|
3304
|
+
return (includePath || []).join("/") === parentPathStr;
|
|
3305
|
+
}
|
|
3285
3306
|
function searchBlocks(nodes) {
|
|
3286
|
-
var
|
|
3307
|
+
var _a, _b;
|
|
3287
3308
|
for (const node of nodes) {
|
|
3288
3309
|
if (node.block.type === "Query") {
|
|
3289
|
-
const
|
|
3290
|
-
if (
|
|
3291
|
-
for (const inc of query.includes) {
|
|
3292
|
-
const isSpaceMatch = !inc.space || inc.space === documentId.uid;
|
|
3293
|
-
const isPathMatch = !inc.path || inc.path === documentPathWithSlash || inc.path === documentPathWithoutSlash;
|
|
3294
|
-
if (isSpaceMatch && isPathMatch) return true;
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3310
|
+
const includes = (_b = (_a = node.block.attributes) == null ? void 0 : _a.query) == null ? void 0 : _b.includes;
|
|
3311
|
+
if (includes == null ? void 0 : includes.some(isSelfMatch)) return true;
|
|
3297
3312
|
}
|
|
3298
3313
|
if (node.children && searchBlocks(node.children)) return true;
|
|
3299
3314
|
}
|