@travetto/model-mongo 3.0.0-rc.10 → 3.0.0-rc.11
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 +4 -4
- package/package.json +6 -6
- package/src/config.ts +1 -1
- package/src/internal/util.ts +1 -1
- package/src/service.ts +18 -2
- package/support/service.mongo.ts +3 -3
package/README.md
CHANGED
|
@@ -46,9 +46,9 @@ export class Init {
|
|
|
46
46
|
|
|
47
47
|
**Code: Structure of MongoModelConfig**
|
|
48
48
|
```typescript
|
|
49
|
-
import
|
|
49
|
+
import type mongo from 'mongodb';
|
|
50
50
|
|
|
51
|
-
import {
|
|
51
|
+
import { FileResourceProvider, TimeSpan } from '@travetto/base';
|
|
52
52
|
import { Config } from '@travetto/config';
|
|
53
53
|
import { Field } from '@travetto/schema';
|
|
54
54
|
|
|
@@ -107,7 +107,7 @@ export class MongoModelConfig {
|
|
|
107
107
|
* Load all the ssl certs as needed
|
|
108
108
|
*/
|
|
109
109
|
async postConstruct(): Promise<void> {
|
|
110
|
-
const resources = new
|
|
110
|
+
const resources = new FileResourceProvider({ includeCommon: true });
|
|
111
111
|
const resolve = (file: string): Promise<string> => resources.describe(file).then(({ path }) => path, () => file);
|
|
112
112
|
|
|
113
113
|
const opts = this.options;
|
|
@@ -149,4 +149,4 @@ export class MongoModelConfig {
|
|
|
149
149
|
standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Configuration support")resolution paths.
|
|
150
150
|
|
|
151
151
|
|
|
152
|
-
The SSL file options in `clientOptions` will automatically be resolved to files when given a path. This path can be a [FileResourceProvider](https://github.com/travetto/travetto/tree/main/module/base/src/resource.ts#
|
|
152
|
+
The SSL file options in `clientOptions` will automatically be resolved to files when given a path. This path can be a [FileResourceProvider](https://github.com/travetto/travetto/tree/main/module/base/src/resource.ts#L46) 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.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.11",
|
|
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.0.0-rc.
|
|
29
|
-
"@travetto/model": "^3.0.0-rc.
|
|
30
|
-
"@travetto/model-query": "^3.0.0-rc.
|
|
31
|
-
"mongodb": "^
|
|
28
|
+
"@travetto/config": "^3.0.0-rc.11",
|
|
29
|
+
"@travetto/model": "^3.0.0-rc.11",
|
|
30
|
+
"@travetto/model-query": "^3.0.0-rc.11",
|
|
31
|
+
"mongodb": "^5.0.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/command": "^3.0.0-rc.
|
|
34
|
+
"@travetto/command": "^3.0.0-rc.8"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/command": {
|
package/src/config.ts
CHANGED
package/src/internal/util.ts
CHANGED
package/src/service.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Wildcard import needed here due to packaging issues
|
|
2
2
|
import * as mongo from 'mongodb';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
4
|
|
|
@@ -194,6 +194,7 @@ export class MongoModelService implements
|
|
|
194
194
|
if (!result.insertedId) {
|
|
195
195
|
throw new ExistsError(cls, cleaned.id);
|
|
196
196
|
}
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
197
198
|
delete (cleaned as { _id?: unknown })._id;
|
|
198
199
|
return cleaned;
|
|
199
200
|
}
|
|
@@ -245,9 +246,11 @@ export class MongoModelService implements
|
|
|
245
246
|
.entries(items)
|
|
246
247
|
.reduce<Record<string, unknown>>((acc, [k, v]) => {
|
|
247
248
|
if (v === null || v === undefined) {
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
248
250
|
const o = (acc.$unset ??= {}) as Record<string, unknown>;
|
|
249
251
|
o[k] = v;
|
|
250
252
|
} else {
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
251
254
|
const o = (acc.$set ??= {}) as Record<string, unknown>;
|
|
252
255
|
o[k] = v;
|
|
253
256
|
}
|
|
@@ -347,6 +350,7 @@ export class MongoModelService implements
|
|
|
347
350
|
|
|
348
351
|
for (const op of operations) {
|
|
349
352
|
if (op.insert) {
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
350
354
|
bulk.insert(MongoUtil.preInsertId(op.insert as T));
|
|
351
355
|
} else if (op.upsert) {
|
|
352
356
|
bulk.find({ _id: MongoUtil.uuid(op.upsert.id!) }).upsert().updateOne({ $set: op.upsert });
|
|
@@ -361,9 +365,11 @@ export class MongoModelService implements
|
|
|
361
365
|
|
|
362
366
|
for (const op of operations) {
|
|
363
367
|
if (op.insert) {
|
|
368
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
364
369
|
MongoUtil.postLoadId(op.insert as T);
|
|
365
370
|
}
|
|
366
371
|
}
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
367
373
|
for (const { index, _id } of res.getUpsertedIds() as { index: number, _id: mongo.ObjectId }[]) {
|
|
368
374
|
out.insertedIds.set(index, MongoUtil.idToString(_id));
|
|
369
375
|
}
|
|
@@ -379,6 +385,7 @@ export class MongoModelService implements
|
|
|
379
385
|
out.errors = res.getWriteErrors();
|
|
380
386
|
for (const err of out.errors) {
|
|
381
387
|
const op = operations[err.index];
|
|
388
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
382
389
|
const k = Object.keys(op)[0] as keyof BulkResponse['counts'];
|
|
383
390
|
out.counts[k] -= 1;
|
|
384
391
|
}
|
|
@@ -400,6 +407,7 @@ export class MongoModelService implements
|
|
|
400
407
|
const result = await store.findOne(
|
|
401
408
|
this.getWhere(
|
|
402
409
|
cls,
|
|
410
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
403
411
|
ModelIndexedUtil.projectIndex(cls, idx, body) as WhereClause<T>
|
|
404
412
|
)
|
|
405
413
|
);
|
|
@@ -415,6 +423,7 @@ export class MongoModelService implements
|
|
|
415
423
|
const result = await store.deleteOne(
|
|
416
424
|
this.getWhere(
|
|
417
425
|
cls,
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
418
427
|
ModelIndexedUtil.projectIndex(cls, idx, body) as WhereClause<T>
|
|
419
428
|
)
|
|
420
429
|
);
|
|
@@ -436,14 +445,17 @@ export class MongoModelService implements
|
|
|
436
445
|
throw new AppError('Cannot list on unique indices', 'data');
|
|
437
446
|
}
|
|
438
447
|
|
|
448
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
439
449
|
const where = this.getWhere(
|
|
440
450
|
cls,
|
|
451
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
441
452
|
ModelIndexedUtil.projectIndex(cls, idx, body, { emptySortValue: { $exists: true } }) as WhereClause<T>
|
|
442
|
-
) as mongo.Filter<
|
|
453
|
+
) as mongo.Filter<Document>;
|
|
443
454
|
|
|
444
455
|
const cursor = store.find(where, { timeout: true }).batchSize(100).sort(asFielded(idxCfg)[IdxFieldsⲐ]);
|
|
445
456
|
|
|
446
457
|
for await (const el of cursor) {
|
|
458
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
447
459
|
yield (await MongoUtil.postLoadId(await ModelCrudUtil.load(cls, el))) as T;
|
|
448
460
|
}
|
|
449
461
|
}
|
|
@@ -505,9 +517,11 @@ export class MongoModelService implements
|
|
|
505
517
|
const items = MongoUtil.extractSimple(data);
|
|
506
518
|
const final = Object.entries(items).reduce<Record<string, unknown>>((acc, [k, v]) => {
|
|
507
519
|
if (v === null || v === undefined) {
|
|
520
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
508
521
|
const o = (acc.$unset = acc.$unset ?? {}) as Record<string, unknown>;
|
|
509
522
|
o[k] = v;
|
|
510
523
|
} else {
|
|
524
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
511
525
|
const o = (acc.$set = acc.$set ?? {}) as Record<string, unknown>;
|
|
512
526
|
o[k] = v;
|
|
513
527
|
}
|
|
@@ -524,6 +538,7 @@ export class MongoModelService implements
|
|
|
524
538
|
const col = await this.getStore(cls);
|
|
525
539
|
const pipeline: object[] = [{
|
|
526
540
|
$group: {
|
|
541
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
527
542
|
_id: `$${field as string}`,
|
|
528
543
|
count: {
|
|
529
544
|
$sum: 1
|
|
@@ -539,6 +554,7 @@ export class MongoModelService implements
|
|
|
539
554
|
|
|
540
555
|
pipeline.unshift({ $match: q });
|
|
541
556
|
|
|
557
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
542
558
|
const result = (await col.aggregate(pipeline).toArray()) as { _id: mongo.ObjectId, count: number }[];
|
|
543
559
|
|
|
544
560
|
return result.map(val => ({
|
package/support/service.mongo.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Env } from '@travetto/base';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommandService } from '@travetto/command';
|
|
3
3
|
|
|
4
|
-
const version = Env.get('MONGO_VERSION', '
|
|
4
|
+
const version = Env.get('MONGO_VERSION', '6.0');
|
|
5
5
|
|
|
6
|
-
export const service:
|
|
6
|
+
export const service: CommandService = {
|
|
7
7
|
name: 'mongodb',
|
|
8
8
|
version,
|
|
9
9
|
port: 27017,
|