1.2.2 โ€ข Published 11 months ago

@nodeboot/aot v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@nodeboot/aot

๐Ÿง  Ahead-of-Time (AOT) support for the Node-Boot framework โ€” enabling faster startup, intelligent component scanning, and OpenAPI-ready model schemas.


โœจ Overview

@nodeboot/aot provides a set of tools and decorators to optimize Node-Boot apps for production, by shifting expensive runtime operations to build-time via Ahead-of-Time (AOT) processing.

It includes:

  • ๐Ÿ” Bean Scanner & Generator (node-boot-aot-beans.js) Scans compiled files for decorators like @Service, @Controller, etc., and generates a precomputed node-boot-beans.json.

  • ๐Ÿ“ฆ Component Scanner Decorator (@EnableComponentScan) Automatically imports application components at runtime from the prebuilt manifest or falls back to dynamic scanning.

  • ๐Ÿงฌ Model Schema Generator (node-boot-aot-models.js) Converts @Model-decorated classes into OpenAPI-compatible JSON Schemas.


๐Ÿ“ฆ Installation

npm install @nodeboot/aot --save-dev

โš™๏ธ Usage Guide

1. ๐Ÿง  Generate AOT Beans Metadata

After building your app (tsc), run the AOT bean scanner to precompile metadata for your components:

node node-boot-aot-beans.js

Add to package.json:

{
    "scripts": {
        "postbuild": "node node-boot-aot-beans.js"
    }
}

This will output dist/node-boot-beans.json โ€” a list of all .js files that contain key decorators such as @Service, @Controller, etc.


2. ๐Ÿงฌ Generate OpenAPI JSON Schemas from @Model Classes

To convert all @Model-decorated classes into OpenAPI-compatible schema:

node node-boot-aot-models.js

This will generate: dist/node-boot-models.json โ€” structured like:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "components": {
        "schemas": {
            "UserModel": {
                "type": "object",
                "properties": {
                    "id": {"type": "string"},
                    "name": {"type": "string"}
                }
            }
        }
    }
}

๐Ÿ” All-in-One Runner

Runs both scripts in one go. Ideal for post-build automation.

node node-boot-aot.js

๐Ÿ’ก Suggested in package.json:

{
    "scripts": {
        "postbuild": "node node-boot-aot.js"
    }
}

๐Ÿง  Runtime Integration

In your main application class, use the @EnableComponentScan() decorator to bootstrap bean registration:

import {EnableComponentScan} from "@nodeboot/aot";

@EnableComponentScan()
@NodeBootApplication()
export class MyApp implements NodeBootApp {
    start(): Promise<NodeBootAppView> {
        return NodeBoot.run(ExpressServer);
    }
}

Optional: Use Custom Decorators

@EnableComponentScan({
  customDecorators: [MyCustomBean, AnotherDecorator]
})

โœ… Automatically resolves the dist/ directory in production and performs active scanning in dev (or if no JSON file is found).


๐Ÿ“ Directory Expectations

DirectoryPurpose
src/Your TypeScript source files
dist/Compiled output after tsc
.jsonOutput files: node-boot-beans.json, node-boot-models.json

๐Ÿ›  Internals

Scripts

  • node-boot-aot-beans.js: Scans compiled JS files for known decorators (@Service, @Controller, etc.) and generates node-boot-beans.json.

  • node-boot-aot-models.js: Scans @Model()-decorated classes and generates a JSON Schema file (node-boot-models.json).

Decorator

  • @EnableComponentScan(options?: { customDecorators?: Function[] }): Scans and imports bean modules based on decorators. Uses prebuilt JSON for performance when available.

โœ… Benefits

  • Fast Startup: Avoids expensive runtime filesystem scans in production.
  • Predictable Component Importing: Always imports only whatโ€™s required.
  • OpenAPI-Ready: JSON schema generation for API modeling & docs.
  • Flexible: Supports custom decorators and intelligent fallbacks.

๐Ÿ”ฎ Future Ideas

  • CLI interface for all AOT operations
  • Watch mode for development
  • Decorator metadata validation

๐Ÿ‘จโ€๐Ÿ’ป Author

Manuel Santos ๐Ÿ“ง ney.br.santos@gmail.com ๐ŸŒ GitHub


๐Ÿ“ License

MIT โ€” feel free to use, modify, and contribute.

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago