@travetto/model-mongo 6.0.0 → 7.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/README.md CHANGED
@@ -43,7 +43,7 @@ export class Init {
43
43
  }
44
44
  ```
45
45
 
46
- where the [MongoModelConfig](https://github.com/travetto/travetto/tree/main/module/model-mongo/src/config.ts#L11) is defined by:
46
+ where the [MongoModelConfig](https://github.com/travetto/travetto/tree/main/module/model-mongo/src/config.ts#L10) is defined by:
47
47
 
48
48
  **Code: Structure of MongoModelConfig**
49
49
  ```typescript
@@ -81,7 +81,6 @@ export class MongoModelConfig {
81
81
  /**
82
82
  * Mongo client options
83
83
  */
84
- @Field(Object)
85
84
  options: mongo.MongoClientOptions = {};
86
85
 
87
86
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-mongo",
3
- "version": "6.0.0",
3
+ "version": "7.0.0-rc.0",
4
4
  "description": "Mongo backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "mongo",
@@ -25,11 +25,11 @@
25
25
  "directory": "module/model-mongo"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/cli": "^6.0.0",
29
- "@travetto/config": "^6.0.0",
30
- "@travetto/model": "^6.0.0",
31
- "@travetto/model-query": "^6.0.0",
32
- "mongodb": "^6.16.0"
28
+ "@travetto/cli": "^7.0.0-rc.0",
29
+ "@travetto/config": "^7.0.0-rc.0",
30
+ "@travetto/model": "^7.0.0-rc.0",
31
+ "@travetto/model-query": "^7.0.0-rc.0",
32
+ "mongodb": "^7.0.0"
33
33
  },
34
34
  "travetto": {
35
35
  "displayName": "MongoDB Model Support"
package/src/config.ts CHANGED
@@ -2,7 +2,6 @@ import type mongo from 'mongodb';
2
2
 
3
3
  import { TimeSpan, TimeUtil, RuntimeResources, Runtime } from '@travetto/runtime';
4
4
  import { Config } from '@travetto/config';
5
- import { Field } from '@travetto/schema';
6
5
 
7
6
  /**
8
7
  * Mongo model config
@@ -41,7 +40,6 @@ export class MongoModelConfig {
41
40
  /**
42
41
  * Mongo client options
43
42
  */
44
- @Field(Object)
45
43
  options: mongo.MongoClientOptions = {};
46
44
 
47
45
  /**
@@ -5,7 +5,7 @@ import {
5
5
  import { AppError, castTo, Class, toConcrete, TypedObject } from '@travetto/runtime';
6
6
  import { type DistanceUnit, type PageableModelQuery, type WhereClause, ModelQueryUtil } from '@travetto/model-query';
7
7
  import type { ModelType, IndexField, IndexConfig } from '@travetto/model';
8
- import { DataUtil, SchemaRegistry, type Point } from '@travetto/schema';
8
+ import { DataUtil, SchemaRegistryIndex, type Point } from '@travetto/schema';
9
9
 
10
10
  const PointImpl = toConcrete<Point>();
11
11
 
@@ -80,14 +80,14 @@ export class MongoUtil {
80
80
 
81
81
  /**/
82
82
  static extractSimple<T>(base: Class<T> | undefined, o: Record<string, unknown>, path: string = '', recursive: boolean = true): Record<string, unknown> {
83
- const schema = base ? SchemaRegistry.get(base) : undefined;
83
+ const fields = base ? SchemaRegistryIndex.getOptionalConfig(base)?.fields : undefined;
84
84
  const out: Record<string, unknown> = {};
85
85
  const sub = o;
86
86
  const keys = Object.keys(sub);
87
87
  for (const key of keys) {
88
88
  const subpath = `${path}${key}`;
89
89
  const v: Record<string, unknown> = castTo(sub[key]);
90
- const subField = schema?.totalView.schema[key];
90
+ const subField = fields?.[key];
91
91
 
92
92
  const isPlain = v && DataUtil.isPlainObject(v);
93
93
  const firstKey = isPlain ? Object.keys(v)[0] : '';
@@ -131,7 +131,7 @@ export class MongoUtil {
131
131
  } else if (firstKey && '$geoWithin' in v) {
132
132
  const coords: [number, number][] = castTo(v.$geoWithin);
133
133
  const first = coords[0];
134
- const last = coords[coords.length - 1];
134
+ const last = coords.at(-1)!;
135
135
  // Connect if not
136
136
  if (first[0] !== last[0] || first[1] !== last[1]) {
137
137
  coords.push(first);
@@ -152,7 +152,7 @@ export class MongoUtil {
152
152
  static getExtraIndices<T extends ModelType>(cls: Class<T>): BasicIdx[] {
153
153
  const out: BasicIdx[] = [];
154
154
  const textFields: string[] = [];
155
- SchemaRegistry.visitFields(cls, (field, path) => {
155
+ SchemaRegistryIndex.visitFields(cls, (field, path) => {
156
156
  if (field.type === PointImpl) {
157
157
  const name = [...path, field].map(x => x.name).join('.');
158
158
  out.push({ [name]: '2d' });
package/src/service.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from 'mongodb';
8
8
 
9
9
  import {
10
- ModelRegistry, ModelType, OptionalId, ModelCrudSupport, ModelStorageSupport,
10
+ ModelRegistryIndex, ModelType, OptionalId, ModelCrudSupport, ModelStorageSupport,
11
11
  ModelExpirySupport, ModelBulkSupport, ModelIndexedSupport, BulkOp, BulkResponse,
12
12
  NotFoundError, ExistsError, ModelBlobSupport,
13
13
  ModelCrudUtil, ModelIndexedUtil, ModelStorageUtil, ModelExpiryUtil, ModelBulkUtil, ModelBlobUtil,
@@ -107,7 +107,7 @@ export class MongoModelService implements
107
107
  writeConcern: { w: 1 }
108
108
  });
109
109
  await ModelStorageUtil.registerModelChangeListener(this);
110
- ShutdownManager.onGracefulShutdown(() => this.client.close(), this);
110
+ ShutdownManager.onGracefulShutdown(() => this.client.close());
111
111
  ModelExpiryUtil.registerCull(this);
112
112
  }
113
113
 
@@ -128,7 +128,7 @@ export class MongoModelService implements
128
128
 
129
129
  async establishIndices<T extends ModelType>(cls: Class<T>): Promise<void> {
130
130
  const col = await this.getStore(cls);
131
- const creating = MongoUtil.getIndices(cls, ModelRegistry.get(cls).indices);
131
+ const creating = MongoUtil.getIndices(cls, ModelRegistryIndex.getConfig(cls).indices);
132
132
  if (creating.length) {
133
133
  console.debug('Creating indexes', { indices: creating });
134
134
  for (const el of creating) {
@@ -158,7 +158,7 @@ export class MongoModelService implements
158
158
  * Get mongo collection
159
159
  */
160
160
  async getStore<T extends ModelType>(cls: Class<T>): Promise<Collection<T>> {
161
- return this.#db.collection(ModelRegistry.getStore(cls).toLowerCase().replace(/[^A-Za-z0-9_]+/g, '_'));
161
+ return this.#db.collection(ModelRegistryIndex.getStoreName(cls).toLowerCase().replace(/[^A-Za-z0-9_]+/g, '_'));
162
162
  }
163
163
 
164
164
  // Crud
@@ -430,7 +430,7 @@ export class MongoModelService implements
430
430
 
431
431
  async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body?: DeepPartial<T>): AsyncIterable<T> {
432
432
  const store = await this.getStore(cls);
433
- const idxCfg = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
433
+ const idxCfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
434
434
 
435
435
  const where = this.getWhereFilter(
436
436
  cls,
@@ -1,6 +1,6 @@
1
1
  import type { ServiceDescriptor } from '@travetto/cli';
2
2
 
3
- const version = process.env.MONGO_VERSION || '8.0';
3
+ const version = process.env.MONGO_VERSION || '8.2';
4
4
 
5
5
  export const service: ServiceDescriptor = {
6
6
  name: 'mongodb',