@travetto/model-mongo 4.1.3 → 5.0.0-rc.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 ArcSine Technologies
3
+ Copyright (c) 2023 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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 { RuntimeResources, Env, TimeSpan } from '@travetto/base';
51
+ import { RuntimeResources, Env, TimeSpan, TimeUtil } 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 ??= 1000 * 60 * 60 * 24; // Wait a day in dev mode
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 [ResourceLoader](https://github.com/travetto/travetto/tree/main/module/base/src/resource.ts#L10) path or just a standard file path.
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/resource.ts#L4)) or just a standard file path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-mongo",
3
- "version": "4.1.3",
3
+ "version": "5.0.0-rc.0",
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": "^4.1.1",
29
- "@travetto/model": "^4.1.3",
30
- "@travetto/model-query": "^4.1.3",
31
- "mongodb": "^6.7.0"
28
+ "@travetto/config": "^5.0.0-rc.0",
29
+ "@travetto/model": "^5.0.0-rc.0",
30
+ "@travetto/model-query": "^5.0.0-rc.0",
31
+ "mongodb": "^6.8.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/command": "^4.1.1"
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 { RuntimeResources, Env, TimeSpan } from '@travetto/base';
3
+ import { RuntimeResources, Env, TimeSpan, TimeUtil } 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 ??= 1000 * 60 * 60 * 24; // Wait a day in dev mode
107
+ opts.waitQueueTimeoutMS ??= TimeUtil.asMillis(1, 'd'); // Wait a day in dev mode
108
108
  }
109
109
  }
110
110
 
@@ -1,6 +1,6 @@
1
1
  import { Binary, ObjectId } from 'mongodb';
2
2
 
3
- import { Class, ObjectUtil } from '@travetto/base';
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 (ObjectUtil.isPlainObject(v)) {
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 && ObjectUtil.isPlainObject(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, PartialStream
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, StreamUtil } from '@travetto/base';
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
- [start, end] = StreamUtil.enforceRange(start, end, meta.size);
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, { start, end: end + 1 });
311
+ const res = await this.#bucket.openDownloadStreamByName(location, range);
318
312
  if (!res) {
319
313
  throw new NotFoundError(STREAMS, location);
320
314
  }
321
- return { stream: res, range: [start, end] };
315
+ return res;
322
316
  }
323
317
 
324
318
  async describeStream(location: string): Promise<StreamMeta> {