@orion-js/mongodb 3.0.32 → 3.0.38

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.
@@ -54,3 +54,23 @@ it('should validate a document', async () => {
54
54
  expect(error.code).toBe('validationError');
55
55
  }
56
56
  });
57
+ it('Should be able to use custom clean for models', async () => {
58
+ const model = (0, models_1.createModel)({
59
+ name: 'File',
60
+ schema: {
61
+ name: { type: String }
62
+ },
63
+ async clean(value) {
64
+ if (!value)
65
+ return null;
66
+ return {
67
+ ...value,
68
+ name: value.name.toUpperCase() + value._id
69
+ };
70
+ }
71
+ });
72
+ const Tests = (0, __1.default)({ name: (0, helpers_1.generateId)(), model });
73
+ const docId = await Tests.insertOne({ name: 'hello' });
74
+ const result = await Tests.findOne(docId);
75
+ expect(result.name).toBe('HELLO' + docId);
76
+ });
@@ -225,3 +225,63 @@ it('should pass full doc on clean as well as validate', async () => {
225
225
  });
226
226
  await Tests.updateOne({}, { $set: { name: 'Nico' } });
227
227
  });
228
+ it('Should allow custom clean function on a blackbox field', async () => {
229
+ const model = (0, models_1.createModel)({
230
+ name: 'Item',
231
+ schema: {
232
+ info: {
233
+ type: 'blackbox',
234
+ optional: true,
235
+ async clean(info, { doc }) {
236
+ return { hello: 'world' };
237
+ }
238
+ }
239
+ }
240
+ });
241
+ const Tests = (0, __1.default)({
242
+ name: (0, helpers_1.generateId)(),
243
+ model
244
+ });
245
+ const itemId = await Tests.insertOne({ info: { hello: 'world2' } });
246
+ await Tests.updateOne(itemId, { $set: { info: { hello: 'world444' } } });
247
+ const item = await Tests.findOne(itemId);
248
+ expect(item).toEqual({ _id: itemId, info: { hello: 'world' } });
249
+ });
250
+ it('Should be able to use custom clean for models on update', async () => {
251
+ const modelFile = (0, models_1.createModel)({
252
+ name: 'File',
253
+ schema: {
254
+ name: { type: String },
255
+ lastName: { type: String, optional: true }
256
+ },
257
+ async clean(value) {
258
+ if (!value)
259
+ return null;
260
+ expect(typeof value.name).toBe('string');
261
+ return {
262
+ ...value,
263
+ name: value.name.toUpperCase(),
264
+ lastName: '1'
265
+ };
266
+ }
267
+ });
268
+ const model = (0, models_1.createModel)({
269
+ name: 'Item',
270
+ schema: {
271
+ file: { type: modelFile }
272
+ }
273
+ });
274
+ const Tests = (0, __1.default)({ name: (0, helpers_1.generateId)(), model });
275
+ const docId = await Tests.insertOne({
276
+ file: { name: '1' }
277
+ });
278
+ await Tests.updateOne(docId, {
279
+ $set: {
280
+ file: { name: 'Hello' }
281
+ }
282
+ });
283
+ const result = await Tests.findOne(docId);
284
+ expect(result.file.name).toBe('HELLO');
285
+ expect(result.file.lastName).toBe('1');
286
+ expect.assertions(4);
287
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/mongodb",
3
- "version": "3.0.32",
3
+ "version": "3.0.38",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -17,11 +17,11 @@
17
17
  "upgrade-interactive": "yarn upgrade-interactive"
18
18
  },
19
19
  "dependencies": {
20
- "@orion-js/helpers": "^3.0.31",
21
- "@orion-js/models": "^3.0.32",
22
- "@orion-js/resolvers": "^3.0.32",
23
- "@orion-js/schema": "^3.0.32",
24
- "@orion-js/typed-model": "^3.0.32",
20
+ "@orion-js/helpers": "^3.0.36",
21
+ "@orion-js/models": "^3.0.38",
22
+ "@orion-js/resolvers": "^3.0.37",
23
+ "@orion-js/schema": "^3.0.37",
24
+ "@orion-js/typed-model": "^3.0.38",
25
25
  "dataloader": "2.0.0",
26
26
  "dot-object": "2.1.4",
27
27
  "mongodb": "4.1.4"
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "8d6dfbbd6fbf5aed082e9d67df81d09db580b015"
41
+ "gitHead": "00903f1488b72e13b7d5031a916eb897d0d80e0c"
42
42
  }