@cedjj/magnus-metadata
TypeScript icon, indicating that this package has built-in type declarations

0.0.9-dev • Public • Published

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 :

@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)

 @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

@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

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

Readme

Keywords

none

Package Sidebar

Install

npm i @cedjj/magnus-metadata

Weekly Downloads

1

Version

0.0.9-dev

License

Apache-2.0

Unpacked Size

71.2 kB

Total Files

34

Last publish

Collaborators

  • mbrmj
  • magnus-cloud