# @cedjj/magnus-metadata

> BLA BLAB

Latest version **0.0.9-dev** (published 2019-03-05) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @cedjj/magnus-metadata
pnpm add @cedjj/magnus-metadata
yarn add @cedjj/magnus-metadata
bun add @cedjj/magnus-metadata
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9-dev |
| Published | 2019-03-05 |
| First published | 2019-03-05 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 69.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Salim Benabbou |
| Maintainers | mbrmj, magnus-cloud |

## Links

- npm: https://www.npmjs.com/package/@cedjj/magnus-metadata
- Repository: https://gitlab.com/magnus-tooling/magnus-metadata
- Homepage: https://gitlab.com/magnus-tooling/magnus-metadata#README
- Issues: https://gitlab.com/magnus-tooling/magnus-metadata/issues
- npm.io page: https://npm.io/package/@cedjj/magnus-metadata

## Dependencies (2)

- [big.js](https://npm.io/package/big.js.md) ^4.0.2
- [immutable](https://npm.io/package/immutable.md) ^3.8.1

## Recent versions

- 0.0.9-dev (latest) — 2019-03-05

## README

# Magnus Metadata

This library aim to provide a set of annotations/decorators that will expose meta-data to the different elements of the platform(front/back/shared).
### Annotations/decoators
 - Entity : a set of annotations to define the entity metadata 
	 - Attributes
	 - Reference 
	 - hooks
 - Modules
 - Static Values


### Handler And registry
Registry to store all the metadata
Handler to read the metadata for using inside you app. must copy the metadata first in 	a local registry, Altough it's already taken care of inside magnnus-back and magnus-front

## Usage

### Entity

To Define an Entity, annotate it this way :

```typescript
@Entity({
  name: "DummyEntity",
  displayName: "DummyEntity",
  model: "DummyEntity",
  endPoint: "dummyendpoint",
  embedded: false
})
```
- name: name of the entity this will be its code
-  displayName : Label to be displayed, In the future this will be the i18n key
- model : Persistence model name
- endPoint : url endpoints to access this ressource
- embedded : if this is true the generated schema will be inside the entity referencing this one

###  Attribute 

#### Simple (string)

```typescript
 @Attribute({ magnus_key:'DummyEntity:code', displayName: 'CODE', type: TypeField.SimpleField })
  code: string;
```

- magnus_key : [entityName]:[fieldName] 
-  displayName : Label to be displayed, In the future this will be the i18n key
-  type: the type of field
	- SimpleField
	- NumberField
	- DateField
	- BooleanField
	- ListField[TO BE TESTED]

### Reference
```typescript
@Reference({
magnus_key: 'DummyEntity:dummyRef'
    displayName: "DummyEntity",
    targetModel: "DummyEntity",
    fieldLabel:"identifiant",
    type: TypeReference.ONE_TO_ONE,
    targetType: DoubleDummyEntity
  })
  dummyRef: DoubleDummyEntity;
```

- magnus_key : [entityName]:[fieldName] 
-  displayName : Label to be displayed, In the future this will be the i18n key
- targetModel : target persistence model
-  type: the type of Reference
	- ONE_TO_ONE
	- ONE_TO_MANY
	- MANY_TO_ONE
	- MANY_TO_MANY
- targetType : class of target entity

# Full example

```typescript

import {Entity, Attribute, Reference, TypeField, TypeReference, IModel} from 'magnus-metadata/magnus_metadata';

@Entity({
  name: "MgEntryPoint",
  displayName: "MgEntryPoint",
  model: "MgEntryPoint",
  endPoint: "entrypoints",
  embedded: true
})
export class MgEntryPoint extends IModel {

  @Attribute({magnus_key :"MgModule:path", displayName: 'MgModule:path', type: TypeField.SimpleField })
  path: string;

  @Attribute({magnus_key :"MgModule:as", displayName: 'MgModule:as', type: TypeField.SimpleField })
  as: string;

  @Attribute({magnus_key :"MgModule:component", displayName: 'MgModule:component', type: TypeField.SimpleField })
  component: string;

  @Attribute({magnus_key :"MgModule:package_path", displayName: 'MgModule:package_path', type: TypeField.SimpleField })
  package_path: string;
}


@Entity({
  name: "MgModule",
  displayName: "MgModule",
  model: "MgModule",
  endPoint: "modules"
})
export class MgModule extends IModel {

  @Attribute({magnus_key :"MgModule:name", displayName: 'MgModule:name', type: TypeField.SimpleField })
  name: string;
  @Attribute({magnus_key :"MgModule:displayName", displayName: 'MgModule:displayName', type: TypeField.SimpleField })
  displayName: string;

  @Reference({magnus_key :"MgModule:entryPoint",
      displayName: "MgEntryPoint",
      targetModel: "MgEntryPoint",
      fieldLabel:"path",
      type: TypeReference.ONE_TO_ONE,
      targetType:MgEntryPoint
    })
  entryPoint:MgEntryPoint;

  @Attribute({magnus_key :"MgModule:homePage", displayName: 'MgModule:homePage', type: TypeField.SimpleField })
  homePage: string;
}


@Entity({
  name: "MgFeature",
  displayName: "MgFeature",
  model: "MgFeature",
  endPoint: "features"
})
export class MgFeature extends IModel {

  @Attribute({magnus_key :"MgFeature:name", displayName: 'MgFeature:name', type: TypeField.SimpleField })
  name: string;

  @Attribute({magnus_key :"MgFeature:displayName", displayName: 'MgFeature:displayName', type: TypeField.SimpleField })
  displayName: string;

  @Reference({magnus_key :"MgFeature:childs",
     displayName: "MgModule",
     targetModel: "MgModule",
     fieldLabel:"displayName",
     type: TypeReference.MANY_TO_ONE,
     targetType:MgModule
   })
  childs:Array<MgModule>;

}

@Entity({
  name: "MgApp",
  displayName: "MgApp",
  model: "MgApp",
  endPoint: "apps"
})
export class MgApp extends IModel {

  @Attribute({magnus_key :"MgApp:name", displayName: 'MgApp:name', type: TypeField.SimpleField })
  name: string;


  @Reference({magnus_key :"MgApp:features",
    displayName: "MgFeature",
    targetModel: "MgFeature",
    type: TypeReference.ONE_TO_MANY,
    targetType:MgFeature
  })
  features: Array<MgFeature>;
}



### TODO
- add validation doc

```

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