@volcanicminds/typeorm 0.0.1 → 0.0.2

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,63 @@
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/backend)
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
+ ## Entities
33
+
34
+ For example, under `/src/entities` create the following:
35
+
36
+ ```ts
37
+ // player.e.ts
38
+
39
+ import { Entity, Column, Index, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm'
40
+
41
+ @Entity()
42
+ class Player {
43
+ @PrimaryGeneratedColumn()
44
+ id: number
45
+
46
+ @Index()
47
+ @Column() // default: nullable false
48
+ name: string
49
+
50
+ @Column({ type: 'varchar', array: true, nullable: true })
51
+ roles: string[]
52
+
53
+ @CreateDateColumn()
54
+ createdAt: Date
55
+
56
+ @UpdateDateColumn()
57
+ updatedAt: Date
58
+ }
59
+
60
+ module.exports = Player
61
+ ```
62
+
63
+ For more info and possibilities see [typeorm decorators](https://typeorm.io/decorator-reference)
package/TODO.md ADDED
@@ -0,0 +1,9 @@
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
+ - pass volcanic backend logging (or use normal console.log)
8
+ -
9
+ - 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,49 @@ 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
+ };
52
+ console.log('options ' + JSON.stringify(options));
53
+ }
54
+ if (options == null || Object.keys(options).length == 0) {
55
+ throw Error('Volcanic Database: options not specified');
56
+ }
57
+ const { classes, repositories, entities } = loaderEntities.load();
58
+ options.entities = [...(options.entities || []), ...(entities || [])];
59
+ new typeorm_1.DataSource(options)
60
+ .initialize()
61
+ .then((ds) => __awaiter(this, void 0, void 0, function* () {
62
+ const repository = {};
63
+ Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])));
64
+ global.database = {
65
+ model: classes,
66
+ repository: repository
67
+ };
68
+ return resolve(ds);
69
+ }))
70
+ .catch((error) => {
71
+ console.log(error);
72
+ reject(error);
73
+ });
74
+ });
75
+ });
76
+ }
14
77
  module.exports = start;
15
78
  module.exports.server = start;
16
79
  module.exports.default = start;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;AAEZ,MAAM,KAAK,GAAG,GAAS,EAAE;IACvB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,CAAA;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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;AACpC,sEAAuD;AAEvD,SAAe,KAAK,CAAC,OAAO;;QAC1B,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACjD,IAAI,MAAM,CAAC,qBAAqB,EAAE;gBAChC,OAAO,GAAG;oBACR,IAAI,EAAE,UAAU;oBAChB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,IAAI;oBACV,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,IAAI;oBACjB,OAAO,EAAE,IAAI;iBAId,CAAA;gBACD,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;aAClD;YAED,IAAI,OAAO,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE;gBACvD,MAAM,KAAK,CAAC,0CAA0C,CAAC,CAAA;aACxD;YAGD,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC,IAAI,EAAE,CAAA;YACjE,OAAO,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAA;YAErE,IAAI,oBAAU,CAAC,OAAO,CAAC;iBACpB,UAAU,EAAE;iBACZ,IAAI,CAAC,CAAO,EAAE,EAAE,EAAE;gBAEjB,MAAM,UAAU,GAAG,EAAE,CAAA;gBACrB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;gBAEzF,MAAM,CAAC,QAAQ,GAAG;oBAChB,KAAK,EAAE,OAAO;oBACd,UAAU,EAAE,UAAU;iBACvB,CAAA;gBAED,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;YACpB,CAAC,CAAA,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBAClB,MAAM,CAAC,KAAK,CAAC,CAAA;YACf,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA;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,25 @@
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
+ console.log('Looking for ' + pattern);
13
+ glob.sync(pattern, { nodir: true, nosort: true, stat: false }).forEach((f) => {
14
+ console.log(f);
15
+ const entityClass = require(f);
16
+ classes[entityClass.name] = entityClass;
17
+ repositories[pluralize(entityClass.name.toLowerCase())] = entityClass;
18
+ entities.push(entityClass);
19
+ });
20
+ });
21
+ console.log('Entities loaded: ' + entities.length);
22
+ return { classes, repositories, entities };
23
+ }
24
+ exports.load = load;
25
+ //# 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;AAGtC,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,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,OAAO,CAAC,CAAA;QACrC,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,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YAEd,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,CAAC,GAAG,CAAC,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;IAClD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAA;AAC5C,CAAC;AApBD,oBAoBC"}
@@ -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,20 @@
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
+ console.log('bbb');
14
+ const c1 = new global.database.model.User();
15
+ c1.breed = 'nread2';
16
+ c1.age = 'young';
17
+ c1.name = 'fuffy';
18
+ yield global.database.repository.users.save(c1);
19
+ }));
4
20
  //# 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,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,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,55 @@
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
19
+ // entities: []
20
+ // subscribers: [],
21
+ // migrations: []
22
+ }
23
+ console.log('options ' + JSON.stringify(options))
24
+ }
25
+
26
+ if (options == null || Object.keys(options).length == 0) {
27
+ throw Error('Volcanic Database: options not specified')
28
+ }
29
+
30
+ // load all entities & classes
31
+ const { classes, repositories, entities } = loaderEntities.load()
32
+ options.entities = [...(options.entities || []), ...(entities || [])]
33
+
34
+ new DataSource(options)
35
+ .initialize()
36
+ .then(async (ds) => {
37
+ // load uselful stuff
38
+ const repository = {}
39
+ Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])))
40
+
41
+ global.database = {
42
+ model: classes,
43
+ repository: repository
44
+ }
45
+
46
+ return resolve(ds)
47
+ })
48
+ .catch((error) => {
49
+ console.log(error)
50
+ reject(error)
51
+ })
52
+ })
5
53
  }
6
54
 
7
55
  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,25 @@
1
+ const glob = require('glob')
2
+ const pluralize = require('pluralize')
3
+ // const path = require('path')
4
+
5
+ export function load() {
6
+ const classes: any = {}
7
+ const repositories: any = {}
8
+ const entities: any[] = []
9
+
10
+ const patterns = [`${__dirname}/../entities/*.e.{ts,js}`, `${process.cwd()}/src/entities/*.e.{ts,js}`]
11
+ patterns.forEach((pattern) => {
12
+ console.log('Looking for ' + pattern)
13
+ glob.sync(pattern, { nodir: true, nosort: true, stat: false }).forEach((f: string) => {
14
+ console.log(f)
15
+
16
+ const entityClass = require(f)
17
+ classes[entityClass.name] = entityClass
18
+ repositories[pluralize(entityClass.name.toLowerCase())] = entityClass
19
+ entities.push(entityClass)
20
+ })
21
+ })
22
+
23
+ console.log('Entities loaded: ' + entities.length)
24
+ return { classes, repositories, entities }
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volcanicminds/typeorm",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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,11 @@
1
1
  'use strict'
2
2
 
3
- require('./index')()
4
3
  global.npmDebugServerStarted = true // internal debug purpose
4
+ require('./index')().then(async (AppDataSource) => {
5
+ console.log('bbb')
6
+ const c1 = new global.database.model.User()
7
+ c1.breed = 'nread2'
8
+ c1.age = 'young'
9
+ c1.name = 'fuffy'
10
+ await global.database.repository.users.save(c1)
11
+ })
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,