@orion-js/mongodb 4.0.0-next.5 → 4.0.0-next.7
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/index.cjs +246 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +235 -44
- package/dist/index.js.map +1 -1
- package/package.json +10 -12
package/dist/index.cjs
CHANGED
|
@@ -197,15 +197,215 @@ function typedId(prefix) {
|
|
|
197
197
|
// src/service/index.ts
|
|
198
198
|
var import_services = require("@orion-js/services");
|
|
199
199
|
|
|
200
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
|
|
201
|
+
function type(input) {
|
|
202
|
+
if (input === null) {
|
|
203
|
+
return "Null";
|
|
204
|
+
} else if (input === void 0) {
|
|
205
|
+
return "Undefined";
|
|
206
|
+
} else if (Number.isNaN(input)) {
|
|
207
|
+
return "NaN";
|
|
208
|
+
}
|
|
209
|
+
const typeResult = Object.prototype.toString.call(input).slice(8, -1);
|
|
210
|
+
return typeResult === "AsyncFunction" ? "Promise" : typeResult;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
|
|
214
|
+
var { isArray } = Array;
|
|
215
|
+
|
|
216
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
|
|
217
|
+
function _isInteger(n) {
|
|
218
|
+
return n << 0 === n;
|
|
219
|
+
}
|
|
220
|
+
var isInteger = Number.isInteger || _isInteger;
|
|
221
|
+
|
|
222
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
|
|
223
|
+
function createPath(path, delimiter = ".") {
|
|
224
|
+
return typeof path === "string" ? path.split(delimiter).map((x) => isInteger(x) ? Number(x) : x) : path;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/equals.js
|
|
228
|
+
function _indexOf(valueToFind, list) {
|
|
229
|
+
if (!isArray(list))
|
|
230
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
231
|
+
const typeOfValue = type(valueToFind);
|
|
232
|
+
if (!["Array", "NaN", "Object", "RegExp"].includes(typeOfValue))
|
|
233
|
+
return list.indexOf(valueToFind);
|
|
234
|
+
let index = -1;
|
|
235
|
+
let foundIndex = -1;
|
|
236
|
+
const { length } = list;
|
|
237
|
+
while (++index < length && foundIndex === -1)
|
|
238
|
+
if (equals(list[index], valueToFind))
|
|
239
|
+
foundIndex = index;
|
|
240
|
+
return foundIndex;
|
|
241
|
+
}
|
|
242
|
+
function _arrayFromIterator(iter) {
|
|
243
|
+
const list = [];
|
|
244
|
+
let next;
|
|
245
|
+
while (!(next = iter.next()).done)
|
|
246
|
+
list.push(next.value);
|
|
247
|
+
return list;
|
|
248
|
+
}
|
|
249
|
+
function _compareSets(a, b) {
|
|
250
|
+
if (a.size !== b.size)
|
|
251
|
+
return false;
|
|
252
|
+
const aList = _arrayFromIterator(a.values());
|
|
253
|
+
const bList = _arrayFromIterator(b.values());
|
|
254
|
+
const filtered = aList.filter((aInstance) => _indexOf(aInstance, bList) === -1);
|
|
255
|
+
return filtered.length === 0;
|
|
256
|
+
}
|
|
257
|
+
function compareErrors(a, b) {
|
|
258
|
+
if (a.message !== b.message) return false;
|
|
259
|
+
if (a.toString !== b.toString) return false;
|
|
260
|
+
return a.toString() === b.toString();
|
|
261
|
+
}
|
|
262
|
+
function parseDate(maybeDate) {
|
|
263
|
+
if (!maybeDate.toDateString) return [false];
|
|
264
|
+
return [true, maybeDate.getTime()];
|
|
265
|
+
}
|
|
266
|
+
function parseRegex(maybeRegex) {
|
|
267
|
+
if (maybeRegex.constructor !== RegExp) return [false];
|
|
268
|
+
return [true, maybeRegex.toString()];
|
|
269
|
+
}
|
|
270
|
+
function equals(a, b) {
|
|
271
|
+
if (arguments.length === 1) return (_b) => equals(a, _b);
|
|
272
|
+
if (Object.is(a, b)) return true;
|
|
273
|
+
const aType = type(a);
|
|
274
|
+
if (aType !== type(b)) return false;
|
|
275
|
+
if (aType === "Function")
|
|
276
|
+
return a.name === void 0 ? false : a.name === b.name;
|
|
277
|
+
if (["NaN", "Null", "Undefined"].includes(aType)) return true;
|
|
278
|
+
if (["BigInt", "Number"].includes(aType)) {
|
|
279
|
+
if (Object.is(-0, a) !== Object.is(-0, b)) return false;
|
|
280
|
+
return a.toString() === b.toString();
|
|
281
|
+
}
|
|
282
|
+
if (["Boolean", "String"].includes(aType))
|
|
283
|
+
return a.toString() === b.toString();
|
|
284
|
+
if (aType === "Array") {
|
|
285
|
+
const aClone = Array.from(a);
|
|
286
|
+
const bClone = Array.from(b);
|
|
287
|
+
if (aClone.toString() !== bClone.toString())
|
|
288
|
+
return false;
|
|
289
|
+
let loopArrayFlag = true;
|
|
290
|
+
aClone.forEach((aCloneInstance, aCloneIndex) => {
|
|
291
|
+
if (loopArrayFlag) {
|
|
292
|
+
if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex]))
|
|
293
|
+
loopArrayFlag = false;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
return loopArrayFlag;
|
|
297
|
+
}
|
|
298
|
+
const aRegex = parseRegex(a);
|
|
299
|
+
const bRegex = parseRegex(b);
|
|
300
|
+
if (aRegex[0])
|
|
301
|
+
return bRegex[0] ? aRegex[1] === bRegex[1] : false;
|
|
302
|
+
else if (bRegex[0]) return false;
|
|
303
|
+
const aDate = parseDate(a);
|
|
304
|
+
const bDate = parseDate(b);
|
|
305
|
+
if (aDate[0])
|
|
306
|
+
return bDate[0] ? aDate[1] === bDate[1] : false;
|
|
307
|
+
else if (bDate[0]) return false;
|
|
308
|
+
if (a instanceof Error) {
|
|
309
|
+
if (!(b instanceof Error)) return false;
|
|
310
|
+
return compareErrors(a, b);
|
|
311
|
+
}
|
|
312
|
+
if (aType === "Set")
|
|
313
|
+
return _compareSets(a, b);
|
|
314
|
+
if (aType === "Object") {
|
|
315
|
+
const aKeys = Object.keys(a);
|
|
316
|
+
if (aKeys.length !== Object.keys(b).length)
|
|
317
|
+
return false;
|
|
318
|
+
let loopObjectFlag = true;
|
|
319
|
+
aKeys.forEach((aKeyInstance) => {
|
|
320
|
+
if (loopObjectFlag) {
|
|
321
|
+
const aValue = a[aKeyInstance];
|
|
322
|
+
const bValue = b[aKeyInstance];
|
|
323
|
+
if (aValue !== bValue && !equals(aValue, bValue))
|
|
324
|
+
loopObjectFlag = false;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
return loopObjectFlag;
|
|
328
|
+
}
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isType.js
|
|
333
|
+
function isType(xType, x) {
|
|
334
|
+
if (arguments.length === 1) {
|
|
335
|
+
return (xHolder) => isType(xType, xHolder);
|
|
336
|
+
}
|
|
337
|
+
return type(x) === xType;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
|
|
341
|
+
function compare(a, b) {
|
|
342
|
+
return String(a) === String(b);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
|
|
346
|
+
function includes(a, list) {
|
|
347
|
+
let index = -1;
|
|
348
|
+
const { length } = list;
|
|
349
|
+
while (++index < length)
|
|
350
|
+
if (compare(list[index], a))
|
|
351
|
+
return true;
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/omit.js
|
|
356
|
+
function omit(propsToOmit, obj) {
|
|
357
|
+
if (arguments.length === 1) return (_obj) => omit(propsToOmit, _obj);
|
|
358
|
+
if (obj === null || obj === void 0)
|
|
359
|
+
return void 0;
|
|
360
|
+
const propsToOmitValue = createPath(propsToOmit, ",");
|
|
361
|
+
const willReturn = {};
|
|
362
|
+
for (const key in obj)
|
|
363
|
+
if (!includes(key, propsToOmitValue))
|
|
364
|
+
willReturn[key] = obj[key];
|
|
365
|
+
return willReturn;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/flatten.js
|
|
369
|
+
function flatten(list, input) {
|
|
370
|
+
const willReturn = input === void 0 ? [] : input;
|
|
371
|
+
for (let i = 0; i < list.length; i++) {
|
|
372
|
+
if (isArray(list[i])) {
|
|
373
|
+
flatten(list[i], willReturn);
|
|
374
|
+
} else {
|
|
375
|
+
willReturn.push(list[i]);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return willReturn;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
|
|
382
|
+
function isEmpty(input) {
|
|
383
|
+
const inputType = type(input);
|
|
384
|
+
if (["Undefined", "NaN", "Number", "Null"].includes(inputType))
|
|
385
|
+
return false;
|
|
386
|
+
if (!input) return true;
|
|
387
|
+
if (inputType === "Object") {
|
|
388
|
+
return Object.keys(input).length === 0;
|
|
389
|
+
}
|
|
390
|
+
if (inputType === "Array") {
|
|
391
|
+
return input.length === 0;
|
|
392
|
+
}
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isNil.js
|
|
397
|
+
function isNil(x) {
|
|
398
|
+
return x === void 0 || x === null;
|
|
399
|
+
}
|
|
400
|
+
|
|
200
401
|
// src/createCollection/getMethods/getSelector.ts
|
|
201
|
-
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
202
402
|
function getSelector(args) {
|
|
203
403
|
if (args.length === 0) return {};
|
|
204
404
|
const selector = args[0];
|
|
205
405
|
if (typeof selector === "string") {
|
|
206
406
|
return { _id: selector };
|
|
207
407
|
}
|
|
208
|
-
if ((
|
|
408
|
+
if (type(selector) === "Object") {
|
|
209
409
|
return selector;
|
|
210
410
|
}
|
|
211
411
|
return {
|
|
@@ -305,11 +505,14 @@ async function validateInc_default({ schema, operationDoc }) {
|
|
|
305
505
|
|
|
306
506
|
// src/createCollection/getMethods/validateModifier/validateSet.ts
|
|
307
507
|
var import_schema5 = require("@orion-js/schema");
|
|
308
|
-
var import_mapKeys = __toESM(require("lodash/mapKeys"), 1);
|
|
309
508
|
async function validateSet_default({ schema, operationDoc }) {
|
|
310
509
|
let cleaned = toDot_default(operationDoc);
|
|
311
|
-
|
|
312
|
-
cleaned
|
|
510
|
+
const transformedObj = {};
|
|
511
|
+
Object.keys(cleaned).map((key) => {
|
|
512
|
+
const newKey = key.replace("$.", "0.");
|
|
513
|
+
transformedObj[newKey] = cleaned[key];
|
|
514
|
+
});
|
|
515
|
+
cleaned = fromDot(transformedObj);
|
|
313
516
|
await (0, import_schema5.validate)(schema, cleaned, { omitRequired: true });
|
|
314
517
|
}
|
|
315
518
|
|
|
@@ -346,8 +549,7 @@ async function validateModifier(schema, modifier) {
|
|
|
346
549
|
|
|
347
550
|
// src/createCollection/getMethods/validateModifier/validateUpsert.ts
|
|
348
551
|
var import_schema6 = require("@orion-js/schema");
|
|
349
|
-
var
|
|
350
|
-
var getPushSimulation = function($push) {
|
|
552
|
+
var getPushSimulation = ($push) => {
|
|
351
553
|
if (!$push) return {};
|
|
352
554
|
const simulation = {};
|
|
353
555
|
for (const key of Object.keys($push)) {
|
|
@@ -360,31 +562,25 @@ var getPushSimulation = function($push) {
|
|
|
360
562
|
}
|
|
361
563
|
return simulation;
|
|
362
564
|
};
|
|
363
|
-
var simulateNewDoc =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
};
|
|
373
|
-
var validateNewDoc = async function(schema, selector, modifier) {
|
|
565
|
+
var simulateNewDoc = (selector, modifier) => fromDot({
|
|
566
|
+
...selector,
|
|
567
|
+
...modifier.$set,
|
|
568
|
+
...modifier.$inc,
|
|
569
|
+
...getPushSimulation(modifier.$push),
|
|
570
|
+
...getPushSimulation(modifier.$addToSet),
|
|
571
|
+
...modifier.$setOnInsert
|
|
572
|
+
});
|
|
573
|
+
var validateNewDoc = async (schema, selector, modifier) => {
|
|
374
574
|
const doc = simulateNewDoc(selector, modifier);
|
|
375
575
|
await (0, import_schema6.validate)(schema, doc);
|
|
376
576
|
};
|
|
377
577
|
async function validateUpsert_default(schema, selector, modifier) {
|
|
378
578
|
await validateNewDoc(schema, selector, modifier);
|
|
379
|
-
await validateModifier(schema, (
|
|
579
|
+
await validateModifier(schema, omit(["$setOnInsert"], modifier));
|
|
380
580
|
}
|
|
381
581
|
|
|
382
582
|
// src/createCollection/getMethods/cleanModifier.ts
|
|
383
583
|
var import_schema7 = require("@orion-js/schema");
|
|
384
|
-
var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
|
|
385
|
-
var import_isNil = __toESM(require("lodash/isNil"), 1);
|
|
386
|
-
var import_isUndefined = __toESM(require("lodash/isUndefined"), 1);
|
|
387
|
-
var import_isEqual = __toESM(require("lodash/isEqual"), 1);
|
|
388
584
|
var shouldCheck2 = (key) => {
|
|
389
585
|
if (key === "$pushAll") throw new Error("$pushAll is not supported; use $push + $each");
|
|
390
586
|
return ["$pull", "$pullAll", "$pop", "$slice"].indexOf(key) === -1;
|
|
@@ -424,23 +620,23 @@ async function cleanModifier(schema, modifier, { isUpsert } = { isUpsert: false
|
|
|
424
620
|
}
|
|
425
621
|
if (operation === "$unset") {
|
|
426
622
|
const isPresent = await (0, import_schema7.cleanKey)(schema, key, "anyvalue", cleanOptions);
|
|
427
|
-
cleaned = !(
|
|
623
|
+
cleaned = !isNil(isPresent) ? "" : null;
|
|
428
624
|
}
|
|
429
|
-
if (
|
|
625
|
+
if (cleaned !== void 0) {
|
|
430
626
|
cleanedModifier[operation][key] = cleaned;
|
|
431
627
|
}
|
|
432
628
|
}
|
|
433
|
-
if ((
|
|
629
|
+
if (isEmpty(cleanedModifier[operation])) {
|
|
434
630
|
delete cleanedModifier[operation];
|
|
435
631
|
}
|
|
436
632
|
}
|
|
437
633
|
if (isUpsert) {
|
|
438
634
|
const cleanedSetOnInsert = await (0, import_schema7.clean)(schema, fromDot(cleanedModifier.$setOnInsert || {}));
|
|
439
|
-
if (!(
|
|
635
|
+
if (!isEmpty(cleanedSetOnInsert)) {
|
|
440
636
|
cleanedModifier.$setOnInsert = cleanedSetOnInsert;
|
|
441
637
|
}
|
|
442
638
|
}
|
|
443
|
-
if ((
|
|
639
|
+
if (equals(cleanedModifier, {})) {
|
|
444
640
|
throw new Error("After cleaning your modifier is empty");
|
|
445
641
|
}
|
|
446
642
|
return cleanedModifier;
|
|
@@ -606,13 +802,12 @@ function deleteMany_default(collection) {
|
|
|
606
802
|
}
|
|
607
803
|
|
|
608
804
|
// src/createCollection/getMethods/insertOne.ts
|
|
609
|
-
var import_isPlainObject2 = __toESM(require("lodash/isPlainObject"), 1);
|
|
610
805
|
var import_schema9 = require("@orion-js/schema");
|
|
611
806
|
var insertOne_default = (collection) => {
|
|
612
807
|
const insertOne = async (insertDoc, options = {}) => {
|
|
613
808
|
await collection.connectionPromise;
|
|
614
809
|
let doc = insertDoc;
|
|
615
|
-
if (!doc || !(
|
|
810
|
+
if (!doc || !isType("Object", doc)) {
|
|
616
811
|
throw new Error("Insert must receive a document");
|
|
617
812
|
}
|
|
618
813
|
if (!doc._id) {
|
|
@@ -632,15 +827,14 @@ var insertOne_default = (collection) => {
|
|
|
632
827
|
};
|
|
633
828
|
|
|
634
829
|
// src/createCollection/getMethods/insertMany.ts
|
|
635
|
-
var
|
|
636
|
-
var import_lodash = require("lodash");
|
|
830
|
+
var import_helpers2 = require("@orion-js/helpers");
|
|
637
831
|
var import_schema10 = require("@orion-js/schema");
|
|
638
832
|
var insertMany_default = (collection) => {
|
|
639
833
|
const insertMany = async (docs, options = {}) => {
|
|
640
834
|
await collection.connectionPromise;
|
|
641
835
|
for (let index = 0; index < docs.length; index++) {
|
|
642
|
-
let doc = (0,
|
|
643
|
-
if (!doc ||
|
|
836
|
+
let doc = (0, import_helpers2.clone)(docs[index]);
|
|
837
|
+
if (!doc || type(doc) !== "Object") {
|
|
644
838
|
throw new Error(`Item at index ${index} is not a document`);
|
|
645
839
|
}
|
|
646
840
|
if (!doc._id) {
|
|
@@ -656,7 +850,7 @@ var insertMany_default = (collection) => {
|
|
|
656
850
|
const { insertedIds } = await wrapErrors(() => {
|
|
657
851
|
return collection.rawCollection.insertMany(docs, options.mongoOptions);
|
|
658
852
|
});
|
|
659
|
-
const ids =
|
|
853
|
+
const ids = Object.values(insertedIds);
|
|
660
854
|
return ids.map((id) => id.toString());
|
|
661
855
|
};
|
|
662
856
|
return insertMany;
|
|
@@ -701,13 +895,12 @@ var estimatedDocumentCount_default = (collection) => {
|
|
|
701
895
|
};
|
|
702
896
|
|
|
703
897
|
// src/createCollection/getMethods/insertAndFind.ts
|
|
704
|
-
var import_isPlainObject4 = __toESM(require("lodash/isPlainObject"), 1);
|
|
705
898
|
var import_schema11 = require("@orion-js/schema");
|
|
706
899
|
var insertAndFind_default = (collection) => {
|
|
707
900
|
const insertAndFind = async (insertDoc, options = {}) => {
|
|
708
901
|
await collection.connectionPromise;
|
|
709
902
|
let doc = insertDoc;
|
|
710
|
-
if (!doc ||
|
|
903
|
+
if (!doc || type(doc) !== "Object") {
|
|
711
904
|
throw new Error("Insert must receive a document");
|
|
712
905
|
}
|
|
713
906
|
if (!doc._id) {
|
|
@@ -757,8 +950,7 @@ function loadOne_default(collection) {
|
|
|
757
950
|
}
|
|
758
951
|
|
|
759
952
|
// src/createCollection/getMethods/dataLoader/loadData.ts
|
|
760
|
-
var
|
|
761
|
-
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
953
|
+
var import_helpers4 = require("@orion-js/helpers");
|
|
762
954
|
|
|
763
955
|
// src/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.ts
|
|
764
956
|
var import_dataloader = __toESM(require("dataloader"), 1);
|
|
@@ -780,17 +972,16 @@ var getDataLoader = (params) => {
|
|
|
780
972
|
};
|
|
781
973
|
|
|
782
974
|
// src/createCollection/getMethods/dataLoader/dataLoad/index.ts
|
|
783
|
-
var
|
|
784
|
-
var import_helpers2 = require("@orion-js/helpers");
|
|
975
|
+
var import_helpers3 = require("@orion-js/helpers");
|
|
785
976
|
var dataLoad = async (options) => {
|
|
786
977
|
const dataLoader = getDataLoader({
|
|
787
|
-
key: (0,
|
|
978
|
+
key: (0, import_helpers3.hashObject)(options.loaderKey),
|
|
788
979
|
func: options.load,
|
|
789
980
|
timeout: options.timeout || 5
|
|
790
981
|
});
|
|
791
982
|
if (options.ids) {
|
|
792
983
|
const resultArray = await dataLoader.loadMany(options.ids);
|
|
793
|
-
return (
|
|
984
|
+
return flatten(resultArray);
|
|
794
985
|
}
|
|
795
986
|
return await dataLoader.load(options.id);
|
|
796
987
|
};
|
|
@@ -811,10 +1002,10 @@ function loadData_default(collection) {
|
|
|
811
1002
|
id: options.value,
|
|
812
1003
|
ids: options.values,
|
|
813
1004
|
timeout: options.timeout,
|
|
814
|
-
load: async (
|
|
1005
|
+
load: async (values) => {
|
|
815
1006
|
const query = {
|
|
816
|
-
...(0,
|
|
817
|
-
[options.key]: { $in:
|
|
1007
|
+
...(0, import_helpers4.clone)(options.match),
|
|
1008
|
+
[options.key]: { $in: values }
|
|
818
1009
|
};
|
|
819
1010
|
const cursor = collection.find(query);
|
|
820
1011
|
if (options.sort) {
|
|
@@ -827,8 +1018,8 @@ function loadData_default(collection) {
|
|
|
827
1018
|
console.info(`Will execute data loading query now on ${collection.name}: `, query);
|
|
828
1019
|
}
|
|
829
1020
|
const items = await cursor.toArray();
|
|
830
|
-
const itemsMap = (0,
|
|
831
|
-
return
|
|
1021
|
+
const itemsMap = (0, import_helpers4.createMapArray)(items, options.key);
|
|
1022
|
+
return values.map((value) => {
|
|
832
1023
|
return itemsMap[value] || [];
|
|
833
1024
|
});
|
|
834
1025
|
}
|
|
@@ -839,7 +1030,7 @@ function loadData_default(collection) {
|
|
|
839
1030
|
}
|
|
840
1031
|
|
|
841
1032
|
// src/createCollection/generateId.ts
|
|
842
|
-
var
|
|
1033
|
+
var import_helpers5 = require("@orion-js/helpers");
|
|
843
1034
|
var import_bson = require("bson");
|
|
844
1035
|
var getIdGenerator = (options) => {
|
|
845
1036
|
var _a, _b;
|
|
@@ -848,7 +1039,7 @@ var getIdGenerator = (options) => {
|
|
|
848
1039
|
if ((_b = idField.name) == null ? void 0 : _b.startsWith("typedId:")) {
|
|
849
1040
|
return () => {
|
|
850
1041
|
const prefix = idField.name.split(":")[1];
|
|
851
|
-
const random = (0,
|
|
1042
|
+
const random = (0, import_helpers5.generateUUID)();
|
|
852
1043
|
return `${prefix}-${random}`;
|
|
853
1044
|
};
|
|
854
1045
|
}
|
|
@@ -856,14 +1047,14 @@ var getIdGenerator = (options) => {
|
|
|
856
1047
|
if (options.idPrefix || options.idGeneration === "uuid") {
|
|
857
1048
|
return () => {
|
|
858
1049
|
const prefix = options.idPrefix || "";
|
|
859
|
-
const random = (0,
|
|
1050
|
+
const random = (0, import_helpers5.generateUUID)();
|
|
860
1051
|
return `${prefix}${random}`;
|
|
861
1052
|
};
|
|
862
1053
|
}
|
|
863
1054
|
if (options.idGeneration === "random") {
|
|
864
1055
|
return () => {
|
|
865
1056
|
const prefix = options.idPrefix || "";
|
|
866
|
-
const random = (0,
|
|
1057
|
+
const random = (0, import_helpers5.generateId)();
|
|
867
1058
|
return `${prefix}${random}`;
|
|
868
1059
|
};
|
|
869
1060
|
}
|
|
@@ -934,7 +1125,7 @@ async function loadIndexes(collection) {
|
|
|
934
1125
|
}
|
|
935
1126
|
|
|
936
1127
|
// src/createCollection/getSchemaAndModel.ts
|
|
937
|
-
var
|
|
1128
|
+
var import_helpers6 = require("@orion-js/helpers");
|
|
938
1129
|
Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
|
|
939
1130
|
function prepareShema(schema) {
|
|
940
1131
|
if (!schema._id) {
|
|
@@ -956,10 +1147,10 @@ function getSchema(options) {
|
|
|
956
1147
|
}
|
|
957
1148
|
if (options.schema.getModel) {
|
|
958
1149
|
const model = options.schema.getModel();
|
|
959
|
-
const schema = model ? (0,
|
|
1150
|
+
const schema = model ? (0, import_helpers6.clone)(model.getSchema()) : {};
|
|
960
1151
|
return prepareShema(schema);
|
|
961
1152
|
}
|
|
962
|
-
if ((
|
|
1153
|
+
if (type(options.schema) === "Object") {
|
|
963
1154
|
return prepareShema(options.schema);
|
|
964
1155
|
}
|
|
965
1156
|
}
|