@travetto/model-mongo 3.4.5 → 4.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/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 { ResourceLoader, GlobalEnv, TimeSpan } from '@travetto/base';
51
+ import { RuntimeResources, Env, TimeSpan } from '@travetto/base';
52
52
  import { Config } from '@travetto/config';
53
53
  import { Field } from '@travetto/schema';
54
54
 
@@ -111,8 +111,7 @@ export class MongoModelConfig {
111
111
  * Load all the ssl certs as needed
112
112
  */
113
113
  async postConstruct(): Promise<void> {
114
- const resources = new ResourceLoader();
115
- const resolve = (file: string): Promise<string> => resources.resolve(file).then(v => v, () => file);
114
+ const resolve = (file: string): Promise<string> => RuntimeResources.resolve(file).then(v => v, () => file);
116
115
 
117
116
  if (this.connectionString) {
118
117
  const details = new URL(this.connectionString);
@@ -152,7 +151,7 @@ export class MongoModelConfig {
152
151
  }
153
152
  }
154
153
 
155
- if (GlobalEnv.devMode) {
154
+ if (!Env.production) {
156
155
  opts.waitQueueTimeoutMS ??= 1000 * 60 * 60 * 24; // Wait a day in dev mode
157
156
  }
158
157
  }
@@ -175,4 +174,4 @@ export class MongoModelConfig {
175
174
  }
176
175
  ```
177
176
 
178
- 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#L9) 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 [ResourceLoader](https://github.com/travetto/travetto/tree/main/module/base/src/resource.ts#L10) path 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.4.5",
3
+ "version": "4.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": "^3.4.4",
29
- "@travetto/model": "^3.4.5",
30
- "@travetto/model-query": "^3.4.5",
28
+ "@travetto/config": "^4.0.0-rc.1",
29
+ "@travetto/model": "^4.0.0-rc.1",
30
+ "@travetto/model-query": "^4.0.0-rc.1",
31
31
  "mongodb": "^6.3.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/command": "^3.4.3"
34
+ "@travetto/command": "^4.0.0-rc.1"
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 { ResourceLoader, GlobalEnv, TimeSpan } from '@travetto/base';
3
+ import { RuntimeResources, Env, TimeSpan } from '@travetto/base';
4
4
  import { Config } from '@travetto/config';
5
5
  import { Field } from '@travetto/schema';
6
6
 
@@ -63,8 +63,7 @@ export class MongoModelConfig {
63
63
  * Load all the ssl certs as needed
64
64
  */
65
65
  async postConstruct(): Promise<void> {
66
- const resources = new ResourceLoader();
67
- const resolve = (file: string): Promise<string> => resources.resolve(file).then(v => v, () => file);
66
+ const resolve = (file: string): Promise<string> => RuntimeResources.resolve(file).then(v => v, () => file);
68
67
 
69
68
  if (this.connectionString) {
70
69
  const details = new URL(this.connectionString);
@@ -104,7 +103,7 @@ export class MongoModelConfig {
104
103
  }
105
104
  }
106
105
 
107
- if (GlobalEnv.devMode) {
106
+ if (!Env.production) {
108
107
  opts.waitQueueTimeoutMS ??= 1000 * 60 * 60 * 24; // Wait a day in dev mode
109
108
  }
110
109
  }
@@ -1,9 +1,9 @@
1
1
  import * as mongo from 'mongodb';
2
2
 
3
- import { Class, DataUtil, ObjectUtil } from '@travetto/base';
3
+ import { Class, ObjectUtil } from '@travetto/base';
4
4
  import { DistanceUnit, ModelQuery, Query, WhereClause } from '@travetto/model-query';
5
5
  import type { ModelType, IndexField } from '@travetto/model';
6
- import { SchemaRegistry } from '@travetto/schema';
6
+ import { DataUtil, SchemaRegistry } from '@travetto/schema';
7
7
  import { ModelQueryUtil } from '@travetto/model-query/src/internal/service/query';
8
8
  import { AllViewⲐ } from '@travetto/schema/src/internal/types';
9
9
 
package/src/service.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Wildcard import needed here due to packaging issues
2
2
  import * as mongo from 'mongodb';
3
- import { Readable } from 'stream';
3
+ import { Readable } from 'node:stream';
4
+ import { pipeline } from 'node:stream/promises';
4
5
 
5
6
  import {
6
7
  ModelRegistry, ModelType, OptionalId,
@@ -79,7 +80,7 @@ export class MongoModelService implements
79
80
  writeConcern: { w: 1 }
80
81
  });
81
82
  await ModelStorageUtil.registerModelChangeListener(this);
82
- ShutdownManager.onShutdown(this, () => this.client.close());
83
+ ShutdownManager.onGracefulShutdown(() => this.client.close(), this);
83
84
  ModelExpiryUtil.registerCull(this);
84
85
  }
85
86
 
@@ -292,9 +293,7 @@ export class MongoModelService implements
292
293
  metadata: meta
293
294
  });
294
295
 
295
- await new Promise<unknown>((resolve, reject) => {
296
- input.pipe(writeStream).on('finish', resolve).on('error', reject);
297
- });
296
+ await pipeline(input, writeStream);
298
297
  }
299
298
 
300
299
  async getStream(location: string): Promise<Readable> {
@@ -553,7 +552,7 @@ export class MongoModelService implements
553
552
  // Facet
554
553
  async facet<T extends ModelType>(cls: Class<T>, field: ValidStringFields<T>, query?: ModelQuery<T>): Promise<{ key: string, count: number }[]> {
555
554
  const col = await this.getStore(cls);
556
- const pipeline: object[] = [{
555
+ const aggs: object[] = [{
557
556
  $group: {
558
557
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
559
558
  _id: `$${field as string}`,
@@ -569,10 +568,10 @@ export class MongoModelService implements
569
568
  q = { $and: [q, MongoUtil.prepareQuery(cls, query).filter] };
570
569
  }
571
570
 
572
- pipeline.unshift({ $match: q });
571
+ aggs.unshift({ $match: q });
573
572
 
574
573
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
575
- const result = (await col.aggregate(pipeline).toArray()) as { _id: mongo.ObjectId, count: number }[];
574
+ const result = (await col.aggregate(aggs).toArray()) as { _id: mongo.ObjectId, count: number }[];
576
575
 
577
576
  return result.map(val => ({
578
577
  key: MongoUtil.idToString(val._id),
@@ -1,7 +1,6 @@
1
- import { Env } from '@travetto/base';
2
1
  import type { CommandService } from '@travetto/command';
3
2
 
4
- const version = Env.get('MONGO_VERSION', '7.0');
3
+ const version = process.env.MONGO_VERSION ?? '7.0';
5
4
 
6
5
  export const service: CommandService = {
7
6
  name: 'mongodb',