@travetto/model-mongo 5.0.6 → 5.0.8

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 (2) hide show
  1. package/package.json +5 -5
  2. package/src/service.ts +12 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-mongo",
3
- "version": "5.0.6",
3
+ "version": "5.0.8",
4
4
  "description": "Mongo backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "mongo",
@@ -25,13 +25,13 @@
25
25
  "directory": "module/model-mongo"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/config": "^5.0.6",
29
- "@travetto/model": "^5.0.6",
30
- "@travetto/model-query": "^5.0.6",
28
+ "@travetto/config": "^5.0.7",
29
+ "@travetto/model": "^5.0.8",
30
+ "@travetto/model-query": "^5.0.8",
31
31
  "mongodb": "^6.9.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/command": "^5.0.6"
34
+ "@travetto/command": "^5.0.7"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/command": {
package/src/service.ts CHANGED
@@ -235,7 +235,7 @@ export class MongoModelService implements
235
235
 
236
236
  // Blob
237
237
  async upsertBlob(location: string, input: BinaryInput, meta?: BlobMeta, overwrite = true): Promise<void> {
238
- const existing = await this.describeBlob(location).then(() => true, () => false);
238
+ const existing = await this.getBlobMeta(location).then(() => true, () => false);
239
239
  if (!overwrite && existing) {
240
240
  return;
241
241
  }
@@ -253,14 +253,15 @@ export class MongoModelService implements
253
253
  }
254
254
 
255
255
  async getBlob(location: string, range?: ByteRange): Promise<Blob> {
256
- const meta = await this.describeBlob(location);
256
+ const meta = await this.getBlobMeta(location);
257
257
  const final = range ? ModelBlobUtil.enforceRange(range, meta.size!) : undefined;
258
258
  const mongoRange = final ? { start: final.start, end: final.end + 1 } : undefined;
259
259
  return BinaryUtil.readableBlob(() => this.#bucket.openDownloadStreamByName(location, mongoRange), { ...meta, range: final });
260
260
  }
261
261
 
262
- async describeBlob(location: string): Promise<BlobMeta> {
263
- return (await this.#describeBlobRaw(location)).metadata ?? {};
262
+ async getBlobMeta(location: string): Promise<BlobMeta> {
263
+ const res = await this.#db.collection<{ metadata: BlobMeta }>(`${ModelBlobNamespace}.files`).findOne({ filename: location });
264
+ return res!.metadata;
264
265
  }
265
266
 
266
267
  async deleteBlob(location: string): Promise<void> {
@@ -268,6 +269,13 @@ export class MongoModelService implements
268
269
  await this.#bucket.delete(fileId);
269
270
  }
270
271
 
272
+ async updateBlobMeta(location: string, meta: BlobMeta): Promise<void> {
273
+ await this.#db.collection<{ metadata: BlobMeta }>(`${ModelBlobNamespace}.files`).findOneAndUpdate(
274
+ { filename: location },
275
+ { $set: { metadata: meta, contentType: meta.contentType! } },
276
+ );
277
+ }
278
+
271
279
  // Bulk
272
280
  async processBulk<T extends ModelType>(cls: Class<T>, operations: BulkOp<T>[]): Promise<BulkResponse<{ index: number }>> {
273
281
  const out: BulkResponse<{ index: number }> = {