npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-generate-history-model

v0.0.31

Published

Code generation history models by models description

Downloads

150

Readme

Grunt plugin for code generation history models by models description

Build Status

This repository provides a grunt plugin for code generation history models by models description.

Установка

npm install grunt-generate-history-model

Как начать использовать

  • Установить typeorm.

    npm install typeorm

  • Создайте gencofig.json в корневом каталоге.

{
    "check":
        {
            "folders":[
                "./models"
            ]
        }
}

Свойство "folders" показывает для каких папок(и их внутренних папок) нужны модели логирования.

  • Установите декораты на нужные модели.
import { InnerClass } from "./innerClass";
import { GenerateHistory, IgnoredInHistory, HistoryIndex } from "grunt-generate-history-model";
import { Column } from "typeorm";

@GenerateHistory({
    "historyPath":"./generated/models"
})
export class Class {

    @Column('text', {'nullable': true })
    public property1: string;
    @Column('integer', {'nullable': true })
    @HistoryIndex()
    public indexProperty: number;
    @Column('text', {'nullable': true })
    @IgnoredInHistory()
    public ignoredProperty: any;
}
  • В package.json добавьте инициализирующую команду в свойство "scripts":
  "scripts": {
    "generation": "generateHistory"
  }

где "generateHistory" - строка для запуска плагина.

  • npm run generation

  • после завершения работы плагина по пути, указанному в декораторе GenerateHistory, появятся файлы с расширением ".ts" :

history model

import {Entity, Column, PrimaryColumn, ColumnOptions, Index, PrimaryGeneratedColumn} from 'typeorm';
import 'reflect-metadata';

@Entity('h_class')
export class hClass {
    @PrimaryGeneratedColumn()
    public __id?: number;

    @Column()
    public __operation: string;

    @Column('timestamp with time zone')
    @Index('ind_hClass_changed_date')
    public __changedate: Date;
   @Column('text', {'nullable': true})
    public property1: string;
   @Column('integer', {'nullable': true})
    @Index('ind_hClass_indexProperty')
    public indexProperty: number;
}

Декораторы

В этом плагине используются 3 декоратора: 1 для классов и 2 для свойств.

Декораторы для классов

GenerateHistory

Основной декоратор для создания моделей логирования.

+-------------+--------------+-------------------------------------------------------+
|                        @GenerateHistory                                            |
+------------------------------------------------------------------------------------+
|   property  |  Mandatory   |                      definition                       |
+-------------+--------------+-------------------------------------------------------+
| options     | true         | options, which used to creare history                 |- complex object
+-------------+--------------+-------------------------------------------------------+

+-------------+--------------+-------------------------------------------------------+
|                        options                                                     |
+------------------------------------------------------------------------------------+
|   property  |  Mandatory   |                      definition                       |
+-------------+--------------+-------------------------------------------------------+
| historyPath | true         | path,where history class will create                  |
+-------------+--------------+-------------------------------------------------------+
@GenerateHistory({'historyPath':'./generated/models'})

Декораторы для свойств

HistoryIndex

Декоратор, который используется для создания декоратора Index из библиотеки typeorm у свойства в модели логирования.

+------------------------------------------------------------------------------------------------+
|                        @HistoryIndex                                                           |
+------------------------------------------------------------------------------------------------+
|   property      |  Mandatory   |                      definition                               |
+-----------------+--------------+---------------------------------------------------------------+
| indexName(param)| false        | add name param to typeorm decorator Index in history model    |
+-----------------+--------------+---------------------------------------------------------------+
@HistoryIndex()

@HistoryIndex("name_index")

IgnoredInHistory

Декоратор, который используется, что бы свойство не было перенесено в модель логирования.

@IgnoredInHistory()

Связь с декораторами typeORM

Column

  • Все поля с декораторм Column, если не отмечены декоратором IgnoredInHistory, создаются и в модели логирования.
  • Если декоратор Column имеет свойство nullable, то это свойство переносится и в модель логирования.

Join Column

  • Если поле имеет составной тип и декоратор JoinColumn, то создается поле с типом number и именем, которое описано в декораторе.