@orion-js/mongodb 3.3.7 → 3.3.9

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
- const prefix = options.idPrefix || '';
8
- const random = (0, helpers_1.generateId)();
9
- return () => `${prefix}${random}`;
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();
@@ -55,3 +55,30 @@ it('generates a ids with a prefix', async () => {
55
55
  await Tests.updateOne({ _id: 'pref_123' }, { $set: { name: 'Nicolás' } });
56
56
  expect(userId).toMatch(/^pref_/);
57
57
  });
58
+ it('generates a ids with a distinct type', async () => {
59
+ let Schema = class Schema {
60
+ };
61
+ __decorate([
62
+ (0, typed_model_1.Prop)(),
63
+ __metadata("design:type", String)
64
+ ], Schema.prototype, "_id", void 0);
65
+ __decorate([
66
+ (0, typed_model_1.Prop)(),
67
+ __metadata("design:type", String)
68
+ ], Schema.prototype, "name", void 0);
69
+ Schema = __decorate([
70
+ (0, typed_model_1.TypedSchema)()
71
+ ], Schema);
72
+ const Tests = (0, index_1.default)({
73
+ name: (0, helpers_1.generateId)(),
74
+ schema: Schema
75
+ });
76
+ const userId = await Tests.insertOne({
77
+ name: 'Nico'
78
+ });
79
+ await Tests.findOne(userId);
80
+ // This should throw an error
81
+ // await Tests.findOne(anId)
82
+ const anId = '123';
83
+ await Tests.findOne(anId);
84
+ });
@@ -111,7 +111,7 @@ export interface CreateCollectionOptions<ModelClass extends ModelClassBase = Mod
111
111
  */
112
112
  idGeneration?: 'mongo' | 'random';
113
113
  /**
114
- * ID prefix. Only used if idGeneration is random. Recommended for type checking
114
+ * ID prefix. idGeneration will be forced to random. Recommended for type checking
115
115
  */
116
116
  idPrefix?: ModelClass['_id'];
117
117
  }
@@ -166,4 +166,7 @@ export interface Collection<ModelClass extends ModelClassBase = ModelClassBase>
166
166
  createIndexesPromise: Promise<string[]>;
167
167
  connectionPromise: Promise<MongoDB.MongoClient>;
168
168
  }
169
+ export declare type DistinctDocumentId<DistinctId extends string> = string & {
170
+ __TYPE__: `DistinctDocumentId<${DistinctId}>`;
171
+ };
169
172
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/mongodb",
3
- "version": "3.3.7",
3
+ "version": "3.3.9",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -20,11 +20,11 @@
20
20
  "@orion-js/env": "^3.3.6",
21
21
  "@orion-js/helpers": "^3.3.6",
22
22
  "@orion-js/logger": "^3.3.6",
23
- "@orion-js/models": "^3.3.6",
24
- "@orion-js/resolvers": "^3.3.6",
25
- "@orion-js/schema": "^3.3.6",
23
+ "@orion-js/models": "^3.3.9",
24
+ "@orion-js/resolvers": "^3.3.9",
25
+ "@orion-js/schema": "^3.3.9",
26
26
  "@orion-js/services": "^3.3.6",
27
- "@orion-js/typed-model": "^3.3.6",
27
+ "@orion-js/typed-model": "^3.3.9",
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": "96be819f20c79ca01714dfc0c33a7dd38b78915e"
44
+ "gitHead": "c9591d61fe15eb98c6b6d5c3773afab11c412e42"
45
45
  }