@volcanicminds/typeorm 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DOCKER.md ADDED
@@ -0,0 +1,26 @@
1
+ # hot to test
2
+
3
+ ```ruby
4
+ docker pull postgres:latest
5
+
6
+ # without data mount
7
+ docker run -itd -e POSTGRES_USER=vminds -e POSTGRES_PASSWORD=vminds -p 5432:5432 --name postgresql postgres
8
+
9
+ # with data mount
10
+ docker run -itd -e POSTGRES_USER=vminds -e POSTGRES_PASSWORD=vminds -p 5432:5432 -v /data:/var/lib/postgresql/data --name postgresql postgres
11
+
12
+
13
+ ```
14
+
15
+ # pgAdmin
16
+
17
+ ```ruby
18
+
19
+ docker pull dpage/pgadmin4:latest
20
+
21
+ docker run --name pgadmin-vminds -p 5051:80 -e "PGADMIN_DEFAULT_EMAIL=developers@volcanicminds.com" -e "PGADMIN_DEFAULT_PASSWORD=vminds" -d dpage/pgadmin4
22
+
23
+ # pgAdmin4: connect pgsql using correct IP read from inspect (retrieve your ID by docker ps)
24
+ docker inspect 6f14e1fa0702 | grep IPAddress
25
+
26
+ ```
package/README.md CHANGED
@@ -1 +1,83 @@
1
- # volcanic-database-typeorm
1
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2
+ [![opensource](https://img.shields.io/badge/open-source-blue)](https://en.wikipedia.org/wiki/Open_source)
3
+ [![volcanic-backend](https://img.shields.io/badge/volcanic-minds-orange)](https://github.com/volcanicminds/volcanic-backend)
4
+ [![npm](https://img.shields.io/badge/package-npm-white)](https://www.npmjs.com/package/@volcanicminds/typeorm)
5
+
6
+ # volcanic-database-typeorm
7
+
8
+ ## Based on
9
+
10
+ Based on [Fastify](https://www.fastify.io) ([GitHub](https://github.com/fastify/fastify)).
11
+
12
+ Based on [TypeORM](https://www.typeorm.io) ([GitHub](https://github.com/typeorm/typeorm)).
13
+
14
+ And, what you see in [package.json](package.json).
15
+
16
+ ## How to install
17
+
18
+ ```js
19
+ yarn add @volcanicminds/typeorm
20
+ ```
21
+
22
+ ## How to upgrade packages
23
+
24
+ ```js
25
+ yarn upgrade-deps
26
+ ```
27
+
28
+ ## Postgres (data types)
29
+
30
+ [typeorm postgres: database schema / column types](https://github.com/typeorm/typeorm/blob/master/test/functional/database-schema/column-types/postgres/entity/Post.ts)
31
+
32
+ [postgres data types: all](https://www.postgresql.org/docs/current/datatype.html)
33
+ [postgres data types: numeric](https://www.postgresql.org/docs/current/datatype-numeric.html)
34
+
35
+ ## Entities
36
+
37
+ For example, under `/src/entities` create the following:
38
+
39
+ ```ts
40
+ // player.e.ts
41
+
42
+ import { Entity, Column, Index, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm'
43
+
44
+ @Entity()
45
+ class Player {
46
+ @PrimaryGeneratedColumn()
47
+ id: number
48
+
49
+ @Index()
50
+ @Column() // default: nullable false
51
+ name: string
52
+
53
+ @Column({ type: 'varchar', array: true, nullable: true })
54
+ roles: string[]
55
+
56
+ @CreateDateColumn()
57
+ createdAt: Date
58
+
59
+ @UpdateDateColumn()
60
+ updatedAt: Date
61
+ }
62
+
63
+ module.exports = Player
64
+ ```
65
+
66
+ For more info and possibilities see [typeorm decorators](https://typeorm.io/decorator-reference)
67
+
68
+ ## Enviroment
69
+
70
+ ```rb
71
+ # or automatically use LOG_LEVEL
72
+ LOG_DB_LEVEL=warn
73
+ LOG_COLORIZE=true
74
+ ```
75
+
76
+ Log levels:
77
+
78
+ - **trace**: useful and useless messages, verbose mode
79
+ - **debug**: well, for debugging purposes.. you know what I mean
80
+ - **info**: minimal logs necessary for understand that everything is working fine
81
+ - **warn**: useful warnings if the environment is controlled
82
+ - **error**: print out errors even if not blocking/fatal errors
83
+ - **fatal**: ok you are dead now, but you want to know
package/TODO.md ADDED
@@ -0,0 +1,7 @@
1
+ # TODO
2
+
3
+ - loading entities
4
+ - expose entities to global
5
+ - expose repo (controller) to global
6
+ - pass options by config file or structure
7
+ - test if is possibile to avoid add package pg here (let choose on the top project)
@@ -0,0 +1,2 @@
1
+ import 'reflect-metadata';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,kBAAkB,CAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,27 @@
1
1
  'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,9 +31,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
32
  });
10
33
  };
11
- const start = () => __awaiter(void 0, void 0, void 0, function* () {
12
- return true;
13
- });
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ require("reflect-metadata");
36
+ const typeorm_1 = require("typeorm");
37
+ const loaderEntities = __importStar(require("./lib/loader/entities"));
38
+ function start(options) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return new Promise((resolve, reject) => {
41
+ if (global.npmDebugServerStarted) {
42
+ options = {
43
+ type: 'postgres',
44
+ host: '127.0.0.1',
45
+ port: 5432,
46
+ username: 'vminds',
47
+ password: 'vminds',
48
+ database: 'vminds',
49
+ synchronize: true,
50
+ logging: true,
51
+ logger: ''
52
+ };
53
+ }
54
+ if (options == null || Object.keys(options).length == 0) {
55
+ throw Error('Volcanic Database: options not specified');
56
+ }
57
+ const { LOG_DB_LEVEL = process.env.LOG_LEVEL || 'trace', LOG_COLORIZE = true } = process.env;
58
+ const logLevel = LOG_DB_LEVEL === 'trace'
59
+ ? 'all'
60
+ : LOG_DB_LEVEL === 'debug'
61
+ ? 'query'
62
+ : LOG_DB_LEVEL === 'info'
63
+ ? 'info'
64
+ : LOG_DB_LEVEL === 'warn'
65
+ ? 'warn'
66
+ : LOG_DB_LEVEL === 'error'
67
+ ? 'error'
68
+ : false;
69
+ const { classes, repositories, entities } = loaderEntities.load();
70
+ options.entities = [...(options.entities || []), ...(entities || [])];
71
+ options.logger = LOG_COLORIZE ? 'advanced-console' : 'simple-console';
72
+ options.logging = logLevel;
73
+ new typeorm_1.DataSource(options)
74
+ .initialize()
75
+ .then((ds) => __awaiter(this, void 0, void 0, function* () {
76
+ const repository = {};
77
+ Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])));
78
+ global.database = {
79
+ model: classes,
80
+ repository: repository
81
+ };
82
+ return resolve(ds);
83
+ }))
84
+ .catch((error) => reject(error));
85
+ });
86
+ });
87
+ }
14
88
  module.exports = start;
15
89
  module.exports.server = start;
16
90
  module.exports.default = start;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mapp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AA;AAED,MAAM,CAAC,OAAO,GAAG,KAAK,CAAA;AACtB,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAA;AAC7B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAA"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const typeorm_1 = require("typeorm");
13
+ let Cat = class Cat {
14
+ };
15
+ __decorate([
16
+ (0, typeorm_1.PrimaryGeneratedColumn)(),
17
+ __metadata("design:type", Number)
18
+ ], Cat.prototype, "id", void 0);
19
+ __decorate([
20
+ (0, typeorm_1.Column)(),
21
+ __metadata("design:type", String)
22
+ ], Cat.prototype, "name", void 0);
23
+ __decorate([
24
+ (0, typeorm_1.Column)(),
25
+ __metadata("design:type", String)
26
+ ], Cat.prototype, "breed", void 0);
27
+ __decorate([
28
+ (0, typeorm_1.Column)(),
29
+ __metadata("design:type", String)
30
+ ], Cat.prototype, "age", void 0);
31
+ Cat = __decorate([
32
+ (0, typeorm_1.Entity)()
33
+ ], Cat);
34
+ module.exports = Cat;
35
+ //# sourceMappingURL=cat.e.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat.e.js","sourceRoot":"","sources":["../../../lib/entities/cat.e.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAgE;AAGhE,IAAM,GAAG,GAAT,MAAM,GAAG;CAYR,CAAA;AAXC;IAAC,IAAA,gCAAsB,GAAE;;+BACf;AAEV;IAAC,IAAA,gBAAM,GAAE;;iCACG;AAEZ;IAAC,IAAA,gBAAM,GAAE;;kCACI;AAEb;IAAC,IAAA,gBAAM,GAAE;;gCACE;AAXP,GAAG;IADR,IAAA,gBAAM,GAAE;GACH,GAAG,CAYR;AAED,MAAM,CAAC,OAAO,GAAG,GAAG,CAAA"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const typeorm_1 = require("typeorm");
13
+ let Dog = class Dog {
14
+ };
15
+ __decorate([
16
+ (0, typeorm_1.PrimaryGeneratedColumn)(),
17
+ __metadata("design:type", Number)
18
+ ], Dog.prototype, "id", void 0);
19
+ __decorate([
20
+ (0, typeorm_1.Column)(),
21
+ __metadata("design:type", String)
22
+ ], Dog.prototype, "name", void 0);
23
+ __decorate([
24
+ (0, typeorm_1.Column)(),
25
+ __metadata("design:type", String)
26
+ ], Dog.prototype, "color", void 0);
27
+ __decorate([
28
+ (0, typeorm_1.Column)(),
29
+ __metadata("design:type", String)
30
+ ], Dog.prototype, "age", void 0);
31
+ Dog = __decorate([
32
+ (0, typeorm_1.Entity)()
33
+ ], Dog);
34
+ module.exports = Dog;
35
+ //# sourceMappingURL=dog.e.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dog.e.js","sourceRoot":"","sources":["../../../lib/entities/dog.e.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAgE;AAGhE,IAAM,GAAG,GAAT,MAAM,GAAG;CAYR,CAAA;AAXC;IAAC,IAAA,gCAAsB,GAAE;;+BACf;AAEV;IAAC,IAAA,gBAAM,GAAE;;iCACG;AAEZ;IAAC,IAAA,gBAAM,GAAE;;kCACI;AAEb;IAAC,IAAA,gBAAM,GAAE;;gCACE;AAXP,GAAG;IADR,IAAA,gBAAM,GAAE;GACH,GAAG,CAYR;AAED,MAAM,CAAC,OAAO,GAAG,GAAG,CAAA"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const typeorm_1 = require("typeorm");
13
+ let User = class User {
14
+ };
15
+ __decorate([
16
+ (0, typeorm_1.PrimaryGeneratedColumn)(),
17
+ __metadata("design:type", Number)
18
+ ], User.prototype, "id", void 0);
19
+ __decorate([
20
+ (0, typeorm_1.Index)(),
21
+ (0, typeorm_1.Column)(),
22
+ __metadata("design:type", String)
23
+ ], User.prototype, "name", void 0);
24
+ __decorate([
25
+ (0, typeorm_1.Column)({ type: 'varchar', array: true, nullable: true }),
26
+ __metadata("design:type", Array)
27
+ ], User.prototype, "roles", void 0);
28
+ __decorate([
29
+ (0, typeorm_1.CreateDateColumn)(),
30
+ __metadata("design:type", Date)
31
+ ], User.prototype, "createdAt", void 0);
32
+ __decorate([
33
+ (0, typeorm_1.UpdateDateColumn)(),
34
+ __metadata("design:type", Date)
35
+ ], User.prototype, "updatedAt", void 0);
36
+ User = __decorate([
37
+ (0, typeorm_1.Entity)()
38
+ ], User);
39
+ module.exports = User;
40
+ //# sourceMappingURL=user.e.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.e.js","sourceRoot":"","sources":["../../../lib/entities/user.e.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAA2G;AAG3G,IAAM,IAAI,GAAV,MAAM,IAAI;CAgBT,CAAA;AAfC;IAAC,IAAA,gCAAsB,GAAE;;gCACf;AAEV;IAAC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;kCACG;AAEZ;IAAC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mCAC1C;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AAfX,IAAI;IADT,IAAA,gBAAM,GAAE;GACH,IAAI,CAgBT;AAED,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.load = void 0;
4
+ const glob = require('glob');
5
+ const pluralize = require('pluralize');
6
+ function load() {
7
+ const classes = {};
8
+ const repositories = {};
9
+ const entities = [];
10
+ const patterns = [`${__dirname}/../entities/*.e.{ts,js}`, `${process.cwd()}/src/entities/*.e.{ts,js}`];
11
+ patterns.forEach((pattern) => {
12
+ glob.sync(pattern, { nodir: true, nosort: true, stat: false }).forEach((f) => {
13
+ const entityClass = require(f);
14
+ classes[entityClass.name] = entityClass;
15
+ repositories[pluralize(entityClass.name.toLowerCase())] = entityClass;
16
+ entities.push(entityClass);
17
+ });
18
+ });
19
+ return { classes, repositories, entities };
20
+ }
21
+ exports.load = load;
22
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../../lib/loader/entities.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAEtC,SAAgB,IAAI;IAClB,MAAM,OAAO,GAAQ,EAAE,CAAA;IACvB,MAAM,YAAY,GAAQ,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAU,EAAE,CAAA;IAE1B,MAAM,QAAQ,GAAG,CAAC,GAAG,SAAS,0BAA0B,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,2BAA2B,CAAC,CAAA;IACtG,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE;YACnF,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;YAC9B,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,WAAW,CAAA;YACvC,YAAY,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,WAAW,CAAA;YACrE,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAA;AAC5C,CAAC;AAhBD,oBAgBC"}
@@ -0,0 +1,7 @@
1
+ export declare class Cat {
2
+ id: number;
3
+ name: string;
4
+ breed: string;
5
+ age: string;
6
+ }
7
+ //# sourceMappingURL=cat.entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat.entity.d.ts","sourceRoot":"","sources":["../../../lib/schema/cat.entity.ts"],"names":[],"mappings":"AAEA,qBACa,GAAG;IAEd,EAAE,EAAE,MAAM,CAAA;IAGV,IAAI,EAAE,MAAM,CAAA;IAGZ,KAAK,EAAE,MAAM,CAAA;IAGb,GAAG,EAAE,MAAM,CAAA;CACZ"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Cat = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ let Cat = class Cat {
15
+ };
16
+ __decorate([
17
+ (0, typeorm_1.Column)(),
18
+ __metadata("design:type", Number)
19
+ ], Cat.prototype, "id", void 0);
20
+ __decorate([
21
+ (0, typeorm_1.Column)(),
22
+ __metadata("design:type", String)
23
+ ], Cat.prototype, "name", void 0);
24
+ __decorate([
25
+ (0, typeorm_1.Column)(),
26
+ __metadata("design:type", String)
27
+ ], Cat.prototype, "breed", void 0);
28
+ __decorate([
29
+ (0, typeorm_1.Column)(),
30
+ __metadata("design:type", String)
31
+ ], Cat.prototype, "age", void 0);
32
+ Cat = __decorate([
33
+ (0, typeorm_1.Entity)()
34
+ ], Cat);
35
+ exports.Cat = Cat;
36
+ //# sourceMappingURL=cat.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat.entity.js","sourceRoot":"","sources":["../../../lib/schema/cat.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAwC;AAGjC,IAAM,GAAG,GAAT,MAAM,GAAG;CAYf,CAAA;AAXC;IAAC,IAAA,gBAAM,GAAE;;+BACC;AAEV;IAAC,IAAA,gBAAM,GAAE;;iCACG;AAEZ;IAAC,IAAA,gBAAM,GAAE;;kCACI;AAEb;IAAC,IAAA,gBAAM,GAAE;;gCACE;AAXA,GAAG;IADf,IAAA,gBAAM,GAAE;GACI,GAAG,CAYf;AAZY,kBAAG"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../start.ts"],"names":[],"mappings":""}
package/dist/start.js CHANGED
@@ -1,4 +1,19 @@
1
1
  'use strict';
2
- require('./index')();
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
3
11
  global.npmDebugServerStarted = true;
12
+ require('./index')().then((AppDataSource) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const c1 = new global.database.model.User();
14
+ c1.breed = 'nread2';
15
+ c1.age = 'young';
16
+ c1.name = 'fuffy';
17
+ yield global.database.repository.users.save(c1);
18
+ }));
4
19
  //# sourceMappingURL=start.js.map
package/dist/start.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"start.js","sourceRoot":"","sources":["../start.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,CAAC,SAAS,CAAC,EAAE,CAAA;AACpB,MAAM,CAAC,qBAAqB,GAAG,IAAI,CAAA"}
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../start.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;AAEZ,MAAM,CAAC,qBAAqB,GAAG,IAAI,CAAA;AACnC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAO,aAAa,EAAE,EAAE;IAChD,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;IAC3C,EAAE,CAAC,KAAK,GAAG,QAAQ,CAAA;IACnB,EAAE,CAAC,GAAG,GAAG,OAAO,CAAA;IAChB,EAAE,CAAC,IAAI,GAAG,OAAO,CAAA;IACjB,MAAM,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACjD,CAAC,CAAA,CAAC,CAAA"}
package/index.ts CHANGED
@@ -1,7 +1,65 @@
1
1
  'use strict'
2
2
 
3
- const start = async (options) => {
4
- return true
3
+ import 'reflect-metadata'
4
+ import { DataSource } from 'typeorm'
5
+ import * as loaderEntities from './lib/loader/entities'
6
+
7
+ async function start(options) {
8
+ return new Promise<DataSource>((resolve, reject) => {
9
+ if (global.npmDebugServerStarted) {
10
+ options = {
11
+ type: 'postgres',
12
+ host: '127.0.0.1',
13
+ port: 5432,
14
+ username: 'vminds',
15
+ password: 'vminds',
16
+ database: 'vminds',
17
+ synchronize: true,
18
+ logging: true, // query, error, schema, warn, info, all
19
+ logger: '' // advanced-console, simple-console
20
+ }
21
+ }
22
+
23
+ if (options == null || Object.keys(options).length == 0) {
24
+ throw Error('Volcanic Database: options not specified')
25
+ }
26
+
27
+ const { LOG_DB_LEVEL = process.env.LOG_LEVEL || 'trace', LOG_COLORIZE = true } = process.env
28
+
29
+ const logLevel: string | boolean =
30
+ LOG_DB_LEVEL === 'trace'
31
+ ? 'all'
32
+ : LOG_DB_LEVEL === 'debug'
33
+ ? 'query'
34
+ : LOG_DB_LEVEL === 'info'
35
+ ? 'info'
36
+ : LOG_DB_LEVEL === 'warn'
37
+ ? 'warn'
38
+ : LOG_DB_LEVEL === 'error'
39
+ ? 'error'
40
+ : false
41
+
42
+ const { classes, repositories, entities } = loaderEntities.load()
43
+ options.entities = [...(options.entities || []), ...(entities || [])]
44
+ options.logger = LOG_COLORIZE ? 'advanced-console' : 'simple-console'
45
+ options.logging = logLevel
46
+
47
+ new DataSource(options)
48
+ .initialize()
49
+ .then(async (ds) => {
50
+ // load uselful stuff
51
+ const repository = {}
52
+ Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])))
53
+
54
+ global.database = {
55
+ model: classes,
56
+ repository: repository
57
+ }
58
+
59
+ return resolve(ds)
60
+ })
61
+ .catch((error) => reject(error))
62
+ })
5
63
  }
6
64
 
7
65
  module.exports = start
@@ -0,0 +1,22 @@
1
+ import { Entity, Column, Index, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm'
2
+
3
+ @Entity()
4
+ class User {
5
+ @PrimaryGeneratedColumn()
6
+ id: number
7
+
8
+ @Index()
9
+ @Column()
10
+ name: string
11
+
12
+ @Column({ type: 'varchar', array: true, nullable: true })
13
+ roles: string[]
14
+
15
+ @CreateDateColumn()
16
+ createdAt: Date
17
+
18
+ @UpdateDateColumn()
19
+ updatedAt: Date
20
+ }
21
+
22
+ module.exports = User
@@ -0,0 +1,20 @@
1
+ const glob = require('glob')
2
+ const pluralize = require('pluralize')
3
+
4
+ export function load() {
5
+ const classes: any = {}
6
+ const repositories: any = {}
7
+ const entities: any[] = []
8
+
9
+ const patterns = [`${__dirname}/../entities/*.e.{ts,js}`, `${process.cwd()}/src/entities/*.e.{ts,js}`]
10
+ patterns.forEach((pattern) => {
11
+ glob.sync(pattern, { nodir: true, nosort: true, stat: false }).forEach((f: string) => {
12
+ const entityClass = require(f)
13
+ classes[entityClass.name] = entityClass
14
+ repositories[pluralize(entityClass.name.toLowerCase())] = entityClass
15
+ entities.push(entityClass)
16
+ })
17
+ })
18
+
19
+ return { classes, repositories, entities }
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volcanicminds/typeorm",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "description": "TypeORM for the volcanic (minds) backend",
6
6
  "keywords": [
@@ -23,6 +23,7 @@
23
23
  "upgrade-deps": "npm-upgrade"
24
24
  },
25
25
  "dependencies": {
26
+ "pluralize": "^8.0.0",
26
27
  "reflect-metadata": "^0.1.13",
27
28
  "typeorm": "^0.3.10"
28
29
  },
package/start.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  'use strict'
2
2
 
3
- require('./index')()
4
3
  global.npmDebugServerStarted = true // internal debug purpose
4
+ require('./index')().then(async (AppDataSource) => {
5
+ const c1 = new global.database.model.User()
6
+ c1.breed = 'nread2'
7
+ c1.age = 'young'
8
+ c1.name = 'fuffy'
9
+ await global.database.repository.users.save(c1)
10
+ })
package/tsconfig.json CHANGED
@@ -17,6 +17,7 @@
17
17
  "emitDecoratorMetadata": true,
18
18
  "experimentalDecorators": true,
19
19
  "useUnknownInCatchVariables": false,
20
+ "strictPropertyInitialization": false,
20
21
  "target": "es6",
21
22
  "sourceMap": true,
22
23
  "allowJs": true,