@travetto/model-mongo 4.1.3 → 5.0.0-rc.1
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/LICENSE +1 -1
- package/README.md +3 -3
- package/package.json +6 -6
- package/src/config.ts +2 -2
- package/src/internal/util.ts +3 -3
- package/src/service.ts +11 -17
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ where the [MongoModelConfig](https://github.com/travetto/travetto/tree/main/modu
|
|
|
48
48
|
```typescript
|
|
49
49
|
import type mongo from 'mongodb';
|
|
50
50
|
|
|
51
|
-
import {
|
|
51
|
+
import { Env, TimeSpan, TimeUtil, RuntimeResources } from '@travetto/base';
|
|
52
52
|
import { Config } from '@travetto/config';
|
|
53
53
|
import { Field } from '@travetto/schema';
|
|
54
54
|
|
|
@@ -152,7 +152,7 @@ export class MongoModelConfig {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
if (!Env.production) {
|
|
155
|
-
opts.waitQueueTimeoutMS ??=
|
|
155
|
+
opts.waitQueueTimeoutMS ??= TimeUtil.asMillis(1, 'd'); // Wait a day in dev mode
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
@@ -174,4 +174,4 @@ export class MongoModelConfig {
|
|
|
174
174
|
}
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
Additionally, you can see that the class is registered with the [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) annotation, and so these values can be overridden using the standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Configuration support") resolution paths.The SSL file options in `clientOptions` will automatically be resolved to files when given a path. This path can be a [
|
|
177
|
+
Additionally, you can see that the class is registered with the [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) annotation, and so these values can be overridden using the standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Configuration support") resolution paths.The SSL file options in `clientOptions` will automatically be resolved to files when given a path. This path can be a resource path (will attempt to lookup using [RuntimeResources](https://github.com/travetto/travetto/tree/main/module/base/src/runtime.ts#L8)) or just a standard file path.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-mongo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-rc.1",
|
|
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": "^
|
|
29
|
-
"@travetto/model": "^
|
|
30
|
-
"@travetto/model-query": "^
|
|
31
|
-
"mongodb": "^6.
|
|
28
|
+
"@travetto/config": "^5.0.0-rc.1",
|
|
29
|
+
"@travetto/model": "^5.0.0-rc.1",
|
|
30
|
+
"@travetto/model-query": "^5.0.0-rc.0",
|
|
31
|
+
"mongodb": "^6.8.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/command": "^
|
|
34
|
+
"@travetto/command": "^5.0.0-rc.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/command": {
|
package/src/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type mongo from 'mongodb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Env, TimeSpan, TimeUtil, RuntimeResources } from '@travetto/base';
|
|
4
4
|
import { Config } from '@travetto/config';
|
|
5
5
|
import { Field } from '@travetto/schema';
|
|
6
6
|
|
|
@@ -104,7 +104,7 @@ export class MongoModelConfig {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (!Env.production) {
|
|
107
|
-
opts.waitQueueTimeoutMS ??=
|
|
107
|
+
opts.waitQueueTimeoutMS ??= TimeUtil.asMillis(1, 'd'); // Wait a day in dev mode
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
package/src/internal/util.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Binary, ObjectId } from 'mongodb';
|
|
2
2
|
|
|
3
|
-
import { Class
|
|
3
|
+
import { Class } from '@travetto/base';
|
|
4
4
|
import { DistanceUnit, ModelQuery, Query, WhereClause } from '@travetto/model-query';
|
|
5
5
|
import type { ModelType, IndexField } from '@travetto/model';
|
|
6
6
|
import { DataUtil, SchemaRegistry } from '@travetto/schema';
|
|
@@ -116,7 +116,7 @@ export class MongoUtil {
|
|
|
116
116
|
return this.uuid(v);
|
|
117
117
|
} else if (Array.isArray(v)) {
|
|
118
118
|
return v.map(x => this.replaceId(x));
|
|
119
|
-
} else if (
|
|
119
|
+
} else if (DataUtil.isPlainObject(v)) {
|
|
120
120
|
const out: Record<string, Binary> = {};
|
|
121
121
|
for (const [k, el] of Object.entries(v)) {
|
|
122
122
|
const found = this.replaceId(el);
|
|
@@ -146,7 +146,7 @@ export class MongoUtil {
|
|
|
146
146
|
if (subpath === 'id') { // Handle ids directly
|
|
147
147
|
out._id = this.replaceId(v);
|
|
148
148
|
} else {
|
|
149
|
-
const isPlain = v &&
|
|
149
|
+
const isPlain = v && DataUtil.isPlainObject(v);
|
|
150
150
|
const firstKey = isPlain ? Object.keys(v)[0] : '';
|
|
151
151
|
|
|
152
152
|
if ((isPlain && !firstKey.startsWith('$')) || v?.constructor?.Ⲑid) {
|
package/src/service.ts
CHANGED
|
@@ -11,14 +11,15 @@ import {
|
|
|
11
11
|
ModelCrudSupport, ModelStorageSupport, ModelStreamSupport,
|
|
12
12
|
ModelExpirySupport, ModelBulkSupport, ModelIndexedSupport,
|
|
13
13
|
StreamMeta, BulkOp, BulkResponse,
|
|
14
|
-
NotFoundError, ExistsError, IndexConfig,
|
|
14
|
+
NotFoundError, ExistsError, IndexConfig,
|
|
15
|
+
StreamRange
|
|
15
16
|
} from '@travetto/model';
|
|
16
17
|
import {
|
|
17
18
|
ModelQuery, ModelQueryCrudSupport, ModelQueryFacetSupport, ModelQuerySupport,
|
|
18
19
|
PageableModelQuery, ValidStringFields, WhereClause, ModelQuerySuggestSupport
|
|
19
20
|
} from '@travetto/model-query';
|
|
20
21
|
|
|
21
|
-
import { ShutdownManager, type Class, AppError, TypedObject
|
|
22
|
+
import { ShutdownManager, type Class, AppError, TypedObject } from '@travetto/base';
|
|
22
23
|
import { Injectable } from '@travetto/di';
|
|
23
24
|
import { DeepPartial, FieldConfig, SchemaRegistry, SchemaValidator } from '@travetto/schema';
|
|
24
25
|
|
|
@@ -30,7 +31,7 @@ import { ModelQuerySuggestUtil } from '@travetto/model-query/src/internal/servic
|
|
|
30
31
|
import { PointImpl } from '@travetto/model-query/src/internal/model/point';
|
|
31
32
|
import { ModelQueryExpiryUtil } from '@travetto/model-query/src/internal/service/expiry';
|
|
32
33
|
import { ModelExpiryUtil } from '@travetto/model/src/internal/service/expiry';
|
|
33
|
-
import { StreamModel, STREAMS } from '@travetto/model/src/internal/service/stream';
|
|
34
|
+
import { enforceRange, StreamModel, STREAMS } from '@travetto/model/src/internal/service/stream';
|
|
34
35
|
import { AllViewⲐ } from '@travetto/schema/src/internal/types';
|
|
35
36
|
import { ModelBulkUtil } from '@travetto/model/src/internal/service/bulk';
|
|
36
37
|
|
|
@@ -299,26 +300,19 @@ export class MongoModelService implements
|
|
|
299
300
|
await pipeline(input, writeStream);
|
|
300
301
|
}
|
|
301
302
|
|
|
302
|
-
async getStream(location: string): Promise<Readable> {
|
|
303
|
-
await this.describeStream(location);
|
|
304
|
-
|
|
305
|
-
const res = await this.#bucket.openDownloadStreamByName(location);
|
|
306
|
-
if (!res) {
|
|
307
|
-
throw new NotFoundError(STREAMS, location);
|
|
308
|
-
}
|
|
309
|
-
return res;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async getStreamPartial(location: string, start: number, end?: number): Promise<PartialStream> {
|
|
303
|
+
async getStream(location: string, range?: StreamRange): Promise<Readable> {
|
|
313
304
|
const meta = await this.describeStream(location);
|
|
314
305
|
|
|
315
|
-
|
|
306
|
+
if (range) {
|
|
307
|
+
range = enforceRange(range, meta.size);
|
|
308
|
+
range.end! += 1; // range is exclusive
|
|
309
|
+
}
|
|
316
310
|
|
|
317
|
-
const res = await this.#bucket.openDownloadStreamByName(location,
|
|
311
|
+
const res = await this.#bucket.openDownloadStreamByName(location, range);
|
|
318
312
|
if (!res) {
|
|
319
313
|
throw new NotFoundError(STREAMS, location);
|
|
320
314
|
}
|
|
321
|
-
return
|
|
315
|
+
return res;
|
|
322
316
|
}
|
|
323
317
|
|
|
324
318
|
async describeStream(location: string): Promise<StreamMeta> {
|