@orion-js/mongodb 3.0.36 → 3.0.41
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.
- package/lib/createCollection/createIndexes.test.js +27 -3
- package/lib/createCollection/getMethods/insertOne.test.js +20 -0
- package/lib/createCollection/getMethods/update.test.js +60 -0
- package/lib/createCollection/index.d.ts +1 -0
- package/lib/createCollection/index.js +5 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +15 -5
- package/package.json +6 -6
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
4
20
|
};
|
|
5
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
22
|
const helpers_1 = require("@orion-js/helpers");
|
|
7
|
-
const _1 =
|
|
23
|
+
const _1 = __importStar(require("."));
|
|
8
24
|
describe('Test indexes', () => {
|
|
25
|
+
it('Should store all create indexes promises in the array', async () => {
|
|
26
|
+
const collection = (0, _1.default)({
|
|
27
|
+
name: (0, helpers_1.generateId)(),
|
|
28
|
+
indexes: [{ keys: { a: 1 }, options: { unique: true } }]
|
|
29
|
+
});
|
|
30
|
+
expect(_1.createIndexesPromises[0]).toBe(collection.createIndexesPromise);
|
|
31
|
+
expect(_1.createIndexesPromises.length).toBe(1);
|
|
32
|
+
});
|
|
9
33
|
it('Should create collection indexes correctly', async () => {
|
|
10
34
|
const collection = (0, _1.default)({
|
|
11
35
|
name: (0, helpers_1.generateId)(),
|
|
@@ -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
|
+
});
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createIndexesPromises = void 0;
|
|
6
7
|
const initItem_1 = __importDefault(require("./initItem"));
|
|
7
8
|
const getMethods_1 = require("./getMethods");
|
|
8
9
|
const dataLoader_1 = require("./getMethods/dataLoader");
|
|
@@ -10,6 +11,7 @@ const generateId_1 = __importDefault(require("./generateId"));
|
|
|
10
11
|
const createIndexes_1 = require("./createIndexes");
|
|
11
12
|
const lodash_1 = require("lodash");
|
|
12
13
|
const __1 = require("..");
|
|
14
|
+
exports.createIndexesPromises = [];
|
|
13
15
|
const createCollection = (options) => {
|
|
14
16
|
const connectionName = options.connectionName || 'main';
|
|
15
17
|
const orionConnection = (0, __1.getMongoConnection)({ name: connectionName });
|
|
@@ -63,7 +65,9 @@ const createCollection = (options) => {
|
|
|
63
65
|
collection.loadById = (0, dataLoader_1.loadById)(collection);
|
|
64
66
|
collection.loadOne = (0, dataLoader_1.loadOne)(collection);
|
|
65
67
|
collection.loadMany = (0, dataLoader_1.loadMany)(collection);
|
|
66
|
-
|
|
68
|
+
const createIndexPromise = (0, createIndexes_1.loadIndexes)(collection);
|
|
69
|
+
exports.createIndexesPromises.push(createIndexPromise);
|
|
70
|
+
collection.createIndexesPromise = createIndexPromise;
|
|
67
71
|
return collection;
|
|
68
72
|
};
|
|
69
73
|
exports.default = createCollection;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import createCollection from './createCollection';
|
|
2
|
-
export { createCollection };
|
|
1
|
+
import createCollection, { createIndexesPromises } from './createCollection';
|
|
2
|
+
export { createCollection, createIndexesPromises };
|
|
3
3
|
export * from './connect';
|
|
4
4
|
export * from './types';
|
package/lib/index.js
CHANGED
|
@@ -6,15 +6,25 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
9
21
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
22
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
23
|
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.createCollection = void 0;
|
|
17
|
-
const createCollection_1 =
|
|
25
|
+
exports.createIndexesPromises = exports.createCollection = void 0;
|
|
26
|
+
const createCollection_1 = __importStar(require("./createCollection"));
|
|
18
27
|
exports.createCollection = createCollection_1.default;
|
|
28
|
+
Object.defineProperty(exports, "createIndexesPromises", { enumerable: true, get: function () { return createCollection_1.createIndexesPromises; } });
|
|
19
29
|
__exportStar(require("./connect"), exports);
|
|
20
30
|
__exportStar(require("./types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/mongodb",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.41",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/helpers": "^3.0.36",
|
|
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.
|
|
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": "
|
|
41
|
+
"gitHead": "9b3b84b2e968a20ecf45d252201ad911f12c8aa0"
|
|
42
42
|
}
|