@orion-js/mongodb 3.0.31 → 3.0.37
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,25 @@ 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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.37",
|
|
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.
|
|
21
|
-
"@orion-js/models": "^3.0.
|
|
22
|
-
"@orion-js/resolvers": "^3.0.
|
|
23
|
-
"@orion-js/schema": "^3.0.
|
|
24
|
-
"@orion-js/typed-model": "^3.0.
|
|
20
|
+
"@orion-js/helpers": "^3.0.36",
|
|
21
|
+
"@orion-js/models": "^3.0.37",
|
|
22
|
+
"@orion-js/resolvers": "^3.0.37",
|
|
23
|
+
"@orion-js/schema": "^3.0.37",
|
|
24
|
+
"@orion-js/typed-model": "^3.0.37",
|
|
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": "
|
|
41
|
+
"gitHead": "741691d7603f3d42e6e3e8fa9dc0f9de51a29424"
|
|
42
42
|
}
|