1.2.2 • Published 1 month ago

@trapi/metadata v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@trapi/metadata 📚

main codecov Known Vulnerabilities npm version

This package is responsible for generating metadata information by analyzing TypeScript REST decorators (self defined or third-party libraries). The metadata can than be used for generating a documentation according to the OpenAPI Specification or to create route schema/handling for libraries like: express, koa, etc.

Inspect the CHANGELOG.md in the repository for breaking changes.

Table of Contents

Installation

npm install --save @trapi/metadata

Configuration

Metadata

The metadata configuration object (Top-Level) is the main configuration object of this library and can be defined according the following type scheme:

import { 
    CacheOptions,
    DecoratorConfig 
} from "@trapi/metadata";

export type EntryPointOptions = {
    cwd: string,
    pattern: string
};

export type EntryPoint = string |
    string[] |
    EntryPointOptions |
    EntryPointOptions[];

export interface Options {
    /**
     * The entry point to your API.
     */
    entryPoint: EntryPoint;
    
    /**
     * Directory to ignore during TypeScript files scan.
     * Default: []
     */
    ignore?: string[];

    /**
     * Directory to allow during TypeScript files scan.
     * Default: []
     */
    allow?: string[],
    
    /**
     * Directory to store and cache metadata files.
     * Default: false
     */
    cache?: string | boolean | Partial<CacheOptions>;
    
    /**
     * Manual decorator properties configuration.
     */
    decorators?: DecoratorConfig[],

    /**
     * Load a specific preset configuration.
     */
    preset?: string;
}

Limitations

At the moment only the following TypeScript UtilityTypes are supported:

  • NonNullable
  • Omit
  • Partial
  • Readonly
  • Record
  • Required
  • Pick

Usage

import {
    generateMetadata,
    Metadata
} from "@trapi/metadata";
import path from "node:path";
import process from "node:process";

const metadata : Metadata = await generateMetadata({
    entryPoint: ['src/controllers/**/*.ts'],
    ignore: ['**/node_modules/**'],
    cache: true,
    preset: '@trapi/preset-routup'
});

console.log(metadata);
// {controllers: [], referenceTypes: {}}

Structure

coming soon

License

Made with 💚

Published under MIT License.

1.2.2

1 month ago

1.2.1

3 months ago

1.2.0

4 months ago

1.1.0

4 months ago

1.0.1

4 months ago

1.0.0

5 months ago

1.0.0-alpha.8

1 year ago

1.0.0-alpha.7

1 year ago

1.0.0-alpha.6

1 year ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.4

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

0.3.0

2 years ago

0.2.1

2 years ago

0.4.1

1 year ago

0.2.3

2 years ago

0.4.0

1 year ago

0.3.1

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.1

3 years ago