@stemy/backend 5.0.9 → 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.
- package/esm2020/fixtures/index.mjs +5 -0
- package/esm2020/fixtures/ttl.fixture.mjs +22 -0
- package/esm2020/public_api.mjs +4 -4
- package/esm2020/services/entities/base-entity.mjs +3 -1
- package/esm2020/services/fixtures.mjs +7 -5
- package/fesm2015/stemy-backend.mjs +33 -6
- package/fesm2015/stemy-backend.mjs.map +1 -1
- package/fesm2020/stemy-backend.mjs +31 -6
- package/fesm2020/stemy-backend.mjs.map +1 -1
- package/fixtures/index.d.ts +2 -0
- package/fixtures/ttl.fixture.d.ts +7 -0
- package/package.json +1 -1
- package/services/fixtures.d.ts +1 -1
|
@@ -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
|
}
|
|
@@ -1944,20 +1946,22 @@ let Fixtures = class Fixtures {
|
|
|
1944
1946
|
constructor(container) {
|
|
1945
1947
|
this.container = container;
|
|
1946
1948
|
}
|
|
1947
|
-
init() {
|
|
1949
|
+
init(output) {
|
|
1948
1950
|
try {
|
|
1949
1951
|
return this.container.resolveAll(FIXTURE);
|
|
1950
1952
|
}
|
|
1951
1953
|
catch (e) {
|
|
1954
|
+
output.writeln(e.message);
|
|
1952
1955
|
return [];
|
|
1953
1956
|
}
|
|
1954
1957
|
}
|
|
1955
1958
|
async load(output) {
|
|
1956
|
-
this.fixtures = this.fixtures || this.init();
|
|
1957
1959
|
output = output || {
|
|
1958
1960
|
write: console.log,
|
|
1959
1961
|
writeln: t => console.log(t + "\n")
|
|
1960
1962
|
};
|
|
1963
|
+
this.fixtures = this.fixtures || this.init(output);
|
|
1964
|
+
output.write(`Loading fixtures: ${this.fixtures.length} items`);
|
|
1961
1965
|
for (let fixture of this.fixtures) {
|
|
1962
1966
|
await fixture.load(output);
|
|
1963
1967
|
}
|
|
@@ -1966,7 +1970,7 @@ let Fixtures = class Fixtures {
|
|
|
1966
1970
|
Fixtures = __decorate([
|
|
1967
1971
|
injectable(),
|
|
1968
1972
|
scoped(Lifecycle.ContainerScoped),
|
|
1969
|
-
__param(0,
|
|
1973
|
+
__param(0, inject(DI_CONTAINER)),
|
|
1970
1974
|
__metadata("design:paramtypes", [Object])
|
|
1971
1975
|
], Fixtures);
|
|
1972
1976
|
|
|
@@ -3791,6 +3795,28 @@ const commands = [
|
|
|
3791
3795
|
FixturesCommand
|
|
3792
3796
|
];
|
|
3793
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
|
+
|
|
3794
3820
|
class BaseDoc {
|
|
3795
3821
|
/**
|
|
3796
3822
|
* Casts this to DocumentType<this> to allow using document methods in get/set-s
|
|
@@ -4222,8 +4248,7 @@ async function setupBackend(config, providers, parent) {
|
|
|
4222
4248
|
providers = Array.isArray(providers) ? providers : [];
|
|
4223
4249
|
parent = parent || createServices();
|
|
4224
4250
|
// Create fixtures
|
|
4225
|
-
const
|
|
4226
|
-
const fixtureProviders = fixtureTypes.map(fixture => {
|
|
4251
|
+
const fixtureProviders = fixtures.concat(config.fixtures || []).map(fixture => {
|
|
4227
4252
|
return {
|
|
4228
4253
|
provide: FIXTURE,
|
|
4229
4254
|
useClass: fixture
|
|
@@ -4291,7 +4316,7 @@ async function setupBackend(config, providers, parent) {
|
|
|
4291
4316
|
});
|
|
4292
4317
|
});
|
|
4293
4318
|
// Add other providers
|
|
4294
|
-
allProviders.push(...
|
|
4319
|
+
allProviders.push(...fixtureProviders, ...paramProviders, ...jobProviders, ...commandProviders, ...restOptions.middlewares, ...restOptions.controllers, ...socketOptions.middlewares, ...socketOptions.controllers, ...providers, {
|
|
4295
4320
|
provide: EXPRESS,
|
|
4296
4321
|
useFactory: (container) => {
|
|
4297
4322
|
return container.resolve(BackendProvider).express;
|