@volcanicminds/typeorm 0.0.7 → 0.0.9
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/dist/index.d.ts +4 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/entities/user.e.d.ts +7 -9
- package/dist/lib/entities/user.e.js +22 -27
- package/dist/lib/entities/user.e.js.map +1 -1
- package/dist/lib/loader/userManager.d.ts +5 -0
- package/dist/lib/loader/userManager.js +75 -0
- package/dist/lib/loader/userManager.js.map +1 -0
- package/esm/index.d.ts +4 -2
- package/esm/index.js +5 -3
- package/esm/index.js.map +1 -1
- package/esm/lib/entities/user.e.d.ts +7 -9
- package/esm/lib/entities/user.e.js +22 -27
- package/esm/lib/entities/user.e.js.map +1 -1
- package/esm/lib/loader/userManager.d.ts +5 -0
- package/esm/lib/loader/userManager.js +60 -0
- package/esm/lib/loader/userManager.js.map +1 -0
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import * as userManager from './lib/loader/userManager';
|
|
3
|
+
import { User } from './lib/entities/user.e';
|
|
4
|
+
export { Database } from './types/global';
|
|
5
|
+
export { User, userManager };
|
package/dist/index.js
CHANGED
|
@@ -32,13 +32,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
35
|
+
exports.userManager = exports.User = void 0;
|
|
36
36
|
require("reflect-metadata");
|
|
37
37
|
const typeorm_1 = require("typeorm");
|
|
38
38
|
const loaderEntities = __importStar(require("./lib/loader/entities"));
|
|
39
|
+
const userManager = __importStar(require("./lib/loader/userManager"));
|
|
40
|
+
exports.userManager = userManager;
|
|
39
41
|
const user_e_1 = require("./lib/entities/user.e");
|
|
40
42
|
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_e_1.User; } });
|
|
41
|
-
Object.defineProperty(exports, "ExtraColumns", { enumerable: true, get: function () { return user_e_1.ExtraColumns; } });
|
|
42
43
|
function start(options) {
|
|
43
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
45
|
return new Promise((resolve, reject) => {
|
|
@@ -79,6 +80,7 @@ function start(options) {
|
|
|
79
80
|
.then((ds) => __awaiter(this, void 0, void 0, function* () {
|
|
80
81
|
const repository = {};
|
|
81
82
|
Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])));
|
|
83
|
+
global.connection = ds;
|
|
82
84
|
global.entity = classes;
|
|
83
85
|
global.repository = repository;
|
|
84
86
|
return resolve(ds);
|
|
@@ -87,5 +89,5 @@ function start(options) {
|
|
|
87
89
|
});
|
|
88
90
|
});
|
|
89
91
|
}
|
|
90
|
-
module.exports = { start, User: user_e_1.User,
|
|
92
|
+
module.exports = { start, User: user_e_1.User, userManager };
|
|
91
93
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;AACpC,sEAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;AACpC,sEAAuD;AACvD,sEAAuD;AAkExC,kCAAW;AAjE1B,kDAA4C;AAiEnC,qFAjEA,aAAI,OAiEA;AA/Db,SAAe,KAAK,CAAC,OAAO;;QAC1B,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;Y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CAAC,CAAC,CAAC,gBAAgB,CAAA;YACrE,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAA;YAQ1B,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,UAAU,GAAG,EAAE,CAAA;gBACtB,MAAM,CAAC,MAAM,GAAG,OAAO,CAAA;gBACvB,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;gBAC9B,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;YACpB,CAAC,CAAA,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA;AAID,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,IAAI,EAAJ,aAAI,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { BaseEntity } from 'typeorm';
|
|
2
|
+
export declare class User extends BaseEntity {
|
|
3
|
+
id: number;
|
|
4
|
+
username: string;
|
|
5
|
+
email: string;
|
|
6
|
+
password: string;
|
|
7
|
+
roles: string[];
|
|
2
8
|
version: number;
|
|
3
9
|
createdAt: Date;
|
|
4
10
|
updatedAt: Date;
|
|
5
11
|
deletedAt: Date;
|
|
6
12
|
}
|
|
7
|
-
export declare class User {
|
|
8
|
-
id: number;
|
|
9
|
-
extra: ExtraColumns;
|
|
10
|
-
name: string;
|
|
11
|
-
email: string;
|
|
12
|
-
password: string;
|
|
13
|
-
allRoles: string[];
|
|
14
|
-
}
|
|
@@ -9,42 +9,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.User =
|
|
12
|
+
exports.User = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
|
-
class
|
|
15
|
-
}
|
|
16
|
-
__decorate([
|
|
17
|
-
(0, typeorm_1.VersionColumn)(),
|
|
18
|
-
__metadata("design:type", Number)
|
|
19
|
-
], ExtraColumns.prototype, "version", void 0);
|
|
20
|
-
__decorate([
|
|
21
|
-
(0, typeorm_1.CreateDateColumn)(),
|
|
22
|
-
__metadata("design:type", Date)
|
|
23
|
-
], ExtraColumns.prototype, "createdAt", void 0);
|
|
24
|
-
__decorate([
|
|
25
|
-
(0, typeorm_1.UpdateDateColumn)(),
|
|
26
|
-
__metadata("design:type", Date)
|
|
27
|
-
], ExtraColumns.prototype, "updatedAt", void 0);
|
|
28
|
-
__decorate([
|
|
29
|
-
(0, typeorm_1.DeleteDateColumn)(),
|
|
30
|
-
__metadata("design:type", Date)
|
|
31
|
-
], ExtraColumns.prototype, "deletedAt", void 0);
|
|
32
|
-
exports.ExtraColumns = ExtraColumns;
|
|
33
|
-
let User = class User {
|
|
14
|
+
let User = class User extends typeorm_1.BaseEntity {
|
|
34
15
|
};
|
|
35
16
|
__decorate([
|
|
36
17
|
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
37
18
|
__metadata("design:type", Number)
|
|
38
19
|
], User.prototype, "id", void 0);
|
|
39
|
-
__decorate([
|
|
40
|
-
(0, typeorm_1.Column)(() => ExtraColumns),
|
|
41
|
-
__metadata("design:type", ExtraColumns)
|
|
42
|
-
], User.prototype, "extra", void 0);
|
|
43
20
|
__decorate([
|
|
44
21
|
(0, typeorm_1.Index)(),
|
|
45
22
|
(0, typeorm_1.Column)(),
|
|
46
23
|
__metadata("design:type", String)
|
|
47
|
-
], User.prototype, "
|
|
24
|
+
], User.prototype, "username", void 0);
|
|
48
25
|
__decorate([
|
|
49
26
|
(0, typeorm_1.Index)(),
|
|
50
27
|
(0, typeorm_1.Column)(),
|
|
@@ -57,9 +34,27 @@ __decorate([
|
|
|
57
34
|
__decorate([
|
|
58
35
|
(0, typeorm_1.Column)({ type: 'simple-array', nullable: true }),
|
|
59
36
|
__metadata("design:type", Array)
|
|
60
|
-
], User.prototype, "
|
|
37
|
+
], User.prototype, "roles", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, typeorm_1.VersionColumn)(),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], User.prototype, "version", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
44
|
+
__metadata("design:type", Date)
|
|
45
|
+
], User.prototype, "createdAt", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
48
|
+
__metadata("design:type", Date)
|
|
49
|
+
], User.prototype, "updatedAt", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, typeorm_1.DeleteDateColumn)(),
|
|
52
|
+
__metadata("design:type", Date)
|
|
53
|
+
], User.prototype, "deletedAt", void 0);
|
|
61
54
|
User = __decorate([
|
|
62
55
|
(0, typeorm_1.Entity)(),
|
|
56
|
+
(0, typeorm_1.Unique)(['username']),
|
|
57
|
+
(0, typeorm_1.Unique)(['email']),
|
|
63
58
|
(0, typeorm_1.TableInheritance)({ column: { type: 'varchar', name: 'type', default: 'user' } })
|
|
64
59
|
], User);
|
|
65
60
|
exports.User = User;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.e.js","sourceRoot":"","sources":["../../../lib/entities/user.e.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"user.e.js","sourceRoot":"","sources":["../../../lib/entities/user.e.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAYgB;AAMT,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,oBAAU;CA6BnC,CAAA;AA5BC;IAAC,IAAA,gCAAsB,EAAC,MAAM,CAAC;;gCACrB;AAEV;IAAC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;sCACO;AAEhB;IAAC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;mCACI;AAEb;IAAC,IAAA,gBAAM,GAAE;;sCACO;AAEhB;IAAC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mCAClC;AAEf;IAAC,IAAA,uBAAa,GAAE;;qCACD;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AA5BJ,IAAI;IAJhB,IAAA,gBAAM,GAAE;IACR,IAAA,gBAAM,EAAC,CAAC,UAAU,CAAC,CAAC;IACpB,IAAA,gBAAM,EAAC,CAAC,OAAO,CAAC,CAAC;IACjB,IAAA,0BAAgB,EAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;GACpE,IAAI,CA6BhB;AA7BY,oBAAI"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.login = exports.register = exports.demo = void 0;
|
|
36
|
+
const bcrypt = __importStar(require("bcrypt"));
|
|
37
|
+
const { User } = require('../entities/user.e');
|
|
38
|
+
function demo() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return [];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.demo = demo;
|
|
44
|
+
function register(data) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const { name, email, password } = data;
|
|
47
|
+
const salt = yield bcrypt.genSalt();
|
|
48
|
+
const hashedPassword = yield bcrypt.hash(password, salt);
|
|
49
|
+
try {
|
|
50
|
+
let user = Object.assign(Object.assign({}, data), { name: name || email, password: hashedPassword });
|
|
51
|
+
return yield User.save(user);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if ((error === null || error === void 0 ? void 0 : error.code) == 23505) {
|
|
55
|
+
throw Error('Email already registered');
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.register = register;
|
|
62
|
+
function login(data) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const { name, email, password } = data;
|
|
65
|
+
try {
|
|
66
|
+
const user = yield global.repository.users.findOneBy({ email: email });
|
|
67
|
+
return user;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.login = login;
|
|
75
|
+
//# sourceMappingURL=userManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userManager.js","sourceRoot":"","sources":["../../../lib/loader/userManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAE9C,SAAsB,IAAI;;QAGxB,OAAO,EAAE,CAAA;IACX,CAAC;CAAA;AAJD,oBAIC;AAED,SAAsB,QAAQ,CAAC,IAAiB;;QAC9C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;QACtC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACnC,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QAExD,IAAI;YACF,IAAI,IAAI,GAAG,gCAAK,IAAI,KAAE,IAAI,EAAE,IAAI,IAAI,KAAK,EAAE,QAAQ,EAAE,cAAc,GAAiB,CAAA;YACpF,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SAC7B;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,KAAK,EAAE;gBACxB,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAA;aACxC;YACD,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CAAA;AAdD,4BAcC;AAED,SAAsB,KAAK,CAAC,IAAiB;;QAC3C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;QAEtC,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YACtE,OAAO,IAAI,CAAA;SACZ;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CAAA;AATD,sBASC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import * as userManager from './lib/loader/userManager';
|
|
3
|
+
import { User } from './lib/entities/user.e';
|
|
4
|
+
export { Database } from './types/global';
|
|
5
|
+
export { User, userManager };
|
package/esm/index.js
CHANGED
|
@@ -23,13 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.userManager = exports.User = void 0;
|
|
27
27
|
require("reflect-metadata");
|
|
28
28
|
const typeorm_1 = require("typeorm");
|
|
29
29
|
const loaderEntities = __importStar(require("./lib/loader/entities"));
|
|
30
|
+
const userManager = __importStar(require("./lib/loader/userManager"));
|
|
31
|
+
exports.userManager = userManager;
|
|
30
32
|
const user_e_1 = require("./lib/entities/user.e");
|
|
31
33
|
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_e_1.User; } });
|
|
32
|
-
Object.defineProperty(exports, "ExtraColumns", { enumerable: true, get: function () { return user_e_1.ExtraColumns; } });
|
|
33
34
|
async function start(options) {
|
|
34
35
|
return new Promise((resolve, reject) => {
|
|
35
36
|
if (global.npmDebugServerStarted) {
|
|
@@ -69,6 +70,7 @@ async function start(options) {
|
|
|
69
70
|
.then(async (ds) => {
|
|
70
71
|
const repository = {};
|
|
71
72
|
Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])));
|
|
73
|
+
global.connection = ds;
|
|
72
74
|
global.entity = classes;
|
|
73
75
|
global.repository = repository;
|
|
74
76
|
return resolve(ds);
|
|
@@ -76,5 +78,5 @@ async function start(options) {
|
|
|
76
78
|
.catch((error) => reject(error));
|
|
77
79
|
});
|
|
78
80
|
}
|
|
79
|
-
module.exports = { start, User: user_e_1.User,
|
|
81
|
+
module.exports = { start, User: user_e_1.User, userManager };
|
|
80
82
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;AACpC,sEAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings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5
|
+
email: string;
|
|
6
|
+
password: string;
|
|
7
|
+
roles: string[];
|
|
2
8
|
version: number;
|
|
3
9
|
createdAt: Date;
|
|
4
10
|
updatedAt: Date;
|
|
5
11
|
deletedAt: Date;
|
|
6
12
|
}
|
|
7
|
-
export declare class User {
|
|
8
|
-
id: number;
|
|
9
|
-
extra: ExtraColumns;
|
|
10
|
-
name: string;
|
|
11
|
-
email: string;
|
|
12
|
-
password: string;
|
|
13
|
-
allRoles: string[];
|
|
14
|
-
}
|
|
@@ -9,42 +9,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.User =
|
|
12
|
+
exports.User = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
|
-
class
|
|
15
|
-
}
|
|
16
|
-
__decorate([
|
|
17
|
-
(0, typeorm_1.VersionColumn)(),
|
|
18
|
-
__metadata("design:type", Number)
|
|
19
|
-
], ExtraColumns.prototype, "version", void 0);
|
|
20
|
-
__decorate([
|
|
21
|
-
(0, typeorm_1.CreateDateColumn)(),
|
|
22
|
-
__metadata("design:type", Date)
|
|
23
|
-
], ExtraColumns.prototype, "createdAt", void 0);
|
|
24
|
-
__decorate([
|
|
25
|
-
(0, typeorm_1.UpdateDateColumn)(),
|
|
26
|
-
__metadata("design:type", Date)
|
|
27
|
-
], ExtraColumns.prototype, "updatedAt", void 0);
|
|
28
|
-
__decorate([
|
|
29
|
-
(0, typeorm_1.DeleteDateColumn)(),
|
|
30
|
-
__metadata("design:type", Date)
|
|
31
|
-
], ExtraColumns.prototype, "deletedAt", void 0);
|
|
32
|
-
exports.ExtraColumns = ExtraColumns;
|
|
33
|
-
let User = class User {
|
|
14
|
+
let User = class User extends typeorm_1.BaseEntity {
|
|
34
15
|
};
|
|
35
16
|
__decorate([
|
|
36
17
|
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
37
18
|
__metadata("design:type", Number)
|
|
38
19
|
], User.prototype, "id", void 0);
|
|
39
|
-
__decorate([
|
|
40
|
-
(0, typeorm_1.Column)(() => ExtraColumns),
|
|
41
|
-
__metadata("design:type", ExtraColumns)
|
|
42
|
-
], User.prototype, "extra", void 0);
|
|
43
20
|
__decorate([
|
|
44
21
|
(0, typeorm_1.Index)(),
|
|
45
22
|
(0, typeorm_1.Column)(),
|
|
46
23
|
__metadata("design:type", String)
|
|
47
|
-
], User.prototype, "
|
|
24
|
+
], User.prototype, "username", void 0);
|
|
48
25
|
__decorate([
|
|
49
26
|
(0, typeorm_1.Index)(),
|
|
50
27
|
(0, typeorm_1.Column)(),
|
|
@@ -57,9 +34,27 @@ __decorate([
|
|
|
57
34
|
__decorate([
|
|
58
35
|
(0, typeorm_1.Column)({ type: 'simple-array', nullable: true }),
|
|
59
36
|
__metadata("design:type", Array)
|
|
60
|
-
], User.prototype, "
|
|
37
|
+
], User.prototype, "roles", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, typeorm_1.VersionColumn)(),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], User.prototype, "version", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
44
|
+
__metadata("design:type", Date)
|
|
45
|
+
], User.prototype, "createdAt", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
48
|
+
__metadata("design:type", Date)
|
|
49
|
+
], User.prototype, "updatedAt", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, typeorm_1.DeleteDateColumn)(),
|
|
52
|
+
__metadata("design:type", Date)
|
|
53
|
+
], User.prototype, "deletedAt", void 0);
|
|
61
54
|
User = __decorate([
|
|
62
55
|
(0, typeorm_1.Entity)(),
|
|
56
|
+
(0, typeorm_1.Unique)(['username']),
|
|
57
|
+
(0, typeorm_1.Unique)(['email']),
|
|
63
58
|
(0, typeorm_1.TableInheritance)({ column: { type: 'varchar', name: 'type', default: 'user' } })
|
|
64
59
|
], User);
|
|
65
60
|
exports.User = User;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.e.js","sourceRoot":"","sources":["../../../lib/entities/user.e.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"user.e.js","sourceRoot":"","sources":["../../../lib/entities/user.e.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAYgB;AAMT,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,oBAAU;CA6BnC,CAAA;AA5BC;IAAC,IAAA,gCAAsB,EAAC,MAAM,CAAC;;gCACrB;AAEV;IAAC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;sCACO;AAEhB;IAAC,IAAA,eAAK,GAAE;IACP,IAAA,gBAAM,GAAE;;mCACI;AAEb;IAAC,IAAA,gBAAM,GAAE;;sCACO;AAEhB;IAAC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mCAClC;AAEf;IAAC,IAAA,uBAAa,GAAE;;qCACD;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AAEf;IAAC,IAAA,0BAAgB,GAAE;8BACR,IAAI;uCAAA;AA5BJ,IAAI;IAJhB,IAAA,gBAAM,GAAE;IACR,IAAA,gBAAM,EAAC,CAAC,UAAU,CAAC,CAAC;IACpB,IAAA,gBAAM,EAAC,CAAC,OAAO,CAAC,CAAC;IACjB,IAAA,0BAAgB,EAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;GACpE,IAAI,CA6BhB;AA7BY,oBAAI"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.login = exports.register = exports.demo = void 0;
|
|
27
|
+
const bcrypt = __importStar(require("bcrypt"));
|
|
28
|
+
const { User } = require('../entities/user.e');
|
|
29
|
+
async function demo() {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
exports.demo = demo;
|
|
33
|
+
async function register(data) {
|
|
34
|
+
const { name, email, password } = data;
|
|
35
|
+
const salt = await bcrypt.genSalt();
|
|
36
|
+
const hashedPassword = await bcrypt.hash(password, salt);
|
|
37
|
+
try {
|
|
38
|
+
let user = { ...data, name: name || email, password: hashedPassword };
|
|
39
|
+
return await User.save(user);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if ((error === null || error === void 0 ? void 0 : error.code) == 23505) {
|
|
43
|
+
throw Error('Email already registered');
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.register = register;
|
|
49
|
+
async function login(data) {
|
|
50
|
+
const { name, email, password } = data;
|
|
51
|
+
try {
|
|
52
|
+
const user = await global.repository.users.findOneBy({ email: email });
|
|
53
|
+
return user;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.login = login;
|
|
60
|
+
//# sourceMappingURL=userManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userManager.js","sourceRoot":"","sources":["../../../lib/loader/userManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAEvC,KAAK,UAAU,IAAI;IAGxB,OAAO,EAAE,CAAA;AACX,CAAC;AAJD,oBAIC;AAEM,KAAK,UAAU,QAAQ,CAAC,IAAiB;IAC9C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IACtC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;IACnC,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAExD,IAAI;QACF,IAAI,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAiB,CAAA;QACpF,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KAC7B;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,KAAK,EAAE;YACxB,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAA;SACxC;QACD,MAAM,KAAK,CAAA;KACZ;AACH,CAAC;AAdD,4BAcC;AAEM,KAAK,UAAU,KAAK,CAAC,IAAiB;IAC3C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IAEtC,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;QACtE,OAAO,IAAI,CAAA;KACZ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,KAAK,CAAA;KACZ;AACH,CAAC;AATD,sBASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volcanicminds/typeorm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "TypeORM for the volcanic (minds) backend",
|
|
6
6
|
"keywords": [
|
|
@@ -28,9 +28,11 @@
|
|
|
28
28
|
"test": "jest test --config ./jest.config.js",
|
|
29
29
|
"build:esm": "tsc --target es2018 --outDir esm",
|
|
30
30
|
"build:cjs": "tsc --target es2015 --module commonjs --outDir dist",
|
|
31
|
-
"build": "npm run build:esm && npm run build:cjs"
|
|
31
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
32
|
+
"compile": "npm run build"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
35
|
+
"bcrypt": "^5.1.0",
|
|
34
36
|
"pluralize": "^8.0.0",
|
|
35
37
|
"reflect-metadata": "^0.1.13",
|
|
36
38
|
"typeorm": "^0.3.10"
|