@orion-js/mongodb 3.6.1 → 3.6.4
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,7 +3,14 @@ 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.idPrefix || options.idGeneration === '
|
|
6
|
+
if (options.idPrefix || options.idGeneration === 'uuid') {
|
|
7
|
+
return () => {
|
|
8
|
+
const prefix = options.idPrefix || '';
|
|
9
|
+
const random = (0, helpers_1.generateUUID)();
|
|
10
|
+
return `${prefix}${random}`;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
if (options.idGeneration === 'random') {
|
|
7
14
|
return () => {
|
|
8
15
|
const prefix = options.idPrefix || '';
|
|
9
16
|
const random = (0, helpers_1.generateId)();
|
|
@@ -27,6 +27,30 @@ it('generates a usable mongo objectId as string', async () => {
|
|
|
27
27
|
const diff = now.valueOf() - objectId.getTimestamp().valueOf();
|
|
28
28
|
expect(diff).toBeGreaterThan(0);
|
|
29
29
|
});
|
|
30
|
+
it('generates a ids with uuidv4', async () => {
|
|
31
|
+
let Schema = class Schema {
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typed_model_1.Prop)(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], Schema.prototype, "_id", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typed_model_1.Prop)(),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], Schema.prototype, "name", void 0);
|
|
41
|
+
Schema = __decorate([
|
|
42
|
+
(0, typed_model_1.TypedSchema)()
|
|
43
|
+
], Schema);
|
|
44
|
+
const Tests = (0, index_1.default)({
|
|
45
|
+
name: (0, helpers_1.generateId)(),
|
|
46
|
+
schema: Schema,
|
|
47
|
+
idPrefix: 'prefix-'
|
|
48
|
+
});
|
|
49
|
+
const userId = await Tests.insertOne({
|
|
50
|
+
name: 'Nico'
|
|
51
|
+
});
|
|
52
|
+
expect(userId).toMatch(/^prefix\-/);
|
|
53
|
+
});
|
|
30
54
|
it('generates a ids with a prefix', async () => {
|
|
31
55
|
let Schema = class Schema {
|
|
32
56
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -115,7 +115,7 @@ export interface CreateCollectionOptions<ModelClass extends ModelClassBase = Mod
|
|
|
115
115
|
/**
|
|
116
116
|
* Select between random id generation o mongo (time based) id generation
|
|
117
117
|
*/
|
|
118
|
-
idGeneration?: 'mongo' | 'random';
|
|
118
|
+
idGeneration?: 'mongo' | 'random' | 'uuid';
|
|
119
119
|
/**
|
|
120
120
|
* ID prefix. idGeneration will be forced to random. Recommended for type checking
|
|
121
121
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.4",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/env": "^3.5.0",
|
|
21
|
-
"@orion-js/helpers": "^3.
|
|
21
|
+
"@orion-js/helpers": "^3.6.4",
|
|
22
22
|
"@orion-js/logger": "^3.5.0",
|
|
23
|
-
"@orion-js/models": "^3.6.
|
|
24
|
-
"@orion-js/resolvers": "^3.6.
|
|
23
|
+
"@orion-js/models": "^3.6.4",
|
|
24
|
+
"@orion-js/resolvers": "^3.6.4",
|
|
25
25
|
"@orion-js/schema": "^3.6.1",
|
|
26
|
-
"@orion-js/services": "^3.
|
|
27
|
-
"@orion-js/typed-model": "^3.6.
|
|
26
|
+
"@orion-js/services": "^3.6.4",
|
|
27
|
+
"@orion-js/typed-model": "^3.6.4",
|
|
28
28
|
"dataloader": "2.1.0",
|
|
29
29
|
"dot-object": "2.1.4",
|
|
30
30
|
"mongodb": "4.5.0"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "28e1115114bc59d456f9a07cbde8ce9bd9521bb9"
|
|
45
45
|
}
|