@stemy/backend 5.0.8 → 5.0.10

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.
@@ -973,6 +973,8 @@ class BaseEntity {
973
973
  const ret = Object.assign({}, this.data);
974
974
  delete ret._id;
975
975
  ret.id = this.id;
976
+ ret.updatedAt = new Date();
977
+ ret.createdAt = ret.createdAt || ret.updatedAt;
976
978
  return ret;
977
979
  }
978
980
  }
@@ -1941,16 +1943,25 @@ OpenApi = __decorate([
1941
1943
  ], OpenApi);
1942
1944
 
1943
1945
  let Fixtures = class Fixtures {
1944
- constructor(fixtures) {
1945
- this.fixtures = fixtures;
1946
+ constructor(container) {
1947
+ this.container = container;
1948
+ }
1949
+ init(output) {
1950
+ try {
1951
+ return this.container.resolveAll(FIXTURE);
1952
+ }
1953
+ catch (e) {
1954
+ output.writeln(e.message);
1955
+ return [];
1956
+ }
1946
1957
  }
1947
1958
  async load(output) {
1948
- if (!this.fixtures)
1949
- return;
1950
1959
  output = output || {
1951
1960
  write: console.log,
1952
1961
  writeln: t => console.log(t + "\n")
1953
1962
  };
1963
+ this.fixtures = this.fixtures || this.init(output);
1964
+ output.write(`Loading fixtures: ${this.fixtures.length} items`);
1954
1965
  for (let fixture of this.fixtures) {
1955
1966
  await fixture.load(output);
1956
1967
  }
@@ -1959,8 +1970,8 @@ let Fixtures = class Fixtures {
1959
1970
  Fixtures = __decorate([
1960
1971
  injectable(),
1961
1972
  scoped(Lifecycle.ContainerScoped),
1962
- __param(0, injectAll(FIXTURE)),
1963
- __metadata("design:paramtypes", [Array])
1973
+ __param(0, inject(DI_CONTAINER)),
1974
+ __metadata("design:paramtypes", [Object])
1964
1975
  ], Fixtures);
1965
1976
 
1966
1977
  const express = express_;
@@ -3784,6 +3795,28 @@ const commands = [
3784
3795
  FixturesCommand
3785
3796
  ];
3786
3797
 
3798
+ let TtlFixture = class TtlFixture {
3799
+ constructor(connector) {
3800
+ this.connector = connector;
3801
+ }
3802
+ async load() {
3803
+ const db = this.connector.database;
3804
+ if (!db)
3805
+ return null;
3806
+ const expires = { expireAfterSeconds: 3600 * 24 };
3807
+ await db.collection("progresses").createIndex({ updatedAt: 1 }, expires);
3808
+ await db.collection("lazyassets").createIndex({ updatedAt: 1 }, expires);
3809
+ }
3810
+ };
3811
+ TtlFixture = __decorate([
3812
+ injectable(),
3813
+ __metadata("design:paramtypes", [MongoConnector])
3814
+ ], TtlFixture);
3815
+
3816
+ const fixtures = [
3817
+ TtlFixture,
3818
+ ];
3819
+
3787
3820
  class BaseDoc {
3788
3821
  /**
3789
3822
  * Casts this to DocumentType<this> to allow using document methods in get/set-s
@@ -4215,8 +4248,7 @@ async function setupBackend(config, providers, parent) {
4215
4248
  providers = Array.isArray(providers) ? providers : [];
4216
4249
  parent = parent || createServices();
4217
4250
  // Create fixtures
4218
- const fixtureTypes = (config.fixtures || []);
4219
- const fixtureProviders = fixtureTypes.map(fixture => {
4251
+ const fixtureProviders = fixtures.concat(config.fixtures || []).map(fixture => {
4220
4252
  return {
4221
4253
  provide: FIXTURE,
4222
4254
  useClass: fixture
@@ -4284,7 +4316,7 @@ async function setupBackend(config, providers, parent) {
4284
4316
  });
4285
4317
  });
4286
4318
  // Add other providers
4287
- allProviders.push(...fixtureTypes, ...fixtureProviders, ...paramProviders, ...jobProviders, ...commandProviders, ...restOptions.middlewares, ...restOptions.controllers, ...socketOptions.middlewares, ...socketOptions.controllers, ...providers, {
4319
+ allProviders.push(...fixtureProviders, ...paramProviders, ...jobProviders, ...commandProviders, ...restOptions.middlewares, ...restOptions.controllers, ...socketOptions.middlewares, ...socketOptions.controllers, ...providers, {
4288
4320
  provide: EXPRESS,
4289
4321
  useFactory: (container) => {
4290
4322
  return container.resolve(BackendProvider).express;