@orion-js/mongodb 3.11.8 → 3.12.0
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/README.md +15 -0
- package/dist/index.cjs +81990 -0
- package/dist/index.d.ts +204 -0
- package/dist/index.js +81964 -0
- package/package.json +29 -27
- package/LICENSE +0 -21
- package/lib/connect/connections.d.ts +0 -13
- package/lib/connect/connections.js +0 -4
- package/lib/connect/getDBName.d.ts +0 -1
- package/lib/connect/getDBName.js +0 -23
- package/lib/connect/getMongoConnection.d.ts +0 -8
- package/lib/connect/getMongoConnection.js +0 -47
- package/lib/connect/getMongoConnection.test.d.ts +0 -1
- package/lib/connect/getMongoConnection.test.js +0 -43
- package/lib/connect/getMongoURLFromEnv.d.ts +0 -1
- package/lib/connect/getMongoURLFromEnv.js +0 -21
- package/lib/connect/index.d.ts +0 -4
- package/lib/connect/index.js +0 -8
- package/lib/createCollection/createIndexPromisesTest.d.ts +0 -1
- package/lib/createCollection/createIndexPromisesTest.js +0 -12
- package/lib/createCollection/createIndexes.d.ts +0 -3
- package/lib/createCollection/createIndexes.js +0 -67
- package/lib/createCollection/createIndexes.test.d.ts +0 -1
- package/lib/createCollection/createIndexes.test.js +0 -91
- package/lib/createCollection/createIndexesPromise.test.d.ts +0 -1
- package/lib/createCollection/createIndexesPromise.test.js +0 -32
- package/lib/createCollection/generateId.d.ts +0 -3
- package/lib/createCollection/generateId.js +0 -25
- package/lib/createCollection/generateId.test.d.ts +0 -1
- package/lib/createCollection/generateId.test.js +0 -108
- package/lib/createCollection/getMethods/aggregate.test.d.ts +0 -1
- package/lib/createCollection/getMethods/aggregate.test.js +0 -20
- package/lib/createCollection/getMethods/cleanModifier.d.ts +0 -4
- package/lib/createCollection/getMethods/cleanModifier.js +0 -75
- package/lib/createCollection/getMethods/cleanModifier.test.d.ts +0 -1
- package/lib/createCollection/getMethods/cleanModifier.test.js +0 -186
- package/lib/createCollection/getMethods/countDocuments.d.ts +0 -2
- package/lib/createCollection/getMethods/countDocuments.js +0 -16
- package/lib/createCollection/getMethods/countDocuments.test.d.ts +0 -1
- package/lib/createCollection/getMethods/countDocuments.test.js +0 -21
- package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.d.ts +0 -9
- package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.js +0 -25
- package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.test.d.ts +0 -1
- package/lib/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.test.js +0 -37
- package/lib/createCollection/getMethods/dataLoader/dataLoad/index.d.ts +0 -9
- package/lib/createCollection/getMethods/dataLoader/dataLoad/index.js +0 -21
- package/lib/createCollection/getMethods/dataLoader/index.d.ts +0 -5
- package/lib/createCollection/getMethods/dataLoader/index.js +0 -14
- package/lib/createCollection/getMethods/dataLoader/loadById.d.ts +0 -2
- package/lib/createCollection/getMethods/dataLoader/loadById.js +0 -13
- package/lib/createCollection/getMethods/dataLoader/loadById.test.d.ts +0 -1
- package/lib/createCollection/getMethods/dataLoader/loadById.test.js +0 -23
- package/lib/createCollection/getMethods/dataLoader/loadData.d.ts +0 -2
- package/lib/createCollection/getMethods/dataLoader/loadData.js +0 -49
- package/lib/createCollection/getMethods/dataLoader/loadMany.d.ts +0 -2
- package/lib/createCollection/getMethods/dataLoader/loadMany.js +0 -10
- package/lib/createCollection/getMethods/dataLoader/loadMany.test.d.ts +0 -1
- package/lib/createCollection/getMethods/dataLoader/loadMany.test.js +0 -85
- package/lib/createCollection/getMethods/dataLoader/loadOne.d.ts +0 -2
- package/lib/createCollection/getMethods/dataLoader/loadOne.js +0 -10
- package/lib/createCollection/getMethods/dataLoader/loadOne.test.d.ts +0 -1
- package/lib/createCollection/getMethods/dataLoader/loadOne.test.js +0 -76
- package/lib/createCollection/getMethods/deleteMany.d.ts +0 -2
- package/lib/createCollection/getMethods/deleteMany.js +0 -16
- package/lib/createCollection/getMethods/deleteOne.d.ts +0 -2
- package/lib/createCollection/getMethods/deleteOne.js +0 -16
- package/lib/createCollection/getMethods/estimatedDocumentCount.d.ts +0 -3
- package/lib/createCollection/getMethods/estimatedDocumentCount.js +0 -10
- package/lib/createCollection/getMethods/estimatedDocumentCount.test.d.ts +0 -1
- package/lib/createCollection/getMethods/estimatedDocumentCount.test.js +0 -15
- package/lib/createCollection/getMethods/find.d.ts +0 -2
- package/lib/createCollection/getMethods/find.js +0 -21
- package/lib/createCollection/getMethods/findOne.d.ts +0 -2
- package/lib/createCollection/getMethods/findOne.js +0 -18
- package/lib/createCollection/getMethods/findOneAndUpdate.d.ts +0 -3
- package/lib/createCollection/getMethods/findOneAndUpdate.js +0 -29
- package/lib/createCollection/getMethods/findOneAndUpdate.test.d.ts +0 -1
- package/lib/createCollection/getMethods/findOneAndUpdate.test.js +0 -15
- package/lib/createCollection/getMethods/getSelector.d.ts +0 -3
- package/lib/createCollection/getMethods/getSelector.js +0 -21
- package/lib/createCollection/getMethods/getSelector.test.d.ts +0 -1
- package/lib/createCollection/getMethods/getSelector.test.js +0 -46
- package/lib/createCollection/getMethods/index.d.ts +0 -16
- package/lib/createCollection/getMethods/index.js +0 -36
- package/lib/createCollection/getMethods/insertAndFind.d.ts +0 -3
- package/lib/createCollection/getMethods/insertAndFind.js +0 -31
- package/lib/createCollection/getMethods/insertAndFind.test.d.ts +0 -1
- package/lib/createCollection/getMethods/insertAndFind.test.js +0 -50
- package/lib/createCollection/getMethods/insertMany.d.ts +0 -3
- package/lib/createCollection/getMethods/insertMany.js +0 -36
- package/lib/createCollection/getMethods/insertMany.test.d.ts +0 -1
- package/lib/createCollection/getMethods/insertMany.test.js +0 -66
- package/lib/createCollection/getMethods/insertOne.d.ts +0 -3
- package/lib/createCollection/getMethods/insertOne.js +0 -31
- package/lib/createCollection/getMethods/insertOne.test.d.ts +0 -1
- package/lib/createCollection/getMethods/insertOne.test.js +0 -104
- package/lib/createCollection/getMethods/update.test.d.ts +0 -1
- package/lib/createCollection/getMethods/update.test.js +0 -287
- package/lib/createCollection/getMethods/updateAndFind.d.ts +0 -3
- package/lib/createCollection/getMethods/updateAndFind.js +0 -18
- package/lib/createCollection/getMethods/updateAndFind.test.d.ts +0 -1
- package/lib/createCollection/getMethods/updateAndFind.test.js +0 -38
- package/lib/createCollection/getMethods/updateItem.d.ts +0 -2
- package/lib/createCollection/getMethods/updateItem.js +0 -19
- package/lib/createCollection/getMethods/updateItem.test.d.ts +0 -1
- package/lib/createCollection/getMethods/updateItem.test.js +0 -38
- package/lib/createCollection/getMethods/updateMany.d.ts +0 -3
- package/lib/createCollection/getMethods/updateMany.js +0 -30
- package/lib/createCollection/getMethods/updateOne.d.ts +0 -3
- package/lib/createCollection/getMethods/updateOne.js +0 -30
- package/lib/createCollection/getMethods/upsert.d.ts +0 -3
- package/lib/createCollection/getMethods/upsert.js +0 -31
- package/lib/createCollection/getMethods/upsert.test.d.ts +0 -1
- package/lib/createCollection/getMethods/upsert.test.js +0 -92
- package/lib/createCollection/getMethods/validateModifier/index.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/index.js +0 -18
- package/lib/createCollection/getMethods/validateModifier/index.test.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/index.test.js +0 -74
- package/lib/createCollection/getMethods/validateModifier/validateInc.d.ts +0 -7
- package/lib/createCollection/getMethods/validateModifier/validateInc.js +0 -20
- package/lib/createCollection/getMethods/validateModifier/validateInc.test.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/validateInc.test.js +0 -12
- package/lib/createCollection/getMethods/validateModifier/validateOperator.d.ts +0 -5
- package/lib/createCollection/getMethods/validateModifier/validateOperator.js +0 -34
- package/lib/createCollection/getMethods/validateModifier/validatePush.d.ts +0 -8
- package/lib/createCollection/getMethods/validateModifier/validatePush.js +0 -27
- package/lib/createCollection/getMethods/validateModifier/validatePush.test.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/validatePush.test.js +0 -90
- package/lib/createCollection/getMethods/validateModifier/validateSet.d.ts +0 -7
- package/lib/createCollection/getMethods/validateModifier/validateSet.js +0 -19
- package/lib/createCollection/getMethods/validateModifier/validateSet.test.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/validateSet.test.js +0 -16
- package/lib/createCollection/getMethods/validateModifier/validateUnset.d.ts +0 -7
- package/lib/createCollection/getMethods/validateModifier/validateUnset.js +0 -19
- package/lib/createCollection/getMethods/validateModifier/validateUnset.test.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/validateUnset.test.js +0 -71
- package/lib/createCollection/getMethods/validateModifier/validateUpsert.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/validateUpsert.js +0 -43
- package/lib/createCollection/getMethods/validateModifier/validateUpsert.test.d.ts +0 -1
- package/lib/createCollection/getMethods/validateModifier/validateUpsert.test.js +0 -50
- package/lib/createCollection/getMethods/wrapErrors.d.ts +0 -1
- package/lib/createCollection/getMethods/wrapErrors.js +0 -29
- package/lib/createCollection/getSchemaAndModel.d.ts +0 -10
- package/lib/createCollection/getSchemaAndModel.js +0 -41
- package/lib/createCollection/handleError.d.ts +0 -1
- package/lib/createCollection/handleError.js +0 -25
- package/lib/createCollection/index.d.ts +0 -4
- package/lib/createCollection/index.js +0 -77
- package/lib/createCollection/initItem.d.ts +0 -2
- package/lib/createCollection/initItem.js +0 -13
- package/lib/createCollection/typedModel.test.d.ts +0 -1
- package/lib/createCollection/typedModel.test.js +0 -159
- package/lib/helpers/fromDot.d.ts +0 -1
- package/lib/helpers/fromDot.js +0 -12
- package/lib/helpers/fromDot.test.d.ts +0 -1
- package/lib/helpers/fromDot.test.js +0 -47
- package/lib/helpers/toDot.d.ts +0 -1
- package/lib/helpers/toDot.js +0 -11
- package/lib/helpers/toDot.test.d.ts +0 -1
- package/lib/helpers/toDot.test.js +0 -23
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -35
- package/lib/service/index.d.ts +0 -3
- package/lib/service/index.js +0 -32
- package/lib/service/index.test.d.ts +0 -1
- package/lib/service/index.test.js +0 -73
- package/lib/tests/setup.d.ts +0 -1
- package/lib/tests/setup.js +0 -20
- package/lib/types/index.d.ts +0 -178
- package/lib/types/index.js +0 -2
- package/lib/types/types.test.d.ts +0 -1
- package/lib/types/types.test.js +0 -59
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
7
|
-
const __1 = __importDefault(require(".."));
|
|
8
|
-
it('ensuring the options are passed properly to the aggregate command', async () => {
|
|
9
|
-
const Tests = (0, __1.default)({ name: (0, helpers_1.generateId)() });
|
|
10
|
-
const cursorDefault = Tests.aggregate([{ $match: {} }]);
|
|
11
|
-
expect(cursorDefault.readPreference.mode).toBe('primary');
|
|
12
|
-
const cursorSecondary = Tests.aggregate([
|
|
13
|
-
{
|
|
14
|
-
$match: {}
|
|
15
|
-
}
|
|
16
|
-
], {
|
|
17
|
-
readPreference: 'secondary'
|
|
18
|
-
});
|
|
19
|
-
expect(cursorSecondary.readPreference.mode).toBe('secondary');
|
|
20
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const schema_1 = require("@orion-js/schema");
|
|
7
|
-
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
8
|
-
const isNil_1 = __importDefault(require("lodash/isNil"));
|
|
9
|
-
const isUndefined_1 = __importDefault(require("lodash/isUndefined"));
|
|
10
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
11
|
-
const fromDot_1 = __importDefault(require("../../helpers/fromDot"));
|
|
12
|
-
const shouldCheck = function (key) {
|
|
13
|
-
if (key === '$pushAll')
|
|
14
|
-
throw new Error('$pushAll is not supported; use $push + $each');
|
|
15
|
-
return ['$pull', '$pullAll', '$pop', '$slice'].indexOf(key) === -1;
|
|
16
|
-
};
|
|
17
|
-
async function cleanModifier(schema, modifier, { isUpsert } = { isUpsert: false }) {
|
|
18
|
-
const cleanedModifier = {};
|
|
19
|
-
for (const operation of Object.keys(modifier)) {
|
|
20
|
-
const operationDoc = modifier[operation];
|
|
21
|
-
cleanedModifier[operation] = {};
|
|
22
|
-
// If non-operators are mixed in, throw error
|
|
23
|
-
if (operation.slice(0, 1) !== '$') {
|
|
24
|
-
throw new Error(`Expected '${operation}' to be a modifier operator like '$set'`);
|
|
25
|
-
}
|
|
26
|
-
if (!shouldCheck(operation)) {
|
|
27
|
-
cleanedModifier[operation] = operationDoc;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
for (const key of Object.keys(operationDoc)) {
|
|
31
|
-
const value = operationDoc[key];
|
|
32
|
-
const cleanOptions = { forceDoc: operationDoc };
|
|
33
|
-
let cleaned = null;
|
|
34
|
-
if (operation === '$push' || operation === '$addToSet') {
|
|
35
|
-
if (typeof value === 'object' && '$each' in value) {
|
|
36
|
-
const $each = await (0, schema_1.cleanKey)(schema, key, value.$each, cleanOptions);
|
|
37
|
-
cleaned = { ...value, $each };
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
cleaned = await (0, schema_1.cleanKey)(schema, `${key}.0`, value, cleanOptions);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (operation === '$set') {
|
|
44
|
-
cleaned = await (0, schema_1.cleanKey)(schema, key, value, cleanOptions);
|
|
45
|
-
}
|
|
46
|
-
if (operation === '$setOnInsert') {
|
|
47
|
-
cleaned = await (0, schema_1.cleanKey)(schema, key, value, cleanOptions);
|
|
48
|
-
}
|
|
49
|
-
if (operation === '$inc') {
|
|
50
|
-
cleaned = await (0, schema_1.cleanKey)(schema, key, value, cleanOptions);
|
|
51
|
-
}
|
|
52
|
-
if (operation === '$unset') {
|
|
53
|
-
const isPresent = await (0, schema_1.cleanKey)(schema, key, 'anyvalue', cleanOptions);
|
|
54
|
-
cleaned = !(0, isNil_1.default)(isPresent) ? '' : null;
|
|
55
|
-
}
|
|
56
|
-
if (!(0, isUndefined_1.default)(cleaned)) {
|
|
57
|
-
cleanedModifier[operation][key] = cleaned;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if ((0, isEmpty_1.default)(cleanedModifier[operation])) {
|
|
61
|
-
delete cleanedModifier[operation];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (isUpsert) {
|
|
65
|
-
const cleanedSetOnInsert = await (0, schema_1.clean)(schema, (0, fromDot_1.default)(cleanedModifier.$setOnInsert || {}));
|
|
66
|
-
if (!(0, isEmpty_1.default)(cleanedSetOnInsert)) {
|
|
67
|
-
cleanedModifier.$setOnInsert = cleanedSetOnInsert;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if ((0, isEqual_1.default)(cleanedModifier, {})) {
|
|
71
|
-
throw new Error('After cleaning your modifier is empty');
|
|
72
|
-
}
|
|
73
|
-
return cleanedModifier;
|
|
74
|
-
}
|
|
75
|
-
exports.default = cleanModifier;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const cleanModifier_1 = __importDefault(require("./cleanModifier"));
|
|
7
|
-
it('should remove the modifier if no fields are present in schema', async () => {
|
|
8
|
-
const schema = {
|
|
9
|
-
firstName: {
|
|
10
|
-
type: String
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const modifier = {
|
|
14
|
-
$set: { name: 'Nicolás' }
|
|
15
|
-
};
|
|
16
|
-
expect.assertions(1);
|
|
17
|
-
try {
|
|
18
|
-
await (0, cleanModifier_1.default)(schema, modifier);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
expect(error.message).toBe('After cleaning your modifier is empty');
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
it('should remove the invalid fields and leave the valid ones', async () => {
|
|
25
|
-
const schema = {
|
|
26
|
-
firstName: {
|
|
27
|
-
type: String
|
|
28
|
-
},
|
|
29
|
-
lastName: {
|
|
30
|
-
type: String
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const modifier = {
|
|
34
|
-
$set: { name: 'Nicolás', lastName: 'López' }
|
|
35
|
-
};
|
|
36
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, modifier);
|
|
37
|
-
expect(cleaned).toEqual({ $set: { lastName: 'López' } });
|
|
38
|
-
});
|
|
39
|
-
it('should keep the null values', async () => {
|
|
40
|
-
const schema = {
|
|
41
|
-
firstName: {
|
|
42
|
-
type: String
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const modifier = {
|
|
46
|
-
$set: { firstName: null }
|
|
47
|
-
};
|
|
48
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, modifier);
|
|
49
|
-
expect(cleaned).toEqual(modifier);
|
|
50
|
-
});
|
|
51
|
-
it('should clean modifier and leave dots', async () => {
|
|
52
|
-
const wife = {
|
|
53
|
-
name: { type: String },
|
|
54
|
-
state: { type: String }
|
|
55
|
-
};
|
|
56
|
-
const schema = {
|
|
57
|
-
wife: { type: wife }
|
|
58
|
-
};
|
|
59
|
-
const modifier = { $set: { 'wife.state': 'Happy' } };
|
|
60
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, modifier);
|
|
61
|
-
expect(cleaned).toEqual(modifier);
|
|
62
|
-
});
|
|
63
|
-
it('should cleans $inc modifier', async () => {
|
|
64
|
-
const schema = {
|
|
65
|
-
age: { type: Number }
|
|
66
|
-
};
|
|
67
|
-
const modifier = { $inc: { age: '1' } };
|
|
68
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, modifier);
|
|
69
|
-
expect(cleaned).toEqual({ $inc: { age: 1 } });
|
|
70
|
-
});
|
|
71
|
-
it('should clean modifier with arrays with index in key', async () => {
|
|
72
|
-
const friend = {
|
|
73
|
-
name: { type: String }
|
|
74
|
-
};
|
|
75
|
-
const schema = {
|
|
76
|
-
friends: { type: [friend] }
|
|
77
|
-
};
|
|
78
|
-
const modifier = { $set: { 'friends.0.name': 'Roberto', 'friends.1.name': 'Joaquín' } };
|
|
79
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, modifier);
|
|
80
|
-
expect(cleaned).toEqual(modifier);
|
|
81
|
-
});
|
|
82
|
-
it('should clean modifier with arrays', async () => {
|
|
83
|
-
const friend = {
|
|
84
|
-
name: { type: String }
|
|
85
|
-
};
|
|
86
|
-
const schema = {
|
|
87
|
-
friends: { type: [friend] }
|
|
88
|
-
};
|
|
89
|
-
const modifier = { $set: { friends: ['Joaquín', 'Roberto'] } };
|
|
90
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, modifier);
|
|
91
|
-
expect(cleaned).toEqual(modifier);
|
|
92
|
-
});
|
|
93
|
-
it('clean well deep schema fields', async () => {
|
|
94
|
-
const tag = {
|
|
95
|
-
name: {
|
|
96
|
-
type: String
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const car = {
|
|
100
|
-
brand: {
|
|
101
|
-
type: String
|
|
102
|
-
},
|
|
103
|
-
tags: {
|
|
104
|
-
type: [tag]
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const schema = {
|
|
108
|
-
name: {
|
|
109
|
-
type: String
|
|
110
|
-
},
|
|
111
|
-
car: {
|
|
112
|
-
type: car
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, {
|
|
116
|
-
$set: { name: 1234, 'car.brand': 'Nissan' }
|
|
117
|
-
});
|
|
118
|
-
expect(cleaned).toEqual({ $set: { name: '1234', 'car.brand': 'Nissan' } });
|
|
119
|
-
});
|
|
120
|
-
it('should clean modifier with $push', async () => {
|
|
121
|
-
const schema = {
|
|
122
|
-
friends: { type: [String] }
|
|
123
|
-
};
|
|
124
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, {
|
|
125
|
-
$push: { friends: 1234 }
|
|
126
|
-
});
|
|
127
|
-
expect(cleaned).toEqual({
|
|
128
|
-
$push: { friends: '1234' }
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
it('should clean modifier with $push and $each', async () => {
|
|
132
|
-
const schema = {
|
|
133
|
-
friends: { type: [String] }
|
|
134
|
-
};
|
|
135
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, {
|
|
136
|
-
$push: { friends: { $each: [1234, 'a string'], $slice: 3 } }
|
|
137
|
-
});
|
|
138
|
-
expect(cleaned).toEqual({
|
|
139
|
-
$push: { friends: { $each: ['1234', 'a string'], $slice: 3 } }
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
it('cleans $push modifier with deep array', async () => {
|
|
143
|
-
const friend = {
|
|
144
|
-
name: { type: String }
|
|
145
|
-
};
|
|
146
|
-
const person = {
|
|
147
|
-
friends: { type: [friend] }
|
|
148
|
-
};
|
|
149
|
-
const schema = {
|
|
150
|
-
persons: { type: [person] }
|
|
151
|
-
};
|
|
152
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, {
|
|
153
|
-
$push: { 'persons.14321.friends': { name: 1234 } }
|
|
154
|
-
});
|
|
155
|
-
expect(cleaned).toEqual({
|
|
156
|
-
$push: { 'persons.14321.friends': { name: '1234' } }
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
it('cleans $unset correctly', async () => {
|
|
160
|
-
const schema = {
|
|
161
|
-
name: { type: String, optional: true },
|
|
162
|
-
info: { type: 'blackbox', optional: true },
|
|
163
|
-
age: { type: Number, optional: true }
|
|
164
|
-
};
|
|
165
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, {
|
|
166
|
-
$unset: { name: '', info: '', age: '' }
|
|
167
|
-
});
|
|
168
|
-
expect(cleaned).toEqual({
|
|
169
|
-
$unset: { name: '', info: '', age: '' }
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
it('should handle $ correctly', async () => {
|
|
173
|
-
const Email = {
|
|
174
|
-
address: { type: String },
|
|
175
|
-
verified: { type: Boolean }
|
|
176
|
-
};
|
|
177
|
-
const schema = {
|
|
178
|
-
emails: { type: [Email] }
|
|
179
|
-
};
|
|
180
|
-
const cleaned = await (0, cleanModifier_1.default)(schema, {
|
|
181
|
-
$set: { 'emails.$.verified': 'true' }
|
|
182
|
-
});
|
|
183
|
-
expect(cleaned).toEqual({
|
|
184
|
-
$set: { 'emails.$.verified': true }
|
|
185
|
-
});
|
|
186
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getSelector_1 = __importDefault(require("./getSelector"));
|
|
7
|
-
function default_1(collection) {
|
|
8
|
-
const func = async function (selectorArg, options) {
|
|
9
|
-
await collection.connectionPromise;
|
|
10
|
-
const selector = (0, getSelector_1.default)(arguments);
|
|
11
|
-
const result = await collection.rawCollection.countDocuments(selector, options);
|
|
12
|
-
return result;
|
|
13
|
-
};
|
|
14
|
-
return func;
|
|
15
|
-
}
|
|
16
|
-
exports.default = default_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
7
|
-
const __1 = __importDefault(require(".."));
|
|
8
|
-
describe('countDocuments operation', () => {
|
|
9
|
-
it('should count all documents', async () => {
|
|
10
|
-
const Tests = (0, __1.default)({ name: (0, helpers_1.generateId)() });
|
|
11
|
-
await Tests.insertMany([{ hello: 'world' }, { hello: 'world' }]);
|
|
12
|
-
const count = await Tests.countDocuments({});
|
|
13
|
-
expect(count).toBe(2);
|
|
14
|
-
});
|
|
15
|
-
it('should count filtering documents', async () => {
|
|
16
|
-
const Tests = (0, __1.default)({ name: (0, helpers_1.generateId)() });
|
|
17
|
-
await Tests.insertMany([{ name: '1' }, { name: '2' }]);
|
|
18
|
-
const count = await Tests.countDocuments({ name: '1' });
|
|
19
|
-
expect(count).toBe(1);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import DataLoader from 'dataloader';
|
|
2
|
-
export declare const cache: Map<any, any>;
|
|
3
|
-
interface Options {
|
|
4
|
-
key: string;
|
|
5
|
-
func: (ids: Array<string>) => Promise<any>;
|
|
6
|
-
timeout: number;
|
|
7
|
-
}
|
|
8
|
-
export declare const getDataLoader: (params: Options) => DataLoader<any, any>;
|
|
9
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDataLoader = exports.cache = void 0;
|
|
7
|
-
const dataloader_1 = __importDefault(require("dataloader"));
|
|
8
|
-
exports.cache = new Map();
|
|
9
|
-
const getDataLoader = function (params) {
|
|
10
|
-
const { key, func, timeout } = params;
|
|
11
|
-
const existing = exports.cache.get(key);
|
|
12
|
-
if (existing)
|
|
13
|
-
return existing;
|
|
14
|
-
const load = async (ids) => {
|
|
15
|
-
exports.cache.delete(key);
|
|
16
|
-
return await func(ids);
|
|
17
|
-
};
|
|
18
|
-
const options = {
|
|
19
|
-
batchScheduleFn: callback => setTimeout(callback, timeout)
|
|
20
|
-
};
|
|
21
|
-
const dataLoader = new dataloader_1.default(load, options);
|
|
22
|
-
exports.cache.set(key, dataLoader);
|
|
23
|
-
return dataLoader;
|
|
24
|
-
};
|
|
25
|
-
exports.getDataLoader = getDataLoader;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getDataLoader_1 = require("./getDataLoader");
|
|
7
|
-
const dataloader_1 = __importDefault(require("dataloader"));
|
|
8
|
-
it('should get data loaders', async () => {
|
|
9
|
-
const dataLoader = (0, getDataLoader_1.getDataLoader)({
|
|
10
|
-
key: 'test1',
|
|
11
|
-
func: async () => { },
|
|
12
|
-
timeout: 1
|
|
13
|
-
});
|
|
14
|
-
expect(dataLoader).toBeInstanceOf(dataloader_1.default);
|
|
15
|
-
});
|
|
16
|
-
it('should return same dataloader with same key', async () => {
|
|
17
|
-
const options = {
|
|
18
|
-
key: 'test1',
|
|
19
|
-
func: async () => { },
|
|
20
|
-
timeout: 1
|
|
21
|
-
};
|
|
22
|
-
const dataLoader1 = (0, getDataLoader_1.getDataLoader)(options);
|
|
23
|
-
const dataLoader2 = (0, getDataLoader_1.getDataLoader)(options);
|
|
24
|
-
expect(dataLoader1).toBe(dataLoader2);
|
|
25
|
-
});
|
|
26
|
-
it('should delete dataloader map when its used', async () => {
|
|
27
|
-
const func = async (keys) => keys;
|
|
28
|
-
const dataLoader = (0, getDataLoader_1.getDataLoader)({
|
|
29
|
-
key: 'test2',
|
|
30
|
-
func,
|
|
31
|
-
timeout: 10
|
|
32
|
-
});
|
|
33
|
-
expect(getDataLoader_1.cache.get('test2')).toBeInstanceOf(dataloader_1.default);
|
|
34
|
-
const result = await dataLoader.load(1);
|
|
35
|
-
expect(result).toBe(1);
|
|
36
|
-
expect(getDataLoader_1.cache.get('test2')).toBeUndefined();
|
|
37
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getDataLoader_1 = require("./getDataLoader");
|
|
7
|
-
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
8
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
9
|
-
const dataLoad = async (options) => {
|
|
10
|
-
const dataLoader = (0, getDataLoader_1.getDataLoader)({
|
|
11
|
-
key: (0, helpers_1.hashObject)(options.loaderKey),
|
|
12
|
-
func: options.load,
|
|
13
|
-
timeout: options.timeout || 5
|
|
14
|
-
});
|
|
15
|
-
if (options.ids) {
|
|
16
|
-
const resultArray = await dataLoader.loadMany(options.ids);
|
|
17
|
-
return (0, flatten_1.default)(resultArray);
|
|
18
|
-
}
|
|
19
|
-
return await dataLoader.load(options.id);
|
|
20
|
-
};
|
|
21
|
-
exports.default = dataLoad;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadMany = exports.loadOne = exports.loadById = exports.loadData = void 0;
|
|
7
|
-
const loadById_1 = __importDefault(require("./loadById"));
|
|
8
|
-
exports.loadById = loadById_1.default;
|
|
9
|
-
const loadMany_1 = __importDefault(require("./loadMany"));
|
|
10
|
-
exports.loadMany = loadMany_1.default;
|
|
11
|
-
const loadOne_1 = __importDefault(require("./loadOne"));
|
|
12
|
-
exports.loadOne = loadOne_1.default;
|
|
13
|
-
const loadData_1 = __importDefault(require("./loadData"));
|
|
14
|
-
exports.loadData = loadData_1.default;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function default_1(collection) {
|
|
4
|
-
const loadById = async (id) => {
|
|
5
|
-
const result = await collection.loadOne({
|
|
6
|
-
key: '_id',
|
|
7
|
-
value: id
|
|
8
|
-
});
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
return loadById;
|
|
12
|
-
}
|
|
13
|
-
exports.default = default_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
7
|
-
const index_1 = __importDefault(require("../../index"));
|
|
8
|
-
it('should data load by id', async () => {
|
|
9
|
-
const Tests = (0, index_1.default)({ name: (0, helpers_1.generateId)() });
|
|
10
|
-
const id1 = await Tests.insertOne({ hello: 'world' });
|
|
11
|
-
const id2 = await Tests.insertOne({ hello: 'world' });
|
|
12
|
-
const [loaded1, loaded2] = await Promise.all([Tests.loadById(id1), Tests.loadById(id2)]);
|
|
13
|
-
expect(loaded1._id).toBe(id1);
|
|
14
|
-
expect(loaded2._id).toBe(id2);
|
|
15
|
-
});
|
|
16
|
-
it('should run only one query when same id', async () => {
|
|
17
|
-
const Tests = (0, index_1.default)({ name: (0, helpers_1.generateId)() });
|
|
18
|
-
const id1 = await Tests.insertOne({ hello: 'world' });
|
|
19
|
-
await Tests.insertOne({ hello: 'world' });
|
|
20
|
-
const [loaded1, loaded2] = await Promise.all([Tests.loadById(id1), Tests.loadById(id1)]);
|
|
21
|
-
expect(loaded1._id).toBe(id1);
|
|
22
|
-
expect(loaded2._id).toBe(id1);
|
|
23
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
7
|
-
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
8
|
-
const dataLoad_1 = __importDefault(require("./dataLoad"));
|
|
9
|
-
function default_1(collection) {
|
|
10
|
-
const loadData = async (options) => {
|
|
11
|
-
await collection.connectionPromise;
|
|
12
|
-
const result = await (0, dataLoad_1.default)({
|
|
13
|
-
loaderKey: {
|
|
14
|
-
key: options.key,
|
|
15
|
-
match: options.match,
|
|
16
|
-
sort: options.sort,
|
|
17
|
-
project: options.project,
|
|
18
|
-
collectionName: collection.name
|
|
19
|
-
},
|
|
20
|
-
id: options.value,
|
|
21
|
-
ids: options.values,
|
|
22
|
-
timeout: options.timeout,
|
|
23
|
-
load: async (values) => {
|
|
24
|
-
const query = {
|
|
25
|
-
...(0, cloneDeep_1.default)(options.match),
|
|
26
|
-
[options.key]: { $in: values }
|
|
27
|
-
};
|
|
28
|
-
const cursor = collection.find(query);
|
|
29
|
-
if (options.sort) {
|
|
30
|
-
cursor.sort(options.sort);
|
|
31
|
-
}
|
|
32
|
-
if (options.project) {
|
|
33
|
-
cursor.project(options.project);
|
|
34
|
-
}
|
|
35
|
-
if (options.debug) {
|
|
36
|
-
console.info(`Will execute data loading query now on ${collection.name}: `, query);
|
|
37
|
-
}
|
|
38
|
-
const items = await cursor.toArray();
|
|
39
|
-
const itemsMap = (0, helpers_1.createMapArray)(items, options.key);
|
|
40
|
-
return values.map(value => {
|
|
41
|
-
return itemsMap[value] || [];
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return result;
|
|
46
|
-
};
|
|
47
|
-
return loadData;
|
|
48
|
-
}
|
|
49
|
-
exports.default = default_1;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function default_1(collection) {
|
|
4
|
-
const loadMany = async (options) => {
|
|
5
|
-
const results = await collection.loadData(options);
|
|
6
|
-
return results;
|
|
7
|
-
};
|
|
8
|
-
return loadMany;
|
|
9
|
-
}
|
|
10
|
-
exports.default = default_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|