@e22m4u/js-repository-mongodb-adapter 0.6.4 → 0.7.1
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/dist/cjs/index.cjs +315 -271
- package/package.json +13 -13
- package/src/mongodb-adapter.js +25 -18
- package/src/mongodb-adapter.spec.js +60 -36
package/dist/cjs/index.cjs
CHANGED
|
@@ -30,204 +30,12 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_mongodb2 = require("mongodb");
|
|
31
31
|
var import_mongodb3 = require("mongodb");
|
|
32
32
|
|
|
33
|
-
// src/utils/pluralize.js
|
|
34
|
-
var singularExceptions = [
|
|
35
|
-
/access$/i,
|
|
36
|
-
/address$/i,
|
|
37
|
-
/alias$/i,
|
|
38
|
-
/bonus$/i,
|
|
39
|
-
/boss$/i,
|
|
40
|
-
/bus$/i,
|
|
41
|
-
/business$/i,
|
|
42
|
-
/canvas$/i,
|
|
43
|
-
/class$/i,
|
|
44
|
-
/cross$/i,
|
|
45
|
-
/dress$/i,
|
|
46
|
-
/focus$/i,
|
|
47
|
-
/gas$/i,
|
|
48
|
-
/glass$/i,
|
|
49
|
-
/kiss$/i,
|
|
50
|
-
/lens$/i,
|
|
51
|
-
/loss$/i,
|
|
52
|
-
/pass$/i,
|
|
53
|
-
/plus$/i,
|
|
54
|
-
/process$/i,
|
|
55
|
-
/status$/i,
|
|
56
|
-
/success$/i,
|
|
57
|
-
/virus$/i
|
|
58
|
-
];
|
|
59
|
-
function pluralize(input) {
|
|
60
|
-
if (!input || typeof input !== "string") {
|
|
61
|
-
return input;
|
|
62
|
-
}
|
|
63
|
-
if (/s$/i.test(input) && !singularExceptions.some((re) => re.test(input))) {
|
|
64
|
-
return input;
|
|
65
|
-
}
|
|
66
|
-
const lastChar = input.slice(-1);
|
|
67
|
-
const isLastCharUpper = lastChar === lastChar.toUpperCase() && lastChar !== lastChar.toLowerCase();
|
|
68
|
-
if (/(s|x|z|ch|sh)$/i.test(input)) {
|
|
69
|
-
return input + (isLastCharUpper ? "ES" : "es");
|
|
70
|
-
}
|
|
71
|
-
if (/[^aeiou]y$/i.test(input)) {
|
|
72
|
-
return input.slice(0, -1) + (isLastCharUpper ? "IES" : "ies");
|
|
73
|
-
}
|
|
74
|
-
return input + (isLastCharUpper ? "S" : "s");
|
|
75
|
-
}
|
|
76
|
-
__name(pluralize, "pluralize");
|
|
77
|
-
|
|
78
|
-
// src/utils/is-iso-date.js
|
|
79
|
-
function isIsoDate(value) {
|
|
80
|
-
if (!value) return false;
|
|
81
|
-
if (value instanceof Date) return true;
|
|
82
|
-
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value)) return false;
|
|
83
|
-
const d = new Date(value);
|
|
84
|
-
return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === value;
|
|
85
|
-
}
|
|
86
|
-
__name(isIsoDate, "isIsoDate");
|
|
87
|
-
|
|
88
|
-
// src/utils/is-object-id.js
|
|
89
|
-
var import_mongodb = require("mongodb");
|
|
90
|
-
function isObjectId(value) {
|
|
91
|
-
if (!value) return false;
|
|
92
|
-
if (value instanceof import_mongodb.ObjectId) return true;
|
|
93
|
-
if (typeof value !== "string") return false;
|
|
94
|
-
return value.match(/^[a-fA-F0-9]{24}$/) != null;
|
|
95
|
-
}
|
|
96
|
-
__name(isObjectId, "isObjectId");
|
|
97
|
-
|
|
98
|
-
// src/utils/to-camel-case.js
|
|
99
|
-
function toCamelCase(input) {
|
|
100
|
-
if (!input) return "";
|
|
101
|
-
const spacedString = String(input).replace(/([-_])/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2");
|
|
102
|
-
const intermediateCased = spacedString.toLowerCase().replace(/\s(.)/g, ($1) => $1.toUpperCase()).replace(/\s/g, "");
|
|
103
|
-
if (!intermediateCased) return "";
|
|
104
|
-
return intermediateCased.charAt(0).toLowerCase() + intermediateCased.slice(1);
|
|
105
|
-
}
|
|
106
|
-
__name(toCamelCase, "toCamelCase");
|
|
107
|
-
|
|
108
|
-
// src/utils/create-mongodb-url.js
|
|
109
|
-
var import_js_repository = require("@e22m4u/js-repository");
|
|
110
|
-
function createMongodbUrl(options = {}) {
|
|
111
|
-
if (!options || typeof options !== "object" || Array.isArray(options))
|
|
112
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
113
|
-
'The first argument of "createMongodbUrl" must be an Object, but %v given.',
|
|
114
|
-
options
|
|
115
|
-
);
|
|
116
|
-
if (options.protocol && typeof options.protocol !== "string")
|
|
117
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
118
|
-
'MongoDB option "protocol" must be a String, but %v given.',
|
|
119
|
-
options.protocol
|
|
120
|
-
);
|
|
121
|
-
if (options.hostname && typeof options.hostname !== "string")
|
|
122
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
123
|
-
'MongoDB option "hostname" must be a String, but %v given.',
|
|
124
|
-
options.hostname
|
|
125
|
-
);
|
|
126
|
-
if (options.host && typeof options.host !== "string")
|
|
127
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
128
|
-
'MongoDB option "host" must be a String, but %v given.',
|
|
129
|
-
options.host
|
|
130
|
-
);
|
|
131
|
-
if (options.port && typeof options.port !== "number" && typeof options.port !== "string") {
|
|
132
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
133
|
-
'MongoDB option "port" must be a Number or a String, but %v given.',
|
|
134
|
-
options.port
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (options.database && typeof options.database !== "string")
|
|
138
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
139
|
-
'MongoDB option "database" must be a String, but %v given.',
|
|
140
|
-
options.database
|
|
141
|
-
);
|
|
142
|
-
if (options.db && typeof options.db !== "string")
|
|
143
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
144
|
-
'MongoDB option "db" must be a String, but %v given.',
|
|
145
|
-
options.db
|
|
146
|
-
);
|
|
147
|
-
if (options.username && typeof options.username !== "string")
|
|
148
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
149
|
-
'MongoDB option "username" must be a String, but %v given.',
|
|
150
|
-
options.username
|
|
151
|
-
);
|
|
152
|
-
if (options.password && typeof options.password !== "string" && typeof options.password !== "number") {
|
|
153
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
154
|
-
'MongoDB option "password" must be a String or a Number, but %v given.',
|
|
155
|
-
options.password
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (options.pass && typeof options.pass !== "string" && typeof options.pass !== "number") {
|
|
159
|
-
throw new import_js_repository.InvalidArgumentError(
|
|
160
|
-
'MongoDB option "pass" must be a String or a Number, but %v given.',
|
|
161
|
-
options.pass
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
const protocol = options.protocol || "mongodb";
|
|
165
|
-
const hostname = options.hostname || options.host || "127.0.0.1";
|
|
166
|
-
const port = options.port || 27017;
|
|
167
|
-
const database = options.database || options.db || "database";
|
|
168
|
-
const username = options.username || options.user;
|
|
169
|
-
const password = options.password || options.pass || void 0;
|
|
170
|
-
let portUrl = "";
|
|
171
|
-
if (protocol !== "mongodb+srv") {
|
|
172
|
-
portUrl = ":" + port;
|
|
173
|
-
}
|
|
174
|
-
if (username && password) {
|
|
175
|
-
return `${protocol}://${username}:${password}@${hostname}${portUrl}/${database}`;
|
|
176
|
-
} else {
|
|
177
|
-
return `${protocol}://${hostname}${portUrl}/${database}`;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
__name(createMongodbUrl, "createMongodbUrl");
|
|
181
|
-
|
|
182
|
-
// src/utils/transform-values-deep.js
|
|
183
|
-
var import_js_repository2 = require("@e22m4u/js-repository");
|
|
184
|
-
function transformValuesDeep(value, transformer) {
|
|
185
|
-
if (!transformer || typeof transformer !== "function")
|
|
186
|
-
throw new import_js_repository2.InvalidArgumentError(
|
|
187
|
-
'The second argument of "transformValuesDeep" must be a Function, but %v given.',
|
|
188
|
-
transformer
|
|
189
|
-
);
|
|
190
|
-
if (Array.isArray(value)) {
|
|
191
|
-
value.forEach((v, i) => value[i] = transformValuesDeep(v, transformer));
|
|
192
|
-
return value;
|
|
193
|
-
} else if (value && typeof value === "object") {
|
|
194
|
-
if (!value.constructor || value.constructor && value.constructor.name === "Object") {
|
|
195
|
-
Object.keys(value).forEach((key) => {
|
|
196
|
-
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
197
|
-
value[key] = transformValuesDeep(value[key], transformer);
|
|
198
|
-
});
|
|
199
|
-
return value;
|
|
200
|
-
} else {
|
|
201
|
-
return transformer(value);
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
return transformer(value);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
__name(transformValuesDeep, "transformValuesDeep");
|
|
208
|
-
|
|
209
|
-
// src/utils/model-name-to-collection-name.js
|
|
210
|
-
function modelNameToCollectionName(modelName) {
|
|
211
|
-
const ccName = toCamelCase(modelName);
|
|
212
|
-
const woModel = ccName.replace(/Model$/i, "");
|
|
213
|
-
if (woModel.length <= 2) {
|
|
214
|
-
return pluralize(ccName);
|
|
215
|
-
}
|
|
216
|
-
return pluralize(woModel);
|
|
217
|
-
}
|
|
218
|
-
__name(modelNameToCollectionName, "modelNameToCollectionName");
|
|
219
|
-
|
|
220
|
-
// src/mongodb-adapter.js
|
|
221
|
-
var import_js_repository3 = require("@e22m4u/js-repository");
|
|
222
|
-
var import_js_repository4 = require("@e22m4u/js-repository");
|
|
223
|
-
var import_js_repository5 = require("@e22m4u/js-repository");
|
|
224
|
-
|
|
225
33
|
// node_modules/@e22m4u/js-service/src/errors/invalid-argument-error.js
|
|
226
34
|
var import_js_format = require("@e22m4u/js-format");
|
|
227
35
|
var _InvalidArgumentError = class _InvalidArgumentError extends import_js_format.Errorf {
|
|
228
36
|
};
|
|
229
37
|
__name(_InvalidArgumentError, "InvalidArgumentError");
|
|
230
|
-
var
|
|
38
|
+
var InvalidArgumentError = _InvalidArgumentError;
|
|
231
39
|
|
|
232
40
|
// node_modules/@e22m4u/js-service/src/service-container.js
|
|
233
41
|
var SERVICE_CONTAINER_CLASS_NAME = "ServiceContainer";
|
|
@@ -254,7 +62,7 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
254
62
|
constructor(parent = void 0) {
|
|
255
63
|
if (parent != null) {
|
|
256
64
|
if (!(parent instanceof _ServiceContainer))
|
|
257
|
-
throw new
|
|
65
|
+
throw new InvalidArgumentError(
|
|
258
66
|
'The provided parameter "parent" of ServicesContainer.constructor must be an instance ServiceContainer, but %v given.',
|
|
259
67
|
parent
|
|
260
68
|
);
|
|
@@ -268,7 +76,7 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
268
76
|
*/
|
|
269
77
|
getParent() {
|
|
270
78
|
if (!this._parent)
|
|
271
|
-
throw new
|
|
79
|
+
throw new InvalidArgumentError("The service container has no parent.");
|
|
272
80
|
return this._parent;
|
|
273
81
|
}
|
|
274
82
|
/**
|
|
@@ -288,21 +96,23 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
288
96
|
*/
|
|
289
97
|
get(ctor, ...args) {
|
|
290
98
|
if (!ctor || typeof ctor !== "function")
|
|
291
|
-
throw new
|
|
99
|
+
throw new InvalidArgumentError(
|
|
292
100
|
"The first argument of ServicesContainer.get must be a class constructor, but %v given.",
|
|
293
101
|
ctor
|
|
294
102
|
);
|
|
295
|
-
|
|
296
|
-
return this._parent.get(ctor);
|
|
297
|
-
}
|
|
103
|
+
const isCtorRegistered = this._services.has(ctor);
|
|
298
104
|
let service = this._services.get(ctor);
|
|
105
|
+
let inheritedCtor = void 0;
|
|
299
106
|
if (!service) {
|
|
300
|
-
const ctors = this._services.keys();
|
|
301
|
-
|
|
302
|
-
if (inheritedCtor)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
107
|
+
const ctors = Array.from(this._services.keys());
|
|
108
|
+
inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
|
|
109
|
+
if (inheritedCtor) service = this._services.get(inheritedCtor);
|
|
110
|
+
}
|
|
111
|
+
if (!service && !isCtorRegistered && !inheritedCtor && this._parent && this._parent.has(ctor)) {
|
|
112
|
+
return this._parent.get(ctor, ...args);
|
|
113
|
+
}
|
|
114
|
+
if (!isCtorRegistered && inheritedCtor) {
|
|
115
|
+
ctor = inheritedCtor;
|
|
306
116
|
}
|
|
307
117
|
if (!service || args.length) {
|
|
308
118
|
service = Array.isArray(ctor.kinds) && ctor.kinds.includes(SERVICE_CLASS_NAME) ? new ctor(this, ...args) : new ctor(...args);
|
|
@@ -323,7 +133,7 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
323
133
|
*/
|
|
324
134
|
getRegistered(ctor, ...args) {
|
|
325
135
|
if (!this.has(ctor))
|
|
326
|
-
throw new
|
|
136
|
+
throw new InvalidArgumentError(
|
|
327
137
|
"The constructor %v is not registered.",
|
|
328
138
|
ctor
|
|
329
139
|
);
|
|
@@ -337,10 +147,10 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
337
147
|
*/
|
|
338
148
|
has(ctor) {
|
|
339
149
|
if (this._services.has(ctor)) return true;
|
|
340
|
-
|
|
341
|
-
const ctors = this._services.keys();
|
|
150
|
+
const ctors = Array.from(this._services.keys());
|
|
342
151
|
const inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
|
|
343
152
|
if (inheritedCtor) return true;
|
|
153
|
+
if (this._parent) return this._parent.has(ctor);
|
|
344
154
|
return false;
|
|
345
155
|
}
|
|
346
156
|
/**
|
|
@@ -352,7 +162,7 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
352
162
|
*/
|
|
353
163
|
add(ctor, ...args) {
|
|
354
164
|
if (!ctor || typeof ctor !== "function")
|
|
355
|
-
throw new
|
|
165
|
+
throw new InvalidArgumentError(
|
|
356
166
|
"The first argument of ServicesContainer.add must be a class constructor, but %v given.",
|
|
357
167
|
ctor
|
|
358
168
|
);
|
|
@@ -369,7 +179,7 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
369
179
|
*/
|
|
370
180
|
use(ctor, ...args) {
|
|
371
181
|
if (!ctor || typeof ctor !== "function")
|
|
372
|
-
throw new
|
|
182
|
+
throw new InvalidArgumentError(
|
|
373
183
|
"The first argument of ServicesContainer.use must be a class constructor, but %v given.",
|
|
374
184
|
ctor
|
|
375
185
|
);
|
|
@@ -386,18 +196,48 @@ var _ServiceContainer = class _ServiceContainer {
|
|
|
386
196
|
*/
|
|
387
197
|
set(ctor, service) {
|
|
388
198
|
if (!ctor || typeof ctor !== "function")
|
|
389
|
-
throw new
|
|
199
|
+
throw new InvalidArgumentError(
|
|
390
200
|
"The first argument of ServicesContainer.set must be a class constructor, but %v given.",
|
|
391
201
|
ctor
|
|
392
202
|
);
|
|
393
203
|
if (!service || typeof service !== "object" || Array.isArray(service))
|
|
394
|
-
throw new
|
|
204
|
+
throw new InvalidArgumentError(
|
|
395
205
|
"The second argument of ServicesContainer.set must be an Object, but %v given.",
|
|
396
206
|
service
|
|
397
207
|
);
|
|
398
208
|
this._services.set(ctor, service);
|
|
399
209
|
return this;
|
|
400
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Найти сервис удовлетворяющий условию.
|
|
213
|
+
*
|
|
214
|
+
* @param {function(Function, ServiceContainer): boolean} predicate
|
|
215
|
+
* @param {boolean} noParent
|
|
216
|
+
* @returns {*}
|
|
217
|
+
*/
|
|
218
|
+
find(predicate, noParent = false) {
|
|
219
|
+
if (typeof predicate !== "function") {
|
|
220
|
+
throw new InvalidArgumentError(
|
|
221
|
+
"The first argument of ServiceContainer.find must be a function, but %v given.",
|
|
222
|
+
predicate
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const isRecursive = !noParent;
|
|
226
|
+
let currentContainer = this;
|
|
227
|
+
do {
|
|
228
|
+
for (const ctor of currentContainer._services.keys()) {
|
|
229
|
+
if (predicate(ctor, currentContainer) === true) {
|
|
230
|
+
return this.get(ctor);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (isRecursive && currentContainer.hasParent()) {
|
|
234
|
+
currentContainer = currentContainer.getParent();
|
|
235
|
+
} else {
|
|
236
|
+
currentContainer = null;
|
|
237
|
+
}
|
|
238
|
+
} while (currentContainer);
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
401
241
|
};
|
|
402
242
|
__name(_ServiceContainer, "ServiceContainer");
|
|
403
243
|
/**
|
|
@@ -496,6 +336,16 @@ var _Service = class _Service {
|
|
|
496
336
|
this.container.set(ctor, service);
|
|
497
337
|
return this;
|
|
498
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Найти сервис удовлетворяющий условию.
|
|
341
|
+
*
|
|
342
|
+
* @param {function(Function, ServiceContainer): boolean} predicate
|
|
343
|
+
* @param {boolean} noParent
|
|
344
|
+
* @returns {*}
|
|
345
|
+
*/
|
|
346
|
+
findService(predicate, noParent = false) {
|
|
347
|
+
return this.container.find(predicate, noParent);
|
|
348
|
+
}
|
|
499
349
|
};
|
|
500
350
|
__name(_Service, "Service");
|
|
501
351
|
/**
|
|
@@ -507,10 +357,10 @@ __publicField(_Service, "kinds", [SERVICE_CLASS_NAME]);
|
|
|
507
357
|
var Service = _Service;
|
|
508
358
|
|
|
509
359
|
// node_modules/@e22m4u/js-debug/src/utils/to-camel-case.js
|
|
510
|
-
function
|
|
360
|
+
function toCamelCase(input) {
|
|
511
361
|
return input.replace(/(^\w|[A-Z]|\b\w)/g, (c) => c.toUpperCase()).replace(/\W+/g, "").replace(/(^\w)/g, (c) => c.toLowerCase());
|
|
512
362
|
}
|
|
513
|
-
__name(
|
|
363
|
+
__name(toCamelCase, "toCamelCase");
|
|
514
364
|
|
|
515
365
|
// node_modules/@e22m4u/js-debug/src/utils/is-non-array-object.js
|
|
516
366
|
function isNonArrayObject(input) {
|
|
@@ -558,16 +408,16 @@ var _Debuggable = class _Debuggable {
|
|
|
558
408
|
* @returns {Function}
|
|
559
409
|
*/
|
|
560
410
|
getDebuggerFor(method) {
|
|
561
|
-
|
|
411
|
+
const name = method.name || "anonymous";
|
|
412
|
+
return this.debug.withHash().withNs(name);
|
|
562
413
|
}
|
|
563
414
|
/**
|
|
564
415
|
* Constructor.
|
|
565
416
|
*
|
|
566
|
-
* @param {object|undefined} container
|
|
567
417
|
* @param {DebuggableOptions|undefined} options
|
|
568
418
|
*/
|
|
569
419
|
constructor(options = void 0) {
|
|
570
|
-
const className =
|
|
420
|
+
const className = toCamelCase(this.constructor.name);
|
|
571
421
|
options = typeof options === "object" && options || {};
|
|
572
422
|
const namespace = options.namespace && String(options.namespace) || void 0;
|
|
573
423
|
if (namespace) {
|
|
@@ -575,10 +425,12 @@ var _Debuggable = class _Debuggable {
|
|
|
575
425
|
} else {
|
|
576
426
|
this.debug = createDebugger(className);
|
|
577
427
|
}
|
|
578
|
-
const
|
|
579
|
-
if (
|
|
428
|
+
const noEnvironmentNamespace = Boolean(options.noEnvironmentNamespace);
|
|
429
|
+
if (noEnvironmentNamespace) this.debug = this.debug.withoutEnvNs();
|
|
580
430
|
this.ctorDebug = this.debug.withNs("constructor").withHash();
|
|
581
|
-
|
|
431
|
+
const noInstantiationMessage = Boolean(options.noInstantiationMessage);
|
|
432
|
+
if (!noInstantiationMessage)
|
|
433
|
+
this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
|
|
582
434
|
}
|
|
583
435
|
};
|
|
584
436
|
__name(_Debuggable, "Debuggable");
|
|
@@ -932,6 +784,14 @@ var _DebuggableService = class _DebuggableService extends Debuggable {
|
|
|
932
784
|
get setService() {
|
|
933
785
|
return this._service.setService;
|
|
934
786
|
}
|
|
787
|
+
/**
|
|
788
|
+
* Найти сервис удовлетворяющий условию.
|
|
789
|
+
*
|
|
790
|
+
* @type {Service['findService']}
|
|
791
|
+
*/
|
|
792
|
+
get findService() {
|
|
793
|
+
return this._service.findService;
|
|
794
|
+
}
|
|
935
795
|
/**
|
|
936
796
|
* Constructor.
|
|
937
797
|
*
|
|
@@ -953,12 +813,196 @@ __publicField(_DebuggableService, "kinds", Service.kinds);
|
|
|
953
813
|
var DebuggableService = _DebuggableService;
|
|
954
814
|
|
|
955
815
|
// src/mongodb-adapter.js
|
|
956
|
-
var
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
var
|
|
960
|
-
|
|
961
|
-
|
|
816
|
+
var import_js_repository3 = require("@e22m4u/js-repository");
|
|
817
|
+
|
|
818
|
+
// src/utils/pluralize.js
|
|
819
|
+
var singularExceptions = [
|
|
820
|
+
/access$/i,
|
|
821
|
+
/address$/i,
|
|
822
|
+
/alias$/i,
|
|
823
|
+
/bonus$/i,
|
|
824
|
+
/boss$/i,
|
|
825
|
+
/bus$/i,
|
|
826
|
+
/business$/i,
|
|
827
|
+
/canvas$/i,
|
|
828
|
+
/class$/i,
|
|
829
|
+
/cross$/i,
|
|
830
|
+
/dress$/i,
|
|
831
|
+
/focus$/i,
|
|
832
|
+
/gas$/i,
|
|
833
|
+
/glass$/i,
|
|
834
|
+
/kiss$/i,
|
|
835
|
+
/lens$/i,
|
|
836
|
+
/loss$/i,
|
|
837
|
+
/pass$/i,
|
|
838
|
+
/plus$/i,
|
|
839
|
+
/process$/i,
|
|
840
|
+
/status$/i,
|
|
841
|
+
/success$/i,
|
|
842
|
+
/virus$/i
|
|
843
|
+
];
|
|
844
|
+
function pluralize(input) {
|
|
845
|
+
if (!input || typeof input !== "string") {
|
|
846
|
+
return input;
|
|
847
|
+
}
|
|
848
|
+
if (/s$/i.test(input) && !singularExceptions.some((re) => re.test(input))) {
|
|
849
|
+
return input;
|
|
850
|
+
}
|
|
851
|
+
const lastChar = input.slice(-1);
|
|
852
|
+
const isLastCharUpper = lastChar === lastChar.toUpperCase() && lastChar !== lastChar.toLowerCase();
|
|
853
|
+
if (/(s|x|z|ch|sh)$/i.test(input)) {
|
|
854
|
+
return input + (isLastCharUpper ? "ES" : "es");
|
|
855
|
+
}
|
|
856
|
+
if (/[^aeiou]y$/i.test(input)) {
|
|
857
|
+
return input.slice(0, -1) + (isLastCharUpper ? "IES" : "ies");
|
|
858
|
+
}
|
|
859
|
+
return input + (isLastCharUpper ? "S" : "s");
|
|
860
|
+
}
|
|
861
|
+
__name(pluralize, "pluralize");
|
|
862
|
+
|
|
863
|
+
// src/utils/is-iso-date.js
|
|
864
|
+
function isIsoDate(value) {
|
|
865
|
+
if (!value) return false;
|
|
866
|
+
if (value instanceof Date) return true;
|
|
867
|
+
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value)) return false;
|
|
868
|
+
const d = new Date(value);
|
|
869
|
+
return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === value;
|
|
870
|
+
}
|
|
871
|
+
__name(isIsoDate, "isIsoDate");
|
|
872
|
+
|
|
873
|
+
// src/utils/is-object-id.js
|
|
874
|
+
var import_mongodb = require("mongodb");
|
|
875
|
+
function isObjectId(value) {
|
|
876
|
+
if (!value) return false;
|
|
877
|
+
if (value instanceof import_mongodb.ObjectId) return true;
|
|
878
|
+
if (typeof value !== "string") return false;
|
|
879
|
+
return value.match(/^[a-fA-F0-9]{24}$/) != null;
|
|
880
|
+
}
|
|
881
|
+
__name(isObjectId, "isObjectId");
|
|
882
|
+
|
|
883
|
+
// src/utils/to-camel-case.js
|
|
884
|
+
function toCamelCase2(input) {
|
|
885
|
+
if (!input) return "";
|
|
886
|
+
const spacedString = String(input).replace(/([-_])/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2");
|
|
887
|
+
const intermediateCased = spacedString.toLowerCase().replace(/\s(.)/g, ($1) => $1.toUpperCase()).replace(/\s/g, "");
|
|
888
|
+
if (!intermediateCased) return "";
|
|
889
|
+
return intermediateCased.charAt(0).toLowerCase() + intermediateCased.slice(1);
|
|
890
|
+
}
|
|
891
|
+
__name(toCamelCase2, "toCamelCase");
|
|
892
|
+
|
|
893
|
+
// src/utils/create-mongodb-url.js
|
|
894
|
+
var import_js_repository = require("@e22m4u/js-repository");
|
|
895
|
+
function createMongodbUrl(options = {}) {
|
|
896
|
+
if (!options || typeof options !== "object" || Array.isArray(options))
|
|
897
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
898
|
+
'The first argument of "createMongodbUrl" must be an Object, but %v given.',
|
|
899
|
+
options
|
|
900
|
+
);
|
|
901
|
+
if (options.protocol && typeof options.protocol !== "string")
|
|
902
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
903
|
+
'MongoDB option "protocol" must be a String, but %v given.',
|
|
904
|
+
options.protocol
|
|
905
|
+
);
|
|
906
|
+
if (options.hostname && typeof options.hostname !== "string")
|
|
907
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
908
|
+
'MongoDB option "hostname" must be a String, but %v given.',
|
|
909
|
+
options.hostname
|
|
910
|
+
);
|
|
911
|
+
if (options.host && typeof options.host !== "string")
|
|
912
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
913
|
+
'MongoDB option "host" must be a String, but %v given.',
|
|
914
|
+
options.host
|
|
915
|
+
);
|
|
916
|
+
if (options.port && typeof options.port !== "number" && typeof options.port !== "string") {
|
|
917
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
918
|
+
'MongoDB option "port" must be a Number or a String, but %v given.',
|
|
919
|
+
options.port
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
if (options.database && typeof options.database !== "string")
|
|
923
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
924
|
+
'MongoDB option "database" must be a String, but %v given.',
|
|
925
|
+
options.database
|
|
926
|
+
);
|
|
927
|
+
if (options.db && typeof options.db !== "string")
|
|
928
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
929
|
+
'MongoDB option "db" must be a String, but %v given.',
|
|
930
|
+
options.db
|
|
931
|
+
);
|
|
932
|
+
if (options.username && typeof options.username !== "string")
|
|
933
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
934
|
+
'MongoDB option "username" must be a String, but %v given.',
|
|
935
|
+
options.username
|
|
936
|
+
);
|
|
937
|
+
if (options.password && typeof options.password !== "string" && typeof options.password !== "number") {
|
|
938
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
939
|
+
'MongoDB option "password" must be a String or a Number, but %v given.',
|
|
940
|
+
options.password
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
if (options.pass && typeof options.pass !== "string" && typeof options.pass !== "number") {
|
|
944
|
+
throw new import_js_repository.InvalidArgumentError(
|
|
945
|
+
'MongoDB option "pass" must be a String or a Number, but %v given.',
|
|
946
|
+
options.pass
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
const protocol = options.protocol || "mongodb";
|
|
950
|
+
const hostname = options.hostname || options.host || "127.0.0.1";
|
|
951
|
+
const port = options.port || 27017;
|
|
952
|
+
const database = options.database || options.db || "database";
|
|
953
|
+
const username = options.username || options.user;
|
|
954
|
+
const password = options.password || options.pass || void 0;
|
|
955
|
+
let portUrl = "";
|
|
956
|
+
if (protocol !== "mongodb+srv") {
|
|
957
|
+
portUrl = ":" + port;
|
|
958
|
+
}
|
|
959
|
+
if (username && password) {
|
|
960
|
+
return `${protocol}://${username}:${password}@${hostname}${portUrl}/${database}`;
|
|
961
|
+
} else {
|
|
962
|
+
return `${protocol}://${hostname}${portUrl}/${database}`;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
__name(createMongodbUrl, "createMongodbUrl");
|
|
966
|
+
|
|
967
|
+
// src/utils/transform-values-deep.js
|
|
968
|
+
var import_js_repository2 = require("@e22m4u/js-repository");
|
|
969
|
+
function transformValuesDeep(value, transformer) {
|
|
970
|
+
if (!transformer || typeof transformer !== "function")
|
|
971
|
+
throw new import_js_repository2.InvalidArgumentError(
|
|
972
|
+
'The second argument of "transformValuesDeep" must be a Function, but %v given.',
|
|
973
|
+
transformer
|
|
974
|
+
);
|
|
975
|
+
if (Array.isArray(value)) {
|
|
976
|
+
value.forEach((v, i) => value[i] = transformValuesDeep(v, transformer));
|
|
977
|
+
return value;
|
|
978
|
+
} else if (value && typeof value === "object") {
|
|
979
|
+
if (!value.constructor || value.constructor && value.constructor.name === "Object") {
|
|
980
|
+
Object.keys(value).forEach((key) => {
|
|
981
|
+
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
982
|
+
value[key] = transformValuesDeep(value[key], transformer);
|
|
983
|
+
});
|
|
984
|
+
return value;
|
|
985
|
+
} else {
|
|
986
|
+
return transformer(value);
|
|
987
|
+
}
|
|
988
|
+
} else {
|
|
989
|
+
return transformer(value);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
__name(transformValuesDeep, "transformValuesDeep");
|
|
993
|
+
|
|
994
|
+
// src/utils/model-name-to-collection-name.js
|
|
995
|
+
function modelNameToCollectionName(modelName) {
|
|
996
|
+
const ccName = toCamelCase2(modelName);
|
|
997
|
+
const woModel = ccName.replace(/Model$/i, "");
|
|
998
|
+
if (woModel.length <= 2) {
|
|
999
|
+
return pluralize(ccName);
|
|
1000
|
+
}
|
|
1001
|
+
return pluralize(woModel);
|
|
1002
|
+
}
|
|
1003
|
+
__name(modelNameToCollectionName, "modelNameToCollectionName");
|
|
1004
|
+
|
|
1005
|
+
// src/mongodb-adapter.js
|
|
962
1006
|
var MONGODB_OPTION_NAMES = [
|
|
963
1007
|
"ALPNProtocols",
|
|
964
1008
|
"allowPartialTrustChain",
|
|
@@ -1096,7 +1140,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1096
1140
|
settings.port = settings.port || 27017;
|
|
1097
1141
|
settings.database = settings.database || settings.db || "database";
|
|
1098
1142
|
super(container, settings);
|
|
1099
|
-
const options = (0,
|
|
1143
|
+
const options = (0, import_js_repository3.selectObjectKeys)(this.settings, MONGODB_OPTION_NAMES);
|
|
1100
1144
|
const url = createMongodbUrl(this.settings);
|
|
1101
1145
|
this._client = new import_mongodb3.MongoClient(url, options);
|
|
1102
1146
|
}
|
|
@@ -1107,7 +1151,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1107
1151
|
* @private
|
|
1108
1152
|
*/
|
|
1109
1153
|
_getIdPropName(modelName) {
|
|
1110
|
-
return this.getService(
|
|
1154
|
+
return this.getService(import_js_repository3.ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
1111
1155
|
modelName
|
|
1112
1156
|
);
|
|
1113
1157
|
}
|
|
@@ -1118,7 +1162,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1118
1162
|
* @private
|
|
1119
1163
|
*/
|
|
1120
1164
|
_getIdColName(modelName) {
|
|
1121
|
-
return this.getService(
|
|
1165
|
+
return this.getService(import_js_repository3.ModelDefinitionUtils).getPrimaryKeyAsColumnName(
|
|
1122
1166
|
modelName
|
|
1123
1167
|
);
|
|
1124
1168
|
}
|
|
@@ -1157,11 +1201,11 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1157
1201
|
*/
|
|
1158
1202
|
_toDatabase(modelName, modelData) {
|
|
1159
1203
|
const tableData = this.getService(
|
|
1160
|
-
|
|
1204
|
+
import_js_repository3.ModelDefinitionUtils
|
|
1161
1205
|
).convertPropertyNamesToColumnNames(modelName, modelData);
|
|
1162
1206
|
const idColName = this._getIdColName(modelName);
|
|
1163
1207
|
if (idColName !== "id" && idColName !== "_id")
|
|
1164
|
-
throw new
|
|
1208
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1165
1209
|
'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
|
|
1166
1210
|
idColName
|
|
1167
1211
|
);
|
|
@@ -1189,7 +1233,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1189
1233
|
if ("_id" in tableData) {
|
|
1190
1234
|
const idColName = this._getIdColName(modelName);
|
|
1191
1235
|
if (idColName !== "id" && idColName !== "_id")
|
|
1192
|
-
throw new
|
|
1236
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1193
1237
|
'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
|
|
1194
1238
|
idColName
|
|
1195
1239
|
);
|
|
@@ -1199,7 +1243,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1199
1243
|
}
|
|
1200
1244
|
}
|
|
1201
1245
|
const modelData = this.getService(
|
|
1202
|
-
|
|
1246
|
+
import_js_repository3.ModelDefinitionUtils
|
|
1203
1247
|
).convertColumnNamesToPropertyNames(modelName, tableData);
|
|
1204
1248
|
return transformValuesDeep(modelData, (value) => {
|
|
1205
1249
|
if (value instanceof import_mongodb2.ObjectId) return String(value);
|
|
@@ -1213,7 +1257,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1213
1257
|
* @param {string} modelName
|
|
1214
1258
|
*/
|
|
1215
1259
|
_getCollectionNameByModelName(modelName) {
|
|
1216
|
-
const modelDef = this.getService(
|
|
1260
|
+
const modelDef = this.getService(import_js_repository3.DefinitionRegistry).getModel(modelName);
|
|
1217
1261
|
if (modelDef.tableName != null) return modelDef.tableName;
|
|
1218
1262
|
return modelNameToCollectionName(modelDef.name);
|
|
1219
1263
|
}
|
|
@@ -1240,7 +1284,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1240
1284
|
* @private
|
|
1241
1285
|
*/
|
|
1242
1286
|
_getIdType(modelName) {
|
|
1243
|
-
const utils = this.getService(
|
|
1287
|
+
const utils = this.getService(import_js_repository3.ModelDefinitionUtils);
|
|
1244
1288
|
const pkPropName = utils.getPrimaryKeyAsPropertyName(modelName);
|
|
1245
1289
|
return utils.getDataTypeByPropertyName(modelName, pkPropName);
|
|
1246
1290
|
}
|
|
@@ -1254,16 +1298,16 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1254
1298
|
*/
|
|
1255
1299
|
_getColName(modelName, propName) {
|
|
1256
1300
|
if (!propName || typeof propName !== "string")
|
|
1257
|
-
throw new
|
|
1301
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1258
1302
|
"Property name must be a non-empty String, but %v given.",
|
|
1259
1303
|
propName
|
|
1260
1304
|
);
|
|
1261
|
-
const utils = this.getService(
|
|
1305
|
+
const utils = this.getService(import_js_repository3.ModelDefinitionUtils);
|
|
1262
1306
|
let colName = propName;
|
|
1263
1307
|
try {
|
|
1264
1308
|
colName = utils.getColumnNameByPropertyName(modelName, propName);
|
|
1265
1309
|
} catch (error) {
|
|
1266
|
-
if (!(error instanceof
|
|
1310
|
+
if (!(error instanceof import_js_repository3.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
|
|
1267
1311
|
throw error;
|
|
1268
1312
|
}
|
|
1269
1313
|
}
|
|
@@ -1279,18 +1323,18 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1279
1323
|
*/
|
|
1280
1324
|
_convertPropNamesChainToColNamesChain(modelName, propsChain) {
|
|
1281
1325
|
if (!modelName || typeof modelName !== "string")
|
|
1282
|
-
throw new
|
|
1326
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1283
1327
|
"Model name must be a non-empty String, but %v given.",
|
|
1284
1328
|
modelName
|
|
1285
1329
|
);
|
|
1286
1330
|
if (!propsChain || typeof propsChain !== "string")
|
|
1287
|
-
throw new
|
|
1331
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1288
1332
|
"Properties chain must be a non-empty String, but %v given.",
|
|
1289
1333
|
propsChain
|
|
1290
1334
|
);
|
|
1291
1335
|
propsChain = propsChain.replace(/\.{2,}/g, ".");
|
|
1292
1336
|
const propNames = propsChain.split(".");
|
|
1293
|
-
const utils = this.getService(
|
|
1337
|
+
const utils = this.getService(import_js_repository3.ModelDefinitionUtils);
|
|
1294
1338
|
let currModelName = modelName;
|
|
1295
1339
|
return propNames.map((currPropName) => {
|
|
1296
1340
|
if (!currModelName) return currPropName;
|
|
@@ -1317,7 +1361,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1317
1361
|
if (fields.indexOf("_id") === -1) fields.push("_id");
|
|
1318
1362
|
return fields.reduce((acc, field) => {
|
|
1319
1363
|
if (!field || typeof field !== "string")
|
|
1320
|
-
throw new
|
|
1364
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1321
1365
|
'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
|
|
1322
1366
|
field
|
|
1323
1367
|
);
|
|
@@ -1344,7 +1388,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1344
1388
|
const idPropName = this._getIdPropName(modelName);
|
|
1345
1389
|
return clause.reduce((acc, order) => {
|
|
1346
1390
|
if (!order || typeof order !== "string")
|
|
1347
|
-
throw new
|
|
1391
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1348
1392
|
'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
|
|
1349
1393
|
order
|
|
1350
1394
|
);
|
|
@@ -1356,7 +1400,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1356
1400
|
try {
|
|
1357
1401
|
field = this._convertPropNamesChainToColNamesChain(modelName, field);
|
|
1358
1402
|
} catch (error) {
|
|
1359
|
-
if (!(error instanceof
|
|
1403
|
+
if (!(error instanceof import_js_repository3.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
|
|
1360
1404
|
throw error;
|
|
1361
1405
|
}
|
|
1362
1406
|
}
|
|
@@ -1376,7 +1420,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1376
1420
|
_buildQuery(modelName, clause) {
|
|
1377
1421
|
if (clause == null) return;
|
|
1378
1422
|
if (typeof clause !== "object" || Array.isArray(clause))
|
|
1379
|
-
throw new
|
|
1423
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1380
1424
|
'The provided option "where" should be an Object, but %v given.',
|
|
1381
1425
|
clause
|
|
1382
1426
|
);
|
|
@@ -1385,7 +1429,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1385
1429
|
Object.keys(clause).forEach((key) => {
|
|
1386
1430
|
var _a, _b;
|
|
1387
1431
|
if (String(key).indexOf("$") !== -1)
|
|
1388
|
-
throw new
|
|
1432
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1389
1433
|
'The symbol "$" is not supported, but %v given.',
|
|
1390
1434
|
key
|
|
1391
1435
|
);
|
|
@@ -1393,7 +1437,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1393
1437
|
if (key === "and" || key === "or" || key === "nor") {
|
|
1394
1438
|
if (cond == null) return;
|
|
1395
1439
|
if (!Array.isArray(cond))
|
|
1396
|
-
throw new
|
|
1440
|
+
throw new import_js_repository3.InvalidOperatorValueError(key, "an Array", cond);
|
|
1397
1441
|
if (cond.length === 0) return;
|
|
1398
1442
|
cond = cond.map((c) => this._buildQuery(modelName, c));
|
|
1399
1443
|
cond = cond.filter((c) => c != null);
|
|
@@ -1446,7 +1490,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1446
1490
|
}
|
|
1447
1491
|
if ("inq" in cond) {
|
|
1448
1492
|
if (!cond.inq || !Array.isArray(cond.inq))
|
|
1449
|
-
throw new
|
|
1493
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1450
1494
|
"inq",
|
|
1451
1495
|
"an Array of possible values",
|
|
1452
1496
|
cond.inq
|
|
@@ -1460,7 +1504,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1460
1504
|
}
|
|
1461
1505
|
if ("nin" in cond) {
|
|
1462
1506
|
if (!cond.nin || !Array.isArray(cond.nin))
|
|
1463
|
-
throw new
|
|
1507
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1464
1508
|
"nin",
|
|
1465
1509
|
"an Array of possible values",
|
|
1466
1510
|
cond
|
|
@@ -1474,7 +1518,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1474
1518
|
}
|
|
1475
1519
|
if ("between" in cond) {
|
|
1476
1520
|
if (!Array.isArray(cond.between) || cond.between.length !== 2)
|
|
1477
|
-
throw new
|
|
1521
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1478
1522
|
"between",
|
|
1479
1523
|
"an Array of 2 elements",
|
|
1480
1524
|
cond.between
|
|
@@ -1485,7 +1529,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1485
1529
|
}
|
|
1486
1530
|
if ("exists" in cond) {
|
|
1487
1531
|
if (typeof cond.exists !== "boolean")
|
|
1488
|
-
throw new
|
|
1532
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1489
1533
|
"exists",
|
|
1490
1534
|
"a Boolean",
|
|
1491
1535
|
cond.exists
|
|
@@ -1494,44 +1538,44 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1494
1538
|
}
|
|
1495
1539
|
if ("like" in cond) {
|
|
1496
1540
|
if (typeof cond.like !== "string" && !(cond.like instanceof RegExp))
|
|
1497
|
-
throw new
|
|
1541
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1498
1542
|
"like",
|
|
1499
1543
|
"a String or RegExp",
|
|
1500
1544
|
cond.like
|
|
1501
1545
|
);
|
|
1502
|
-
opConds.push({ $regex: (0,
|
|
1546
|
+
opConds.push({ $regex: (0, import_js_repository3.likeToRegexp)(cond.like) });
|
|
1503
1547
|
}
|
|
1504
1548
|
if ("nlike" in cond) {
|
|
1505
1549
|
if (typeof cond.nlike !== "string" && !(cond.nlike instanceof RegExp))
|
|
1506
|
-
throw new
|
|
1550
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1507
1551
|
"nlike",
|
|
1508
1552
|
"a String or RegExp",
|
|
1509
1553
|
cond.nlike
|
|
1510
1554
|
);
|
|
1511
|
-
opConds.push({ $not: (0,
|
|
1555
|
+
opConds.push({ $not: (0, import_js_repository3.likeToRegexp)(cond.nlike) });
|
|
1512
1556
|
}
|
|
1513
1557
|
if ("ilike" in cond) {
|
|
1514
1558
|
if (typeof cond.ilike !== "string" && !(cond.ilike instanceof RegExp))
|
|
1515
|
-
throw new
|
|
1559
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1516
1560
|
"ilike",
|
|
1517
1561
|
"a String or RegExp",
|
|
1518
1562
|
cond.ilike
|
|
1519
1563
|
);
|
|
1520
|
-
opConds.push({ $regex: (0,
|
|
1564
|
+
opConds.push({ $regex: (0, import_js_repository3.likeToRegexp)(cond.ilike, true) });
|
|
1521
1565
|
}
|
|
1522
1566
|
if ("nilike" in cond) {
|
|
1523
1567
|
if (typeof cond.nilike !== "string" && !(cond.nilike instanceof RegExp)) {
|
|
1524
|
-
throw new
|
|
1568
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1525
1569
|
"nilike",
|
|
1526
1570
|
"a String or RegExp",
|
|
1527
1571
|
cond.nilike
|
|
1528
1572
|
);
|
|
1529
1573
|
}
|
|
1530
|
-
opConds.push({ $not: (0,
|
|
1574
|
+
opConds.push({ $not: (0, import_js_repository3.likeToRegexp)(cond.nilike, true) });
|
|
1531
1575
|
}
|
|
1532
1576
|
if ("regexp" in cond) {
|
|
1533
1577
|
if (typeof cond.regexp !== "string" && !(cond.regexp instanceof RegExp)) {
|
|
1534
|
-
throw new
|
|
1578
|
+
throw new import_js_repository3.InvalidOperatorValueError(
|
|
1535
1579
|
"regexp",
|
|
1536
1580
|
"a String or RegExp",
|
|
1537
1581
|
cond.regexp
|
|
@@ -1539,11 +1583,11 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1539
1583
|
}
|
|
1540
1584
|
const flags = cond.flags || void 0;
|
|
1541
1585
|
if (flags && typeof flags !== "string")
|
|
1542
|
-
throw new
|
|
1586
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1543
1587
|
"RegExp flags must be a String, but %v given.",
|
|
1544
1588
|
cond.flags
|
|
1545
1589
|
);
|
|
1546
|
-
opConds.push({ $regex: (0,
|
|
1590
|
+
opConds.push({ $regex: (0, import_js_repository3.stringToRegexp)(cond.regexp, flags) });
|
|
1547
1591
|
}
|
|
1548
1592
|
if (opConds.length === 1) {
|
|
1549
1593
|
query[key] = opConds[0];
|
|
@@ -1570,10 +1614,10 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1570
1614
|
const idValue = modelData[idPropName];
|
|
1571
1615
|
if (idValue == null || idValue === "" || idValue === 0) {
|
|
1572
1616
|
const pkType = this._getIdType(modelName);
|
|
1573
|
-
if (pkType !==
|
|
1574
|
-
throw new
|
|
1617
|
+
if (pkType !== import_js_repository3.DataType.STRING && pkType !== import_js_repository3.DataType.ANY)
|
|
1618
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1575
1619
|
"MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
|
|
1576
|
-
(0,
|
|
1620
|
+
(0, import_js_repository3.capitalize)(pkType),
|
|
1577
1621
|
idPropName
|
|
1578
1622
|
);
|
|
1579
1623
|
delete modelData[idPropName];
|
|
@@ -1605,7 +1649,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1605
1649
|
const table = this._getCollection(modelName);
|
|
1606
1650
|
const { matchedCount } = await table.replaceOne({ _id: id }, tableData);
|
|
1607
1651
|
if (matchedCount < 1)
|
|
1608
|
-
throw new
|
|
1652
|
+
throw new import_js_repository3.InvalidArgumentError("Identifier %v is not found.", String(id));
|
|
1609
1653
|
const projection = this._buildProjection(
|
|
1610
1654
|
modelName,
|
|
1611
1655
|
filter && filter.fields
|
|
@@ -1627,10 +1671,10 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1627
1671
|
idValue = this._coerceId(idValue);
|
|
1628
1672
|
if (idValue == null || idValue === "" || idValue === 0) {
|
|
1629
1673
|
const pkType = this._getIdType(modelName);
|
|
1630
|
-
if (pkType !==
|
|
1631
|
-
throw new
|
|
1674
|
+
if (pkType !== import_js_repository3.DataType.STRING && pkType !== import_js_repository3.DataType.ANY)
|
|
1675
|
+
throw new import_js_repository3.InvalidArgumentError(
|
|
1632
1676
|
"MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
|
|
1633
|
-
(0,
|
|
1677
|
+
(0, import_js_repository3.capitalize)(pkType),
|
|
1634
1678
|
idPropName
|
|
1635
1679
|
);
|
|
1636
1680
|
delete modelData[idPropName];
|
|
@@ -1688,7 +1732,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1688
1732
|
const table = this._getCollection(modelName);
|
|
1689
1733
|
const { matchedCount } = await table.updateOne({ _id: id }, { $set: tableData });
|
|
1690
1734
|
if (matchedCount < 1)
|
|
1691
|
-
throw new
|
|
1735
|
+
throw new import_js_repository3.InvalidArgumentError("Identifier %v is not found.", String(id));
|
|
1692
1736
|
const projection = this._buildProjection(
|
|
1693
1737
|
modelName,
|
|
1694
1738
|
filter && filter.fields
|
|
@@ -1732,7 +1776,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
1732
1776
|
);
|
|
1733
1777
|
const patchedData = await table.findOne({ _id: id }, { projection });
|
|
1734
1778
|
if (!patchedData)
|
|
1735
|
-
throw new
|
|
1779
|
+
throw new import_js_repository3.InvalidArgumentError("Identifier %v is not found.", String(id));
|
|
1736
1780
|
return this._fromDatabase(modelName, patchedData);
|
|
1737
1781
|
}
|
|
1738
1782
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-repository-mongodb-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "MongoDB адаптер для @e22m4u/js-repository",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,25 +42,25 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@e22m4u/js-format": "~0.2.0",
|
|
45
|
-
"@e22m4u/js-repository": "~0.
|
|
45
|
+
"@e22m4u/js-repository": "~0.6.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@commitlint/cli": "~
|
|
49
|
-
"@commitlint/config-conventional": "~
|
|
50
|
-
"@eslint/js": "~9.
|
|
48
|
+
"@commitlint/cli": "~20.1.0",
|
|
49
|
+
"@commitlint/config-conventional": "~20.0.0",
|
|
50
|
+
"@eslint/js": "~9.39.0",
|
|
51
51
|
"c8": "~10.1.3",
|
|
52
|
-
"chai": "~6.0
|
|
52
|
+
"chai": "~6.2.0",
|
|
53
53
|
"chai-as-promised": "~8.0.2",
|
|
54
|
-
"dotenv": "~17.2.
|
|
55
|
-
"esbuild": "~0.25.
|
|
56
|
-
"eslint": "~9.
|
|
54
|
+
"dotenv": "~17.2.3",
|
|
55
|
+
"esbuild": "~0.25.12",
|
|
56
|
+
"eslint": "~9.39.0",
|
|
57
57
|
"eslint-config-prettier": "~10.1.8",
|
|
58
58
|
"eslint-plugin-chai-expect": "~3.1.0",
|
|
59
|
-
"eslint-plugin-mocha": "~11.
|
|
60
|
-
"globals": "~16.
|
|
59
|
+
"eslint-plugin-mocha": "~11.2.0",
|
|
60
|
+
"globals": "~16.5.0",
|
|
61
61
|
"husky": "~9.1.7",
|
|
62
|
-
"mocha": "~11.7.
|
|
62
|
+
"mocha": "~11.7.4",
|
|
63
63
|
"prettier": "~3.6.2",
|
|
64
|
-
"rimraf": "~6.0
|
|
64
|
+
"rimraf": "~6.1.0"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/mongodb-adapter.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
/* eslint no-unused-vars: 0 */
|
|
2
2
|
import {ObjectId} from 'mongodb';
|
|
3
3
|
import {MongoClient} from 'mongodb';
|
|
4
|
-
import {isIsoDate} from './utils/index.js';
|
|
5
|
-
import {isObjectId} from './utils/index.js';
|
|
6
|
-
import {Adapter} from '@e22m4u/js-repository';
|
|
7
|
-
import {DataType} from '@e22m4u/js-repository';
|
|
8
|
-
import {capitalize} from '@e22m4u/js-repository';
|
|
9
|
-
import {createMongodbUrl} from './utils/index.js';
|
|
10
4
|
import {ServiceContainer} from '@e22m4u/js-service';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Adapter,
|
|
8
|
+
DataType,
|
|
9
|
+
likeToRegexp,
|
|
10
|
+
capitalize,
|
|
11
|
+
stringToRegexp,
|
|
12
|
+
selectObjectKeys,
|
|
13
|
+
DefinitionRegistry,
|
|
14
|
+
ModelDefinitionUtils,
|
|
15
|
+
InvalidArgumentError,
|
|
16
|
+
InvalidOperatorValueError,
|
|
17
|
+
} from '@e22m4u/js-repository';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
isIsoDate,
|
|
21
|
+
isObjectId,
|
|
22
|
+
createMongodbUrl,
|
|
23
|
+
transformValuesDeep,
|
|
24
|
+
modelNameToCollectionName,
|
|
25
|
+
} from './utils/index.js';
|
|
19
26
|
|
|
20
27
|
/**
|
|
21
28
|
* Mongodb option names.
|
|
@@ -630,7 +637,7 @@ export class MongodbAdapter extends Adapter {
|
|
|
630
637
|
'a String or RegExp',
|
|
631
638
|
cond.like,
|
|
632
639
|
);
|
|
633
|
-
opConds.push({$regex:
|
|
640
|
+
opConds.push({$regex: likeToRegexp(cond.like)});
|
|
634
641
|
}
|
|
635
642
|
// nlike
|
|
636
643
|
if ('nlike' in cond) {
|
|
@@ -640,7 +647,7 @@ export class MongodbAdapter extends Adapter {
|
|
|
640
647
|
'a String or RegExp',
|
|
641
648
|
cond.nlike,
|
|
642
649
|
);
|
|
643
|
-
opConds.push({$not:
|
|
650
|
+
opConds.push({$not: likeToRegexp(cond.nlike)});
|
|
644
651
|
}
|
|
645
652
|
// ilike
|
|
646
653
|
if ('ilike' in cond) {
|
|
@@ -650,7 +657,7 @@ export class MongodbAdapter extends Adapter {
|
|
|
650
657
|
'a String or RegExp',
|
|
651
658
|
cond.ilike,
|
|
652
659
|
);
|
|
653
|
-
opConds.push({$regex:
|
|
660
|
+
opConds.push({$regex: likeToRegexp(cond.ilike, true)});
|
|
654
661
|
}
|
|
655
662
|
// nilike
|
|
656
663
|
if ('nilike' in cond) {
|
|
@@ -664,7 +671,7 @@ export class MongodbAdapter extends Adapter {
|
|
|
664
671
|
cond.nilike,
|
|
665
672
|
);
|
|
666
673
|
}
|
|
667
|
-
opConds.push({$not:
|
|
674
|
+
opConds.push({$not: likeToRegexp(cond.nilike, true)});
|
|
668
675
|
}
|
|
669
676
|
// regexp and flags (optional)
|
|
670
677
|
if ('regexp' in cond) {
|
|
@@ -1164,39 +1164,63 @@ describe('MongodbAdapter', function () {
|
|
|
1164
1164
|
});
|
|
1165
1165
|
|
|
1166
1166
|
it('converts the "like" operator to "$regex"', async function () {
|
|
1167
|
-
const
|
|
1167
|
+
const input1 = {foo: {like: 'test'}};
|
|
1168
|
+
const input2 = {foo: {like: 'test%'}};
|
|
1169
|
+
const input3 = {foo: {like: 'test_'}};
|
|
1168
1170
|
const schema = createSchema();
|
|
1169
1171
|
schema.defineModel({name: 'model', datasource: 'mongodb'});
|
|
1170
1172
|
const A = await schema.getService(AdapterRegistry).getAdapter('mongodb');
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
+
const res1 = A._buildQuery('model', input1);
|
|
1174
|
+
const res2 = A._buildQuery('model', input2);
|
|
1175
|
+
const res3 = A._buildQuery('model', input3);
|
|
1176
|
+
expect(res1).to.be.eql({foo: {$regex: /^test$/}});
|
|
1177
|
+
expect(res2).to.be.eql({foo: {$regex: /^test.*$/}});
|
|
1178
|
+
expect(res3).to.be.eql({foo: {$regex: /^test.$/}});
|
|
1173
1179
|
});
|
|
1174
1180
|
|
|
1175
1181
|
it('converts the "nlike" operator to "$not"', async function () {
|
|
1176
|
-
const
|
|
1182
|
+
const input1 = {foo: {nlike: 'test'}};
|
|
1183
|
+
const input2 = {foo: {nlike: 'test%'}};
|
|
1184
|
+
const input3 = {foo: {nlike: 'test_'}};
|
|
1177
1185
|
const schema = createSchema();
|
|
1178
1186
|
schema.defineModel({name: 'model', datasource: 'mongodb'});
|
|
1179
1187
|
const A = await schema.getService(AdapterRegistry).getAdapter('mongodb');
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1188
|
+
const res1 = A._buildQuery('model', input1);
|
|
1189
|
+
const res2 = A._buildQuery('model', input2);
|
|
1190
|
+
const res3 = A._buildQuery('model', input3);
|
|
1191
|
+
expect(res1).to.be.eql({foo: {$not: /^test$/}});
|
|
1192
|
+
expect(res2).to.be.eql({foo: {$not: /^test.*$/}});
|
|
1193
|
+
expect(res3).to.be.eql({foo: {$not: /^test.$/}});
|
|
1182
1194
|
});
|
|
1183
1195
|
|
|
1184
1196
|
it('converts the "ilike" operator to "$regex" with "i" flag', async function () {
|
|
1185
|
-
const
|
|
1197
|
+
const input1 = {foo: {ilike: 'test'}};
|
|
1198
|
+
const input2 = {foo: {ilike: 'test%'}};
|
|
1199
|
+
const input3 = {foo: {ilike: 'test_'}};
|
|
1186
1200
|
const schema = createSchema();
|
|
1187
1201
|
schema.defineModel({name: 'model', datasource: 'mongodb'});
|
|
1188
1202
|
const A = await schema.getService(AdapterRegistry).getAdapter('mongodb');
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1203
|
+
const res1 = A._buildQuery('model', input1);
|
|
1204
|
+
const res2 = A._buildQuery('model', input2);
|
|
1205
|
+
const res3 = A._buildQuery('model', input3);
|
|
1206
|
+
expect(res1).to.be.eql({foo: {$regex: /^test$/i}});
|
|
1207
|
+
expect(res2).to.be.eql({foo: {$regex: /^test.*$/i}});
|
|
1208
|
+
expect(res3).to.be.eql({foo: {$regex: /^test.$/i}});
|
|
1191
1209
|
});
|
|
1192
1210
|
|
|
1193
1211
|
it('converts the "nilike" operator to "$not" with "i" flag', async function () {
|
|
1194
|
-
const
|
|
1212
|
+
const input1 = {foo: {nilike: 'test'}};
|
|
1213
|
+
const input2 = {foo: {nilike: 'test%'}};
|
|
1214
|
+
const input3 = {foo: {nilike: 'test_'}};
|
|
1195
1215
|
const schema = createSchema();
|
|
1196
1216
|
schema.defineModel({name: 'model', datasource: 'mongodb'});
|
|
1197
1217
|
const A = await schema.getService(AdapterRegistry).getAdapter('mongodb');
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1218
|
+
const res1 = A._buildQuery('model', input1);
|
|
1219
|
+
const res2 = A._buildQuery('model', input2);
|
|
1220
|
+
const res3 = A._buildQuery('model', input3);
|
|
1221
|
+
expect(res1).to.be.eql({foo: {$not: /^test$/i}});
|
|
1222
|
+
expect(res2).to.be.eql({foo: {$not: /^test.*$/i}});
|
|
1223
|
+
expect(res3).to.be.eql({foo: {$not: /^test.$/i}});
|
|
1200
1224
|
});
|
|
1201
1225
|
|
|
1202
1226
|
it('converts property value to an instance of ObjectId', async function () {
|
|
@@ -1442,10 +1466,10 @@ describe('MongodbAdapter', function () {
|
|
|
1442
1466
|
{foo: {$nin: ['qwe']}},
|
|
1443
1467
|
{foo: {$gte: 100, $lte: 200}},
|
|
1444
1468
|
{foo: {$exists: true}},
|
|
1445
|
-
{foo: {$regex:
|
|
1446
|
-
{foo: {$not:
|
|
1447
|
-
{foo: {$regex:
|
|
1448
|
-
{foo: {$not:
|
|
1469
|
+
{foo: {$regex: /^asd$/}},
|
|
1470
|
+
{foo: {$not: /^zxc$/}},
|
|
1471
|
+
{foo: {$regex: /^rty$/i}},
|
|
1472
|
+
{foo: {$not: /^fgh$/i}},
|
|
1449
1473
|
{foo: {$regex: /vbn/i}},
|
|
1450
1474
|
],
|
|
1451
1475
|
};
|
|
@@ -1492,10 +1516,10 @@ describe('MongodbAdapter', function () {
|
|
|
1492
1516
|
{foo: {$nin: ['qwe']}},
|
|
1493
1517
|
{foo: {$gte: 100, $lte: 200}},
|
|
1494
1518
|
{foo: {$exists: true}},
|
|
1495
|
-
{foo: {$regex:
|
|
1496
|
-
{foo: {$not:
|
|
1497
|
-
{foo: {$regex:
|
|
1498
|
-
{foo: {$not:
|
|
1519
|
+
{foo: {$regex: /^asd$/}},
|
|
1520
|
+
{foo: {$not: /^zxc$/}},
|
|
1521
|
+
{foo: {$regex: /^rty$/i}},
|
|
1522
|
+
{foo: {$not: /^fgh$/i}},
|
|
1499
1523
|
{foo: {$regex: /vbn/i}},
|
|
1500
1524
|
],
|
|
1501
1525
|
};
|
|
@@ -3814,7 +3838,7 @@ describe('MongodbAdapter', function () {
|
|
|
3814
3838
|
const id4 = input4[DEF_PK];
|
|
3815
3839
|
const result = await rep.patch(
|
|
3816
3840
|
{foo: 'test'},
|
|
3817
|
-
{foo: {like: 'sit amet'}},
|
|
3841
|
+
{foo: {like: '%sit amet%'}},
|
|
3818
3842
|
);
|
|
3819
3843
|
expect(result).to.be.eq(2);
|
|
3820
3844
|
const rawData = await MDB_CLIENT.db()
|
|
@@ -3843,7 +3867,7 @@ describe('MongodbAdapter', function () {
|
|
|
3843
3867
|
const id4 = input4[DEF_PK];
|
|
3844
3868
|
const result = await rep.patch(
|
|
3845
3869
|
{foo: 'test'},
|
|
3846
|
-
{foo: {nlike: 'sit amet'}},
|
|
3870
|
+
{foo: {nlike: '%sit amet%'}},
|
|
3847
3871
|
);
|
|
3848
3872
|
expect(result).to.be.eq(2);
|
|
3849
3873
|
const rawData = await MDB_CLIENT.db()
|
|
@@ -3872,7 +3896,7 @@ describe('MongodbAdapter', function () {
|
|
|
3872
3896
|
const id4 = input4[DEF_PK];
|
|
3873
3897
|
const result = await rep.patch(
|
|
3874
3898
|
{foo: 'test'},
|
|
3875
|
-
{foo: {ilike: 'sit amet'}},
|
|
3899
|
+
{foo: {ilike: '%sit amet%'}},
|
|
3876
3900
|
);
|
|
3877
3901
|
expect(result).to.be.eq(3);
|
|
3878
3902
|
const rawData = await MDB_CLIENT.db()
|
|
@@ -3901,7 +3925,7 @@ describe('MongodbAdapter', function () {
|
|
|
3901
3925
|
const id4 = input4[DEF_PK];
|
|
3902
3926
|
const result = await rep.patch(
|
|
3903
3927
|
{foo: 'test'},
|
|
3904
|
-
{foo: {nilike: 'sit amet'}},
|
|
3928
|
+
{foo: {nilike: '%sit amet%'}},
|
|
3905
3929
|
);
|
|
3906
3930
|
expect(result).to.be.eq(1);
|
|
3907
3931
|
const rawData = await MDB_CLIENT.db()
|
|
@@ -4703,7 +4727,7 @@ describe('MongodbAdapter', function () {
|
|
|
4703
4727
|
const created2 = await rep.create({foo: 'dolor sit amet'});
|
|
4704
4728
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
4705
4729
|
const created4 = await rep.create({foo: 'sit amet'});
|
|
4706
|
-
const result = await rep.find({where: {foo: {like: 'sit amet'}}});
|
|
4730
|
+
const result = await rep.find({where: {foo: {like: '%sit amet%'}}});
|
|
4707
4731
|
expect(result).to.be.eql([
|
|
4708
4732
|
{[DEF_PK]: created2[DEF_PK], foo: 'dolor sit amet'},
|
|
4709
4733
|
{[DEF_PK]: created4[DEF_PK], foo: 'sit amet'},
|
|
@@ -4718,7 +4742,7 @@ describe('MongodbAdapter', function () {
|
|
|
4718
4742
|
const created2 = await rep.create({foo: 'dolor sit amet'});
|
|
4719
4743
|
const created3 = await rep.create({foo: 'DOLOR SIT AMET'});
|
|
4720
4744
|
const created4 = await rep.create({foo: 'sit amet'});
|
|
4721
|
-
const result = await rep.find({where: {foo: {ilike: 'sit amet'}}});
|
|
4745
|
+
const result = await rep.find({where: {foo: {ilike: '%sit amet%'}}});
|
|
4722
4746
|
expect(result).to.be.eql([
|
|
4723
4747
|
{[DEF_PK]: created2[DEF_PK], foo: 'dolor sit amet'},
|
|
4724
4748
|
{[DEF_PK]: created3[DEF_PK], foo: 'DOLOR SIT AMET'},
|
|
@@ -4734,7 +4758,7 @@ describe('MongodbAdapter', function () {
|
|
|
4734
4758
|
await rep.create({foo: 'dolor sit amet'});
|
|
4735
4759
|
const created3 = await rep.create({foo: 'DOLOR SIT AMET'});
|
|
4736
4760
|
await rep.create({foo: 'sit amet'});
|
|
4737
|
-
const result = await rep.find({where: {foo: {nlike: 'sit amet'}}});
|
|
4761
|
+
const result = await rep.find({where: {foo: {nlike: '%sit amet%'}}});
|
|
4738
4762
|
expect(result).to.be.eql([
|
|
4739
4763
|
{[DEF_PK]: created1[DEF_PK], foo: 'lorem ipsum'},
|
|
4740
4764
|
{[DEF_PK]: created3[DEF_PK], foo: 'DOLOR SIT AMET'},
|
|
@@ -4749,7 +4773,7 @@ describe('MongodbAdapter', function () {
|
|
|
4749
4773
|
await rep.create({foo: 'dolor sit amet'});
|
|
4750
4774
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
4751
4775
|
await rep.create({foo: 'sit amet'});
|
|
4752
|
-
const result = await rep.find({where: {foo: {nilike: 'sit amet'}}});
|
|
4776
|
+
const result = await rep.find({where: {foo: {nilike: '%sit amet%'}}});
|
|
4753
4777
|
expect(result).to.be.eql([
|
|
4754
4778
|
{[DEF_PK]: created1[DEF_PK], foo: 'lorem ipsum'},
|
|
4755
4779
|
]);
|
|
@@ -5077,7 +5101,7 @@ describe('MongodbAdapter', function () {
|
|
|
5077
5101
|
await rep.create({foo: 'dolor sit amet'});
|
|
5078
5102
|
const created3 = await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5079
5103
|
await rep.create({foo: 'sit amet'});
|
|
5080
|
-
const result = await rep.delete({foo: {like: 'sit amet'}});
|
|
5104
|
+
const result = await rep.delete({foo: {like: '%sit amet%'}});
|
|
5081
5105
|
expect(result).to.be.eq(2);
|
|
5082
5106
|
const rawData = await MDB_CLIENT.db()
|
|
5083
5107
|
.collection('models')
|
|
@@ -5097,7 +5121,7 @@ describe('MongodbAdapter', function () {
|
|
|
5097
5121
|
const created2 = await rep.create({foo: 'dolor sit amet'});
|
|
5098
5122
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5099
5123
|
const created4 = await rep.create({foo: 'sit amet'});
|
|
5100
|
-
const result = await rep.delete({foo: {nlike: 'sit amet'}});
|
|
5124
|
+
const result = await rep.delete({foo: {nlike: '%sit amet%'}});
|
|
5101
5125
|
expect(result).to.be.eq(2);
|
|
5102
5126
|
const rawData = await MDB_CLIENT.db()
|
|
5103
5127
|
.collection('models')
|
|
@@ -5117,7 +5141,7 @@ describe('MongodbAdapter', function () {
|
|
|
5117
5141
|
await rep.create({foo: 'dolor sit amet'});
|
|
5118
5142
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5119
5143
|
await rep.create({foo: 'sit amet'});
|
|
5120
|
-
const result = await rep.delete({foo: {ilike: 'sit amet'}});
|
|
5144
|
+
const result = await rep.delete({foo: {ilike: '%sit amet%'}});
|
|
5121
5145
|
expect(result).to.be.eq(3);
|
|
5122
5146
|
const rawData = await MDB_CLIENT.db()
|
|
5123
5147
|
.collection('models')
|
|
@@ -5136,7 +5160,7 @@ describe('MongodbAdapter', function () {
|
|
|
5136
5160
|
const created2 = await rep.create({foo: 'dolor sit amet'});
|
|
5137
5161
|
const created3 = await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5138
5162
|
const created4 = await rep.create({foo: 'sit amet'});
|
|
5139
|
-
const result = await rep.delete({foo: {nilike: 'sit amet'}});
|
|
5163
|
+
const result = await rep.delete({foo: {nilike: '%sit amet%'}});
|
|
5140
5164
|
expect(result).to.be.eq(1);
|
|
5141
5165
|
const rawData = await MDB_CLIENT.db()
|
|
5142
5166
|
.collection('models')
|
|
@@ -5401,7 +5425,7 @@ describe('MongodbAdapter', function () {
|
|
|
5401
5425
|
await rep.create({foo: 'dolor sit amet'});
|
|
5402
5426
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5403
5427
|
await rep.create({foo: 'sit amet'});
|
|
5404
|
-
const result = await rep.count({foo: {like: 'sit amet'}});
|
|
5428
|
+
const result = await rep.count({foo: {like: '%sit amet%'}});
|
|
5405
5429
|
expect(result).to.be.eql(2);
|
|
5406
5430
|
});
|
|
5407
5431
|
|
|
@@ -5413,7 +5437,7 @@ describe('MongodbAdapter', function () {
|
|
|
5413
5437
|
await rep.create({foo: 'dolor sit amet'});
|
|
5414
5438
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5415
5439
|
await rep.create({foo: 'sit amet'});
|
|
5416
|
-
const result = await rep.count({foo: {nlike: 'sit amet'}});
|
|
5440
|
+
const result = await rep.count({foo: {nlike: '%sit amet%'}});
|
|
5417
5441
|
expect(result).to.be.eql(2);
|
|
5418
5442
|
});
|
|
5419
5443
|
|
|
@@ -5425,7 +5449,7 @@ describe('MongodbAdapter', function () {
|
|
|
5425
5449
|
await rep.create({foo: 'dolor sit amet'});
|
|
5426
5450
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5427
5451
|
await rep.create({foo: 'sit amet'});
|
|
5428
|
-
const result = await rep.count({foo: {ilike: 'sit amet'}});
|
|
5452
|
+
const result = await rep.count({foo: {ilike: '%sit amet%'}});
|
|
5429
5453
|
expect(result).to.be.eql(3);
|
|
5430
5454
|
});
|
|
5431
5455
|
|
|
@@ -5437,7 +5461,7 @@ describe('MongodbAdapter', function () {
|
|
|
5437
5461
|
await rep.create({foo: 'dolor sit amet'});
|
|
5438
5462
|
await rep.create({foo: 'DOLOR SIT AMET'});
|
|
5439
5463
|
await rep.create({foo: 'sit amet'});
|
|
5440
|
-
const result = await rep.count({foo: {nilike: 'sit amet'}});
|
|
5464
|
+
const result = await rep.count({foo: {nilike: '%sit amet%'}});
|
|
5441
5465
|
expect(result).to.be.eql(1);
|
|
5442
5466
|
});
|
|
5443
5467
|
|