@stemy/backend 5.0.9 → 5.1.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.
- package/common-types.d.ts +3 -0
- package/esm2020/common-types.mjs +1 -1
- 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/asset.mjs +5 -1
- package/esm2020/services/entities/base-entity.mjs +3 -1
- package/esm2020/services/entities/lazy-asset.mjs +12 -1
- package/esm2020/services/entities/temp-asset.mjs +4 -1
- package/esm2020/services/fixtures.mjs +7 -5
- package/esm2020/services/lazy-assets.mjs +4 -2
- package/esm2020/utils.mjs +8 -2
- package/fesm2015/stemy-backend.mjs +65 -8
- package/fesm2015/stemy-backend.mjs.map +1 -1
- package/fesm2020/stemy-backend.mjs +59 -8
- 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/entities/asset.d.ts +1 -0
- package/services/entities/lazy-asset.d.ts +2 -0
- package/services/entities/temp-asset.d.ts +1 -0
- package/services/fixtures.d.ts +1 -1
- package/utils.d.ts +1 -1
|
@@ -624,8 +624,14 @@ function gunzipPromised(data, opts) {
|
|
|
624
624
|
});
|
|
625
625
|
});
|
|
626
626
|
}
|
|
627
|
-
function deleteFromBucket(bucket,
|
|
627
|
+
function deleteFromBucket(bucket, id) {
|
|
628
|
+
const fileId = id instanceof ObjectId ? id : new ObjectId(id);
|
|
628
629
|
return new Promise(((resolve, reject) => {
|
|
630
|
+
if (!id) {
|
|
631
|
+
// We don't care about empty id
|
|
632
|
+
resolve(null);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
629
635
|
bucket.delete(fileId, error => {
|
|
630
636
|
let err = error;
|
|
631
637
|
if (error) {
|
|
@@ -993,6 +999,8 @@ class BaseEntity {
|
|
|
993
999
|
const ret = Object.assign({}, this.data);
|
|
994
1000
|
delete ret._id;
|
|
995
1001
|
ret.id = this.id;
|
|
1002
|
+
ret.updatedAt = new Date();
|
|
1003
|
+
ret.createdAt = ret.createdAt || ret.updatedAt;
|
|
996
1004
|
return ret;
|
|
997
1005
|
}
|
|
998
1006
|
}
|
|
@@ -1019,6 +1027,12 @@ class Asset extends BaseEntity {
|
|
|
1019
1027
|
return deleteFromBucket(this.bucket, this.mId);
|
|
1020
1028
|
});
|
|
1021
1029
|
}
|
|
1030
|
+
setMeta(metadata) {
|
|
1031
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1032
|
+
metadata = Object.assign(this.metadata, metadata || {});
|
|
1033
|
+
yield this.collection.updateOne({ _id: this.mId }, { $set: { metadata } });
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1022
1036
|
getBuffer() {
|
|
1023
1037
|
return streamToBuffer(this.stream);
|
|
1024
1038
|
}
|
|
@@ -1062,6 +1076,11 @@ class TempAsset {
|
|
|
1062
1076
|
throw new Error(`Temp asset '${this.id}' can not be removed!`);
|
|
1063
1077
|
});
|
|
1064
1078
|
}
|
|
1079
|
+
setMeta(meta) {
|
|
1080
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1081
|
+
Object.assign(this.metadata, meta || {});
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1065
1084
|
getBuffer() {
|
|
1066
1085
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1067
1086
|
return this.buffer;
|
|
@@ -1269,6 +1288,12 @@ class LazyAsset extends BaseEntity {
|
|
|
1269
1288
|
get jobQue() {
|
|
1270
1289
|
return this.data.jobQue;
|
|
1271
1290
|
}
|
|
1291
|
+
get createdAt() {
|
|
1292
|
+
return this.data.createdAt;
|
|
1293
|
+
}
|
|
1294
|
+
get updatedAt() {
|
|
1295
|
+
return this.data.updatedAt;
|
|
1296
|
+
}
|
|
1272
1297
|
get progressId() {
|
|
1273
1298
|
return this.data.progressId;
|
|
1274
1299
|
}
|
|
@@ -1316,16 +1341,21 @@ class LazyAsset extends BaseEntity {
|
|
|
1316
1341
|
}
|
|
1317
1342
|
writeAsset(asset) {
|
|
1318
1343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1344
|
+
this.data.updatedAt = new Date();
|
|
1319
1345
|
this.data.assetId = asset.id;
|
|
1346
|
+
yield asset.setMeta({ lazyId: this.id });
|
|
1320
1347
|
yield this.save();
|
|
1321
1348
|
return asset;
|
|
1322
1349
|
});
|
|
1323
1350
|
}
|
|
1324
1351
|
startWorkingOnAsset(fromLoad) {
|
|
1325
1352
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1353
|
+
const oldAsset = this.data.assetId;
|
|
1354
|
+
this.data.updatedAt = new Date();
|
|
1326
1355
|
this.data.progressId = (yield this.progresses.create()).id;
|
|
1327
1356
|
this.data.assetId = null;
|
|
1328
1357
|
yield this.save();
|
|
1358
|
+
yield deleteFromBucket(this.assets.bucket, oldAsset);
|
|
1329
1359
|
const jobParams = JSON.parse(yield gunzipPromised(this.data.jobParams));
|
|
1330
1360
|
yield this.progresses.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, jobParams), { lazyId: this.id, fromLoad }));
|
|
1331
1361
|
});
|
|
@@ -1847,11 +1877,13 @@ let LazyAssets = class LazyAssets {
|
|
|
1847
1877
|
const data = {
|
|
1848
1878
|
jobName,
|
|
1849
1879
|
jobParams,
|
|
1850
|
-
jobQue
|
|
1880
|
+
jobQue,
|
|
1851
1881
|
};
|
|
1852
1882
|
const existingAsset = yield this.find(data);
|
|
1853
1883
|
if (existingAsset)
|
|
1854
1884
|
return existingAsset;
|
|
1885
|
+
data.createdAt = new Date();
|
|
1886
|
+
data.updatedAt = data.createdAt;
|
|
1855
1887
|
const res = yield this.collection.insertOne(data);
|
|
1856
1888
|
return new LazyAsset(res.insertedId, data, this.collection, this.logger, this.assets, this.progresses);
|
|
1857
1889
|
});
|
|
@@ -2074,21 +2106,23 @@ let Fixtures = class Fixtures {
|
|
|
2074
2106
|
constructor(container) {
|
|
2075
2107
|
this.container = container;
|
|
2076
2108
|
}
|
|
2077
|
-
init() {
|
|
2109
|
+
init(output) {
|
|
2078
2110
|
try {
|
|
2079
2111
|
return this.container.resolveAll(FIXTURE);
|
|
2080
2112
|
}
|
|
2081
2113
|
catch (e) {
|
|
2114
|
+
output.writeln(e.message);
|
|
2082
2115
|
return [];
|
|
2083
2116
|
}
|
|
2084
2117
|
}
|
|
2085
2118
|
load(output) {
|
|
2086
2119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2087
|
-
this.fixtures = this.fixtures || this.init();
|
|
2088
2120
|
output = output || {
|
|
2089
2121
|
write: console.log,
|
|
2090
2122
|
writeln: t => console.log(t + "\n")
|
|
2091
2123
|
};
|
|
2124
|
+
this.fixtures = this.fixtures || this.init(output);
|
|
2125
|
+
output.write(`Loading fixtures: ${this.fixtures.length} items`);
|
|
2092
2126
|
for (let fixture of this.fixtures) {
|
|
2093
2127
|
yield fixture.load(output);
|
|
2094
2128
|
}
|
|
@@ -2098,7 +2132,7 @@ let Fixtures = class Fixtures {
|
|
|
2098
2132
|
Fixtures = __decorate([
|
|
2099
2133
|
injectable(),
|
|
2100
2134
|
scoped(Lifecycle.ContainerScoped),
|
|
2101
|
-
__param(0,
|
|
2135
|
+
__param(0, inject(DI_CONTAINER)),
|
|
2102
2136
|
__metadata("design:paramtypes", [Object])
|
|
2103
2137
|
], Fixtures);
|
|
2104
2138
|
|
|
@@ -4017,6 +4051,30 @@ const commands = [
|
|
|
4017
4051
|
FixturesCommand
|
|
4018
4052
|
];
|
|
4019
4053
|
|
|
4054
|
+
let TtlFixture = class TtlFixture {
|
|
4055
|
+
constructor(connector) {
|
|
4056
|
+
this.connector = connector;
|
|
4057
|
+
}
|
|
4058
|
+
load() {
|
|
4059
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4060
|
+
const db = this.connector.database;
|
|
4061
|
+
if (!db)
|
|
4062
|
+
return null;
|
|
4063
|
+
const expires = { expireAfterSeconds: 3600 * 24 };
|
|
4064
|
+
yield db.collection("progresses").createIndex({ updatedAt: 1 }, expires);
|
|
4065
|
+
yield db.collection("lazyassets").createIndex({ updatedAt: 1 }, expires);
|
|
4066
|
+
});
|
|
4067
|
+
}
|
|
4068
|
+
};
|
|
4069
|
+
TtlFixture = __decorate([
|
|
4070
|
+
injectable(),
|
|
4071
|
+
__metadata("design:paramtypes", [MongoConnector])
|
|
4072
|
+
], TtlFixture);
|
|
4073
|
+
|
|
4074
|
+
const fixtures = [
|
|
4075
|
+
TtlFixture,
|
|
4076
|
+
];
|
|
4077
|
+
|
|
4020
4078
|
class BaseDoc {
|
|
4021
4079
|
/**
|
|
4022
4080
|
* Casts this to DocumentType<this> to allow using document methods in get/set-s
|
|
@@ -4455,8 +4513,7 @@ function setupBackend(config, providers, parent) {
|
|
|
4455
4513
|
providers = Array.isArray(providers) ? providers : [];
|
|
4456
4514
|
parent = parent || createServices();
|
|
4457
4515
|
// Create fixtures
|
|
4458
|
-
const
|
|
4459
|
-
const fixtureProviders = fixtureTypes.map(fixture => {
|
|
4516
|
+
const fixtureProviders = fixtures.concat(config.fixtures || []).map(fixture => {
|
|
4460
4517
|
return {
|
|
4461
4518
|
provide: FIXTURE,
|
|
4462
4519
|
useClass: fixture
|
|
@@ -4517,7 +4574,7 @@ function setupBackend(config, providers, parent) {
|
|
|
4517
4574
|
});
|
|
4518
4575
|
});
|
|
4519
4576
|
// Add other providers
|
|
4520
|
-
allProviders.push(...
|
|
4577
|
+
allProviders.push(...fixtureProviders, ...paramProviders, ...jobProviders, ...commandProviders, ...restOptions.middlewares, ...restOptions.controllers, ...socketOptions.middlewares, ...socketOptions.controllers, ...providers, {
|
|
4521
4578
|
provide: EXPRESS,
|
|
4522
4579
|
useFactory: (container) => {
|
|
4523
4580
|
return container.resolve(BackendProvider).express;
|