diff --git a/app/lib/src/backend/graph_backend.dart b/app/lib/src/backend/graph_backend.dart index 32cb78e..4dfd49e 100644 --- a/app/lib/src/backend/graph_backend.dart +++ b/app/lib/src/backend/graph_backend.dart @@ -70,9 +70,22 @@ abstract class GraphBackend { Future setPageType(String pageId, String? type); - /// Types in use (most used first), then the seeded suggestions not used yet. + /// Types in use (most used first), then types defined but unused, then the seeded + /// suggestions not used yet; each with its emoji icon (`TagDto.icon`). Future> typeCatalog(); + /// Adds a type to the vocabulary even with no pages; returns its spelling. + Future createType(String name); + + /// Sets (or with `null` clears) the emoji of a type. Synced with the graph. + Future setTypeIcon(String name, String? icon); + + /// Renames a type (and same-name tags), keeping its icon; returns the pages changed. + Future renameType(String old, String new_); + + /// Deletes a type: its pages lose it and its icon goes; returns the pages changed. + Future removeType(String name); + /// Every tag in use (listed or implied by a type), most used first. Future> tagCatalog(); @@ -270,6 +283,16 @@ class FfiGraphBackend implements GraphBackend { Future removeTag(String name) => _g.removeTag(name: name); @override Future> typeCatalog() => _g.typeCatalog(); + @override + Future createType(String name) => _g.createType(name: name); + @override + Future setTypeIcon(String name, String? icon) => + _g.setTypeIcon(name: name, icon: icon); + @override + Future renameType(String old, String new_) => + _g.renameType(old: old, new_: new_); + @override + Future removeType(String name) => _g.removeType(name: name); @override Future> tagCatalog() => _g.tagCatalog(); diff --git a/app/lib/src/rust/api/dto.dart b/app/lib/src/rust/api/dto.dart index b8a7f2d..17dfdcd 100644 --- a/app/lib/src/rust/api/dto.dart +++ b/app/lib/src/rust/api/dto.dart @@ -8,7 +8,7 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; // These functions are ignored because they are not marked as `pub`: `new` -// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `assert_fields_are_eq`, `assert_fields_are_eq`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from` +// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `assert_fields_are_eq`, `assert_fields_are_eq`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from`, `from` class AssetDto { final String hash; @@ -43,12 +43,16 @@ class BacklinkGroup { final String pageId; final String pageTitle; final bool isJournal; + + /// Type of the referencing page (for its icon). + final String? pageType; final List blocks; const BacklinkGroup({ required this.pageId, required this.pageTitle, required this.isJournal, + this.pageType, required this.blocks, }); @@ -57,6 +61,7 @@ class BacklinkGroup { pageId.hashCode ^ pageTitle.hashCode ^ isJournal.hashCode ^ + pageType.hashCode ^ blocks.hashCode; @override @@ -67,6 +72,7 @@ class BacklinkGroup { pageId == other.pageId && pageTitle == other.pageTitle && isJournal == other.isJournal && + pageType == other.pageType && blocks == other.blocks; } @@ -266,6 +272,9 @@ class GraphNode { /// display name, `degree` the number of pages carrying the tag. final bool isTag; + /// The page's type (tree labels show its icon; the network view does not). + final String? pageType; + const GraphNode({ required this.id, required this.title, @@ -280,6 +289,7 @@ class GraphNode { this.homeHub, required this.tags, required this.isTag, + this.pageType, }); @override @@ -296,7 +306,8 @@ class GraphNode { isHub.hashCode ^ homeHub.hashCode ^ tags.hashCode ^ - isTag.hashCode; + isTag.hashCode ^ + pageType.hashCode; @override bool operator ==(Object other) => @@ -315,7 +326,8 @@ class GraphNode { isHub == other.isHub && homeHub == other.homeHub && tags == other.tags && - isTag == other.isTag; + isTag == other.isTag && + pageType == other.pageType; } /// A hub (folder-like page) with its members. @@ -518,16 +530,24 @@ class PageBrief { final bool isJournal; final bool isHub; + /// The page's type (the UI shows its icon next to the title). + final String? pageType; + const PageBrief({ required this.id, required this.title, required this.isJournal, required this.isHub, + this.pageType, }); @override int get hashCode => - id.hashCode ^ title.hashCode ^ isJournal.hashCode ^ isHub.hashCode; + id.hashCode ^ + title.hashCode ^ + isJournal.hashCode ^ + isHub.hashCode ^ + pageType.hashCode; @override bool operator ==(Object other) => @@ -537,7 +557,8 @@ class PageBrief { id == other.id && title == other.title && isJournal == other.isJournal && - isHub == other.isHub; + isHub == other.isHub && + pageType == other.pageType; } /// Everything the page view needs in one call. @@ -753,14 +774,37 @@ class TagDto { /// One of the seeded suggestions. final bool suggested; + /// Emoji of a type (types only). + final String? icon; + + /// Pages listing it as an explicit tag (tags only). + final int explicit; + + /// Pages having it as their type (tags only). + final int typed; + + /// Pages carrying it through their hub (tags only; hub tags cannot be renamed or removed). + final int fromHub; + const TagDto({ required this.name, required this.count, required this.suggested, + this.icon, + required this.explicit, + required this.typed, + required this.fromHub, }); @override - int get hashCode => name.hashCode ^ count.hashCode ^ suggested.hashCode; + int get hashCode => + name.hashCode ^ + count.hashCode ^ + suggested.hashCode ^ + icon.hashCode ^ + explicit.hashCode ^ + typed.hashCode ^ + fromHub.hashCode; @override bool operator ==(Object other) => @@ -769,7 +813,11 @@ class TagDto { runtimeType == other.runtimeType && name == other.name && count == other.count && - suggested == other.suggested; + suggested == other.suggested && + icon == other.icon && + explicit == other.explicit && + typed == other.typed && + fromHub == other.fromHub; } class TimelineDayDto { @@ -831,14 +879,19 @@ class TitleHit { final String title; final bool isAlias; + /// Type of the page (for its icon). + final String? pageType; + const TitleHit({ required this.pageId, required this.title, required this.isAlias, + this.pageType, }); @override - int get hashCode => pageId.hashCode ^ title.hashCode ^ isAlias.hashCode; + int get hashCode => + pageId.hashCode ^ title.hashCode ^ isAlias.hashCode ^ pageType.hashCode; @override bool operator ==(Object other) => @@ -847,5 +900,6 @@ class TitleHit { runtimeType == other.runtimeType && pageId == other.pageId && title == other.title && - isAlias == other.isAlias; + isAlias == other.isAlias && + pageType == other.pageType; } diff --git a/app/lib/src/rust/api/graph.dart b/app/lib/src/rust/api/graph.dart index 3c49ca1..b646ff8 100644 --- a/app/lib/src/rust/api/graph.dart +++ b/app/lib/src/rust/api/graph.dart @@ -58,6 +58,9 @@ abstract class SynapseGraph implements RustOpaqueInterface { required String title, }); + /// Adds a type to the vocabulary even if no page uses it; returns its spelling. + Future createType({required String name}); + /// Deletes a block and its subtree. Future> deleteBlock({required String id}); @@ -183,12 +186,18 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// of pages changed. Future removeTag({required String name}); + /// Deletes a type: its pages lose it and its icon is dropped; returns the pages changed. + Future removeType({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_}); + /// Renames a type (and same-name tags), keeping its icon; returns the pages changed. + Future renameType({required String old, required String new_}); + /// Blocks whose text contains `query` (for `((` autocomplete), most recent first. Future> searchBlocks({ required String query, @@ -220,6 +229,9 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// typed. Future setPageType({required String pageId, String? pageType}); + /// Sets (or with `None` clears) the emoji of a type, defining the type if needed. + Future setTypeIcon({required String name, String? icon}); + /// Every tag in use (listed or implied by a type) with its number of pages, most used first. Future> tagCatalog(); @@ -229,7 +241,8 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// Today's date (graph clock) as `YYYY-MM-DD`. String today(); - /// Types in use (most used first) followed by the seeded suggestions not used yet. + /// Types in use (most used first), then defined unused types, then the seeded suggestions + /// not used yet; each with its icon. Future> typeCatalog(); /// Replaces a block's Markdown (the debounced save while typing). diff --git a/app/lib/src/rust/frb_generated.dart b/app/lib/src/rust/frb_generated.dart index f605c8a..62cd249 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 => -1472342481; + int get rustContentHash => 272705018; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -175,6 +175,11 @@ abstract class RustLibApi extends BaseApi { required String title, }); + Future crateApiGraphSynapseGraphCreateType({ + required SynapseGraph that, + required String name, + }); + Future> crateApiGraphSynapseGraphDeleteBlock({ required SynapseGraph that, required String id, @@ -344,6 +349,11 @@ abstract class RustLibApi extends BaseApi { required String name, }); + Future crateApiGraphSynapseGraphRemoveType({ + required SynapseGraph that, + required String name, + }); + Future crateApiGraphSynapseGraphRenamePage({ required SynapseGraph that, required String id, @@ -356,6 +366,12 @@ abstract class RustLibApi extends BaseApi { required String new_, }); + Future crateApiGraphSynapseGraphRenameType({ + required SynapseGraph that, + required String old, + required String new_, + }); + Future> crateApiGraphSynapseGraphSearchBlocks({ required SynapseGraph that, required String query, @@ -392,6 +408,12 @@ abstract class RustLibApi extends BaseApi { String? pageType, }); + Future crateApiGraphSynapseGraphSetTypeIcon({ + required SynapseGraph that, + required String name, + String? icon, + }); + Future> crateApiGraphSynapseGraphTagCatalog({ required SynapseGraph that, }); @@ -1070,6 +1092,44 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "hubId", "title"], ); + @override + Future crateApiGraphSynapseGraphCreateType({ + required SynapseGraph that, + required String name, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(name, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 17, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_String, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphCreateTypeConstMeta, + argValues: [that, name], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphCreateTypeConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_create_type", + argNames: ["that", "name"], + ); + @override Future> crateApiGraphSynapseGraphDeleteBlock({ required SynapseGraph that, @@ -1087,7 +1147,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 17, + funcId: 18, port: port_, ); }, @@ -1125,7 +1185,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 18, + funcId: 19, port: port_, ); }, @@ -1156,7 +1216,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { that, serializer, ); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 19)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 20)!; }, codec: SseCodec( decodeSuccessData: sse_decode_String, @@ -1187,7 +1247,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 20, + funcId: 21, port: port_, ); }, @@ -1225,7 +1285,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 21, + funcId: 22, port: port_, ); }, @@ -1263,7 +1323,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 22, + funcId: 23, port: port_, ); }, @@ -1297,7 +1357,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 23, + funcId: 24, port: port_, ); }, @@ -1332,7 +1392,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 24, + funcId: 25, port: port_, ); }, @@ -1374,7 +1434,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 25, + funcId: 26, port: port_, ); }, @@ -1412,7 +1472,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 26, + funcId: 27, port: port_, ); }, @@ -1450,7 +1510,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 27, + funcId: 28, port: port_, ); }, @@ -1490,7 +1550,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 28, + funcId: 29, port: port_, ); }, @@ -1526,7 +1586,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 29, + funcId: 30, port: port_, ); }, @@ -1568,7 +1628,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 30, + funcId: 31, port: port_, ); }, @@ -1608,7 +1668,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 31, + funcId: 32, port: port_, ); }, @@ -1650,7 +1710,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 32, + funcId: 33, port: port_, ); }, @@ -1681,7 +1741,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 33, + funcId: 34, port: port_, ); }, @@ -1717,7 +1777,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 34, + funcId: 35, port: port_, ); }, @@ -1755,7 +1815,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 35, + funcId: 36, port: port_, ); }, @@ -1793,7 +1853,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 36, + funcId: 37, port: port_, ); }, @@ -1831,7 +1891,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 37, + funcId: 38, port: port_, ); }, @@ -1869,7 +1929,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 38, + funcId: 39, port: port_, ); }, @@ -1907,7 +1967,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 39, + funcId: 40, port: port_, ); }, @@ -1945,7 +2005,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 40, + funcId: 41, port: port_, ); }, @@ -1983,7 +2043,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 41, + funcId: 42, port: port_, ); }, @@ -2025,7 +2085,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 42, + funcId: 43, port: port_, ); }, @@ -2065,7 +2125,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 43, + funcId: 44, port: port_, ); }, @@ -2105,7 +2165,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 44, + funcId: 45, port: port_, ); }, @@ -2145,7 +2205,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 45, + funcId: 46, port: port_, ); }, @@ -2183,7 +2243,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 46, + funcId: 47, port: port_, ); }, @@ -2223,7 +2283,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 47, + funcId: 48, port: port_, ); }, @@ -2263,7 +2323,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 48, + funcId: 49, port: port_, ); }, @@ -2301,7 +2361,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 49, + funcId: 50, port: port_, ); }, @@ -2322,6 +2382,44 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "name"], ); + @override + Future crateApiGraphSynapseGraphRemoveType({ + required SynapseGraph that, + required String name, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(name, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 51, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_u_32, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphRemoveTypeConstMeta, + argValues: [that, name], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphRemoveTypeConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_remove_type", + argNames: ["that", "name"], + ); + @override Future crateApiGraphSynapseGraphRenamePage({ required SynapseGraph that, @@ -2341,7 +2439,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 50, + funcId: 52, port: port_, ); }, @@ -2381,7 +2479,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 51, + funcId: 53, port: port_, ); }, @@ -2402,6 +2500,46 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "old", "new_"], ); + @override + Future crateApiGraphSynapseGraphRenameType({ + 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: 54, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_u_32, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphRenameTypeConstMeta, + argValues: [that, old, new_], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphRenameTypeConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_rename_type", + argNames: ["that", "old", "new_"], + ); + @override Future> crateApiGraphSynapseGraphSearchBlocks({ required SynapseGraph that, @@ -2421,7 +2559,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 52, + funcId: 55, port: port_, ); }, @@ -2461,7 +2599,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 53, + funcId: 56, port: port_, ); }, @@ -2501,7 +2639,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 54, + funcId: 57, port: port_, ); }, @@ -2541,7 +2679,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 55, + funcId: 58, port: port_, ); }, @@ -2581,7 +2719,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 56, + funcId: 59, port: port_, ); }, @@ -2621,7 +2759,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 57, + funcId: 60, port: port_, ); }, @@ -2642,6 +2780,46 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "pageId", "pageType"], ); + @override + Future crateApiGraphSynapseGraphSetTypeIcon({ + required SynapseGraph that, + required String name, + String? icon, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(name, serializer); + sse_encode_opt_String(icon, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 61, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphSetTypeIconConstMeta, + argValues: [that, name, icon], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphSetTypeIconConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_set_type_icon", + argNames: ["that", "name", "icon"], + ); + @override Future> crateApiGraphSynapseGraphTagCatalog({ required SynapseGraph that, @@ -2657,7 +2835,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 58, + funcId: 62, port: port_, ); }, @@ -2697,7 +2875,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 59, + funcId: 63, port: port_, ); }, @@ -2728,7 +2906,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { that, serializer, ); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 60)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 64)!; }, codec: SseCodec( decodeSuccessData: sse_decode_String, @@ -2759,7 +2937,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 61, + funcId: 65, port: port_, ); }, @@ -2799,7 +2977,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 62, + funcId: 66, port: port_, ); }, @@ -2920,13 +3098,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { BacklinkGroup dco_decode_backlink_group(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 4) - throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); + if (arr.length != 5) + throw Exception('unexpected arr length: expect 5 but see ${arr.length}'); return BacklinkGroup( pageId: dco_decode_String(arr[0]), pageTitle: dco_decode_String(arr[1]), isJournal: dco_decode_bool(arr[2]), - blocks: dco_decode_list_block_dto(arr[3]), + pageType: dco_decode_opt_String(arr[3]), + blocks: dco_decode_list_block_dto(arr[4]), ); } @@ -3042,8 +3221,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 != 13) - throw Exception('unexpected arr length: expect 13 but see ${arr.length}'); + if (arr.length != 14) + throw Exception('unexpected arr length: expect 14 but see ${arr.length}'); return GraphNode( id: dco_decode_String(arr[0]), title: dco_decode_String(arr[1]), @@ -3058,6 +3237,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { homeHub: dco_decode_opt_box_autoadd_u_32(arr[10]), tags: dco_decode_list_String(arr[11]), isTag: dco_decode_bool(arr[12]), + pageType: dco_decode_opt_String(arr[13]), ); } @@ -3322,13 +3502,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { PageBrief dco_decode_page_brief(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 4) - throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); + if (arr.length != 5) + throw Exception('unexpected arr length: expect 5 but see ${arr.length}'); return PageBrief( id: dco_decode_String(arr[0]), title: dco_decode_String(arr[1]), isJournal: dco_decode_bool(arr[2]), isHub: dco_decode_bool(arr[3]), + pageType: dco_decode_opt_String(arr[4]), ); } @@ -3427,12 +3608,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { TagDto dco_decode_tag_dto(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 3) - throw Exception('unexpected arr length: expect 3 but see ${arr.length}'); + if (arr.length != 7) + throw Exception('unexpected arr length: expect 7 but see ${arr.length}'); return TagDto( name: dco_decode_String(arr[0]), count: dco_decode_u_32(arr[1]), suggested: dco_decode_bool(arr[2]), + icon: dco_decode_opt_String(arr[3]), + explicit: dco_decode_u_32(arr[4]), + typed: dco_decode_u_32(arr[5]), + fromHub: dco_decode_u_32(arr[6]), ); } @@ -3466,12 +3651,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { TitleHit dco_decode_title_hit(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 3) - throw Exception('unexpected arr length: expect 3 but see ${arr.length}'); + if (arr.length != 4) + throw Exception('unexpected arr length: expect 4 but see ${arr.length}'); return TitleHit( pageId: dco_decode_String(arr[0]), title: dco_decode_String(arr[1]), isAlias: dco_decode_bool(arr[2]), + pageType: dco_decode_opt_String(arr[3]), ); } @@ -3612,11 +3798,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_pageId = sse_decode_String(deserializer); var var_pageTitle = sse_decode_String(deserializer); var var_isJournal = sse_decode_bool(deserializer); + var var_pageType = sse_decode_opt_String(deserializer); var var_blocks = sse_decode_list_block_dto(deserializer); return BacklinkGroup( pageId: var_pageId, pageTitle: var_pageTitle, isJournal: var_isJournal, + pageType: var_pageType, blocks: var_blocks, ); } @@ -3751,6 +3939,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { 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); + var var_pageType = sse_decode_opt_String(deserializer); return GraphNode( id: var_id, title: var_title, @@ -3765,6 +3954,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { homeHub: var_homeHub, tags: var_tags, isTag: var_isTag, + pageType: var_pageType, ); } @@ -4167,11 +4357,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_title = sse_decode_String(deserializer); var var_isJournal = sse_decode_bool(deserializer); var var_isHub = sse_decode_bool(deserializer); + var var_pageType = sse_decode_opt_String(deserializer); return PageBrief( id: var_id, title: var_title, isJournal: var_isJournal, isHub: var_isHub, + pageType: var_pageType, ); } @@ -4277,7 +4469,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_name = sse_decode_String(deserializer); var var_count = sse_decode_u_32(deserializer); var var_suggested = sse_decode_bool(deserializer); - return TagDto(name: var_name, count: var_count, suggested: var_suggested); + var var_icon = sse_decode_opt_String(deserializer); + var var_explicit = sse_decode_u_32(deserializer); + var var_typed = sse_decode_u_32(deserializer); + var var_fromHub = sse_decode_u_32(deserializer); + return TagDto( + name: var_name, + count: var_count, + suggested: var_suggested, + icon: var_icon, + explicit: var_explicit, + typed: var_typed, + fromHub: var_fromHub, + ); } @protected @@ -4309,7 +4513,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_pageId = sse_decode_String(deserializer); var var_title = sse_decode_String(deserializer); var var_isAlias = sse_decode_bool(deserializer); - return TitleHit(pageId: var_pageId, title: var_title, isAlias: var_isAlias); + var var_pageType = sse_decode_opt_String(deserializer); + return TitleHit( + pageId: var_pageId, + title: var_title, + isAlias: var_isAlias, + pageType: var_pageType, + ); } @protected @@ -4449,6 +4659,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.pageId, serializer); sse_encode_String(self.pageTitle, serializer); sse_encode_bool(self.isJournal, serializer); + sse_encode_opt_String(self.pageType, serializer); sse_encode_list_block_dto(self.blocks, serializer); } @@ -4557,6 +4768,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_opt_box_autoadd_u_32(self.homeHub, serializer); sse_encode_list_String(self.tags, serializer); sse_encode_bool(self.isTag, serializer); + sse_encode_opt_String(self.pageType, serializer); } @protected @@ -4942,6 +5154,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.title, serializer); sse_encode_bool(self.isJournal, serializer); sse_encode_bool(self.isHub, serializer); + sse_encode_opt_String(self.pageType, serializer); } @protected @@ -5016,6 +5229,10 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.name, serializer); sse_encode_u_32(self.count, serializer); sse_encode_bool(self.suggested, serializer); + sse_encode_opt_String(self.icon, serializer); + sse_encode_u_32(self.explicit, serializer); + sse_encode_u_32(self.typed, serializer); + sse_encode_u_32(self.fromHub, serializer); } @protected @@ -5043,6 +5260,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_String(self.pageId, serializer); sse_encode_String(self.title, serializer); sse_encode_bool(self.isAlias, serializer); + sse_encode_opt_String(self.pageType, serializer); } @protected @@ -5222,6 +5440,10 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { title: title, ); + /// Adds a type to the vocabulary even if no page uses it; returns its spelling. + Future createType({required String name}) => RustLib.instance.api + .crateApiGraphSynapseGraphCreateType(that: this, name: name); + /// Deletes a block and its subtree. Future> deleteBlock({required String id}) => RustLib .instance @@ -5436,6 +5658,10 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { Future removeTag({required String name}) => RustLib.instance.api .crateApiGraphSynapseGraphRemoveTag(that: this, name: name); + /// Deletes a type: its pages lose it and its icon is dropped; returns the pages changed. + Future removeType({required String name}) => RustLib.instance.api + .crateApiGraphSynapseGraphRemoveType(that: this, name: name); + Future renamePage({required String id, required String newTitle}) => RustLib.instance.api.crateApiGraphSynapseGraphRenamePage( that: this, @@ -5450,6 +5676,12 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { .api .crateApiGraphSynapseGraphRenameTag(that: this, old: old, new_: new_); + /// Renames a type (and same-name tags), keeping its icon; returns the pages changed. + Future renameType({required String old, required String new_}) => RustLib + .instance + .api + .crateApiGraphSynapseGraphRenameType(that: this, old: old, new_: new_); + /// Blocks whose text contains `query` (for `((` autocomplete), most recent first. Future> searchBlocks({ required String query, @@ -5507,6 +5739,12 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { pageType: pageType, ); + /// Sets (or with `None` clears) the emoji of a type, defining the type if needed. + Future setTypeIcon({required String name, String? icon}) => RustLib + .instance + .api + .crateApiGraphSynapseGraphSetTypeIcon(that: this, name: name, icon: icon); + /// 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); @@ -5523,7 +5761,8 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { String today() => RustLib.instance.api.crateApiGraphSynapseGraphToday(that: this); - /// Types in use (most used first) followed by the seeded suggestions not used yet. + /// Types in use (most used first), then defined unused types, then the seeded suggestions + /// not used yet; each with its icon. Future> typeCatalog() => RustLib.instance.api.crateApiGraphSynapseGraphTypeCatalog(that: this); diff --git a/app/test/support/memory_backend.dart b/app/test/support/memory_backend.dart index eae55ea..7d98713 100644 --- a/app/test/support/memory_backend.dart +++ b/app/test/support/memory_backend.dart @@ -267,7 +267,11 @@ class MemoryBackend implements GraphBackend { Future> outline(String pageId) async => _dto(pageId); @override - Future> backlinks(String pageId) async => []; + Future> backlinks(String pageId) async => + backlinkGroups[pageId] ?? []; + + /// Linked references returned by `backlinks`, by target page id (tests fill it). + final backlinkGroups = >{}; @override Future> related(String pageId, {int limit = 12}) async => []; @override @@ -286,7 +290,14 @@ class MemoryBackend implements GraphBackend { (p) => p.journalDate == null && p.title.toLowerCase().contains(q), ) .take(limit) - .map((p) => TitleHit(pageId: p.id, title: p.title, isAlias: false)) + .map( + (p) => TitleHit( + pageId: p.id, + title: p.title, + isAlias: false, + pageType: p.pageType, + ), + ) .toList(); } @@ -335,6 +346,7 @@ class MemoryBackend implements GraphBackend { title: p.title, isJournal: p.journalDate != null, isHub: p.isHub, + pageType: p.pageType, ); void _put( @@ -499,29 +511,160 @@ class MemoryBackend implements GraphBackend { return pages[pageId]!; } + /// Type definitions like the core's `type_defs`: key -> (name, icon, removed). + final typeDefs = {}; + + ({String name, String? icon, bool removed})? _liveDef(String name) { + final d = typeDefs[_tagKey(name)]; + return d == null || d.removed ? null : d; + } + @override Future> typeCatalog() async { final used = {}; for (final p in pages.values) { for (final t in [if (p.pageType != null) p.pageType!]) { final k = _tagKey(t); - used[k] = TagDto( - name: used[k]?.name ?? t, - count: (used[k]?.count ?? 0) + 1, + used[k] = _tag( + used[k]?.name ?? t, + (used[k]?.count ?? 0) + 1, suggested: suggestedTypes.contains(k), + icon: _liveDef(k)?.icon, ); } } final out = used.values.toList() - ..sort((a, b) => b.count.compareTo(a.count)); + ..sort((a, b) { + final c = b.count.compareTo(a.count); + return c != 0 ? c : _tagKey(a.name).compareTo(_tagKey(b.name)); + }); + final unused = + typeDefs.entries + .where( + (e) => + !e.value.removed && + !used.containsKey(e.key) && + !suggestedTypes.contains(e.key), + ) + .map((e) => e.value) + .toList() + ..sort((a, b) => _tagKey(a.name).compareTo(_tagKey(b.name))); + out.addAll(unused.map((d) => _tag(d.name, 0, icon: d.icon))); for (final s in suggestedTypes) { - if (!used.containsKey(s)) { - out.add(TagDto(name: s, count: 0, suggested: true)); + final d = typeDefs[s]; + if (!used.containsKey(s) && !(d?.removed ?? false)) { + out.add(_tag(d?.name ?? s, 0, suggested: true, icon: d?.icon)); } } return out; } + TagDto _tag( + String name, + int count, { + bool suggested = false, + String? icon, + int explicit = 0, + int typed = 0, + int fromHub = 0, + }) => TagDto( + name: name, + count: count, + suggested: suggested, + icon: icon, + explicit: explicit, + typed: typed, + fromHub: fromHub, + ); + + String _typeName(String raw) { + final n = _normTag(raw); + if (n.isEmpty) throw Exception('Empty type name'); + return n; + } + + /// Spelling of a type: its definition, else a page using it, else [name]. + String _typeSpelling(String name) { + final d = _liveDef(name); + if (d != null) return d.name; + for (final p in pages.values) { + if (p.pageType != null && _tagKey(p.pageType!) == _tagKey(name)) { + return p.pageType!; + } + } + return name; + } + + @override + Future createType(String name) async { + final n = _typeName(name); + final d = _liveDef(n); + if (d != null) return d.name; + final spelled = _typeSpelling(n); + typeDefs[_tagKey(n)] = (name: spelled, icon: null, removed: false); + return spelled; + } + + @override + Future setTypeIcon(String name, String? icon) async { + final n = _typeName(name); + final i = icon?.trim(); + if (i != null && + i.isNotEmpty && + (i.runes.length > 16 || + i.contains(RegExp(r'\s')) || + i.runes.every((r) => r < 128))) { + throw Exception('Not an emoji icon'); + } + typeDefs[_tagKey(n)] = ( + name: _typeSpelling(n), + icon: (i == null || i.isEmpty) ? null : i, + removed: false, + ); + } + + @override + Future renameType(String old, String new_) async { + _typeName(new_); + await createType(old); + return renameTag(old, new_); + } + + /// Moves a live type definition to [name] (`renameTag`, like the core). + void _renameTypeDef(String old, String name) { + final d = _liveDef(old); + if (d == null) return; + if (_tagKey(old) == _tagKey(name)) { + typeDefs[_tagKey(name)] = (name: name, icon: d.icon, removed: false); + return; + } + final target = _liveDef(name); + typeDefs[_tagKey(name)] = ( + name: name, + icon: target?.icon ?? d.icon, + removed: false, + ); + typeDefs[_tagKey(old)] = (name: d.name, icon: null, removed: true); + } + + @override + Future removeType(String name) async { + final n = _typeName(name); + var count = 0; + for (final p in pages.values.toList()) { + if (p.pageType != null && _tagKey(p.pageType!) == _tagKey(n)) { + _put(p, clearType: true); + count++; + } + } + typeDefs[_tagKey(n)] = ( + name: typeDefs[_tagKey(n)]?.name ?? n, + icon: null, + removed: true, + ); + return count; + } + @override Future addPageTag(String pageId, String tag) => setPageTags(pageId, [...pages[pageId]!.tags, tag]); @@ -537,12 +680,17 @@ class MemoryBackend implements GraphBackend { Future> tagCatalog() async { final used = {}; for (final p in pages.values) { + final hub = _hubTag(p); for (final t in allTags(p)) { final k = _tagKey(t); - used[k] = TagDto( - name: used[k]?.name ?? t, - count: (used[k]?.count ?? 0) + 1, - suggested: false, + final prev = used[k]; + bool isK(String? x) => x != null && _tagKey(x) == k; + used[k] = _tag( + prev?.name ?? t, + (prev?.count ?? 0) + 1, + explicit: (prev?.explicit ?? 0) + (p.tags.any(isK) ? 1 : 0), + typed: (prev?.typed ?? 0) + (isK(p.pageType) ? 1 : 0), + fromHub: (prev?.fromHub ?? 0) + (isK(hub) ? 1 : 0), ); } } @@ -581,6 +729,7 @@ class MemoryBackend implements GraphBackend { _put(p, tags: tags, pageType: hasType ? name : null); n++; } + _renameTypeDef(old, name); return n; } @@ -985,6 +1134,7 @@ class MemoryBackend implements GraphBackend { homeHub: home[ids[i]] == null ? null : index[home[ids[i]]!], tags: allTags(pages[ids[i]]!), isTag: false, + pageType: pages[ids[i]]!.pageType, ), for (var j = 0; j < tagKeys.length; j++) GraphNode( diff --git a/crates/synapse-core/src/types.rs b/crates/synapse-core/src/types.rs index d54c5c4..d504f65 100644 --- a/crates/synapse-core/src/types.rs +++ b/crates/synapse-core/src/types.rs @@ -154,6 +154,23 @@ impl Graph { Ok(out) } + /// The type of every typed page. + pub fn all_page_types(&self) -> Result> { + let mut st = self + .conn() + .prepare_cached("SELECT id, types FROM pages WHERE types != '[]'")?; + let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?; + let mut out = HashMap::new(); + for row in rows { + let (id, types) = row?; + let types: Vec = serde_json::from_str(&types).unwrap_or_default(); + if let Some(t) = types.into_iter().next() { + out.insert(crate::store::parse_id(&id)?, t); + } + } + Ok(out) + } + /// Every stored type definition (removed ones included), by name key. pub fn type_defs(&self) -> Result> { let mut st = self diff --git a/crates/synapse-ffi/src/api/dto.rs b/crates/synapse-ffi/src/api/dto.rs index 4732f3e..44927e0 100644 --- a/crates/synapse-ffi/src/api/dto.rs +++ b/crates/synapse-ffi/src/api/dto.rs @@ -50,6 +50,28 @@ pub struct TagDto { pub count: u32, /// One of the seeded suggestions. pub suggested: bool, + /// Emoji of a type (types only). + pub icon: Option, + /// Pages listing it as an explicit tag (tags only). + pub explicit: u32, + /// Pages having it as their type (tags only). + pub typed: u32, + /// Pages carrying it through their hub (tags only; hub tags cannot be renamed or removed). + pub from_hub: u32, +} + +impl From for TagDto { + fn from(t: synapse_core::TagInfo) -> Self { + Self { + name: t.name, + count: t.count, + suggested: t.suggested, + icon: t.icon, + explicit: t.explicit, + typed: t.typed, + from_hub: t.from_hub, + } + } } /// One row of the outline, in pre-order. @@ -110,6 +132,8 @@ pub struct BacklinkGroup { pub page_id: String, pub page_title: String, pub is_journal: bool, + /// Type of the referencing page (for its icon). + pub page_type: Option, pub blocks: Vec, } @@ -119,6 +143,8 @@ pub struct PageBrief { pub title: String, pub is_journal: bool, pub is_hub: bool, + /// The page's type (the UI shows its icon next to the title). + pub page_type: Option, } impl From<&Page> for PageBrief { @@ -128,6 +154,7 @@ impl From<&Page> for PageBrief { title: p.title.clone(), is_journal: p.is_journal(), is_hub: p.is_hub(), + page_type: p.page_type().map(String::from), } } } @@ -185,6 +212,8 @@ pub struct TitleHit { /// The matched title or alias. pub title: String, pub is_alias: bool, + /// Type of the page (for its icon). + pub page_type: Option, } /// A block matching a search (`((` autocomplete, quick switcher content results). @@ -240,6 +269,8 @@ pub struct GraphNode { /// 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 page's type (tree labels show its icon; the network view does not). + pub page_type: Option, } /// The whole page-level graph, edges as parallel arrays (cheap to move across the FFI). diff --git a/crates/synapse-ffi/src/api/graph.rs b/crates/synapse-ffi/src/api/graph.rs index b0c457f..28e2bf0 100644 --- a/crates/synapse-ffi/src/api/graph.rs +++ b/crates/synapse-ffi/src/api/graph.rs @@ -209,15 +209,23 @@ impl SynapseGraph { if !seen.insert(bl.block.id) { continue; } - let i = *index.entry(bl.block.page_id).or_insert_with(|| { - groups.push(BacklinkGroup { - page_id: bl.block.page_id.to_string(), - page_title: bl.page_title.clone(), - is_journal: parse_day(&bl.page_title).is_some(), - blocks: Vec::new(), - }); - groups.len() - 1 - }); + let i = match index.get(&bl.block.page_id) { + Some(&i) => i, + None => { + let page_type = g + .get_page(bl.block.page_id)? + .and_then(|p| p.page_type().map(String::from)); + groups.push(BacklinkGroup { + page_id: bl.block.page_id.to_string(), + page_title: bl.page_title.clone(), + is_journal: parse_day(&bl.page_title).is_some(), + page_type, + blocks: Vec::new(), + }); + index.insert(bl.block.page_id, groups.len() - 1); + groups.len() - 1 + } + }; groups[i].blocks.push(BlockDto::new(0, &bl.block, false)); } Ok(groups) diff --git a/crates/synapse-ffi/src/api/graph_view.rs b/crates/synapse-ffi/src/api/graph_view.rs index e7647b8..5abae7b 100644 --- a/crates/synapse-ffi/src/api/graph_view.rs +++ b/crates/synapse-ffi/src/api/graph_view.rs @@ -83,6 +83,11 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result { .into_iter() .map(|(id, t)| (id.to_string(), t)) .collect(); + let mut page_types: HashMap = g + .all_page_types()? + .into_iter() + .map(|(id, t)| (id.to_string(), t)) + .collect(); { let mut st = conn.prepare( "SELECT id, title, journal_date, origin_journal, created_at FROM pages @@ -100,6 +105,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result { })?; for row in rows { let (id, title, journal_date, origin_journal, created_at) = row?; + let page_type = page_types.remove(&id); let tags = page_tags.get(&id).cloned().unwrap_or_default(); index.insert(id.clone(), nodes.len() as u32); nodes.push(GraphNode { @@ -116,6 +122,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result { home_hub: None, tags, is_tag: false, + page_type, }); } } @@ -328,6 +335,7 @@ fn tagged( home_hub: None, tags: Vec::new(), is_tag: true, + page_type: None, }); nodes.len() as u32 - 1 }); diff --git a/crates/synapse-ffi/src/api/search.rs b/crates/synapse-ffi/src/api/search.rs index 3bf8d34..669a5e9 100644 --- a/crates/synapse-ffi/src/api/search.rs +++ b/crates/synapse-ffi/src/api/search.rs @@ -23,6 +23,7 @@ impl SynapseGraph { page_id: p.id.to_string(), title: p.title.clone(), is_alias: false, + page_type: p.page_type().map(String::from), }) .collect()); } @@ -52,13 +53,15 @@ impl SynapseGraph { hits.truncate(limit as usize); let mut out = Vec::with_capacity(hits.len()); for (_, _, title, id) in hits { - let is_alias = g - .get_page(id)? + let page = g.get_page(id)?; + let is_alias = page + .as_ref() .is_some_and(|p| title_key(&p.title) != title_key(&title)); out.push(TitleHit { page_id: id.to_string(), title, is_alias, + page_type: page.and_then(|p| p.page_type().map(String::from)), }); } Ok(out) diff --git a/crates/synapse-ffi/src/api/tags.rs b/crates/synapse-ffi/src/api/tags.rs index 571d6c0..fcfcbf3 100644 --- a/crates/synapse-ffi/src/api/tags.rs +++ b/crates/synapse-ffi/src/api/tags.rs @@ -42,11 +42,7 @@ impl SynapseGraph { .lock() .tag_catalog()? .into_iter() - .map(|t| TagDto { - name: t.name, - count: t.count, - suggested: t.suggested, - }) + .map(TagDto::from) .collect()) } @@ -72,17 +68,34 @@ impl SynapseGraph { )?)) } - /// Types in use (most used first) followed by the seeded suggestions not used yet. + /// Adds a type to the vocabulary even if no page uses it; returns its spelling. + pub fn create_type(&self, name: String) -> Result { + Ok(self.lock().create_type(&name)?) + } + + /// Sets (or with `None` clears) the emoji of a type, defining the type if needed. + pub fn set_type_icon(&self, name: String, icon: Option) -> Result<()> { + Ok(self.lock().set_type_icon(&name, icon.as_deref())?) + } + + /// Renames a type (and same-name tags), keeping its icon; returns the pages changed. + pub fn rename_type(&self, old: String, new: String) -> Result { + Ok(self.lock().rename_type(&old, &new)? as u32) + } + + /// Deletes a type: its pages lose it and its icon is dropped; returns the pages changed. + pub fn remove_type(&self, name: String) -> Result { + Ok(self.lock().remove_type(&name)? as u32) + } + + /// Types in use (most used first), then defined unused types, then the seeded suggestions + /// not used yet; each with its icon. pub fn type_catalog(&self) -> Result> { Ok(self .lock() .type_catalog()? .into_iter() - .map(|t| TagDto { - name: t.name, - count: t.count, - suggested: t.suggested, - }) + .map(TagDto::from) .collect()) } } diff --git a/crates/synapse-ffi/src/frb_generated.rs b/crates/synapse-ffi/src/frb_generated.rs index d9ecec6..da2e78d 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 = -1472342481; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 272705018; // Section: executor @@ -921,6 +921,61 @@ fn wire__crate__api__graph__SynapseGraph_create_page_from_template_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_create_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_create_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_name = ::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::create_type( + &*api_that_guard, + api_name, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_delete_block_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -2722,6 +2777,61 @@ fn wire__crate__api__graph__SynapseGraph_remove_tag_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_remove_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_remove_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_name = ::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::remove_type( + &*api_that_guard, + api_name, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_rename_page_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -2836,6 +2946,63 @@ fn wire__crate__api__graph__SynapseGraph_rename_tag_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_rename_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_rename_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_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_type( + &*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, @@ -3178,6 +3345,63 @@ fn wire__crate__api__graph__SynapseGraph_set_page_type_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_set_type_icon_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_set_type_icon", + 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_name = ::sse_decode(&mut deserializer); + let api_icon = >::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::set_type_icon( + &*api_that_guard, + api_name, + api_icon, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_tag_catalog_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -3533,11 +3757,13 @@ impl SseDecode for crate::api::dto::BacklinkGroup { let mut var_pageId = ::sse_decode(deserializer); let mut var_pageTitle = ::sse_decode(deserializer); let mut var_isJournal = ::sse_decode(deserializer); + let mut var_pageType = >::sse_decode(deserializer); let mut var_blocks = >::sse_decode(deserializer); return crate::api::dto::BacklinkGroup { page_id: var_pageId, page_title: var_pageTitle, is_journal: var_isJournal, + page_type: var_pageType, blocks: var_blocks, }; } @@ -3657,6 +3883,7 @@ impl SseDecode for crate::api::dto::GraphNode { let mut var_homeHub = >::sse_decode(deserializer); let mut var_tags = >::sse_decode(deserializer); let mut var_isTag = ::sse_decode(deserializer); + let mut var_pageType = >::sse_decode(deserializer); return crate::api::dto::GraphNode { id: var_id, title: var_title, @@ -3671,6 +3898,7 @@ impl SseDecode for crate::api::dto::GraphNode { home_hub: var_homeHub, tags: var_tags, is_tag: var_isTag, + page_type: var_pageType, }; } } @@ -4073,11 +4301,13 @@ impl SseDecode for crate::api::dto::PageBrief { let mut var_title = ::sse_decode(deserializer); let mut var_isJournal = ::sse_decode(deserializer); let mut var_isHub = ::sse_decode(deserializer); + let mut var_pageType = >::sse_decode(deserializer); return crate::api::dto::PageBrief { id: var_id, title: var_title, is_journal: var_isJournal, is_hub: var_isHub, + page_type: var_pageType, }; } } @@ -4201,10 +4431,18 @@ impl SseDecode for crate::api::dto::TagDto { let mut var_name = ::sse_decode(deserializer); let mut var_count = ::sse_decode(deserializer); let mut var_suggested = ::sse_decode(deserializer); + let mut var_icon = >::sse_decode(deserializer); + let mut var_explicit = ::sse_decode(deserializer); + let mut var_typed = ::sse_decode(deserializer); + let mut var_fromHub = ::sse_decode(deserializer); return crate::api::dto::TagDto { name: var_name, count: var_count, suggested: var_suggested, + icon: var_icon, + explicit: var_explicit, + typed: var_typed, + from_hub: var_fromHub, }; } } @@ -4243,10 +4481,12 @@ impl SseDecode for crate::api::dto::TitleHit { let mut var_pageId = ::sse_decode(deserializer); let mut var_title = ::sse_decode(deserializer); let mut var_isAlias = ::sse_decode(deserializer); + let mut var_pageType = >::sse_decode(deserializer); return crate::api::dto::TitleHit { page_id: var_pageId, title: var_title, is_alias: var_isAlias, + page_type: var_pageType, }; } } @@ -4337,211 +4577,235 @@ fn pde_ffi_dispatcher_primary_impl( rust_vec_len, data_len, ), - 17 => wire__crate__api__graph__SynapseGraph_delete_block_impl( + 17 => wire__crate__api__graph__SynapseGraph_create_type_impl( port, ptr, rust_vec_len, data_len, ), - 18 => wire__crate__api__graph__SynapseGraph_delete_page_impl( + 18 => wire__crate__api__graph__SynapseGraph_delete_block_impl( port, ptr, rust_vec_len, data_len, ), - 20 => { + 19 => wire__crate__api__graph__SynapseGraph_delete_page_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 21 => { wire__crate__api__graph__SynapseGraph_graph_data_impl(port, ptr, rust_vec_len, data_len) } - 21 => wire__crate__api__graph__SynapseGraph_hub_conversion_preview_impl( + 22 => wire__crate__api__graph__SynapseGraph_hub_conversion_preview_impl( port, ptr, rust_vec_len, data_len, ), - 22 => wire__crate__api__graph__SynapseGraph_hub_template_impl( + 23 => wire__crate__api__graph__SynapseGraph_hub_template_impl( port, ptr, rust_vec_len, data_len, ), - 23 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len), - 24 => wire__crate__api__graph__SynapseGraph_indent_block_impl( + 24 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len), + 25 => wire__crate__api__graph__SynapseGraph_indent_block_impl( port, ptr, rust_vec_len, data_len, ), - 25 => wire__crate__api__graph__SynapseGraph_insert_block_impl( + 26 => wire__crate__api__graph__SynapseGraph_insert_block_impl( port, ptr, rust_vec_len, data_len, ), - 26 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len), - 27 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl( + 27 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len), + 28 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl( port, ptr, rust_vec_len, data_len, ), - 28 => { + 29 => { wire__crate__api__graph__SynapseGraph_journals_impl(port, ptr, rust_vec_len, data_len) } - 29 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl( + 30 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl( port, ptr, rust_vec_len, data_len, ), - 30 => { + 31 => { wire__crate__api__graph__SynapseGraph_list_pages_impl(port, ptr, rust_vec_len, data_len) } - 31 => wire__crate__api__graph__SynapseGraph_merge_block_impl( + 32 => wire__crate__api__graph__SynapseGraph_merge_block_impl( port, ptr, rust_vec_len, data_len, ), - 32 => { + 33 => { wire__crate__api__graph__SynapseGraph_move_block_impl(port, ptr, rust_vec_len, data_len) } - 33 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), - 34 => { + 34 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), + 35 => { wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len) } - 35 => wire__crate__api__graph__SynapseGraph_outdent_block_impl( + 36 => wire__crate__api__graph__SynapseGraph_outdent_block_impl( port, ptr, rust_vec_len, data_len, ), - 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( + 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( port, ptr, rust_vec_len, data_len, ), - 39 => wire__crate__api__graph__SynapseGraph_page_structure_impl( + 40 => wire__crate__api__graph__SynapseGraph_page_structure_impl( port, ptr, rust_vec_len, data_len, ), - 40 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( + 41 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl( port, ptr, rust_vec_len, data_len, ), - 41 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( + 42 => wire__crate__api__graph__SynapseGraph_purge_pages_impl( port, ptr, rust_vec_len, data_len, ), - 42 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( + 43 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl( port, ptr, rust_vec_len, data_len, ), - 43 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( + 44 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl( port, ptr, rust_vec_len, data_len, ), - 44 => wire__crate__api__graph__SynapseGraph_record_visit_impl( + 45 => wire__crate__api__graph__SynapseGraph_record_visit_impl( port, ptr, rust_vec_len, data_len, ), - 45 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), - 46 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( + 46 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), + 47 => wire__crate__api__graph__SynapseGraph_remove_alias_impl( port, ptr, rust_vec_len, data_len, ), - 47 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( + 48 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl( port, ptr, rust_vec_len, data_len, ), - 48 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( + 49 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( port, ptr, rust_vec_len, data_len, ), - 49 => { + 50 => { wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len) } - 50 => wire__crate__api__graph__SynapseGraph_rename_page_impl( + 51 => wire__crate__api__graph__SynapseGraph_remove_type_impl( port, ptr, rust_vec_len, data_len, ), - 51 => { + 52 => wire__crate__api__graph__SynapseGraph_rename_page_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 53 => { wire__crate__api__graph__SynapseGraph_rename_tag_impl(port, ptr, rust_vec_len, data_len) } - 52 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( + 54 => wire__crate__api__graph__SynapseGraph_rename_type_impl( port, ptr, rust_vec_len, data_len, ), - 53 => wire__crate__api__graph__SynapseGraph_search_titles_impl( + 55 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( port, ptr, rust_vec_len, data_len, ), - 54 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( + 56 => wire__crate__api__graph__SynapseGraph_search_titles_impl( port, ptr, rust_vec_len, data_len, ), - 55 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( + 57 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( port, ptr, rust_vec_len, data_len, ), - 56 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( + 58 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( port, ptr, rust_vec_len, data_len, ), - 57 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( + 59 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( port, ptr, rust_vec_len, data_len, ), - 58 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( + 60 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( port, ptr, rust_vec_len, data_len, ), - 59 => { + 61 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 62 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 63 => { wire__crate__api__graph__SynapseGraph_timeline_impl(port, ptr, rust_vec_len, data_len) } - 61 => wire__crate__api__graph__SynapseGraph_type_catalog_impl( + 65 => wire__crate__api__graph__SynapseGraph_type_catalog_impl( port, ptr, rust_vec_len, data_len, ), - 62 => wire__crate__api__graph__SynapseGraph_update_block_impl( + 66 => wire__crate__api__graph__SynapseGraph_update_block_impl( port, ptr, rust_vec_len, @@ -4561,8 +4825,8 @@ fn pde_ffi_dispatcher_sync_impl( match func_id { 1 => wire__crate__api__layout__ForceLayout_new_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), + 20 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len), + 64 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -4624,6 +4888,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::BacklinkGroup { self.page_id.into_into_dart().into_dart(), self.page_title.into_into_dart().into_dart(), self.is_journal.into_into_dart().into_dart(), + self.page_type.into_into_dart().into_dart(), self.blocks.into_into_dart().into_dart(), ] .into_dart() @@ -4751,6 +5016,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::GraphNode { self.home_hub.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(), ] .into_dart() } @@ -4893,6 +5159,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::PageBrief { self.title.into_into_dart().into_dart(), self.is_journal.into_into_dart().into_dart(), self.is_hub.into_into_dart().into_dart(), + self.page_type.into_into_dart().into_dart(), ] .into_dart() } @@ -5030,6 +5297,10 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::TagDto { self.name.into_into_dart().into_dart(), self.count.into_into_dart().into_dart(), self.suggested.into_into_dart().into_dart(), + self.icon.into_into_dart().into_dart(), + self.explicit.into_into_dart().into_dart(), + self.typed.into_into_dart().into_dart(), + self.from_hub.into_into_dart().into_dart(), ] .into_dart() } @@ -5088,6 +5359,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::TitleHit { self.page_id.into_into_dart().into_dart(), self.title.into_into_dart().into_dart(), self.is_alias.into_into_dart().into_dart(), + self.page_type.into_into_dart().into_dart(), ] .into_dart() } @@ -5165,6 +5437,7 @@ impl SseEncode for crate::api::dto::BacklinkGroup { ::sse_encode(self.page_id, serializer); ::sse_encode(self.page_title, serializer); ::sse_encode(self.is_journal, serializer); + >::sse_encode(self.page_type, serializer); >::sse_encode(self.blocks, serializer); } } @@ -5251,6 +5524,7 @@ impl SseEncode for crate::api::dto::GraphNode { >::sse_encode(self.home_hub, serializer); >::sse_encode(self.tags, serializer); ::sse_encode(self.is_tag, serializer); + >::sse_encode(self.page_type, serializer); } } @@ -5574,6 +5848,7 @@ impl SseEncode for crate::api::dto::PageBrief { ::sse_encode(self.title, serializer); ::sse_encode(self.is_journal, serializer); ::sse_encode(self.is_hub, serializer); + >::sse_encode(self.page_type, serializer); } } @@ -5664,6 +5939,10 @@ impl SseEncode for crate::api::dto::TagDto { ::sse_encode(self.name, serializer); ::sse_encode(self.count, serializer); ::sse_encode(self.suggested, serializer); + >::sse_encode(self.icon, serializer); + ::sse_encode(self.explicit, serializer); + ::sse_encode(self.typed, serializer); + ::sse_encode(self.from_hub, serializer); } } @@ -5691,6 +5970,7 @@ impl SseEncode for crate::api::dto::TitleHit { ::sse_encode(self.page_id, serializer); ::sse_encode(self.title, serializer); ::sse_encode(self.is_alias, serializer); + >::sse_encode(self.page_type, serializer); } } diff --git a/crates/synapse-ffi/tests/api.rs b/crates/synapse-ffi/tests/api.rs index 7225d39..9f679cf 100644 --- a/crates/synapse-ffi/tests/api.rs +++ b/crates/synapse-ffi/tests/api.rs @@ -506,6 +506,52 @@ fn page_type_and_tag_renaming_round_trip_through_the_api() { assert!(g.set_page_type(a, None).unwrap().page_type.is_none()); } +#[test] +fn type_icons_and_page_types_reach_the_ui_dtos() { + let (_d, g) = open(); + let (a, _) = page_with(&g, "Ana", &["x"]); + let (b, _) = page_with(&g, "Notes", &["about [[Ana]]"]); + g.set_page_type(a.clone(), Some("persona".into())).unwrap(); + g.set_page_type(b.clone(), Some("idea".into())).unwrap(); + g.set_type_icon("persona".into(), Some("🧑".into())) + .unwrap(); + assert!( + g.set_type_icon("persona".into(), Some("xy".into())) + .is_err() + ); + assert_eq!(g.create_type(" Libro ".into()).unwrap(), "Libro"); + let cat = g.type_catalog().unwrap(); + let persona = cat.iter().find(|t| t.name == "persona").unwrap(); + assert_eq!((persona.count, persona.icon.as_deref()), (1, Some("🧑"))); + assert!(cat.iter().any(|t| t.name == "Libro" && t.count == 0)); + assert!(cat.iter().any(|t| t.name == "sueño" && t.count == 0)); + + // Lists of pages carry the page type, so the UI can look up its icon. + let hits = g.search_titles("Ana".into(), 5).unwrap(); + assert_eq!(hits[0].page_type.as_deref(), Some("persona")); + let bl = g.backlinks(a.clone()).unwrap(); + assert_eq!(bl[0].page_type.as_deref(), Some("idea")); + let briefs = g.pages_with_tag("persona".into()).unwrap(); + assert_eq!(briefs[0].page_type.as_deref(), Some("persona")); + let data = g.graph_data().unwrap(); + let node = data.nodes.iter().find(|n| n.id == a).unwrap(); + assert_eq!(node.page_type.as_deref(), Some("persona")); + + // Rename keeps the icon; remove drops the type from its pages. + assert_eq!(g.rename_type("persona".into(), "Gente".into()).unwrap(), 1); + let cat = g.type_catalog().unwrap(); + let gente = cat.iter().find(|t| t.name == "Gente").unwrap(); + assert_eq!(gente.icon.as_deref(), Some("🧑")); + assert_eq!(g.remove_type("Gente".into()).unwrap(), 1); + assert!(g.page(a).unwrap().unwrap().page.page_type.is_none()); + + // The tag catalog says where tags come from. + g.add_page_tag(b.clone(), "idea".into()).unwrap(); + let tags = g.tag_catalog().unwrap(); + let idea = tags.iter().find(|t| t.name == "idea").unwrap(); + assert_eq!((idea.explicit, idea.typed, idea.from_hub), (1, 1, 0)); +} + #[test] fn a_hub_tag_and_a_same_name_type_need_no_tag_node_beside_the_hub() { let (_d, g) = open();