@orion-js/mongodb 3.3.6 → 3.3.8
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.
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const helpers_1 = require("@orion-js/helpers");
|
|
4
4
|
const bson_1 = require("bson");
|
|
5
5
|
const getIdGenerator = (options) => {
|
|
6
|
-
if (options.idGeneration === 'random') {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
if (options.idPrefix || options.idGeneration === 'random') {
|
|
7
|
+
return () => {
|
|
8
|
+
const prefix = options.idPrefix || '';
|
|
9
|
+
const random = (0, helpers_1.generateId)();
|
|
10
|
+
return `${prefix}${random}`;
|
|
11
|
+
};
|
|
10
12
|
}
|
|
11
13
|
return () => {
|
|
12
14
|
const id = new bson_1.ObjectID();
|
package/lib/service/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CreateCollectionOptions } from '../types';
|
|
2
|
-
export declare function MongoCollection(options: CreateCollectionOptions): (object: any, propertyName: string, index?: number) => void;
|
|
1
|
+
import { CreateCollectionOptions, ModelClassBase } from '../types';
|
|
2
|
+
export declare function MongoCollection<ModelClass extends ModelClassBase = ModelClassBase>(options: CreateCollectionOptions<ModelClass>): (object: any, propertyName: string, index?: number) => void;
|
|
3
3
|
export declare function Repository(): ClassDecorator;
|
|
@@ -36,7 +36,12 @@ describe('Collection as IOC', () => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
__decorate([
|
|
39
|
-
(0, _1.MongoCollection)({
|
|
39
|
+
(0, _1.MongoCollection)({
|
|
40
|
+
name: 'users',
|
|
41
|
+
schema: User,
|
|
42
|
+
idGeneration: 'random',
|
|
43
|
+
idPrefix: 'user_'
|
|
44
|
+
}),
|
|
40
45
|
__metadata("design:type", Object)
|
|
41
46
|
], UserRepo.prototype, "users", void 0);
|
|
42
47
|
UserRepo = __decorate([
|
package/lib/types/index.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export interface CreateCollectionOptions<ModelClass extends ModelClassBase = Mod
|
|
|
111
111
|
*/
|
|
112
112
|
idGeneration?: 'mongo' | 'random';
|
|
113
113
|
/**
|
|
114
|
-
* ID prefix.
|
|
114
|
+
* ID prefix. idGeneration will be forced to random. Recommended for type checking
|
|
115
115
|
*/
|
|
116
116
|
idPrefix?: ModelClass['_id'];
|
|
117
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.8",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "78e2d748683f8b4df0e78d349eb05cb6da56e910"
|
|
45
45
|
}
|