Skip to content

JWebMP/TypescriptClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

95 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Angular TypeScript Client

Build Maven Central License

Java 25+ Maven 4

A Java annotation library that lets JWebMP components describe Angular TypeScript metadata entirely in Java. Annotate your classes with @NgComponent, @NgDataService, @NgDirective, and friends β€” the generator produces ready-to-compile .ts files, Angular modules, routing configs, and STOMP-backed event-bus services without you ever editing TypeScript by hand.

✨ Features

  • Ng* annotation family β€” @NgApp, @NgComponent, @NgModule, @NgDirective, @NgDataService, @NgDataType, @NgServiceProvider, @NgProvider, @NgValidator, @NgSchema
  • Component metadata β€” @NgInput, @NgOutput, @NgComponentTagAttribute for Angular component I/O
  • Lifecycle hooks β€” @NgOnInit, @NgOnDestroy, @NgAfterViewInit, @NgAfterViewChecked, @NgAfterContentInit, @NgAfterContentChecked
  • Structural code generation β€” @NgField, @NgMethod, @NgConstructorParameter, @NgConstructorBody, @NgInterface, @NgSignal, @NgSignalComputed, @NgSignalEffect, @NgModel, @NgInject
  • Import management β€” @NgImportReference, @NgImportModule, @NgImportProvider, @NgComponentReference, @NgDataTypeReference, @NgIgnoreImportReference, @NgIgnoreRender
  • Global annotations β€” @NgGlobalField, @NgGlobalConstructorParameter, @NgGlobalComponentConstructorParameter, @NgGlobalComponentImportReference for cross-cutting concerns
  • Routing β€” @NgRoutable (path, redirectTo, pathMatch, parent, sortOrder) and @NgRouteData
  • Boot-module annotations β€” @NgBootDeclaration, @NgBootModuleImport, @NgBootImportReference, @NgBootEntryComponent, @NgBootImportProvider, @NgBootProvider, @NgBootConstructorBody, @NgBootConstructorParameter, @NgBootGlobalField, @NgBootModuleSchema
  • Angular CLI config β€” @NgAsset, @NgScript, @NgStyleSheet, @NgPolyfill for angular.json integration
  • TypeScript dependencies β€” @TsDependency, @TsDevDependency, @NgSourceDirectoryReference
  • CRTP fluent interfaces β€” INgApp, INgComponent, INgDirective, INgDataService, INgDataType, INgModule, INgProvider, INgServiceProvider, INgRoutable, INgValidatorDirective, INgFormControlValidatorFunction, INgFormGroupValidatorFunction
  • SPI extension points β€” OnGetAllConstructorParameters, OnGetAllConstructorBodies, OnGetAllFields, OnGetAllImports, OnGetAllMethods, OnGetAllModuleImports
  • Built-in event bus β€” EventBusService (STOMP over WebSocket) with auto-reconnect, listener registration, and RxJS observables
  • TypeScript type helpers β€” any, bool, number, string placeholder classes for type mapping
  • Java β†’ TS field mapping β€” INgDataType introspects Java fields (including generics, enums, dates, optionals) and emits TypeScript interface fields with jakarta.validation awareness
  • Classpath scanning β€” AnnotationHelper scans the hierarchy of every Ng-annotated class at startup via AngularTypeScriptPostStartup (reactive Uni-based)
  • Output directory control β€” jwebmp.outputDirectory env/system property overrides the default ~/.jwebmp/<appName> output location

πŸ“¦ Installation

<dependency>
  <groupId>com.jwebmp.plugins</groupId>
  <artifactId>typescript-client</artifactId>
</dependency>

Version is managed by the com.jwebmp:jwebmp-bom imported in the parent POM.

πŸ—ΊοΈ JPMS Module

module com.jwebmp.core.base.angular.client {
    requires transitive com.guicedee.client;
    requires transitive com.jwebmp.client;
    requires transitive com.guicedee.guicedinjection;
    requires transitive com.guicedee.jsonrepresentation;
    requires transitive org.apache.commons.lang3;
    requires transitive org.apache.commons.io;
    requires transitive jakarta.validation;

    exports com.jwebmp.core.base.angular.client.annotations.angular;
    exports com.jwebmp.core.base.angular.client.annotations.components;
    exports com.jwebmp.core.base.angular.client.annotations.functions;
    exports com.jwebmp.core.base.angular.client.annotations.globals;
    exports com.jwebmp.core.base.angular.client.annotations.references;
    exports com.jwebmp.core.base.angular.client.annotations.constructors;
    exports com.jwebmp.core.base.angular.client.annotations.angularconfig;
    exports com.jwebmp.core.base.angular.client.annotations.structures;
    exports com.jwebmp.core.base.angular.client.annotations.routing;
    exports com.jwebmp.core.base.angular.client.annotations.typescript;
    exports com.jwebmp.core.base.angular.client.annotations.boot;
    exports com.jwebmp.core.base.angular.client;
    exports com.jwebmp.core.base.angular.client.services;
    exports com.jwebmp.core.base.angular.client.services.interfaces;
    exports com.jwebmp.core.base.angular.client.services.spi;
    exports com.jwebmp.core.base.angular.client.services.tstypes;

    provides IGuiceScanModuleInclusions with AngularTypeScriptClientModuleInclusion;
    provides IGuiceModule             with AngularClientModule;
    provides IGuiceConfigurator        with GuicedConfig;
    provides IGuicePostStartup         with AngularTypeScriptPostStartup;

    uses OnGetAllConstructorParameters;
    uses OnGetAllConstructorBodies;
    uses OnGetAllFields;
    uses OnGetAllImports;
    uses OnGetAllMethods;
    uses OnGetAllModuleImports;
}

πŸš€ Quick Start

1. Define an Angular app

@NgApp(value = "my-app", bootComponent = AppComponent.class)
public class MyApp extends Page<MyApp> implements INgApp<MyApp> {
    @Override
    public List<IComponentHierarchyBase<?, ?>> getRoutes() {
        return List.of();
    }
}

2. Create a component

@NgComponent("app-header")
public class HeaderComponent extends DivSimple<HeaderComponent>
        implements INgComponent<HeaderComponent> { }

3. Declare a data type (generates a TypeScript interface)

@NgDataType
public class UserDTO implements INgDataType<UserDTO> {
    private String name;
    private String email;
    private int age;
}

4. Wire a data service

@NgDataService(value = "userData", listenerName = "user.data")
public class UserDataService implements INgDataService<UserDataService> { }

5. Add routing

@NgRoutable(path = "dashboard", parent = {AppComponent.class})
@NgComponent("app-dashboard")
public class DashboardComponent extends DivSimple<DashboardComponent>
        implements INgComponent<DashboardComponent> { }

6. Run the build

mvn clean install

TypeScript output is written to ~/.jwebmp/<appName>/ (override with jwebmp.outputDirectory).

πŸ—οΈ Architecture

Annotation Categories

Category Annotations Purpose
Angular types @NgApp, @NgComponent, @NgModule, @NgDirective, @NgDataService, @NgDataType, @NgServiceProvider, @NgProvider, @NgValidator, @NgSchema Declare Angular constructs
Component I/O @NgInput, @NgOutput, @NgComponentTagAttribute Component inputs, outputs, and host attributes
Lifecycle @NgOnInit, @NgOnDestroy, @NgAfterViewInit, @NgAfterViewChecked, @NgAfterContentInit, @NgAfterContentChecked Angular lifecycle hook bodies
Structure @NgField, @NgMethod, @NgConstructorParameter, @NgConstructorBody, @NgInterface, @NgSignal, @NgSignalComputed, @NgSignalEffect, @NgModel, @NgInject TypeScript class members
References @NgImportReference, @NgImportModule, @NgImportProvider, @NgComponentReference, @NgDataTypeReference, @NgIgnoreImportReference, @NgIgnoreRender Import/export management
Globals @NgGlobalField, @NgGlobalConstructorParameter, @NgGlobalComponentConstructorParameter, @NgGlobalComponentImportReference Cross-cutting members applied to all components
Boot module @NgBootDeclaration, @NgBootModuleImport, @NgBootImportReference, @NgBootEntryComponent, @NgBootImportProvider, @NgBootProvider, @NgBootConstructorBody, @NgBootConstructorParameter, @NgBootGlobalField, @NgBootModuleSchema Root Angular module configuration
Angular CLI @NgAsset, @NgScript, @NgStyleSheet, @NgPolyfill angular.json assets/scripts/styles/polyfills
TypeScript @TsDependency, @TsDevDependency, @NgSourceDirectoryReference package.json and source directory references
Routing @NgRoutable, @NgRouteData Angular route declarations

CRTP Interface Hierarchy

IComponent<J>
 β”œβ”€β”€ INgApp<J>              β†’ @NgApp
 β”œβ”€β”€ INgComponent<J>        β†’ @NgComponent (selector, template, styles, standalone)
 β”œβ”€β”€ INgDirective<J>        β†’ @NgDirective (selector, inputs, outputs, standalone)
 β”œβ”€β”€ INgDataService<J>      β†’ @NgDataService (signal-based, event-bus listener)
 β”œβ”€β”€ INgDataType<J>         β†’ @NgDataType (Java fields β†’ TS interface fields)
 β”œβ”€β”€ INgModule<J>           β†’ @NgModule
 β”œβ”€β”€ INgProvider<J>         β†’ @NgProvider (injectable service)
 β”œβ”€β”€ INgServiceProvider<J>  β†’ @NgServiceProvider (data service + data type bridge)
 └── INgRoutable<J>         β†’ @NgRoutable (route path, parent, guards)

Startup Flow

IGuiceContext.instance()
 └─ GuicedConfig                          β†’ enables annotation/classpath/field/method scanning
     └─ AngularClientModule               β†’ binds AnnotationHelper singleton
         └─ AngularTypeScriptPostStartup  β†’ scans all Ng-annotated classes via AnnotationHelper.startup()

Key Classes

Class Role
AnnotationHelper Singleton that scans class hierarchies, collects all Ng annotations (including globals and repeatables), and caches ClassAnnotationMapping results
AnnotationsMap Central registry mapping single β†’ repeatable annotation pairs, global annotations, and the set of classes to scan
AppUtils File-system utilities β€” resolves output directories, reads/writes generated TS files, locates angular.json, package.json, tsconfig.json, etc.
EventBusService Built-in Angular provider that manages a STOMP WebSocket connection with auto-reconnect, listener registration, and RxJS subjects
DynamicData Generic wrapper for sending heterogeneous data payloads through INgDataService
ComponentConfiguration Runtime configuration holder for a single component's generated metadata
TypescriptIndexPageConfigurator SPI for customising the generated index.html

SPI Extension Points

SPI Purpose
OnGetAllConstructorParameters Add/modify constructor parameters for any Ng component
OnGetAllConstructorBodies Add/modify constructor body statements
OnGetAllFields Add/modify class-level fields
OnGetAllImports Add/modify import references
OnGetAllMethods Add/modify class methods
OnGetAllModuleImports Add/modify NgModule import entries

βš™οΈ Configuration

Environment / System Property Default Purpose
jwebmp.outputDirectory β€” Override the generated TS output directory
jwebmp ~ (user home) Base directory when jwebmp.outputDirectory is not set (output goes to <base>/.jwebmp/<appName>)

Important: Generated TypeScript is read-only. Change Java annotations and rerun the build β€” never edit the output files directly.

πŸ”— Dependencies

com.jwebmp.core.base.angular.client
 β”œβ”€β”€ com.jwebmp.client              (JWebMP client library)
 β”œβ”€β”€ com.guicedee.client             (GuicedEE lifecycle & SPI)
 β”œβ”€β”€ com.guicedee.guicedinjection    (Guice DI + classpath scanning)
 β”œβ”€β”€ com.guicedee.jsonrepresentation (Jackson / JSON utilities)
 β”œβ”€β”€ org.apache.commons.lang3        (StringUtils, etc.)
 β”œβ”€β”€ org.apache.commons.io           (FileUtils, IOUtils)
 β”œβ”€β”€ jakarta.validation              (@NotNull awareness in TS field generation)
 └── org.apache.logging.log4j.core   (Log4j2 logging)

πŸ› οΈ Build

  • Java: 25 LTS
  • Maven: inherits com.jwebmp:parent:2.0.0-SNAPSHOT
  • JPMS: module descriptor at src/main/java/module-info.java
mvn clean install

Run tests:

mvn test

πŸ”„ CI

GitHub Actions workflow at .github/workflows/maven-package.yml (GuicedEE shared workflow).

Required secrets: USERNAME, USER_TOKEN, SONA_USERNAME, SONA_PASSWORD.

Example environment file: .env.example.

πŸ“– Documentation

Document Path
Architecture diagrams docs/architecture/README.md

🀝 Contributing

Issues and pull requests are welcome. Please add tests (using jwebmp-testlib) for new annotations, SPI hooks, or rendering logic.

πŸ“„ License

Apache 2.0

About

A client library for use with JWebMP and AngularTS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages