@travetto/model-mongo 5.0.0-rc.12 → 5.0.0-rc.13
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/package.json +5 -5
- package/src/service.ts +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-mongo",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.13",
|
|
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.0-rc.
|
|
29
|
-
"@travetto/model": "^5.0.0-rc.
|
|
30
|
-
"@travetto/model-query": "^5.0.0-rc.
|
|
28
|
+
"@travetto/config": "^5.0.0-rc.13",
|
|
29
|
+
"@travetto/model": "^5.0.0-rc.13",
|
|
30
|
+
"@travetto/model-query": "^5.0.0-rc.13",
|
|
31
31
|
"mongodb": "^6.8.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/command": "^5.0.0-rc.
|
|
34
|
+
"@travetto/command": "^5.0.0-rc.12"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/command": {
|
package/src/service.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Readable } from 'node:stream';
|
|
|
9
9
|
import {
|
|
10
10
|
ModelRegistry, ModelType, OptionalId, ModelCrudSupport, ModelStorageSupport,
|
|
11
11
|
ModelExpirySupport, ModelBulkSupport, ModelIndexedSupport, BulkOp, BulkResponse,
|
|
12
|
-
NotFoundError, ExistsError, IndexConfig, ModelBlobSupport
|
|
12
|
+
NotFoundError, ExistsError, IndexConfig, ModelBlobSupport
|
|
13
13
|
} from '@travetto/model';
|
|
14
14
|
import {
|
|
15
15
|
ModelQuery, ModelQueryCrudSupport, ModelQueryFacetSupport, ModelQuerySupport,
|
|
@@ -34,7 +34,7 @@ import { ModelQueryExpiryUtil } from '@travetto/model-query/src/internal/service
|
|
|
34
34
|
import { ModelExpiryUtil } from '@travetto/model/src/internal/service/expiry';
|
|
35
35
|
import { AllViewⲐ } from '@travetto/schema/src/internal/types';
|
|
36
36
|
import { ModelBulkUtil } from '@travetto/model/src/internal/service/bulk';
|
|
37
|
-
import { MODEL_BLOB, ModelBlobNamespace } from '@travetto/model/src/internal/service/blob';
|
|
37
|
+
import { MODEL_BLOB, ModelBlobNamespace, ModelBlobUtil } from '@travetto/model/src/internal/service/blob';
|
|
38
38
|
|
|
39
39
|
import { MongoUtil, WithId } from './internal/util';
|
|
40
40
|
import { MongoModelConfig } from './config';
|
|
@@ -281,22 +281,22 @@ export class MongoModelService implements
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
// Blob
|
|
284
|
-
async
|
|
285
|
-
await this.describeBlob(location);
|
|
286
|
-
if (
|
|
287
|
-
|
|
284
|
+
async upsertBlob(location: string, input: BinaryInput, meta?: BlobMeta, overwrite = true): Promise<void> {
|
|
285
|
+
const existing = await this.describeBlob(location).then(() => true, () => false);
|
|
286
|
+
if (!overwrite && existing) {
|
|
287
|
+
return;
|
|
288
288
|
}
|
|
289
|
-
return this.upsertBlob(location, input, meta);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async upsertBlob(location: string, input: BinaryInput, meta?: BlobMeta): Promise<void> {
|
|
293
289
|
const [stream, blobMeta] = await ModelBlobUtil.getInput(input, meta);
|
|
294
290
|
const writeStream = this.#bucket.openUploadStream(location, {
|
|
295
291
|
contentType: blobMeta.contentType,
|
|
296
|
-
metadata: blobMeta
|
|
292
|
+
metadata: blobMeta,
|
|
297
293
|
});
|
|
298
|
-
|
|
299
294
|
await pipeline(stream, writeStream);
|
|
295
|
+
|
|
296
|
+
if (existing) {
|
|
297
|
+
const [read] = await this.#bucket.find({ filename: location, _id: { $ne: writeStream.id } }).toArray();
|
|
298
|
+
await this.#bucket.delete(read._id);
|
|
299
|
+
}
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
async getBlob(location: string, range?: ByteRange): Promise<Blob> {
|