@vynelix/nestjs-multi-auth 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/README.md +760 -0
- package/bin/cli.js +152 -0
- package/dist/auth/auth-type.enum.d.ts +22 -0
- package/dist/auth/auth-type.enum.js +32 -0
- package/dist/auth/auth-type.enum.js.map +1 -0
- package/dist/auth/auth.controller.d.ts +70 -0
- package/dist/auth/auth.controller.js +434 -0
- package/dist/auth/auth.controller.js.map +1 -0
- package/dist/auth/auth.module.d.ts +9 -0
- package/dist/auth/auth.module.js +193 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/auth.service.d.ts +180 -0
- package/dist/auth/auth.service.js +695 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/auth/core/auth-mapper.d.ts +6 -0
- package/dist/auth/core/auth-mapper.js +17 -0
- package/dist/auth/core/auth-mapper.js.map +1 -0
- package/dist/auth/core/jwt.strategy.d.ts +13 -0
- package/dist/auth/core/jwt.strategy.js +59 -0
- package/dist/auth/core/jwt.strategy.js.map +1 -0
- package/dist/auth/core/registration.d.ts +3 -0
- package/dist/auth/core/registration.js +60 -0
- package/dist/auth/core/registration.js.map +1 -0
- package/dist/auth/current-user-interface.d.ts +4 -0
- package/dist/auth/current-user-interface.js +4 -0
- package/dist/auth/current-user-interface.js.map +1 -0
- package/dist/auth/current-user.decorator.d.ts +2 -0
- package/dist/auth/current-user.decorator.js +16 -0
- package/dist/auth/current-user.decorator.js.map +1 -0
- package/dist/auth/decorator/current-user.decorator.d.ts +2 -0
- package/dist/auth/decorator/current-user.decorator.js +13 -0
- package/dist/auth/decorator/current-user.decorator.js.map +1 -0
- package/dist/auth/decorator/email-or-phone.decorator.d.ts +2 -0
- package/dist/auth/decorator/email-or-phone.decorator.js +26 -0
- package/dist/auth/decorator/email-or-phone.decorator.js.map +1 -0
- package/dist/auth/decorator/optional.decorator.d.ts +2 -0
- package/dist/auth/decorator/optional.decorator.js +9 -0
- package/dist/auth/decorator/optional.decorator.js.map +1 -0
- package/dist/auth/decorator/public.decorator.d.ts +2 -0
- package/dist/auth/decorator/public.decorator.js +9 -0
- package/dist/auth/decorator/public.decorator.js.map +1 -0
- package/dist/auth/dto/auth-response.dto.d.ts +17 -0
- package/dist/auth/dto/auth-response.dto.js +83 -0
- package/dist/auth/dto/auth-response.dto.js.map +1 -0
- package/dist/auth/dto/identifier-response.dto.d.ts +8 -0
- package/dist/auth/dto/identifier-response.dto.js +46 -0
- package/dist/auth/dto/identifier-response.dto.js.map +1 -0
- package/dist/auth/dto/login.dto.d.ts +11 -0
- package/dist/auth/dto/login.dto.js +68 -0
- package/dist/auth/dto/login.dto.js.map +1 -0
- package/dist/auth/dto/mfa.dto.d.ts +8 -0
- package/dist/auth/dto/mfa.dto.js +51 -0
- package/dist/auth/dto/mfa.dto.js.map +1 -0
- package/dist/auth/dto/oauth-provider-response.dto.d.ts +5 -0
- package/dist/auth/dto/oauth-provider-response.dto.js +30 -0
- package/dist/auth/dto/oauth-provider-response.dto.js.map +1 -0
- package/dist/auth/dto/refresh-token.dto.d.ts +3 -0
- package/dist/auth/dto/refresh-token.dto.js +28 -0
- package/dist/auth/dto/refresh-token.dto.js.map +1 -0
- package/dist/auth/dto/requests/forgot-password.dto.d.ts +5 -0
- package/dist/auth/dto/requests/forgot-password.dto.js +36 -0
- package/dist/auth/dto/requests/forgot-password.dto.js.map +1 -0
- package/dist/auth/dto/requests/login.dto.d.ts +11 -0
- package/dist/auth/dto/requests/login.dto.js +68 -0
- package/dist/auth/dto/requests/login.dto.js.map +1 -0
- package/dist/auth/dto/requests/magic-link.dto.d.ts +6 -0
- package/dist/auth/dto/requests/magic-link.dto.js +33 -0
- package/dist/auth/dto/requests/magic-link.dto.js.map +1 -0
- package/dist/auth/dto/requests/mfa.dto.d.ts +8 -0
- package/dist/auth/dto/requests/mfa.dto.js +51 -0
- package/dist/auth/dto/requests/mfa.dto.js.map +1 -0
- package/dist/auth/dto/requests/refresh-token.dto.d.ts +3 -0
- package/dist/auth/dto/requests/refresh-token.dto.js +29 -0
- package/dist/auth/dto/requests/refresh-token.dto.js.map +1 -0
- package/dist/auth/dto/requests/reset-password.dto.d.ts +5 -0
- package/dist/auth/dto/requests/reset-password.dto.js +36 -0
- package/dist/auth/dto/requests/reset-password.dto.js.map +1 -0
- package/dist/auth/dto/requests/secure-account.dto.d.ts +3 -0
- package/dist/auth/dto/requests/secure-account.dto.js +24 -0
- package/dist/auth/dto/requests/secure-account.dto.js.map +1 -0
- package/dist/auth/dto/requests/signup.dto.d.ts +13 -0
- package/dist/auth/dto/requests/signup.dto.js +70 -0
- package/dist/auth/dto/requests/signup.dto.js.map +1 -0
- package/dist/auth/dto/requests/update-password.dto.d.ts +4 -0
- package/dist/auth/dto/requests/update-password.dto.js +30 -0
- package/dist/auth/dto/requests/update-password.dto.js.map +1 -0
- package/dist/auth/dto/requests/verify.dto.d.ts +7 -0
- package/dist/auth/dto/requests/verify.dto.js +48 -0
- package/dist/auth/dto/requests/verify.dto.js.map +1 -0
- package/dist/auth/dto/responses/auth-response.dto.d.ts +17 -0
- package/dist/auth/dto/responses/auth-response.dto.js +83 -0
- package/dist/auth/dto/responses/auth-response.dto.js.map +1 -0
- package/dist/auth/dto/responses/identifier-response.dto.d.ts +10 -0
- package/dist/auth/dto/responses/identifier-response.dto.js +56 -0
- package/dist/auth/dto/responses/identifier-response.dto.js.map +1 -0
- package/dist/auth/dto/responses/oauth-provider-response.dto.d.ts +10 -0
- package/dist/auth/dto/responses/oauth-provider-response.dto.js +55 -0
- package/dist/auth/dto/responses/oauth-provider-response.dto.js.map +1 -0
- package/dist/auth/dto/signup.dto.d.ts +13 -0
- package/dist/auth/dto/signup.dto.js +70 -0
- package/dist/auth/dto/signup.dto.js.map +1 -0
- package/dist/auth/dto/verify.dto.d.ts +7 -0
- package/dist/auth/dto/verify.dto.js +48 -0
- package/dist/auth/dto/verify.dto.js.map +1 -0
- package/dist/auth/entities/auth-identify.entity.d.ts +33 -0
- package/dist/auth/entities/auth-identify.entity.js +73 -0
- package/dist/auth/entities/auth-identify.entity.js.map +1 -0
- package/dist/auth/entities/auth.entity.d.ts +45 -0
- package/dist/auth/entities/auth.entity.js +129 -0
- package/dist/auth/entities/auth.entity.js.map +1 -0
- package/dist/auth/entities/base.entity.d.ts +6 -0
- package/dist/auth/entities/base.entity.js +41 -0
- package/dist/auth/entities/base.entity.js.map +1 -0
- package/dist/auth/entities/mfa-method.entity.d.ts +23 -0
- package/dist/auth/entities/mfa-method.entity.js +69 -0
- package/dist/auth/entities/mfa-method.entity.js.map +1 -0
- package/dist/auth/entities/oauth-provider.entity.d.ts +38 -0
- package/dist/auth/entities/oauth-provider.entity.js +88 -0
- package/dist/auth/entities/oauth-provider.entity.js.map +1 -0
- package/dist/auth/entities/otp-token.entity.d.ts +22 -0
- package/dist/auth/entities/otp-token.entity.js +61 -0
- package/dist/auth/entities/otp-token.entity.js.map +1 -0
- package/dist/auth/entities/session.entity.d.ts +19 -0
- package/dist/auth/entities/session.entity.js +65 -0
- package/dist/auth/entities/session.entity.js.map +1 -0
- package/dist/auth/enums/auth-type.enum.d.ts +23 -0
- package/dist/auth/enums/auth-type.enum.js +34 -0
- package/dist/auth/enums/auth-type.enum.js.map +1 -0
- package/dist/auth/guards/jwt-auth.guard.d.ts +10 -0
- package/dist/auth/guards/jwt-auth.guard.js +68 -0
- package/dist/auth/guards/jwt-auth.guard.js.map +1 -0
- package/dist/auth/guards/optional-auth.guard.d.ts +8 -0
- package/dist/auth/guards/optional-auth.guard.js +45 -0
- package/dist/auth/guards/optional-auth.guard.js.map +1 -0
- package/dist/auth/guards/ws-jwt-auth.guard.d.ts +0 -0
- package/dist/auth/guards/ws-jwt-auth.guard.js +31 -0
- package/dist/auth/guards/ws-jwt-auth.guard.js.map +1 -0
- package/dist/auth/interfaces/auth-module-async-options.interface.d.ts +7 -0
- package/dist/auth/interfaces/auth-module-async-options.interface.js +3 -0
- package/dist/auth/interfaces/auth-module-async-options.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-module-options.interface.d.ts +132 -0
- package/dist/auth/interfaces/auth-module-options.interface.js +5 -0
- package/dist/auth/interfaces/auth-module-options.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-notification-provider.interface.d.ts +29 -0
- package/dist/auth/interfaces/auth-notification-provider.interface.js +5 -0
- package/dist/auth/interfaces/auth-notification-provider.interface.js.map +1 -0
- package/dist/auth/interfaces/auth-user-service.interface.d.ts +13 -0
- package/dist/auth/interfaces/auth-user-service.interface.js +7 -0
- package/dist/auth/interfaces/auth-user-service.interface.js.map +1 -0
- package/dist/auth/interfaces/current-user-interface.d.ts +4 -0
- package/dist/auth/interfaces/current-user-interface.js +4 -0
- package/dist/auth/interfaces/current-user-interface.js.map +1 -0
- package/dist/auth/interfaces/current-user.decorator.d.ts +2 -0
- package/dist/auth/interfaces/current-user.decorator.js +16 -0
- package/dist/auth/interfaces/current-user.decorator.js.map +1 -0
- package/dist/auth/interfaces/jwt-payload-interface.d.ts +4 -0
- package/dist/auth/interfaces/jwt-payload-interface.js +3 -0
- package/dist/auth/interfaces/jwt-payload-interface.js.map +1 -0
- package/dist/auth/interfaces/oauth-strategy.interface.d.ts +14 -0
- package/dist/auth/interfaces/oauth-strategy.interface.js +3 -0
- package/dist/auth/interfaces/oauth-strategy.interface.js.map +1 -0
- package/dist/auth/jwt-payload-interface.d.ts +4 -0
- package/dist/auth/jwt-payload-interface.js +3 -0
- package/dist/auth/jwt-payload-interface.js.map +1 -0
- package/dist/auth/jwt.strategy.d.ts +13 -0
- package/dist/auth/jwt.strategy.js +60 -0
- package/dist/auth/jwt.strategy.js.map +1 -0
- package/dist/auth/strategies/company.strategy.d.ts +0 -0
- package/dist/auth/strategies/company.strategy.js +1 -0
- package/dist/auth/strategies/company.strategy.js.map +1 -0
- package/dist/auth/strategies/google.strategy.d.ts +7 -0
- package/dist/auth/strategies/google.strategy.js +23 -0
- package/dist/auth/strategies/google.strategy.js.map +1 -0
- package/dist/auth/strategies/local-auth.strategy.d.ts +24 -0
- package/dist/auth/strategies/local-auth.strategy.js +244 -0
- package/dist/auth/strategies/local-auth.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/apple.strategy.d.ts +27 -0
- package/dist/auth/strategies/oauth/apple.strategy.js +176 -0
- package/dist/auth/strategies/oauth/apple.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/facebook.strategy.d.ts +24 -0
- package/dist/auth/strategies/oauth/facebook.strategy.js +150 -0
- package/dist/auth/strategies/oauth/facebook.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/google.strategy.d.ts +25 -0
- package/dist/auth/strategies/oauth/google.strategy.js +225 -0
- package/dist/auth/strategies/oauth/google.strategy.js.map +1 -0
- package/dist/auth/strategies/oauth/oauth-strategy.interface.d.ts +14 -0
- package/dist/auth/strategies/oauth/oauth-strategy.interface.js +3 -0
- package/dist/auth/strategies/oauth/oauth-strategy.interface.js.map +1 -0
- package/dist/auth/strategies/oauth/oauth.strategy.d.ts +25 -0
- package/dist/auth/strategies/oauth/oauth.strategy.js +70 -0
- package/dist/auth/strategies/oauth/oauth.strategy.js.map +1 -0
- package/dist/auth/strategies/otp.strategy.d.ts +7 -0
- package/dist/auth/strategies/otp.strategy.js +23 -0
- package/dist/auth/strategies/otp.strategy.js.map +1 -0
- package/dist/auth/strategies/password.strategy.d.ts +14 -0
- package/dist/auth/strategies/password.strategy.js +130 -0
- package/dist/auth/strategies/password.strategy.js.map +1 -0
- package/dist/auth/utils/duration.util.d.ts +8 -0
- package/dist/auth/utils/duration.util.js +29 -0
- package/dist/auth/utils/duration.util.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/auth-entities.d.ts +7 -0
- package/dist/migrations/auth-entities.js +18 -0
- package/dist/migrations/auth-entities.js.map +1 -0
- package/dist/migrations/auth-schema.initializer.d.ts +9 -0
- package/dist/migrations/auth-schema.initializer.js +36 -0
- package/dist/migrations/auth-schema.initializer.js.map +1 -0
- package/dist/migrations/auth.migration.v1.d.ts +12 -0
- package/dist/migrations/auth.migration.v1.js +157 -0
- package/dist/migrations/auth.migration.v1.js.map +1 -0
- package/dist/migrations/auth.migration.v2.d.ts +8 -0
- package/dist/migrations/auth.migration.v2.js +39 -0
- package/dist/migrations/auth.migration.v2.js.map +1 -0
- package/dist/migrations/auth.migrations.d.ts +2 -0
- package/dist/migrations/auth.migrations.js +8 -0
- package/dist/migrations/auth.migrations.js.map +1 -0
- package/dist/migrations/migration.runner.d.ts +9 -0
- package/dist/migrations/migration.runner.js +67 -0
- package/dist/migrations/migration.runner.js.map +1 -0
- package/dist/migrations/migration.service.d.ts +9 -0
- package/dist/migrations/migration.service.js +71 -0
- package/dist/migrations/migration.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,67 @@
|
|
|
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.AuthMigrationService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const auth_migrations_1 = require("./auth.migrations");
|
|
16
|
+
let AuthMigrationService = class AuthMigrationService {
|
|
17
|
+
constructor(dataSource) {
|
|
18
|
+
this.dataSource = dataSource;
|
|
19
|
+
}
|
|
20
|
+
async runMigrations() {
|
|
21
|
+
const queryRunner = this.dataSource.createQueryRunner();
|
|
22
|
+
await queryRunner.connect();
|
|
23
|
+
await this.ensureMetaTable(queryRunner);
|
|
24
|
+
const currentVersion = await this.getCurrentVersion(queryRunner);
|
|
25
|
+
const pendingMigrations = auth_migrations_1.AuthMigrations.filter((m) => m.prototype.version > currentVersion);
|
|
26
|
+
for (const MigrationClass of pendingMigrations) {
|
|
27
|
+
const migration = new MigrationClass();
|
|
28
|
+
await queryRunner.startTransaction();
|
|
29
|
+
try {
|
|
30
|
+
await migration.up(queryRunner);
|
|
31
|
+
await this.updateVersion(queryRunner, migration.version);
|
|
32
|
+
await queryRunner.commitTransaction();
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
await queryRunner.rollbackTransaction();
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
await queryRunner.release();
|
|
40
|
+
}
|
|
41
|
+
async ensureMetaTable(qr) {
|
|
42
|
+
await qr.query(`
|
|
43
|
+
CREATE TABLE IF NOT EXISTS auth_schema_meta (
|
|
44
|
+
id SERIAL PRIMARY KEY,
|
|
45
|
+
version INT NOT NULL,
|
|
46
|
+
updated_at TIMESTAMP DEFAULT now()
|
|
47
|
+
)
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
async getCurrentVersion(qr) {
|
|
51
|
+
const result = await qr.query(`
|
|
52
|
+
SELECT version FROM auth_schema_meta ORDER BY version DESC LIMIT 1
|
|
53
|
+
`);
|
|
54
|
+
return result.length > 0 ? result[0].version : 0;
|
|
55
|
+
}
|
|
56
|
+
async updateVersion(qr, version) {
|
|
57
|
+
await qr.query(`
|
|
58
|
+
INSERT INTO auth_schema_meta (version) VALUES ($1)
|
|
59
|
+
`, [version]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.AuthMigrationService = AuthMigrationService;
|
|
63
|
+
exports.AuthMigrationService = AuthMigrationService = __decorate([
|
|
64
|
+
(0, common_1.Injectable)(),
|
|
65
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
66
|
+
], AuthMigrationService);
|
|
67
|
+
//# sourceMappingURL=migration.runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.runner.js","sourceRoot":"","sources":["../../src/migrations/migration.runner.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAAkD;AAClD,uDAAmD;AAG5C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC7B,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAI,CAAC;IAE/C,KAAK,CAAC,aAAa;QACf,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;QAExD,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAE5B,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAExC,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAEjE,MAAM,iBAAiB,GAAG,gCAAc,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,GAAG,cAAc,CAC9C,CAAC;QAEF,KAAK,MAAM,cAAc,IAAI,iBAAiB,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;YAEvC,MAAM,WAAW,CAAC,gBAAgB,EAAE,CAAC;YAErC,IAAI,CAAC;gBACD,MAAM,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;gBAEhC,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;gBAEzD,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;YAC1C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC;gBACxC,MAAM,GAAG,CAAC;YACd,CAAC;QACL,CAAC;QAED,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,EAAe;QACjC,MAAM,EAAE,CAAC,KAAK,CAAC;;;;;;SAMd,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,EAAe;QACnC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC;;SAE7B,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,OAAe;QAChD,MAAM,EAAE,CAAC,KAAK,CAAC;;SAEd,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAClB,CAAC;CACJ,CAAA;AA3DY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAEuB,oBAAU;GADjC,oBAAoB,CA2DhC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataSource, QueryRunner } from "typeorm";
|
|
2
|
+
export declare class AuthMigrationService {
|
|
3
|
+
private dataSource;
|
|
4
|
+
constructor(dataSource: DataSource);
|
|
5
|
+
runMigrations(): Promise<void>;
|
|
6
|
+
ensureMetaTable(qr?: QueryRunner): Promise<void>;
|
|
7
|
+
getCurrentVersion(qr?: QueryRunner): Promise<number>;
|
|
8
|
+
updateVersion(qr?: QueryRunner, version?: number): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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.AuthMigrationService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const auth_migrations_1 = require("./auth.migrations");
|
|
16
|
+
let AuthMigrationService = class AuthMigrationService {
|
|
17
|
+
constructor(dataSource) {
|
|
18
|
+
this.dataSource = dataSource;
|
|
19
|
+
}
|
|
20
|
+
async runMigrations() {
|
|
21
|
+
const queryRunner = this.dataSource.createQueryRunner();
|
|
22
|
+
await queryRunner.connect();
|
|
23
|
+
await this.ensureMetaTable(queryRunner);
|
|
24
|
+
const currentVersion = await this.getCurrentVersion(queryRunner);
|
|
25
|
+
const pendingMigrations = auth_migrations_1.AuthMigrations.filter((M) => M.version > currentVersion);
|
|
26
|
+
for (const MigrationClass of pendingMigrations) {
|
|
27
|
+
const migration = new MigrationClass();
|
|
28
|
+
await queryRunner.startTransaction();
|
|
29
|
+
try {
|
|
30
|
+
await migration.up(queryRunner);
|
|
31
|
+
await this.updateVersion(queryRunner, migration.version);
|
|
32
|
+
await queryRunner.commitTransaction();
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
await queryRunner.rollbackTransaction();
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
await queryRunner.release();
|
|
40
|
+
}
|
|
41
|
+
async ensureMetaTable(qr) {
|
|
42
|
+
const executor = qr || this.dataSource;
|
|
43
|
+
await executor.query(`
|
|
44
|
+
CREATE TABLE IF NOT EXISTS auth_schema_meta (
|
|
45
|
+
id SERIAL PRIMARY KEY,
|
|
46
|
+
version INT NOT NULL,
|
|
47
|
+
updated_at TIMESTAMP DEFAULT now()
|
|
48
|
+
)
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
async getCurrentVersion(qr) {
|
|
52
|
+
await this.ensureMetaTable(qr);
|
|
53
|
+
const executor = qr || this.dataSource;
|
|
54
|
+
const result = await executor.query(`
|
|
55
|
+
SELECT version FROM auth_schema_meta ORDER BY version DESC LIMIT 1
|
|
56
|
+
`);
|
|
57
|
+
return result.length > 0 ? result[0].version : 0;
|
|
58
|
+
}
|
|
59
|
+
async updateVersion(qr, version) {
|
|
60
|
+
const executor = qr || this.dataSource;
|
|
61
|
+
await executor.query(`
|
|
62
|
+
INSERT INTO auth_schema_meta (version) VALUES ($1)
|
|
63
|
+
`, [version]);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.AuthMigrationService = AuthMigrationService;
|
|
67
|
+
exports.AuthMigrationService = AuthMigrationService = __decorate([
|
|
68
|
+
(0, common_1.Injectable)(),
|
|
69
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
70
|
+
], AuthMigrationService);
|
|
71
|
+
//# sourceMappingURL=migration.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.service.js","sourceRoot":"","sources":["../../src/migrations/migration.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAAkD;AAClD,uDAAmD;AAG5C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC7B,YA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