@orion-js/migrations 4.0.0-next.3 → 4.0.0-next.5

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.cjs CHANGED
@@ -1,7 +1,14 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
12
  var __export = (target, all) => {
6
13
  for (var name in all)
7
14
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,14 +22,45 @@ var __copyProps = (to, from, except, desc) => {
15
22
  return to;
16
23
  };
17
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var __decorateClass = (decorators, target, key, kind) => {
19
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
- if (decorator = decorators[i])
22
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
- if (kind && result) __defProp(target, key, result);
24
- return result;
25
+ var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
26
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
27
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
28
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
29
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
30
+ var __runInitializers = (array, flags, self, value) => {
31
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
32
+ return value;
33
+ };
34
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
35
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
36
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
37
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
38
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
39
+ return __privateGet(this, extra);
40
+ }, set [name](x) {
41
+ return __privateSet(this, extra, x);
42
+ } }, name));
43
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
44
+ for (var i = decorators.length - 1; i >= 0; i--) {
45
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
46
+ if (k) {
47
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
48
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
49
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
50
+ }
51
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
52
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
53
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
54
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
55
+ }
56
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
25
57
  };
58
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
59
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
60
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
61
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
62
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
63
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
26
64
 
27
65
  // src/index.ts
28
66
  var index_exports = {};
@@ -38,27 +76,27 @@ module.exports = __toCommonJS(index_exports);
38
76
 
39
77
  // src/Schema.ts
40
78
  var import_typed_model = require("@orion-js/typed-model");
79
+ var _completedAt_dec, _name_dec, __id_dec, _MigrationSchema_decorators, _init;
80
+ _MigrationSchema_decorators = [(0, import_typed_model.TypedSchema)()], __id_dec = [(0, import_typed_model.Prop)({ type: "string" })], _name_dec = [(0, import_typed_model.Prop)({ type: String })], _completedAt_dec = [(0, import_typed_model.Prop)({ type: Date })];
41
81
  var MigrationSchema = class {
42
- _id;
43
- name;
44
- completedAt;
82
+ constructor() {
83
+ __publicField(this, "_id", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
84
+ __publicField(this, "name", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
85
+ __publicField(this, "completedAt", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
86
+ }
45
87
  };
46
- __decorateClass([
47
- (0, import_typed_model.Prop)({ type: "string" })
48
- ], MigrationSchema.prototype, "_id", 2);
49
- __decorateClass([
50
- (0, import_typed_model.Prop)()
51
- ], MigrationSchema.prototype, "name", 2);
52
- __decorateClass([
53
- (0, import_typed_model.Prop)()
54
- ], MigrationSchema.prototype, "completedAt", 2);
55
- MigrationSchema = __decorateClass([
56
- (0, import_typed_model.TypedSchema)()
57
- ], MigrationSchema);
88
+ _init = __decoratorStart(null);
89
+ __decorateElement(_init, 5, "_id", __id_dec, MigrationSchema);
90
+ __decorateElement(_init, 5, "name", _name_dec, MigrationSchema);
91
+ __decorateElement(_init, 5, "completedAt", _completedAt_dec, MigrationSchema);
92
+ MigrationSchema = __decorateElement(_init, 0, "MigrationSchema", _MigrationSchema_decorators, MigrationSchema);
93
+ __runInitializers(_init, 1, MigrationSchema);
58
94
 
59
95
  // src/Repo.ts
60
96
  var import_mongodb = require("@orion-js/mongodb");
61
97
  var import_services = require("@orion-js/services");
98
+ var _MigrationsRepo_decorators, _init2;
99
+ _MigrationsRepo_decorators = [(0, import_services.Service)()];
62
100
  var MigrationsRepo = class {
63
101
  collection = (0, import_mongodb.createCollection)({
64
102
  name: "orionjs.migrations",
@@ -74,9 +112,9 @@ var MigrationsRepo = class {
74
112
  await this.collection.insertOne({ name, completedAt: /* @__PURE__ */ new Date() });
75
113
  }
76
114
  };
77
- MigrationsRepo = __decorateClass([
78
- (0, import_services.Service)()
79
- ], MigrationsRepo);
115
+ _init2 = __decoratorStart(null);
116
+ MigrationsRepo = __decorateElement(_init2, 0, "MigrationsRepo", _MigrationsRepo_decorators, MigrationsRepo);
117
+ __runInitializers(_init2, 1, MigrationsRepo);
80
118
 
81
119
  // src/loadMigrations/index.ts
82
120
  var import_dogs = require("@orion-js/dogs");
@@ -84,22 +122,27 @@ var import_dogs = require("@orion-js/dogs");
84
122
  // src/service/index.ts
85
123
  var import_services2 = require("@orion-js/services");
86
124
  var import_services3 = require("@orion-js/services");
125
+ var serviceMetadata = /* @__PURE__ */ new WeakMap();
87
126
  function MigrationService(options) {
88
- return function(target) {
89
- (0, import_services3.Service)()(target);
90
- target.prototype.service = target;
91
- target.prototype.options = options;
92
- target.prototype.serviceType = "migration";
127
+ return function(target, context) {
128
+ (0, import_services3.Service)()(target, context);
129
+ context.addInitializer(function() {
130
+ serviceMetadata.set(this, { _serviceType: "migrations", options });
131
+ });
93
132
  };
94
133
  }
95
134
  function getMigrationsFromServices(services) {
96
- return services.filter((service) => service.prototype.serviceType === "migration").map((service) => {
97
- const options = service.prototype.options;
135
+ return services.map((service) => {
136
+ const instance = (0, import_services2.getInstance)(service);
137
+ const options = serviceMetadata.get(instance.constructor);
138
+ if (!options._serviceType || options._serviceType !== "migrations") {
139
+ throw new Error(`Service ${service.name} is not a migration service`);
140
+ }
98
141
  return {
99
- ...options,
142
+ ...options.options,
100
143
  runMigration: async (context) => {
101
- const instance = (0, import_services2.getInstance)(service);
102
- return await instance.runMigration(context);
144
+ const instance2 = (0, import_services2.getInstance)(service);
145
+ return await instance2.runMigration(context);
103
146
  }
104
147
  };
105
148
  });
@@ -111,8 +154,12 @@ var import_services5 = require("@orion-js/services");
111
154
  // src/MigrationsService.ts
112
155
  var import_services4 = require("@orion-js/services");
113
156
  var import_logger = require("@orion-js/logger");
157
+ var _migrationsRepo_dec, _MigrationsService_decorators, _init3;
158
+ _MigrationsService_decorators = [(0, import_services4.Service)()], _migrationsRepo_dec = [(0, import_services4.Inject)(() => MigrationsRepo)];
114
159
  var MigrationsService = class {
115
- migrationsRepo;
160
+ constructor() {
161
+ __publicField(this, "migrationsRepo", __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
162
+ }
116
163
  async getNextMigration(migrationsList) {
117
164
  const completedNames = await this.migrationsRepo.getCompletedMigrationNames();
118
165
  for (const migrationExecutable of migrationsList) {
@@ -155,12 +202,10 @@ var MigrationsService = class {
155
202
  session.endSession();
156
203
  }
157
204
  };
158
- __decorateClass([
159
- (0, import_services4.Inject)(() => MigrationsRepo)
160
- ], MigrationsService.prototype, "migrationsRepo", 2);
161
- MigrationsService = __decorateClass([
162
- (0, import_services4.Service)()
163
- ], MigrationsService);
205
+ _init3 = __decoratorStart(null);
206
+ __decorateElement(_init3, 5, "migrationsRepo", _migrationsRepo_dec, MigrationsService);
207
+ MigrationsService = __decorateElement(_init3, 0, "MigrationsService", _MigrationsService_decorators, MigrationsService);
208
+ __runInitializers(_init3, 1, MigrationsService);
164
209
 
165
210
  // src/loadMigrations/index.ts
166
211
  function loadMigrations(migrationServices, options) {
@@ -176,7 +221,7 @@ function loadMigrations(migrationServices, options) {
176
221
  orionjsRunMigrations: (0, import_dogs.defineJob)({
177
222
  type: "recurrent",
178
223
  runEvery: 30 * 1e3,
179
- async resolve(params, context) {
224
+ async resolve(_params, context) {
180
225
  const instance = (0, import_services5.getInstance)(MigrationsService);
181
226
  await instance.runMigrations(migrations, context);
182
227
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Schema.ts","../src/Repo.ts","../src/loadMigrations/index.ts","../src/service/index.ts","../src/MigrationsService.ts"],"sourcesContent":["export * from './Schema'\nexport * from './Repo'\nexport * from './loadMigrations'\nexport * from './service'\nexport * from './MigrationsService'\n","import {TypedSchema, Prop} from '@orion-js/typed-model'\n\nexport type MigrationId = `scnmg-${string}`\n\n@TypedSchema()\nexport class MigrationSchema {\n @Prop({type: 'string'})\n _id: MigrationId\n\n @Prop()\n name: string\n\n @Prop()\n completedAt: Date\n}\n","import {MongoCollection, Repository, Collection, createCollection} from '@orion-js/mongodb'\nimport {MigrationSchema} from './Schema'\nimport { Service } from '@orion-js/services'\n\n@Service()\nexport class MigrationsRepo {\n public collection = createCollection<MigrationSchema>({\n name: 'orionjs.migrations',\n schema: MigrationSchema,\n idPrefix: 'scnmg-',\n indexes: []\n })\n\n async getCompletedMigrationNames() {\n const migrations = await this.collection.find().toArray()\n return migrations.map(m => m.name)\n }\n\n async saveCompletedMigration(name: string) {\n await this.collection.insertOne({name, completedAt: new Date()})\n }\n}\n","import {defineJob, startWorkers} from '@orion-js/dogs'\nimport {getMigrationsFromServices} from '../service'\nimport {getInstance} from '@orion-js/services'\nimport {MigrationsService} from '../MigrationsService'\n\nexport interface Options {\n lockTime?: number\n omitJob?: boolean\n}\n\nexport function loadMigrations(migrationServices: any[], options?: Options) {\n const migrations = getMigrationsFromServices(migrationServices)\n if (options?.omitJob) return migrations\n\n startWorkers({\n cooldownPeriod: 1000,\n lockTime: 1000 * 60 * 20, // 20 min\n workersCount: 1,\n pollInterval: 10 * 1000,\n jobs: {\n orionjsRunMigrations: defineJob({\n type: 'recurrent',\n runEvery: 30 * 1000,\n async resolve(params, context) {\n const instance = getInstance(MigrationsService)\n await instance.runMigrations(migrations, context)\n }\n })\n }\n })\n\n return migrations\n}\n","import {ExecutionContext} from '@orion-js/dogs'\nimport {getInstance} from '@orion-js/services'\nimport {Service} from '@orion-js/services'\n\nexport interface MigrationServiceOptions {\n name: string\n useMongoTransactions: false\n}\n\nexport function MigrationService(options: MigrationServiceOptions): ClassDecorator {\n return function (target: any) {\n Service()(target)\n target.prototype.service = target\n target.prototype.options = options\n target.prototype.serviceType = 'migration'\n }\n}\n\nexport type MigrationExecutable = {\n runMigration(context: ExecutionContext): Promise<void>\n} & MigrationServiceOptions\n\nexport function getMigrationsFromServices(services: any[]): MigrationExecutable[] {\n return services\n .filter(service => service.prototype.serviceType === 'migration')\n .map(service => {\n const options = service.prototype.options\n return {\n ...options,\n runMigration: async (context: ExecutionContext) => {\n const instance = getInstance(service) as any\n return await instance.runMigration(context)\n }\n }\n })\n}\n","import {Inject, Service} from '@orion-js/services'\nimport type {MigrationsRepo as MigrationsRepoType} from './Repo'\nimport {MigrationsRepo} from './Repo'\nimport {logger} from '@orion-js/logger'\nimport {MigrationExecutable} from './service'\nimport {ExecutionContext} from '@orion-js/dogs'\n\n@Service()\nexport class MigrationsService {\n @Inject(() => MigrationsRepo)\n private migrationsRepo: MigrationsRepoType\n\n async getNextMigration(migrationsList: MigrationExecutable[]) {\n const completedNames = await this.migrationsRepo.getCompletedMigrationNames()\n\n for (const migrationExecutable of migrationsList) {\n if (completedNames.includes(migrationExecutable.name)) continue\n return migrationExecutable\n }\n }\n\n async runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext) {\n const next = await this.getNextMigration(migrationsList)\n if (!next) return\n\n logger.info('[orionjs/migrations] Running migration...', {name: next.name})\n\n if (next.useMongoTransactions) {\n await this.runAsTransaction(next.runMigration, context)\n } else {\n await this.runMigration(next.runMigration, context)\n }\n\n logger.info('[orionjs/migrations] Migration executed correctly', {name: next.name})\n\n await this.migrationsRepo.saveCompletedMigration(next.name)\n\n await this.runMigrations(migrationsList, context)\n }\n\n async runMigration(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext\n ) {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration', error)\n throw error\n }\n }\n\n async runAsTransaction(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext\n ) {\n const {client} = this.migrationsRepo.collection.client\n const session = client.startSession()\n\n await session.withTransaction(async () => {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration, will abort transaction', error)\n throw error\n }\n })\n\n session.endSession()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAAgC;AAKzB,IAAM,kBAAN,MAAsB;AAAA,EAE3B;AAAA,EAGA;AAAA,EAGA;AACF;AAPE;AAAA,MADC,yBAAK,EAAC,MAAM,SAAQ,CAAC;AAAA,GADX,gBAEX;AAGA;AAAA,MADC,yBAAK;AAAA,GAJK,gBAKX;AAGA;AAAA,MADC,yBAAK;AAAA,GAPK,gBAQX;AARW,kBAAN;AAAA,MADN,gCAAY;AAAA,GACA;;;ACLb,qBAAwE;AAExE,sBAAwB;AAGjB,IAAM,iBAAN,MAAqB;AAAA,EACnB,iBAAa,iCAAkC;AAAA,IAClD,MAAM;AAA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AAAA,IACnB,MAAM;AAAA,MACJ,0BAAsB,uBAAU;AAAA,QAC9B,MAAM;AAAA,QACN,UAAU,KAAK;AAAA,QACf,MAAM,QAAQ,QAAQ,SAAS;AAC7B,gBAAM,eAAW,8BAAY,iBAAiB;AAC9C,gBAAM,SAAS,cAAc,YAAY,OAAO;AAAA,QAClD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":["import_services","import_services","import_services"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/Schema.ts","../src/Repo.ts","../src/loadMigrations/index.ts","../src/service/index.ts","../src/MigrationsService.ts"],"sourcesContent":["export * from './Schema'\nexport * from './Repo'\nexport * from './loadMigrations'\nexport * from './service'\nexport * from './MigrationsService'\n","import {TypedSchema, Prop} from '@orion-js/typed-model'\n\nexport type MigrationId = `scnmg-${string}`\n\n@TypedSchema()\nexport class MigrationSchema {\n @Prop({type: 'string'})\n _id: MigrationId\n\n @Prop({type: String})\n name: string\n\n @Prop({type: Date})\n completedAt: Date\n}\n","import {createCollection} from '@orion-js/mongodb'\nimport {MigrationSchema} from './Schema'\nimport {Service} from '@orion-js/services'\n\n@Service()\nexport class MigrationsRepo {\n public collection = createCollection<MigrationSchema>({\n name: 'orionjs.migrations',\n schema: MigrationSchema,\n idPrefix: 'scnmg-',\n indexes: [],\n })\n\n async getCompletedMigrationNames() {\n const migrations = await this.collection.find().toArray()\n return migrations.map(m => m.name)\n }\n\n async saveCompletedMigration(name: string) {\n await this.collection.insertOne({name, completedAt: new Date()})\n }\n}\n","import {defineJob, startWorkers} from '@orion-js/dogs'\nimport {getMigrationsFromServices} from '../service'\nimport {getInstance} from '@orion-js/services'\nimport {MigrationsService} from '../MigrationsService'\n\nexport interface Options {\n lockTime?: number\n omitJob?: boolean\n}\n\nexport function loadMigrations(migrationServices: any[], options?: Options) {\n const migrations = getMigrationsFromServices(migrationServices)\n if (options?.omitJob) return migrations\n\n startWorkers({\n cooldownPeriod: 1000,\n lockTime: 1000 * 60 * 20, // 20 min\n workersCount: 1,\n pollInterval: 10 * 1000,\n jobs: {\n orionjsRunMigrations: defineJob({\n type: 'recurrent',\n runEvery: 30 * 1000,\n async resolve(_params, context) {\n const instance = getInstance(MigrationsService)\n await instance.runMigrations(migrations, context)\n },\n }),\n },\n })\n\n return migrations\n}\n","import {ExecutionContext} from '@orion-js/dogs'\nimport {getInstance} from '@orion-js/services'\nimport {Service} from '@orion-js/services'\n\nexport interface MigrationServiceOptions {\n name: string\n useMongoTransactions: false\n}\n\n// Define metadata storage using WeakMaps\nconst serviceMetadata = new WeakMap<any, {_serviceType: string; options: MigrationServiceOptions}>()\n\nexport function MigrationService(options: MigrationServiceOptions) {\n return function (target: any, context: ClassDecoratorContext<any>) {\n Service()(target, context)\n\n context.addInitializer(function (this) {\n serviceMetadata.set(this, {_serviceType: 'migrations', options: options})\n })\n }\n}\n\nexport type MigrationExecutable = {\n runMigration(context: ExecutionContext): Promise<void>\n} & MigrationServiceOptions\n\nexport function getMigrationsFromServices(services: any[]): MigrationExecutable[] {\n return services.map(service => {\n const instance = getInstance(service)\n const options = serviceMetadata.get(instance.constructor)\n if (!options._serviceType || options._serviceType !== 'migrations') {\n throw new Error(`Service ${service.name} is not a migration service`)\n }\n\n return {\n ...options.options,\n runMigration: async (context: ExecutionContext) => {\n const instance = getInstance(service) as any\n return await instance.runMigration(context)\n },\n }\n })\n}\n","import {Inject, Service} from '@orion-js/services'\nimport type {MigrationsRepo as MigrationsRepoType} from './Repo'\nimport {MigrationsRepo} from './Repo'\nimport {logger} from '@orion-js/logger'\nimport {MigrationExecutable} from './service'\nimport {ExecutionContext} from '@orion-js/dogs'\n\n@Service()\nexport class MigrationsService {\n @Inject(() => MigrationsRepo)\n private migrationsRepo: MigrationsRepoType\n\n async getNextMigration(migrationsList: MigrationExecutable[]) {\n const completedNames = await this.migrationsRepo.getCompletedMigrationNames()\n\n for (const migrationExecutable of migrationsList) {\n if (completedNames.includes(migrationExecutable.name)) continue\n return migrationExecutable\n }\n }\n\n async runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext) {\n const next = await this.getNextMigration(migrationsList)\n if (!next) return\n\n logger.info('[orionjs/migrations] Running migration...', {name: next.name})\n\n if (next.useMongoTransactions) {\n await this.runAsTransaction(next.runMigration, context)\n } else {\n await this.runMigration(next.runMigration, context)\n }\n\n logger.info('[orionjs/migrations] Migration executed correctly', {name: next.name})\n\n await this.migrationsRepo.saveCompletedMigration(next.name)\n\n await this.runMigrations(migrationsList, context)\n }\n\n async runMigration(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext,\n ) {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration', error)\n throw error\n }\n }\n\n async runAsTransaction(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext,\n ) {\n const {client} = this.migrationsRepo.collection.client\n const session = client.startSession()\n\n await session.withTransaction(async () => {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration, will abort transaction', error)\n throw error\n }\n })\n\n session.endSession()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAAgC;AAAhC;AAIA,mCAAC,gCAAY,IAEX,gBAAC,yBAAK,EAAC,MAAM,SAAQ,CAAC,IAGtB,iBAAC,yBAAK,EAAC,MAAM,OAAM,CAAC,IAGpB,wBAAC,yBAAK,EAAC,MAAM,KAAI,CAAC;AAPb,IAAM,kBAAN,MAAsB;AAAA,EAAtB;AAEL;AAGA;AAGA;AAAA;AACF;AATO;AAEL,mCADA,UADW;AAKX,oCADA,WAJW;AAQX,2CADA,kBAPW;AAAA,kBAAN,+CADP,6BACa;AAAN,4BAAM;;;ACLb,qBAA+B;AAE/B,sBAAsB;AAFtB,gCAAAA;AAIA,kCAAC,yBAAQ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O;AAAA,MACpB,SAAS,OAAO;AACd,6BAAO,MAAM,wEAAwE,KAAK;AAC1F,cAAM;AAAA,MACR;AAAA,IACF,CAAC;AAED,YAAQ,WAAW;AAAA,EACrB;AACF;AA9DOA,SAAA;AAEL,kBAAAA,QAAA,GAAQ,kBADR,qBADW;AAAA,oBAAN,kBAAAA,QAAA,wBADP,+BACa;AAAN,kBAAAA,QAAA,GAAM;;;AFEN,SAAS,eAAe,mBAA0B,SAAmB;AAC1E,QAAM,aAAa,0BAA0B,iBAAiB;AAC9D,MAAI,mCAAS,QAAS,QAAO;AAE7B,gCAAa;AAAA,IACX,gBAAgB;AAAA,IAChB,UAAU,MAAO,KAAK;AAAA;AAAA,IACtB,cAAc;AAAA,IACd,cAAc,KAAK;AAAA,IACnB,MAAM;AAAA,MACJ,0BAAsB,uBAAU;AAAA,QAC9B,MAAM;AAAA,QACN,UAAU,KAAK;AAAA,QACf,MAAM,QAAQ,SAAS,SAAS;AAC9B,gBAAM,eAAW,8BAAY,iBAAiB;AAC9C,gBAAM,SAAS,cAAc,YAAY,OAAO;AAAA,QAClD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":["_init","import_services","instance","import_services","import_services","_init"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Collection } from '@orion-js/mongodb';
1
+ import * as _orion_js_mongodb from '@orion-js/mongodb';
2
2
  import { ExecutionContext } from '@orion-js/dogs';
3
3
 
4
4
  type MigrationId = `scnmg-${string}`;
@@ -9,7 +9,7 @@ declare class MigrationSchema {
9
9
  }
10
10
 
11
11
  declare class MigrationsRepo {
12
- collection: Collection<MigrationSchema>;
12
+ collection: _orion_js_mongodb.Collection<_orion_js_mongodb.DocumentWithId<MigrationSchema>>;
13
13
  getCompletedMigrationNames(): Promise<string[]>;
14
14
  saveCompletedMigration(name: string): Promise<void>;
15
15
  }
@@ -24,7 +24,7 @@ interface MigrationServiceOptions {
24
24
  name: string;
25
25
  useMongoTransactions: false;
26
26
  }
27
- declare function MigrationService(options: MigrationServiceOptions): ClassDecorator;
27
+ declare function MigrationService(options: MigrationServiceOptions): (target: any, context: ClassDecoratorContext<any>) => void;
28
28
  type MigrationExecutable = {
29
29
  runMigration(context: ExecutionContext): Promise<void>;
30
30
  } & MigrationServiceOptions;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Collection } from '@orion-js/mongodb';
1
+ import * as _orion_js_mongodb from '@orion-js/mongodb';
2
2
  import { ExecutionContext } from '@orion-js/dogs';
3
3
 
4
4
  type MigrationId = `scnmg-${string}`;
@@ -9,7 +9,7 @@ declare class MigrationSchema {
9
9
  }
10
10
 
11
11
  declare class MigrationsRepo {
12
- collection: Collection<MigrationSchema>;
12
+ collection: _orion_js_mongodb.Collection<_orion_js_mongodb.DocumentWithId<MigrationSchema>>;
13
13
  getCompletedMigrationNames(): Promise<string[]>;
14
14
  saveCompletedMigration(name: string): Promise<void>;
15
15
  }
@@ -24,7 +24,7 @@ interface MigrationServiceOptions {
24
24
  name: string;
25
25
  useMongoTransactions: false;
26
26
  }
27
- declare function MigrationService(options: MigrationServiceOptions): ClassDecorator;
27
+ declare function MigrationService(options: MigrationServiceOptions): (target: any, context: ClassDecoratorContext<any>) => void;
28
28
  type MigrationExecutable = {
29
29
  runMigration(context: ExecutionContext): Promise<void>;
30
30
  } & MigrationServiceOptions;
package/dist/index.js CHANGED
@@ -1,37 +1,75 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result) __defProp(target, key, result);
9
- return result;
4
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
10
7
  };
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
11
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
12
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
13
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
14
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
15
+ var __runInitializers = (array, flags, self, value) => {
16
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
17
+ return value;
18
+ };
19
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
20
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
21
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
22
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
23
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
24
+ return __privateGet(this, extra);
25
+ }, set [name](x) {
26
+ return __privateSet(this, extra, x);
27
+ } }, name));
28
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
29
+ for (var i = decorators.length - 1; i >= 0; i--) {
30
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
31
+ if (k) {
32
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
33
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
34
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
35
+ }
36
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
37
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
38
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
39
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
40
+ }
41
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
42
+ };
43
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
44
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
45
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
46
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
47
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
48
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
11
49
 
12
50
  // src/Schema.ts
13
51
  import { TypedSchema, Prop } from "@orion-js/typed-model";
52
+ var _completedAt_dec, _name_dec, __id_dec, _MigrationSchema_decorators, _init;
53
+ _MigrationSchema_decorators = [TypedSchema()], __id_dec = [Prop({ type: "string" })], _name_dec = [Prop({ type: String })], _completedAt_dec = [Prop({ type: Date })];
14
54
  var MigrationSchema = class {
15
- _id;
16
- name;
17
- completedAt;
55
+ constructor() {
56
+ __publicField(this, "_id", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
57
+ __publicField(this, "name", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
58
+ __publicField(this, "completedAt", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
59
+ }
18
60
  };
19
- __decorateClass([
20
- Prop({ type: "string" })
21
- ], MigrationSchema.prototype, "_id", 2);
22
- __decorateClass([
23
- Prop()
24
- ], MigrationSchema.prototype, "name", 2);
25
- __decorateClass([
26
- Prop()
27
- ], MigrationSchema.prototype, "completedAt", 2);
28
- MigrationSchema = __decorateClass([
29
- TypedSchema()
30
- ], MigrationSchema);
61
+ _init = __decoratorStart(null);
62
+ __decorateElement(_init, 5, "_id", __id_dec, MigrationSchema);
63
+ __decorateElement(_init, 5, "name", _name_dec, MigrationSchema);
64
+ __decorateElement(_init, 5, "completedAt", _completedAt_dec, MigrationSchema);
65
+ MigrationSchema = __decorateElement(_init, 0, "MigrationSchema", _MigrationSchema_decorators, MigrationSchema);
66
+ __runInitializers(_init, 1, MigrationSchema);
31
67
 
32
68
  // src/Repo.ts
33
69
  import { createCollection } from "@orion-js/mongodb";
34
70
  import { Service } from "@orion-js/services";
71
+ var _MigrationsRepo_decorators, _init2;
72
+ _MigrationsRepo_decorators = [Service()];
35
73
  var MigrationsRepo = class {
36
74
  collection = createCollection({
37
75
  name: "orionjs.migrations",
@@ -47,9 +85,9 @@ var MigrationsRepo = class {
47
85
  await this.collection.insertOne({ name, completedAt: /* @__PURE__ */ new Date() });
48
86
  }
49
87
  };
50
- MigrationsRepo = __decorateClass([
51
- Service()
52
- ], MigrationsRepo);
88
+ _init2 = __decoratorStart(null);
89
+ MigrationsRepo = __decorateElement(_init2, 0, "MigrationsRepo", _MigrationsRepo_decorators, MigrationsRepo);
90
+ __runInitializers(_init2, 1, MigrationsRepo);
53
91
 
54
92
  // src/loadMigrations/index.ts
55
93
  import { defineJob, startWorkers } from "@orion-js/dogs";
@@ -57,22 +95,27 @@ import { defineJob, startWorkers } from "@orion-js/dogs";
57
95
  // src/service/index.ts
58
96
  import { getInstance } from "@orion-js/services";
59
97
  import { Service as Service2 } from "@orion-js/services";
98
+ var serviceMetadata = /* @__PURE__ */ new WeakMap();
60
99
  function MigrationService(options) {
61
- return function(target) {
62
- Service2()(target);
63
- target.prototype.service = target;
64
- target.prototype.options = options;
65
- target.prototype.serviceType = "migration";
100
+ return function(target, context) {
101
+ Service2()(target, context);
102
+ context.addInitializer(function() {
103
+ serviceMetadata.set(this, { _serviceType: "migrations", options });
104
+ });
66
105
  };
67
106
  }
68
107
  function getMigrationsFromServices(services) {
69
- return services.filter((service) => service.prototype.serviceType === "migration").map((service) => {
70
- const options = service.prototype.options;
108
+ return services.map((service) => {
109
+ const instance = getInstance(service);
110
+ const options = serviceMetadata.get(instance.constructor);
111
+ if (!options._serviceType || options._serviceType !== "migrations") {
112
+ throw new Error(`Service ${service.name} is not a migration service`);
113
+ }
71
114
  return {
72
- ...options,
115
+ ...options.options,
73
116
  runMigration: async (context) => {
74
- const instance = getInstance(service);
75
- return await instance.runMigration(context);
117
+ const instance2 = getInstance(service);
118
+ return await instance2.runMigration(context);
76
119
  }
77
120
  };
78
121
  });
@@ -84,8 +127,12 @@ import { getInstance as getInstance2 } from "@orion-js/services";
84
127
  // src/MigrationsService.ts
85
128
  import { Inject, Service as Service3 } from "@orion-js/services";
86
129
  import { logger } from "@orion-js/logger";
130
+ var _migrationsRepo_dec, _MigrationsService_decorators, _init3;
131
+ _MigrationsService_decorators = [Service3()], _migrationsRepo_dec = [Inject(() => MigrationsRepo)];
87
132
  var MigrationsService = class {
88
- migrationsRepo;
133
+ constructor() {
134
+ __publicField(this, "migrationsRepo", __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
135
+ }
89
136
  async getNextMigration(migrationsList) {
90
137
  const completedNames = await this.migrationsRepo.getCompletedMigrationNames();
91
138
  for (const migrationExecutable of migrationsList) {
@@ -128,12 +175,10 @@ var MigrationsService = class {
128
175
  session.endSession();
129
176
  }
130
177
  };
131
- __decorateClass([
132
- Inject(() => MigrationsRepo)
133
- ], MigrationsService.prototype, "migrationsRepo", 2);
134
- MigrationsService = __decorateClass([
135
- Service3()
136
- ], MigrationsService);
178
+ _init3 = __decoratorStart(null);
179
+ __decorateElement(_init3, 5, "migrationsRepo", _migrationsRepo_dec, MigrationsService);
180
+ MigrationsService = __decorateElement(_init3, 0, "MigrationsService", _MigrationsService_decorators, MigrationsService);
181
+ __runInitializers(_init3, 1, MigrationsService);
137
182
 
138
183
  // src/loadMigrations/index.ts
139
184
  function loadMigrations(migrationServices, options) {
@@ -149,7 +194,7 @@ function loadMigrations(migrationServices, options) {
149
194
  orionjsRunMigrations: defineJob({
150
195
  type: "recurrent",
151
196
  runEvery: 30 * 1e3,
152
- async resolve(params, context) {
197
+ async resolve(_params, context) {
153
198
  const instance = getInstance2(MigrationsService);
154
199
  await instance.runMigrations(migrations, context);
155
200
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Schema.ts","../src/Repo.ts","../src/loadMigrations/index.ts","../src/service/index.ts","../src/MigrationsService.ts"],"sourcesContent":["import {TypedSchema, Prop} from '@orion-js/typed-model'\n\nexport type MigrationId = `scnmg-${string}`\n\n@TypedSchema()\nexport class MigrationSchema {\n @Prop({type: 'string'})\n _id: MigrationId\n\n @Prop()\n name: string\n\n @Prop()\n completedAt: Date\n}\n","import {MongoCollection, Repository, Collection, createCollection} from '@orion-js/mongodb'\nimport {MigrationSchema} from './Schema'\nimport { Service } from '@orion-js/services'\n\n@Service()\nexport class MigrationsRepo {\n public collection = createCollection<MigrationSchema>({\n name: 'orionjs.migrations',\n schema: MigrationSchema,\n idPrefix: 'scnmg-',\n indexes: []\n })\n\n async getCompletedMigrationNames() {\n const migrations = await this.collection.find().toArray()\n return migrations.map(m => m.name)\n }\n\n async saveCompletedMigration(name: string) {\n await this.collection.insertOne({name, completedAt: new Date()})\n }\n}\n","import {defineJob, startWorkers} from '@orion-js/dogs'\nimport {getMigrationsFromServices} from '../service'\nimport {getInstance} from '@orion-js/services'\nimport {MigrationsService} from '../MigrationsService'\n\nexport interface Options {\n lockTime?: number\n omitJob?: boolean\n}\n\nexport function loadMigrations(migrationServices: any[], options?: Options) {\n const migrations = getMigrationsFromServices(migrationServices)\n if (options?.omitJob) return migrations\n\n startWorkers({\n cooldownPeriod: 1000,\n lockTime: 1000 * 60 * 20, // 20 min\n workersCount: 1,\n pollInterval: 10 * 1000,\n jobs: {\n orionjsRunMigrations: defineJob({\n type: 'recurrent',\n runEvery: 30 * 1000,\n async resolve(params, context) {\n const instance = getInstance(MigrationsService)\n await instance.runMigrations(migrations, context)\n }\n })\n }\n })\n\n return migrations\n}\n","import {ExecutionContext} from '@orion-js/dogs'\nimport {getInstance} from '@orion-js/services'\nimport {Service} from '@orion-js/services'\n\nexport interface MigrationServiceOptions {\n name: string\n useMongoTransactions: false\n}\n\nexport function MigrationService(options: MigrationServiceOptions): ClassDecorator {\n return function (target: any) {\n Service()(target)\n target.prototype.service = target\n target.prototype.options = options\n target.prototype.serviceType = 'migration'\n }\n}\n\nexport type MigrationExecutable = {\n runMigration(context: ExecutionContext): Promise<void>\n} & MigrationServiceOptions\n\nexport function getMigrationsFromServices(services: any[]): MigrationExecutable[] {\n return services\n .filter(service => service.prototype.serviceType === 'migration')\n .map(service => {\n const options = service.prototype.options\n return {\n ...options,\n runMigration: async (context: ExecutionContext) => {\n const instance = getInstance(service) as any\n return await instance.runMigration(context)\n }\n }\n })\n}\n","import {Inject, Service} from '@orion-js/services'\nimport type {MigrationsRepo as MigrationsRepoType} from './Repo'\nimport {MigrationsRepo} from './Repo'\nimport {logger} from '@orion-js/logger'\nimport {MigrationExecutable} from './service'\nimport {ExecutionContext} from '@orion-js/dogs'\n\n@Service()\nexport class MigrationsService {\n @Inject(() => MigrationsRepo)\n private migrationsRepo: MigrationsRepoType\n\n async getNextMigration(migrationsList: MigrationExecutable[]) {\n const completedNames = await this.migrationsRepo.getCompletedMigrationNames()\n\n for (const migrationExecutable of migrationsList) {\n if (completedNames.includes(migrationExecutable.name)) continue\n return migrationExecutable\n }\n }\n\n async runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext) {\n const next = await this.getNextMigration(migrationsList)\n if (!next) return\n\n logger.info('[orionjs/migrations] Running migration...', {name: next.name})\n\n if (next.useMongoTransactions) {\n await this.runAsTransaction(next.runMigration, context)\n } else {\n await this.runMigration(next.runMigration, context)\n }\n\n logger.info('[orionjs/migrations] Migration executed correctly', {name: next.name})\n\n await this.migrationsRepo.saveCompletedMigration(next.name)\n\n await this.runMigrations(migrationsList, context)\n }\n\n async runMigration(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext\n ) {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration', error)\n throw error\n }\n }\n\n async runAsTransaction(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext\n ) {\n const {client} = this.migrationsRepo.collection.client\n const session = client.startSession()\n\n await session.withTransaction(async () => {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration, will abort transaction', error)\n throw error\n }\n })\n\n session.endSession()\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAQ,aAAa,YAAW;AAKzB,IAAM,kBAAN,MAAsB;AAAA,EAE3B;AAAA,EAGA;AAAA,EAGA;AACF;AAPE;AAAA,EADC,KAAK,EAAC,MAAM,SAAQ,CAAC;AAAA,GADX,gBAEX;AAGA;AAAA,EADC,KAAK;AAAA,GAJK,gBAKX;AAGA;AAAA,EADC,KAAK;AAAA,GAPK,gBAQX;AARW,kBAAN;AAAA,EADN,YAAY;AAAA,GACA;;;ACLb,SAAiD,wBAAuB;AAExE,SAAS,eAAe;AAGjB,IAAM,iBAAN,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AAAA,IACX,gBAAgB;AAAA,IAChB,UAAU,MAAO,KAAK;AAAA;AAAA,IACtB,cAAc;AAAA,IACd,cAAc,KAAK;AAAA,IACnB,MAAM;AAAA,MACJ,sBAAsB,UAAU;AAAA,QAC9B,MAAM;AAAA,QACN,UAAU,KAAK;AAAA,QACf,MAAM,QAAQ,QAAQ,SAAS;AAC7B,gBAAM,WAAWC,aAAY,iBAAiB;AAC9C,gBAAM,SAAS,cAAc,YAAY,OAAO;AAAA,QAClD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":["Service","getInstance","Service","Service","getInstance"]}
1
+ {"version":3,"sources":["../src/Schema.ts","../src/Repo.ts","../src/loadMigrations/index.ts","../src/service/index.ts","../src/MigrationsService.ts"],"sourcesContent":["import {TypedSchema, Prop} from '@orion-js/typed-model'\n\nexport type MigrationId = `scnmg-${string}`\n\n@TypedSchema()\nexport class MigrationSchema {\n @Prop({type: 'string'})\n _id: MigrationId\n\n @Prop({type: String})\n name: string\n\n @Prop({type: Date})\n completedAt: Date\n}\n","import {createCollection} from '@orion-js/mongodb'\nimport {MigrationSchema} from './Schema'\nimport {Service} from '@orion-js/services'\n\n@Service()\nexport class MigrationsRepo {\n public collection = createCollection<MigrationSchema>({\n name: 'orionjs.migrations',\n schema: MigrationSchema,\n idPrefix: 'scnmg-',\n indexes: [],\n })\n\n async getCompletedMigrationNames() {\n const migrations = await this.collection.find().toArray()\n return migrations.map(m => m.name)\n }\n\n async saveCompletedMigration(name: string) {\n await this.collection.insertOne({name, completedAt: new Date()})\n }\n}\n","import {defineJob, startWorkers} from '@orion-js/dogs'\nimport {getMigrationsFromServices} from '../service'\nimport {getInstance} from '@orion-js/services'\nimport {MigrationsService} from '../MigrationsService'\n\nexport interface Options {\n lockTime?: number\n omitJob?: boolean\n}\n\nexport function loadMigrations(migrationServices: any[], options?: Options) {\n const migrations = getMigrationsFromServices(migrationServices)\n if (options?.omitJob) return migrations\n\n startWorkers({\n cooldownPeriod: 1000,\n lockTime: 1000 * 60 * 20, // 20 min\n workersCount: 1,\n pollInterval: 10 * 1000,\n jobs: {\n orionjsRunMigrations: defineJob({\n type: 'recurrent',\n runEvery: 30 * 1000,\n async resolve(_params, context) {\n const instance = getInstance(MigrationsService)\n await instance.runMigrations(migrations, context)\n },\n }),\n },\n })\n\n return migrations\n}\n","import {ExecutionContext} from '@orion-js/dogs'\nimport {getInstance} from '@orion-js/services'\nimport {Service} from '@orion-js/services'\n\nexport interface MigrationServiceOptions {\n name: string\n useMongoTransactions: false\n}\n\n// Define metadata storage using WeakMaps\nconst serviceMetadata = new WeakMap<any, {_serviceType: string; options: MigrationServiceOptions}>()\n\nexport function MigrationService(options: MigrationServiceOptions) {\n return function (target: any, context: ClassDecoratorContext<any>) {\n Service()(target, context)\n\n context.addInitializer(function (this) {\n serviceMetadata.set(this, {_serviceType: 'migrations', options: options})\n })\n }\n}\n\nexport type MigrationExecutable = {\n runMigration(context: ExecutionContext): Promise<void>\n} & MigrationServiceOptions\n\nexport function getMigrationsFromServices(services: any[]): MigrationExecutable[] {\n return services.map(service => {\n const instance = getInstance(service)\n const options = serviceMetadata.get(instance.constructor)\n if (!options._serviceType || options._serviceType !== 'migrations') {\n throw new Error(`Service ${service.name} is not a migration service`)\n }\n\n return {\n ...options.options,\n runMigration: async (context: ExecutionContext) => {\n const instance = getInstance(service) as any\n return await instance.runMigration(context)\n },\n }\n })\n}\n","import {Inject, Service} from '@orion-js/services'\nimport type {MigrationsRepo as MigrationsRepoType} from './Repo'\nimport {MigrationsRepo} from './Repo'\nimport {logger} from '@orion-js/logger'\nimport {MigrationExecutable} from './service'\nimport {ExecutionContext} from '@orion-js/dogs'\n\n@Service()\nexport class MigrationsService {\n @Inject(() => MigrationsRepo)\n private migrationsRepo: MigrationsRepoType\n\n async getNextMigration(migrationsList: MigrationExecutable[]) {\n const completedNames = await this.migrationsRepo.getCompletedMigrationNames()\n\n for (const migrationExecutable of migrationsList) {\n if (completedNames.includes(migrationExecutable.name)) continue\n return migrationExecutable\n }\n }\n\n async runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext) {\n const next = await this.getNextMigration(migrationsList)\n if (!next) return\n\n logger.info('[orionjs/migrations] Running migration...', {name: next.name})\n\n if (next.useMongoTransactions) {\n await this.runAsTransaction(next.runMigration, context)\n } else {\n await this.runMigration(next.runMigration, context)\n }\n\n logger.info('[orionjs/migrations] Migration executed correctly', {name: next.name})\n\n await this.migrationsRepo.saveCompletedMigration(next.name)\n\n await this.runMigrations(migrationsList, context)\n }\n\n async runMigration(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext,\n ) {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration', error)\n throw error\n }\n }\n\n async runAsTransaction(\n func: (context: ExecutionContext) => Promise<void>,\n context: ExecutionContext,\n ) {\n const {client} = this.migrationsRepo.collection.client\n const session = client.startSession()\n\n await session.withTransaction(async () => {\n try {\n await func(context)\n } catch (error) {\n logger.error('[orionjs/migrations] Error running migration, will abort transaction', error)\n throw error\n }\n })\n\n session.endSession()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAQ,aAAa,YAAW;AAAhC;AAIA,+BAAC,YAAY,IAEX,YAAC,KAAK,EAAC,MAAM,SAAQ,CAAC,IAGtB,aAAC,KAAK,EAAC,MAAM,OAAM,CAAC,IAGpB,oBAAC,KAAK,EAAC,MAAM,KAAI,CAAC;AAPb,IAAM,kBAAN,MAAsB;AAAA,EAAtB;AAEL;AAGA;AAGA;AAAA;AACF;AATO;AAEL,mCADA,UADW;AAKX,oCADA,WAJW;AAQX,2CADA,kBAPW;AAAA,kBAAN,+CADP,6BACa;AAAN,4BAAM;;;ACLb,SAAQ,wBAAuB;AAE/B,SAAQ,eAAc;AAFtB,gCAAAA;AAIA,8BAAC,QAAQ;AACF,IAAM,iBAAN,MAAqB;AAAA,EACnB,aAA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AAA,MACpB,SAAS,OAAO;AACd,eAAO,MAAM,wEAAwE,KAAK;AAC1F,cAAM;AAAA,MACR;AAAA,IACF,CAAC;AAED,YAAQ,WAAW;AAAA,EACrB;AACF;AA9DOA,SAAA;AAEL,kBAAAA,QAAA,GAAQ,kBADR,qBADW;AAAA,oBAAN,kBAAAA,QAAA,wBADP,+BACa;AAAN,kBAAAA,QAAA,GAAM;;;AFEN,SAAS,eAAe,mBAA0B,SAAmB;AAC1E,QAAM,aAAa,0BAA0B,iBAAiB;AAC9D,MAAI,mCAAS,QAAS,QAAO;AAE7B,eAAa;AAAA,IACX,gBAAgB;AAAA,IAChB,UAAU,MAAO,KAAK;AAAA;AAAA,IACtB,cAAc;AAAA,IACd,cAAc,KAAK;AAAA,IACnB,MAAM;AAAA,MACJ,sBAAsB,UAAU;AAAA,QAC9B,MAAM;AAAA,QACN,UAAU,KAAK;AAAA,QACf,MAAM,QAAQ,SAAS,SAAS;AAC9B,gBAAM,WAAWE,aAAY,iBAAiB;AAC9C,gBAAM,SAAS,cAAc,YAAY,OAAO;AAAA,QAClD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":["_init","Service","instance","getInstance","Service","_init","Service","getInstance"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/migrations",
3
- "version": "4.0.0-next.3",
3
+ "version": "4.0.0-next.5",
4
4
  "main": "./dist/index.cjs",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -9,16 +9,15 @@
9
9
  "author": "nicolaslopezj",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@orion-js/dogs": "4.0.0-next.3",
13
- "@orion-js/mongodb": "4.0.0-next.3",
14
- "@orion-js/services": "4.0.0-next.3",
15
- "@orion-js/logger": "4.0.0-next.3",
16
- "@orion-js/typed-model": "4.0.0-next.3",
17
- "@orion-js/helpers": "4.0.0-next.3"
12
+ "@orion-js/helpers": "4.0.0-next.5",
13
+ "@orion-js/typed-model": "4.0.0-next.5",
14
+ "@orion-js/dogs": "4.0.0-next.5",
15
+ "@orion-js/services": "4.0.0-next.5",
16
+ "@orion-js/mongodb": "4.0.0-next.5",
17
+ "@orion-js/logger": "4.0.0-next.5"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/lodash": "4.14.195",
21
- "reflect-metadata": "^0.1.13",
22
21
  "typescript": "^5.4.5",
23
22
  "@types/node": "^18.0.0",
24
23
  "tsup": "^8.0.1",