@lenne.tech/nest-server 11.2.0 → 11.4.0

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.
Files changed (73) hide show
  1. package/bin/migrate.js +40 -0
  2. package/dist/core/common/decorators/unified-field.decorator.d.ts +2 -0
  3. package/dist/core/common/decorators/unified-field.decorator.js +26 -9
  4. package/dist/core/common/decorators/unified-field.decorator.js.map +1 -1
  5. package/dist/core/common/models/core-persistence.model.js +2 -2
  6. package/dist/core/common/models/core-persistence.model.js.map +1 -1
  7. package/dist/core/modules/file/core-file-info.model.js +41 -23
  8. package/dist/core/modules/file/core-file-info.model.js.map +1 -1
  9. package/dist/core/modules/migrate/cli/migrate-cli.d.ts +3 -0
  10. package/dist/core/modules/migrate/cli/migrate-cli.js +221 -0
  11. package/dist/core/modules/migrate/cli/migrate-cli.js.map +1 -0
  12. package/dist/core/modules/migrate/helpers/migration.helper.d.ts +12 -0
  13. package/dist/core/modules/migrate/helpers/migration.helper.js +57 -0
  14. package/dist/core/modules/migrate/helpers/migration.helper.js.map +1 -0
  15. package/dist/core/modules/migrate/helpers/ts-compiler.d.ts +2 -0
  16. package/dist/core/modules/migrate/helpers/ts-compiler.js +3 -0
  17. package/dist/core/modules/migrate/helpers/ts-compiler.js.map +1 -0
  18. package/dist/core/modules/migrate/index.d.ts +4 -0
  19. package/dist/core/modules/migrate/index.js +21 -0
  20. package/dist/core/modules/migrate/index.js.map +1 -0
  21. package/dist/core/modules/migrate/migration-runner.d.ts +26 -0
  22. package/dist/core/modules/migrate/migration-runner.js +124 -0
  23. package/dist/core/modules/migrate/migration-runner.js.map +1 -0
  24. package/dist/core/modules/migrate/mongo-state-store.d.ts +30 -0
  25. package/dist/core/modules/migrate/mongo-state-store.js +105 -0
  26. package/dist/core/modules/migrate/mongo-state-store.js.map +1 -0
  27. package/dist/core/modules/migrate/templates/migration-with-helper.template.d.ts +2 -0
  28. package/dist/core/modules/migrate/templates/migration-with-helper.template.js +10 -0
  29. package/dist/core/modules/migrate/templates/migration-with-helper.template.js.map +1 -0
  30. package/dist/core/modules/migrate/templates/migration.template.d.ts +2 -0
  31. package/dist/core/modules/migrate/templates/migration.template.js +15 -0
  32. package/dist/core/modules/migrate/templates/migration.template.js.map +1 -0
  33. package/dist/core/modules/user/core-user.model.js +95 -54
  34. package/dist/core/modules/user/core-user.model.js.map +1 -1
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +1 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/main.js +22 -0
  39. package/dist/main.js.map +1 -1
  40. package/dist/server/common/models/persistence.model.js +13 -11
  41. package/dist/server/common/models/persistence.model.js.map +1 -1
  42. package/dist/server/modules/auth/auth.model.js +6 -2
  43. package/dist/server/modules/auth/auth.model.js.map +1 -1
  44. package/dist/server/modules/user/user.controller.d.ts +19 -0
  45. package/dist/server/modules/user/user.controller.js +256 -0
  46. package/dist/server/modules/user/user.controller.js.map +1 -0
  47. package/dist/server/modules/user/user.model.js +37 -24
  48. package/dist/server/modules/user/user.model.js.map +1 -1
  49. package/dist/server/modules/user/user.module.js +2 -1
  50. package/dist/server/modules/user/user.module.js.map +1 -1
  51. package/dist/tsconfig.build.tsbuildinfo +1 -1
  52. package/package.json +33 -29
  53. package/src/core/common/decorators/unified-field.decorator.ts +49 -10
  54. package/src/core/common/models/core-persistence.model.ts +3 -3
  55. package/src/core/modules/file/core-file-info.model.ts +40 -22
  56. package/src/core/modules/migrate/MIGRATION_FROM_NODEPIT.md +219 -0
  57. package/src/core/modules/migrate/README.md +452 -0
  58. package/src/core/modules/migrate/cli/migrate-cli.ts +319 -0
  59. package/src/core/modules/migrate/helpers/migration.helper.ts +117 -0
  60. package/src/core/modules/migrate/helpers/ts-compiler.js +14 -0
  61. package/src/core/modules/migrate/index.ts +41 -0
  62. package/src/core/modules/migrate/migration-runner.ts +230 -0
  63. package/src/core/modules/migrate/mongo-state-store.ts +283 -0
  64. package/src/core/modules/migrate/templates/migration-with-helper.template.ts +72 -0
  65. package/src/core/modules/migrate/templates/migration.template.ts +59 -0
  66. package/src/core/modules/user/core-user.model.ts +120 -78
  67. package/src/index.ts +9 -3
  68. package/src/main.ts +25 -0
  69. package/src/server/common/models/persistence.model.ts +15 -13
  70. package/src/server/modules/auth/auth.model.ts +7 -3
  71. package/src/server/modules/user/user.controller.ts +242 -0
  72. package/src/server/modules/user/user.model.ts +39 -26
  73. package/src/server/modules/user/user.module.ts +2 -1
@@ -0,0 +1,4 @@
1
+ export * from './cli/migrate-cli';
2
+ export * from './helpers/migration.helper';
3
+ export * from './migration-runner';
4
+ export * from './mongo-state-store';
@@ -0,0 +1,21 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cli/migrate-cli"), exports);
18
+ __exportStar(require("./helpers/migration.helper"), exports);
19
+ __exportStar(require("./migration-runner"), exports);
20
+ __exportStar(require("./mongo-state-store"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/modules/migrate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAqCA,oDAAkC;AAClC,6DAA2C;AAC3C,qDAAmC;AACnC,sDAAoC"}
@@ -0,0 +1,26 @@
1
+ import { MongoStateStore } from './mongo-state-store';
2
+ export interface MigrationFile {
3
+ down?: () => Promise<void>;
4
+ filePath: string;
5
+ timestamp: number;
6
+ title: string;
7
+ up: () => Promise<void>;
8
+ }
9
+ export interface MigrationRunnerOptions {
10
+ migrationsDirectory: string;
11
+ pattern?: RegExp;
12
+ stateStore: MongoStateStore;
13
+ }
14
+ export declare class MigrationRunner {
15
+ private options;
16
+ private pattern;
17
+ constructor(options: MigrationRunnerOptions);
18
+ private loadMigrationFiles;
19
+ up(): Promise<void>;
20
+ down(): Promise<void>;
21
+ status(): Promise<{
22
+ completed: string[];
23
+ pending: string[];
24
+ }>;
25
+ static create(migrationsDirectory: string, name: string): Promise<string>;
26
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MigrationRunner = void 0;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ class MigrationRunner {
7
+ constructor(options) {
8
+ this.options = options;
9
+ this.pattern = options.pattern || /\.(ts|js)$/;
10
+ }
11
+ async loadMigrationFiles() {
12
+ const files = fs
13
+ .readdirSync(this.options.migrationsDirectory)
14
+ .filter((file) => this.pattern.test(file))
15
+ .sort();
16
+ const migrations = [];
17
+ for (const file of files) {
18
+ const filePath = path.join(this.options.migrationsDirectory, file);
19
+ const module = require(filePath);
20
+ if (!module.up) {
21
+ console.warn(`Migration ${file} has no 'up' function, skipping...`);
22
+ continue;
23
+ }
24
+ const timestampMatch = file.match(/^(\d+)-/);
25
+ const timestamp = timestampMatch ? parseInt(timestampMatch[1], 10) : Date.now();
26
+ migrations.push({
27
+ down: module.down,
28
+ filePath,
29
+ timestamp,
30
+ title: file,
31
+ up: module.up,
32
+ });
33
+ }
34
+ return migrations;
35
+ }
36
+ async up() {
37
+ const allMigrations = await this.loadMigrationFiles();
38
+ const state = await this.options.stateStore.loadAsync();
39
+ const completedMigrations = (state.migrations || []).map((m) => m.title);
40
+ const pendingMigrations = allMigrations.filter((m) => !completedMigrations.includes(m.title));
41
+ if (pendingMigrations.length === 0) {
42
+ console.log('No pending migrations');
43
+ return;
44
+ }
45
+ console.log(`Running ${pendingMigrations.length} pending migration(s)...`);
46
+ for (const migration of pendingMigrations) {
47
+ console.log(`Running migration: ${migration.title}`);
48
+ await migration.up();
49
+ const newState = await this.options.stateStore.loadAsync();
50
+ const migrations = newState.migrations || [];
51
+ migrations.push({
52
+ timestamp: migration.timestamp,
53
+ title: migration.title,
54
+ });
55
+ await this.options.stateStore.saveAsync({
56
+ lastRun: migration.title,
57
+ migrations,
58
+ up: () => { },
59
+ });
60
+ console.log(`✓ Migration completed: ${migration.title}`);
61
+ }
62
+ console.log('All migrations completed successfully');
63
+ }
64
+ async down() {
65
+ const state = await this.options.stateStore.loadAsync();
66
+ const completedMigrations = state.migrations || [];
67
+ if (completedMigrations.length === 0) {
68
+ console.log('No migrations to rollback');
69
+ return;
70
+ }
71
+ const lastMigration = completedMigrations[completedMigrations.length - 1];
72
+ const allMigrations = await this.loadMigrationFiles();
73
+ const migrationToRollback = allMigrations.find((m) => m.title === lastMigration.title);
74
+ if (!migrationToRollback) {
75
+ throw new Error(`Migration file not found: ${lastMigration.title}`);
76
+ }
77
+ if (!migrationToRollback.down) {
78
+ throw new Error(`Migration ${lastMigration.title} has no 'down' function`);
79
+ }
80
+ console.log(`Rolling back migration: ${migrationToRollback.title}`);
81
+ await migrationToRollback.down();
82
+ const newMigrations = completedMigrations.slice(0, -1);
83
+ await this.options.stateStore.saveAsync({
84
+ lastRun: newMigrations.length > 0 ? newMigrations[newMigrations.length - 1].title : undefined,
85
+ migrations: newMigrations,
86
+ up: () => { },
87
+ });
88
+ console.log(`✓ Migration rolled back: ${migrationToRollback.title}`);
89
+ }
90
+ async status() {
91
+ const allMigrations = await this.loadMigrationFiles();
92
+ const state = await this.options.stateStore.loadAsync();
93
+ const completedMigrations = (state.migrations || []).map((m) => m.title);
94
+ return {
95
+ completed: completedMigrations,
96
+ pending: allMigrations.filter((m) => !completedMigrations.includes(m.title)).map((m) => m.title),
97
+ };
98
+ }
99
+ static async create(migrationsDirectory, name) {
100
+ const timestamp = Date.now();
101
+ const fileName = `${timestamp}-${name}.ts`;
102
+ const filePath = path.join(migrationsDirectory, fileName);
103
+ const template = `/**
104
+ * Migration: ${name}
105
+ * Created: ${new Date().toISOString()}
106
+ */
107
+
108
+ export const up = async () => {
109
+ // TODO: Implement migration
110
+ console.log('Running migration: ${name}');
111
+ };
112
+
113
+ export const down = async () => {
114
+ // TODO: Implement rollback
115
+ console.log('Rolling back migration: ${name}');
116
+ };
117
+ `;
118
+ fs.writeFileSync(filePath, template, 'utf-8');
119
+ console.log(`✓ Created migration: ${fileName}`);
120
+ return filePath;
121
+ }
122
+ }
123
+ exports.MigrationRunner = MigrationRunner;
124
+ //# sourceMappingURL=migration-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../../../src/core/modules/migrate/migration-runner.ts"],"names":[],"mappings":";;;AAGA,yBAAyB;AACzB,6BAA6B;AAsD7B,MAAa,eAAe;IAI1B,YAAY,OAA+B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC;IACjD,CAAC;IAKO,KAAK,CAAC,kBAAkB;QAC9B,MAAM,KAAK,GAAG,EAAE;aACb,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;aAC7C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACzC,IAAI,EAAE,CAAC;QAEV,MAAM,UAAU,GAAoB,EAAE,CAAC;QAEvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,CA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,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAEzE,OAAO;YACL,SAAS,EAAE,mBAAmB;YAC9B,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;SACjG,CAAC;IACJ,CAAC;IAKD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,mBAA2B,EAAE,IAAY;QAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,GAAG,SAAS,IAAI,IAAI,KAAK,CAAC;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QAE1D,MAAM,QAAQ,GAAG;gBACL,IAAI;cACN,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;;;;;oCAKF,IAAI;;;;;yCAKC,IAAI;;CAE5C,CAAC;QAEE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;QAEhD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA3KD,0CA2KC"}
@@ -0,0 +1,30 @@
1
+ export interface MigrationOptions {
2
+ [key: string]: unknown;
3
+ stateStore: MongoStateStore;
4
+ }
5
+ export interface MigrationSet {
6
+ down?: (done?: (err?: Error) => void) => void;
7
+ lastRun?: string;
8
+ migrations: Array<{
9
+ timestamp?: number;
10
+ title: string;
11
+ }>;
12
+ up: (done?: (err?: Error) => void) => void;
13
+ }
14
+ export interface MongoStateStoreOptions {
15
+ collectionName?: string;
16
+ lockCollectionName?: string;
17
+ uri: string;
18
+ }
19
+ export declare class MongoStateStore {
20
+ private readonly collectionName;
21
+ readonly mongodbHost: string;
22
+ readonly lockCollectionName?: string;
23
+ constructor(objectOrHost: MongoStateStoreOptions | string);
24
+ load(fn: (err?: Error, set?: MigrationSet) => void): void;
25
+ loadAsync(): Promise<MigrationSet>;
26
+ save(set: MigrationSet, fn: (err?: Error) => void): void;
27
+ saveAsync(set: MigrationSet): Promise<void>;
28
+ }
29
+ export declare function synchronizedMigration(opts: MigrationOptions, callback: (set: MigrationSet) => Promise<void>): Promise<void>;
30
+ export declare function synchronizedUp(opts: MigrationOptions): Promise<void>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoStateStore = void 0;
4
+ exports.synchronizedMigration = synchronizedMigration;
5
+ exports.synchronizedUp = synchronizedUp;
6
+ const mongodb_1 = require("mongodb");
7
+ const util_1 = require("util");
8
+ class MongoStateStore {
9
+ constructor(objectOrHost) {
10
+ this.mongodbHost = typeof objectOrHost === 'string' ? objectOrHost : objectOrHost.uri;
11
+ this.collectionName =
12
+ typeof objectOrHost === 'string' ? 'migrations' : (objectOrHost.collectionName ?? 'migrations');
13
+ this.lockCollectionName = typeof objectOrHost !== 'string' ? objectOrHost.lockCollectionName : undefined;
14
+ }
15
+ load(fn) {
16
+ this.loadAsync()
17
+ .then((result) => fn(undefined, result))
18
+ .catch((err) => fn(err));
19
+ }
20
+ async loadAsync() {
21
+ return dbRequest(this.mongodbHost, async (db) => {
22
+ const result = await db.collection(this.collectionName).find({}).toArray();
23
+ if (result.length > 1) {
24
+ throw new Error(`Expected exactly one result, but got ${result.length}`);
25
+ }
26
+ if (result.length === 0) {
27
+ console.debug('No migrations found, probably running the very first time');
28
+ return {};
29
+ }
30
+ return result[0];
31
+ });
32
+ }
33
+ save(set, fn) {
34
+ this.saveAsync(set)
35
+ .then(() => fn())
36
+ .catch((err) => fn(err));
37
+ }
38
+ async saveAsync(set) {
39
+ const { lastRun, migrations } = set;
40
+ await dbRequest(this.mongodbHost, async (db) => {
41
+ await db.collection(this.collectionName).replaceOne({}, { lastRun, migrations }, { upsert: true });
42
+ });
43
+ }
44
+ }
45
+ exports.MongoStateStore = MongoStateStore;
46
+ async function synchronizedMigration(opts, callback) {
47
+ if (!opts.stateStore) {
48
+ throw new Error('No `stateStore` in migration options');
49
+ }
50
+ const stateStore = opts.stateStore;
51
+ if (!(stateStore instanceof MongoStateStore)) {
52
+ throw new Error('Given `stateStore` is not `MongoStateStore`');
53
+ }
54
+ const lockCollectionName = stateStore.lockCollectionName;
55
+ if (typeof lockCollectionName !== 'string') {
56
+ throw new Error('`lockCollectionName` in MongoStateStore is not set');
57
+ }
58
+ try {
59
+ await acquireLock(stateStore.mongodbHost, lockCollectionName);
60
+ const set = await stateStore.loadAsync();
61
+ await callback(set);
62
+ }
63
+ finally {
64
+ await releaseLock(stateStore.mongodbHost, lockCollectionName);
65
+ }
66
+ }
67
+ async function synchronizedUp(opts) {
68
+ await synchronizedMigration(opts, async (loadedSet) => {
69
+ await (0, util_1.promisify)(loadedSet.up).call(loadedSet);
70
+ });
71
+ }
72
+ async function acquireLock(url, lockCollectionName) {
73
+ await dbRequest(url, async (db) => {
74
+ const collection = db.collection(lockCollectionName);
75
+ await collection.createIndex({ lock: 1 }, { unique: true });
76
+ let showMessage = true;
77
+ for (;;) {
78
+ const result = await collection.updateOne({ lock: 'lock' }, { $set: { lock: 'lock' } }, { upsert: true });
79
+ const lockAcquired = result.upsertedCount > 0;
80
+ if (lockAcquired) {
81
+ break;
82
+ }
83
+ if (showMessage) {
84
+ console.debug('Waiting for migration lock release …');
85
+ showMessage = false;
86
+ }
87
+ await (0, util_1.promisify)(setTimeout)(100);
88
+ }
89
+ });
90
+ }
91
+ async function dbRequest(url, callback) {
92
+ let client;
93
+ try {
94
+ client = await mongodb_1.MongoClient.connect(url);
95
+ const db = client.db();
96
+ return await callback(db);
97
+ }
98
+ finally {
99
+ await client?.close();
100
+ }
101
+ }
102
+ async function releaseLock(url, lockCollectionName) {
103
+ await dbRequest(url, (db) => db.collection(lockCollectionName).deleteOne({ lock: 'lock' }));
104
+ }
105
+ //# sourceMappingURL=mongo-state-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-state-store.js","sourceRoot":"","sources":["../../../../src/core/modules/migrate/mongo-state-store.ts"],"names":[],"mappings":";;;AAmKA,sDA6BC;AAqBD,wCAIC;AAzND,qCAA0C;AAC1C,+BAAiC;AAyDjC,MAAa,eAAe;IAe1B,YAAY,YAA6C;QACvD,IAAI,CAAC,WAAW,GAAG,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC;QACtF,IAAI,CAAC,cAAc;YACjB,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,cAAc,IAAI,YAAY,CAAC,CAAC;QAClG,IAAI,CAAC,kBAAkB,GAAG,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,CAAC;IAOD,IAAI,CAAC,EAA6C;QAChD,IAAI,CAAC,SAAS,EAAE;aACb,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;aACvC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC;IAOD,KAAK,CAAC,SAAS;QACb,OAAO,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,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2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const up = async () => {
5
+ };
6
+ exports.up = up;
7
+ const down = async () => {
8
+ };
9
+ exports.down = down;
10
+ //# sourceMappingURL=migration-with-helper.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-with-helper.template.js","sourceRoot":"","sources":["../../../../../src/core/modules/migrate/templates/migration-with-helper.template.ts"],"names":[],"mappings":";;;AAgCO,MAAM,EAAE,GAAG,KAAK,IAAI,EAAE;AAiB7B,CAAC,CAAC;AAjBW,QAAA,EAAE,MAiBb;AAKK,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;AAiB/B,CAAC,CAAC;AAjBW,QAAA,IAAI,QAiBf"}
@@ -0,0 +1,2 @@
1
+ export declare const up: () => Promise<void>;
2
+ export declare const down: () => Promise<void>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const getDb = async () => {
5
+ throw new Error('Please configure the getDb() function in this migration file or use the migration helper from @lenne.tech/nest-server');
6
+ };
7
+ const up = async () => {
8
+ const db = await getDb();
9
+ };
10
+ exports.up = up;
11
+ const down = async () => {
12
+ const db = await getDb();
13
+ };
14
+ exports.down = down;
15
+ //# sourceMappingURL=migration.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.template.js","sourceRoot":"","sources":["../../../../../src/core/modules/migrate/templates/migration.template.ts"],"names":[],"mappings":";;;AAiBA,MAAM,KAAK,GAAG,KAAK,IAAiB,EAAE;IAQpC,MAAM,IAAI,KAAK,CACb,uHAAuH,CACxH,CAAC;AACJ,CAAC,CAAC;AAOK,MAAM,EAAE,GAAG,KAAK,IAAI,EAAE;IAC3B,MAAM,EAAE,GAAO,MAAM,KAAK,EAAE,CAAC;AAO/B,CAAC,CAAC;AARW,QAAA,EAAE,MAQb;AAOK,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;IAC7B,MAAM,EAAE,GAAO,MAAM,KAAK,EAAE,CAAC;AAO/B,CAAC,CAAC;AARW,QAAA,IAAI,QAQf"}
@@ -13,8 +13,8 @@ exports.CoreUserModel = void 0;
13
13
  const graphql_1 = require("@nestjs/graphql");
14
14
  const mongoose_1 = require("@nestjs/mongoose");
15
15
  const swagger_1 = require("@nestjs/swagger");
16
- const class_validator_1 = require("class-validator");
17
16
  const restricted_decorator_1 = require("../../common/decorators/restricted.decorator");
17
+ const unified_field_decorator_1 = require("../../common/decorators/unified-field.decorator");
18
18
  const role_enum_1 = require("../../common/enums/role.enum");
19
19
  const core_persistence_model_1 = require("../../common/models/core-persistence.model");
20
20
  let CoreUserModel = class CoreUserModel extends core_persistence_model_1.CorePersistenceModel {
@@ -40,7 +40,7 @@ let CoreUserModel = class CoreUserModel extends core_persistence_model_1.CorePer
40
40
  if (!this.roles || this.roles.length < 1) {
41
41
  return false;
42
42
  }
43
- return !roles || roles.length < 1 ? true : this.roles.some(role => roles.includes(role));
43
+ return !roles || roles.length < 1 ? true : this.roles.some((role) => roles.includes(role));
44
44
  }
45
45
  hasAllRoles(roles) {
46
46
  if (typeof roles === 'string') {
@@ -49,7 +49,7 @@ let CoreUserModel = class CoreUserModel extends core_persistence_model_1.CorePer
49
49
  if (!this.roles || this.roles.length < 1) {
50
50
  return false;
51
51
  }
52
- return !roles ? true : roles.every(role => this.roles.includes(role));
52
+ return !roles ? true : roles.every((role) => this.roles.includes(role));
53
53
  }
54
54
  init() {
55
55
  super.init();
@@ -63,55 +63,66 @@ let CoreUserModel = class CoreUserModel extends core_persistence_model_1.CorePer
63
63
  };
64
64
  exports.CoreUserModel = CoreUserModel;
65
65
  __decorate([
66
- (0, swagger_1.ApiProperty)(),
67
- (0, graphql_1.Field)({ description: 'Email of the user', nullable: true }),
68
- (0, mongoose_1.Prop)({ index: true, lowercase: true, trim: true }),
69
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
66
+ (0, unified_field_decorator_1.UnifiedField)({
67
+ description: 'Email of the user',
68
+ isOptional: true,
69
+ mongoose: { index: true, lowercase: true, trim: true },
70
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
71
+ }),
70
72
  __metadata("design:type", String)
71
73
  ], CoreUserModel.prototype, "email", void 0);
72
74
  __decorate([
73
- (0, swagger_1.ApiProperty)(),
74
- (0, graphql_1.Field)({ description: 'First name of the user', nullable: true }),
75
- (0, class_validator_1.IsOptional)(),
76
- (0, mongoose_1.Prop)(),
77
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
75
+ (0, unified_field_decorator_1.UnifiedField)({
76
+ description: 'First name of the user',
77
+ isOptional: true,
78
+ mongoose: true,
79
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
80
+ }),
78
81
  __metadata("design:type", String)
79
82
  ], CoreUserModel.prototype, "firstName", void 0);
80
83
  __decorate([
81
- (0, swagger_1.ApiProperty)(),
82
- (0, graphql_1.Field)({ description: 'Last name of the user', nullable: true }),
83
- (0, class_validator_1.IsOptional)(),
84
- (0, mongoose_1.Prop)(),
85
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
84
+ (0, unified_field_decorator_1.UnifiedField)({
85
+ description: 'Last name of the user',
86
+ isOptional: true,
87
+ mongoose: true,
88
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
89
+ }),
86
90
  __metadata("design:type", String)
87
91
  ], CoreUserModel.prototype, "lastName", void 0);
88
92
  __decorate([
89
- (0, swagger_1.ApiProperty)(),
90
- (0, mongoose_1.Prop)(),
91
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_NO_ONE),
93
+ (0, unified_field_decorator_1.UnifiedField)({
94
+ isOptional: true,
95
+ mongoose: true,
96
+ roles: role_enum_1.RoleEnum.S_NO_ONE,
97
+ }),
92
98
  __metadata("design:type", String)
93
99
  ], CoreUserModel.prototype, "password", void 0);
94
100
  __decorate([
95
- (0, swagger_1.ApiProperty)(),
96
- (0, graphql_1.Field)(() => [String], { description: 'Roles of the user', nullable: true }),
97
- (0, class_validator_1.IsOptional)(),
98
- (0, mongoose_1.Prop)([String]),
99
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
101
+ (0, unified_field_decorator_1.UnifiedField)({
102
+ description: 'Roles of the user',
103
+ isArray: true,
104
+ isOptional: true,
105
+ mongoose: [String],
106
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
107
+ type: () => String,
108
+ }),
100
109
  __metadata("design:type", Array)
101
110
  ], CoreUserModel.prototype, "roles", void 0);
102
111
  __decorate([
103
- (0, swagger_1.ApiProperty)(),
104
- (0, graphql_1.Field)({ description: 'Username of the user', nullable: true }),
105
- (0, class_validator_1.IsOptional)(),
106
- (0, mongoose_1.Prop)(),
107
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
112
+ (0, unified_field_decorator_1.UnifiedField)({
113
+ description: 'Username of the user',
114
+ isOptional: true,
115
+ mongoose: true,
116
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
117
+ }),
108
118
  __metadata("design:type", String)
109
119
  ], CoreUserModel.prototype, "username", void 0);
110
120
  __decorate([
111
- (0, swagger_1.ApiProperty)(),
112
- (0, class_validator_1.IsOptional)(),
113
- (0, mongoose_1.Prop)(),
114
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_NO_ONE),
121
+ (0, unified_field_decorator_1.UnifiedField)({
122
+ isOptional: true,
123
+ mongoose: true,
124
+ roles: role_enum_1.RoleEnum.S_NO_ONE,
125
+ }),
115
126
  __metadata("design:type", String)
116
127
  ], CoreUserModel.prototype, "passwordResetToken", void 0);
117
128
  __decorate([
@@ -119,9 +130,21 @@ __decorate([
119
130
  (0, swagger_1.ApiProperty)({
120
131
  additionalProperties: {
121
132
  properties: {
122
- deviceDescription: { description: 'Description of the device from which the token was generated', nullable: true, type: 'string' },
123
- deviceId: { description: 'ID of the device from which the token was generated', nullable: true, type: 'string' },
124
- tokenId: { description: 'Token ID to make sure that there is only one RefreshToken for each device', nullable: false, type: 'string' },
133
+ deviceDescription: {
134
+ description: 'Description of the device from which the token was generated',
135
+ nullable: true,
136
+ type: 'string',
137
+ },
138
+ deviceId: {
139
+ description: 'ID of the device from which the token was generated',
140
+ nullable: true,
141
+ type: 'string',
142
+ },
143
+ tokenId: {
144
+ description: 'Token ID to make sure that there is only one RefreshToken for each device',
145
+ nullable: false,
146
+ type: 'string',
147
+ },
125
148
  },
126
149
  type: 'object',
127
150
  },
@@ -140,7 +163,6 @@ __decorate([
140
163
  },
141
164
  type: 'object',
142
165
  }),
143
- (0, class_validator_1.IsOptional)(),
144
166
  (0, mongoose_1.Prop)((0, mongoose_1.raw)({})),
145
167
  (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_NO_ONE),
146
168
  __metadata("design:type", Object)
@@ -150,9 +172,23 @@ __decorate([
150
172
  (0, swagger_1.ApiProperty)({
151
173
  additionalProperties: {
152
174
  properties: {
153
- createdAt: { description: 'Token Created At', example: 1740037703939, format: 'int64', nullable: true, type: 'number' },
154
- deviceId: { description: 'ID of the device from which the token was generated', nullable: true, type: 'string' },
155
- tokenId: { description: 'Token ID to make sure that there is only one RefreshToken for each device', nullable: false, type: 'string' },
175
+ createdAt: {
176
+ description: 'Token Created At',
177
+ example: 1740037703939,
178
+ format: 'int64',
179
+ nullable: true,
180
+ type: 'number',
181
+ },
182
+ deviceId: {
183
+ description: 'ID of the device from which the token was generated',
184
+ nullable: true,
185
+ type: 'string',
186
+ },
187
+ tokenId: {
188
+ description: 'Token ID to make sure that there is only one RefreshToken for each device',
189
+ nullable: false,
190
+ type: 'string',
191
+ },
156
192
  },
157
193
  type: 'object',
158
194
  },
@@ -171,30 +207,35 @@ __decorate([
171
207
  },
172
208
  type: 'object',
173
209
  }),
174
- (0, class_validator_1.IsOptional)(),
175
210
  (0, mongoose_1.Prop)((0, mongoose_1.raw)({})),
176
211
  (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_NO_ONE),
177
212
  __metadata("design:type", Object)
178
213
  ], CoreUserModel.prototype, "tempTokens", void 0);
179
214
  __decorate([
180
- (0, swagger_1.ApiProperty)(),
181
- (0, class_validator_1.IsOptional)(),
182
- (0, mongoose_1.Prop)(),
183
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_NO_ONE),
215
+ (0, unified_field_decorator_1.UnifiedField)({
216
+ isOptional: true,
217
+ mongoose: true,
218
+ roles: role_enum_1.RoleEnum.S_NO_ONE,
219
+ }),
184
220
  __metadata("design:type", String)
185
221
  ], CoreUserModel.prototype, "verificationToken", void 0);
186
222
  __decorate([
187
- (0, swagger_1.ApiProperty)(),
188
- (0, graphql_1.Field)(() => Boolean, { description: 'Verification state of the user', nullable: true }),
189
- (0, mongoose_1.Prop)({ type: Boolean }),
190
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
223
+ (0, unified_field_decorator_1.UnifiedField)({
224
+ description: 'Verification state of the user',
225
+ isOptional: true,
226
+ mongoose: { type: Boolean },
227
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
228
+ type: () => Boolean,
229
+ }),
191
230
  __metadata("design:type", Boolean)
192
231
  ], CoreUserModel.prototype, "verified", void 0);
193
232
  __decorate([
194
- (0, swagger_1.ApiProperty)(),
195
- (0, graphql_1.Field)({ description: 'Verified date', nullable: true }),
196
- (0, mongoose_1.Prop)(),
197
- (0, restricted_decorator_1.Restricted)(role_enum_1.RoleEnum.S_EVERYONE),
233
+ (0, unified_field_decorator_1.UnifiedField)({
234
+ description: 'Verified date',
235
+ isOptional: true,
236
+ mongoose: true,
237
+ roles: role_enum_1.RoleEnum.S_EVERYONE,
238
+ }),
198
239
  __metadata("design:type", Date)
199
240
  ], CoreUserModel.prototype, "verifiedAt", void 0);
200
241
  exports.CoreUserModel = CoreUserModel = __decorate([