diff --git a/Cargo.lock b/Cargo.lock index 90680a7..69ad914 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3479,7 +3479,9 @@ dependencies = [ "anyhow", "chrono", "flutter_rust_bridge", + "serde_json", "synapse-core", + "synapse-modules", "tempfile", "uuid", ] diff --git a/app/lib/src/rust/api/dto.dart b/app/lib/src/rust/api/dto.dart index 17dfdcd..f3171f4 100644 --- a/app/lib/src/rust/api/dto.dart +++ b/app/lib/src/rust/api/dto.dart @@ -7,8 +7,8 @@ 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`, `from` +// These functions are ignored because they are not marked as `pub`: `new`, `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`, `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`, `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`, `fmt`, `fmt`, `from`, `from`, `from` class AssetDto { final String hash; @@ -505,6 +505,95 @@ class LegacyCandidate { preselected == other.preselected; } +/// An installed (or inspected) module. +class ModuleDto { + final String id; + final String name; + final String version; + final String description; + final String author; + + /// `storage`, `crypto`, `clipboard`, `pages:read`, `pages:write`. + final List permissions; + final List views; + + /// Block macros (`{{name args}}`) it renders. + final List macros; + + /// How often the app sends it a `tick` request, if at all. + final int? tickSeconds; + final bool enabled; + + /// Size of the module file in bytes. + final BigInt size; + + const ModuleDto({ + required this.id, + required this.name, + required this.version, + required this.description, + required this.author, + required this.permissions, + required this.views, + required this.macros, + this.tickSeconds, + required this.enabled, + required this.size, + }); + + @override + int get hashCode => + id.hashCode ^ + name.hashCode ^ + version.hashCode ^ + description.hashCode ^ + author.hashCode ^ + permissions.hashCode ^ + views.hashCode ^ + macros.hashCode ^ + tickSeconds.hashCode ^ + enabled.hashCode ^ + size.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is ModuleDto && + runtimeType == other.runtimeType && + id == other.id && + name == other.name && + version == other.version && + description == other.description && + author == other.author && + permissions == other.permissions && + views == other.views && + macros == other.macros && + tickSeconds == other.tickSeconds && + enabled == other.enabled && + size == other.size; +} + +/// A view a module adds to the sidebar. +class ModuleViewDto { + final String id; + final String title; + final String? icon; + + const ModuleViewDto({required this.id, required this.title, this.icon}); + + @override + int get hashCode => id.hashCode ^ title.hashCode ^ icon.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is ModuleViewDto && + runtimeType == other.runtimeType && + id == other.id && + title == other.title && + icon == other.icon; +} + /// A level of a namespace (`A/B` under `A`); `id` is `None` when only deeper pages exist. class NamespaceEntry { final String title; diff --git a/app/lib/src/rust/api/graph.dart b/app/lib/src/rust/api/graph.dart index 7e00568..4b56e84 100644 --- a/app/lib/src/rust/api/graph.dart +++ b/app/lib/src/rust/api/graph.dart @@ -92,6 +92,15 @@ abstract class SynapseGraph implements RustOpaqueInterface { required String content, }); + /// Reads and validates a module file without installing it (for the consent dialog). + Future inspectModule({required List wasm}); + + /// Installs or updates a module; `granted` must list every permission it asks for. + Future installModule({ + required List wasm, + required List granted, + }); + /// The journal of `date` (created if missing). Future journal({required String date}); @@ -120,6 +129,12 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// block's slot when `into` is its parent, otherwise they become last children of `into`. Future> mergeBlock({required String id, required String into}); + /// Sends a JSON request to a module and returns its JSON response. + Future moduleCall({required String id, required String request}); + + /// Installed modules, by name. + Future> modules(); + /// Moves a block with its subtree (drag and drop), possibly to another page. Future> moveBlock({ required String id, @@ -218,6 +233,8 @@ abstract class SynapseGraph implements RustOpaqueInterface { required String description, }); + Future setModuleEnabled({required String id, required bool enabled}); + /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot /// be tagged. Future setPageTags({ @@ -232,6 +249,9 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// Sets (or with `None` clears) the emoji of a type, defining the type if needed. Future setTypeIcon({required String name, String? icon}); + /// Stops a module's running instance (dropping its in-memory state). + Future stopModule({required String id}); + /// Every tag in use (listed or implied by a type) with its number of pages, most used first. Future> tagCatalog(); @@ -245,6 +265,10 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// not used yet; each with its icon. Future> typeCatalog(); + /// Removes a module from this device; `delete_data` also deletes its synced data on every + /// device. + Future uninstallModule({required String id, required bool deleteData}); + /// Replaces a block's Markdown (the debounced save while typing). Future updateBlock({required String id, required String content}); } diff --git a/app/lib/src/rust/frb_generated.dart b/app/lib/src/rust/frb_generated.dart index a844c8c..7416cc5 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 => 272705018; + int get rustContentHash => -821319892; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -220,6 +220,17 @@ abstract class RustLibApi extends BaseApi { required String content, }); + Future crateApiGraphSynapseGraphInspectModule({ + required SynapseGraph that, + required List wasm, + }); + + Future crateApiGraphSynapseGraphInstallModule({ + required SynapseGraph that, + required List wasm, + required List granted, + }); + Future crateApiGraphSynapseGraphJournal({ required SynapseGraph that, required String date, @@ -253,6 +264,16 @@ abstract class RustLibApi extends BaseApi { required String into, }); + Future crateApiGraphSynapseGraphModuleCall({ + required SynapseGraph that, + required String id, + required String request, + }); + + Future> crateApiGraphSynapseGraphModules({ + required SynapseGraph that, + }); + Future> crateApiGraphSynapseGraphMoveBlock({ required SynapseGraph that, required String id, @@ -396,6 +417,12 @@ abstract class RustLibApi extends BaseApi { required String description, }); + Future crateApiGraphSynapseGraphSetModuleEnabled({ + required SynapseGraph that, + required String id, + required bool enabled, + }); + Future crateApiGraphSynapseGraphSetPageTags({ required SynapseGraph that, required String pageId, @@ -414,6 +441,11 @@ abstract class RustLibApi extends BaseApi { String? icon, }); + Future crateApiGraphSynapseGraphStopModule({ + required SynapseGraph that, + required String id, + }); + Future> crateApiGraphSynapseGraphTagCatalog({ required SynapseGraph that, }); @@ -430,6 +462,12 @@ abstract class RustLibApi extends BaseApi { required SynapseGraph that, }); + Future crateApiGraphSynapseGraphUninstallModule({ + required SynapseGraph that, + required String id, + required bool deleteData, + }); + Future crateApiGraphSynapseGraphUpdateBlock({ required SynapseGraph that, required String id, @@ -1455,6 +1493,84 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "pageId", "place", "content"], ); + @override + Future crateApiGraphSynapseGraphInspectModule({ + required SynapseGraph that, + required List wasm, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_list_prim_u_8_loose(wasm, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 27, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_module_dto, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphInspectModuleConstMeta, + argValues: [that, wasm], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphInspectModuleConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_inspect_module", + argNames: ["that", "wasm"], + ); + + @override + Future crateApiGraphSynapseGraphInstallModule({ + required SynapseGraph that, + required List wasm, + required List granted, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_list_prim_u_8_loose(wasm, serializer); + sse_encode_list_String(granted, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 28, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_module_dto, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphInstallModuleConstMeta, + argValues: [that, wasm, granted], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphInstallModuleConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_install_module", + argNames: ["that", "wasm", "granted"], + ); + @override Future crateApiGraphSynapseGraphJournal({ required SynapseGraph that, @@ -1472,7 +1588,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 27, + funcId: 29, port: port_, ); }, @@ -1510,7 +1626,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 28, + funcId: 30, port: port_, ); }, @@ -1550,7 +1666,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 29, + funcId: 31, port: port_, ); }, @@ -1586,7 +1702,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 30, + funcId: 32, port: port_, ); }, @@ -1628,7 +1744,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 31, + funcId: 33, port: port_, ); }, @@ -1668,7 +1784,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 32, + funcId: 34, port: port_, ); }, @@ -1689,6 +1805,82 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "id", "into"], ); + @override + Future crateApiGraphSynapseGraphModuleCall({ + required SynapseGraph that, + required String id, + required String request, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(id, serializer); + sse_encode_String(request, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 35, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_String, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphModuleCallConstMeta, + argValues: [that, id, request], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphModuleCallConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_module_call", + argNames: ["that", "id", "request"], + ); + + @override + Future> crateApiGraphSynapseGraphModules({ + required SynapseGraph that, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 36, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_list_module_dto, + decodeErrorData: null, + ), + constMeta: kCrateApiGraphSynapseGraphModulesConstMeta, + argValues: [that], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphModulesConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_modules", + argNames: ["that"], + ); + @override Future> crateApiGraphSynapseGraphMoveBlock({ required SynapseGraph that, @@ -1710,7 +1902,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 33, + funcId: 37, port: port_, ); }, @@ -1741,7 +1933,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 34, + funcId: 38, port: port_, ); }, @@ -1777,7 +1969,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 35, + funcId: 39, port: port_, ); }, @@ -1815,7 +2007,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 36, + funcId: 40, port: port_, ); }, @@ -1853,7 +2045,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 37, + funcId: 41, port: port_, ); }, @@ -1891,7 +2083,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 38, + funcId: 42, port: port_, ); }, @@ -1929,7 +2121,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 39, + funcId: 43, port: port_, ); }, @@ -1967,7 +2159,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 40, + funcId: 44, port: port_, ); }, @@ -2005,7 +2197,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 41, + funcId: 45, port: port_, ); }, @@ -2043,7 +2235,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 42, + funcId: 46, port: port_, ); }, @@ -2085,7 +2277,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 43, + funcId: 47, port: port_, ); }, @@ -2125,7 +2317,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 44, + funcId: 48, port: port_, ); }, @@ -2165,7 +2357,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 45, + funcId: 49, port: port_, ); }, @@ -2205,7 +2397,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 46, + funcId: 50, port: port_, ); }, @@ -2243,7 +2435,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 47, + funcId: 51, port: port_, ); }, @@ -2283,7 +2475,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 48, + funcId: 52, port: port_, ); }, @@ -2323,7 +2515,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 49, + funcId: 53, port: port_, ); }, @@ -2361,7 +2553,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 50, + funcId: 54, port: port_, ); }, @@ -2399,7 +2591,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 51, + funcId: 55, port: port_, ); }, @@ -2439,7 +2631,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 52, + funcId: 56, port: port_, ); }, @@ -2479,7 +2671,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 53, + funcId: 57, port: port_, ); }, @@ -2519,7 +2711,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 54, + funcId: 58, port: port_, ); }, @@ -2559,7 +2751,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 55, + funcId: 59, port: port_, ); }, @@ -2599,7 +2791,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 56, + funcId: 60, port: port_, ); }, @@ -2639,7 +2831,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 57, + funcId: 61, port: port_, ); }, @@ -2679,7 +2871,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 58, + funcId: 62, port: port_, ); }, @@ -2700,6 +2892,46 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "hubId", "description"], ); + @override + Future crateApiGraphSynapseGraphSetModuleEnabled({ + required SynapseGraph that, + required String id, + required bool enabled, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(id, serializer); + sse_encode_bool(enabled, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 63, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphSetModuleEnabledConstMeta, + argValues: [that, id, enabled], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphSetModuleEnabledConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_set_module_enabled", + argNames: ["that", "id", "enabled"], + ); + @override Future crateApiGraphSynapseGraphSetPageTags({ required SynapseGraph that, @@ -2719,7 +2951,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 59, + funcId: 64, port: port_, ); }, @@ -2759,7 +2991,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 60, + funcId: 65, port: port_, ); }, @@ -2799,7 +3031,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 61, + funcId: 66, port: port_, ); }, @@ -2820,6 +3052,44 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that", "name", "icon"], ); + @override + Future crateApiGraphSynapseGraphStopModule({ + required SynapseGraph that, + required String id, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(id, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 67, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: null, + ), + constMeta: kCrateApiGraphSynapseGraphStopModuleConstMeta, + argValues: [that, id], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphStopModuleConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_stop_module", + argNames: ["that", "id"], + ); + @override Future> crateApiGraphSynapseGraphTagCatalog({ required SynapseGraph that, @@ -2835,7 +3105,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 62, + funcId: 68, port: port_, ); }, @@ -2875,7 +3145,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 63, + funcId: 69, port: port_, ); }, @@ -2906,7 +3176,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { that, serializer, ); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 64)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 70)!; }, codec: SseCodec( decodeSuccessData: sse_decode_String, @@ -2937,7 +3207,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 65, + funcId: 71, port: port_, ); }, @@ -2958,6 +3228,46 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["that"], ); + @override + Future crateApiGraphSynapseGraphUninstallModule({ + required SynapseGraph that, + required String id, + required bool deleteData, + }) { + return handler.executeNormal( + NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerSynapseGraph( + that, + serializer, + ); + sse_encode_String(id, serializer); + sse_encode_bool(deleteData, serializer); + pdeCallFfi( + generalizedFrbRustBinding, + serializer, + funcId: 72, + port: port_, + ); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: sse_decode_AnyhowException, + ), + constMeta: kCrateApiGraphSynapseGraphUninstallModuleConstMeta, + argValues: [that, id, deleteData], + apiImpl: this, + ), + ); + } + + TaskConstMeta get kCrateApiGraphSynapseGraphUninstallModuleConstMeta => + const TaskConstMeta( + debugName: "SynapseGraph_uninstall_module", + argNames: ["that", "id", "deleteData"], + ); + @override Future crateApiGraphSynapseGraphUpdateBlock({ required SynapseGraph that, @@ -2977,7 +3287,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { pdeCallFfi( generalizedFrbRustBinding, serializer, - funcId: 66, + funcId: 73, port: port_, ); }, @@ -3372,6 +3682,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (raw as List).map(dco_decode_legacy_candidate).toList(); } + @protected + List dco_decode_list_module_dto(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List).map(dco_decode_module_dto).toList(); + } + + @protected + List dco_decode_list_module_view_dto(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return (raw as List).map(dco_decode_module_view_dto).toList(); + } + @protected List dco_decode_list_namespace_entry(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -3456,6 +3778,40 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (raw as List).map(dco_decode_title_hit).toList(); } + @protected + ModuleDto dco_decode_module_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}'); + return ModuleDto( + id: dco_decode_String(arr[0]), + name: dco_decode_String(arr[1]), + version: dco_decode_String(arr[2]), + description: dco_decode_String(arr[3]), + author: dco_decode_String(arr[4]), + permissions: dco_decode_list_String(arr[5]), + views: dco_decode_list_module_view_dto(arr[6]), + macros: dco_decode_list_String(arr[7]), + tickSeconds: dco_decode_opt_box_autoadd_u_32(arr[8]), + enabled: dco_decode_bool(arr[9]), + size: dco_decode_u_64(arr[10]), + ); + } + + @protected + ModuleViewDto dco_decode_module_view_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}'); + return ModuleViewDto( + id: dco_decode_String(arr[0]), + title: dco_decode_String(arr[1]), + icon: dco_decode_opt_String(arr[2]), + ); + } + @protected NamespaceEntry dco_decode_namespace_entry(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -4141,6 +4497,32 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } + @protected + List sse_decode_list_module_dto(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = []; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_module_dto(deserializer)); + } + return ans_; + } + + @protected + List sse_decode_list_module_view_dto( + SseDeserializer deserializer, + ) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var len_ = sse_decode_i_32(deserializer); + var ans_ = []; + for (var idx_ = 0; idx_ < len_; ++idx_) { + ans_.add(sse_decode_module_view_dto(deserializer)); + } + return ans_; + } + @protected List sse_decode_list_namespace_entry( SseDeserializer deserializer, @@ -4283,6 +4665,44 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return ans_; } + @protected + ModuleDto sse_decode_module_dto(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_id = sse_decode_String(deserializer); + var var_name = sse_decode_String(deserializer); + var var_version = sse_decode_String(deserializer); + var var_description = sse_decode_String(deserializer); + var var_author = sse_decode_String(deserializer); + var var_permissions = sse_decode_list_String(deserializer); + var var_views = sse_decode_list_module_view_dto(deserializer); + var var_macros = sse_decode_list_String(deserializer); + var var_tickSeconds = sse_decode_opt_box_autoadd_u_32(deserializer); + var var_enabled = sse_decode_bool(deserializer); + var var_size = sse_decode_u_64(deserializer); + return ModuleDto( + id: var_id, + name: var_name, + version: var_version, + description: var_description, + author: var_author, + permissions: var_permissions, + views: var_views, + macros: var_macros, + tickSeconds: var_tickSeconds, + enabled: var_enabled, + size: var_size, + ); + } + + @protected + ModuleViewDto sse_decode_module_view_dto(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_id = sse_decode_String(deserializer); + var var_title = sse_decode_String(deserializer); + var var_icon = sse_decode_opt_String(deserializer); + return ModuleViewDto(id: var_id, title: var_title, icon: var_icon); + } + @protected NamespaceEntry sse_decode_namespace_entry(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -4922,6 +5342,30 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_list_module_dto( + List self, + SseSerializer serializer, + ) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_module_dto(item, serializer); + } + } + + @protected + void sse_encode_list_module_view_dto( + List self, + SseSerializer serializer, + ) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + for (final item in self) { + sse_encode_module_view_dto(item, serializer); + } + } + @protected void sse_encode_list_namespace_entry( List self, @@ -5078,6 +5522,33 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_module_dto(ModuleDto self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.id, serializer); + sse_encode_String(self.name, serializer); + sse_encode_String(self.version, serializer); + sse_encode_String(self.description, serializer); + sse_encode_String(self.author, serializer); + sse_encode_list_String(self.permissions, serializer); + sse_encode_list_module_view_dto(self.views, serializer); + sse_encode_list_String(self.macros, serializer); + sse_encode_opt_box_autoadd_u_32(self.tickSeconds, serializer); + sse_encode_bool(self.enabled, serializer); + sse_encode_u_64(self.size, serializer); + } + + @protected + void sse_encode_module_view_dto( + ModuleViewDto self, + SseSerializer serializer, + ) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.id, serializer); + sse_encode_String(self.title, serializer); + sse_encode_opt_String(self.icon, serializer); + } + @protected void sse_encode_namespace_entry( NamespaceEntry self, @@ -5494,6 +5965,22 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { content: content, ); + /// Reads and validates a module file without installing it (for the consent dialog). + Future inspectModule({required List wasm}) => RustLib + .instance + .api + .crateApiGraphSynapseGraphInspectModule(that: this, wasm: wasm); + + /// Installs or updates a module; `granted` must list every permission it asks for. + Future installModule({ + required List wasm, + required List granted, + }) => RustLib.instance.api.crateApiGraphSynapseGraphInstallModule( + that: this, + wasm: wasm, + granted: granted, + ); + /// The journal of `date` (created if missing). Future journal({required String date}) => RustLib.instance.api .crateApiGraphSynapseGraphJournal(that: this, date: date); @@ -5544,6 +6031,18 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { into: into, ); + /// Sends a JSON request to a module and returns its JSON response. + Future moduleCall({required String id, required String request}) => + RustLib.instance.api.crateApiGraphSynapseGraphModuleCall( + that: this, + id: id, + request: request, + ); + + /// Installed modules, by name. + Future> modules() => + RustLib.instance.api.crateApiGraphSynapseGraphModules(that: this); + /// Moves a block with its subtree (drag and drop), possibly to another page. Future> moveBlock({ required String id, @@ -5719,6 +6218,13 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { description: description, ); + Future setModuleEnabled({required String id, required bool enabled}) => + RustLib.instance.api.crateApiGraphSynapseGraphSetModuleEnabled( + that: this, + id: id, + enabled: enabled, + ); + /// Replaces the tags of a page (names only, stored sorted). Journals and templates cannot /// be tagged. Future setPageTags({ @@ -5745,6 +6251,10 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { .api .crateApiGraphSynapseGraphSetTypeIcon(that: this, name: name, icon: icon); + /// Stops a module's running instance (dropping its in-memory state). + Future stopModule({required String id}) => RustLib.instance.api + .crateApiGraphSynapseGraphStopModule(that: this, id: id); + /// 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); @@ -5766,6 +6276,17 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { Future> typeCatalog() => RustLib.instance.api.crateApiGraphSynapseGraphTypeCatalog(that: this); + /// Removes a module from this device; `delete_data` also deletes its synced data on every + /// device. + Future uninstallModule({ + required String id, + required bool deleteData, + }) => RustLib.instance.api.crateApiGraphSynapseGraphUninstallModule( + that: this, + id: id, + deleteData: deleteData, + ); + /// Replaces a block's Markdown (the debounced save while typing). Future updateBlock({required String id, required String content}) => RustLib.instance.api.crateApiGraphSynapseGraphUpdateBlock( diff --git a/app/lib/src/rust/frb_generated.io.dart b/app/lib/src/rust/frb_generated.io.dart index a75d160..b26f458 100644 --- a/app/lib/src/rust/frb_generated.io.dart +++ b/app/lib/src/rust/frb_generated.io.dart @@ -160,6 +160,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_legacy_candidate(dynamic raw); + @protected + List dco_decode_list_module_dto(dynamic raw); + + @protected + List dco_decode_list_module_view_dto(dynamic raw); + @protected List dco_decode_list_namespace_entry(dynamic raw); @@ -202,6 +208,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_title_hit(dynamic raw); + @protected + ModuleDto dco_decode_module_dto(dynamic raw); + + @protected + ModuleViewDto dco_decode_module_view_dto(dynamic raw); + @protected NamespaceEntry dco_decode_namespace_entry(dynamic raw); @@ -406,6 +418,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseDeserializer deserializer, ); + @protected + List sse_decode_list_module_dto(SseDeserializer deserializer); + + @protected + List sse_decode_list_module_view_dto( + SseDeserializer deserializer, + ); + @protected List sse_decode_list_namespace_entry( SseDeserializer deserializer, @@ -452,6 +472,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List sse_decode_list_title_hit(SseDeserializer deserializer); + @protected + ModuleDto sse_decode_module_dto(SseDeserializer deserializer); + + @protected + ModuleViewDto sse_decode_module_view_dto(SseDeserializer deserializer); + @protected NamespaceEntry sse_decode_namespace_entry(SseDeserializer deserializer); @@ -683,6 +709,18 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseSerializer serializer, ); + @protected + void sse_encode_list_module_dto( + List self, + SseSerializer serializer, + ); + + @protected + void sse_encode_list_module_view_dto( + List self, + SseSerializer serializer, + ); + @protected void sse_encode_list_namespace_entry( List self, @@ -752,6 +790,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_list_title_hit(List self, SseSerializer serializer); + @protected + void sse_encode_module_dto(ModuleDto self, SseSerializer serializer); + + @protected + void sse_encode_module_view_dto(ModuleViewDto self, SseSerializer serializer); + @protected void sse_encode_namespace_entry( NamespaceEntry self, diff --git a/app/lib/src/rust/frb_generated.web.dart b/app/lib/src/rust/frb_generated.web.dart index 7fcbfef..51921ac 100644 --- a/app/lib/src/rust/frb_generated.web.dart +++ b/app/lib/src/rust/frb_generated.web.dart @@ -162,6 +162,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_legacy_candidate(dynamic raw); + @protected + List dco_decode_list_module_dto(dynamic raw); + + @protected + List dco_decode_list_module_view_dto(dynamic raw); + @protected List dco_decode_list_namespace_entry(dynamic raw); @@ -204,6 +210,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List dco_decode_list_title_hit(dynamic raw); + @protected + ModuleDto dco_decode_module_dto(dynamic raw); + + @protected + ModuleViewDto dco_decode_module_view_dto(dynamic raw); + @protected NamespaceEntry dco_decode_namespace_entry(dynamic raw); @@ -408,6 +420,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseDeserializer deserializer, ); + @protected + List sse_decode_list_module_dto(SseDeserializer deserializer); + + @protected + List sse_decode_list_module_view_dto( + SseDeserializer deserializer, + ); + @protected List sse_decode_list_namespace_entry( SseDeserializer deserializer, @@ -454,6 +474,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected List sse_decode_list_title_hit(SseDeserializer deserializer); + @protected + ModuleDto sse_decode_module_dto(SseDeserializer deserializer); + + @protected + ModuleViewDto sse_decode_module_view_dto(SseDeserializer deserializer); + @protected NamespaceEntry sse_decode_namespace_entry(SseDeserializer deserializer); @@ -685,6 +711,18 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { SseSerializer serializer, ); + @protected + void sse_encode_list_module_dto( + List self, + SseSerializer serializer, + ); + + @protected + void sse_encode_list_module_view_dto( + List self, + SseSerializer serializer, + ); + @protected void sse_encode_list_namespace_entry( List self, @@ -754,6 +792,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_list_title_hit(List self, SseSerializer serializer); + @protected + void sse_encode_module_dto(ModuleDto self, SseSerializer serializer); + + @protected + void sse_encode_module_view_dto(ModuleViewDto self, SseSerializer serializer); + @protected void sse_encode_namespace_entry( NamespaceEntry self, diff --git a/crates/synapse-ffi/Cargo.toml b/crates/synapse-ffi/Cargo.toml index 00d64bd..3ba6533 100644 --- a/crates/synapse-ffi/Cargo.toml +++ b/crates/synapse-ffi/Cargo.toml @@ -13,6 +13,8 @@ anyhow = "1" chrono.workspace = true flutter_rust_bridge = "=2.13.0" synapse-core.workspace = true +synapse-modules = { path = "../synapse-modules" } +serde_json.workspace = true uuid.workspace = true [dev-dependencies] diff --git a/crates/synapse-ffi/src/api/dto.rs b/crates/synapse-ffi/src/api/dto.rs index 44927e0..56f232e 100644 --- a/crates/synapse-ffi/src/api/dto.rs +++ b/crates/synapse-ffi/src/api/dto.rs @@ -367,3 +367,57 @@ pub struct LegacyCandidate { pub blocks: u32, pub preselected: bool, } + +/// A view a module adds to the sidebar. +#[derive(Debug, Clone, PartialEq)] +pub struct ModuleViewDto { + pub id: String, + pub title: String, + pub icon: Option, +} + +/// An installed (or inspected) module. +#[derive(Debug, Clone, PartialEq)] +pub struct ModuleDto { + pub id: String, + pub name: String, + pub version: String, + pub description: String, + pub author: String, + /// `storage`, `crypto`, `clipboard`, `pages:read`, `pages:write`. + pub permissions: Vec, + pub views: Vec, + /// Block macros (`{{name args}}`) it renders. + pub macros: Vec, + /// How often the app sends it a `tick` request, if at all. + pub tick_seconds: Option, + pub enabled: bool, + /// Size of the module file in bytes. + pub size: u64, +} + +impl ModuleDto { + pub(crate) fn new(m: &synapse_modules::Manifest, enabled: bool, size: u64) -> Self { + Self { + id: m.id.clone(), + name: m.name.clone(), + version: m.version.clone(), + description: m.description.clone(), + author: m.author.clone(), + permissions: m.permissions.iter().map(|p| p.as_str().to_string()).collect(), + views: m + .views + .iter() + .map(|v| ModuleViewDto { + id: v.id.clone(), + title: v.title.clone(), + icon: v.icon.clone(), + }) + .collect(), + macros: m.macros.clone(), + tick_seconds: m.tick_seconds, + enabled, + size, + } + } +} diff --git a/crates/synapse-ffi/src/api/graph.rs b/crates/synapse-ffi/src/api/graph.rs index 28e2bf0..c4232f6 100644 --- a/crates/synapse-ffi/src/api/graph.rs +++ b/crates/synapse-ffi/src/api/graph.rs @@ -20,16 +20,21 @@ pub struct SynapseGraph { pub(crate) graph_cache: Mutex)>>, /// Hubs and home hubs, keyed by op-log sequence. pub(crate) structure_cache: Mutex)>>, + /// Installed modules (`/modules/`), started on first use. + pub(crate) modules: synapse_modules::Registry, } impl SynapseGraph { /// Opens (or creates) the graph stored in `dir`. pub fn open(dir: String) -> Result { let graph = Graph::open(&dir).with_context(|| format!("opening graph at {dir}"))?; + let graph = Arc::new(Mutex::new(graph)); + let modules = synapse_modules::Registry::open(std::path::Path::new(&dir), graph.clone()); Ok(SynapseGraph { - graph: Arc::new(Mutex::new(graph)), + graph, graph_cache: Mutex::new(None), structure_cache: Mutex::new(None), + modules, }) } diff --git a/crates/synapse-ffi/src/api/mod.rs b/crates/synapse-ffi/src/api/mod.rs index b7ba4ba..cdf476a 100644 --- a/crates/synapse-ffi/src/api/mod.rs +++ b/crates/synapse-ffi/src/api/mod.rs @@ -6,6 +6,7 @@ //! - `graph_view`: the whole page-level graph for the graph views (cached by op seq). //! - `structure`: hubs (folder-like pages), namespaces and the legacy page purge. //! - `tags`: free-form tags on pages (names, not pages) and their vocabulary. +//! - `modules`: installed WebAssembly modules (synapse-modules) and requests to them. //! - `layout`: Barnes-Hut force-directed layout, stepped from Dart off the UI thread. //! //! Extension points for Phase 2 (one module each, methods on `SynapseGraph` or their own @@ -17,6 +18,7 @@ pub mod dto; pub mod graph; pub mod graph_view; pub mod layout; +pub mod modules; pub mod outline; pub mod search; pub mod structure; diff --git a/crates/synapse-ffi/src/api/modules.rs b/crates/synapse-ffi/src/api/modules.rs new file mode 100644 index 0000000..9a379c5 --- /dev/null +++ b/crates/synapse-ffi/src/api/modules.rs @@ -0,0 +1,58 @@ +//! Installed modules: inspect, install, enable, uninstall, and JSON requests to them. +//! +//! Requests and responses are JSON strings (module API v1, see `docs/modules.md`); the app +//! renders the UI trees and applies the effects. None of these calls hold the graph lock +//! while a module runs: host functions lock it per call. + +use super::dto::ModuleDto; +use super::graph::SynapseGraph; +use anyhow::{Result, anyhow}; +use synapse_modules::Permission; + +impl SynapseGraph { + /// Reads and validates a module file without installing it (for the consent dialog). + pub fn inspect_module(&self, wasm: Vec) -> Result { + let m = self.modules.inspect(&wasm)?; + Ok(ModuleDto::new(&m, false, wasm.len() as u64)) + } + + /// Installs or updates a module; `granted` must list every permission it asks for. + pub fn install_module(&self, wasm: Vec, granted: Vec) -> Result { + let granted = granted + .iter() + .map(|p| Permission::parse(p).ok_or_else(|| anyhow!("unknown permission {p:?}"))) + .collect::>>()?; + let info = self.modules.install(&wasm, &granted)?; + Ok(ModuleDto::new(&info.manifest, info.enabled, info.size)) + } + + /// Installed modules, by name. + pub fn modules(&self) -> Vec { + self.modules + .list() + .iter() + .map(|i| ModuleDto::new(&i.manifest, i.enabled, i.size)) + .collect() + } + + pub fn set_module_enabled(&self, id: String, enabled: bool) -> Result<()> { + Ok(self.modules.set_enabled(&id, enabled)?) + } + + /// Removes a module from this device; `delete_data` also deletes its synced data on every + /// device. + pub fn uninstall_module(&self, id: String, delete_data: bool) -> Result<()> { + Ok(self.modules.uninstall(&id, delete_data)?) + } + + /// Sends a JSON request to a module and returns its JSON response. + pub fn module_call(&self, id: String, request: String) -> Result { + let req: serde_json::Value = serde_json::from_str(&request)?; + Ok(self.modules.call(&id, &req)?.to_string()) + } + + /// Stops a module's running instance (dropping its in-memory state). + pub fn stop_module(&self, id: String) { + self.modules.stop(&id); + } +} diff --git a/crates/synapse-ffi/src/frb_generated.rs b/crates/synapse-ffi/src/frb_generated.rs index da2e78d..b178063 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 = 272705018; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -821319892; // Section: executor @@ -1458,6 +1458,118 @@ fn wire__crate__api__graph__SynapseGraph_insert_block_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_inspect_module_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_inspect_module", + 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_wasm = >::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::inspect_module( + &*api_that_guard, + api_wasm, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} +fn wire__crate__api__graph__SynapseGraph_install_module_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_install_module", + 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_wasm = >::sse_decode(&mut deserializer); + let api_granted = >::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::install_module( + &*api_that_guard, + api_wasm, + api_granted, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_journal_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -1791,6 +1903,113 @@ fn wire__crate__api__graph__SynapseGraph_merge_block_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_module_call_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_module_call", + 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_id = ::sse_decode(&mut deserializer); + let api_request = ::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::module_call( + &*api_that_guard, + api_id, + api_request, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} +fn wire__crate__api__graph__SynapseGraph_modules_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_modules", + 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); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((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 = + Ok::<_, ()>(crate::api::graph::SynapseGraph::modules(&*api_that_guard))?; + std::result::Result::Ok(output_ok) + })()) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_move_block_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -3231,6 +3450,63 @@ fn wire__crate__api__graph__SynapseGraph_set_hub_description_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_set_module_enabled_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_module_enabled", + 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_id = ::sse_decode(&mut deserializer); + let api_enabled = ::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_module_enabled( + &*api_that_guard, + api_id, + api_enabled, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_set_page_tags_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -3402,6 +3678,58 @@ fn wire__crate__api__graph__SynapseGraph_set_type_icon_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_stop_module_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_stop_module", + 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_id = ::sse_decode(&mut deserializer); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((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 = Ok::<_, ()>({ + crate::api::graph::SynapseGraph::stop_module(&*api_that_guard, api_id); + })?; + 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, @@ -3610,6 +3938,63 @@ fn wire__crate__api__graph__SynapseGraph_type_catalog_impl( }, ) } +fn wire__crate__api__graph__SynapseGraph_uninstall_module_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_uninstall_module", + 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_id = ::sse_decode(&mut deserializer); + let api_delete_data = ::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::uninstall_module( + &*api_that_guard, + api_id, + api_delete_data, + )?; + std::result::Result::Ok(output_ok) + })(), + ) + } + }, + ) +} fn wire__crate__api__graph__SynapseGraph_update_block_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -4095,6 +4480,30 @@ impl SseDecode for Vec { } } +impl SseDecode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = Vec::with_capacity(len_ as usize); + for idx_ in 0..len_ { + ans_.push(::sse_decode(deserializer)); + } + return ans_; + } +} + +impl SseDecode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = Vec::with_capacity(len_ as usize); + for idx_ in 0..len_ { + ans_.push(::sse_decode(deserializer)); + } + return ans_; + } +} + impl SseDecode for Vec { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -4227,6 +4636,50 @@ impl SseDecode for Vec { } } +impl SseDecode for crate::api::dto::ModuleDto { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_id = ::sse_decode(deserializer); + let mut var_name = ::sse_decode(deserializer); + let mut var_version = ::sse_decode(deserializer); + let mut var_description = ::sse_decode(deserializer); + let mut var_author = ::sse_decode(deserializer); + let mut var_permissions = >::sse_decode(deserializer); + let mut var_views = >::sse_decode(deserializer); + let mut var_macros = >::sse_decode(deserializer); + let mut var_tickSeconds = >::sse_decode(deserializer); + let mut var_enabled = ::sse_decode(deserializer); + let mut var_size = ::sse_decode(deserializer); + return crate::api::dto::ModuleDto { + id: var_id, + name: var_name, + version: var_version, + description: var_description, + author: var_author, + permissions: var_permissions, + views: var_views, + macros: var_macros, + tick_seconds: var_tickSeconds, + enabled: var_enabled, + size: var_size, + }; + } +} + +impl SseDecode for crate::api::dto::ModuleViewDto { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_id = ::sse_decode(deserializer); + let mut var_title = ::sse_decode(deserializer); + let mut var_icon = >::sse_decode(deserializer); + return crate::api::dto::ModuleViewDto { + id: var_id, + title: var_title, + icon: var_icon, + }; + } +} + impl SseDecode for crate::api::dto::NamespaceEntry { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -4623,189 +5076,226 @@ fn pde_ffi_dispatcher_primary_impl( 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( + 27 => wire__crate__api__graph__SynapseGraph_inspect_module_impl( port, ptr, rust_vec_len, data_len, ), - 29 => { - wire__crate__api__graph__SynapseGraph_journals_impl(port, ptr, rust_vec_len, data_len) - } - 30 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl( + 28 => wire__crate__api__graph__SynapseGraph_install_module_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 29 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len), + 30 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl( port, ptr, rust_vec_len, data_len, ), 31 => { - wire__crate__api__graph__SynapseGraph_list_pages_impl(port, ptr, rust_vec_len, data_len) + wire__crate__api__graph__SynapseGraph_journals_impl(port, ptr, rust_vec_len, data_len) } - 32 => wire__crate__api__graph__SynapseGraph_merge_block_impl( + 32 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl( port, ptr, rust_vec_len, data_len, ), 33 => { + wire__crate__api__graph__SynapseGraph_list_pages_impl(port, ptr, rust_vec_len, data_len) + } + 34 => wire__crate__api__graph__SynapseGraph_merge_block_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 35 => wire__crate__api__graph__SynapseGraph_module_call_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 36 => wire__crate__api__graph__SynapseGraph_modules_impl(port, ptr, rust_vec_len, data_len), + 37 => { 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 => { + 38 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len), + 39 => { wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len) } - 36 => wire__crate__api__graph__SynapseGraph_outdent_block_impl( + 40 => 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( + 41 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len), + 42 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len), + 43 => 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( + 44 => 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( + 45 => 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( + 46 => 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( + 47 => 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( + 48 => 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( + 49 => 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( + 50 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len), + 51 => 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( + 52 => 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( + 53 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl( port, ptr, rust_vec_len, data_len, ), - 50 => { + 54 => { wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len) } - 51 => wire__crate__api__graph__SynapseGraph_remove_type_impl( + 55 => wire__crate__api__graph__SynapseGraph_remove_type_impl( port, ptr, rust_vec_len, data_len, ), - 52 => wire__crate__api__graph__SynapseGraph_rename_page_impl( + 56 => wire__crate__api__graph__SynapseGraph_rename_page_impl( port, ptr, rust_vec_len, data_len, ), - 53 => { + 57 => { wire__crate__api__graph__SynapseGraph_rename_tag_impl(port, ptr, rust_vec_len, data_len) } - 54 => wire__crate__api__graph__SynapseGraph_rename_type_impl( + 58 => wire__crate__api__graph__SynapseGraph_rename_type_impl( port, ptr, rust_vec_len, data_len, ), - 55 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( + 59 => wire__crate__api__graph__SynapseGraph_search_blocks_impl( port, ptr, rust_vec_len, data_len, ), - 56 => wire__crate__api__graph__SynapseGraph_search_titles_impl( + 60 => wire__crate__api__graph__SynapseGraph_search_titles_impl( port, ptr, rust_vec_len, data_len, ), - 57 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( + 61 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl( port, ptr, rust_vec_len, data_len, ), - 58 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( + 62 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl( port, ptr, rust_vec_len, data_len, ), - 59 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( + 63 => wire__crate__api__graph__SynapseGraph_set_module_enabled_impl( port, ptr, rust_vec_len, data_len, ), - 60 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( + 64 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl( port, ptr, rust_vec_len, data_len, ), - 61 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl( + 65 => wire__crate__api__graph__SynapseGraph_set_page_type_impl( port, ptr, rust_vec_len, data_len, ), - 62 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( + 66 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl( port, ptr, rust_vec_len, data_len, ), - 63 => { + 67 => wire__crate__api__graph__SynapseGraph_stop_module_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 68 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 69 => { wire__crate__api__graph__SynapseGraph_timeline_impl(port, ptr, rust_vec_len, data_len) } - 65 => wire__crate__api__graph__SynapseGraph_type_catalog_impl( + 71 => wire__crate__api__graph__SynapseGraph_type_catalog_impl( port, ptr, rust_vec_len, data_len, ), - 66 => wire__crate__api__graph__SynapseGraph_update_block_impl( + 72 => wire__crate__api__graph__SynapseGraph_uninstall_module_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 73 => wire__crate__api__graph__SynapseGraph_update_block_impl( port, ptr, rust_vec_len, @@ -4826,7 +5316,7 @@ fn pde_ffi_dispatcher_sync_impl( 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), 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), + 70 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -5131,6 +5621,53 @@ impl flutter_rust_bridge::IntoIntoDart } } // Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::api::dto::ModuleDto { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [ + self.id.into_into_dart().into_dart(), + self.name.into_into_dart().into_dart(), + self.version.into_into_dart().into_dart(), + self.description.into_into_dart().into_dart(), + self.author.into_into_dart().into_dart(), + self.permissions.into_into_dart().into_dart(), + self.views.into_into_dart().into_dart(), + self.macros.into_into_dart().into_dart(), + self.tick_seconds.into_into_dart().into_dart(), + self.enabled.into_into_dart().into_dart(), + self.size.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for crate::api::dto::ModuleDto {} +impl flutter_rust_bridge::IntoIntoDart for crate::api::dto::ModuleDto { + fn into_into_dart(self) -> crate::api::dto::ModuleDto { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::api::dto::ModuleViewDto { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [ + self.id.into_into_dart().into_dart(), + self.title.into_into_dart().into_dart(), + self.icon.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::api::dto::ModuleViewDto +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::api::dto::ModuleViewDto +{ + fn into_into_dart(self) -> crate::api::dto::ModuleViewDto { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs impl flutter_rust_bridge::IntoDart for crate::api::dto::NamespaceEntry { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { [ @@ -5673,6 +6210,26 @@ impl SseEncode for Vec { } } +impl SseEncode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + ::sse_encode(item, serializer); + } + } +} + +impl SseEncode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + ::sse_encode(item, serializer); + } + } +} + impl SseEncode for Vec { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -5783,6 +6340,32 @@ impl SseEncode for Vec { } } +impl SseEncode for crate::api::dto::ModuleDto { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.id, serializer); + ::sse_encode(self.name, serializer); + ::sse_encode(self.version, serializer); + ::sse_encode(self.description, serializer); + ::sse_encode(self.author, serializer); + >::sse_encode(self.permissions, serializer); + >::sse_encode(self.views, serializer); + >::sse_encode(self.macros, serializer); + >::sse_encode(self.tick_seconds, serializer); + ::sse_encode(self.enabled, serializer); + ::sse_encode(self.size, serializer); + } +} + +impl SseEncode for crate::api::dto::ModuleViewDto { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.id, serializer); + ::sse_encode(self.title, serializer); + >::sse_encode(self.icon, serializer); + } +} + impl SseEncode for crate::api::dto::NamespaceEntry { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { diff --git a/crates/synapse-ffi/tests/api.rs b/crates/synapse-ffi/tests/api.rs index 2858ee3..598fee6 100644 --- a/crates/synapse-ffi/tests/api.rs +++ b/crates/synapse-ffi/tests/api.rs @@ -588,3 +588,34 @@ fn a_hub_tag_and_a_same_name_type_need_no_tag_node_beside_the_hub() { ("anime", 2) ); } + +#[test] +fn modules_install_and_answer_requests_over_ffi() { + let (_d, g) = open(); + let wasm = std::fs::read(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../app/assets/modules/synapse.secrets.wasm" + )) + .unwrap(); + let m = g.inspect_module(wasm.clone()).unwrap(); + assert_eq!(m.id, "synapse.secrets"); + assert_eq!(m.views[0].id, "vault"); + assert_eq!(m.macros, ["secret"]); + assert!(g.install_module(wasm.clone(), vec![]).is_err()); + assert!( + g.install_module(wasm.clone(), vec!["storage".into(), "nope".into()]) + .is_err() + ); + let m = g.install_module(wasm, m.permissions.clone()).unwrap(); + assert!(m.enabled); + assert_eq!(g.modules().len(), 1); + let r = g + .module_call(m.id.clone(), r#"{"op":"render","view":"vault"}"#.into()) + .unwrap(); + assert!(r.contains("Create vault")); + assert!(g.module_call(m.id.clone(), "not json".into()).is_err()); + g.set_module_enabled(m.id.clone(), false).unwrap(); + assert!(g.module_call(m.id.clone(), "{}".into()).is_err()); + g.uninstall_module(m.id, true).unwrap(); + assert!(g.modules().is_empty()); +}