@opra/mongodb 1.0.0-alpha.38 → 1.0.0-alpha.39

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.
@@ -41,6 +41,7 @@ class MongoCollectionService extends mongo_entity_service_js_1.MongoEntityServic
41
41
  input,
42
42
  options,
43
43
  };
44
+ command.input._id = command.input._id ?? this._generateId(command);
44
45
  return this._executeCommand(command, () => this._create(command));
45
46
  }
46
47
  /**
@@ -64,13 +64,13 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
64
64
  input,
65
65
  options,
66
66
  };
67
+ command.input._id = command.input._id ?? this._generateId(command);
67
68
  return this._executeCommand(command, () => this._create(command));
68
69
  }
69
70
  async _create(command) {
70
71
  const inputCodec = this.getInputCodec('create');
71
72
  const { documentId, options } = command;
72
73
  const doc = inputCodec(command.input);
73
- doc._id = doc._id || this._generateId(command);
74
74
  const docFilter = mongo_adapter_js_1.MongoAdapter.prepareKeyValues(documentId, ['_id']);
75
75
  const r = await this._dbUpdateOne(docFilter, {
76
76
  $push: { [this.fieldName]: doc },
@@ -625,7 +625,7 @@ class MongoNestedService extends mongo_service_js_1.MongoService {
625
625
  * This method is mostly used for security issues like securing multi-tenant applications.
626
626
  *
627
627
  * @protected
628
- * @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
628
+ * @returns {MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined} The common filter or a Promise
629
629
  * that resolves to the common filter, or undefined if not available.
630
630
  */
631
631
  _getNestedFilter(args) {
@@ -26,8 +26,9 @@ class MongoService extends core_1.ServiceBase {
26
26
  this.db = options?.db;
27
27
  this.documentFilter = options?.documentFilter;
28
28
  this.interceptor = options?.interceptor;
29
- this.collectionName = options?.collectionName;
30
- if (!this.collectionName) {
29
+ if (options?.collectionName)
30
+ this.collectionName = options?.collectionName;
31
+ else {
31
32
  if (typeof dataType === 'string')
32
33
  this.collectionName = dataType;
33
34
  if (typeof dataType === 'function') {
@@ -38,6 +38,7 @@ export class MongoCollectionService extends MongoEntityService {
38
38
  input,
39
39
  options,
40
40
  };
41
+ command.input._id = command.input._id ?? this._generateId(command);
41
42
  return this._executeCommand(command, () => this._create(command));
42
43
  }
43
44
  /**
@@ -60,13 +60,13 @@ export class MongoNestedService extends MongoService {
60
60
  input,
61
61
  options,
62
62
  };
63
+ command.input._id = command.input._id ?? this._generateId(command);
63
64
  return this._executeCommand(command, () => this._create(command));
64
65
  }
65
66
  async _create(command) {
66
67
  const inputCodec = this.getInputCodec('create');
67
68
  const { documentId, options } = command;
68
69
  const doc = inputCodec(command.input);
69
- doc._id = doc._id || this._generateId(command);
70
70
  const docFilter = MongoAdapter.prepareKeyValues(documentId, ['_id']);
71
71
  const r = await this._dbUpdateOne(docFilter, {
72
72
  $push: { [this.fieldName]: doc },
@@ -621,7 +621,7 @@ export class MongoNestedService extends MongoService {
621
621
  * This method is mostly used for security issues like securing multi-tenant applications.
622
622
  *
623
623
  * @protected
624
- * @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
624
+ * @returns {MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined} The common filter or a Promise
625
625
  * that resolves to the common filter, or undefined if not available.
626
626
  */
627
627
  _getNestedFilter(args) {
@@ -23,8 +23,9 @@ export class MongoService extends ServiceBase {
23
23
  this.db = options?.db;
24
24
  this.documentFilter = options?.documentFilter;
25
25
  this.interceptor = options?.interceptor;
26
- this.collectionName = options?.collectionName;
27
- if (!this.collectionName) {
26
+ if (options?.collectionName)
27
+ this.collectionName = options?.collectionName;
28
+ else {
28
29
  if (typeof dataType === 'string')
29
30
  this.collectionName = dataType;
30
31
  if (typeof dataType === 'function') {
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@opra/mongodb",
3
- "version": "1.0.0-alpha.38",
3
+ "version": "1.0.0-alpha.39",
4
4
  "description": "Opra MongoDB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "lodash.omit": "^4.5.0",
9
9
  "putil-isplainobject": "^1.1.5",
10
- "tslib": "^2.6.3",
10
+ "tslib": "^2.7.0",
11
11
  "valgen": "^5.9.0"
12
12
  },
13
13
  "peerDependencies": {
14
- "@opra/common": "^1.0.0-alpha.38",
15
- "@opra/core": "^1.0.0-alpha.38",
14
+ "@opra/common": "^1.0.0-alpha.39",
15
+ "@opra/core": "^1.0.0-alpha.39",
16
16
  "mongodb": ">= 6.0.0"
17
17
  },
18
18
  "type": "module",
@@ -1,4 +1,4 @@
1
1
  import { ComplexType, FieldsProjection } from '@opra/common';
2
- import mongodb, { Document } from 'mongodb';
2
+ import mongodb, { type Document } from 'mongodb';
3
3
  export default function prepareProjection(dataType: ComplexType, projection?: string | string[] | Document): mongodb.Document | undefined;
4
4
  export declare function prepare(dataType: ComplexType, target: mongodb.Document, projection?: FieldsProjection): void;
@@ -1,5 +1,5 @@
1
- import mongodb, { UpdateFilter } from 'mongodb';
2
- import { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
1
+ import mongodb, { type UpdateFilter } from 'mongodb';
2
+ import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
3
3
  import { MongoAdapter } from './mongo-adapter.js';
4
4
  import { MongoEntityService } from './mongo-entity-service.js';
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import mongodb from 'mongodb';
2
- import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
2
+ import type { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
3
3
  import { MongoService } from './mongo-service.js';
4
4
  /**
5
5
  *
@@ -1,9 +1,8 @@
1
1
  import { ComplexType } from '@opra/common';
2
2
  import mongodb from 'mongodb';
3
- import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
3
+ import type { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
4
4
  import { MongoAdapter } from './mongo-adapter.js';
5
5
  import { MongoService } from './mongo-service.js';
6
- import FilterInput = MongoAdapter.FilterInput;
7
6
  /**
8
7
  *
9
8
  * @namespace MongoNestedService
@@ -15,37 +14,37 @@ export declare namespace MongoNestedService {
15
14
  interface Options extends MongoService.Options {
16
15
  defaultLimit?: number;
17
16
  nestedKey?: string;
18
- nestedFilter?: FilterInput | ((args: MongoService.CommandInfo, _this: this) => FilterInput | Promise<FilterInput> | undefined);
17
+ nestedFilter?: MongoAdapter.FilterInput | ((args: MongoService.CommandInfo, _this: this) => MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined);
19
18
  }
20
19
  interface CommandInfo extends MongoService.CommandInfo {
21
20
  }
22
21
  interface CreateOptions extends MongoService.CreateOptions {
23
22
  }
24
23
  interface CountOptions<T> extends MongoService.CountOptions<T> {
25
- documentFilter?: FilterInput;
24
+ documentFilter?: MongoAdapter.FilterInput;
26
25
  }
27
26
  interface DeleteOptions<T> extends MongoService.DeleteOptions<T> {
28
- documentFilter?: FilterInput;
27
+ documentFilter?: MongoAdapter.FilterInput;
29
28
  }
30
29
  interface DeleteManyOptions<T> extends MongoService.DeleteManyOptions<T> {
31
- documentFilter?: FilterInput;
30
+ documentFilter?: MongoAdapter.FilterInput;
32
31
  }
33
32
  interface ExistsOptions<T> extends MongoService.ExistsOptions<T> {
34
33
  }
35
34
  interface ExistsOneOptions<T> extends MongoService.ExistsOneOptions<T> {
36
35
  }
37
36
  interface FindOneOptions<T> extends MongoService.FindOneOptions<T> {
38
- documentFilter?: FilterInput;
37
+ documentFilter?: MongoAdapter.FilterInput;
39
38
  }
40
39
  interface FindManyOptions<T> extends MongoService.FindManyOptions<T> {
41
- documentFilter?: FilterInput;
42
- nestedFilter?: FilterInput;
40
+ documentFilter?: MongoAdapter.FilterInput;
41
+ nestedFilter?: MongoAdapter.FilterInput;
43
42
  }
44
43
  interface UpdateOneOptions<T> extends MongoService.UpdateOneOptions<T> {
45
- documentFilter?: FilterInput;
44
+ documentFilter?: MongoAdapter.FilterInput;
46
45
  }
47
46
  interface UpdateManyOptions<T> extends MongoService.UpdateManyOptions<T> {
48
- documentFilter?: FilterInput;
47
+ documentFilter?: MongoAdapter.FilterInput;
49
48
  count?: boolean;
50
49
  }
51
50
  interface CreateCommand extends RequiredSome<CommandInfo, 'documentId' | 'input'> {
@@ -112,7 +111,7 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
112
111
  *
113
112
  * @type {FilterInput | Function}
114
113
  */
115
- nestedFilter?: FilterInput | ((args: MongoService.CommandInfo, _this: this) => FilterInput | Promise<FilterInput> | undefined);
114
+ nestedFilter?: MongoAdapter.FilterInput | ((args: MongoService.CommandInfo, _this: this) => MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined);
116
115
  /**
117
116
  * Constructs a new instance
118
117
  *
@@ -296,8 +295,8 @@ export declare class MongoNestedService<T extends mongodb.Document> extends Mong
296
295
  * This method is mostly used for security issues like securing multi-tenant applications.
297
296
  *
298
297
  * @protected
299
- * @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
298
+ * @returns {MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined} The common filter or a Promise
300
299
  * that resolves to the common filter, or undefined if not available.
301
300
  */
302
- protected _getNestedFilter(args: MongoService.CommandInfo): FilterInput | Promise<FilterInput> | undefined;
301
+ protected _getNestedFilter(args: MongoService.CommandInfo): MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined;
303
302
  }
@@ -1,9 +1,8 @@
1
- import * as OpraCommon from '@opra/common';
2
- import { ComplexType } from '@opra/common';
1
+ import { ComplexType, type OpraFilter } from '@opra/common';
3
2
  import { HttpContext, ServiceBase } from '@opra/core';
4
- import mongodb, { Document, TransactionOptions } from 'mongodb';
5
- import { Nullish, PartialDTO, StrictOmit, Type } from 'ts-gems';
6
- import { IsObject } from 'valgen';
3
+ import mongodb, { type Document, type TransactionOptions } from 'mongodb';
4
+ import type { Nullish, PartialDTO, StrictOmit, Type } from 'ts-gems';
5
+ import type { IsObject } from 'valgen';
7
6
  import { MongoAdapter } from './mongo-adapter.js';
8
7
  /**
9
8
  * The namespace for the MongoService.
@@ -31,7 +30,7 @@ export declare namespace MongoService {
31
30
  input?: any;
32
31
  options?: any;
33
32
  }
34
- type CommonFilter = MongoAdapter.FilterInput | ((args: MongoService.CommandInfo, _this: MongoService<any>) => MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined);
33
+ type DocumentFilter = MongoAdapter.FilterInput | ((args: CommandInfo, _this: MongoService<any>) => MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined);
35
34
  /**
36
35
  * Represents options for "create" operation
37
36
  *
@@ -47,7 +46,7 @@ export declare namespace MongoService {
47
46
  * @template T - The type of the document.
48
47
  */
49
48
  interface CountOptions<T> extends mongodb.CountOptions {
50
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
49
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
51
50
  }
52
51
  /**
53
52
  * Represents options for "delete" operation
@@ -56,7 +55,7 @@ export declare namespace MongoService {
56
55
  * @template T - The type of the document.
57
56
  */
58
57
  interface DeleteOptions<T> extends mongodb.DeleteOptions {
59
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
58
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
60
59
  }
61
60
  /**
62
61
  * Represents options for "deleteMany" operation
@@ -65,7 +64,7 @@ export declare namespace MongoService {
65
64
  * @template T - The type of the document.
66
65
  */
67
66
  interface DeleteManyOptions<T> extends mongodb.DeleteOptions {
68
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
67
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
69
68
  }
70
69
  /**
71
70
  * Represents options for "distinct" operation
@@ -74,7 +73,7 @@ export declare namespace MongoService {
74
73
  * @template T - The type of the document.
75
74
  */
76
75
  interface DistinctOptions<T> extends mongodb.DistinctOptions {
77
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
76
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
78
77
  }
79
78
  /**
80
79
  * Represents options for "exists" operation
@@ -82,7 +81,7 @@ export declare namespace MongoService {
82
81
  * @interface
83
82
  */
84
83
  interface ExistsOptions<T> extends Omit<mongodb.CommandOperationOptions, 'writeConcern'> {
85
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
84
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
86
85
  }
87
86
  /**
88
87
  * Represents options for checking the document exists
@@ -90,7 +89,7 @@ export declare namespace MongoService {
90
89
  * @interface
91
90
  */
92
91
  interface ExistsOneOptions<T> extends Omit<mongodb.CommandOperationOptions, 'writeConcern'> {
93
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
92
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
94
93
  }
95
94
  /**
96
95
  * Represents options for "findOne" operation
@@ -107,7 +106,7 @@ export declare namespace MongoService {
107
106
  * @template T - The type of the document.
108
107
  */
109
108
  interface FindManyOptions<T> extends mongodb.AggregateOptions {
110
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
109
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
111
110
  projection?: string | string[] | Document;
112
111
  sort?: string[];
113
112
  limit?: number;
@@ -121,7 +120,7 @@ export declare namespace MongoService {
121
120
  */
122
121
  interface UpdateOneOptions<T> extends StrictOmit<mongodb.FindOneAndUpdateOptions, 'projection' | 'returnDocument' | 'includeResultMetadata'> {
123
122
  projection?: string | string[] | Document;
124
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
123
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
125
124
  }
126
125
  /**
127
126
  * Represents options for "updateMany" operation
@@ -130,7 +129,7 @@ export declare namespace MongoService {
130
129
  * @template T - The type of the document.
131
130
  */
132
131
  interface UpdateManyOptions<T> extends StrictOmit<mongodb.UpdateOptions, 'upsert'> {
133
- filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
132
+ filter?: mongodb.Filter<T> | OpraFilter.Ast | string;
134
133
  }
135
134
  }
136
135
  export interface MongoService {
@@ -188,7 +187,7 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
188
187
  *
189
188
  * @type {FilterInput | Function}
190
189
  */
191
- documentFilter?: MongoService.CommonFilter | MongoService.CommonFilter[];
190
+ documentFilter?: MongoService.DocumentFilter | MongoService.DocumentFilter[];
192
191
  /**
193
192
  * Constructs a new instance
194
193
  *
@@ -1,5 +1,5 @@
1
- import mongodb, { UpdateFilter } from 'mongodb';
2
- import { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
1
+ import mongodb, { type UpdateFilter } from 'mongodb';
2
+ import type { PartialDTO, PatchDTO, RequiredSome, Type } from 'ts-gems';
3
3
  import { MongoAdapter } from './mongo-adapter.js';
4
4
  import { MongoEntityService } from './mongo-entity-service.js';
5
5
  /**