diff --git a/app/lib/src/rust/api/dto.dart b/app/lib/src/rust/api/dto.dart index 621f01e..b081b3d 100644 --- a/app/lib/src/rust/api/dto.dart +++ b/app/lib/src/rust/api/dto.dart @@ -246,7 +246,7 @@ class GraphNode { /// Community (Louvain), numbered by size: 0 is the largest. 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; /// 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). 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 tags; + /// A virtual tag node (not a page, no outline): `id` is `tag:`, `title` the + /// display name, `degree` the number of pages carrying the tag. + final bool isTag; + const GraphNode({ required this.id, required this.title, @@ -271,6 +275,7 @@ class GraphNode { required this.isHub, this.homeHub, required this.tags, + required this.isTag, }); @override @@ -286,7 +291,8 @@ class GraphNode { primaryTag.hashCode ^ isHub.hashCode ^ homeHub.hashCode ^ - tags.hashCode; + tags.hashCode ^ + isTag.hashCode; @override bool operator ==(Object other) => @@ -304,7 +310,8 @@ class GraphNode { primaryTag == other.primaryTag && isHub == other.isHub && homeHub == other.homeHub && - tags == other.tags; + tags == other.tags && + isTag == other.isTag; } /// A hub (folder-like page) with its members. @@ -586,14 +593,12 @@ class PageDto { /// Hub description (empty for notes). 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 tags; - /// The page is a tag page (a topic that other pages are filed under). - final bool isTag; - - /// Type names ("persona", "lugar"...: plain names, not pages), in the order added. - final List types; + /// The page's single type ("persona", "lugar"...: a name, not a page); it implies a tag of + /// the same name. + final String? pageType; const PageDto({ required this.id, @@ -605,8 +610,7 @@ class PageDto { required this.isHub, required this.description, required this.tags, - required this.isTag, - required this.types, + this.pageType, }); @override @@ -620,8 +624,7 @@ class PageDto { isHub.hashCode ^ description.hashCode ^ tags.hashCode ^ - isTag.hashCode ^ - types.hashCode; + pageType.hashCode; @override bool operator ==(Object other) => @@ -637,8 +640,7 @@ class PageDto { isHub == other.isHub && description == other.description && tags == other.tags && - isTag == other.isTag && - types == other.types; + pageType == other.pageType; } /// Hub and namespace context of one page. diff --git a/app/lib/src/rust/api/graph.dart b/app/lib/src/rust/api/graph.dart index f509557..3494b46 100644 --- a/app/lib/src/rust/api/graph.dart +++ b/app/lib/src/rust/api/graph.dart @@ -17,8 +17,6 @@ abstract class SynapseGraph implements RustOpaqueInterface { Future addPageTag({required String pageId, required String tag}); - Future 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, /// the hub itself and memberships that would create a cycle. Future addToHub({required String pageId, required String hubId}); @@ -148,7 +146,7 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// Hub and namespace context of a page. Future 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> pagesWithTag({required String tag}); /// Deletes pages and their blocks in one transaction. Returns how many existed. @@ -180,10 +178,16 @@ abstract class SynapseGraph implements RustOpaqueInterface { Future removePageTag({required String pageId, required String tag}); - Future 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 removeTag({required String name}); Future 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 renameTag({required String old, required String new_}); + /// Blocks whose text contains `query` (for `((` autocomplete), most recent first. Future> searchBlocks({ required String query, @@ -204,20 +208,18 @@ abstract class SynapseGraph implements RustOpaqueInterface { required String description, }); - /// Replaces the tags of a page (each title gets a tag page if it has none). Journals, - /// templates and tag pages cannot be tagged. + /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot + /// be tagged. Future setPageTags({ required String pageId, required List tags, }); - /// Replaces the types of a page. Journals and templates cannot be typed. - Future setPageTypes({ - required String pageId, - required List types, - }); + /// Sets (or with `None` clears) the single type of a page. Journals and templates cannot be + /// typed. + Future setPageType({required String pageId, String? pageType}); - /// 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> tagCatalog(); /// Timeline data for `[from, to]` (oldest first) with titles of every page it mentions. diff --git a/app/lib/src/rust/frb_generated.dart b/app/lib/src/rust/frb_generated.dart index cd045f5..218ef9e 100644 --- a/app/lib/src/rust/frb_generated.dart +++ b/app/lib/src/rust/frb_generated.dart @@ -69,7 +69,7 @@ class RustLib extends BaseEntrypoint { String get codegenVersion => '2.13.0'; @override - int get rustContentHash => 465538383; + int get rustContentHash => -1472342481; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -123,12 +123,6 @@ abstract class RustLibApi extends BaseApi { required String tag, }); - Future crateApiGraphSynapseGraphAddPageType({ - required SynapseGraph that, - required String pageId, - required String ty, - }); - Future crateApiGraphSynapseGraphAddToHub({ required SynapseGraph that, required String pageId, @@ -345,10 +339,9 @@ abstract class RustLibApi extends BaseApi { required String tag, }); - Future crateApiGraphSynapseGraphRemovePageType({ + Future crateApiGraphSynapseGraphRemoveTag({ required SynapseGraph that, - required String pageId, - required String ty, + required String name, }); Future crateApiGraphSynapseGraphRenamePage({ @@ -357,6 +350,12 @@ abstract class RustLibApi extends BaseApi { required String newTitle, }); + Future crateApiGraphSynapseGraphRenameTag({ + required SynapseGraph that, + required String old, + required String new_, + }); + Future> crateApiGraphSynapseGraphSearchBlocks({ required SynapseGraph that, required String query, @@ -387,10 +386,10 @@ abstract class RustLibApi extends BaseApi { required List tags, }); - Future crateApiGraphSynapseGraphSetPageTypes({ + Future crateApiGraphSynapseGraphSetPageType({ required SynapseGraph that, required String pageId, - required List types, + String? pageType, }); Future> crateApiGraphSynapseGraphTagCatalog({ @@ -713,46 +712,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "pageId", "tag"], ); - @override - Future 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 Future crateApiGraphSynapseGraphAddToHub({ required SynapseGraph that, @@ -772,7 +731,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 9, + funcId: 8, port: port_, ); }, @@ -810,7 +769,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 10, + funcId: 9, port: port_, ); }, @@ -845,7 +804,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { serializer, ); sse_encode_String(hash, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 11)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 10)!; }, codec: SseCodec( decodeSuccessData: sse_decode_opt_String, @@ -881,7 +840,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 12, + funcId: 11, port: port_, ); }, @@ -919,7 +878,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 13, + funcId: 12, port: port_, ); }, @@ -965,7 +924,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 14, + funcId: 13, port: port_, ); }, @@ -1010,7 +969,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 15, + funcId: 14, port: port_, ); }, @@ -1050,7 +1009,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 16, + funcId: 15, port: port_, ); }, @@ -1090,7 +1049,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 17, + funcId: 16, port: port_, ); }, @@ -1128,7 +1087,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 18, + funcId: 17, port: port_, ); }, @@ -1166,7 +1125,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 19, + funcId: 18, port: port_, ); }, @@ -1197,7 +1156,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { that, serializer, ); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 20)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 19)!; }, codec: SseCodec( decodeSuccessData: sse_decode_String, @@ -1228,7 +1187,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 21, + funcId: 20, port: port_, ); }, @@ -1266,7 +1225,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 22, + funcId: 21, port: port_, ); }, @@ -1304,7 +1263,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 23, + funcId: 22, port: port_, ); }, @@ -1338,7 +1297,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 24, + funcId: 23, port: port_, ); }, @@ -1373,7 +1332,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 25, + funcId: 24, port: port_, ); }, @@ -1415,7 +1374,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 26, + funcId: 25, port: port_, ); }, @@ -1453,7 +1412,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 27, + funcId: 26, port: port_, ); }, @@ -1491,7 +1450,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 28, + funcId: 27, port: port_, ); }, @@ -1531,7 +1490,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 29, + funcId: 28, port: port_, ); }, @@ -1567,7 +1526,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 30, + funcId: 29, port: port_, ); }, @@ -1609,7 +1568,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 31, + funcId: 30, port: port_, ); }, @@ -1649,7 +1608,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 32, + funcId: 31, port: port_, ); }, @@ -1691,7 +1650,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 33, + funcId: 32, port: port_, ); }, @@ -1722,7 +1681,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 34, + funcId: 33, port: port_, ); }, @@ -1758,7 +1717,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 35, + funcId: 34, port: port_, ); }, @@ -1796,7 +1755,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 36, + funcId: 35, port: port_, ); }, @@ -1834,7 +1793,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 37, + funcId: 36, port: port_, ); }, @@ -1872,7 +1831,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 38, + funcId: 37, port: port_, ); }, @@ -1910,7 +1869,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 39, + funcId: 38, port: port_, ); }, @@ -1948,7 +1907,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 40, + funcId: 39, port: port_, ); }, @@ -1986,7 +1945,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 41, + funcId: 40, port: port_, ); }, @@ -2024,7 +1983,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 42, + funcId: 41, port: port_, ); }, @@ -2066,7 +2025,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 43, + funcId: 42, port: port_, ); }, @@ -2106,7 +2065,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 44, + funcId: 43, port: port_, ); }, @@ -2146,7 +2105,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 45, + funcId: 44, port: port_, ); }, @@ -2186,7 +2145,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 46, + funcId: 45, port: port_, ); }, @@ -2224,7 +2183,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 47, + funcId: 46, port: port_, ); }, @@ -2264,7 +2223,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 48, + funcId: 47, port: port_, ); }, @@ -2304,7 +2263,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 49, + funcId: 48, port: port_, ); }, @@ -2326,10 +2285,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); @override - Future crateApiGraphSynapseGraphRemovePageType({ + Future crateApiGraphSynapseGraphRemoveTag({ required SynapseGraph that, - required String pageId, - required String ty, + required String name, }) { return handler.executeNormal( NormalTask( @@ -2339,30 +2297,29 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { that, serializer, ); - sse_encode_String(pageId, serializer); - sse_encode_String(ty, serializer); + sse_encode_String(name, serializer); pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 50, + funcId: 49, port: port_, ); }, codec: SseCodec( - decodeSuccessData: sse_decode_page_dto, + decodeSuccessData: sse_decode_u_32, decodeErrorData: sse_decode_AnyhowException, ), - constMeta: kCrateApiGraphSynapseGraphRemovePageTypeConstMeta, - argValues: [that, pageId, ty], + constMeta: kCrateApiGraphSynapseGraphRemoveTagConstMeta, + argValues: [that, name], apiImpl: this, ), ); } - TaskConstMeta get kCrateApiGraphSynapseGraphRemovePageTypeConstMeta => + TaskConstMeta get kCrateApiGraphSynapseGraphRemoveTagConstMeta => const TaskConstMeta( - debugName: "SynapseGraph_remove_page_type", - argNames: ["that", "pageId", "ty"], + debugName: "SynapseGraph_remove_tag", + argNames: ["that", "name"], ); @override @@ -2384,7 +2341,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 51, + funcId: 50, port: port_, ); }, @@ -2405,6 +2362,46 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "id", "newTitle"], ); + @override + Future 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 Future> crateApiGraphSynapseGraphSearchBlocks({ required SynapseGraph that, @@ -2606,10 +2603,10 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { ); @override - Future crateApiGraphSynapseGraphSetPageTypes({ + Future crateApiGraphSynapseGraphSetPageType({ required SynapseGraph that, required String pageId, - required List types, + String? pageType, }) { return handler.executeNormal( NormalTask( @@ -2620,7 +2617,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { serializer, ); sse_encode_String(pageId, serializer); - sse_encode_list_String(types, serializer); + sse_encode_opt_String(pageType, serializer); pdeCallFfi( generalizedFrbRustBinding, serializer, @@ -2632,17 +2629,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { decodeSuccessData: sse_decode_page_dto, decodeErrorData: sse_decode_AnyhowException, ), - constMeta: kCrateApiGraphSynapseGraphSetPageTypesConstMeta, - argValues: [that, pageId, types], + constMeta: kCrateApiGraphSynapseGraphSetPageTypeConstMeta, + argValues: [that, pageId, pageType], apiImpl: this, ), ); } - TaskConstMeta get kCrateApiGraphSynapseGraphSetPageTypesConstMeta => + TaskConstMeta get kCrateApiGraphSynapseGraphSetPageTypeConstMeta => const TaskConstMeta( - debugName: "SynapseGraph_set_page_types", - argNames: ["that", "pageId", "types"], + debugName: "SynapseGraph_set_page_type", + argNames: ["that", "pageId", "pageType"], ); @override @@ -3044,8 +3041,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { GraphNode dco_decode_graph_node(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 12) - throw Exception('unexpected arr length: expect 12 but see ${arr.length}'); + if (arr.length != 13) + throw Exception('unexpected arr length: expect 13 but see ${arr.length}'); return GraphNode( id: dco_decode_String(arr[0]), title: dco_decode_String(arr[1]), @@ -3059,6 +3056,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { isHub: dco_decode_bool(arr[9]), homeHub: dco_decode_opt_box_autoadd_u_32(arr[10]), 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) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 11) - throw Exception('unexpected arr length: expect 11 but see ${arr.length}'); + if (arr.length != 10) + throw Exception('unexpected arr length: expect 10 but see ${arr.length}'); return PageDto( id: dco_decode_String(arr[0]), title: dco_decode_String(arr[1]), @@ -3364,8 +3362,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { isHub: dco_decode_bool(arr[6]), description: dco_decode_String(arr[7]), tags: dco_decode_list_String(arr[8]), - isTag: dco_decode_bool(arr[9]), - types: dco_decode_list_String(arr[10]), + pageType: dco_decode_opt_String(arr[9]), ); } @@ -3746,6 +3743,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_isHub = sse_decode_bool(deserializer); var var_homeHub = sse_decode_opt_box_autoadd_u_32(deserializer); var var_tags = sse_decode_list_String(deserializer); + var var_isTag = sse_decode_bool(deserializer); return GraphNode( id: var_id, title: var_title, @@ -3759,6 +3757,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { isHub: var_isHub, homeHub: var_homeHub, 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_description = sse_decode_String(deserializer); var var_tags = sse_decode_list_String(deserializer); - var var_isTag = sse_decode_bool(deserializer); - var var_types = sse_decode_list_String(deserializer); + var var_pageType = sse_decode_opt_String(deserializer); return PageDto( id: var_id, title: var_title, @@ -4210,8 +4208,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { isHub: var_isHub, description: var_description, tags: var_tags, - isTag: var_isTag, - types: var_types, + pageType: var_pageType, ); } @@ -4551,6 +4548,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_bool(self.isHub, serializer); sse_encode_opt_box_autoadd_u_32(self.homeHub, serializer); sse_encode_list_String(self.tags, serializer); + sse_encode_bool(self.isTag, serializer); } @protected @@ -4960,8 +4958,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_bool(self.isHub, serializer); sse_encode_String(self.description, serializer); sse_encode_list_String(self.tags, serializer); - sse_encode_bool(self.isTag, serializer); - sse_encode_list_String(self.types, serializer); + sse_encode_opt_String(self.pageType, serializer); } @protected @@ -5147,13 +5144,6 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { tag: tag, ); - Future 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, /// the hub itself and memberships that would create a cycle. Future addToHub({required String pageId, required String hubId}) => @@ -5366,7 +5356,7 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { .api .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> pagesWithTag({required String tag}) => RustLib .instance .api @@ -5432,14 +5422,10 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { tag: tag, ); - Future removePageType({ - required String pageId, - required String ty, - }) => RustLib.instance.api.crateApiGraphSynapseGraphRemovePageType( - that: this, - pageId: pageId, - ty: ty, - ); + /// Removes the explicit tag from every page (types of that name stay); returns the number + /// of pages changed. + Future removeTag({required String name}) => RustLib.instance.api + .crateApiGraphSynapseGraphRemoveTag(that: this, name: name); Future renamePage({required String id, required String newTitle}) => RustLib.instance.api.crateApiGraphSynapseGraphRenamePage( @@ -5448,6 +5434,13 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { newTitle: newTitle, ); + /// Renames a tag in the `tags` and `types` of every page carrying it; returns the number of + /// pages changed. + Future 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. Future> searchBlocks({ required String query, @@ -5485,8 +5478,8 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { description: description, ); - /// Replaces the tags of a page (each title gets a tag page if it has none). Journals, - /// templates and tag pages cannot be tagged. + /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot + /// be tagged. Future setPageTags({ required String pageId, required List tags, @@ -5496,17 +5489,16 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { tags: tags, ); - /// Replaces the types of a page. Journals and templates cannot be typed. - Future setPageTypes({ - required String pageId, - required List types, - }) => RustLib.instance.api.crateApiGraphSynapseGraphSetPageTypes( - that: this, - pageId: pageId, - types: types, - ); + /// Sets (or with `None` clears) the single type of a page. Journals and templates cannot be + /// typed. + Future setPageType({required String pageId, String? pageType}) => + RustLib.instance.api.crateApiGraphSynapseGraphSetPageType( + that: this, + pageId: pageId, + pageType: pageType, + ); - /// 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> tagCatalog() => RustLib.instance.api.crateApiGraphSynapseGraphTagCatalog(that: this); diff --git a/crates/synapse-ffi/src/api/dto.rs b/crates/synapse-ffi/src/api/dto.rs index d92db8a..130d841 100644 --- a/crates/synapse-ffi/src/api/dto.rs +++ b/crates/synapse-ffi/src/api/dto.rs @@ -18,12 +18,11 @@ pub struct PageDto { pub is_hub: bool, /// Hub description (empty for notes). 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, - /// The page is a tag page (a topic that other pages are filed under). - pub is_tag: bool, - /// Type names ("persona", "lugar"...: plain names, not pages), in the order added. - pub types: Vec, + /// The page's single type ("persona", "lugar"...: a name, not a page); it implies a tag of + /// the same name. + pub page_type: Option, } impl From<&Page> for PageDto { @@ -38,8 +37,7 @@ impl From<&Page> for PageDto { is_hub: p.is_hub(), description: p.description.clone(), tags: p.tags.clone(), - is_tag: p.is_tag(), - types: p.types.clone(), + page_type: p.page_type().map(String::from), } } } @@ -210,8 +208,9 @@ pub mod edge_kind { pub const SYNAPSE: u8 = 6; /// Hub membership, hub → member (structural, weight 1). pub const CONTAINS: u8 = 7; - /// A page filed under a tag page (page → tag page, weight 1). Unlike `TAG` (an inline - /// `#tag` in the text) it comes from the page's own `tags` list. + /// A page carrying a tag (page → virtual tag node, weight 1; the tag is listed in the + /// 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; } @@ -229,14 +228,17 @@ pub struct GraphNode { pub backlinks: u32, /// Community (Louvain), numbered by size: 0 is the largest. 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, /// The page is a hub (`PageKind::Hub`). pub is_hub: bool, /// Node index of the deepest hub containing this page (a hub: itself). pub home_hub: Option, - /// 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, + /// A virtual tag node (not a page, no outline): `id` is `tag:`, `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). diff --git a/crates/synapse-ffi/src/api/graph_view.rs b/crates/synapse-ffi/src/api/graph_view.rs index f95f2c6..cfb57df 100644 --- a/crates/synapse-ffi/src/api/graph_view.rs +++ b/crates/synapse-ffi/src/api/graph_view.rs @@ -115,6 +115,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result { is_hub: false, home_hub: None, tags, + is_tag: false, }); } } @@ -227,7 +228,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result { } } - tagged(g, &index, &by_key, &mut b)?; + tagged(g, &index, &mut nodes, &mut b)?; // Stable edge order (sources, then targets, then kind). 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 { neigh[s as usize].insert(t); neigh[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; } } @@ -283,20 +284,48 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result { Ok(out) } -/// A page filed under a tag page gets one `TAGGED` edge to it. +/// Tags are virtual nodes (`tag:`, appended after the pages): every page carrying a tag, +/// listed or implied by a type, gets one `TAGGED` edge to it. fn tagged( g: &Graph, index: &HashMap, - by_key: &HashMap, + nodes: &mut Vec, b: &mut Builder, ) -> Result<()> { - let mut st = g.conn().prepare("SELECT tag_key, page_id FROM page_tags")?; + let display: HashMap = 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 mut tag_index: HashMap = HashMap::new(); for row in rows { - let (tag, page) = row?; - if let (Some(&s), Some(&t)) = (index.get(&page), by_key.get(&tag)) { - b.add(s, t, edge_kind::TAGGED, 1.0); - } + let (key, page) = row?; + let Some(&s) = index.get(&page) else { + 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(()) } diff --git a/crates/synapse-ffi/src/api/tags.rs b/crates/synapse-ffi/src/api/tags.rs index 096c0cb..571d6c0 100644 --- a/crates/synapse-ffi/src/api/tags.rs +++ b/crates/synapse-ffi/src/api/tags.rs @@ -1,13 +1,12 @@ -//! Tags (topic pages that notes are filed under) and types (plain names saying what a page -//! is). Rules live in `synapse_core::{tags, types}`; this module shapes them for the UI. +//! 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. use super::dto::{PageBrief, PageDto, TagDto}; use super::graph::{SynapseGraph, parse_id}; use anyhow::Result; impl SynapseGraph { - /// Replaces the tags of a page (each title gets a tag page if it has none). Journals, - /// templates and tag pages cannot be tagged. + /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot + /// be tagged. pub fn set_page_tags(&self, page_id: String, tags: Vec) -> Result { let g = self.lock(); 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 { + 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 { + 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> { Ok(self .lock() @@ -39,7 +50,7 @@ impl SynapseGraph { .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> { let g = self.lock(); let mut out = Vec::new(); @@ -51,24 +62,14 @@ impl SynapseGraph { Ok(out) } - /// Replaces the types of a page. Journals and templates cannot be typed. - pub fn set_page_types(&self, page_id: String, types: Vec) -> Result { + /// Sets (or with `None` clears) the single type of a page. Journals and templates cannot be + /// typed. + pub fn set_page_type(&self, page_id: String, page_type: Option) -> Result { let g = self.lock(); - Ok(PageDto::from( - &g.set_page_types(parse_id(&page_id)?, types)?, - )) - } - - pub fn add_page_type(&self, page_id: String, ty: String) -> Result { - 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 { - let g = self.lock(); - Ok(PageDto::from( - &g.remove_page_type(parse_id(&page_id)?, &ty)?, - )) + Ok(PageDto::from(&g.set_page_type( + parse_id(&page_id)?, + page_type.as_deref(), + )?)) } /// Types in use (most used first) followed by the seeded suggestions not used yet. diff --git a/crates/synapse-ffi/src/frb_generated.rs b/crates/synapse-ffi/src/frb_generated.rs index 5e9703c..83b051c 100644 --- a/crates/synapse-ffi/src/frb_generated.rs +++ b/crates/synapse-ffi/src/frb_generated.rs @@ -41,7 +41,7 @@ flutter_rust_bridge::frb_generated_boilerplate!( default_rust_auto_opaque = RustAutoOpaqueMoi, ); 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 @@ -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::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 = , - >>::sse_decode(&mut deserializer); - let api_page_id = ::sse_decode(&mut deserializer); - let api_ty = ::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( port_: flutter_rust_bridge::for_generated::MessagePort, 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, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, 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::TaskInfo { - debug_name: "SynapseGraph_remove_page_type", + debug_name: "SynapseGraph_remove_tag", port: Some(port_), 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 = , >>::sse_decode(&mut deserializer); - let api_page_id = ::sse_decode(&mut deserializer); - let api_ty = ::sse_decode(&mut deserializer); + let api_name = ::sse_decode(&mut deserializer); deserializer.end(); move |context| { 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 output_ok = crate::api::graph::SynapseGraph::remove_page_type( + let output_ok = crate::api::graph::SynapseGraph::remove_tag( &*api_that_guard, - api_page_id, - api_ty, + api_name, )?; 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::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 = , + >>::sse_decode(&mut deserializer); + let api_old = ::sse_decode(&mut deserializer); + let api_new = ::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( port_: flutter_rust_bridge::for_generated::MessagePort, 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, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, 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::TaskInfo { - debug_name: "SynapseGraph_set_page_types", + debug_name: "SynapseGraph_set_page_type", port: Some(port_), 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, >>::sse_decode(&mut deserializer); let api_page_id = ::sse_decode(&mut deserializer); - let api_types = >::sse_decode(&mut deserializer); + let api_page_type = >::sse_decode(&mut deserializer); deserializer.end(); move |context| { 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 output_ok = crate::api::graph::SynapseGraph::set_page_types( + let output_ok = crate::api::graph::SynapseGraph::set_page_type( &*api_that_guard, api_page_id, - api_types, + api_page_type, )?; std::result::Result::Ok(output_ok) })(), @@ -3656,6 +3654,7 @@ impl SseDecode for crate::api::dto::GraphNode { let mut var_isHub = ::sse_decode(deserializer); let mut var_homeHub = >::sse_decode(deserializer); let mut var_tags = >::sse_decode(deserializer); + let mut var_isTag = ::sse_decode(deserializer); return crate::api::dto::GraphNode { id: var_id, title: var_title, @@ -3669,6 +3668,7 @@ impl SseDecode for crate::api::dto::GraphNode { is_hub: var_isHub, home_hub: var_homeHub, tags: var_tags, + is_tag: var_isTag, }; } } @@ -4110,8 +4110,7 @@ impl SseDecode for crate::api::dto::PageDto { let mut var_isHub = ::sse_decode(deserializer); let mut var_description = ::sse_decode(deserializer); let mut var_tags = >::sse_decode(deserializer); - let mut var_isTag = ::sse_decode(deserializer); - let mut var_types = >::sse_decode(deserializer); + let mut var_pageType = >::sse_decode(deserializer); return crate::api::dto::PageDto { id: var_id, title: var_title, @@ -4122,8 +4121,7 @@ impl SseDecode for crate::api::dto::PageDto { is_hub: var_isHub, description: var_description, tags: var_tags, - is_tag: var_isTag, - types: var_types, + page_type: var_pageType, }; } } @@ -4306,196 +4304,190 @@ fn pde_ffi_dispatcher_primary_impl( rust_vec_len, data_len, ), - 8 => wire__crate__api__graph__SynapseGraph_add_page_type_impl( - port, - ptr, - rust_vec_len, - data_len, - ), - 9 => { + 8 => { 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), - 12 => { + 9 => wire__crate__api__graph__SynapseGraph_aliases_impl(port, ptr, rust_vec_len, data_len), + 11 => { 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) } - 14 => wire__crate__api__graph__SynapseGraph_convert_to_hub_impl( + 13 => wire__crate__api__graph__SynapseGraph_convert_to_hub_impl( port, ptr, rust_vec_len, data_len, ), - 15 => wire__crate__api__graph__SynapseGraph_convert_to_note_impl( + 14 => wire__crate__api__graph__SynapseGraph_convert_to_note_impl( port, ptr, rust_vec_len, data_len, ), - 16 => { + 15 => { 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, ptr, rust_vec_len, data_len, ), - 18 => wire__crate__api__graph__SynapseGraph_delete_block_impl( + 17 => wire__crate__api__graph__SynapseGraph_delete_block_impl( port, ptr, rust_vec_len, data_len, ), - 19 => wire__crate__api__graph__SynapseGraph_delete_page_impl( + 18 => wire__crate__api__graph__SynapseGraph_delete_page_impl( port, ptr, rust_vec_len, data_len, ), - 21 => { + 20 => { 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, ptr, rust_vec_len, data_len, ), - 23 => wire__crate__api__graph__SynapseGraph_hub_template_impl( + 22 => wire__crate__api__graph__SynapseGraph_hub_template_impl( port, ptr, rust_vec_len, data_len, ), - 24 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len), - 25 => wire__crate__api__graph__SynapseGraph_indent_block_impl( + 23 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len), + 24 => wire__crate__api__graph__SynapseGraph_indent_block_impl( port, ptr, rust_vec_len, data_len, ), - 26 => wire__crate__api__graph__SynapseGraph_insert_block_impl( + 25 => wire__crate__api__graph__SynapseGraph_insert_block_impl( port, ptr, rust_vec_len, data_len, ), - 27 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len), - 28 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl( + 26 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len), + 27 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl( port, ptr, rust_vec_len, data_len, ), - 29 => { + 28 => { 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, ptr, rust_vec_len, data_len, ), - 31 => { + 30 => { 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, ptr, rust_vec_len, data_len, ), - 33 => { + 32 => { 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), - 35 => { + 33 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), + 34 => { 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, ptr, rust_vec_len, data_len, ), - 37 => 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), - 39 => wire__crate__api__graph__SynapseGraph_page_by_title_impl( + 36 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len), + 37 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len), + 38 => wire__crate__api__graph__SynapseGraph_page_by_title_impl( port, ptr, rust_vec_len, data_len, ), - 40 => wire__crate__api__graph__SynapseGraph_page_structure_impl( + 39 => wire__crate__api__graph__SynapseGraph_page_structure_impl( port, ptr, rust_vec_len, data_len, ), - 41 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( + 40 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( port, ptr, rust_vec_len, data_len, ), - 42 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( + 41 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( port, ptr, rust_vec_len, data_len, ), - 43 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( + 42 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( port, ptr, rust_vec_len, data_len, ), - 44 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( + 43 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( port, ptr, rust_vec_len, data_len, ), - 45 => wire__crate__api__graph__SynapseGraph_record_visit_impl( + 44 => wire__crate__api__graph__SynapseGraph_record_visit_impl( port, ptr, rust_vec_len, data_len, ), - 46 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), - 47 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( + 45 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), + 46 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( port, ptr, rust_vec_len, data_len, ), - 48 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( + 47 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( port, ptr, rust_vec_len, data_len, ), - 49 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( + 48 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( port, ptr, rust_vec_len, data_len, ), - 50 => wire__crate__api__graph__SynapseGraph_remove_page_type_impl( - port, - ptr, - rust_vec_len, - data_len, - ), - 51 => wire__crate__api__graph__SynapseGraph_rename_page_impl( + 49 => { + wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len) + } + 50 => wire__crate__api__graph__SynapseGraph_rename_page_impl( port, ptr, rust_vec_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( port, ptr, @@ -4526,7 +4518,7 @@ fn pde_ffi_dispatcher_primary_impl( rust_vec_len, data_len, ), - 57 => wire__crate__api__graph__SynapseGraph_set_page_types_impl( + 57 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( port, ptr, rust_vec_len, @@ -4566,8 +4558,8 @@ fn pde_ffi_dispatcher_sync_impl( // Codec=Pde (Serialization + dispatch), see doc to use other codecs match func_id { 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), - 20 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len), + 10 => wire__crate__api__graph__SynapseGraph_asset_path_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), _ => unreachable!(), } @@ -4755,6 +4747,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::GraphNode { self.is_hub.into_into_dart().into_dart(), self.home_hub.into_into_dart().into_dart(), self.tags.into_into_dart().into_dart(), + self.is_tag.into_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.description.into_into_dart().into_dart(), self.tags.into_into_dart().into_dart(), - self.is_tag.into_into_dart().into_dart(), - self.types.into_into_dart().into_dart(), + self.page_type.into_into_dart().into_dart(), ] .into_dart() } @@ -5254,6 +5246,7 @@ impl SseEncode for crate::api::dto::GraphNode { ::sse_encode(self.is_hub, serializer); >::sse_encode(self.home_hub, serializer); >::sse_encode(self.tags, serializer); + ::sse_encode(self.is_tag, serializer); } } @@ -5603,8 +5596,7 @@ impl SseEncode for crate::api::dto::PageDto { ::sse_encode(self.is_hub, serializer); ::sse_encode(self.description, serializer); >::sse_encode(self.tags, serializer); - ::sse_encode(self.is_tag, serializer); - >::sse_encode(self.types, serializer); + >::sse_encode(self.page_type, serializer); } } diff --git a/crates/synapse-ffi/tests/api.rs b/crates/synapse-ffi/tests/api.rs index 72fff89..7de068f 100644 --- a/crates/synapse-ffi/tests/api.rs +++ b/crates/synapse-ffi/tests/api.rs @@ -399,7 +399,7 @@ fn legacy_candidates_and_purge() { } #[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 (a, _) = page_with(&g, "Rust", &["x"]); let (b, _) = page_with(&g, "Go", &["y"]); @@ -407,13 +407,13 @@ fn tags_are_pages_and_their_own_edge_kind() { for (p, tags) in [ (&a, 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()) .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 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 mut tagged: Vec<(String, String)> = (0..data.kinds.len()) .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", "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. - let tp = &data.nodes[data + // Tags are virtual: no page behind them, flagged, with the page count as degree. + let tag = data .nodes .iter() - .position(|n| n.title == "tecnología") - .unwrap()]; - assert_eq!(tp.backlinks, 2); - assert!(g.page(tp.id.clone()).unwrap().unwrap().page.is_tag); + .find(|n| n.is_tag && n.title == "tecnología"); + let tag = tag.expect("tag node"); + assert_eq!(tag.id, "tag:tecnología"); + 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!( - idx(&a), - data.nodes.iter().position(|n| n.id == a).unwrap() as u32 + go.tags, + ["idea", "Tecnología"], + "tags, with the type's tag once" ); let cat = g.tag_catalog().unwrap(); assert_eq!((cat[0].name.as_str(), cat[0].count), ("idea", 2)); + assert_eq!(g.pages_with_tag("IDEA".into()).unwrap().len(), 2); } #[test] -fn types_round_trip_through_the_api() { +fn page_type_and_tag_renaming_round_trip_through_the_api() { let (_d, g) = open(); let (a, _) = page_with(&g, "Ana", &["x"]); - let p = g.add_page_type(a.clone(), "persona".into()).unwrap(); - assert_eq!(p.types, ["persona"]); + let p = g.set_page_type(a.clone(), Some("persona".into())).unwrap(); + 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.remove_page_type(a, "PERSONA".into()) - .unwrap() - .types - .is_empty() + g.add_page_tag(a.clone(), "web".into()).unwrap(); + assert_eq!(g.rename_tag("lugar".into(), "sitio".into()).unwrap(), 1); + assert_eq!(g.rename_tag("web".into(), "red".into()).unwrap(), 1); + let p = g.page(a.clone()).unwrap().unwrap().page; + 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()); }