From 7595e0bf22b7b8e2948c52793351ab0baf48f967 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Mon, 13 Jan 2025 12:17:59 +0700 Subject: [PATCH] refactor type gen to split out mini lcm and fw lite shared types into their own config method. Don't export apis which are not JSInvokable --- .../TypeGen/ReinforcedFwLiteTypingConfig.cs | 73 ++++++++++++------- .../FwLiteShared/Auth/IAuthService.ts | 2 - .../Services/IMiniLcmApiProvider.ts | 1 - 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs b/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs index dde5c94c4..b8556c429 100644 --- a/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs +++ b/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs @@ -27,24 +27,29 @@ public static void Configure(ConfigurationBuilder builder) .AutoOptionalProperties() .UseVisitor()); DisableEsLintChecks(builder); - builder.Substitute(typeof(WritingSystemId), new RtSimpleTypeName("string")); + builder.Substitute(typeof(Guid), new RtSimpleTypeName("string")); builder.Substitute(typeof(Uri), new RtSimpleTypeName("string")); builder.Substitute(typeof(DateTimeOffset), new RtSimpleTypeName("string")); builder.SubstituteGeneric(typeof(ValueTask<>), (type, resolver) => resolver.ResolveTypeName(typeof(Task<>).MakeGenericType(type.GenericTypeArguments[0]), true)); var dotnetObjectRefInterface = typeof(DotNetObjectReference<>).GetInterfaces().First(); builder.SubstituteGeneric(typeof(DotNetObjectReference<>), (type, resolver) => resolver.ResolveTypeName(dotnetObjectRefInterface)); + builder.ExportAsThirdParty([dotnetObjectRefInterface], + exportBuilder => exportBuilder.WithName("DotNet.DotNetObject").Imports([ + new() { From = "@microsoft/dotnet-js-interop", Target = "type {DotNet}" } + ])); + + ConfigureMiniLcmTypes(builder); + ConfigureFwLiteSharedTypes(builder); + } + + private static void ConfigureMiniLcmTypes(ConfigurationBuilder builder) + { + builder.Substitute(typeof(WritingSystemId), new RtSimpleTypeName("string")); //todo generate a multistring type rather than just substituting it everywhere - builder.ExportAsThirdParty().WithName("IMultiString").Imports([new () - { - From = "$lib/dotnet-types/i-multi-string", - Target = "type {IMultiString}" - }]); - builder.ExportAsThirdParty([dotnetObjectRefInterface], exportBuilder => exportBuilder.WithName("DotNet.DotNetObject").Imports([new () - { - From = "@microsoft/dotnet-js-interop", - Target = "type {DotNet}" - }])); + builder.ExportAsThirdParty().WithName("IMultiString").Imports([ + new() { From = "$lib/dotnet-types/i-multi-string", Target = "type {IMultiString}" } + ]); builder.ExportAsInterface().WithPublicNonStaticProperties(exportBuilder => { if (exportBuilder.Member.Name == nameof(Sense.Order)) @@ -69,29 +74,38 @@ public static void Configure(ConfigurationBuilder builder) builder.ExportAsInterface() .FlattenHierarchy() .WithPublicProperties() - .WithPublicMethods(b => b.AlwaysReturnPromise()); + .WithPublicMethods(b => b.AlwaysReturnPromise().OnlyJsInvokable()); builder.ExportAsEnum().UseString(); builder.ExportAsInterfaces([typeof(QueryOptions), typeof(SortOptions), typeof(ExemplarOptions)], exportBuilder => exportBuilder.WithPublicNonStaticProperties()); + } + + private static void ConfigureFwLiteSharedTypes(ConfigurationBuilder builder) + { builder.ExportAsEnum().UseString(); - builder.ExportAsInterface().WithPublicMethods(b => b.AlwaysReturnPromise()); - builder.ExportAsInterface().WithPublicMethods(b => b.AlwaysReturnPromise()); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicMethods(b => b.AlwaysReturnPromise()); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicProperties(); - builder.ExportAsInterface().WithPublicProperties(); builder.ExportAsEnum().UseString(); builder.ExportAsEnum(); - builder.ExportAsInterface().WithPublicMethods(b => b.AlwaysReturnPromise()); + builder.ExportAsInterfaces([ + typeof(AuthService), + typeof(ImportFwdataService), + typeof(CombinedProjectsService), + typeof(MiniLcmApiProvider) + ], exportBuilder => exportBuilder.WithPublicMethods(b => b.AlwaysReturnPromise().OnlyJsInvokable())); + + builder.ExportAsInterfaces([ + typeof(ServerStatus), + typeof(ProjectModel), + typeof(ServerProjects), + typeof(LexboxServer), + typeof(CrdtProject), + typeof(ProjectData), + typeof(IProjectIdentifier), + typeof(FwLiteConfig) + ], exportBuilder => exportBuilder.WithPublicProperties()); } - private static void AlwaysReturnPromise(this MethodExportBuilder exportBuilder) + private static MethodExportBuilder AlwaysReturnPromise(this MethodExportBuilder exportBuilder) { var isUpdatePatchMethod = exportBuilder.Member.GetParameters() .Any(p => p.ParameterType.IsGenericType && @@ -99,7 +113,7 @@ private static void AlwaysReturnPromise(this MethodExportBuilder exportBuilder) if (isUpdatePatchMethod) { exportBuilder.Ignore(); - return; + return exportBuilder; } var isTaskMethod = (exportBuilder.Member.ReturnType.IsGenericType && @@ -118,6 +132,13 @@ private static void AlwaysReturnPromise(this MethodExportBuilder exportBuilder) exportBuilder.Returns(typeof(Task<>).MakeGenericType(exportBuilder.Member.ReturnType)); } } + return exportBuilder; + } + + private static void OnlyJsInvokable(this MethodExportBuilder exportBuilder) + { + if (exportBuilder.Member.GetCustomAttribute() is null) + exportBuilder.Ignore(); } private static T WithPublicNonStaticProperties(this T tc, Action? configuration = null) diff --git a/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Auth/IAuthService.ts b/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Auth/IAuthService.ts index 3ff3e7a27..2b31ffea0 100644 --- a/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Auth/IAuthService.ts +++ b/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Auth/IAuthService.ts @@ -11,8 +11,6 @@ export interface IAuthService servers() : Promise; signInWebView(server: ILexboxServer) : Promise; useSystemWebView() : Promise; - signInWebApp(server: ILexboxServer, returnUrl: string) : Promise; logout(server: ILexboxServer) : Promise; - getLoggedInName(server: ILexboxServer) : Promise; } /* eslint-enable */ diff --git a/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Services/IMiniLcmApiProvider.ts b/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Services/IMiniLcmApiProvider.ts index ef3ae090c..191ce0bf8 100644 --- a/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Services/IMiniLcmApiProvider.ts +++ b/frontend/viewer/src/lib/dotnet-types/generated-types/FwLiteShared/Services/IMiniLcmApiProvider.ts @@ -8,7 +8,6 @@ import type {DotNet} from '@microsoft/dotnet-js-interop'; export interface IMiniLcmApiProvider { getMiniLcmApi() : Promise; - setMiniLcmApi(miniLcmApi: DotNet.DotNetObject) : Promise; clearMiniLcmApi() : Promise; } /* eslint-enable */