feat(ffi): virtual tag nodes, single page type, rename and remove tag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-26 03:33:17 +01:00
1 parent e2ed9054c6
commit 0005a8e7a4
8 files changed
+409 -378

No files matched your search

+18 -16
View File
@@ -246,7 +246,7 @@ class GraphNode {
/// Community (Louvain), numbered by size: 0 is the largest. /// Community (Louvain), numbered by size: 0 is the largest.
final int cluster; final int cluster;
/// Node index of the tag this page uses most, if any. /// Node index of the tag (page or virtual tag node) this page uses most, if any.
final int? primaryTag; final int? primaryTag;
/// The page is a hub (`PageKind::Hub`). /// The page is a hub (`PageKind::Hub`).
@@ -255,9 +255,13 @@ class GraphNode {
/// Node index of the deepest hub containing this page (a hub: itself). /// Node index of the deepest hub containing this page (a hub: itself).
final int? homeHub; final int? homeHub;
/// Tag names of the page (see `PageDto::tags`), for grouping by tag. /// Tag names of the page, listed or implied by its types, for grouping by tag.
final List<String> tags; final List<String> tags;
/// A virtual tag node (not a page, no outline): `id` is `tag:<title_key>`, `title` the
/// display name, `degree` the number of pages carrying the tag.
final bool isTag;
const GraphNode({ const GraphNode({
required this.id, required this.id,
required this.title, required this.title,
@@ -271,6 +275,7 @@ class GraphNode {
required this.isHub, required this.isHub,
this.homeHub, this.homeHub,
required this.tags, required this.tags,
required this.isTag,
}); });
@override @override
@@ -286,7 +291,8 @@ class GraphNode {
primaryTag.hashCode ^ primaryTag.hashCode ^
isHub.hashCode ^ isHub.hashCode ^
homeHub.hashCode ^ homeHub.hashCode ^
tags.hashCode; tags.hashCode ^
isTag.hashCode;
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
@@ -304,7 +310,8 @@ class GraphNode {
primaryTag == other.primaryTag && primaryTag == other.primaryTag &&
isHub == other.isHub && isHub == other.isHub &&
homeHub == other.homeHub && homeHub == other.homeHub &&
tags == other.tags; tags == other.tags &&
isTag == other.isTag;
} }
/// A hub (folder-like page) with its members. /// A hub (folder-like page) with its members.
@@ -586,14 +593,12 @@ class PageDto {
/// Hub description (empty for notes). /// Hub description (empty for notes).
final String description; final String description;
/// Titles of the tag pages this page is filed under, in the order they were added. /// Tag names (no pages) this page lists, sorted by name; its type implies a tag too.
final List<String> tags; final List<String> tags;
/// The page is a tag page (a topic that other pages are filed under). /// The page's single type ("persona", "lugar"...: a name, not a page); it implies a tag of
final bool isTag; /// the same name.
final String? pageType;
/// Type names ("persona", "lugar"...: plain names, not pages), in the order added.
final List<String> types;
const PageDto({ const PageDto({
required this.id, required this.id,
@@ -605,8 +610,7 @@ class PageDto {
required this.isHub, required this.isHub,
required this.description, required this.description,
required this.tags, required this.tags,
required this.isTag, this.pageType,
required this.types,
}); });
@override @override
@@ -620,8 +624,7 @@ class PageDto {
isHub.hashCode ^ isHub.hashCode ^
description.hashCode ^ description.hashCode ^
tags.hashCode ^ tags.hashCode ^
isTag.hashCode ^ pageType.hashCode;
types.hashCode;
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
@@ -637,8 +640,7 @@ class PageDto {
isHub == other.isHub && isHub == other.isHub &&
description == other.description && description == other.description &&
tags == other.tags && tags == other.tags &&
isTag == other.isTag && pageType == other.pageType;
types == other.types;
} }
/// Hub and namespace context of one page. /// Hub and namespace context of one page.
+14 -12
View File
@@ -17,8 +17,6 @@ abstract class SynapseGraph implements RustOpaqueInterface {
Future<PageDto> addPageTag({required String pageId, required String tag}); Future<PageDto> addPageTag({required String pageId, required String tag});
Future<PageDto> addPageType({required String pageId, required String ty});
/// Puts a page in a hub (no-op when it already is). Fails for journals, non-hub targets, /// Puts a page in a hub (no-op when it already is). Fails for journals, non-hub targets,
/// the hub itself and memberships that would create a cycle. /// the hub itself and memberships that would create a cycle.
Future<void> addToHub({required String pageId, required String hubId}); Future<void> addToHub({required String pageId, required String hubId});
@@ -148,7 +146,7 @@ abstract class SynapseGraph implements RustOpaqueInterface {
/// Hub and namespace context of a page. /// Hub and namespace context of a page.
Future<PageStructure> pageStructure({required String pageId}); Future<PageStructure> pageStructure({required String pageId});
/// Pages carrying a tag, most recently updated first. /// Pages carrying a tag (listed or via their type), most recently updated first.
Future<List<PageBrief>> pagesWithTag({required String tag}); Future<List<PageBrief>> pagesWithTag({required String tag});
/// Deletes pages and their blocks in one transaction. Returns how many existed. /// Deletes pages and their blocks in one transaction. Returns how many existed.
@@ -180,10 +178,16 @@ abstract class SynapseGraph implements RustOpaqueInterface {
Future<PageDto> removePageTag({required String pageId, required String tag}); Future<PageDto> removePageTag({required String pageId, required String tag});
Future<PageDto> removePageType({required String pageId, required String ty}); /// Removes the explicit tag from every page (types of that name stay); returns the number
/// of pages changed.
Future<int> removeTag({required String name});
Future<PageDto> renamePage({required String id, required String newTitle}); Future<PageDto> renamePage({required String id, required String newTitle});
/// Renames a tag in the `tags` and `types` of every page carrying it; returns the number of
/// pages changed.
Future<int> renameTag({required String old, required String new_});
/// Blocks whose text contains `query` (for `((` autocomplete), most recent first. /// Blocks whose text contains `query` (for `((` autocomplete), most recent first.
Future<List<BlockHit>> searchBlocks({ Future<List<BlockHit>> searchBlocks({
required String query, required String query,
@@ -204,20 +208,18 @@ abstract class SynapseGraph implements RustOpaqueInterface {
required String description, required String description,
}); });
/// Replaces the tags of a page (each title gets a tag page if it has none). Journals, /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot
/// templates and tag pages cannot be tagged. /// be tagged.
Future<PageDto> setPageTags({ Future<PageDto> setPageTags({
required String pageId, required String pageId,
required List<String> tags, required List<String> tags,
}); });
/// Replaces the types of a page. Journals and templates cannot be typed. /// Sets (or with `None` clears) the single type of a page. Journals and templates cannot be
Future<PageDto> setPageTypes({ /// typed.
required String pageId, Future<PageDto> setPageType({required String pageId, String? pageType});
required List<String> types,
});
/// Every tag page with its number of pages, most used first. /// Every tag in use (listed or implied by a type) with its number of pages, most used first.
Future<List<TagDto>> tagCatalog(); Future<List<TagDto>> tagCatalog();
/// Timeline data for `[from, to]` (oldest first) with titles of every page it mentions. /// Timeline data for `[from, to]` (oldest first) with titles of every page it mentions.
+146 -154
View File
@@ -69,7 +69,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.13.0'; String get codegenVersion => '2.13.0';
@override @override
int get rustContentHash => 465538383; int get rustContentHash => -1472342481;
static const kDefaultExternalLibraryLoaderConfig = static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig( ExternalLibraryLoaderConfig(
@@ -123,12 +123,6 @@ abstract class RustLibApi extends BaseApi {
required String tag, required String tag,
}); });
Future<PageDto> crateApiGraphSynapseGraphAddPageType({
required SynapseGraph that,
required String pageId,
required String ty,
});
Future<void> crateApiGraphSynapseGraphAddToHub({ Future<void> crateApiGraphSynapseGraphAddToHub({
required SynapseGraph that, required SynapseGraph that,
required String pageId, required String pageId,
@@ -345,10 +339,9 @@ abstract class RustLibApi extends BaseApi {
required String tag, required String tag,
}); });
Future<PageDto> crateApiGraphSynapseGraphRemovePageType({ Future<int> crateApiGraphSynapseGraphRemoveTag({
required SynapseGraph that, required SynapseGraph that,
required String pageId, required String name,
required String ty,
}); });
Future<PageDto> crateApiGraphSynapseGraphRenamePage({ Future<PageDto> crateApiGraphSynapseGraphRenamePage({
@@ -357,6 +350,12 @@ abstract class RustLibApi extends BaseApi {
required String newTitle, required String newTitle,
}); });
Future<int> crateApiGraphSynapseGraphRenameTag({
required SynapseGraph that,
required String old,
required String new_,
});
Future<List<BlockHit>> crateApiGraphSynapseGraphSearchBlocks({ Future<List<BlockHit>> crateApiGraphSynapseGraphSearchBlocks({
required SynapseGraph that, required SynapseGraph that,
required String query, required String query,
@@ -387,10 +386,10 @@ abstract class RustLibApi extends BaseApi {
required List<String> tags, required List<String> tags,
}); });
Future<PageDto> crateApiGraphSynapseGraphSetPageTypes({ Future<PageDto> crateApiGraphSynapseGraphSetPageType({
required SynapseGraph that, required SynapseGraph that,
required String pageId, required String pageId,
required List<String> types, String? pageType,
}); });
Future<List<TagDto>> crateApiGraphSynapseGraphTagCatalog({ Future<List<TagDto>> crateApiGraphSynapseGraphTagCatalog({
@@ -713,46 +712,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["that", "pageId", "tag"], argNames: ["that", "pageId", "tag"],
); );
@override
Future<PageDto> crateApiGraphSynapseGraphAddPageType({
required SynapseGraph that,
required String pageId,
required String ty,
}) {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph(
that,
serializer,
);
sse_encode_String(pageId, serializer);
sse_encode_String(ty, serializer);
pdeCallFfi(
generalizedFrbRustBinding,
serializer,
funcId: 8,
port: port_,
);
},
codec: SseCodec(
decodeSuccessData: sse_decode_page_dto,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiGraphSynapseGraphAddPageTypeConstMeta,
argValues: [that, pageId, ty],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiGraphSynapseGraphAddPageTypeConstMeta =>
const TaskConstMeta(
debugName: "SynapseGraph_add_page_type",
argNames: ["that", "pageId", "ty"],
);
@override @override
Future<void> crateApiGraphSynapseGraphAddToHub({ Future<void> crateApiGraphSynapseGraphAddToHub({
required SynapseGraph that, required SynapseGraph that,
@@ -772,7 +731,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 9, funcId: 8,
port: port_, port: port_,
); );
}, },
@@ -810,7 +769,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 10, funcId: 9,
port: port_, port: port_,
); );
}, },
@@ -845,7 +804,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
serializer, serializer,
); );
sse_encode_String(hash, serializer); sse_encode_String(hash, serializer);
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 11)!; return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 10)!;
}, },
codec: SseCodec( codec: SseCodec(
decodeSuccessData: sse_decode_opt_String, decodeSuccessData: sse_decode_opt_String,
@@ -881,7 +840,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 12, funcId: 11,
port: port_, port: port_,
); );
}, },
@@ -919,7 +878,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 13, funcId: 12,
port: port_, port: port_,
); );
}, },
@@ -965,7 +924,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 14, funcId: 13,
port: port_, port: port_,
); );
}, },
@@ -1010,7 +969,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 15, funcId: 14,
port: port_, port: port_,
); );
}, },
@@ -1050,7 +1009,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 16, funcId: 15,
port: port_, port: port_,
); );
}, },
@@ -1090,7 +1049,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 17, funcId: 16,
port: port_, port: port_,
); );
}, },
@@ -1128,7 +1087,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 18, funcId: 17,
port: port_, port: port_,
); );
}, },
@@ -1166,7 +1125,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 19, funcId: 18,
port: port_, port: port_,
); );
}, },
@@ -1197,7 +1156,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
that, that,
serializer, serializer,
); );
return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 20)!; return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 19)!;
}, },
codec: SseCodec( codec: SseCodec(
decodeSuccessData: sse_decode_String, decodeSuccessData: sse_decode_String,
@@ -1228,7 +1187,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 21, funcId: 20,
port: port_, port: port_,
); );
}, },
@@ -1266,7 +1225,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 22, funcId: 21,
port: port_, port: port_,
); );
}, },
@@ -1304,7 +1263,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 23, funcId: 22,
port: port_, port: port_,
); );
}, },
@@ -1338,7 +1297,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 24, funcId: 23,
port: port_, port: port_,
); );
}, },
@@ -1373,7 +1332,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 25, funcId: 24,
port: port_, port: port_,
); );
}, },
@@ -1415,7 +1374,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 26, funcId: 25,
port: port_, port: port_,
); );
}, },
@@ -1453,7 +1412,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 27, funcId: 26,
port: port_, port: port_,
); );
}, },
@@ -1491,7 +1450,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 28, funcId: 27,
port: port_, port: port_,
); );
}, },
@@ -1531,7 +1490,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 29, funcId: 28,
port: port_, port: port_,
); );
}, },
@@ -1567,7 +1526,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 30, funcId: 29,
port: port_, port: port_,
); );
}, },
@@ -1609,7 +1568,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 31, funcId: 30,
port: port_, port: port_,
); );
}, },
@@ -1649,7 +1608,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 32, funcId: 31,
port: port_, port: port_,
); );
}, },
@@ -1691,7 +1650,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 33, funcId: 32,
port: port_, port: port_,
); );
}, },
@@ -1722,7 +1681,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 34, funcId: 33,
port: port_, port: port_,
); );
}, },
@@ -1758,7 +1717,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 35, funcId: 34,
port: port_, port: port_,
); );
}, },
@@ -1796,7 +1755,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 36, funcId: 35,
port: port_, port: port_,
); );
}, },
@@ -1834,7 +1793,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 37, funcId: 36,
port: port_, port: port_,
); );
}, },
@@ -1872,7 +1831,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 38, funcId: 37,
port: port_, port: port_,
); );
}, },
@@ -1910,7 +1869,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 39, funcId: 38,
port: port_, port: port_,
); );
}, },
@@ -1948,7 +1907,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 40, funcId: 39,
port: port_, port: port_,
); );
}, },
@@ -1986,7 +1945,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 41, funcId: 40,
port: port_, port: port_,
); );
}, },
@@ -2024,7 +1983,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 42, funcId: 41,
port: port_, port: port_,
); );
}, },
@@ -2066,7 +2025,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 43, funcId: 42,
port: port_, port: port_,
); );
}, },
@@ -2106,7 +2065,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 44, funcId: 43,
port: port_, port: port_,
); );
}, },
@@ -2146,7 +2105,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 45, funcId: 44,
port: port_, port: port_,
); );
}, },
@@ -2186,7 +2145,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 46, funcId: 45,
port: port_, port: port_,
); );
}, },
@@ -2224,7 +2183,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 47, funcId: 46,
port: port_, port: port_,
); );
}, },
@@ -2264,7 +2223,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 48, funcId: 47,
port: port_, port: port_,
); );
}, },
@@ -2304,7 +2263,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 49, funcId: 48,
port: port_, port: port_,
); );
}, },
@@ -2326,10 +2285,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
); );
@override @override
Future<PageDto> crateApiGraphSynapseGraphRemovePageType({ Future<int> crateApiGraphSynapseGraphRemoveTag({
required SynapseGraph that, required SynapseGraph that,
required String pageId, required String name,
required String ty,
}) { }) {
return handler.executeNormal( return handler.executeNormal(
NormalTask( NormalTask(
@@ -2339,30 +2297,29 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
that, that,
serializer, serializer,
); );
sse_encode_String(pageId, serializer); sse_encode_String(name, serializer);
sse_encode_String(ty, serializer);
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 50, funcId: 49,
port: port_, port: port_,
); );
}, },
codec: SseCodec( codec: SseCodec(
decodeSuccessData: sse_decode_page_dto, decodeSuccessData: sse_decode_u_32,
decodeErrorData: sse_decode_AnyhowException, decodeErrorData: sse_decode_AnyhowException,
), ),
constMeta: kCrateApiGraphSynapseGraphRemovePageTypeConstMeta, constMeta: kCrateApiGraphSynapseGraphRemoveTagConstMeta,
argValues: [that, pageId, ty], argValues: [that, name],
apiImpl: this, apiImpl: this,
), ),
); );
} }
TaskConstMeta get kCrateApiGraphSynapseGraphRemovePageTypeConstMeta => TaskConstMeta get kCrateApiGraphSynapseGraphRemoveTagConstMeta =>
const TaskConstMeta( const TaskConstMeta(
debugName: "SynapseGraph_remove_page_type", debugName: "SynapseGraph_remove_tag",
argNames: ["that", "pageId", "ty"], argNames: ["that", "name"],
); );
@override @override
@@ -2384,7 +2341,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
funcId: 51, funcId: 50,
port: port_, port: port_,
); );
}, },
@@ -2405,6 +2362,46 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["that", "id", "newTitle"], argNames: ["that", "id", "newTitle"],
); );
@override
Future<int> crateApiGraphSynapseGraphRenameTag({
required SynapseGraph that,
required String old,
required String new_,
}) {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph(
that,
serializer,
);
sse_encode_String(old, serializer);
sse_encode_String(new_, serializer);
pdeCallFfi(
generalizedFrbRustBinding,
serializer,
funcId: 51,
port: port_,
);
},
codec: SseCodec(
decodeSuccessData: sse_decode_u_32,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiGraphSynapseGraphRenameTagConstMeta,
argValues: [that, old, new_],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiGraphSynapseGraphRenameTagConstMeta =>
const TaskConstMeta(
debugName: "SynapseGraph_rename_tag",
argNames: ["that", "old", "new_"],
);
@override @override
Future<List<BlockHit>> crateApiGraphSynapseGraphSearchBlocks({ Future<List<BlockHit>> crateApiGraphSynapseGraphSearchBlocks({
required SynapseGraph that, required SynapseGraph that,
@@ -2606,10 +2603,10 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
); );
@override @override
Future<PageDto> crateApiGraphSynapseGraphSetPageTypes({ Future<PageDto> crateApiGraphSynapseGraphSetPageType({
required SynapseGraph that, required SynapseGraph that,
required String pageId, required String pageId,
required List<String> types, String? pageType,
}) { }) {
return handler.executeNormal( return handler.executeNormal(
NormalTask( NormalTask(
@@ -2620,7 +2617,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
serializer, serializer,
); );
sse_encode_String(pageId, serializer); sse_encode_String(pageId, serializer);
sse_encode_list_String(types, serializer); sse_encode_opt_String(pageType, serializer);
pdeCallFfi( pdeCallFfi(
generalizedFrbRustBinding, generalizedFrbRustBinding,
serializer, serializer,
@@ -2632,17 +2629,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
decodeSuccessData: sse_decode_page_dto, decodeSuccessData: sse_decode_page_dto,
decodeErrorData: sse_decode_AnyhowException, decodeErrorData: sse_decode_AnyhowException,
), ),
constMeta: kCrateApiGraphSynapseGraphSetPageTypesConstMeta, constMeta: kCrateApiGraphSynapseGraphSetPageTypeConstMeta,
argValues: [that, pageId, types], argValues: [that, pageId, pageType],
apiImpl: this, apiImpl: this,
), ),
); );
} }
TaskConstMeta get kCrateApiGraphSynapseGraphSetPageTypesConstMeta => TaskConstMeta get kCrateApiGraphSynapseGraphSetPageTypeConstMeta =>
const TaskConstMeta( const TaskConstMeta(
debugName: "SynapseGraph_set_page_types", debugName: "SynapseGraph_set_page_type",
argNames: ["that", "pageId", "types"], argNames: ["that", "pageId", "pageType"],
); );
@override @override
@@ -3044,8 +3041,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
GraphNode dco_decode_graph_node(dynamic raw) { GraphNode dco_decode_graph_node(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs // Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>; final arr = raw as List<dynamic>;
if (arr.length != 12) if (arr.length != 13)
throw Exception('unexpected arr length: expect 12 but see ${arr.length}'); throw Exception('unexpected arr length: expect 13 but see ${arr.length}');
return GraphNode( return GraphNode(
id: dco_decode_String(arr[0]), id: dco_decode_String(arr[0]),
title: dco_decode_String(arr[1]), title: dco_decode_String(arr[1]),
@@ -3059,6 +3056,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
isHub: dco_decode_bool(arr[9]), isHub: dco_decode_bool(arr[9]),
homeHub: dco_decode_opt_box_autoadd_u_32(arr[10]), homeHub: dco_decode_opt_box_autoadd_u_32(arr[10]),
tags: dco_decode_list_String(arr[11]), tags: dco_decode_list_String(arr[11]),
isTag: dco_decode_bool(arr[12]),
); );
} }
@@ -3352,8 +3350,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
PageDto dco_decode_page_dto(dynamic raw) { PageDto dco_decode_page_dto(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs // Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>; final arr = raw as List<dynamic>;
if (arr.length != 11) if (arr.length != 10)
throw Exception('unexpected arr length: expect 11 but see ${arr.length}'); throw Exception('unexpected arr length: expect 10 but see ${arr.length}');
return PageDto( return PageDto(
id: dco_decode_String(arr[0]), id: dco_decode_String(arr[0]),
title: dco_decode_String(arr[1]), title: dco_decode_String(arr[1]),
@@ -3364,8 +3362,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
isHub: dco_decode_bool(arr[6]), isHub: dco_decode_bool(arr[6]),
description: dco_decode_String(arr[7]), description: dco_decode_String(arr[7]),
tags: dco_decode_list_String(arr[8]), tags: dco_decode_list_String(arr[8]),
isTag: dco_decode_bool(arr[9]), pageType: dco_decode_opt_String(arr[9]),
types: dco_decode_list_String(arr[10]),
); );
} }
@@ -3746,6 +3743,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
var var_isHub = sse_decode_bool(deserializer); var var_isHub = sse_decode_bool(deserializer);
var var_homeHub = sse_decode_opt_box_autoadd_u_32(deserializer); var var_homeHub = sse_decode_opt_box_autoadd_u_32(deserializer);
var var_tags = sse_decode_list_String(deserializer); var var_tags = sse_decode_list_String(deserializer);
var var_isTag = sse_decode_bool(deserializer);
return GraphNode( return GraphNode(
id: var_id, id: var_id,
title: var_title, title: var_title,
@@ -3759,6 +3757,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
isHub: var_isHub, isHub: var_isHub,
homeHub: var_homeHub, homeHub: var_homeHub,
tags: var_tags, tags: var_tags,
isTag: var_isTag,
); );
} }
@@ -4198,8 +4197,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
var var_isHub = sse_decode_bool(deserializer); var var_isHub = sse_decode_bool(deserializer);
var var_description = sse_decode_String(deserializer); var var_description = sse_decode_String(deserializer);
var var_tags = sse_decode_list_String(deserializer); var var_tags = sse_decode_list_String(deserializer);
var var_isTag = sse_decode_bool(deserializer); var var_pageType = sse_decode_opt_String(deserializer);
var var_types = sse_decode_list_String(deserializer);
return PageDto( return PageDto(
id: var_id, id: var_id,
title: var_title, title: var_title,
@@ -4210,8 +4208,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
isHub: var_isHub, isHub: var_isHub,
description: var_description, description: var_description,
tags: var_tags, tags: var_tags,
isTag: var_isTag, pageType: var_pageType,
types: var_types,
); );
} }
@@ -4551,6 +4548,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_bool(self.isHub, serializer); sse_encode_bool(self.isHub, serializer);
sse_encode_opt_box_autoadd_u_32(self.homeHub, serializer); sse_encode_opt_box_autoadd_u_32(self.homeHub, serializer);
sse_encode_list_String(self.tags, serializer); sse_encode_list_String(self.tags, serializer);
sse_encode_bool(self.isTag, serializer);
} }
@protected @protected
@@ -4960,8 +4958,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_bool(self.isHub, serializer); sse_encode_bool(self.isHub, serializer);
sse_encode_String(self.description, serializer); sse_encode_String(self.description, serializer);
sse_encode_list_String(self.tags, serializer); sse_encode_list_String(self.tags, serializer);
sse_encode_bool(self.isTag, serializer); sse_encode_opt_String(self.pageType, serializer);
sse_encode_list_String(self.types, serializer);
} }
@protected @protected
@@ -5147,13 +5144,6 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
tag: tag, tag: tag,
); );
Future<PageDto> addPageType({required String pageId, required String ty}) =>
RustLib.instance.api.crateApiGraphSynapseGraphAddPageType(
that: this,
pageId: pageId,
ty: ty,
);
/// Puts a page in a hub (no-op when it already is). Fails for journals, non-hub targets, /// Puts a page in a hub (no-op when it already is). Fails for journals, non-hub targets,
/// the hub itself and memberships that would create a cycle. /// the hub itself and memberships that would create a cycle.
Future<void> addToHub({required String pageId, required String hubId}) => Future<void> addToHub({required String pageId, required String hubId}) =>
@@ -5366,7 +5356,7 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
.api .api
.crateApiGraphSynapseGraphPageStructure(that: this, pageId: pageId); .crateApiGraphSynapseGraphPageStructure(that: this, pageId: pageId);
/// Pages carrying a tag, most recently updated first. /// Pages carrying a tag (listed or via their type), most recently updated first.
Future<List<PageBrief>> pagesWithTag({required String tag}) => RustLib Future<List<PageBrief>> pagesWithTag({required String tag}) => RustLib
.instance .instance
.api .api
@@ -5432,14 +5422,10 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
tag: tag, tag: tag,
); );
Future<PageDto> removePageType({ /// Removes the explicit tag from every page (types of that name stay); returns the number
required String pageId, /// of pages changed.
required String ty, Future<int> removeTag({required String name}) => RustLib.instance.api
}) => RustLib.instance.api.crateApiGraphSynapseGraphRemovePageType( .crateApiGraphSynapseGraphRemoveTag(that: this, name: name);
that: this,
pageId: pageId,
ty: ty,
);
Future<PageDto> renamePage({required String id, required String newTitle}) => Future<PageDto> renamePage({required String id, required String newTitle}) =>
RustLib.instance.api.crateApiGraphSynapseGraphRenamePage( RustLib.instance.api.crateApiGraphSynapseGraphRenamePage(
@@ -5448,6 +5434,13 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
newTitle: newTitle, newTitle: newTitle,
); );
/// Renames a tag in the `tags` and `types` of every page carrying it; returns the number of
/// pages changed.
Future<int> renameTag({required String old, required String new_}) => RustLib
.instance
.api
.crateApiGraphSynapseGraphRenameTag(that: this, old: old, new_: new_);
/// Blocks whose text contains `query` (for `((` autocomplete), most recent first. /// Blocks whose text contains `query` (for `((` autocomplete), most recent first.
Future<List<BlockHit>> searchBlocks({ Future<List<BlockHit>> searchBlocks({
required String query, required String query,
@@ -5485,8 +5478,8 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
description: description, description: description,
); );
/// Replaces the tags of a page (each title gets a tag page if it has none). Journals, /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot
/// templates and tag pages cannot be tagged. /// be tagged.
Future<PageDto> setPageTags({ Future<PageDto> setPageTags({
required String pageId, required String pageId,
required List<String> tags, required List<String> tags,
@@ -5496,17 +5489,16 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph {
tags: tags, tags: tags,
); );
/// Replaces the types of a page. Journals and templates cannot be typed. /// Sets (or with `None` clears) the single type of a page. Journals and templates cannot be
Future<PageDto> setPageTypes({ /// typed.
required String pageId, Future<PageDto> setPageType({required String pageId, String? pageType}) =>
required List<String> types, RustLib.instance.api.crateApiGraphSynapseGraphSetPageType(
}) => RustLib.instance.api.crateApiGraphSynapseGraphSetPageTypes( that: this,
that: this, pageId: pageId,
pageId: pageId, pageType: pageType,
types: types, );
);
/// Every tag page with its number of pages, most used first. /// Every tag in use (listed or implied by a type) with its number of pages, most used first.
Future<List<TagDto>> tagCatalog() => Future<List<TagDto>> tagCatalog() =>
RustLib.instance.api.crateApiGraphSynapseGraphTagCatalog(that: this); RustLib.instance.api.crateApiGraphSynapseGraphTagCatalog(that: this);
+13 -11
View File
@@ -18,12 +18,11 @@ pub struct PageDto {
pub is_hub: bool, pub is_hub: bool,
/// Hub description (empty for notes). /// Hub description (empty for notes).
pub description: String, pub description: String,
/// Titles of the tag pages this page is filed under, in the order they were added. /// Tag names (no pages) this page lists, sorted by name; its type implies a tag too.
pub tags: Vec<String>, pub tags: Vec<String>,
/// The page is a tag page (a topic that other pages are filed under). /// The page's single type ("persona", "lugar"...: a name, not a page); it implies a tag of
pub is_tag: bool, /// the same name.
/// Type names ("persona", "lugar"...: plain names, not pages), in the order added. pub page_type: Option<String>,
pub types: Vec<String>,
} }
impl From<&Page> for PageDto { impl From<&Page> for PageDto {
@@ -38,8 +37,7 @@ impl From<&Page> for PageDto {
is_hub: p.is_hub(), is_hub: p.is_hub(),
description: p.description.clone(), description: p.description.clone(),
tags: p.tags.clone(), tags: p.tags.clone(),
is_tag: p.is_tag(), page_type: p.page_type().map(String::from),
types: p.types.clone(),
} }
} }
} }
@@ -210,8 +208,9 @@ pub mod edge_kind {
pub const SYNAPSE: u8 = 6; pub const SYNAPSE: u8 = 6;
/// Hub membership, hub → member (structural, weight 1). /// Hub membership, hub → member (structural, weight 1).
pub const CONTAINS: u8 = 7; pub const CONTAINS: u8 = 7;
/// A page filed under a tag page (page → tag page, weight 1). Unlike `TAG` (an inline /// A page carrying a tag (page → virtual tag node, weight 1; the tag is listed in the
/// `#tag` in the text) it comes from the page's own `tags` list. /// page's `tags` or implied by one of its `types`). Unlike `TAG` (an inline `#tag` in the
/// text, a link to a page) it comes from the page's own names.
pub const TAGGED: u8 = 8; pub const TAGGED: u8 = 8;
} }
@@ -229,14 +228,17 @@ pub struct GraphNode {
pub backlinks: u32, pub backlinks: u32,
/// Community (Louvain), numbered by size: 0 is the largest. /// Community (Louvain), numbered by size: 0 is the largest.
pub cluster: u32, pub cluster: u32,
/// Node index of the tag this page uses most, if any. /// Node index of the tag (page or virtual tag node) this page uses most, if any.
pub primary_tag: Option<u32>, pub primary_tag: Option<u32>,
/// The page is a hub (`PageKind::Hub`). /// The page is a hub (`PageKind::Hub`).
pub is_hub: bool, pub is_hub: bool,
/// Node index of the deepest hub containing this page (a hub: itself). /// Node index of the deepest hub containing this page (a hub: itself).
pub home_hub: Option<u32>, pub home_hub: Option<u32>,
/// Tag names of the page (see `PageDto::tags`), for grouping by tag. /// Tag names of the page, listed or implied by its types, for grouping by tag.
pub tags: Vec<String>, pub tags: Vec<String>,
/// A virtual tag node (not a page, no outline): `id` is `tag:<title_key>`, `title` the
/// display name, `degree` the number of pages carrying the tag.
pub is_tag: bool,
} }
/// The whole page-level graph, edges as parallel arrays (cheap to move across the FFI). /// The whole page-level graph, edges as parallel arrays (cheap to move across the FFI).
+38 -9
View File
@@ -115,6 +115,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
is_hub: false, is_hub: false,
home_hub: None, home_hub: None,
tags, tags,
is_tag: false,
}); });
} }
} }
@@ -227,7 +228,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
} }
} }
tagged(g, &index, &by_key, &mut b)?; tagged(g, &index, &mut nodes, &mut b)?;
// Stable edge order (sources, then targets, then kind). // Stable edge order (sources, then targets, then kind).
let mut edges: Vec<((u32, u32, u8), f32)> = b.edges.into_iter().collect(); let mut edges: Vec<((u32, u32, u8), f32)> = b.edges.into_iter().collect();
@@ -245,7 +246,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
neigh[s as usize].insert(t); neigh[s as usize].insert(t);
neigh[t as usize].insert(s); neigh[t as usize].insert(s);
referrers[t as usize].insert(s); referrers[t as usize].insert(s);
if k == edge_kind::TAG { if k == edge_kind::TAG || k == edge_kind::TAGGED {
*tag_use[s as usize].entry(t).or_default() += w; *tag_use[s as usize].entry(t).or_default() += w;
} }
} }
@@ -283,20 +284,48 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
Ok(out) Ok(out)
} }
/// A page filed under a tag page gets one `TAGGED` edge to it. /// Tags are virtual nodes (`tag:<key>`, appended after the pages): every page carrying a tag,
/// listed or implied by a type, gets one `TAGGED` edge to it.
fn tagged( fn tagged(
g: &Graph, g: &Graph,
index: &HashMap<String, u32>, index: &HashMap<String, u32>,
by_key: &HashMap<String, u32>, nodes: &mut Vec<GraphNode>,
b: &mut Builder, b: &mut Builder,
) -> Result<()> { ) -> Result<()> {
let mut st = g.conn().prepare("SELECT tag_key, page_id FROM page_tags")?; let display: HashMap<String, String> = g
.tag_catalog()?
.into_iter()
.map(|t| (title_key(&t.name), t.name))
.collect();
let mut st = g
.conn()
.prepare("SELECT tag_key, page_id FROM page_tags ORDER BY tag_key, page_id")?;
let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?; let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?;
let mut tag_index: HashMap<String, u32> = HashMap::new();
for row in rows { for row in rows {
let (tag, page) = row?; let (key, page) = row?;
if let (Some(&s), Some(&t)) = (index.get(&page), by_key.get(&tag)) { let Some(&s) = index.get(&page) else {
b.add(s, t, edge_kind::TAGGED, 1.0); continue;
} };
let t = *tag_index.entry(key.clone()).or_insert_with(|| {
nodes.push(GraphNode {
id: format!("tag:{key}"),
title: display.get(&key).cloned().unwrap_or_else(|| key.clone()),
journal_date: None,
origin_journal: None,
created_at: 0,
degree: 0,
backlinks: 0,
cluster: 0,
primary_tag: None,
is_hub: false,
home_hub: None,
tags: Vec::new(),
is_tag: true,
});
nodes.len() as u32 - 1
});
b.add(s, t, edge_kind::TAGGED, 1.0);
} }
Ok(()) Ok(())
} }
+24 -23
View File
@@ -1,13 +1,12 @@
//! Tags (topic pages that notes are filed under) and types (plain names saying what a page //! Tags (names a page is filed under) and the single type (a name saying what a page is). Rules live in `synapse_core::{tags, types}`; this module shapes them for the UI.
//! is). Rules live in `synapse_core::{tags, types}`; this module shapes them for the UI.
use super::dto::{PageBrief, PageDto, TagDto}; use super::dto::{PageBrief, PageDto, TagDto};
use super::graph::{SynapseGraph, parse_id}; use super::graph::{SynapseGraph, parse_id};
use anyhow::Result; use anyhow::Result;
impl SynapseGraph { impl SynapseGraph {
/// Replaces the tags of a page (each title gets a tag page if it has none). Journals, /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot
/// templates and tag pages cannot be tagged. /// be tagged.
pub fn set_page_tags(&self, page_id: String, tags: Vec<String>) -> Result<PageDto> { pub fn set_page_tags(&self, page_id: String, tags: Vec<String>) -> Result<PageDto> {
let g = self.lock(); let g = self.lock();
Ok(PageDto::from(&g.set_page_tags(parse_id(&page_id)?, tags)?)) Ok(PageDto::from(&g.set_page_tags(parse_id(&page_id)?, tags)?))
@@ -25,7 +24,19 @@ impl SynapseGraph {
)) ))
} }
/// Every tag page with its number of pages, most used first. /// Renames a tag in the `tags` and `types` of every page carrying it; returns the number of
/// pages changed.
pub fn rename_tag(&self, old: String, new: String) -> Result<u32> {
Ok(self.lock().rename_tag(&old, &new)? as u32)
}
/// Removes the explicit tag from every page (types of that name stay); returns the number
/// of pages changed.
pub fn remove_tag(&self, name: String) -> Result<u32> {
Ok(self.lock().remove_tag(&name)? as u32)
}
/// Every tag in use (listed or implied by a type) with its number of pages, most used first.
pub fn tag_catalog(&self) -> Result<Vec<TagDto>> { pub fn tag_catalog(&self) -> Result<Vec<TagDto>> {
Ok(self Ok(self
.lock() .lock()
@@ -39,7 +50,7 @@ impl SynapseGraph {
.collect()) .collect())
} }
/// Pages carrying a tag, most recently updated first. /// Pages carrying a tag (listed or via their type), most recently updated first.
pub fn pages_with_tag(&self, tag: String) -> Result<Vec<PageBrief>> { pub fn pages_with_tag(&self, tag: String) -> Result<Vec<PageBrief>> {
let g = self.lock(); let g = self.lock();
let mut out = Vec::new(); let mut out = Vec::new();
@@ -51,24 +62,14 @@ impl SynapseGraph {
Ok(out) Ok(out)
} }
/// Replaces the types of a page. Journals and templates cannot be typed. /// Sets (or with `None` clears) the single type of a page. Journals and templates cannot be
pub fn set_page_types(&self, page_id: String, types: Vec<String>) -> Result<PageDto> { /// typed.
pub fn set_page_type(&self, page_id: String, page_type: Option<String>) -> Result<PageDto> {
let g = self.lock(); let g = self.lock();
Ok(PageDto::from( Ok(PageDto::from(&g.set_page_type(
&g.set_page_types(parse_id(&page_id)?, types)?, parse_id(&page_id)?,
)) page_type.as_deref(),
} )?))
pub fn add_page_type(&self, page_id: String, ty: String) -> Result<PageDto> {
let g = self.lock();
Ok(PageDto::from(&g.add_page_type(parse_id(&page_id)?, &ty)?))
}
pub fn remove_page_type(&self, page_id: String, ty: String) -> Result<PageDto> {
let g = self.lock();
Ok(PageDto::from(
&g.remove_page_type(parse_id(&page_id)?, &ty)?,
))
} }
/// Types in use (most used first) followed by the seeded suggestions not used yet. /// Types in use (most used first) followed by the seeded suggestions not used yet.
+125 -133
View File
@@ -41,7 +41,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
default_rust_auto_opaque = RustAutoOpaqueMoi, default_rust_auto_opaque = RustAutoOpaqueMoi,
); );
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.13.0"; pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.13.0";
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 465538383; pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -1472342481;
// Section: executor // Section: executor
@@ -419,63 +419,6 @@ fn wire__crate__api__graph__SynapseGraph_add_page_tag_impl(
}, },
) )
} }
fn wire__crate__api__graph__SynapseGraph_add_page_type_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
data_len_: i32,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "SynapseGraph_add_page_type",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let message = unsafe {
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
ptr_,
rust_vec_len_,
data_len_,
)
};
let mut deserializer =
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
let api_that = <RustOpaqueMoi<
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
>>::sse_decode(&mut deserializer);
let api_page_id = <String>::sse_decode(&mut deserializer);
let api_ty = <String>::sse_decode(&mut deserializer);
deserializer.end();
move |context| {
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
(move || {
let mut api_that_guard = None;
let decode_indices_ =
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
&api_that, 0, false,
)],
);
for i in decode_indices_ {
match i {
0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()),
_ => unreachable!(),
}
}
let api_that_guard = api_that_guard.unwrap();
let output_ok = crate::api::graph::SynapseGraph::add_page_type(
&*api_that_guard,
api_page_id,
api_ty,
)?;
std::result::Result::Ok(output_ok)
})(),
)
}
},
)
}
fn wire__crate__api__graph__SynapseGraph_add_to_hub_impl( fn wire__crate__api__graph__SynapseGraph_add_to_hub_impl(
port_: flutter_rust_bridge::for_generated::MessagePort, port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
@@ -2724,7 +2667,7 @@ fn wire__crate__api__graph__SynapseGraph_remove_page_tag_impl(
}, },
) )
} }
fn wire__crate__api__graph__SynapseGraph_remove_page_type_impl( fn wire__crate__api__graph__SynapseGraph_remove_tag_impl(
port_: flutter_rust_bridge::for_generated::MessagePort, port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32, rust_vec_len_: i32,
@@ -2732,7 +2675,7 @@ fn wire__crate__api__graph__SynapseGraph_remove_page_type_impl(
) { ) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>( FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo { flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "SynapseGraph_remove_page_type", debug_name: "SynapseGraph_remove_tag",
port: Some(port_), port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
}, },
@@ -2749,8 +2692,7 @@ fn wire__crate__api__graph__SynapseGraph_remove_page_type_impl(
let api_that = <RustOpaqueMoi< let api_that = <RustOpaqueMoi<
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>, flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
>>::sse_decode(&mut deserializer); >>::sse_decode(&mut deserializer);
let api_page_id = <String>::sse_decode(&mut deserializer); let api_name = <String>::sse_decode(&mut deserializer);
let api_ty = <String>::sse_decode(&mut deserializer);
deserializer.end(); deserializer.end();
move |context| { move |context| {
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>( transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
@@ -2769,10 +2711,9 @@ fn wire__crate__api__graph__SynapseGraph_remove_page_type_impl(
} }
} }
let api_that_guard = api_that_guard.unwrap(); let api_that_guard = api_that_guard.unwrap();
let output_ok = crate::api::graph::SynapseGraph::remove_page_type( let output_ok = crate::api::graph::SynapseGraph::remove_tag(
&*api_that_guard, &*api_that_guard,
api_page_id, api_name,
api_ty,
)?; )?;
std::result::Result::Ok(output_ok) std::result::Result::Ok(output_ok)
})(), })(),
@@ -2838,6 +2779,63 @@ fn wire__crate__api__graph__SynapseGraph_rename_page_impl(
}, },
) )
} }
fn wire__crate__api__graph__SynapseGraph_rename_tag_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
data_len_: i32,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "SynapseGraph_rename_tag",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let message = unsafe {
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
ptr_,
rust_vec_len_,
data_len_,
)
};
let mut deserializer =
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
let api_that = <RustOpaqueMoi<
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
>>::sse_decode(&mut deserializer);
let api_old = <String>::sse_decode(&mut deserializer);
let api_new = <String>::sse_decode(&mut deserializer);
deserializer.end();
move |context| {
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
(move || {
let mut api_that_guard = None;
let decode_indices_ =
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
&api_that, 0, false,
)],
);
for i in decode_indices_ {
match i {
0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()),
_ => unreachable!(),
}
}
let api_that_guard = api_that_guard.unwrap();
let output_ok = crate::api::graph::SynapseGraph::rename_tag(
&*api_that_guard,
api_old,
api_new,
)?;
std::result::Result::Ok(output_ok)
})(),
)
}
},
)
}
fn wire__crate__api__graph__SynapseGraph_search_blocks_impl( fn wire__crate__api__graph__SynapseGraph_search_blocks_impl(
port_: flutter_rust_bridge::for_generated::MessagePort, port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
@@ -3123,7 +3121,7 @@ fn wire__crate__api__graph__SynapseGraph_set_page_tags_impl(
}, },
) )
} }
fn wire__crate__api__graph__SynapseGraph_set_page_types_impl( fn wire__crate__api__graph__SynapseGraph_set_page_type_impl(
port_: flutter_rust_bridge::for_generated::MessagePort, port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32, rust_vec_len_: i32,
@@ -3131,7 +3129,7 @@ fn wire__crate__api__graph__SynapseGraph_set_page_types_impl(
) { ) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>( FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo { flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "SynapseGraph_set_page_types", debug_name: "SynapseGraph_set_page_type",
port: Some(port_), port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
}, },
@@ -3149,7 +3147,7 @@ fn wire__crate__api__graph__SynapseGraph_set_page_types_impl(
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>, flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
>>::sse_decode(&mut deserializer); >>::sse_decode(&mut deserializer);
let api_page_id = <String>::sse_decode(&mut deserializer); let api_page_id = <String>::sse_decode(&mut deserializer);
let api_types = <Vec<String>>::sse_decode(&mut deserializer); let api_page_type = <Option<String>>::sse_decode(&mut deserializer);
deserializer.end(); deserializer.end();
move |context| { move |context| {
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>( transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
@@ -3168,10 +3166,10 @@ fn wire__crate__api__graph__SynapseGraph_set_page_types_impl(
} }
} }
let api_that_guard = api_that_guard.unwrap(); let api_that_guard = api_that_guard.unwrap();
let output_ok = crate::api::graph::SynapseGraph::set_page_types( let output_ok = crate::api::graph::SynapseGraph::set_page_type(
&*api_that_guard, &*api_that_guard,
api_page_id, api_page_id,
api_types, api_page_type,
)?; )?;
std::result::Result::Ok(output_ok) std::result::Result::Ok(output_ok)
})(), })(),
@@ -3656,6 +3654,7 @@ impl SseDecode for crate::api::dto::GraphNode {
let mut var_isHub = <bool>::sse_decode(deserializer); let mut var_isHub = <bool>::sse_decode(deserializer);
let mut var_homeHub = <Option<u32>>::sse_decode(deserializer); let mut var_homeHub = <Option<u32>>::sse_decode(deserializer);
let mut var_tags = <Vec<String>>::sse_decode(deserializer); let mut var_tags = <Vec<String>>::sse_decode(deserializer);
let mut var_isTag = <bool>::sse_decode(deserializer);
return crate::api::dto::GraphNode { return crate::api::dto::GraphNode {
id: var_id, id: var_id,
title: var_title, title: var_title,
@@ -3669,6 +3668,7 @@ impl SseDecode for crate::api::dto::GraphNode {
is_hub: var_isHub, is_hub: var_isHub,
home_hub: var_homeHub, home_hub: var_homeHub,
tags: var_tags, tags: var_tags,
is_tag: var_isTag,
}; };
} }
} }
@@ -4110,8 +4110,7 @@ impl SseDecode for crate::api::dto::PageDto {
let mut var_isHub = <bool>::sse_decode(deserializer); let mut var_isHub = <bool>::sse_decode(deserializer);
let mut var_description = <String>::sse_decode(deserializer); let mut var_description = <String>::sse_decode(deserializer);
let mut var_tags = <Vec<String>>::sse_decode(deserializer); let mut var_tags = <Vec<String>>::sse_decode(deserializer);
let mut var_isTag = <bool>::sse_decode(deserializer); let mut var_pageType = <Option<String>>::sse_decode(deserializer);
let mut var_types = <Vec<String>>::sse_decode(deserializer);
return crate::api::dto::PageDto { return crate::api::dto::PageDto {
id: var_id, id: var_id,
title: var_title, title: var_title,
@@ -4122,8 +4121,7 @@ impl SseDecode for crate::api::dto::PageDto {
is_hub: var_isHub, is_hub: var_isHub,
description: var_description, description: var_description,
tags: var_tags, tags: var_tags,
is_tag: var_isTag, page_type: var_pageType,
types: var_types,
}; };
} }
} }
@@ -4306,196 +4304,190 @@ fn pde_ffi_dispatcher_primary_impl(
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
8 => wire__crate__api__graph__SynapseGraph_add_page_type_impl( 8 => {
port,
ptr,
rust_vec_len,
data_len,
),
9 => {
wire__crate__api__graph__SynapseGraph_add_to_hub_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_add_to_hub_impl(port, ptr, rust_vec_len, data_len)
} }
10 => wire__crate__api__graph__SynapseGraph_aliases_impl(port, ptr, rust_vec_len, data_len), 9 => wire__crate__api__graph__SynapseGraph_aliases_impl(port, ptr, rust_vec_len, data_len),
12 => { 11 => {
wire__crate__api__graph__SynapseGraph_backlinks_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_backlinks_impl(port, ptr, rust_vec_len, data_len)
} }
13 => { 12 => {
wire__crate__api__graph__SynapseGraph_block_ref_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_block_ref_impl(port, ptr, rust_vec_len, data_len)
} }
14 => wire__crate__api__graph__SynapseGraph_convert_to_hub_impl( 13 => wire__crate__api__graph__SynapseGraph_convert_to_hub_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
15 => wire__crate__api__graph__SynapseGraph_convert_to_note_impl( 14 => wire__crate__api__graph__SynapseGraph_convert_to_note_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
16 => { 15 => {
wire__crate__api__graph__SynapseGraph_create_hub_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_create_hub_impl(port, ptr, rust_vec_len, data_len)
} }
17 => wire__crate__api__graph__SynapseGraph_create_page_from_template_impl( 16 => wire__crate__api__graph__SynapseGraph_create_page_from_template_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
18 => wire__crate__api__graph__SynapseGraph_delete_block_impl( 17 => wire__crate__api__graph__SynapseGraph_delete_block_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
19 => wire__crate__api__graph__SynapseGraph_delete_page_impl( 18 => wire__crate__api__graph__SynapseGraph_delete_page_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
21 => { 20 => {
wire__crate__api__graph__SynapseGraph_graph_data_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_graph_data_impl(port, ptr, rust_vec_len, data_len)
} }
22 => wire__crate__api__graph__SynapseGraph_hub_conversion_preview_impl( 21 => wire__crate__api__graph__SynapseGraph_hub_conversion_preview_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
23 => wire__crate__api__graph__SynapseGraph_hub_template_impl( 22 => wire__crate__api__graph__SynapseGraph_hub_template_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
24 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len), 23 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len),
25 => wire__crate__api__graph__SynapseGraph_indent_block_impl( 24 => wire__crate__api__graph__SynapseGraph_indent_block_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
26 => wire__crate__api__graph__SynapseGraph_insert_block_impl( 25 => wire__crate__api__graph__SynapseGraph_insert_block_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
27 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len), 26 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len),
28 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl( 27 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
29 => { 28 => {
wire__crate__api__graph__SynapseGraph_journals_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_journals_impl(port, ptr, rust_vec_len, data_len)
} }
30 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl( 29 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
31 => { 30 => {
wire__crate__api__graph__SynapseGraph_list_pages_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_list_pages_impl(port, ptr, rust_vec_len, data_len)
} }
32 => wire__crate__api__graph__SynapseGraph_merge_block_impl( 31 => wire__crate__api__graph__SynapseGraph_merge_block_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
33 => { 32 => {
wire__crate__api__graph__SynapseGraph_move_block_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_move_block_impl(port, ptr, rust_vec_len, data_len)
} }
34 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), 33 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len),
35 => { 34 => {
wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len) wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len)
} }
36 => wire__crate__api__graph__SynapseGraph_outdent_block_impl( 35 => wire__crate__api__graph__SynapseGraph_outdent_block_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
37 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len), 36 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len),
38 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len), 37 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len),
39 => wire__crate__api__graph__SynapseGraph_page_by_title_impl( 38 => wire__crate__api__graph__SynapseGraph_page_by_title_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
40 => wire__crate__api__graph__SynapseGraph_page_structure_impl( 39 => wire__crate__api__graph__SynapseGraph_page_structure_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
41 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( 40 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
42 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( 41 => wire__crate__api__graph__SynapseGraph_purge_pages_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
43 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( 42 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
44 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( 43 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
45 => wire__crate__api__graph__SynapseGraph_record_visit_impl( 44 => wire__crate__api__graph__SynapseGraph_record_visit_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
46 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), 45 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len),
47 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( 46 => wire__crate__api__graph__SynapseGraph_remove_alias_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
48 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( 47 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
49 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( 48 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
50 => wire__crate__api__graph__SynapseGraph_remove_page_type_impl( 49 => {
port, wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len)
ptr, }
rust_vec_len, 50 => wire__crate__api__graph__SynapseGraph_rename_page_impl(
data_len,
),
51 => wire__crate__api__graph__SynapseGraph_rename_page_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
51 => {
wire__crate__api__graph__SynapseGraph_rename_tag_impl(port, ptr, rust_vec_len, data_len)
}
52 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( 52 => wire__crate__api__graph__SynapseGraph_search_blocks_impl(
port, port,
ptr, ptr,
@@ -4526,7 +4518,7 @@ fn pde_ffi_dispatcher_primary_impl(
rust_vec_len, rust_vec_len,
data_len, data_len,
), ),
57 => wire__crate__api__graph__SynapseGraph_set_page_types_impl( 57 => wire__crate__api__graph__SynapseGraph_set_page_type_impl(
port, port,
ptr, ptr,
rust_vec_len, rust_vec_len,
@@ -4566,8 +4558,8 @@ fn pde_ffi_dispatcher_sync_impl(
// Codec=Pde (Serialization + dispatch), see doc to use other codecs // Codec=Pde (Serialization + dispatch), see doc to use other codecs
match func_id { match func_id {
1 => wire__crate__api__layout__ForceLayout_new_impl(ptr, rust_vec_len, data_len), 1 => wire__crate__api__layout__ForceLayout_new_impl(ptr, rust_vec_len, data_len),
11 => wire__crate__api__graph__SynapseGraph_asset_path_impl(ptr, rust_vec_len, data_len), 10 => wire__crate__api__graph__SynapseGraph_asset_path_impl(ptr, rust_vec_len, data_len),
20 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len), 19 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len),
60 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len), 60 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len),
_ => unreachable!(), _ => unreachable!(),
} }
@@ -4755,6 +4747,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::GraphNode {
self.is_hub.into_into_dart().into_dart(), self.is_hub.into_into_dart().into_dart(),
self.home_hub.into_into_dart().into_dart(), self.home_hub.into_into_dart().into_dart(),
self.tags.into_into_dart().into_dart(), self.tags.into_into_dart().into_dart(),
self.is_tag.into_into_dart().into_dart(),
] ]
.into_dart() .into_dart()
} }
@@ -4939,8 +4932,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::PageDto {
self.is_hub.into_into_dart().into_dart(), self.is_hub.into_into_dart().into_dart(),
self.description.into_into_dart().into_dart(), self.description.into_into_dart().into_dart(),
self.tags.into_into_dart().into_dart(), self.tags.into_into_dart().into_dart(),
self.is_tag.into_into_dart().into_dart(), self.page_type.into_into_dart().into_dart(),
self.types.into_into_dart().into_dart(),
] ]
.into_dart() .into_dart()
} }
@@ -5254,6 +5246,7 @@ impl SseEncode for crate::api::dto::GraphNode {
<bool>::sse_encode(self.is_hub, serializer); <bool>::sse_encode(self.is_hub, serializer);
<Option<u32>>::sse_encode(self.home_hub, serializer); <Option<u32>>::sse_encode(self.home_hub, serializer);
<Vec<String>>::sse_encode(self.tags, serializer); <Vec<String>>::sse_encode(self.tags, serializer);
<bool>::sse_encode(self.is_tag, serializer);
} }
} }
@@ -5603,8 +5596,7 @@ impl SseEncode for crate::api::dto::PageDto {
<bool>::sse_encode(self.is_hub, serializer); <bool>::sse_encode(self.is_hub, serializer);
<String>::sse_encode(self.description, serializer); <String>::sse_encode(self.description, serializer);
<Vec<String>>::sse_encode(self.tags, serializer); <Vec<String>>::sse_encode(self.tags, serializer);
<bool>::sse_encode(self.is_tag, serializer); <Option<String>>::sse_encode(self.page_type, serializer);
<Vec<String>>::sse_encode(self.types, serializer);
} }
} }
+31 -20
View File
@@ -399,7 +399,7 @@ fn legacy_candidates_and_purge() {
} }
#[test] #[test]
fn tags_are_pages_and_their_own_edge_kind() { fn tags_are_virtual_graph_nodes_with_their_own_edge_kind() {
let (_d, g) = open(); let (_d, g) = open();
let (a, _) = page_with(&g, "Rust", &["x"]); let (a, _) = page_with(&g, "Rust", &["x"]);
let (b, _) = page_with(&g, "Go", &["y"]); let (b, _) = page_with(&g, "Go", &["y"]);
@@ -407,13 +407,13 @@ fn tags_are_pages_and_their_own_edge_kind() {
for (p, tags) in [ for (p, tags) in [
(&a, vec!["tecnología", "idea"]), (&a, vec!["tecnología", "idea"]),
(&b, vec!["Tecnología", "idea"]), (&b, vec!["Tecnología", "idea"]),
(&c, vec!["lugar"]),
] { ] {
g.set_page_tags(p.clone(), tags.into_iter().map(String::from).collect()) g.set_page_tags(p.clone(), tags.into_iter().map(String::from).collect())
.unwrap(); .unwrap();
} }
g.set_page_type(c.clone(), Some("lugar".into())).unwrap();
g.set_page_type(b.clone(), Some("Idea".into())).unwrap();
let data = g.graph_data().unwrap(); let data = g.graph_data().unwrap();
let idx = |id: &str| data.nodes.iter().position(|n| n.id == id).unwrap() as u32;
let title = |i: u32| data.nodes[i as usize].title.clone(); let title = |i: u32| data.nodes[i as usize].title.clone();
let mut tagged: Vec<(String, String)> = (0..data.kinds.len()) let mut tagged: Vec<(String, String)> = (0..data.kinds.len())
.filter(|&e| data.kinds[e] == edge_kind::TAGGED) .filter(|&e| data.kinds[e] == edge_kind::TAGGED)
@@ -430,35 +430,46 @@ fn tags_are_pages_and_their_own_edge_kind() {
pair("Rust", "idea"), pair("Rust", "idea"),
pair("Rust", "tecnología"), pair("Rust", "tecnología"),
], ],
"each page points at its tag pages" "each page points at its tags, including the one its type implies, once"
); );
// The tag page is a real node that counts backlinks, and the DTOs flag it. // Tags are virtual: no page behind them, flagged, with the page count as degree.
let tp = &data.nodes[data let tag = data
.nodes .nodes
.iter() .iter()
.position(|n| n.title == "tecnología") .find(|n| n.is_tag && n.title == "tecnología");
.unwrap()]; let tag = tag.expect("tag node");
assert_eq!(tp.backlinks, 2); assert_eq!(tag.id, "tag:tecnología");
assert!(g.page(tp.id.clone()).unwrap().unwrap().page.is_tag); assert_eq!((tag.degree, tag.journal_date.clone()), (2, None));
assert!(g.page(tag.id.clone()).is_err() || g.page(tag.id.clone()).unwrap().is_none());
assert_eq!(data.nodes.iter().filter(|n| n.is_tag).count(), 3);
let go = data.nodes.iter().find(|n| n.title == "Go").unwrap();
assert_eq!( assert_eq!(
idx(&a), go.tags,
data.nodes.iter().position(|n| n.id == a).unwrap() as u32 ["idea", "Tecnología"],
"tags, with the type's tag once"
); );
let cat = g.tag_catalog().unwrap(); let cat = g.tag_catalog().unwrap();
assert_eq!((cat[0].name.as_str(), cat[0].count), ("idea", 2)); assert_eq!((cat[0].name.as_str(), cat[0].count), ("idea", 2));
assert_eq!(g.pages_with_tag("IDEA".into()).unwrap().len(), 2);
} }
#[test] #[test]
fn types_round_trip_through_the_api() { fn page_type_and_tag_renaming_round_trip_through_the_api() {
let (_d, g) = open(); let (_d, g) = open();
let (a, _) = page_with(&g, "Ana", &["x"]); let (a, _) = page_with(&g, "Ana", &["x"]);
let p = g.add_page_type(a.clone(), "persona".into()).unwrap(); let p = g.set_page_type(a.clone(), Some("persona".into())).unwrap();
assert_eq!(p.types, ["persona"]); assert_eq!(p.page_type.as_deref(), Some("persona"));
let p = g.set_page_type(a.clone(), Some("lugar".into())).unwrap();
assert_eq!(p.page_type.as_deref(), Some("lugar"));
assert!(g.type_catalog().unwrap().iter().any(|t| t.name == "lugar")); assert!(g.type_catalog().unwrap().iter().any(|t| t.name == "lugar"));
assert!( g.add_page_tag(a.clone(), "web".into()).unwrap();
g.remove_page_type(a, "PERSONA".into()) assert_eq!(g.rename_tag("lugar".into(), "sitio".into()).unwrap(), 1);
.unwrap() assert_eq!(g.rename_tag("web".into(), "red".into()).unwrap(), 1);
.types let p = g.page(a.clone()).unwrap().unwrap().page;
.is_empty() assert_eq!(
(p.page_type.as_deref(), p.tags),
(Some("sitio"), vec!["red".to_string()])
); );
assert_eq!(g.remove_tag("red".into()).unwrap(), 1);
assert!(g.set_page_type(a, None).unwrap().page_type.is_none());
} }