@travetto/model-mongo 4.0.0-rc.0 → 4.0.0-rc.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-mongo",
3
- "version": "4.0.0-rc.0",
3
+ "version": "4.0.0-rc.2",
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.0.0-rc.0",
29
- "@travetto/model": "^4.0.0-rc.0",
30
- "@travetto/model-query": "^4.0.0-rc.0",
28
+ "@travetto/config": "^4.0.0-rc.2",
29
+ "@travetto/model": "^4.0.0-rc.2",
30
+ "@travetto/model-query": "^4.0.0-rc.2",
31
31
  "mongodb": "^6.3.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/command": "^4.0.0-rc.0"
34
+ "@travetto/command": "^4.0.0-rc.2"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/command": {
@@ -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
3
  import { Readable } from 'node:stream';
4
+ import { pipeline } from 'node:stream/promises';
4
5
 
5
6
  import {
6
7
  ModelRegistry, ModelType, OptionalId,
@@ -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),