# @typemon/metadata

> Highly abstracted and simplified metadata management.

Latest version **1.0.0-rc.4** (published 2021-01-26) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @typemon/metadata
pnpm add @typemon/metadata
yarn add @typemon/metadata
bun add @typemon/metadata
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.4 |
| Published | 2021-01-26 |
| First published | 2020-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Monster Space Network |
| Maintainers | monsterspace.network |
| Keywords | monster-space-network, typemon, metadata |

## Links

- npm: https://www.npmjs.com/package/@typemon/metadata
- Repository: https://gitlab.com/monster-space-network/typemon/metadata
- Homepage: https://gitlab.com/monster-space-network/typemon/metadata#readme
- Issues: https://gitlab.com/monster-space-network/typemon/metadata/issues
- npm.io page: https://npm.io/package/@typemon/metadata

## Dependencies (1)

- [@typemon/check](https://npm.io/package/@typemon/check.md) ^5.2.0

## Recent versions

- 1.0.0-rc.4 (latest) — 2021-01-26
- 1.0.0-rc.3 — 2020-12-27
- 1.0.0-rc.2 — 2020-12-25
- 1.0.0-rc.1 — 2020-12-21
- 1.0.0-rc.0 — 2020-10-27

## README

# Metadata - [![version](https://img.shields.io/npm/v/@typemon/metadata.svg)](https://www.npmjs.com/package/@typemon/metadata) [![license](https://img.shields.io/npm/l/@typemon/metadata.svg)](https://gitlab.com/monster-space-network/typemon/metadata/blob/master/LICENSE) ![typescript-version](https://img.shields.io/npm/dependency-version/@typemon/metadata/dev/typescript.svg) [![gitlab-pipeline](https://gitlab.com/monster-space-network/typemon/metadata/badges/master/pipeline.svg)](https://gitlab.com/monster-space-network/typemon/metadata/-/pipelines) [![coverage](https://gitlab.com/monster-space-network/typemon/metadata/badges/master/coverage.svg)](https://gitlab.com/monster-space-network/typemon/metadata/-/graphs/master/charts)
- Provides highly abstracted metadata management functions
- Support inheritance and parameter metadata
- Fully integrated with decorators



## Installation
```
$ npm install @typemon/metadata reflect-metadata
```

### [TypeScript](https://github.com/Microsoft/TypeScript)
Configure metadata and decorator options.
```json
{
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
}
```

### [Reflect Metadata](https://github.com/rbuckton/reflect-metadata)
Import only once at the application entry point.
```typescript
import 'reflect-metadata';
```



## Usage
I don't think I need an explanation.
```typescript
const metadata: Metadata = Metadata.of({
    target,
    propertyKey?,
    parameterIndex?,
});

metadata.set(key, value);
metadata.get(key, value);
metadata.delete(key);
```

This is recommended for a one-time operation.
```typescript
Metadata.set({
    target,
    propertyKey?,
    parameterIndex?,
    key,
    value,
});
```



## Parameter Metadata
In the same way, you can easily manage parameter metadata as well.
- Inheritance is supported just like regular metadata.
- If possible, the `design:type` metadata is set.
```typescript
@Decorator()
class Parent {
    public constructor(
        public readonly parameter: string,
    ) { }
}

@Decorator()
class Child extends Parent { }

const child: Metadata = Metadata.of({
    target: Child,
    parameterIndex: 0,
});
const parent: Metadata = Metadata.of({
    target: Parent,
    parameterIndex: 0,
});

expect(child.parent).toBe(parent);
expect(child.get('design:type')).toBe(String);
expect((): void => child.getOwn('design:type')).toThrow(MetadataDoesNotExistError);
```



## Decorator
You can easily create decorators, and basically decorate them everywhere.
```typescript
function Decorator(...parameters: any): Metadata.Decorator {
    return Metadata.decorator((metadata: Metadata): void => {
        ...
    });
}

@Decorator(key, value)
class Example {
    @Decorator(key, value)
    public static property: unknown;

    @Decorator(key, value)
    public static method(
        @Decorator(key, value)
        parameter: unknown,
    ): void { }

    @Decorator(key, value)
    public property: unknown;

    public constructor(
        @Decorator(key, value)
        parameter: unknown,
    ) { }

    @Decorator(key, value)
    public method(
        @Decorator(key, value)
        parameter: unknown,
    ): void { }
}
```

You can limit the type.
```typescript
function Decorator(...parameters: any): ClassDecorator {
    return Metadata.decorator((metadata: Metadata): void => {
        ...
    });
}
```

You can combine types.
```typescript
function Decorator(...parameters: any): PropertyDecorator & MethodDecorator {
    return Metadata.decorator((metadata: Metadata): void => {
        ...
    });
}
```

You can also decorate dynamically.
```typescript
Metadata.decorate({
    target,
    propertyKey?,
    parameterIndex?,
    decorators,
});
```

---
_Source: https://npm.io/package/@typemon/metadata · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
